From 6e52f5ce9a4647f7e70d41527713b9b7652e5c36 Mon Sep 17 00:00:00 2001 From: lq1405 <2769838458@qq.com> Date: Wed, 21 May 2025 21:27:35 +0800 Subject: [PATCH] =?UTF-8?q?V=201.1.0=20=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BF=A1=E6=81=AF=20=E5=AE=8C=E5=96=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BF=A1=E6=81=AF=E5=BE=97=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.ts | 7 + package.json | 2 +- src/access.ts | 5 +- src/locales/zh-CN/menu.ts | 2 + src/pages/Options/AddModifyOption.tsx | 236 +++++++++++++ src/pages/Options/OptionsManagement.tsx | 443 ++++++++++++++++++++++++ src/pages/Other/DataInfo/index.tsx | 13 +- src/services/enum/optionEnum.ts | 37 ++ src/services/services/common.ts | 52 +++ src/services/typing/access.d.ts | 2 + src/services/typing/basic.d.ts | 12 + src/services/typing/options/option.d.ts | 13 +- 12 files changed, 810 insertions(+), 14 deletions(-) create mode 100644 src/pages/Options/AddModifyOption.tsx create mode 100644 src/pages/Options/OptionsManagement.tsx create mode 100644 src/services/typing/basic.d.ts diff --git a/config/routes.ts b/config/routes.ts index 0ce0ff4..c4de3af 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -83,6 +83,13 @@ export default [ } ] }, + { + path: '/optionManagement', + name: 'optionManagement', + icon: 'Product', + access: 'canOptionManagement', + component: './Options/OptionsManagement', + }, { path: '/roleManagement', name: 'roleManagement', diff --git a/package.json b/package.json index 6296c4c..5ef4d39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lms", - "version": "1.0.8", + "version": "1.1.0", "private": true, "description": "An out-of-box UI solution for enterprise applications", "scripts": { diff --git a/src/access.ts b/src/access.ts index 9a905c3..66e0a39 100644 --- a/src/access.ts +++ b/src/access.ts @@ -7,6 +7,7 @@ export default function access(initialState: { currentUser?: API.CurrentUser } | let access = { canPrompt: false, canRoleManagement: false, + canOptionManagement: false, canUserManagement: false, canEditUser: false, @@ -87,6 +88,7 @@ export default function access(initialState: { currentUser?: API.CurrentUser } | access = { ...access, canPrompt: true, + canOptionManagement : true, canUserManagement: true, canEditUser: true, @@ -121,7 +123,8 @@ export default function access(initialState: { currentUser?: API.CurrentUser } | ...access, canPrompt: true, canRoleManagement: true, - + canOptionManagement : true, + canUserManagement: true, canEditUser: true, canDeleteUser: true, diff --git a/src/locales/zh-CN/menu.ts b/src/locales/zh-CN/menu.ts index 6ea7047..3d9c920 100644 --- a/src/locales/zh-CN/menu.ts +++ b/src/locales/zh-CN/menu.ts @@ -13,6 +13,8 @@ export default { 'menu.roleManagement': '角色管理', + 'menu.optionManagement': '数据管理', + 'menu.userManagement': '用户管理', 'menu.machineManagement': '机器码管理', diff --git a/src/pages/Options/AddModifyOption.tsx b/src/pages/Options/AddModifyOption.tsx new file mode 100644 index 0000000..6f57ede --- /dev/null +++ b/src/pages/Options/AddModifyOption.tsx @@ -0,0 +1,236 @@ +import React, { useEffect, useState } from 'react'; +import { Form, Input, Button, Card, Select, message, Spin, FormInstance, SelectProps, Tag } from 'antd'; +import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons'; +import { useParams, history } from 'umi'; +import { PageContainer } from '@ant-design/pro-layout'; +import { useModel } from '@umijs/max'; +import { cusRequest } from '@/request'; +import { getOptionCategoryOptions, getOptionTypeOptions, OptionCategory, OptionType } from '@/services/enum/optionEnum'; +import { useSoftStore } from '@/store/software'; +import { OptionModel } from '@/services/typing/options/option'; +import { CheckJsonString } from '@/services/services/common'; +import { QueryRoleOption } from '@/services/services/role'; +import { isEmpty } from 'lodash'; + +const { TextArea } = Input; + +interface OptionParams { + optionKey?: string; + category?: OptionCategory; + setFormRef: (form: FormInstance) => void; + open: boolean; +} + +const AddModifyOption: React.FC = ({ optionKey, setFormRef, open, category }) => { + const { initialState } = useModel('@@initialState'); + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const [tip, setTip] = useState('加载数据中。。。'); + const [roleOptions, setRoleOptions] = useState([]); + const [messageApi, messageHolder] = message.useMessage(); + type TagRender = SelectProps['tagRender']; + const isEdit = !!optionKey; + + const tagRender: TagRender = (props) => { + const { label, value, closable, onClose } = props; + const onPreventMouseDown = (event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + }; + return ( + + {label} + + ); + }; + + + // 获取选项详情 + const fetchOptionDetail = async () => { + debugger; + if (isEmpty(optionKey)) return; + setLoading(true); + setTip('正在获取选项详情,请稍等。。。'); + try { + const res = await cusRequest(`/lms/Options/GetAllMessageOptionsByKey/${category}/${optionKey}`, { + method: 'GET', + }); + + if (res.code === 1) { + form.setFieldsValue(res.data); + } else { + messageApi.error(res.message || '获取选项详情失败'); + } + } catch (error) { + console.error('获取选项详情失败:', error); + messageApi.error('获取选项详情失败'); + } finally { + setLoading(false); + } + }; + + // 保存选项 + const handleSubmit = async (values: OptionModel.OptionsItem) => { + setLoading(true); + setTip('正在保存数据,请稍等。。。'); + try { + + // 判断类型和值 + if (values.type == OptionType.JSON) { + if (CheckJsonString(values.value) == false) { + messageApi.error("JSON格式不正确,请检查"); + return; + } + } + if (values.type == OptionType.Number) { + if (isNaN(Number(values.value))) { + messageApi.error("数字格式不正确,请检查"); + return; + } + } + if (values.type == OptionType.Boolean) { + if (values.value !== 'true' && values.value !== 'false') { + messageApi.error("布尔值格式不正确,请检查"); + return; + } + } + + let url = '/lms/Options/AddOptions'; + let method = 'POST'; + + if (isEdit) { + url = `/lms/Options/ModifyOptionsByKey/${optionKey}`; + method = 'POST'; + delete values.key; + } + debugger; + if (values.roleNames == null || values.roleNames == undefined) { + values.roleNames = []; + } + + const res = await cusRequest(url, { + method, + data: values, + }); + console.log(res); + + if (res.code == 1) { + messageApi.success(`${isEdit ? '修改' : '添加'}成功`); + } else { + messageApi.error(res.message || `${isEdit ? '修改' : '添加'}失败`); + } + } catch (error) { + console.error(`${isEdit ? '修改' : '添加'}选项失败:`, error); + messageApi.error(`${isEdit ? '修改' : '添加'}失败`); + } finally { + setLoading(false); + } + }; + + + // 获取选项列表 + const fetchOptions = async () => { + QueryRoleOption().then((res: string[]) => { + let temRoleNames = res.map((item) => { + return { + value: item, + } + }); + if (!initialState?.currentUser?.roleNames.includes("Super Admin")) { + temRoleNames = res.filter(item => item !== "Super Admin").map((item) => { + return { + value: item, + } + }); + } + console.log("temRoleNames", temRoleNames); + setRoleOptions(temRoleNames); + }).catch((error: any) => { + messageApi.error(error.message); + }) + }; + + // 组件加载时获取数据 + useEffect(() => { + fetchOptions(); + setFormRef(form); + debugger + if (isEdit) { + fetchOptionDetail(); + } + }, [optionKey, open, setFormRef]); + + return ( + + +
+ + + + + + +