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

365 lines
13 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>
2026-01-04 14:55:31 +08:00
<!-- <Table
2025-11-25 15:15:38 +08:00
ref="tableRef"
:tree-config="{ transform: true, parentField: 'uPid', rowField: 'uId' }"
:scroll-y="{ enabled: true }"
2026-01-04 14:55:31 +08:00
/> -->
<el-tabs v-model="tableName" type="border-card" @tab-change="changeTab">
<el-tab-pane v-for="item in tableStore.table.data" :key="item.name" :label="item.name" :name="item.name">
2026-01-05 16:34:42 +08:00
<el-tabs v-model="tableName1" tab-position="left" class="componentList">
2026-01-04 14:55:31 +08:00
<el-tab-pane v-for="k in item?.children" :key="k.name" :label="k.name" :name="k.name">
<template #label>
<span class="custom-tabs-label">
2026-01-05 16:34:42 +08:00
<p>{{ k.name }}</p>
2026-01-04 14:55:31 +08:00
<!-- <el-icon><Edit /></el-icon> -->
<el-button
type="primary"
icon="el-icon-Edit"
link
class="ml10"
2026-01-05 16:34:42 +08:00
@click.stop="editTree(k, 0)"
2026-01-04 14:55:31 +08:00
></el-button>
<el-button
type="danger"
icon="el-icon-Delete"
link
class="ml0"
2026-01-05 16:34:42 +08:00
@click.stop="del(k)"
2026-01-04 14:55:31 +08:00
></el-button>
</span>
</template>
<div :style="height" style="overflow-y: auto; overflow-x: hidden">
<el-row :gutter="10" class="pl5 pr5 pt5">
<el-col :span="6" v-for="component in k.children" :key="component.id" class="mb10">
2026-01-05 16:34:42 +08:00
<el-card class="box-card" shadow="hover">
2026-01-04 14:55:31 +08:00
<div slot="header" class="clearfix">
<span style="display: flex; align-items: center">
{{ component.name }}
</span>
<div style="height: 32px">
<div style="display: flex; justify-content: end">
<el-button
icon="el-icon-Edit"
style="padding: 3px 0; color: blue"
type="text"
2026-01-05 16:34:42 +08:00
@click.stop="editTree(component, 1)"
2026-01-04 14:55:31 +08:00
>
编辑
</el-button>
<el-button
icon="el-icon-Delete"
style="padding: 3px 0; color: red"
type="text"
2026-01-05 16:34:42 +08:00
@click.stop="del(component)"
2026-01-04 14:55:31 +08:00
>
删除
</el-button>
</div>
</div>
</div>
<!-- <img v-if="component.image" :src="component.image" class="image xiaoshou" /> -->
<el-image
style="width: 100%; height: 180px"
:src="component.image"
:preview-src-list="[component.image]"
show-progress
:initial-index="4"
/>
</el-card>
</el-col>
</el-row>
</div>
</el-tab-pane>
</el-tabs>
</el-tab-pane>
</el-tabs>
2025-11-25 15:15:38 +08:00
<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'
2026-01-04 14:55:31 +08:00
import { ElMessage, ElMessageBox } from 'element-plus'
2025-10-13 16:14:03 +08:00
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'
2026-01-04 14:55:31 +08:00
import { Edit, Delete } from '@element-plus/icons-vue'
import { mainHeight } from '@/utils/layout'
2025-10-13 16:14:03 +08:00
defineOptions({
name: 'component'
})
const addRef = ref()
const addFlag = ref(false)
const tableRef = ref()
2026-01-04 14:55:31 +08:00
const height = ref(mainHeight(140))
2025-11-25 15:15:38 +08:00
const treeRef = ref()
2026-01-04 14:55:31 +08:00
const tableName = ref('')
const tableName1 = 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',
2026-01-04 14:55:31 +08:00
disabled: row => row.systemType == null,
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',
2026-01-04 14:55:31 +08:00
disabled: row => row.systemType == null,
2025-10-13 16:14:03 +08:00
popconfirm: {
confirmButtonText: '确认',
cancelButtonText: '取消',
confirmButtonType: 'danger',
title: '确定删除?'
},
click: row => {
2026-01-04 14:55:31 +08:00
deleteSubassembly({ id: row.id }).then(() => {
ElMessage.success('删除成功!')
tableStore.index()
})
2025-10-13 16:14:03 +08:00
}
}
]
}
],
loadCallback: () => {
addFlag.value = false
2026-01-04 14:55:31 +08:00
tableName.value = tableName.value == '' ? tableStore.table.data[0].name : tableName.value
tableName1.value = tableName1.value == '' ? tableStore.table.data[0].children[0].name : tableName1.value
// 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
2025-10-13 16:14:03 +08:00
}
})
2026-01-04 14:55:31 +08:00
const changeTab = (e: any) => {
console.log('🚀 ~ changeTab ~ e:', e)
tableName1.value = tableStore.table.data.filter(item => item.name == e)[0].children[0].name
}
2025-10-13 16:14:03 +08:00
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
}
2026-01-04 14:55:31 +08:00
// 修改
const editTree = (row: any, num: number) => {
addFlag.value = true
setTimeout(() => {
if (num == 0) {
treeRef.value?.open('修改树', row)
} else {
addRef.value?.open('修改组件', row)
}
}, 100)
}
// 删除
const del = (row: any) => {
ElMessageBox.confirm('确定删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteSubassembly({ id: row.id }).then(() => {
ElMessage.success('删除成功!')
tableStore.index()
})
})
.catch(() => {})
}
2025-10-13 16:14:03 +08:00
// 新增
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>
2026-01-04 14:55:31 +08:00
<style lang="scss" scoped>
.text {
font-size: 14px;
}
span {
font-size: 16px;
}
.item {
margin-bottom: 18px;
}
.image {
display: block;
width: 100%;
height: 180px;
}
.clearfix::before,
.clearfix::after {
display: table;
content: '';
}
.clearfix::after {
clear: both;
}
.box-card {
width: 100%;
// border: 1px solid #000;
box-shadow: var(--el-box-shadow-light);
}
.xiaoshou {
cursor: pointer;
}
.setstyle {
min-height: 200px;
padding: 0 !important;
margin: 0;
overflow: auto;
cursor: default !important;
}
.color {
color: var(--el-color-primary);
}
:deep(.el-select-dropdown__wrap) {
max-height: 300px;
}
:deep(.el-tree) {
padding-top: 15px;
padding-left: 10px;
// 不可全选样式
.el-tree-node {
.is-leaf + .el-checkbox .el-checkbox__inner {
display: inline-block;
}
.el-checkbox .el-checkbox__inner {
display: none;
}
}
}
:deep(.el-card__header) {
padding: 13px 20px;
height: 44px;
}
:deep(.el-card__body) {
padding: 10px;
}
.table-pagination {
height: 58px;
box-sizing: border-box;
width: 100%;
max-width: 100%;
background-color: var(--ba-bg-color-overlay);
padding: 13px 15px;
border-left: 1px solid #e4e7e9;
border-right: 1px solid #e4e7e9;
border-bottom: 1px solid #e4e7e9;
}
:deep(.el-pagination__sizes) {
.el-select {
min-width: 128px;
}
}
2026-01-05 16:34:42 +08:00
:deep(.componentList){
.el-tabs__header{
height: calc(100vh - 250px)!important;
}
}
2026-01-04 14:55:31 +08:00
</style>