|
@@ -1,8 +1,15 @@
|
|
|
<template>
|
|
|
<div class="__cus-manage_content">
|
|
|
<div class="__cus-manage_content-title"><SvgIcon class="flag" name="flag_1" color="var(--cus-main-color)"/>{{$route.meta.title}}</div>
|
|
|
+ <div class="buttons">
|
|
|
+ <CusButton type="main" title="新增字典" @click="onAddParent()"/>
|
|
|
+ <CusButton title="删除字典" style="margin-left: 10px" @click="onDelParent()"/>
|
|
|
+ <template v-if="state.tree.value?.id">
|
|
|
+ <CusButton type="main" title="新增字典项" style="margin-left: auto" @click="onAdd"/>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
<div class="__cus-manage_content-main" v-loading="state.query.loading">
|
|
|
- <div class="tree">
|
|
|
+ <div class="tree" v-loading="state.tree.loading">
|
|
|
<div class="tree-filter">
|
|
|
<el-input v-model="state.tree.filter"/>
|
|
|
</div>
|
|
@@ -14,6 +21,8 @@
|
|
|
:props="state.tree.defaultProps"
|
|
|
default-expand-all
|
|
|
:filter-node-method="filterNode"
|
|
|
+ @node-click="onTreeClick"
|
|
|
+ :highlight-current="true"
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -24,22 +33,22 @@
|
|
|
:no-page="true"
|
|
|
default-expand-all
|
|
|
>
|
|
|
- <template #labelType-column-value="{scope}">
|
|
|
- {{DictionaryStore.labelTypeMap.get(scope.row.labelType)}}
|
|
|
+ <template #dictState-column-value="{scope}">
|
|
|
+ <el-switch
|
|
|
+ v-model="scope.row.dictState"
|
|
|
+ active-value="0"
|
|
|
+ inactive-value="1"
|
|
|
+ @click="onChangeDictState(scope.row)"
|
|
|
+ />
|
|
|
</template>
|
|
|
<template #do-column-value="{scope}">
|
|
|
- <template v-if="scope.row.labelLevel == 2">
|
|
|
- <CusButton type="table-add" title="新增下级" @click="onAdd(scope.row)"/>
|
|
|
- </template>
|
|
|
- <template v-else>
|
|
|
- <CusButton type="table-edit" @click="onEdit(scope.row)"/>
|
|
|
- <CusButton type="table-del" @click="onDel(scope.row)"/>
|
|
|
- </template>
|
|
|
+ <CusButton type="table-edit" @click="onEdit(scope.row)"/>
|
|
|
+ <CusButton type="table-del" @click="onDel(scope.row)"/>
|
|
|
</template>
|
|
|
</CusTable>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <DetailCom v-model:show="state.detail.show" :transfer="state.detail.transfer" @refresh="initTree"/>
|
|
|
+ <DetailCom v-model:show="state.detail.show" :transfer="state.detail.transfer" @refresh="flag => flag ? initTree() : initDictList()"/>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -48,7 +57,7 @@ import {getCurrentInstance, onMounted, reactive, ref, watch} from "vue";
|
|
|
import DetailCom from './detail.vue'
|
|
|
import {useDictionaryStore} from "@/stores";
|
|
|
import {ElMessage, ElMessageBox} from "element-plus";
|
|
|
-import {sysLabelDelete, sysLabelGetAllSysLabels} from "@/api/modules/manage/type";
|
|
|
+import {dictDel, dictEdit, dictGetAllSysDictsByValue, dictList} from "@/api/modules/manage/dict";
|
|
|
|
|
|
const {proxy} = getCurrentInstance()
|
|
|
const DictionaryStore = useDictionaryStore()
|
|
@@ -56,13 +65,10 @@ const state: any = reactive({
|
|
|
query: {
|
|
|
loading: false,
|
|
|
tableHead: [
|
|
|
- {value: "labelName", label: "名称", align: 'left', headerAlign: 'left', minWidth: 400},
|
|
|
- {value: "labelType", label: "类型", width: 120},
|
|
|
- {value: "labelOrder", label: "排序", width: 120},
|
|
|
- {value: "indexNum", label: "索引数量", width: 120},
|
|
|
- {value: "createTime", label: "创建时间", width: 200},
|
|
|
- {value: "updateTime", label: "最后修改时间", width: 200},
|
|
|
- {value: "remark", label: "备注", width: 200},
|
|
|
+ {value: "dictLabel", label: "字典名称"},
|
|
|
+ {value: "dictValue", label: "字典值"},
|
|
|
+ {value: "dictState", label: "字典状态"},
|
|
|
+ {value: "sortCode", label: "排序"},
|
|
|
{value: "do", label: "操作", width: 220, fixed: 'right'},
|
|
|
],
|
|
|
result: {
|
|
@@ -78,75 +84,130 @@ const state: any = reactive({
|
|
|
transfer: {}
|
|
|
},
|
|
|
tree: {
|
|
|
+ value: '',
|
|
|
+ loading: false,
|
|
|
filter: '',
|
|
|
defaultProps: {
|
|
|
- children: 'children',
|
|
|
- label: 'label',
|
|
|
+ label: 'dictLabel',
|
|
|
+ vaue: 'dictValue',
|
|
|
},
|
|
|
options: []
|
|
|
}
|
|
|
})
|
|
|
const ref_tree = ref()
|
|
|
const initTree = () => {
|
|
|
- state.query.loading = true
|
|
|
- sysLabelGetAllSysLabels().then(res => {
|
|
|
+ state.tree.loading = true
|
|
|
+ dictList().then(res => {
|
|
|
if (res.code === 200) {
|
|
|
- state.query.result.data = res.data.map(v => ({...v, children: v.sysLabels}))
|
|
|
- state.query.loading = false
|
|
|
+ state.tree.options = res.data.filter(v => v.parentId == 0)
|
|
|
+ state.tree.loading = false
|
|
|
} else {
|
|
|
ElMessage.error(res.msg)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-const onAdd = (row) => {
|
|
|
+const onAddParent = () => {
|
|
|
+ state.detail.transfer = {
|
|
|
+ mode: 'parent',
|
|
|
+ }
|
|
|
+ state.detail.show = true
|
|
|
+}
|
|
|
+const onAdd = () => {
|
|
|
state.detail.transfer = {
|
|
|
mode: 'add',
|
|
|
- labelParentId: row.id,
|
|
|
- labelType: row.labelType
|
|
|
+ parentId: state.tree.value.id
|
|
|
}
|
|
|
state.detail.show = true
|
|
|
}
|
|
|
const onEdit = (row) => {
|
|
|
state.detail.transfer = {
|
|
|
mode: 'edit',
|
|
|
- id: row.id,
|
|
|
+ row: JSON.parse(JSON.stringify(row)),
|
|
|
}
|
|
|
state.detail.show = true
|
|
|
}
|
|
|
+const onDelParent = () => {
|
|
|
+ if (state.tree.value?.id) {
|
|
|
+ ElMessageBox.confirm(`请确认是否删除${state.tree.value.dictLabel}?`, "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning",
|
|
|
+ } as any).then(() => {
|
|
|
+ dictDel(state.tree.value.id).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ ElMessage.success('删除成功!')
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ }
|
|
|
+ initTree()
|
|
|
+ })
|
|
|
+ }).catch(() => {})
|
|
|
+ } else {
|
|
|
+ ElMessage.warning('请先选择字典!')
|
|
|
+ }
|
|
|
+}
|
|
|
const onDel = (row) => {
|
|
|
- ElMessageBox.confirm(`请确认是否删除${row.labelName}?`, "提示", {
|
|
|
+ ElMessageBox.confirm(`请确认是否删除${row.dictLabel}?`, "提示", {
|
|
|
confirmButtonText: "确定",
|
|
|
cancelButtonText: "取消",
|
|
|
type: "warning",
|
|
|
} as any).then(() => {
|
|
|
- state.loading = true
|
|
|
- sysLabelDelete(row.id).then(res => {
|
|
|
+ dictDel(row.id).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
ElMessage.success('删除成功!')
|
|
|
} else {
|
|
|
ElMessage.error(res.msg)
|
|
|
}
|
|
|
- initTree()
|
|
|
+ initDictList()
|
|
|
})
|
|
|
}).catch(() => {})
|
|
|
}
|
|
|
const filterNode = (value, data) => {
|
|
|
if (!value) return true
|
|
|
- return data.label.includes(value)
|
|
|
+ return data.dictLabel.includes(value)
|
|
|
}
|
|
|
watch(() => state.tree.filter, (n) => {
|
|
|
ref_tree.value?.filter(n)
|
|
|
})
|
|
|
-const initDictionary = () => {
|
|
|
- DictionaryStore.initDict('label_type')
|
|
|
+const onTreeClick = (row) => {
|
|
|
+ state.tree.value = row
|
|
|
+ initDictList()
|
|
|
+}
|
|
|
+const initDictList = () => {
|
|
|
+ if (state.tree.value?.dictValue) {
|
|
|
+ state.query.loading = true
|
|
|
+ dictGetAllSysDictsByValue(proxy.$util.formatGetParam({dictValue: state.tree.value.dictValue})).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ state.query.result.data = res.data
|
|
|
+ state.query.loading = false
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+const onChangeDictState = (row) => {
|
|
|
+ const p = JSON.parse(JSON.stringify(row))
|
|
|
+ dictEdit(p).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ ElMessage.success('修改成功!')
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ }
|
|
|
+ initDictList()
|
|
|
+ })
|
|
|
}
|
|
|
onMounted(() => {
|
|
|
- initDictionary()
|
|
|
initTree()
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
+.buttons {
|
|
|
+ width: 100%;
|
|
|
+ display: flex;
|
|
|
+ margin-bottom: 10px;
|
|
|
+}
|
|
|
.__cus-manage_content-main {
|
|
|
display: flex;
|
|
|
width: 100%;
|
|
@@ -154,6 +215,14 @@ onMounted(() => {
|
|
|
gap: 10px;
|
|
|
.tree {
|
|
|
width: 300px;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ .tree-filter {
|
|
|
+ }
|
|
|
+ .tree-main {
|
|
|
+ flex: 1;
|
|
|
+ overflow-y: auto;
|
|
|
+ }
|
|
|
}
|
|
|
.table {
|
|
|
overflow: hidden;
|