159 lines
5.3 KiB
Vue
159 lines
5.3 KiB
Vue
<template>
|
||
<div class="default-main">
|
||
<TableHeader :showSearch="false">
|
||
<template v-slot:operation>
|
||
<el-button type="primary" @click="addTree" icon="el-icon-Plus">新增树</el-button>
|
||
<el-button type="primary" @click="add" icon="el-icon-Plus">新增组件</el-button>
|
||
</template>
|
||
</TableHeader>
|
||
<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()" />
|
||
</div>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { ref, onMounted, provide, nextTick } from 'vue'
|
||
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'
|
||
import Tree from './addTree.vue'
|
||
import { deleteSubassembly } from '@/api/user-boot/dept'
|
||
defineOptions({
|
||
name: 'component'
|
||
})
|
||
const addRef = ref()
|
||
const addFlag = ref(false)
|
||
const tableRef = ref()
|
||
const treeRef = ref()
|
||
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'
|
||
},
|
||
{ field: 'code', title: '组件标识', minWidth: '100' },
|
||
{ field: 'path', title: '组件路径' },
|
||
{ field: 'image', title: '组件展示', render: 'image' },
|
||
{
|
||
title: '操作',
|
||
render: 'buttons',
|
||
width: '150',
|
||
buttons: [
|
||
{
|
||
name: 'edit',
|
||
title: '修改',
|
||
type: 'primary',
|
||
icon: 'el-icon-Plus',
|
||
render: 'basicButton',
|
||
|
||
click: row => {
|
||
addFlag.value = true
|
||
setTimeout(() => {
|
||
if (row.path == '' || row.path == null) {
|
||
// 修改树
|
||
treeRef.value.open('修改树', row)
|
||
} else {
|
||
// 组件修改
|
||
|
||
addRef.value.open('修改组件', row)
|
||
}
|
||
}, 100)
|
||
}
|
||
},
|
||
{
|
||
name: 'del',
|
||
text: '删除',
|
||
type: 'danger',
|
||
icon: 'el-icon-Delete',
|
||
render: 'confirmButton',
|
||
|
||
popconfirm: {
|
||
confirmButtonText: '确认',
|
||
cancelButtonText: '取消',
|
||
confirmButtonType: 'danger',
|
||
title: '确定删除?'
|
||
},
|
||
click: row => {
|
||
if (row.path == '' || row.path == null) {
|
||
} else {
|
||
deleteSubassembly({ id: row.id }).then(() => {
|
||
ElMessage.success('删除成功!')
|
||
tableStore.index()
|
||
})
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
],
|
||
loadCallback: () => {
|
||
addFlag.value = false
|
||
setTimeout(() => {
|
||
tableRef.value?.getRef()?.setAllTreeExpand(true)
|
||
}, 0)
|
||
tableStore.table.data.forEach((item: any) => {
|
||
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)
|
||
}
|
||
// 新增数
|
||
const addTree = () => {
|
||
addFlag.value = true
|
||
setTimeout(() => {
|
||
treeRef.value.open('新增树')
|
||
}, 100)
|
||
}
|
||
const cancel = () => {
|
||
addFlag.value = false
|
||
}
|
||
provide('tableStore', tableStore)
|
||
onMounted(() => {
|
||
tableStore.index()
|
||
})
|
||
</script>
|