Commit 3dd2203803053d1f0f5117cb01c9dd15ebd96729

Authored by xingyu4j
1 parent 7b2871ac

refactor: config vxe

yudao-ui-admin-vue3/src/api/infra/config/index.ts
1 1 import request from '@/config/axios'
2   -import type { ConfigVO } from './types'
  2 +
  3 +export type ConfigVO = {
  4 + id: number
  5 + group: string
  6 + name: string
  7 + key: string
  8 + value: string
  9 + type: string
  10 + visible: boolean
  11 + remark: string
  12 + createTime: string
  13 +}
  14 +export interface ConfigPageReqVO extends PageParam {
  15 + name?: string
  16 + type?: number
  17 + createTime?: string[]
  18 +}
  19 +
  20 +export interface ConfigExportReqVO {
  21 + name?: string
  22 + type?: number
  23 + createTime?: string[]
  24 +}
3 25  
4 26 // 查询参数列表
5   -export const getConfigPageApi = (params) => {
  27 +export const getConfigPageApi = (params: ConfigPageReqVO) => {
6 28 return request.get({ url: '/infra/config/page', params })
7 29 }
8 30  
... ... @@ -32,6 +54,6 @@ export const deleteConfigApi = (id: number) => {
32 54 }
33 55  
34 56 // 导出参数
35   -export const exportConfigApi = (params) => {
  57 +export const exportConfigApi = (params: ConfigExportReqVO) => {
36 58 return request.download({ url: '/infra/config/export', params })
37 59 }
... ...
yudao-ui-admin-vue3/src/api/infra/config/types.ts deleted
1   -export type ConfigVO = {
2   - id: number
3   - group: string
4   - name: string
5   - key: string
6   - value: string
7   - type: string
8   - visible: boolean
9   - remark: string
10   - createTime: string
11   -}
yudao-ui-admin-vue3/src/views/infra/config/config.data.ts
1 1 import { reactive } from 'vue'
2 2 import { useI18n } from '@/hooks/web/useI18n'
3 3 import { required } from '@/utils/formRules'
4   -import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
5 4 import { DICT_TYPE } from '@/utils/dict'
  5 +import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
6 6 const { t } = useI18n() // 国际化
7 7  
8 8 // 表单校验
... ... @@ -14,105 +14,81 @@ export const rules = reactive({
14 14 })
15 15  
16 16 // CrudSchema
17   -const crudSchemas = reactive<CrudSchema[]>([
18   - {
19   - label: t('common.index'),
20   - field: 'id',
21   - type: 'index',
22   - form: {
23   - show: false
  17 +const crudSchemas = reactive<VxeCrudSchema>({
  18 + primaryKey: 'id',
  19 + primaryType: 'seq',
  20 + action: true,
  21 + columns: [
  22 + {
  23 + title: '参数分类',
  24 + field: 'category'
24 25 },
25   - detail: {
26   - show: false
27   - }
28   - },
29   - {
30   - label: '参数分类',
31   - field: 'category'
32   - },
33   - {
34   - label: '参数名称',
35   - field: 'name',
36   - search: {
37   - show: true
38   - }
39   - },
40   - {
41   - label: '参数键名',
42   - field: 'key',
43   - search: {
44   - show: true
45   - }
46   - },
47   - {
48   - label: '参数键值',
49   - field: 'value'
50   - },
51   - {
52   - label: '系统内置',
53   - field: 'type',
54   - dictType: DICT_TYPE.INFRA_CONFIG_TYPE,
55   - dictClass: 'number',
56   - search: {
57   - show: true
58   - }
59   - },
60   - {
61   - label: '是否可见',
62   - field: 'visible',
63   - form: {
64   - component: 'RadioButton',
65   - componentProps: {
66   - options: [
67   - { label: '是', value: true },
68   - { label: '否', value: false }
69   - ]
70   - }
71   - }
72   - },
73   - {
74   - label: t('form.remark'),
75   - field: 'remark',
76   - form: {
77   - component: 'Input',
78   - componentProps: {
79   - type: 'textarea',
80   - rows: 4
  26 + {
  27 + title: '参数名称',
  28 + field: 'name',
  29 + isSearch: true
  30 + },
  31 + {
  32 + title: '参数键名',
  33 + field: 'key',
  34 + isSearch: true
  35 + },
  36 + {
  37 + title: '参数键值',
  38 + field: 'value'
  39 + },
  40 + {
  41 + title: '系统内置',
  42 + field: 'type',
  43 + dictType: DICT_TYPE.INFRA_CONFIG_TYPE,
  44 + dictClass: 'number',
  45 + isSearch: true
  46 + },
  47 + {
  48 + title: '是否可见',
  49 + field: 'visible',
  50 + table: {
  51 + slots: {
  52 + default: 'visible_default'
  53 + }
81 54 },
82   - colProps: {
83   - span: 24
  55 + form: {
  56 + component: 'RadioButton',
  57 + componentProps: {
  58 + options: [
  59 + { label: '是', value: true },
  60 + { label: '否', value: false }
  61 + ]
  62 + }
84 63 }
85 64 },
86   - table: {
87   - show: false
88   - }
89   - },
90   - {
91   - label: t('common.createTime'),
92   - field: 'createTime',
93   - form: {
94   - show: false
95   - },
96   - search: {
97   - show: true,
98   - component: 'DatePicker',
99   - componentProps: {
100   - type: 'datetimerange',
101   - valueFormat: 'YYYY-MM-DD HH:mm:ss',
102   - defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]
  65 + {
  66 + title: t('form.remark'),
  67 + field: 'remark',
  68 + isTable: false,
  69 + form: {
  70 + component: 'Input',
  71 + componentProps: {
  72 + type: 'textarea',
  73 + rows: 4
  74 + },
  75 + colProps: {
  76 + span: 24
  77 + }
103 78 }
104   - }
105   - },
106   - {
107   - label: t('table.action'),
108   - field: 'action',
109   - width: '240px',
110   - form: {
111   - show: false
112 79 },
113   - detail: {
114   - show: false
  80 + {
  81 + title: t('common.createTime'),
  82 + field: 'createTime',
  83 + formatter: 'formatDate',
  84 + isForm: false,
  85 + search: {
  86 + show: true,
  87 + itemRender: {
  88 + name: 'XDataTimePicker'
  89 + }
  90 + }
115 91 }
116   - }
117   -])
118   -export const { allSchemas } = useCrudSchemas(crudSchemas)
  92 + ]
  93 +})
  94 +export const { allSchemas } = useVxeCrudSchemas(crudSchemas)
... ...
yudao-ui-admin-vue3/src/views/infra/config/index.vue
1   -<script setup lang="ts">
2   -import { ref, unref } from 'vue'
3   -import dayjs from 'dayjs'
4   -import { ElMessage } from 'element-plus'
5   -import { DICT_TYPE } from '@/utils/dict'
6   -import { useTable } from '@/hooks/web/useTable'
7   -import { useI18n } from '@/hooks/web/useI18n'
8   -import { FormExpose } from '@/components/Form'
9   -import type { ConfigVO } from '@/api/infra/config/types'
10   -import { rules, allSchemas } from './config.data'
11   -import * as ConfigApi from '@/api/infra/config'
12   -const { t } = useI18n() // 国际化
13   -
14   -// ========== 列表相关 ==========
15   -const { register, tableObject, methods } = useTable<ConfigVO>({
16   - getListApi: ConfigApi.getConfigPageApi,
17   - delListApi: ConfigApi.deleteConfigApi,
18   - exportListApi: ConfigApi.exportConfigApi
19   -})
20   -const { getList, setSearchParams, delList, exportList } = methods
21   -
22   -// ========== CRUD 相关 ==========
23   -const actionLoading = ref(false) // 遮罩层
24   -const actionType = ref('') // 操作按钮的类型
25   -const dialogVisible = ref(false) // 是否显示弹出层
26   -const dialogTitle = ref('edit') // 弹出层标题
27   -const formRef = ref<FormExpose>() // 表单 Ref
28   -
29   -// 设置标题
30   -const setDialogTile = (type: string) => {
31   - dialogTitle.value = t('action.' + type)
32   - actionType.value = type
33   - dialogVisible.value = true
34   -}
35   -
36   -// 新增操作
37   -const handleCreate = () => {
38   - setDialogTile('create')
39   -}
40   -
41   -// 修改操作
42   -const handleUpdate = async (row: ConfigVO) => {
43   - setDialogTile('update')
44   - // 设置数据
45   - const res = await ConfigApi.getConfigApi(row.id)
46   - unref(formRef)?.setValues(res)
47   -}
48   -
49   -// 提交按钮
50   -const submitForm = async () => {
51   - const elForm = unref(formRef)?.getElFormRef()
52   - if (!elForm) return
53   - elForm.validate(async (valid) => {
54   - if (valid) {
55   - actionLoading.value = true
56   - // 提交请求
57   - try {
58   - const data = unref(formRef)?.formModel as ConfigVO
59   - if (actionType.value === 'create') {
60   - await ConfigApi.createConfigApi(data)
61   - ElMessage.success(t('common.createSuccess'))
62   - } else {
63   - await ConfigApi.updateConfigApi(data)
64   - ElMessage.success(t('common.updateSuccess'))
65   - }
66   - // 操作成功,重新加载列表
67   - dialogVisible.value = false
68   - await getList()
69   - } finally {
70   - actionLoading.value = false
71   - }
72   - }
73   - })
74   -}
75   -
76   -// ========== 详情相关 ==========
77   -const detailRef = ref() // 详情 Ref
78   -
79   -// 详情操作
80   -const handleDetail = async (row: ConfigVO) => {
81   - // 设置数据
82   - detailRef.value = row
83   - setDialogTile('detail')
84   -}
85   -
86   -// ========== 初始化 ==========
87   -getList()
88   -</script>
89   -
90 1 <template>
91   - <!-- 搜索工作区 -->
92 2 <ContentWrap>
93   - <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
94   - </ContentWrap>
95   - <ContentWrap>
96   - <!-- 操作工具栏 -->
97   - <div class="mb-10px">
98   - <el-button type="primary" v-hasPermi="['infra:config:create']" @click="handleCreate">
99   - <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
100   - </el-button>
101   - <el-button
102   - type="warning"
103   - v-hasPermi="['infra:config:export']"
104   - :loading="tableObject.exportLoading"
105   - @click="exportList('参数配置.xls')"
106   - >
107   - <Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
108   - </el-button>
109   - </div>
110 3 <!-- 列表 -->
111   - <Table
112   - :columns="allSchemas.tableColumns"
113   - :selection="false"
114   - :data="tableObject.tableList"
115   - :loading="tableObject.loading"
116   - :pagination="{
117   - total: tableObject.total
118   - }"
119   - v-model:pageSize="tableObject.pageSize"
120   - v-model:currentPage="tableObject.currentPage"
121   - @register="register"
122   - >
123   - <template #visible="{ row }">
124   - <span>{{ row.visible ? '是' : '否' }} </span>
125   - </template>
126   - <template #type="{ row }">
127   - <DictTag :type="DICT_TYPE.INFRA_CONFIG_TYPE" :value="row.type" />
  4 + <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  5 + <template #toolbar_buttons>
  6 + <!-- 操作:新增 -->
  7 + <XButton
  8 + type="primary"
  9 + preIcon="ep:zoom-in"
  10 + :title="t('action.add')"
  11 + v-hasPermi="['infra:config:create']"
  12 + @click="handleCreate()"
  13 + />
  14 + <!-- 操作:导出 -->
  15 + <XButton
  16 + type="warning"
  17 + preIcon="ep:download"
  18 + :title="t('action.export')"
  19 + v-hasPermi="['infra:config:export']"
  20 + @click="handleExport()"
  21 + />
128 22 </template>
129   - <template #createTime="{ row }">
130   - <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  23 + <template #visible_default="{ row }">
  24 + <span>{{ row.visible ? '是' : '否' }} </span>
131 25 </template>
132   - <template #action="{ row }">
  26 + <template #actionbtns_default="{ row }">
133 27 <el-button
134 28 link
135 29 type="primary"
136 30 v-hasPermi="['infra:config:update']"
137   - @click="handleUpdate(row)"
  31 + @click="handleUpdate(row.id)"
138 32 >
139 33 <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
140 34 </el-button>
... ... @@ -142,7 +36,7 @@ getList()
142 36 link
143 37 type="primary"
144 38 v-hasPermi="['infra:config:update']"
145   - @click="handleDetail(row)"
  39 + @click="handleDetail(row.id)"
146 40 >
147 41 <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
148 42 </el-button>
... ... @@ -150,12 +44,12 @@ getList()
150 44 link
151 45 type="primary"
152 46 v-hasPermi="['infra:config:delete']"
153   - @click="delList(row.id, false)"
  47 + @click="handleDelete(row.id)"
154 48 >
155 49 <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
156 50 </el-button>
157 51 </template>
158   - </Table>
  52 + </vxe-grid>
159 53 </ContentWrap>
160 54  
161 55 <XModal v-model="dialogVisible" :title="dialogTitle">
... ... @@ -170,7 +64,7 @@ getList()
170 64 <Descriptions
171 65 v-if="actionType === 'detail'"
172 66 :schema="allSchemas.detailSchema"
173   - :data="detailRef"
  67 + :data="detailData"
174 68 >
175 69 <template #visible="{ row }">
176 70 <span>{{ row.visible ? '是' : '否' }} </span>
... ... @@ -191,3 +85,99 @@ getList()
191 85 </template>
192 86 </XModal>
193 87 </template>
  88 +
  89 +<script setup lang="ts">
  90 +// 全局相关的 import
  91 +import { ref, unref } from 'vue'
  92 +import { useI18n } from '@/hooks/web/useI18n'
  93 +import { useMessage } from '@/hooks/web/useMessage'
  94 +import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  95 +import { VxeGridInstance } from 'vxe-table'
  96 +import { FormExpose } from '@/components/Form'
  97 +// 业务相关的 import
  98 +import * as ConfigApi from '@/api/infra/config'
  99 +import { rules, allSchemas } from './config.data'
  100 +
  101 +const { t } = useI18n() // 国际化
  102 +const message = useMessage() // 消息弹窗
  103 +// 列表相关的变量
  104 +const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  105 +const { gridOptions, getList, deleteData, exportList } = useVxeGrid<ConfigApi.ConfigVO>({
  106 + allSchemas: allSchemas,
  107 + getListApi: ConfigApi.getConfigPageApi,
  108 + deleteApi: ConfigApi.deleteConfigApi,
  109 + exportListApi: ConfigApi.exportConfigApi
  110 +})
  111 +
  112 +// ========== CRUD 相关 ==========
  113 +const actionLoading = ref(false) // 遮罩层
  114 +const actionType = ref('') // 操作按钮的类型
  115 +const dialogVisible = ref(false) // 是否显示弹出层
  116 +const dialogTitle = ref('edit') // 弹出层标题
  117 +const formRef = ref<FormExpose>() // 表单 Ref
  118 +const detailData = ref() // 详情 Ref
  119 +
  120 +// 设置标题
  121 +const setDialogTile = (type: string) => {
  122 + dialogTitle.value = t('action.' + type)
  123 + actionType.value = type
  124 + dialogVisible.value = true
  125 +}
  126 +
  127 +// 新增操作
  128 +const handleCreate = () => {
  129 + setDialogTile('create')
  130 +}
  131 +
  132 +// 导出操作
  133 +const handleExport = async () => {
  134 + await exportList(xGrid, '配置.xls')
  135 +}
  136 +
  137 +// 修改操作
  138 +const handleUpdate = async (rowId: number) => {
  139 + setDialogTile('update')
  140 + // 设置数据
  141 + const res = await ConfigApi.getConfigApi(rowId)
  142 + unref(formRef)?.setValues(res)
  143 +}
  144 +
  145 +// 详情操作
  146 +const handleDetail = async (rowId: number) => {
  147 + setDialogTile('detail')
  148 + const res = await ConfigApi.getConfigApi(rowId)
  149 + detailData.value = res
  150 +}
  151 +
  152 +// 删除操作
  153 +const handleDelete = async (rowId: number) => {
  154 + await deleteData(xGrid, rowId)
  155 +}
  156 +
  157 +// 提交按钮
  158 +const submitForm = async () => {
  159 + const elForm = unref(formRef)?.getElFormRef()
  160 + if (!elForm) return
  161 + elForm.validate(async (valid) => {
  162 + if (valid) {
  163 + actionLoading.value = true
  164 + // 提交请求
  165 + try {
  166 + const data = unref(formRef)?.formModel as ConfigApi.ConfigVO
  167 + if (actionType.value === 'create') {
  168 + await ConfigApi.createConfigApi(data)
  169 + message.success(t('common.createSuccess'))
  170 + } else {
  171 + await ConfigApi.updateConfigApi(data)
  172 + message.success(t('common.updateSuccess'))
  173 + }
  174 + dialogVisible.value = false
  175 + } finally {
  176 + actionLoading.value = false
  177 + // 刷新列表
  178 + await getList(xGrid)
  179 + }
  180 + }
  181 + })
  182 +}
  183 +</script>
... ...