Files
admin-govern/src/views/setting/dictionary/component/index.vue

159 lines
5.3 KiB
Vue
Raw Normal View History

2025-10-13 16:14:03 +08:00
<template>
<div class="default-main">
<TableHeader :showSearch="false">
<template v-slot:operation>
2025-11-25 15:15:38 +08:00
<el-button type="primary" @click="addTree" icon="el-icon-Plus">新增树</el-button>
<el-button type="primary" @click="add" icon="el-icon-Plus">新增组件</el-button>
2025-10-13 16:14:03 +08:00
</template>
</TableHeader>
2025-11-25 15:15:38 +08:00
<Table
ref="tableRef"
:tree-config="{ transform: true, parentField: 'uPid', rowField: 'uId' }"
:scroll-y="{ enabled: true }"
/>
<Add ref="addRef" v-if="addFlag" @cancel="cancel" @submit="tableStore.index()" />
<!-- 新增树 -->
<Tree ref="treeRef" v-if="addFlag" @cancel="cancel" @submit="tableStore.index()" />
2025-10-13 16:14:03 +08:00
</div>
</template>
<script setup lang="ts">
2025-11-25 15:15:38 +08:00
import { ref, onMounted, provide, nextTick } from 'vue'
2025-10-13 16:14:03 +08:00
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import { useDictData } from '@/stores/dictData'
import { ElMessage } from 'element-plus'
import TableHeader from '@/components/table/header/index.vue'
import Add from './add.vue'
2025-11-25 15:15:38 +08:00
import Tree from './addTree.vue'
2025-10-13 16:14:03 +08:00
import { deleteSubassembly } from '@/api/user-boot/dept'
defineOptions({
name: 'component'
})
const addRef = ref()
const addFlag = ref(false)
const tableRef = ref()
2025-11-25 15:15:38 +08:00
const treeRef = ref()
2025-10-13 16:14:03 +08:00
const treeData: any = ref([])
const tableStore = new TableStore({
url: '/user-boot/component/componentTree',
method: 'GET',
showPage: false,
column: [
{ field: 'name', title: '功能组件名称', align: 'left', treeNode: true },
{
title: '组件图标',
field: 'icon',
align: 'center',
width: '80',
render: 'icon'
},
2025-11-25 15:15:38 +08:00
{ field: 'code', title: '组件标识', minWidth: '100' },
2025-10-13 16:14:03 +08:00
{ field: 'path', title: '组件路径' },
{ field: 'image', title: '组件展示', render: 'image' },
{
title: '操作',
render: 'buttons',
width: '150',
2025-10-13 16:14:03 +08:00
buttons: [
{
name: 'edit',
title: '修改',
type: 'primary',
icon: 'el-icon-Plus',
render: 'basicButton',
2025-11-25 15:15:38 +08:00
2025-10-13 16:14:03 +08:00
click: row => {
addFlag.value = true
setTimeout(() => {
2025-11-25 15:15:38 +08:00
if (row.path == '' || row.path == null) {
// 修改树
treeRef.value.open('修改树', row)
} else {
// 组件修改
addRef.value.open('修改组件', row)
}
2025-10-13 16:14:03 +08:00
}, 100)
}
},
{
name: 'del',
text: '删除',
type: 'danger',
icon: 'el-icon-Delete',
render: 'confirmButton',
2025-11-25 15:15:38 +08:00
2025-10-13 16:14:03 +08:00
popconfirm: {
confirmButtonText: '确认',
cancelButtonText: '取消',
confirmButtonType: 'danger',
title: '确定删除?'
},
click: row => {
2025-11-25 15:15:38 +08:00
if (row.path == '' || row.path == null) {
} else {
deleteSubassembly({ id: row.id }).then(() => {
ElMessage.success('删除成功!')
tableStore.index()
})
}
2025-10-13 16:14:03 +08:00
}
}
]
}
],
loadCallback: () => {
addFlag.value = false
setTimeout(() => {
tableRef.value?.getRef()?.setAllTreeExpand(true)
}, 0)
tableStore.table.data.forEach((item: any) => {
2025-10-13 16:14:03 +08:00
item.state = 0
})
treeData.value = tree2List(tableStore.table.data, Math.random() * 1000)
tableStore.table.data = treeData.value
}
})
const tree2List = (list: any, id: any) => {
//存储结果的数组
let arr: any = []
// 遍历 tree 数组
list.forEach((item: any) => {
item.uPid = id
item.uId = Math.random() * 1000
// 判断item是否存在children
if (!item.children) return arr.push(item)
// 函数递归对children数组进行tree2List的转换
const children = tree2List(item.children, item.uId)
// 删除item的children属性
delete item.children
// 把item和children数组添加至结果数组
//..children: 意思是把children数组展开
arr.push(item, ...children)
})
// 返回结果数组
return arr
}
// 新增
const add = () => {
addFlag.value = true
setTimeout(() => {
addRef.value.open('新增组件')
}, 100)
}
2025-11-25 15:15:38 +08:00
// 新增数
const addTree = () => {
addFlag.value = true
setTimeout(() => {
treeRef.value.open('新增树')
}, 100)
}
const cancel = () => {
addFlag.value = false
}
2025-10-13 16:14:03 +08:00
provide('tableStore', tableStore)
onMounted(() => {
tableStore.index()
})
</script>