Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setting user-info page #4

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/app/setting/SettingClient/BtnList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Bot,
Cog,
Info,
LogOut,
MessageCircleMore,
Expand All @@ -22,8 +23,17 @@ const SettingBtnList = React.memo<any>(() => {
() => [
{
icon: User2Icon,
title: '编辑个人资料',
href: '/setting/profile',
title: '个人资料',
href: '/setting/user-info',
},
{
icon: Cog,
title: '数据控制',
href: '/setting/user-info',
},
{
icon: Settings,
title: '账号设置',
},
],
[]
Expand Down Expand Up @@ -65,10 +75,6 @@ const SettingBtnList = React.memo<any>(() => {

const btnsSetting: Btn[] = React.useMemo(
() => [
{
icon: Settings,
title: '账号设置',
},
{
icon: LogOut,
title: '退出登录',
Expand All @@ -78,8 +84,8 @@ const SettingBtnList = React.memo<any>(() => {
);
return (
<div className={styles.btnlist}>
<BtnsBlock btns={btnsUser} />
<BtnsBlock btns={btnsMy} />
<BtnsBlock btns={btnsUser} />
<BtnsBlock btns={btnsActions} />
<BtnsBlock btns={btnsSetting} />
</div>
Expand Down
15 changes: 9 additions & 6 deletions src/app/setting/SettingClient/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import classNames from 'classnames';
import React from 'react';

import ReturnBtn from '@/components/ReturnBtn';
Expand All @@ -18,11 +17,15 @@ interface SettingProps {
const Setting = React.memo<SettingProps>(({ user }: SettingProps) => {
const { styles } = useStyles();
return (
<div className={classNames(styles.setting, 'showScrollBar')}>
<ReturnBtn />
<div className={styles.content}>
<UserInfo user={user} />
<BtnList />
<div className={styles.setting}>
<div>
<ReturnBtn />
<div className={'scrollBar'}>
<div className={styles.content}>
<UserInfo user={user} />
<BtnList />
</div>
</div>
</div>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/setting/SettingClient/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ token }) => ({
setting: {
height: '100%',
width: '100%',
background: token.colorBgLayout,
overflowY: 'auto',
position: 'relative',
},
content: {
maxWidth: '600px',
margin: '0 auto',
paddingTop: '64px',
paddingBottom: '24px',
},
}));
122 changes: 122 additions & 0 deletions src/app/setting/user-info/UserInfoClient/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use client';

import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Flex, Form, Input, Upload } from 'antd';
import type { UploadFile } from 'antd';
import classNames from 'classnames';
import React, { useState } from 'react';

import ReturnBtn from '@/components/ReturnBtn';

import { useStyles } from './styles';

const getBase64 = (img: any, callback: (url: string) => void) => {
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result as string));
reader.readAsDataURL(img);
};

interface Props {
user: {
name: string;
};
}

const normFile = (e: any) => {
if (Array.isArray(e)) {
return e;
}
if (!e?.fileList?.length) {
return [];
}
return [e?.fileList[e?.fileList?.length - 1]];
};

const onFinish = () => {
// console.log('values', values)
};
const UserInfoClient: React.FC<Props> = () => {
const { styles } = useStyles();
const [loading, setLoading] = useState(false);
const [imageUrl, setImageUrl] = useState<string>();
const [form] = Form.useForm();

const uploadButton = (
<div className={styles.uploadText}>
{loading ? <LoadingOutlined /> : <PlusOutlined />}
<div>上传头像</div>
</div>
);

return (
<div className={classNames(styles.userInfo)}>
<div>
<ReturnBtn title="个人资料" to="/setting" />
<Flex className={classNames(styles.content, 'scrollBar')} justify={'center'}>
<Form form={form} layout="vertical" onFinish={onFinish}>
<Form.Item getValueFromEvent={normFile} name="avatar" valuePropName="fileList">
<Upload
accept={'image/png, image/jpeg, image/jpg'}
beforeUpload={(file: any) => {
// const isLt10M = file.size / 1024 / 1024 <= 5;
// if (!isLt10M) {
// notification.warn({
// message: '不能大于 5MB!',
// });
// return Promise.reject();
// }
return Promise.resolve(file);
}}
customRequest={(options: any) => {
const { onSuccess, file } = options;
file.status = 'done';
onSuccess(file.uid);
getBase64(file as UploadFile, url => {
setLoading(false);
setImageUrl(url);
});
}}
listType="picture-circle"
onChange={({ file }) => {
file.status = 'done';
}}
showUploadList={false}
>
{imageUrl ? (
<img alt="avatar" src={imageUrl} style={{ width: '100%' }} />
) : (
uploadButton
)}
</Upload>
</Form.Item>
<Form.Item
label="昵称"
name="nickname"
rules={[{ required: true, message: '请输入昵称' }]}
>
<Input placeholder="请输入昵称" size="large" />
</Form.Item>
<Form.Item
extra={'只能使用字母、数字以及下划线,长度为 4-16 个字符'}
label="账号"
name="id"
rules={[{ required: true, message: '请输入账号' }]}
>
<Input placeholder="请输入账号" size="large" />
</Form.Item>
{/* <Form.Item name="pwd" initialValue={'******'} label="登录密码">
<Input.Password size="large" disabled />
</Form.Item> */}
<Form.Item>
<Button className={styles.sub} htmlType={'submit'} size="large" type="primary">
完成
</Button>
</Form.Item>
</Form>
</Flex>
</div>
</div>
);
};

export default UserInfoClient;
46 changes: 46 additions & 0 deletions src/app/setting/user-info/UserInfoClient/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ token }) => ({
userInfo: {
'height': '100%',
'width': '100%',
'background': token.colorBgLayout,
'position': 'relative',
'& > div': {
position: 'relative',
overflow: 'hidden',
height: '100%',
paddingBottom: '40px',
paddingTop: '64px',
},
},
sub: {
width: '100%',
},
content: {
'paddingTop': 16,
'paddingBottom': 42,
'.ant-form': {
width: 600,
},
'.ant-upload-wrapper': {
textAlign: 'center',
position: 'relative',
},
'.ant-upload-wrapper.ant-upload-picture-circle-wrapper .ant-upload.ant-upload-select': {
overflow: 'hidden',
border: 'unset',
},
'.ant-input-lg': {
borderRadius: token.borderRadius,
padding: '8px 11px',
},
},
uploadText: {
'border': 0,
'background': 'none',
'& > div': {
marginTop: 4,
},
},
}));
7 changes: 7 additions & 0 deletions src/app/setting/user-info/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PropsWithChildren, memo } from 'react';

const Layout = memo<PropsWithChildren>(({ children }) => {
return <>{children}</>;
});

export default Layout;
17 changes: 17 additions & 0 deletions src/app/setting/user-info/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import { getUserData } from '../../actions/user';
import UserInfoClient from './UserInfoClient';

export default async function DesktopPage() {
const user = await getUserData();
const props = {
user,
};
// todo fetch server data
return (
<>
<UserInfoClient {...props} />
</>
);
}
20 changes: 18 additions & 2 deletions src/components/BtnsBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ActionIcon } from '@lobehub/ui';
import { Flex } from 'antd';
import { createStyles } from 'antd-style';
import { ChevronRight, User } from 'lucide-react';
import Link from 'next/link';
import React from 'react';

export const useStyles = createStyles(() => ({
Expand All @@ -14,6 +15,12 @@ export const useStyles = createStyles(() => ({
overflowY: 'auto',
width: '100%',
},
linkWrapper: {
'color': 'inherit',
'&:hover': {
color: 'inherit',
},
},
btn: {
'width': '100%',
'background': 'white',
Expand Down Expand Up @@ -68,8 +75,9 @@ const BtnsBlock = React.memo<BtnsBlockProps>(props => {
{btns.map((item, idx) => {
const icon = item.icon || User;
const icon_bg = item.icon_bg || theme.colorPrimary;
return (
<Flex align={'center'} className={styles.btn} key={item.title + idx}>
const key = item.title + idx;
const children = (
<Flex align={'center'} className={styles.btn} key={key}>
<div className={styles.icon} style={{ backgroundColor: icon_bg }}>
<ActionIcon color={'white'} icon={icon} />
</div>
Expand All @@ -83,6 +91,14 @@ const BtnsBlock = React.memo<BtnsBlockProps>(props => {
</Flex>
</Flex>
);
if (item.href) {
return (
<Link className={styles.linkWrapper} href={item.href} key={'link-wrapper-' + key}>
{children}
</Link>
);
}
return children;
})}
</div>
);
Expand Down
15 changes: 14 additions & 1 deletion src/components/ReturnBtn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const useStyles = createStyles(() => ({
returnBtn: {
padding: '0 16px',
height: '64px',
position: 'fixed',
position: 'absolute',
top: 0,
width: '100%',
zIndex: 9,
overflowY: 'auto',
},
btn: {
borderRadius: '12px !important',
Expand All @@ -22,10 +24,20 @@ export const useStyles = createStyles(() => ({
height: 25,
},
},
title: {
flex: '1 1',
alignItems: 'center',
display: 'flex',
fontWeight: 590,
fontSize: 16,
flexDirection: 'column',
marginLeft: '-40px',
},
}));

interface ReturnBtnProps {
to?: string;
title?: string;
}

const ReturnBtn = React.memo<ReturnBtnProps>(props => {
Expand All @@ -36,6 +48,7 @@ const ReturnBtn = React.memo<ReturnBtnProps>(props => {
<Link href={to || '/chat'}>
<ActionIcon className={styles.btn} icon={ChevronLeft} />
</Link>
<div className={styles.title}>{props.title}</div>
</Flex>
);
});
Expand Down
1 change: 0 additions & 1 deletion src/layout/AppLayout/SideBar/Chats/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
position: relative;
overflow-y: auto;
flex: 1 1 0%;
padding-right: 8px;
}

.content {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/AppLayout/SideBar/Chats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './index.module.css';
const Chats: any = async () => {
const list = await getChatList();
return (
<div className={classnames(styles.chats, 'showScrollBar')}>
<div className={classnames(styles.chats, 'scrollBar')}>
<div className={styles.content}>
{list.map((item: any, idx: number) => (
<ChatItem data={item} key={item.name + idx} />
Expand Down
Loading
Loading