refactor: 字典界面优化
Former-commit-id: e071bde67c7c65152a1fda1607d1ad4846153404
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
name: 'dictItem',
|
name: 'dictItem'
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
getDictItemData,
|
getDictItemData,
|
||||||
saveDictItem,
|
saveDictItem,
|
||||||
updateDictItem,
|
updateDictItem,
|
||||||
deleteDictItems,
|
deleteDictItems
|
||||||
} from '@/api/dict';
|
} from '@/api/dict';
|
||||||
import { Search, Plus, Edit, Refresh, Delete } from '@element-plus/icons-vue';
|
import { Search, Plus, Edit, Refresh, Delete } from '@element-plus/icons-vue';
|
||||||
import { DictItem, DictItemForm, DictItemQuery } from '@/api/dict/types';
|
import { DictItem, DictItemForm, DictItemQuery } from '@/api/dict/types';
|
||||||
@@ -23,19 +23,19 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: () => {
|
default: () => {
|
||||||
return '';
|
return '';
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
typeName: {
|
typeName: {
|
||||||
type: String,
|
type: String,
|
||||||
default: () => {
|
default: () => {
|
||||||
return '';
|
return '';
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.typeCode,
|
() => props.typeCode,
|
||||||
(value) => {
|
value => {
|
||||||
state.queryParams.typeCode = value;
|
state.queryParams.typeCode = value;
|
||||||
state.formData.typeCode = value;
|
state.formData.typeCode = value;
|
||||||
handleQuery();
|
handleQuery();
|
||||||
@@ -49,10 +49,6 @@ const state = reactive({
|
|||||||
loading: true,
|
loading: true,
|
||||||
// 选中ID数组
|
// 选中ID数组
|
||||||
ids: [] as number[],
|
ids: [] as number[],
|
||||||
// 非单个禁用
|
|
||||||
single: true,
|
|
||||||
// 非多个禁用
|
|
||||||
multiple: true,
|
|
||||||
total: 0,
|
total: 0,
|
||||||
queryParams: { pageNum: 1, pageSize: 10 } as DictItemQuery,
|
queryParams: { pageNum: 1, pageSize: 10 } as DictItemQuery,
|
||||||
dictItemList: [] as DictItem[],
|
dictItemList: [] as DictItem[],
|
||||||
@@ -61,40 +57,40 @@ const state = reactive({
|
|||||||
typeCode: props.typeCode,
|
typeCode: props.typeCode,
|
||||||
typeName: props.typeName,
|
typeName: props.typeName,
|
||||||
status: 1,
|
status: 1,
|
||||||
sort: 1,
|
sort: 1
|
||||||
} as DictItemForm,
|
} as DictItemForm,
|
||||||
rules: {
|
rules: {
|
||||||
name: [{ required: true, message: '请输入字典项名称', trigger: 'blur' }],
|
name: [{ required: true, message: '请输入字典项名称', trigger: 'blur' }],
|
||||||
value: [{ required: true, message: '请输入字典项值', trigger: 'blur' }],
|
value: [{ required: true, message: '请输入字典项值', trigger: 'blur' }]
|
||||||
},
|
},
|
||||||
localDictCode: props.typeCode,
|
localDictCode: props.typeCode,
|
||||||
localDictName: props.typeName,
|
localDictName: props.typeName
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
loading,
|
loading,
|
||||||
multiple,
|
ids,
|
||||||
queryParams,
|
queryParams,
|
||||||
dictItemList,
|
dictItemList,
|
||||||
dialog,
|
dialog,
|
||||||
formData,
|
formData,
|
||||||
rules,
|
rules,
|
||||||
total,
|
total
|
||||||
} = toRefs(state);
|
} = toRefs(state);
|
||||||
|
|
||||||
function handleQuery() {
|
function handleQuery() {
|
||||||
if (state.queryParams.typeCode) {
|
if (queryParams.value.typeCode) {
|
||||||
state.loading = true;
|
loading.value = true;
|
||||||
listDictItemPages(state.queryParams).then(({ data }) => {
|
listDictItemPages(state.queryParams).then(({ data }) => {
|
||||||
state.dictItemList = data.list;
|
dictItemList.value = data.list;
|
||||||
state.total = data.total;
|
total.value = data.total;
|
||||||
state.loading = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
state.dictItemList = [];
|
dictItemList.value = [];
|
||||||
state.total = 0;
|
total.value = 0;
|
||||||
state.queryParams.pageNum = 1;
|
queryParams.value.pageNum = 1;
|
||||||
state.loading = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +101,6 @@ function resetQuery() {
|
|||||||
|
|
||||||
function handleSelectionChange(selection: any) {
|
function handleSelectionChange(selection: any) {
|
||||||
state.ids = selection.map((item: any) => item.id);
|
state.ids = selection.map((item: any) => item.id);
|
||||||
state.single = selection.length !== 1;
|
|
||||||
state.multiple = !selection.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
@@ -116,14 +110,14 @@ function handleAdd() {
|
|||||||
}
|
}
|
||||||
state.dialog = {
|
state.dialog = {
|
||||||
title: '添加字典数据项',
|
title: '添加字典数据项',
|
||||||
visible: true,
|
visible: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdate(row: any) {
|
function handleUpdate(row: any) {
|
||||||
state.dialog = {
|
state.dialog = {
|
||||||
title: '修改字典数据项',
|
title: '修改字典数据项',
|
||||||
visible: true,
|
visible: true
|
||||||
};
|
};
|
||||||
const id = row.id || state.ids;
|
const id = row.id || state.ids;
|
||||||
getDictItemData(id).then(({ data }) => {
|
getDictItemData(id).then(({ data }) => {
|
||||||
@@ -162,7 +156,7 @@ function handleDelete(row: any) {
|
|||||||
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
|
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning'
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
deleteDictItems(ids).then(() => {
|
deleteDictItems(ids).then(() => {
|
||||||
@@ -182,24 +176,8 @@ onMounted(() => {
|
|||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- 搜索表单 -->
|
<!-- 搜索表单 -->
|
||||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||||
<el-form-item>
|
<el-form-item label="关键字" prop="name">
|
||||||
<el-button type="success" :icon="Plus" @click="handleAdd"
|
<el-input v-model="queryParams.name" placeholder="数据标签" clearable />
|
||||||
>新增</el-button
|
|
||||||
>
|
|
||||||
<el-button
|
|
||||||
type="danger"
|
|
||||||
:icon="Delete"
|
|
||||||
:disabled="multiple"
|
|
||||||
@click="handleDelete"
|
|
||||||
>删除</el-button
|
|
||||||
>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item prop="name">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.name"
|
|
||||||
placeholder="数据项名称"
|
|
||||||
clearable
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" :icon="Search" @click="handleQuery"
|
<el-button type="primary" :icon="Search" @click="handleQuery"
|
||||||
@@ -209,6 +187,20 @@ onMounted(() => {
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
|
<el-card shadow="false">
|
||||||
|
<template #header>
|
||||||
|
<el-button type="success" :icon="Plus" @click="handleAdd"
|
||||||
|
>新增</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
:icon="Delete"
|
||||||
|
:disabled="ids.length === 0"
|
||||||
|
@click="handleDelete"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
|
||||||
<!-- 数据表格 -->
|
<!-- 数据表格 -->
|
||||||
<el-table
|
<el-table
|
||||||
:data="dictItemList"
|
:data="dictItemList"
|
||||||
@@ -216,9 +208,9 @@ onMounted(() => {
|
|||||||
border
|
border
|
||||||
@selection-change="handleSelectionChange"
|
@selection-change="handleSelectionChange"
|
||||||
>
|
>
|
||||||
<el-table-column type="selection" min-width="5%" />
|
<el-table-column type="selection" width="50" />
|
||||||
<el-table-column label="数据项名称" prop="name" />
|
<el-table-column label="数据标签" prop="name" />
|
||||||
<el-table-column label="数据项值" prop="value" />
|
<el-table-column label="数据值" prop="value" />
|
||||||
<el-table-column label="状态" align="center">
|
<el-table-column label="状态" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-tag v-if="scope.row.status === 1" type="success">启用</el-tag>
|
<el-tag v-if="scope.row.status === 1" type="success">启用</el-tag>
|
||||||
@@ -227,20 +219,12 @@ onMounted(() => {
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center">
|
<el-table-column label="操作" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button type="primary" link @click="handleUpdate(scope.row)"
|
||||||
type="primary"
|
>编辑</el-button
|
||||||
:icon="Edit"
|
>
|
||||||
circle
|
<el-button type="danger" link @click.stop="handleDelete(scope.row)"
|
||||||
plain
|
>删除</el-button
|
||||||
@click.stop="handleUpdate(scope.row)"
|
>
|
||||||
/>
|
|
||||||
<el-button
|
|
||||||
type="danger"
|
|
||||||
:icon="Delete"
|
|
||||||
circle
|
|
||||||
plain
|
|
||||||
@click.stop="handleDelete(scope.row)"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -252,6 +236,7 @@ onMounted(() => {
|
|||||||
v-model:limit="queryParams.pageSize"
|
v-model:limit="queryParams.pageSize"
|
||||||
@pagination="handleQuery"
|
@pagination="handleQuery"
|
||||||
/>
|
/>
|
||||||
|
</el-card>
|
||||||
|
|
||||||
<!-- 表单弹窗 -->
|
<!-- 表单弹窗 -->
|
||||||
<el-dialog
|
<el-dialog
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
name: 'dictType',
|
name: 'dictType'
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -8,20 +8,7 @@ export default {
|
|||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- 搜索表单 -->
|
<!-- 搜索表单 -->
|
||||||
<el-form ref="queryFormRef" :model="state.queryParams" :inline="true">
|
<el-form ref="queryFormRef" :model="state.queryParams" :inline="true">
|
||||||
<el-form-item>
|
<el-form-item label="关键字" prop="name">
|
||||||
<el-button type="success" :icon="Plus" @click="handleAdd"
|
|
||||||
>新增</el-button
|
|
||||||
>
|
|
||||||
<el-button
|
|
||||||
type="danger"
|
|
||||||
:icon="Delete"
|
|
||||||
:disabled="state.multiple"
|
|
||||||
@click="handleDelete"
|
|
||||||
>删除
|
|
||||||
</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item prop="name">
|
|
||||||
<el-input
|
<el-input
|
||||||
v-model="state.queryParams.name"
|
v-model="state.queryParams.name"
|
||||||
placeholder="字典名称"
|
placeholder="字典名称"
|
||||||
@@ -36,7 +23,19 @@ export default {
|
|||||||
<el-button :icon="Refresh" @click="resetQuery()">重置</el-button>
|
<el-button :icon="Refresh" @click="resetQuery()">重置</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
<el-card shadow="false">
|
||||||
|
<template #header>
|
||||||
|
<el-button type="success" :icon="Plus" @click="handleAdd"
|
||||||
|
>新增</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
:icon="Delete"
|
||||||
|
:disabled="ids.length === 0"
|
||||||
|
@click="handleDelete"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
|
</template>
|
||||||
<!-- 数据表格 -->
|
<!-- 数据表格 -->
|
||||||
<el-table
|
<el-table
|
||||||
highlight-current-row
|
highlight-current-row
|
||||||
@@ -58,20 +57,12 @@ export default {
|
|||||||
|
|
||||||
<el-table-column label="操作" align="center" width="150">
|
<el-table-column label="操作" align="center" width="150">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button type="primary" link @click.stop="handleUpdate(scope.row)"
|
||||||
type="primary"
|
>编辑</el-button
|
||||||
:icon="Edit"
|
>
|
||||||
circle
|
<el-button type="danger" link @click.stop="handleDelete(scope.row)"
|
||||||
plain
|
>删除</el-button
|
||||||
@click.stop="handleUpdate(scope.row)"
|
>
|
||||||
/>
|
|
||||||
<el-button
|
|
||||||
type="danger"
|
|
||||||
:icon="Delete"
|
|
||||||
circle
|
|
||||||
plain
|
|
||||||
@click.stop="handleDelete(scope.row)"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -83,6 +74,7 @@ export default {
|
|||||||
v-model:limit="queryParams.pageSize"
|
v-model:limit="queryParams.pageSize"
|
||||||
@pagination="handleQuery"
|
@pagination="handleQuery"
|
||||||
/>
|
/>
|
||||||
|
</el-card>
|
||||||
|
|
||||||
<!-- 弹窗表单 -->
|
<!-- 弹窗表单 -->
|
||||||
<el-dialog
|
<el-dialog
|
||||||
@@ -135,9 +127,9 @@ import {
|
|||||||
getDictTypeForm,
|
getDictTypeForm,
|
||||||
addDictType,
|
addDictType,
|
||||||
updateDictType,
|
updateDictType,
|
||||||
deleteDictTypes,
|
deleteDictTypes
|
||||||
} from '@/api/dict';
|
} from '@/api/dict';
|
||||||
import { Search, Plus, Edit, Refresh, Delete } from '@element-plus/icons-vue';
|
import { Search, Plus, Refresh, Delete } from '@element-plus/icons-vue';
|
||||||
import { ElForm, ElMessage, ElMessageBox } from 'element-plus';
|
import { ElForm, ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import { Dict, DictQuery, DictTypeForm } from '@/api/dict/types';
|
import { Dict, DictQuery, DictTypeForm } from '@/api/dict/types';
|
||||||
|
|
||||||
@@ -150,27 +142,23 @@ const state = reactive({
|
|||||||
loading: true,
|
loading: true,
|
||||||
// 选中ID数组
|
// 选中ID数组
|
||||||
ids: [] as number[],
|
ids: [] as number[],
|
||||||
// 非单个禁用
|
|
||||||
single: true,
|
|
||||||
// 非多个禁用
|
|
||||||
multiple: true,
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10
|
||||||
} as DictQuery,
|
} as DictQuery,
|
||||||
dictList: [] as Dict[],
|
dictList: [] as Dict[],
|
||||||
total: 0,
|
total: 0,
|
||||||
dialog: { visible: false } as DialogType,
|
dialog: { visible: false } as DialogType,
|
||||||
formData: {
|
formData: {
|
||||||
status: 1,
|
status: 1
|
||||||
} as DictTypeForm,
|
} as DictTypeForm,
|
||||||
rules: {
|
rules: {
|
||||||
name: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
|
name: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
|
||||||
code: [{ required: true, message: '请输入字典编码', trigger: 'blur' }],
|
code: [{ required: true, message: '请输入字典编码', trigger: 'blur' }]
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const { total, dialog, loading, dictList, formData, rules, queryParams } =
|
const { total, ids, dialog, loading, dictList, formData, rules, queryParams } =
|
||||||
toRefs(state);
|
toRefs(state);
|
||||||
|
|
||||||
function handleQuery() {
|
function handleQuery() {
|
||||||
@@ -190,21 +178,19 @@ function resetQuery() {
|
|||||||
|
|
||||||
function handleSelectionChange(selection: any) {
|
function handleSelectionChange(selection: any) {
|
||||||
state.ids = selection.map((item: any) => item.id);
|
state.ids = selection.map((item: any) => item.id);
|
||||||
state.single = selection.length !== 1;
|
|
||||||
state.multiple = !selection.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
state.dialog = {
|
state.dialog = {
|
||||||
title: '添加字典',
|
title: '添加字典',
|
||||||
visible: true,
|
visible: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdate(row: any) {
|
function handleUpdate(row: any) {
|
||||||
state.dialog = {
|
state.dialog = {
|
||||||
title: '修改字典',
|
title: '修改字典',
|
||||||
visible: true,
|
visible: true
|
||||||
};
|
};
|
||||||
const id = row.id || state.ids;
|
const id = row.id || state.ids;
|
||||||
getDictTypeForm(id).then(({ data }) => {
|
getDictTypeForm(id).then(({ data }) => {
|
||||||
@@ -233,9 +219,9 @@ function submitForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
state.formData.id = undefined;
|
formData.value.id = undefined;
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value.resetFields();
|
||||||
state.dialog.visible = false;
|
dialog.value.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDelete(row: any) {
|
function handleDelete(row: any) {
|
||||||
@@ -243,7 +229,7 @@ function handleDelete(row: any) {
|
|||||||
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
|
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning'
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
deleteDictTypes(ids).then(() => {
|
deleteDictTypes(ids).then(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user