mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-10 08:57:10 +08:00
refactor: 重构字典管理(左树右表)
This commit is contained in:
@@ -4,8 +4,8 @@ import http from '@/utils/http'
|
|||||||
const BASE_URL = '/system/dict'
|
const BASE_URL = '/system/dict'
|
||||||
|
|
||||||
/** @desc 查询字典列表 */
|
/** @desc 查询字典列表 */
|
||||||
export function listDict(query: System.DictPageQuery) {
|
export function listDict(query: System.DictQuery) {
|
||||||
return http.get<PageRes<System.DictResp[]>>(`${BASE_URL}`, query)
|
return http.get<System.DictResp[]>(`${BASE_URL}/list`, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @desc 查询字典详情 */
|
/** @desc 查询字典详情 */
|
||||||
|
@@ -146,9 +146,6 @@ export interface DictQuery {
|
|||||||
sort: Array<string>
|
sort: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DictPageQuery extends DictQuery, PageQuery {
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DictItemResp = {
|
export type DictItemResp = {
|
||||||
id: string
|
id: string
|
||||||
label: string
|
label: string
|
||||||
|
@@ -1,59 +1,70 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="table-page">
|
<div class="table-page">
|
||||||
<GiTable
|
<a-row justify="space-between" align="center" class="header">
|
||||||
row-key="id"
|
<a-space wrap>
|
||||||
title="字典管理"
|
<slot name="custom-title">
|
||||||
:data="dataList"
|
<div class="title">字典管理</div>
|
||||||
:columns="columns"
|
</slot>
|
||||||
:loading="loading"
|
</a-space>
|
||||||
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
|
</a-row>
|
||||||
:pagination="pagination"
|
<a-row align="stretch" :gutter="14" class="pane">
|
||||||
:disabled-tools="['size']"
|
<a-col :xs="0" :sm="8" :md="7" :lg="6" :xl="5" :xxl="4" flex="260px" class="h-full ov-hidden">
|
||||||
:disabled-column-keys="['name']"
|
<DictTree placeholder="请输入关键词" @node-click="handleSelectDict" />
|
||||||
@refresh="search"
|
</a-col>
|
||||||
>
|
<a-col :xs="24" :sm="16" :md="17" :lg="18" :xl="19" :xxl="20" flex="1" class="h-full ov-hidden">
|
||||||
<template #custom-left>
|
<GiTable
|
||||||
<a-input v-model="queryForm.description" placeholder="请输入关键词" allow-clear @change="search">
|
row-key="id"
|
||||||
<template #prefix><icon-search /></template>
|
:data="dataList"
|
||||||
</a-input>
|
:columns="columns"
|
||||||
<a-button @click="reset">重置</a-button>
|
:loading="loading"
|
||||||
</template>
|
:scroll="{ x: '100%', y: '100%', minWidth: 600 }"
|
||||||
<template #custom-right>
|
:pagination="pagination"
|
||||||
<a-button v-permission="['system:dict:add']" type="primary" @click="onAdd">
|
:disabled-tools="['size']"
|
||||||
<template #icon><icon-plus /></template>
|
:disabled-column-keys="['label']"
|
||||||
<span>新增</span>
|
@refresh="search"
|
||||||
</a-button>
|
>
|
||||||
</template>
|
<template #custom-left>
|
||||||
<template #isSystem="{ record }">
|
<a-input v-model="queryForm.description" placeholder="请输入关键词" allow-clear @change="search">
|
||||||
<a-tag v-if="record.isSystem" color="red">是</a-tag>
|
<template #prefix><icon-search /></template>
|
||||||
<a-tag v-else color="arcoblue">否</a-tag>
|
</a-input>
|
||||||
</template>
|
<a-button @click="reset">重置</a-button>
|
||||||
<template #action="{ record }">
|
</template>
|
||||||
<a-space>
|
<template #custom-right>
|
||||||
<a-link @click="onViewDictItem(record)">管理</a-link>
|
<a-button v-permission="['system:dict:item:add']" type="primary" @click="onAdd">
|
||||||
<a-link v-permission="['system:dict:update']" @click="onUpdate(record)">修改</a-link>
|
<template #icon><icon-plus /></template>
|
||||||
<a-link
|
<span>新增</span>
|
||||||
v-permission="['system:dict:delete']"
|
</a-button>
|
||||||
status="danger"
|
</template>
|
||||||
:title="record.isSystem ? '系统内置数据不能删除' : '删除'"
|
<template #label="{ record }">
|
||||||
:disabled="record.disabled"
|
<a-tag :color="record.color">{{ record.label }}</a-tag>
|
||||||
@click="onDelete(record)"
|
</template>
|
||||||
>
|
<template #status="{ record }">
|
||||||
删除
|
<GiCellStatus :status="record.status" />
|
||||||
</a-link>
|
</template>
|
||||||
</a-space>
|
<template #action="{ record }">
|
||||||
</template>
|
<a-space>
|
||||||
</GiTable>
|
<a-link v-permission="['system:dict:item:update']" @click="onUpdate(record)">修改</a-link>
|
||||||
|
<a-link
|
||||||
|
v-permission="['system:dict:item:delete']"
|
||||||
|
status="danger"
|
||||||
|
@click="onDelete(record)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</a-link>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
|
</GiTable>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
|
||||||
<DictAddModal ref="DictAddModalRef" @save-success="search" />
|
<DictItemAddModal ref="DictItemAddModalRef" @save-success="search" />
|
||||||
<DictItemModal ref="DictItemModalRef" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DictAddModal from './DictAddModal.vue'
|
import DictTree from './tree/index.vue'
|
||||||
import { type DictQuery, type DictResp, deleteDict, listDict } from '@/apis'
|
import DictItemAddModal from './DictItemAddModal.vue'
|
||||||
import DictItemModal from '@/views/system/dict/item/index.vue'
|
import { type DictItemQuery, type DictItemResp, deleteDictItem, listDictItem } from '@/apis'
|
||||||
import type { TableInstanceColumns } from '@/components/GiTable/type'
|
import type { TableInstanceColumns } from '@/components/GiTable/type'
|
||||||
import { useTable } from '@/hooks'
|
import { useTable } from '@/hooks'
|
||||||
import { isMobile } from '@/utils'
|
import { isMobile } from '@/utils'
|
||||||
@@ -61,7 +72,8 @@ import has from '@/utils/has'
|
|||||||
|
|
||||||
defineOptions({ name: 'SystemDict' })
|
defineOptions({ name: 'SystemDict' })
|
||||||
|
|
||||||
const queryForm = reactive<DictQuery>({
|
const queryForm = reactive<DictItemQuery>({
|
||||||
|
dictId: '',
|
||||||
sort: ['createTime,desc']
|
sort: ['createTime,desc']
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -71,7 +83,7 @@ const {
|
|||||||
pagination,
|
pagination,
|
||||||
search,
|
search,
|
||||||
handleDelete
|
handleDelete
|
||||||
} = useTable((page) => listDict({ ...queryForm, ...page }), { immediate: true })
|
} = useTable((page) => listDictItem({ ...queryForm, ...page }), { immediate: true })
|
||||||
|
|
||||||
const columns: TableInstanceColumns[] = [
|
const columns: TableInstanceColumns[] = [
|
||||||
{
|
{
|
||||||
@@ -80,50 +92,60 @@ const columns: TableInstanceColumns[] = [
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize)
|
render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize)
|
||||||
},
|
},
|
||||||
{ title: '名称', dataIndex: 'name', ellipsis: true, tooltip: true },
|
{ title: '标签', dataIndex: 'label', slotName: 'label', width: 100, align: 'center' },
|
||||||
{ title: '编码', dataIndex: 'code', width: 170, ellipsis: true, tooltip: true },
|
{ title: '值', dataIndex: 'value', width: 100, align: 'center', ellipsis: true, tooltip: true },
|
||||||
{ title: '系统内置', slotName: 'isSystem', align: 'center', show: false },
|
{ title: '状态', slotName: 'status', width: 90, align: 'center' },
|
||||||
{ title: '描述', dataIndex: 'description', ellipsis: true, tooltip: true },
|
{
|
||||||
{ title: '创建人', dataIndex: 'createUserString', ellipsis: true, tooltip: true, show: false },
|
title: '排序',
|
||||||
|
dataIndex: 'sort',
|
||||||
|
width: 90,
|
||||||
|
align: 'center',
|
||||||
|
sortable: {
|
||||||
|
sortDirections: ['ascend', 'descend']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ title: '描述', dataIndex: 'description', width: 130, ellipsis: true, tooltip: true },
|
||||||
|
{ title: '创建人', dataIndex: 'createUserString', width: 140, ellipsis: true, tooltip: true, show: false },
|
||||||
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
|
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
|
||||||
{ title: '修改人', dataIndex: 'updateUserString', ellipsis: true, tooltip: true, show: false },
|
{ title: '修改人', dataIndex: 'updateUserString', width: 140, ellipsis: true, tooltip: true, show: false },
|
||||||
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
|
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
slotName: 'action',
|
slotName: 'action',
|
||||||
width: 180,
|
width: 130,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
fixed: !isMobile() ? 'right' : undefined,
|
fixed: !isMobile() ? 'right' : undefined,
|
||||||
show: has.hasPermOr(['system:dict:update', 'system:dict:delete'])
|
show: has.hasPermOr(['system:dict:item:update', 'system:dict:item:delete'])
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
// 重置
|
// 重置
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
queryForm.description = undefined
|
queryForm.description = undefined
|
||||||
|
queryForm.status = undefined
|
||||||
search()
|
search()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const onDelete = (item: DictResp) => {
|
const onDelete = (item: DictItemResp) => {
|
||||||
return handleDelete(() => deleteDict(item.id), { content: `是否确定删除字典 [${item.name}]?`, showModal: true })
|
return handleDelete(() => deleteDictItem(item.id), { content: `是否确定删除 [${item.label}]?`, showModal: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const DictAddModalRef = ref<InstanceType<typeof DictAddModal>>()
|
// 根据选中字典查询
|
||||||
|
const handleSelectDict = (keys: Array<any>) => {
|
||||||
|
queryForm.dictId = keys.length === 1 ? keys[0] : undefined
|
||||||
|
search()
|
||||||
|
}
|
||||||
|
|
||||||
|
const DictItemAddModalRef = ref<InstanceType<typeof DictItemAddModal>>()
|
||||||
// 新增
|
// 新增
|
||||||
const onAdd = () => {
|
const onAdd = () => {
|
||||||
DictAddModalRef.value?.onAdd()
|
DictItemAddModalRef.value?.onAdd(queryForm.dictId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改
|
// 修改
|
||||||
const onUpdate = (item: DictResp) => {
|
const onUpdate = (item: DictItemResp) => {
|
||||||
DictAddModalRef.value?.onUpdate(item.id)
|
DictItemAddModalRef.value?.onUpdate(item.id)
|
||||||
}
|
|
||||||
|
|
||||||
const DictItemModalRef = ref<InstanceType<typeof DictItemModal>>()
|
|
||||||
// 查看字典项
|
|
||||||
const onViewDictItem = (item: DictResp) => {
|
|
||||||
DictItemModalRef.value?.open(item.id, item.code)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@@ -1,156 +0,0 @@
|
|||||||
<template>
|
|
||||||
<a-modal
|
|
||||||
v-model:visible="visible"
|
|
||||||
:title="`字典项管理(${dictCode})`"
|
|
||||||
title-align="start"
|
|
||||||
:mask-closable="false"
|
|
||||||
:esc-to-close="false"
|
|
||||||
:modal-style="{ maxWidth: '780px' }"
|
|
||||||
:width="width >= 600 ? '90%' : '100%'"
|
|
||||||
ok-text="关闭"
|
|
||||||
hide-cancel
|
|
||||||
>
|
|
||||||
<GiTable
|
|
||||||
row-key="id"
|
|
||||||
:data="dataList"
|
|
||||||
:columns="columns"
|
|
||||||
:loading="loading"
|
|
||||||
:scroll="{ x: '100%', y: '100%', minWidth: 800 }"
|
|
||||||
:pagination="pagination"
|
|
||||||
:disabled-tools="['size']"
|
|
||||||
:disabled-column-keys="['label']"
|
|
||||||
@refresh="search"
|
|
||||||
>
|
|
||||||
<template #custom-left>
|
|
||||||
<a-input v-model="queryForm.description" placeholder="请输入关键词" allow-clear @change="search">
|
|
||||||
<template #prefix><icon-search /></template>
|
|
||||||
</a-input>
|
|
||||||
<a-button @click="reset">重置</a-button>
|
|
||||||
</template>
|
|
||||||
<template #custom-right>
|
|
||||||
<a-button v-permission="['system:dict:item:add']" type="primary" @click="onAdd">
|
|
||||||
<template #icon><icon-plus /></template>
|
|
||||||
<span>新增</span>
|
|
||||||
</a-button>
|
|
||||||
</template>
|
|
||||||
<template #label="{ record }">
|
|
||||||
<a-tag :color="record.color">{{ record.label }}</a-tag>
|
|
||||||
</template>
|
|
||||||
<template #status="{ record }">
|
|
||||||
<GiCellStatus :status="record.status" />
|
|
||||||
</template>
|
|
||||||
<template #action="{ record }">
|
|
||||||
<a-space>
|
|
||||||
<a-link v-permission="['system:dict:item:update']" @click="onUpdate(record)">修改</a-link>
|
|
||||||
<a-popconfirm
|
|
||||||
type="warning"
|
|
||||||
content="是否确定删除该条数据?"
|
|
||||||
:ok-button-props="{ status: 'danger' }"
|
|
||||||
@ok="onDelete(record)"
|
|
||||||
>
|
|
||||||
<a-link v-permission="['system:dict:item:delete']" status="danger">删除</a-link>
|
|
||||||
</a-popconfirm>
|
|
||||||
</a-space>
|
|
||||||
</template>
|
|
||||||
</GiTable>
|
|
||||||
|
|
||||||
<DictItemAddModal ref="DictItemAddModalRef" @save-success="search" />
|
|
||||||
</a-modal>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { useWindowSize } from '@vueuse/core'
|
|
||||||
import DictItemAddModal from './DictItemAddModal.vue'
|
|
||||||
import { type DictItemQuery, type DictItemResp, deleteDictItem, listDictItem } from '@/apis'
|
|
||||||
import type { TableInstanceColumns } from '@/components/GiTable/type'
|
|
||||||
import { useTable } from '@/hooks'
|
|
||||||
import { isMobile } from '@/utils'
|
|
||||||
import has from '@/utils/has'
|
|
||||||
|
|
||||||
const { width } = useWindowSize()
|
|
||||||
|
|
||||||
const queryForm = reactive<DictItemQuery>({
|
|
||||||
dictId: '',
|
|
||||||
sort: ['createTime,desc']
|
|
||||||
})
|
|
||||||
|
|
||||||
const {
|
|
||||||
tableData: dataList,
|
|
||||||
loading,
|
|
||||||
pagination,
|
|
||||||
search,
|
|
||||||
handleDelete
|
|
||||||
} = useTable((page) => listDictItem({ ...queryForm, ...page }), { immediate: true })
|
|
||||||
|
|
||||||
const columns: TableInstanceColumns[] = [
|
|
||||||
{
|
|
||||||
title: '序号',
|
|
||||||
width: 66,
|
|
||||||
align: 'center',
|
|
||||||
render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize)
|
|
||||||
},
|
|
||||||
{ title: '标签', dataIndex: 'label', slotName: 'label' },
|
|
||||||
{ title: '值', dataIndex: 'value', ellipsis: true, tooltip: true },
|
|
||||||
{ title: '状态', slotName: 'status', align: 'center' },
|
|
||||||
{
|
|
||||||
title: '排序',
|
|
||||||
dataIndex: 'sort',
|
|
||||||
width: 90,
|
|
||||||
align: 'center',
|
|
||||||
sortable: {
|
|
||||||
sortDirections: ['ascend', 'descend']
|
|
||||||
},
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
{ title: '描述', dataIndex: 'description', ellipsis: true, tooltip: true },
|
|
||||||
{ title: '创建人', dataIndex: 'createUserString', ellipsis: true, tooltip: true, show: false },
|
|
||||||
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
|
|
||||||
{ title: '修改人', dataIndex: 'updateUserString', ellipsis: true, tooltip: true, show: false },
|
|
||||||
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
slotName: 'action',
|
|
||||||
width: 130,
|
|
||||||
align: 'center',
|
|
||||||
fixed: !isMobile() ? 'right' : undefined,
|
|
||||||
show: has.hasPermOr(['system:dict:item:update', 'system:dict:item:delete'])
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
// 重置
|
|
||||||
const reset = () => {
|
|
||||||
queryForm.description = undefined
|
|
||||||
queryForm.status = undefined
|
|
||||||
search()
|
|
||||||
}
|
|
||||||
|
|
||||||
const dictCode = ref('')
|
|
||||||
const visible = ref(false)
|
|
||||||
// 打开
|
|
||||||
const open = (id: string, code: string) => {
|
|
||||||
dataList.value = []
|
|
||||||
queryForm.dictId = id
|
|
||||||
dictCode.value = code
|
|
||||||
visible.value = true
|
|
||||||
search()
|
|
||||||
}
|
|
||||||
defineExpose({ open })
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
const onDelete = (item: DictItemResp) => {
|
|
||||||
return handleDelete(() => deleteDictItem(item.id), { content: `是否确定删除 [${item.label}]?`, showModal: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
const DictItemAddModalRef = ref<InstanceType<typeof DictItemAddModal>>()
|
|
||||||
// 新增
|
|
||||||
const onAdd = () => {
|
|
||||||
DictItemAddModalRef.value?.onAdd(queryForm.dictId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改
|
|
||||||
const onUpdate = (item: DictItemResp) => {
|
|
||||||
DictItemAddModalRef.value?.onUpdate(item.id)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
|
62
src/views/system/dict/tree/RightMenu.vue
Normal file
62
src/views/system/dict/tree/RightMenu.vue
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<template>
|
||||||
|
<a-menu class="right-menu">
|
||||||
|
<a-menu-item v-permission="['system:dict:update']" @click="onClick('update')">
|
||||||
|
<template #icon><icon-edit :size="16" :stroke-width="3" /></template>
|
||||||
|
<span>修改</span>
|
||||||
|
</a-menu-item>
|
||||||
|
|
||||||
|
<a-menu-item v-permission="['system:dict:delete']" :title="data.isSystem ? '系统内置数据不能删除' : undefined" :disabled="data.isSystem" @click="onClick('delete')">
|
||||||
|
<template #icon><icon-delete :size="16" :stroke-width="3" /></template>
|
||||||
|
<span>删除</span>
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { DictResp } from '@/apis'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
data: DictResp
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'on-menu-item-click', mode: string, data: DictResp): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// 点击菜单项
|
||||||
|
const onClick = (mode: string) => {
|
||||||
|
emit('on-menu-item-click', mode, props.data)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(.arco-menu-inner) {
|
||||||
|
padding: 4px;
|
||||||
|
|
||||||
|
.arco-menu-item {
|
||||||
|
height: 34px;
|
||||||
|
|
||||||
|
&:not(.arco-menu-selected) {
|
||||||
|
color: $color-text-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-menu {
|
||||||
|
width: 120px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid var(--color-border-2);
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
.arrow-icon {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
212
src/views/system/dict/tree/index.vue
Normal file
212
src/views/system/dict/tree/index.vue
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
<template>
|
||||||
|
<div class="dict-tree">
|
||||||
|
<div class="dict-tree__search">
|
||||||
|
<a-input v-model="inputValue" :placeholder="props.placeholder" allow-clear>
|
||||||
|
<template #prefix><icon-search /></template>
|
||||||
|
</a-input>
|
||||||
|
</div>
|
||||||
|
<div class="dict-tree_tree">
|
||||||
|
<a-scrollbar style="height: 100%; overflow: auto" outer-style="height: 100%">
|
||||||
|
<a-tree
|
||||||
|
:data="(treeData as unknown as TreeNodeData[])"
|
||||||
|
:field-names="{ key: 'id' }"
|
||||||
|
block-node
|
||||||
|
@select="select"
|
||||||
|
>
|
||||||
|
<template #title="node">
|
||||||
|
<a-trigger
|
||||||
|
v-model:popup-visible="node.popupVisible"
|
||||||
|
trigger="contextMenu"
|
||||||
|
align-point
|
||||||
|
animation-name="slide-dynamic-origin"
|
||||||
|
auto-fit-transform-origin
|
||||||
|
position="bl"
|
||||||
|
scroll-to-close
|
||||||
|
>
|
||||||
|
<div @contextmenu="onContextmenu(node)">{{ node.name }}({{ node.code }})</div>
|
||||||
|
<template #content>
|
||||||
|
<RightMenu
|
||||||
|
v-if="has.hasPermOr(['system:dict:update', 'system:dict:delete'])"
|
||||||
|
:data="node"
|
||||||
|
@on-menu-item-click="onMenuItemClick"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</a-trigger>
|
||||||
|
</template>
|
||||||
|
</a-tree>
|
||||||
|
<a-affix :offset-bottom="30">
|
||||||
|
<a-button v-permission="['system:dict:add']" type="primary" style="width: 100%" @click="onAdd">
|
||||||
|
<template #icon><icon-plus /></template>
|
||||||
|
<span>新增</span>
|
||||||
|
</a-button>
|
||||||
|
</a-affix>
|
||||||
|
</a-scrollbar>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DictAddModal ref="DictAddModalRef" @save-success="getTreeData" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="tsx">
|
||||||
|
import { Message, Modal } from '@arco-design/web-vue'
|
||||||
|
import type { TreeNodeData } from '@arco-design/web-vue'
|
||||||
|
import { mapTree } from 'xe-utils'
|
||||||
|
import DictAddModal from './DictAddModal.vue'
|
||||||
|
import RightMenu from './RightMenu.vue'
|
||||||
|
import { type DictQuery, type DictResp, deleteDict, listDict } from '@/apis'
|
||||||
|
import has from '@/utils/has'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
placeholder?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
placeholder: '请输入关键词'
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'node-click', keys: Array<any>): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// 选中节点
|
||||||
|
const select = (keys: Array<any>) => {
|
||||||
|
emit('node-click', keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryForm = reactive<DictQuery>({
|
||||||
|
sort: ['createTime,asc']
|
||||||
|
})
|
||||||
|
|
||||||
|
interface TreeItem extends DictResp {
|
||||||
|
popupVisible: boolean
|
||||||
|
}
|
||||||
|
const treeData = ref<TreeItem[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
// 查询树列表
|
||||||
|
const getTreeData = async (query: DictQuery = { ...queryForm }) => {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
const { data } = await listDict(query)
|
||||||
|
treeData.value = mapTree(data, (i) => ({
|
||||||
|
...i,
|
||||||
|
popupVisible: false,
|
||||||
|
icon: () => {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 树查询
|
||||||
|
const inputValue = ref('')
|
||||||
|
watch(inputValue, (val) => {
|
||||||
|
queryForm.description = val
|
||||||
|
getTreeData()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 保存当前右键的节点
|
||||||
|
const contextmenuNode = ref<TreeItem | null>(null)
|
||||||
|
const onContextmenu = (node: TreeItem) => {
|
||||||
|
contextmenuNode.value = node
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭右键菜单弹框
|
||||||
|
const closeRightMenuPopup = () => {
|
||||||
|
if (contextmenuNode.value?.popupVisible) {
|
||||||
|
contextmenuNode.value.popupVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const DictAddModalRef = ref<InstanceType<typeof DictAddModal>>()
|
||||||
|
// 新增
|
||||||
|
const onAdd = () => {
|
||||||
|
DictAddModalRef.value?.onAdd()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 右键菜单项点击
|
||||||
|
const onMenuItemClick = (mode: string, node: DictResp) => {
|
||||||
|
closeRightMenuPopup()
|
||||||
|
if (mode === 'update') {
|
||||||
|
DictAddModalRef.value?.onUpdate(node.id)
|
||||||
|
} else if (mode === 'delete') {
|
||||||
|
Modal.warning({
|
||||||
|
title: '提示',
|
||||||
|
content: `是否确定删除 [${node.name}]?`,
|
||||||
|
hideCancel: false,
|
||||||
|
okButtonProps: { status: 'danger' },
|
||||||
|
onBeforeOk: async () => {
|
||||||
|
try {
|
||||||
|
const res = await deleteDict(node.id)
|
||||||
|
if (res.success) {
|
||||||
|
Message.success('删除成功')
|
||||||
|
getTreeData()
|
||||||
|
}
|
||||||
|
return res.success
|
||||||
|
} catch (error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getTreeData()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(.arco-tree-node-title) {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.arco-tree-node-title-text) {
|
||||||
|
width: 100%;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.arco-tree-node) {
|
||||||
|
.arco-tree-node-switcher {
|
||||||
|
width: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arco-tree-node-title {
|
||||||
|
border-radius: var(--border-radius-medium);
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--color-secondary-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.arco-tree-node-selected) {
|
||||||
|
.arco-tree-node-title {
|
||||||
|
background-color: rgba(var(--primary-6), 0.1);
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(var(--primary-6), 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dict-tree {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
&__search {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__tree {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: var(--color-bg-1);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
Reference in New Issue
Block a user