From fee38f39e36bcda9924f5b26dca609dda6b331e0 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期日, 22 六月 2025 16:53:27 +0800
Subject: [PATCH] no message
---
zy-asrs-flow/src/pages/account/setting/components/base.jsx | 365 +++++++++++++++++++++++++++++-----------------------
1 files changed, 204 insertions(+), 161 deletions(-)
diff --git a/zy-asrs-flow/src/pages/account/setting/components/base.jsx b/zy-asrs-flow/src/pages/account/setting/components/base.jsx
index 4bdb957..475c85e 100644
--- a/zy-asrs-flow/src/pages/account/setting/components/base.jsx
+++ b/zy-asrs-flow/src/pages/account/setting/components/base.jsx
@@ -1,161 +1,204 @@
-import { UploadOutlined } from '@ant-design/icons';
-import {
- ProForm,
- ProFormDependency,
- ProFormFieldSet,
- ProFormSelect,
- ProFormText,
- ProFormTextArea,
-} from '@ant-design/pro-components';
-import { useRequest } from '@umijs/max';
-import { Button, Input, message, Upload } from 'antd';
-import React from 'react';
-import useStyles from './index.style';
-
-const queryCurrent = () => {
-
-}
-
-const validatorPhone = (rule, value, callback) => {
- if (!value[0]) {
- callback('Please input your area code!');
- }
- if (!value[1]) {
- callback('Please input your phone number!');
- }
- callback();
-};
-
-const BaseView = () => {
- const { styles } = useStyles();
-
- // 澶村儚缁勪欢 鏂逛究浠ュ悗鐙珛锛屽鍔犺鍓箣绫荤殑鍔熻兘
- const AvatarView = ({ avatar }) => (
- <>
- <div className={styles.avatar_title}>澶村儚</div>
- <div className={styles.avatar}>
- <img src={avatar} alt="avatar" />
- </div>
- <Upload showUploadList={false}>
- <div className={styles.button_view}>
- <Button>
- <UploadOutlined />
- 鏇存崲澶村儚
- </Button>
- </div>
- </Upload>
- </>
- );
-
- const { data: currentUser, loading } = useRequest(() => {
- return queryCurrent();
- });
-
- const getAvatarURL = () => {
- if (currentUser) {
- if (currentUser.avatar) {
- return currentUser.avatar;
- }
- const url = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png';
- return url;
- }
- return '';
- };
-
- const handleFinish = async () => {
- message.success('鏇存柊鍩烘湰淇℃伅鎴愬姛');
- };
-
- return (
- <div className={styles.baseView}>
- {loading ? null : (
- <>
- <div className={styles.left}>
- <ProForm
- layout="vertical"
- onFinish={handleFinish}
- submitter={{
- searchConfig: {
- submitText: '鏇存柊鍩烘湰淇℃伅',
- },
- render: (_, dom) => dom[1],
- }}
- initialValues={{
- ...currentUser,
- phone: currentUser?.phone.split('-'),
- }}
- hideRequiredMark
- >
- <ProFormText
- width="md"
- name="email"
- label="閭"
- rules={[
- {
- required: true,
- message: '璇疯緭鍏ユ偍鐨勯偖绠�!',
- },
- ]}
- />
- <ProFormText
- width="md"
- name="name"
- label="鏄电О"
- rules={[
- {
- required: true,
- message: '璇疯緭鍏ユ偍鐨勬樀绉�!',
- },
- ]}
- />
- <ProFormTextArea
- name="profile"
- label="涓汉绠�浠�"
- rules={[
- {
- required: true,
- message: '璇疯緭鍏ヤ釜浜虹畝浠�!',
- },
- ]}
- placeholder="涓汉绠�浠�"
- />
-
- <ProFormText
- width="md"
- name="address"
- label="鍦板潃"
- rules={[
- {
- required: true,
- message: '璇疯緭鍏ユ偍鐨勫湴鍧�!',
- },
- ]}
- />
- <ProFormFieldSet
- name="phone"
- label="鑱旂郴鐢佃瘽"
- rules={[
- {
- required: true,
- message: '璇疯緭鍏ユ偍鐨勮仈绯荤數璇�!',
- },
- {
- validator: validatorPhone,
- },
- ]}
- >
- <Input className={styles.area_code} />
- <Input className={styles.phone_number} />
- </ProFormFieldSet>
- </ProForm>
- </div>
- <div className={styles.right}>
- <AvatarView avatar={getAvatarURL()} />
- </div>
- </>
- )}
- </div>
- );
-};
-
-export default BaseView;
+import {
+ ProForm,
+ ProFormText,
+ ProFormTextArea,
+ ProFormSelect,
+ ProFormDigit
+} from '@ant-design/pro-components';
+import { Button, Input, message, Upload, Form } from 'antd';
+import { FormattedMessage, useIntl } from '@umijs/max';
+import React from 'react';
+import useStyles from './index.style';
+import Http from '@/utils/http';
+
+import defaultAvat from '/public/img/defaultAva.jpg'
+
+const handleUpdate = async (val, intl) => {
+ const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '姝e湪鏇存柊' }));
+ try {
+ const resp = await Http.doPost('api/user/update', val);
+ if (resp.code === 200) {
+ message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '鏇存柊鎴愬姛' }));
+ return true;
+ } else {
+ message.error(resp.msg);
+ return false;
+ }
+ } catch (error) {
+ message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '鏇存柊澶辫触璇烽噸璇曪紒' }));
+ return false;
+ } finally {
+ hide();
+ }
+};
+
+const BaseView = () => {
+ const intl = useIntl();
+ const { styles } = useStyles();
+ const [loading, setLoading] = React.useState(false);
+ const [currentUser, setCurrentUser] = React.useState({});
+ const [form] = Form.useForm();
+
+ const AvatarView = ({ avatar }) => (
+ <>
+ <div className={styles.avatar_title}>澶村儚</div>
+ <div className={styles.avatar}>
+ <img src={avatar} alt="avatar" />
+ </div>
+ <Upload showUploadList={false}>
+ <div className={styles.button_view}>
+ {/* <Button>
+ <UploadOutlined />
+ 鏇存崲澶村儚
+ </Button> */}
+ </div>
+ </Upload>
+ </>
+ );
+
+ const queryCurrent = () => {
+ setLoading(true);
+ Http.doGetPromise('api/auth/user', {}, (res) => {
+ setLoading(false);
+ setCurrentUser(res.data);
+ }).catch((err) => {
+ console.error(err);
+ setLoading(false);
+ })
+ }
+
+ React.useEffect(() => {
+ queryCurrent();
+ }, []);
+
+ const getAvatarURL = () => {
+ if (currentUser) {
+ if (currentUser.avatar) {
+ return currentUser.avatar;
+ }
+ }
+ return defaultAvat;
+ };
+
+ const handleFinish = async (values) => {
+ handleUpdate(values, intl);
+ };
+
+ return (
+ <div className={styles.baseView}>
+ {loading ? null : (
+ <>
+ <div className={styles.left}>
+ <ProForm
+ form={form}
+ layout="vertical"
+ onFinish={handleFinish}
+ submitter={{
+ searchConfig: {
+ submitText: intl.formatMessage({ id: 'personal.base.button.name', defaultMessage: '鏇存柊鍩烘湰淇℃伅' }),
+ },
+ render: (_, dom) => dom[1],
+ }}
+ initialValues={{
+ ...currentUser,
+ }}
+ hideRequiredMark
+ >
+ <ProFormDigit
+ name="id"
+ disabled
+ hidden={true}
+ />
+ <ProFormText
+ width="md"
+ name="username"
+ label={intl.formatMessage({ id: 'common.username', defaultMessage: "璐﹀彿" })}
+ disabled
+ rules={[
+ {
+ required: true,
+ },
+ ]}
+ />
+ <ProFormText
+ width="md"
+ name="nickname"
+ label={intl.formatMessage({ id: 'common.nickname', defaultMessage: "鍚嶇О" })}
+ rules={[
+ {
+ required: true,
+ },
+ ]}
+ />
+ <ProFormSelect
+ width="md"
+ name="sex"
+ label={intl.formatMessage({ id: 'common.sex', defaultMessage: "鎬у埆" })}
+ colProps={{ md: 12, xl: 12 }}
+ options={[
+ { label: intl.formatMessage({ id: 'common.undefined', defaultMessage: "鏈煡" }), value: 0 },
+ { label: intl.formatMessage({ id: 'common.male', defaultMessage: '鐢�' }), value: 1 },
+ { label: intl.formatMessage({ id: 'common.female', defaultMessage: '濂�' }), value: 2 },
+ ]}
+ />
+ <ProFormText
+ width="md"
+ name="phone"
+ label={intl.formatMessage({ id: 'common.phone', defaultMessage: "鎵嬫満鍙�" })}
+ rules={[
+ {
+ required: false,
+ },
+ ]}
+ />
+ <ProFormText
+ width="md"
+ name="email"
+ label={intl.formatMessage({ id: 'common.email', defaultMessage: "閭" })}
+ rules={[
+ {
+ required: false,
+ },
+ ]}
+ />
+ <ProFormText
+ width="md"
+ name="realName"
+ label={intl.formatMessage({ id: 'common.realname', defaultMessage: "鐪熷疄濮撳悕" })}
+ rules={[
+ {
+ required: false,
+ },
+ ]}
+ />
+ <ProFormText
+ width="md"
+ name="idCard"
+ label={intl.formatMessage({ id: 'common.idcard', defaultMessage: "韬唤璇佸彿" })}
+ rules={[
+ {
+ required: false,
+ },
+ ]}
+ />
+ <ProFormTextArea
+ name="introduction"
+ label={intl.formatMessage({ id: 'common.introduction', defaultMessage: "涓汉绠�浠�" })}
+ rules={[
+ {
+ required: false,
+ },
+ ]}
+ />
+ </ProForm>
+ </div>
+ <div className={styles.right}>
+ <AvatarView avatar={getAvatarURL()} />
+ </div>
+ </>
+ )}
+ </div>
+ );
+};
+
+export default BaseView;
--
Gitblit v1.9.1