feat: 添加字典详情
Some checks failed
coverage CI / build (push) Has been cancelled

This commit is contained in:
2025-09-24 15:28:36 +08:00
parent 9363dc0d6e
commit 34cd919441
7 changed files with 364 additions and 13 deletions

View File

@@ -4,8 +4,8 @@ NODE_ENV=development
VITE_DEV=true VITE_DEV=true
# 请求路径 # 请求路径
# VITE_BASE_URL='http://114.132.60.20:48080' VITE_BASE_URL='http://114.132.60.20:48080'
VITE_BASE_URL='http://192.168.1.114:48080' # 理君 # VITE_BASE_URL='http://192.168.1.114:48080' # 理君
# 文件上传类型server - 后端上传, client - 前端直连上传,仅支持 S3 服务 # 文件上传类型server - 后端上传, client - 前端直连上传,仅支持 S3 服务

View File

@@ -13,9 +13,9 @@ export default {
// 如果需要自定义本地开发服务器 请取消注释按需调整 // 如果需要自定义本地开发服务器 请取消注释按需调整
dev: { dev: {
// localhost:8000/api/** -> https://preview.pro.ant.design/api/** // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
"/admin-api/": { '/admin-api/': {
// 要代理的地址 // 要代理的地址
target: "http://192.168.1.114:48080", target: 'http://114.132.60.20:48080',
// 配置了这个可以从 http 代理到 https // 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie // 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true, changeOrigin: true,
@@ -27,17 +27,17 @@ export default {
*/ */
test: { test: {
// localhost:8000/api/** -> https://preview.pro.ant.design/api/** // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
"/api/": { '/api/': {
target: "https://proapi.azurewebsites.net", target: 'https://proapi.azurewebsites.net',
changeOrigin: true, changeOrigin: true,
pathRewrite: { "^": "" }, pathRewrite: { '^': '' },
}, },
}, },
pre: { pre: {
"/api/": { '/api/': {
target: "your pre url", target: 'your pre url',
changeOrigin: true, changeOrigin: true,
pathRewrite: { "^": "" }, pathRewrite: { '^': '' },
}, },
}, },
}; };

View File

@@ -13,6 +13,7 @@ export const baseDictTypeColumns: ProColumns<DictTypeVO>[] = [
dataIndex: 'id', dataIndex: 'id',
width: 80, width: 80,
align: 'left', align: 'left',
hideInSearch: true,
}, },
{ {
title: '字典名称', title: '字典名称',
@@ -41,6 +42,7 @@ export const baseDictTypeColumns: ProColumns<DictTypeVO>[] = [
title: '备注', title: '备注',
dataIndex: 'remark', dataIndex: 'remark',
width: 120, width: 120,
hideInSearch: true, // 在搜索表单中隐藏
}, },
{ {
title: '创建时间', title: '创建时间',
@@ -63,7 +65,7 @@ export const baseDictTypeColumns: ProColumns<DictTypeVO>[] = [
}, },
]; ];
export const formColumns = (_type: string): ProFormColumnsType[] => [ export const formColumns = (type: string): ProFormColumnsType[] => [
{ {
title: '字典名称', title: '字典名称',
dataIndex: 'name', dataIndex: 'name',
@@ -84,6 +86,9 @@ export const formColumns = (_type: string): ProFormColumnsType[] => [
title: '字典类型', title: '字典类型',
dataIndex: 'type', dataIndex: 'type',
valueType: 'text', valueType: 'text',
fieldProps: {
disabled: type === 'update',
},
colProps: { colProps: {
span: 12, span: 12,
}, },

View File

@@ -0,0 +1,189 @@
import type {
ProColumns,
ProFormColumnsType,
} from '@ant-design/pro-components';
import { Tag } from 'antd';
import dayjs from 'dayjs';
import { tenantStatus } from '@/constants';
import type { DictDataVO } from '@/services/system/dict/dict.data';
import { getStatusLabel } from '@/utils/constant';
export const baseDictDataColumns: ProColumns<DictDataVO>[] = [
{
title: '字典编码',
dataIndex: 'id',
width: 80,
hideInSearch: true,
},
{
title: '字典标签',
dataIndex: 'label',
width: 120,
},
{
title: '字典键值',
dataIndex: 'value',
width: 120,
},
{
title: '字典排序',
dataIndex: 'sort',
width: 80,
},
{
title: '状态',
dataIndex: 'status',
width: 80,
render: (_, record) => (
<Tag color={record.status === 1 ? 'red' : 'green'}>
{getStatusLabel(tenantStatus, record.status)}
</Tag>
),
},
{
title: '颜色类型',
dataIndex: 'colorType',
width: 80,
},
{
title: 'CSS Class',
dataIndex: 'cssClass',
width: 120,
},
{
title: '备注',
dataIndex: 'remark',
width: 120,
},
{
title: '创建时间',
dataIndex: 'createTime',
valueType: 'dateRange',
search: {
transform: (value) => {
return {
'createTime[0]': dayjs(value[0])
.startOf('day')
.format('YYYY-MM-DD HH:mm:ss'),
'createTime[1]': dayjs(value[1])
.endOf('day')
.format('YYYY-MM-DD HH:mm:ss'),
};
},
},
render: (_, record: DictDataVO) =>
dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
},
];
export const formColumns = (_type: string): ProFormColumnsType[] => [
{
title: '字典类型',
dataIndex: 'dictType',
fieldProps: {
disabled: true,
},
},
{
title: '字典标签',
dataIndex: 'label',
formItemProps: {
rules: [
{
required: true,
message: '请输入字典标签',
},
],
},
},
{
title: '字典键值',
dataIndex: 'value',
formItemProps: {
rules: [
{
required: true,
message: '请输入字典键值',
},
],
},
},
{
title: '显示排序',
dataIndex: 'sort',
valueType: 'digit',
fieldProps: {
min: 0,
max: 9999,
},
formItemProps: {
rules: [
{
required: true,
message: '请输入排序',
},
],
},
},
{
title: '状态',
dataIndex: 'status',
valueType: 'select',
fieldProps: {
options: [
{
label: '启用',
value: 1,
},
{
label: '禁用',
value: 0,
},
],
},
formItemProps: {
rules: [
{
required: true,
},
],
},
},
{
title: '颜色类型',
dataIndex: 'colorType',
valueType: 'select',
fieldProps: {
options: [
{
label: '默认(waiting)',
value: 'waiting',
},
{
label: '成功(success)',
value: 'success',
},
{
label: '信息(processing)',
value: 'processing',
},
{
label: '失败(error)',
value: 'error',
},
{
label: '警告(warning)',
value: 'warning',
},
],
},
},
{
title: 'CSS Class',
dataIndex: 'cssClass',
},
{
title: '备注',
dataIndex: 'remark',
},
];

View File

@@ -0,0 +1,139 @@
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { useParams } from '@umijs/max';
import { Popconfirm } from 'antd';
import React, { useCallback, useRef, useState } from 'react';
import ConfigurableDrawerForm, {
type ConfigurableDrawerFormRef,
} from '@/components/DrawerForm';
import EnhancedProTable from '@/components/EnhancedProTable';
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
import { formStatusType } from '@/constants';
import {
createDictData,
type DictDataVO,
deleteDictData,
getDictDataPage,
updateDictData,
} from '@/services/system/dict/dict.data';
import { baseDictDataColumns, formColumns } from './config';
const SyStemDictData = () => {
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
const tableRef = useRef<ActionType>(null);
const [type, setType] = useState<'create' | 'update'>('create');
const [id, setId] = useState<number>(0);
const routerParams = useParams();
console.log(routerParams);
const handleEdit = (record: DictDataVO) => {
setType('update');
setId(record.id);
configurableDrawerRef.current?.open(record);
};
const onFetch = async (params: { pageSize?: number; current?: number }) => {
const data = await getDictDataPage({
...params,
dictType: routerParams.type,
pageNo: params.current,
pageSize: params.pageSize,
});
return {
data: data.list,
success: true,
total: data.total,
};
};
const handleAdd = () => {
setType('create');
configurableDrawerRef.current?.open({
dictType: routerParams.type,
});
};
const handleSubmit = useCallback(
async (values: DictDataVO) => {
if (type === 'create') {
await createDictData(values);
} else {
await updateDictData({
...values,
id,
});
}
tableRef.current?.reload();
return true;
},
[type, id],
);
const toolbarActions: ToolbarAction[] = [
{
key: 'add',
label: '新建',
type: 'primary',
icon: <PlusOutlined />,
onClick: handleAdd,
},
];
const actionColumns: ProColumns<DictDataVO> = {
title: '操作',
dataIndex: 'option',
valueType: 'option',
fixed: 'right',
width: 120,
render: (
_text: React.ReactNode,
record: DictDataVO,
_: any,
action: any,
) => [
<a key="editable" onClick={() => handleEdit(record)}>
</a>,
<Popconfirm
title="是否删除?"
key="delete"
onConfirm={async () => {
await deleteDictData(record.id);
action?.reload();
}}
okText="是"
cancelText="否"
>
<a></a>
</Popconfirm>,
],
};
const columns = [...baseDictDataColumns, actionColumns];
return (
<>
<EnhancedProTable<DictDataVO>
ref={tableRef}
columns={columns}
request={onFetch}
toolbarActions={toolbarActions}
headerTitle="租户列表"
showIndex={false}
showSelection={false}
/>
<ConfigurableDrawerForm
ref={configurableDrawerRef}
title={formStatusType[type]}
columns={formColumns(type)}
onSubmit={handleSubmit}
/>
</>
);
};
export default SyStemDictData;

View File

@@ -1,5 +1,6 @@
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { history } from '@umijs/max';
import { Popconfirm } from 'antd'; import { Popconfirm } from 'antd';
import React, { useCallback, useRef, useState } from 'react'; import React, { useCallback, useRef, useState } from 'react';
import ConfigurableDrawerForm, { import ConfigurableDrawerForm, {
@@ -24,6 +25,8 @@ const SyStemDict = () => {
const [type, setType] = useState<'create' | 'update'>('create'); const [type, setType] = useState<'create' | 'update'>('create');
const [id, setId] = useState<number>(0); const [id, setId] = useState<number>(0);
//获取路由数据
const handleEdit = (record: DictTypeVO) => { const handleEdit = (record: DictTypeVO) => {
setType('update'); setType('update');
setId(record.id); setId(record.id);
@@ -102,6 +105,16 @@ const SyStemDict = () => {
> >
<a></a> <a></a>
</Popconfirm>, </Popconfirm>,
<a
key="data"
onClick={() =>
history.push({
pathname: '/system/dict/data/' + record.type,
})
}
>
</a>,
], ],
}; };

View File

@@ -1,7 +1,7 @@
import { request } from "@umijs/max"; import { request } from "@umijs/max";
export type DictDataVO = { export type DictDataVO = {
id: number | undefined; id: number;
sort: number | undefined; sort: number | undefined;
label: string; label: string;
value: string; value: string;
@@ -13,6 +13,11 @@ export type DictDataVO = {
createTime: Date; createTime: Date;
}; };
export interface DictDataReqVO extends PageParam {
dictType?: string;
createTime?: Date;
}
// 查询字典数据(精简)列表 // 查询字典数据(精简)列表
// export const getSimpleDictDataList = () => { // export const getSimpleDictDataList = () => {
// return request.get({ url: "/system/dict-data/simple-list" }); // return request.get({ url: "/system/dict-data/simple-list" });
@@ -29,7 +34,7 @@ export const getSimpleDictDataList = () => {
// return request.get({ url: "/system/dict-data/page", params }); // return request.get({ url: "/system/dict-data/page", params });
// }; // };
export const getDictDataPage = (params: PageParam) => { export const getDictDataPage = (params: DictDataReqVO) => {
return request("/system/dict-data/page", { return request("/system/dict-data/page", {
method: "GET", method: "GET",
params, params,