From aee7a3fd9b606070c98e21b270c42c4a50954905 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Thu, 24 Nov 2022 00:15:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AD=97=E5=85=B8=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: e071bde67c7c65152a1fda1607d1ad4846153404 --- src/views/system/dict/components/DictItem.vue | 163 ++++++++---------- src/views/system/dict/components/DictType.vue | 142 +++++++-------- 2 files changed, 138 insertions(+), 167 deletions(-) diff --git a/src/views/system/dict/components/DictItem.vue b/src/views/system/dict/components/DictItem.vue index fed33cac..5a9a2ad4 100644 --- a/src/views/system/dict/components/DictItem.vue +++ b/src/views/system/dict/components/DictItem.vue @@ -1,6 +1,6 @@ @@ -13,7 +13,7 @@ import { getDictItemData, saveDictItem, updateDictItem, - deleteDictItems, + deleteDictItems } from '@/api/dict'; import { Search, Plus, Edit, Refresh, Delete } from '@element-plus/icons-vue'; import { DictItem, DictItemForm, DictItemQuery } from '@/api/dict/types'; @@ -23,19 +23,19 @@ const props = defineProps({ type: String, default: () => { return ''; - }, + } }, typeName: { type: String, default: () => { return ''; - }, - }, + } + } }); watch( () => props.typeCode, - (value) => { + value => { state.queryParams.typeCode = value; state.formData.typeCode = value; handleQuery(); @@ -49,10 +49,6 @@ const state = reactive({ loading: true, // 选中ID数组 ids: [] as number[], - // 非单个禁用 - single: true, - // 非多个禁用 - multiple: true, total: 0, queryParams: { pageNum: 1, pageSize: 10 } as DictItemQuery, dictItemList: [] as DictItem[], @@ -61,40 +57,40 @@ const state = reactive({ typeCode: props.typeCode, typeName: props.typeName, status: 1, - sort: 1, + sort: 1 } as DictItemForm, rules: { name: [{ required: true, message: '请输入字典项名称', trigger: 'blur' }], - value: [{ required: true, message: '请输入字典项值', trigger: 'blur' }], + value: [{ required: true, message: '请输入字典项值', trigger: 'blur' }] }, localDictCode: props.typeCode, - localDictName: props.typeName, + localDictName: props.typeName }); const { loading, - multiple, + ids, queryParams, dictItemList, dialog, formData, rules, - total, + total } = toRefs(state); function handleQuery() { - if (state.queryParams.typeCode) { - state.loading = true; + if (queryParams.value.typeCode) { + loading.value = true; listDictItemPages(state.queryParams).then(({ data }) => { - state.dictItemList = data.list; - state.total = data.total; - state.loading = false; + dictItemList.value = data.list; + total.value = data.total; + loading.value = false; }); } else { - state.dictItemList = []; - state.total = 0; - state.queryParams.pageNum = 1; - state.loading = false; + dictItemList.value = []; + total.value = 0; + queryParams.value.pageNum = 1; + loading.value = false; } } @@ -105,8 +101,6 @@ function resetQuery() { function handleSelectionChange(selection: any) { state.ids = selection.map((item: any) => item.id); - state.single = selection.length !== 1; - state.multiple = !selection.length; } function handleAdd() { @@ -116,14 +110,14 @@ function handleAdd() { } state.dialog = { title: '添加字典数据项', - visible: true, + visible: true }; } function handleUpdate(row: any) { state.dialog = { title: '修改字典数据项', - visible: true, + visible: true }; const id = row.id || state.ids; getDictItemData(id).then(({ data }) => { @@ -162,7 +156,7 @@ function handleDelete(row: any) { ElMessageBox.confirm('确认删除已选中的数据项?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', - type: 'warning', + type: 'warning' }) .then(() => { deleteDictItems(ids).then(() => { @@ -182,24 +176,8 @@ onMounted(() => {
- - 新增 - 删除 - - - + + { - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + export default { - name: 'dictType', + name: 'dictType' }; @@ -8,20 +8,7 @@ export default {
- - 新增 - 删除 - - - - + 重置 + + + + + + + + + + - - - - - - - - + + + + - - - - - - + + item.id); - state.single = selection.length !== 1; - state.multiple = !selection.length; } function handleAdd() { state.dialog = { title: '添加字典', - visible: true, + visible: true }; } function handleUpdate(row: any) { state.dialog = { title: '修改字典', - visible: true, + visible: true }; const id = row.id || state.ids; getDictTypeForm(id).then(({ data }) => { @@ -233,9 +219,9 @@ function submitForm() { } function cancel() { - state.formData.id = undefined; + formData.value.id = undefined; dataFormRef.value.resetFields(); - state.dialog.visible = false; + dialog.value.visible = false; } function handleDelete(row: any) { @@ -243,7 +229,7 @@ function handleDelete(row: any) { ElMessageBox.confirm('确认删除已选中的数据项?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', - type: 'warning', + type: 'warning' }) .then(() => { deleteDictTypes(ids).then(() => {