From 73ec26744d0024a133eecd3a287abeca120865c0 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 12 May 2025 00:15:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20ele=20=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-ele/src/views/system/dict/data.ts | 388 ++++++++++++++++++ apps/web-ele/src/views/system/dict/index.vue | 35 ++ .../views/system/dict/modules/data-form.vue | 98 +++++ .../views/system/dict/modules/data-grid.vue | 158 +++++++ .../views/system/dict/modules/type-form.vue | 88 ++++ .../views/system/dict/modules/type-grid.vue | 153 +++++++ 6 files changed, 920 insertions(+) create mode 100644 apps/web-ele/src/views/system/dict/data.ts create mode 100644 apps/web-ele/src/views/system/dict/index.vue create mode 100644 apps/web-ele/src/views/system/dict/modules/data-form.vue create mode 100644 apps/web-ele/src/views/system/dict/modules/data-grid.vue create mode 100644 apps/web-ele/src/views/system/dict/modules/type-form.vue create mode 100644 apps/web-ele/src/views/system/dict/modules/type-grid.vue diff --git a/apps/web-ele/src/views/system/dict/data.ts b/apps/web-ele/src/views/system/dict/data.ts new file mode 100644 index 000000000..48ab6c727 --- /dev/null +++ b/apps/web-ele/src/views/system/dict/data.ts @@ -0,0 +1,388 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { SystemDictDataApi } from '#/api/system/dict/data'; +import type { SystemDictTypeApi } from '#/api/system/dict/type'; + +import { useAccess } from '@vben/access'; + +import { z } from '#/adapter/form'; +import { getSimpleDictTypeList } from '#/api/system/dict/type'; +import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils'; + +const { hasAccessByCodes } = useAccess(); + +// ============================== 字典类型 ============================== + +/** 类型新增/修改的表单 */ +export function useTypeFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'name', + label: '字典名称', + component: 'Input', + componentProps: { + placeholder: '请输入字典名称', + }, + rules: 'required', + }, + { + fieldName: 'type', + label: '字典类型', + component: 'Input', + componentProps: (values) => { + return { + placeholder: '请输入字典类型', + disabled: !!values.id, + }; + }, + rules: 'required', + dependencies: { + triggerFields: [''], + }, + }, + { + fieldName: 'status', + label: '状态', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number().default(CommonStatusEnum.ENABLE), + }, + { + fieldName: 'remark', + label: '备注', + component: 'Textarea', + componentProps: { + placeholder: '请输入备注', + }, + }, + ]; +} + +/** 类型列表的搜索表单 */ +export function useTypeGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'name', + label: '字典名称', + component: 'Input', + componentProps: { + placeholder: '请输入字典名称', + clearable: true, + }, + }, + { + fieldName: 'status', + label: '状态', + component: 'Select', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + placeholder: '请选择状态', + clearable: true, + }, + }, + ]; +} + +/** 类型列表的字段 */ +export function useTypeGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '字典编号', + minWidth: 100, + }, + { + field: 'name', + title: '字典名称', + minWidth: 200, + }, + { + field: 'type', + title: '字典类型', + minWidth: 220, + }, + { + field: 'status', + title: '状态', + minWidth: 120, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + }, + { + field: 'remark', + title: '备注', + minWidth: 180, + }, + { + field: 'createTime', + title: '创建时间', + minWidth: 180, + formatter: 'formatDateTime', + }, + { + minWidth: 120, + title: '操作', + field: 'operation', + fixed: 'right', + align: 'center', + cellRender: { + attrs: { + nameField: 'type', + nameTitle: '字典类型', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['system:dict:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['system:dict:delete']), + }, + ], + }, + }, + ]; +} + +// ============================== 字典数据 ============================== + +// TODO @芋艿:后续针对 antd,增加 +/** + * 颜色选项 + */ +const colorOptions = [ + { value: '', label: '无' }, + { value: 'processing', label: '主要' }, + { value: 'success', label: '成功' }, + { value: 'default', label: '默认' }, + { value: 'warning', label: '警告' }, + { value: 'error', label: '危险' }, + { value: 'pink', label: 'pink' }, + { value: 'red', label: 'red' }, + { value: 'orange', label: 'orange' }, + { value: 'green', label: 'green' }, + { value: 'cyan', label: 'cyan' }, + { value: 'blue', label: 'blue' }, + { value: 'purple', label: 'purple' }, +]; + +/** 数据新增/修改的表单 */ +export function useDataFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'dictType', + label: '字典类型', + component: 'ApiSelect', + componentProps: (values) => { + return { + api: getSimpleDictTypeList, + placeholder: '请输入字典类型', + labelField: 'name', + valueField: 'type', + disabled: !!values.id, + }; + }, + rules: 'required', + dependencies: { + triggerFields: [''], + }, + }, + { + fieldName: 'label', + label: '数据标签', + component: 'Input', + componentProps: { + placeholder: '请输入数据标签', + }, + rules: 'required', + }, + { + fieldName: 'value', + label: '数据键值', + component: 'Input', + componentProps: { + placeholder: '请输入数据键值', + }, + rules: 'required', + }, + { + fieldName: 'sort', + label: '显示排序', + component: 'InputNumber', + componentProps: { + placeholder: '请输入显示排序', + }, + rules: 'required', + }, + { + fieldName: 'status', + label: '状态', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + placeholder: '请选择状态', + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number().default(CommonStatusEnum.ENABLE), + }, + { + fieldName: 'colorType', + label: '颜色类型', + component: 'Select', + componentProps: { + options: colorOptions, + placeholder: '请选择颜色类型', + }, + }, + { + fieldName: 'cssClass', + label: 'CSS Class', + component: 'Input', + componentProps: { + placeholder: '请输入 CSS Class', + }, + help: '输入 hex 模式的颜色, 例如 #108ee9', + }, + { + fieldName: 'remark', + label: '备注', + component: 'Textarea', + componentProps: { + placeholder: '请输入备注', + }, + }, + ]; +} + +/** 字典数据列表搜索表单 */ +export function useDataGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'label', + label: '字典标签', + component: 'Input', + componentProps: { + placeholder: '请输入字典标签', + clearable: true, + }, + }, + { + fieldName: 'status', + label: '状态', + component: 'Select', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + placeholder: '请选择状态', + clearable: true, + }, + }, + ]; +} + +/** + * 字典数据表格列 + */ +export function useDataGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '字典编码', + minWidth: 100, + }, + { + field: 'label', + title: '字典标签', + minWidth: 180, + }, + { + field: 'value', + title: '字典键值', + minWidth: 100, + }, + { + field: 'sort', + title: '字典排序', + minWidth: 100, + }, + { + field: 'status', + title: '状态', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + }, + { + field: 'colorType', + title: '颜色类型', + minWidth: 120, + }, + { + field: 'cssClass', + title: 'CSS Class', + minWidth: 120, + }, + { + title: '创建时间', + field: 'createTime', + minWidth: 180, + formatter: 'formatDateTime', + }, + { + minWidth: 120, + title: '操作', + field: 'operation', + fixed: 'right', + align: 'center', + cellRender: { + attrs: { + nameField: 'label', + nameTitle: '字典数据', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['system:dict:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['system:dict:delete']), + }, + ], + }, + }, + ]; +} diff --git a/apps/web-ele/src/views/system/dict/index.vue b/apps/web-ele/src/views/system/dict/index.vue new file mode 100644 index 000000000..a5d937c9e --- /dev/null +++ b/apps/web-ele/src/views/system/dict/index.vue @@ -0,0 +1,35 @@ + + + diff --git a/apps/web-ele/src/views/system/dict/modules/data-form.vue b/apps/web-ele/src/views/system/dict/modules/data-form.vue new file mode 100644 index 000000000..f625f338f --- /dev/null +++ b/apps/web-ele/src/views/system/dict/modules/data-form.vue @@ -0,0 +1,98 @@ + + + diff --git a/apps/web-ele/src/views/system/dict/modules/data-grid.vue b/apps/web-ele/src/views/system/dict/modules/data-grid.vue new file mode 100644 index 000000000..346928fc5 --- /dev/null +++ b/apps/web-ele/src/views/system/dict/modules/data-grid.vue @@ -0,0 +1,158 @@ + + + diff --git a/apps/web-ele/src/views/system/dict/modules/type-form.vue b/apps/web-ele/src/views/system/dict/modules/type-form.vue new file mode 100644 index 000000000..9f982e56e --- /dev/null +++ b/apps/web-ele/src/views/system/dict/modules/type-form.vue @@ -0,0 +1,88 @@ + + + diff --git a/apps/web-ele/src/views/system/dict/modules/type-grid.vue b/apps/web-ele/src/views/system/dict/modules/type-grid.vue new file mode 100644 index 000000000..662bc4072 --- /dev/null +++ b/apps/web-ele/src/views/system/dict/modules/type-grid.vue @@ -0,0 +1,153 @@ + + +