diff --git a/src/pages/index/components/ChangePasswordModal.tsx b/src/pages/index/components/ChangePasswordModal.tsx new file mode 100644 index 0000000..88b0281 --- /dev/null +++ b/src/pages/index/components/ChangePasswordModal.tsx @@ -0,0 +1,85 @@ +import React, { useEffect } from 'react'; +import { Modal, Form, Input } from 'antd'; +// props: visible, onOk, onCancel +const ChangePasswordModal: React.FC<{ + visible: boolean; + onOk: (values: { userId: string; newPassword: string; confirmPassword: string }) => Promise; + onCancel: () => void; +}> = ({ visible, onOk, onCancel }) => { + const [form] = Form.useForm(); + + useEffect(() => { + const userinfo = JSON.parse(sessionStorage.getItem('Userinfo') ?? '{}'); + form.setFieldsValue({ + userId: userinfo.userId, + userName: userinfo.loginName + }) + + },[form]) + + const handleOk = async () => { + try { + const values = await form.validateFields(); + await onOk({ ...values }); + form.resetFields(); + } catch (err) {} + }; + + return ( + +
+ + + + + + + + + + + ({ + validator(_, value) { + if (!value || getFieldValue('newPassword') === value) return Promise.resolve(); + return Promise.reject('两次输入密码不一致'); + }, + }), + ]} + > + + +
+
+ ); +}; + +export default ChangePasswordModal; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 01dc4e8..6fe6b19 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,9 +1,12 @@ import React, { useEffect, useState } from 'react'; import { Card, Row, Col, Spin, message } from 'antd'; import { Column, Pie, Bar } from '@ant-design/charts'; -import { - getYearcountNum, - getAccessTypeCountNum, +import ChangePasswordModal from './components/ChangePasswordModal'; + +import { + changePasswordOnFirstLogin, + getYearcountNum, + getAccessTypeCountNum, getSupplierTypeCountNum, getAccessFlowCountNum, // 第四个接口 getSupplierAuditCountNum // 第五个接口 @@ -19,6 +22,39 @@ const HomeDashboard: React.FC = () => { const [supplierAuditData, setSupplierAuditData] = useState([]); const [loading, setLoading] = useState(false); + // ======= 新增部分:弹窗控制 ======= + const [showChangePwd, setShowChangePwd] = useState(false); + useEffect(() => { + // 检查 firstLogin + const userStr = sessionStorage.getItem('currentUser'); + if (userStr) { + try { + const userObj = JSON.parse(userStr); + if (userObj?.supplierUser?.firstLogin === 0) { + setShowChangePwd(true); + } + } catch (e) { } + } + }, []); + // 修改密码确认回调 + const handleChangePwd = async (values: { userId: string; newPassword: string; confirmPassword: string; }) => { + try { + await changePasswordOnFirstLogin({ ...values }); + message.success('密码修改成功,请重新登录'); + // 更新缓存 firstLogin=1 + const userStr = sessionStorage.getItem('currentUser'); + if (userStr) { + const userObj = JSON.parse(userStr); + if (userObj?.supplierUser) userObj.supplierUser.firstLogin = 1; + sessionStorage.setItem('currentUser', JSON.stringify(userObj)); + } + setShowChangePwd(false); + + } catch (e: any) { + message.error(e?.message || '修改密码失败'); + } + }; + useEffect(() => { setLoading(true); Promise.all([ @@ -40,18 +76,18 @@ const HomeDashboard: React.FC = () => { // 2. 准入类别统计 if (accessTypeRes.code === 200 && Array.isArray(accessTypeRes.data)) { - setAccessTypeData((accessTypeRes.data || []).map((item: AccessTypeItem) => ({ - type: item.accessTypeText, - count: Number(item.countNum), - }))); + setAccessTypeData((accessTypeRes.data || []).map((item: AccessTypeItem) => ({ + type: item.accessTypeText, + count: Number(item.countNum), + }))); } else message.error('获取准入类别统计失败'); // 3. 供应商身份类别统计 if (supplierTypeRes.code === 200 && Array.isArray(supplierTypeRes.data)) { - setSupplierTypeData((supplierTypeRes.data || []).map((item: SupplierTypeItem) => ({ - type: item.supplierTypeCn, - count: Number(item.countNum), - }))); + setSupplierTypeData((supplierTypeRes.data || []).map((item: SupplierTypeItem) => ({ + type: item.supplierTypeCn, + count: Number(item.countNum), + }))); } else message.error('获取身份类别统计失败'); // 4. 准入流程进度统计 @@ -156,37 +192,45 @@ const HomeDashboard: React.FC = () => { }; return ( - - - {/* 第一行:3图 */} - - - - - - - - - - - - - - - - {/* 第二行:2图 */} - - - - - - - - - - - - + <> + { }} + /> + + + {/* 第一行:3图 */} + + + + + + + + + + + + + + + + {/* 第二行:2图 */} + + + + + + + + + + + + + + ); }; diff --git a/src/pages/index/servers.ts b/src/pages/index/servers.ts index eefdd11..f85a889 100644 --- a/src/pages/index/servers.ts +++ b/src/pages/index/servers.ts @@ -1,5 +1,18 @@ import request from '@/utils/request'; +/** + * + * @param params + * @returns + * + */ +interface PasswordOnFirstLogin { + userId:string; + newPassword:string; + confirmPassword:string; +} +export const changePasswordOnFirstLogin = (data:PasswordOnFirstLogin) => request.post(`/v1/login/supplier/changePasswordOnFirstLogin`, { data}); + /** * * @param params