|
@@ -11,28 +11,31 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <a-table :data="dataSource" row-key="typeKey" :columns="columns" :scroll="{ x: 'auto' }" :pagination="pageData"
|
|
|
- @page-change="evChangePage" @expanded-change="expandTableIds">
|
|
|
+ <a-table :data="dataSource" row-key="typeKey" :columns="columns" :scroll="{ x: 'auto' }" :pagination="false">
|
|
|
<template #operation="{ record }">
|
|
|
- <a class="a-link" href="javascript:;" style="margin: 0 1rem;" @click="dictShowModel(2, record)">修改</a>
|
|
|
+ <a class="a-link" href="javascript:;" style="margin: 0 0.4rem;" @click="dictShowModel(2, record)"
|
|
|
+ v-if="!record.typeKey">修改</a>
|
|
|
+ <a class="a-link" href="javascript:;" style="margin: 0 0.4rem;" @click="dictShowModel(3, record)"
|
|
|
+ v-if="record.typeKey">添加</a>
|
|
|
+
|
|
|
<a-popconfirm :content="`是否确认删除字典编号为 ${record.id} 的数据项?`" @ok="deleteChange(record.id)" type="warning">
|
|
|
- <a class="a-link" href="javascript:;" style="color: red;">删除</a>
|
|
|
+ <a class="a-link" href="javascript:;" style="color: red;margin: 0 0.4rem;">删除</a>
|
|
|
</a-popconfirm>
|
|
|
|
|
|
</template>
|
|
|
</a-table>
|
|
|
|
|
|
<!-- 弹框 -->
|
|
|
- <a-modal :title="typeCurrent == 1 ? '添加字典' : '修改字典'" v-model:visible="visible" @onCancel="resetForm" centered
|
|
|
+ <a-modal :title="typeCurrent !== 2 ? '添加字典' : '修改字典'" v-model:visible="visible" @onCancel="resetForm" centered
|
|
|
:maskClosable="false" :footer="null">
|
|
|
<a-form ref="formRef" :rules="rules" :model="formState" @submit="handleSubmit">
|
|
|
- <a-form-item label="字典名称" field="typeLabel">
|
|
|
+ <a-form-item label="标签名称" field="typeLabel" v-if="typeCurrent == 1">
|
|
|
<a-input v-model="formState.typeLabel" />
|
|
|
</a-form-item>
|
|
|
- <a-form-item label="字典类型" field="typeKey">
|
|
|
+ <a-form-item label="标签类型" field="typeKey" v-if="typeCurrent == 1">
|
|
|
<a-input v-model="formState.typeKey" />
|
|
|
</a-form-item>
|
|
|
- <a-form-item label="数据标签" field="label">
|
|
|
+ <a-form-item label="字典名称" field="label">
|
|
|
<a-input v-model="formState.label" />
|
|
|
</a-form-item>
|
|
|
<a-form-item label="数据键值" field="value">
|
|
@@ -51,7 +54,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { onMounted, ref, reactive } from "vue";
|
|
|
+import { onMounted, ref, reactive, h } from "vue";
|
|
|
import { dictionaryList, dictionaryAdd, dictionaryDelete, dictionaryUpdate, dictionaryDeleteAll } from '@/api/path/dict';
|
|
|
|
|
|
const visible = ref(false);
|
|
@@ -63,18 +66,10 @@ const formData = ref({
|
|
|
typeLabel: '',
|
|
|
});
|
|
|
const columns = ref([
|
|
|
-
|
|
|
- // {title: '数据标签', dataIndex: 'label', align: 'center', width: 120},
|
|
|
- { title: '字典名称', dataIndex: 'typeLabel', align: 'center', width: 120 },
|
|
|
- { title: '字典类型', dataIndex: 'typeKey', align: 'center', width: 150 },
|
|
|
+ { title: '标签名称', dataIndex: 'typeLabel', align: 'center', width: 120 },
|
|
|
+ { title: '标签类型', dataIndex: 'typeKey', align: 'center', width: 150 },
|
|
|
+ { title: '字典名称', dataIndex: 'label', align: 'center', width: 120 },
|
|
|
{ title: '数据键值', dataIndex: 'value', align: 'center', width: 120 },
|
|
|
- // {
|
|
|
- // title: '备注',
|
|
|
- // dataIndex: 'remark',
|
|
|
- // align: 'center',
|
|
|
- // width: 180
|
|
|
- // },
|
|
|
- // {title: '创建时间', dataIndex: 'created_at', align: 'center', width: 200},
|
|
|
{
|
|
|
title: '操作',
|
|
|
dataIndex: 'id',
|
|
@@ -113,11 +108,11 @@ const rules = {
|
|
|
};
|
|
|
|
|
|
const formState = reactive({
|
|
|
- // label: '',
|
|
|
+ label: '',
|
|
|
value: '',
|
|
|
typeKey: '',
|
|
|
typeLabel: '',
|
|
|
- // remark: '',
|
|
|
+ remark: '',
|
|
|
});
|
|
|
|
|
|
const pageData = ref({
|
|
@@ -135,12 +130,9 @@ const intData = async () => {
|
|
|
...formData.value
|
|
|
}
|
|
|
const res = await dictionaryList(param)
|
|
|
- dataSource.value = res.data.map(res => ({
|
|
|
- ...res,
|
|
|
- children: []
|
|
|
- }))
|
|
|
+ dataSource.value = res.data
|
|
|
pageData.value.total = res.total;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
// 提交
|
|
|
const handleSubmit = async ({ values, errors }) => {
|
|
@@ -150,9 +142,9 @@ const handleSubmit = async ({ values, errors }) => {
|
|
|
typeKey: formState.typeKey,
|
|
|
typeLabel: formState.typeLabel,
|
|
|
remark: formState.remark,
|
|
|
- id: typeCurrent.value == 1 ? undefined : dicId.value
|
|
|
+ id: typeCurrent.value !== 2 ? undefined : dicId.value
|
|
|
}
|
|
|
- let res = typeCurrent.value === 1 ? await dictionaryAdd(submitData) : await dictionaryUpdate(submitData)
|
|
|
+ let res = typeCurrent.value !== 2 ? await dictionaryAdd(submitData) : await dictionaryUpdate(submitData)
|
|
|
if (res.code === 200) {
|
|
|
intData();
|
|
|
resetForm();
|
|
@@ -169,14 +161,31 @@ const dictShowModel = (type, data) => {
|
|
|
typeCurrent.value = type;
|
|
|
visible.value = true;
|
|
|
if (type == 2) {
|
|
|
- dicId.value = data.id;
|
|
|
- formState.label = data.label;
|
|
|
- formState.value = data.value;
|
|
|
- formState.typeKey = data.typeKey;
|
|
|
- formState.typeLabel = data.typeLabel;
|
|
|
- formState.remark = data.remark;
|
|
|
+ dataSource.value.forEach(res => {
|
|
|
+ res.children.forEach(val => {
|
|
|
+ if (val.id == data.id) {
|
|
|
+ dicId.value = data.id
|
|
|
+ formState.typeKey = res.typeKey
|
|
|
+ formState.typeLabel = res.typeLabel
|
|
|
+ formState.remark = res.remark
|
|
|
+ formState.value = data.value
|
|
|
+ formState.label = data.label
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else if (type == 3) {
|
|
|
+ dataSource.value.forEach(res => {
|
|
|
+ res.children.forEach(val => {
|
|
|
+ if (val.id == data.id) {
|
|
|
+ formState.typeKey = res.typeKey
|
|
|
+ formState.typeLabel = res.typeLabel
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
// 取消
|
|
|
const resetForm = () => {
|
|
|
visible.value = false;
|
|
@@ -191,11 +200,6 @@ const resetForm = () => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-const evChangePage = (page) => {
|
|
|
- pageData.value.current = page
|
|
|
- intData()
|
|
|
-}
|
|
|
-
|
|
|
// 重置
|
|
|
const resetSelectData = () => {
|
|
|
formData.value.typeKey = "";
|
|
@@ -203,21 +207,6 @@ const resetSelectData = () => {
|
|
|
intData();
|
|
|
}
|
|
|
|
|
|
-const expandTableIds = async (e) => {
|
|
|
- if (e.length === 0) return
|
|
|
- let res = await dictionaryDeleteAll({ typeKey: e[0] });
|
|
|
- if (res.code === 200) {
|
|
|
- dataSource.value.forEach((item) => {
|
|
|
- // 检查 item.typeKey 是否包含 e 中的任意一个值
|
|
|
- if (e.some((key) => item.typeKey.includes(key))) {
|
|
|
- // 判断 children 是否为空,为空则添加数据
|
|
|
- if (item.children.length === 0) {
|
|
|
- item.children = [...res.data];
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-};
|
|
|
|
|
|
|
|
|
onMounted(() => {
|