From 3540f51429534f790435fc862a6e8dd6e2ef4f90 Mon Sep 17 00:00:00 2001 From: sunqh <253801736@qq.com> Date: Tue, 27 Jan 2026 14:04:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configs/menuConfig.tsx | 2 +- src/configs/routes.ts | 4 +- .../Profile/components/ProfileEditForm.tsx | 83 +++++++++++++++++-- .../components/AdminDepEditModal.tsx | 0 .../components/AdminDepSelect.tsx | 0 src/pages/Staff/{dep => Dept}/index.tsx | 4 +- src/pages/Staff/List/index.tsx | 2 +- src/store/type.ts | 1 + src/utils/common.ts | 2 +- vite.config.ts | 2 +- 10 files changed, 85 insertions(+), 15 deletions(-) rename src/pages/Staff/{dep => Dept}/components/AdminDepEditModal.tsx (100%) rename src/pages/Staff/{dep => Dept}/components/AdminDepSelect.tsx (100%) rename src/pages/Staff/{dep => Dept}/index.tsx (99%) diff --git a/src/configs/menuConfig.tsx b/src/configs/menuConfig.tsx index f996306..3410488 100644 --- a/src/configs/menuConfig.tsx +++ b/src/configs/menuConfig.tsx @@ -31,7 +31,7 @@ const authMenu: MenuDataItem = { icon: , children: [ { name: '管理员信息', path: '/staff/list', auth: 'SF_ADMIN_ADMIN_VIEW' }, - { name: '组织架构', path: '/staff/dep', auth: 'SF_ADMIN_DEPART_VIEW' }, + { name: '组织架构', path: '/staff/dept', auth: 'SF_ADMIN_DEPART_VIEW' }, { name: '岗位角色', path: '/staff/group', auth: 'SF_ADMIN_GROUP_VIEW' }, { name: '我的权限', path: '/staff/auth', auth: 'SF_ADMIN_AUTH_VIEW' }, { name: '登录日志', path: '/staff/login', auth: 'SF_LOGIN_LOG_VIEW' }, diff --git a/src/configs/routes.ts b/src/configs/routes.ts index a04c4b3..4e870e8 100644 --- a/src/configs/routes.ts +++ b/src/configs/routes.ts @@ -7,7 +7,7 @@ import Index from '@/pages/Index'; import Login from '@/pages/Record/Login'; import Sys from '@/pages/Record/Sys'; import Auth from '@/pages/Staff/Auth'; -import Dep from '@/pages/Staff/Dep'; +import Dept from '@/pages/Staff/Dept'; import Grp from '@/pages/Staff/Grp'; import StaffList from '@/pages/Staff/List'; import UserList from '@/pages/User/List'; @@ -44,7 +44,7 @@ export const routes: IRouteItem[] = [ Layout: AppLayout, children: [ { path: '/list', Component: StaffList }, - { path: '/dep', Component: Dep }, + { path: '/dept', Component: Dept }, { path: '/group', Component: Grp }, { path: '/auth', Component: Auth }, { path: '/login', Component: Login }, diff --git a/src/pages/Profile/components/ProfileEditForm.tsx b/src/pages/Profile/components/ProfileEditForm.tsx index 5a4fbc6..c5ae1c6 100644 --- a/src/pages/Profile/components/ProfileEditForm.tsx +++ b/src/pages/Profile/components/ProfileEditForm.tsx @@ -1,7 +1,6 @@ -import { Button, Form, Input, notification } from 'antd'; -import { stringify } from 'qs'; +import { Button, Form, Input, notification, Upload } from 'antd'; import type React from 'react'; -import { useEffect } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { AdminServices } from '@/services/AdminServices'; import { useUserStore } from '@/store/UserStore'; import type { IRef } from '@/utils/type'; @@ -18,8 +17,10 @@ export type IProfileEditFormType = { export const ProfileEditForm: React.FC = (props) => { const [form] = Form.useForm(); const userInfo = useUserStore().user; + const [previewUrl, setPreviewUrl] = useState(); + const avatarFileRef = useRef(null); - // 请求成功回调 + // 保存回调 const success = (res: any) => { if (res.err_code === 0) { notification.success({ message: '保存成功' }); @@ -27,28 +28,96 @@ export const ProfileEditForm: React.FC = (props) => { } }; - const { loading: editLoading, request: editRequest } = useRequest(AdminServices.profile, { onSuccess: success }); + const { loading: editLoading, request: editRequest } = useRequest(AdminServices.profile, { + onSuccess: success, + }); + // 保存方法 const save = async () => { try { - const values = await form.validateFields(); - editRequest(stringify(values)); + const values = await form.getFieldsValue(); + console.log('values', values); + // 使用 FormData + const formData = new FormData(); + + // 避免空密码提交 + if (values.password) { + formData.append('password', values.password); + } + + // 普通字段 + formData.append('nickname', values.nickname); + formData.append('mobile', values.mobile); + formData.append('email', values.email || ''); + + // 上传头像文件 + if (avatarFileRef.current) { + formData.append('avatar', avatarFileRef.current); + } + + //console.log('formData entries:'); + // formData.forEach((value, key) => { + // console.log(key, value); + // }); + //console.log('formData', formData); + // 调用 useRequest + editRequest(formData); } catch (error) { console.log('表单验证未通过', error); } }; useEffect(() => { + const uri = `${userInfo.avatar}?v=${encodeURIComponent(userInfo.update_date)}`; + console.log('uri', uri); form.setFieldsValue({ username: userInfo.username, mobile: userInfo.mobile, email: userInfo.email, nickname: userInfo.nickname, + avatar: uri, // 默认头像 }); + setPreviewUrl(userInfo.avatar); }, [userInfo]); return (
+ + { + // 如果有预览 URL,释放对象 + if (previewUrl) { + URL.revokeObjectURL(previewUrl); + } + + avatarFileRef.current = file; + const url = URL.createObjectURL(file); + + setPreviewUrl(url); + //src={`${previewUrl}?v=${encodeURIComponent(userInfo.update_date)}`} + + // 阻止自动上传 + return false; + }} + > +
+ avatar +
+
+
+ diff --git a/src/pages/Staff/dep/components/AdminDepEditModal.tsx b/src/pages/Staff/Dept/components/AdminDepEditModal.tsx similarity index 100% rename from src/pages/Staff/dep/components/AdminDepEditModal.tsx rename to src/pages/Staff/Dept/components/AdminDepEditModal.tsx diff --git a/src/pages/Staff/dep/components/AdminDepSelect.tsx b/src/pages/Staff/Dept/components/AdminDepSelect.tsx similarity index 100% rename from src/pages/Staff/dep/components/AdminDepSelect.tsx rename to src/pages/Staff/Dept/components/AdminDepSelect.tsx diff --git a/src/pages/Staff/dep/index.tsx b/src/pages/Staff/Dept/index.tsx similarity index 99% rename from src/pages/Staff/dep/index.tsx rename to src/pages/Staff/Dept/index.tsx index 31c4d10..f7b3589 100644 --- a/src/pages/Staff/dep/index.tsx +++ b/src/pages/Staff/Dept/index.tsx @@ -242,9 +242,9 @@ const DepListForm: React.FC = () => { ); }; -const Dep = () => ( +const Dept = () => ( ); -export default Dep; +export default Dept; diff --git a/src/pages/Staff/List/index.tsx b/src/pages/Staff/List/index.tsx index 907758b..2ba6d77 100644 --- a/src/pages/Staff/List/index.tsx +++ b/src/pages/Staff/List/index.tsx @@ -14,7 +14,7 @@ import { AdminServices } from '@/services/AdminServices'; import { useAuthStore } from '@/store/AuthStore'; import { tableFixedByPhone, toArray } from '@/utils/common'; import { useRequest } from '@/utils/useRequest'; -import AdminDepSelect from '../Dep/components/AdminDepSelect'; +import AdminDepSelect from '../Dept/components/AdminDepSelect'; import AdminGrpSelect from '../Grp/components/AdminGrpSelect'; import { AdminEditModal, type IAdminEditModalType } from './components/AdminEditModal'; diff --git a/src/store/type.ts b/src/store/type.ts index aacc4fe..20fff48 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -11,6 +11,7 @@ export type UserInfo = { wx_nick_name?: string; wx_open_id?: string; department_id?: number; + update_date?: any; }; export type CompanyInfo = { diff --git a/src/utils/common.ts b/src/utils/common.ts index dc2557f..6d8e51a 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -39,7 +39,7 @@ export const pathAddApiString = (path: string): string => { if (`${path}`.startsWith('/')) { return `/api/adminrelas${path}`; } - return `/api/adminrelas/${path}`; + return `/api/adminrelas${path}`; } return path; }; diff --git a/vite.config.ts b/vite.config.ts index a3e33ff..60fd220 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,7 +28,7 @@ export default defineConfig({ rewrite: (path) => path.replace(/^\/api/, ''), // 不可以省略rewrite }, '/static': { - target: 'http://192.168.1.138:83', + target: 'http://www.free.loc', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), // 不可以省略rewrite },