Skip to content

Commit

Permalink
feat: v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Dec 31, 2021
1 parent 51c6db9 commit 358b70f
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 302 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"axios": "^0.24.0",
"bezier-easing": "^2.1.0",
"classnames": "^2.3.1",
"gravatar": "^1.8.2",
"highlight.js": "^11.3.1",
"js-base64": "^3.7.2",
"lodash": "^4.17.21",
Expand All @@ -44,7 +43,6 @@
},
"devDependencies": {
"@types/ali-oss": "^6.16.2",
"@types/gravatar": "^1.8.3",
"@types/lodash": "^4.14.178",
"@types/marked": "^4.0.1",
"@types/node": "^17.0.1",
Expand Down
19 changes: 9 additions & 10 deletions public/__demo__/mock/option.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"status": "success",
"message": "获取设置成功",
"result": {
"keywords": ["Surmon", "前端技术开发", "JavaScript"],
"keywords": ["Surmon", "JavaScript"],
"ad_config": "",
"_id": "589e01b75af07d59124234cd",
"title": "Surmon.me",
"sub_title": "来苏之望",
"description": "凡心所向,素履所往;生如逆旅,一苇以航",
"title": "Blog name",
"sub_title": "sub title",
"description": "site description",
"site_url": "https://surmon.me",
"site_email": "surmon@foxmail.com",
"site_email": "i@example.com",
"site_icp": "",
"ping_sites": ["http://ping.baidu.com/ping/RPC2"],
"__v": 124,
"blocklist": {
"ips": [
Expand All @@ -25,17 +24,17 @@
],
"mails": [
"[email protected]",
"ciscolai666@gmail.com",
"172632763254@qq.com",
"swwerwe@163.com",
"example@gmail.com",
"spam@qq.com",
"ham@163.com",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
],
"keywords": ["asd", "sss", "阿什顿发", "dsds", "asasas", "sdf", "test", "阿萨德"]
},
"meta": { "likes": 590 },
"meta": { "likes": 600 },
"update_at": "2019-01-23T17:44:13.425Z"
}
}
8 changes: 1 addition & 7 deletions src/components/AppLayout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {

import { RouteKey, rc } from '@/routes'
import { removeToken } from '@/services/token'
import { AvatarType } from '@/constants/auth'
import { getGravatar } from '@/transforms/avatar'
import { useAdminState } from '@/state/admin'

import styles from './style.module.less'
Expand Down Expand Up @@ -87,11 +85,7 @@ export const AppHeader: React.FC<AppHeaderProps> = (props) => {
size="small"
icon={<UserOutlined />}
className={styles.avatar}
src={
admin.data.avatar_type === AvatarType.Gravatar
? getGravatar(admin.data.email)
: admin.data.avatar
}
src={admin.data.avatar}
/>
</div>
</Dropdown>
Expand Down
8 changes: 1 addition & 7 deletions src/components/AppLayout/Sider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { GithubOutlined } from '@ant-design/icons'

import { GITHUB_REPO_URL, GITHUB_REPO_NAME } from '@/config'
import { getResourceUrl } from '@/transforms/url'
import { getGravatar } from '@/transforms/avatar'
import { RouteKey, routeMap, rc } from '@/routes'
import { AvatarType } from '@/constants/auth'
import { useAdminState } from '@/state/admin'

import styles from './style.module.less'
Expand Down Expand Up @@ -38,11 +36,7 @@ export const AppSider: React.FC<AppSiderProps> = (props) => {
<Spin spinning={admin.loading.value} size="small">
<div className={styles.userInfo}>
<img
src={
admin.data.avatar_type === AvatarType.Gravatar
? getGravatar(admin.data.email)
: admin.data.avatar
}
src={admin.data.avatar}
alt={admin.data.name}
draggable={false}
className={classnames(
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const APP_COLOR_PRIMARY = '#177ddc'

export const VITE_ENV = import.meta.env
export const ENV = import.meta.env.MODE
export const isDev = ENV === 'development'
export const BASE_PATH = import.meta.env.BASE_URL as string
export const API_URL = import.meta.env.VITE_API_URL as string
export const ENABLED_AD = Boolean(import.meta.env.VITE_ENABLE_AD)
Expand Down
10 changes: 2 additions & 8 deletions src/constants/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
* @author Surmon <https://github.com/surmon-china>
*/

export enum AvatarType {
Gravatar = 1,
URL = 2,
}

export interface Auth {
name: string
slogan: string
email: string
avatar_type: AvatarType
avatar?: string
avatar: string
// optional
password?: string
new_password?: string
}
12 changes: 10 additions & 2 deletions src/constants/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ export interface Comment {
dislikes: number
author: {
name: string
email?: string
site?: string
email?: string
email_hash: string | null
}
ip_location?: any
ip_location?: Partial<{
country: string
country_code: string
region: string
region_code: string
city: string
zip: string
}>
update_at?: string
create_at?: string
extends: Array<GeneralExtend>
Expand Down
2 changes: 1 addition & 1 deletion src/constants/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Option {
description: string
keywords: Array<string>
site_url: string
site_email?: string
site_email: string
blocklist: {
ips: Array<string>
mails: Array<string>
Expand Down
10 changes: 7 additions & 3 deletions src/pages/Comment/EditDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ export const EditDrawer: React.FC<EditDrawerProps> = (props) => {
/>
</Form.Item>
<Form.Item label="IP / 地址">
<Typography.Text copyable={true}>
{props.comment.value?.ip || '-'}
</Typography.Text>
{props.comment.value?.ip ? (
<Typography.Text copyable={true}>
{props.comment.value.ip}
</Typography.Text>
) : (
'-'
)}
<Divider type="vertical" />
{props.comment.value?.ip_location?.country || '-'}
<span> - </span>
Expand Down
20 changes: 15 additions & 5 deletions src/pages/Comment/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const CommentListTable: React.FC<CommentListTableProps> = (props) => {
头像:
<Avatar
shape="square"
size="small"
size="default"
src={autoCommentAvatar(comment)}
/>
</span>
Expand Down Expand Up @@ -145,13 +145,23 @@ export const CommentListTable: React.FC<CommentListTableProps> = (props) => {
<Space direction="vertical">
<span>
IP:
<Typography.Text copyable={true}>{comment.ip || '-'}</Typography.Text>
{!comment.ip ? (
'-'
) : (
<Typography.Text copyable={true}>{comment.ip}</Typography.Text>
)}
</span>
<span>
位置:
{comment.ip_location?.country || '-'}
<span> - </span>
{comment.ip_location?.city || '-'}
{!comment.ip_location
? '-'
: [
comment.ip_location.country,
comment.ip_location.region,
comment.ip_location.city,
]
.filter(Boolean)
.join(' · ')}
</span>
<span>
终端:
Expand Down
1 change: 0 additions & 1 deletion src/pages/Dsiqus/Post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Card,
Table,
Select,
Modal,
Input,
Space,
Divider,
Expand Down
78 changes: 11 additions & 67 deletions src/pages/Profile/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { CheckOutlined, MailOutlined } from '@ant-design/icons'

import { RouteKey, rc } from '@/routes'
import { ImageUploader } from '@/components/common/ImageUploader'
import { Auth, AvatarType } from '@/constants/auth'
import { getGravatar } from '@/transforms/avatar'
import { Auth } from '@/constants/auth'
import { scrollTo } from '@/services/scroller'
import { removeToken } from '@/services/token'
import { useAdminState } from '@/state/admin'
Expand Down Expand Up @@ -48,6 +47,7 @@ export const AuthForm: React.FC<BaseFormProps> = (props) => {

const handleSubmit = () => {
form.validateFields().then((newAdminAuth) => {
Reflect.deleteProperty(newAdminAuth, 'rel_new_password')
updateAdminAuth({
...adminAuth.data,
...newAdminAuth,
Expand Down Expand Up @@ -85,52 +85,13 @@ export const AuthForm: React.FC<BaseFormProps> = (props) => {
wrapperCol={{ span: props.wrapperSpan }}
>
<Form.Item
name="avatar_type"
label="个人头像"
name="avatar"
label="头像"
required={true}
wrapperCol={{ span: 6 }}
rules={[{ required: true }]}
rules={[{ required: true, message: '请上传图片' }]}
>
<Select
options={[
{
label: 'Gravatar',
value: AvatarType.Gravatar,
},
{
label: '自定义',
value: AvatarType.URL,
},
]}
/>
</Form.Item>
<Form.Item noStyle={true} shouldUpdate={true}>
{(formValues) => {
const avatarType = formValues.getFieldValue('avatar_type')
if (avatarType === AvatarType.Gravatar) {
return (
<Form.Item label="Gravatar" wrapperCol={{ span: 6 }}>
<Avatar
shape="square"
style={{ width: '100%' }}
src={getGravatar(formValues.getFieldValue('email'))}
/>
</Form.Item>
)
}

return (
<Form.Item
name="avatar"
label="头像地址"
required={true}
wrapperCol={{ span: 6 }}
rules={[{ required: true, message: '请上传图片' }]}
>
<ImageUploader disabledMarkdown={true} />
</Form.Item>
)
}}
<ImageUploader disabledMarkdown={true} />
</Form.Item>
<Form.Item
name="name"
Expand All @@ -142,36 +103,19 @@ export const AuthForm: React.FC<BaseFormProps> = (props) => {
</Form.Item>
<Form.Item
name="slogan"
label="个人签名"
label="签名"
required={true}
rules={[{ required: true, message: '请输入签名' }]}
>
<Input placeholder="个人签名" />
</Form.Item>
<Form.Item
name="email"
label="个人邮箱"
required={true}
rules={[
{
message: '请输入',
required: true,
},
{
message: '请输入正确的邮箱地址',
type: 'email',
},
]}
>
<Input suffix={<MailOutlined />} placeholder="[email protected]" />
<Input placeholder="签名" />
</Form.Item>
<Divider />
<Form.Item
name="password"
label="旧密码"
rules={[
{
message: '确认新旧密码一致且有效',
message: '确保新旧密码不一致,且有效',
validator: validatePassword,
},
]}
Expand All @@ -183,7 +127,7 @@ export const AuthForm: React.FC<BaseFormProps> = (props) => {
label="新密码"
rules={[
{
message: '确认新旧密码一致且有效',
message: '确保新旧密码不一致,且有效',
validator: validatePassword,
},
]}
Expand All @@ -195,7 +139,7 @@ export const AuthForm: React.FC<BaseFormProps> = (props) => {
label="确认新密码"
rules={[
{
message: '确认新旧密码一致且有效',
message: '确保新旧密码不一致,且有效',
validator: validatePassword,
},
]}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TabsConfig = [
},
{
key: TabKey.Auth,
name: '个人资料',
name: '站长资料',
icon: <UserOutlined />,
element: <AuthForm labelSpan={FORM_LABEL_SPAN} wrapperSpan={FORM_WRAPPER_SPAN} />,
},
Expand Down
13 changes: 5 additions & 8 deletions src/state/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

import { ref, reactive, readonly, useReactivity } from 'veact'
import { createLoading } from 'veact-use'
import { AvatarType, Auth } from '@/constants/auth'
import { Auth } from '@/constants/auth'
import { getAdminInfo } from '@/store/auth'
import { getResourceUrl } from '@/transforms/url'

const DEFAULT_ADMIN_INFO: Auth = Object.freeze({
name: 'Admin',
slogan: 'NodePress',
email: '',
avatar_type: AvatarType.URL,
avatar: getResourceUrl('/images/profile/logo-smooth.png'),
})

Expand All @@ -22,11 +20,10 @@ const loading = createLoading(false, ref)
const fetch = () => {
return loading.promise(getAdminInfo()).then((result) => {
if (result) {
data.name = result.name
data.slogan = result.slogan
data.email = result.email
data.avatar_type = result.avatar_type
data.avatar = result.avatar
Object.keys(result).forEach((key) => {
// @ts-ignore
data[key] = result[key]
})
}
return result
})
Expand Down
Loading

0 comments on commit 358b70f

Please sign in to comment.