This commit is contained in:
zhangjianjun 2026-03-30 18:51:44 +08:00
parent f6a0bc8161
commit 22cf2a2f82
4 changed files with 152 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import type { App } from 'vue'
import routes from 'src/routes' import routes from 'src/routes'
import { indexStore } from 'lib/stores' import { indexStore } from 'lib/stores'
const store = indexStore(); const store = indexStore();
const resource = store.$state.kwargs.resource; const resource = store.$state.kwargs.resource || [];
export default function BeforeMount(app: App<Element>) { export default function BeforeMount(app: App<Element>) {
const resourcePaths = resource.map((item: any) => item.path); const resourcePaths = resource.map((item: any) => item.path);

View File

@ -1,7 +1,6 @@
import type { RouteRecordRaw } from "vue-router"; import type { RouteRecordRaw } from "vue-router";
import TableLayout from "lib/layout/TableLayout.vue"; import TableLayout from "lib/layout/TableLayout.vue";
import MainLayout from "lib/layout/MainLayout.vue"; import MainLayout from "lib/layout/MainLayout.vue";
import { indexStore } from "lib/stores";
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
{ {

View File

@ -1,6 +1,8 @@
import type { TableData } from 'lib/type/TableData' import type { TableData } from 'lib/type/TableData'
const data: TableData = { const data: TableData = {
rowKey: "id",
defaultExpandAll: true,
async fetchFun(self, data) { async fetchFun(self, data) {
const res = await self.api?.getDataList(data) const res = await self.api?.getDataList(data)
return res return res
@ -20,20 +22,67 @@ const data: TableData = {
} }
}) })
return data return data
},
getTree(arr: any) {
// 构建一个map来存储所有节点
const map: any = {}
const roots: any[] = []
// 先创建所有节点的映射
arr.forEach((item: any) => {
map[item.key] = { ...item, children: [] }
})
// 构建树结构
arr.forEach((item: any) => {
const node = map[item.key]
if (item.pid === 0 || item.pid === '0') {
// 如果是根节点添加到roots数组
roots.push(node)
} else {
// 如果有父节点添加到父节点的children中
if (map[item.pid]) {
map[item.pid].children.push(node)
} else {
// 如果找不到父节点,也作为根节点处理
roots.push(node)
} }
}
})
return roots
},
}, },
launchTask: [ launchTask: [
async (self: any) => { async (self: any) => {
if (self.bean) { if (self.bean) {
const res = await self.api?.getResources({ type: "", page: 1, size: 1000 }) const res = await self.api?.getResources({ type: "", page: 1, size: 1000 })
const resources = res.data.items?.map((item: any) => { const items = res.data.items || []
const type = item.type === 'page' ? '页面' : '接口' const data = items.map((item: any) => {
return { return {
key: item.id, name: item.name,
name: `${type}${item.name}` key: String(item.id),
id: item.id,
pid: item.pid ? String(item.pid) : item.type,
type: item.type,
} }
}) })
self.bean.resources = resources data.unshift(...[
{
name: '页面',
key: 'page',
id: 'page',
pid: '0',
type: 'page'
},
{
name: '接口',
key: 'api',
id: 'api',
pid: '0',
type: 'api'
}
])
self.bean.resources = self.methods?.getTree(data)
} }
} }
], ],
@ -63,11 +112,14 @@ const data: TableData = {
{ {
key: 'resource', key: 'resource',
name: '权限', name: '权限',
type: 'select', type: 'cascader',
getItems: (self: any) => { getItems: (self: any) => {
return self.bean ? self.bean.resources : [] return self.bean ? self.bean.resources : []
}, },
cascaderProps: {
multiple: true, multiple: true,
checkStrictly: false
},
must: true must: true
}, },
], ],
@ -114,7 +166,7 @@ const data: TableData = {
primary: 'id', primary: 'id',
beforeShow: async (self: any, form: any, row: any) => { beforeShow: async (self: any, form: any, row: any) => {
const res = await self.api?.getDataDetail(row.id) const res = await self.api?.getDataDetail(row.id)
const resources = res.data.map((item: any) => item.id) const resources = res.data.map((item: any) => String(item.id))
const findItem = form.data.find((i: any) => i.key === 'resource') const findItem = form.data.find((i: any) => i.key === 'resource')
findItem.values[form.show] = resources findItem.values[form.show] = resources
}, },
@ -128,11 +180,14 @@ const data: TableData = {
{ {
key: 'resource', key: 'resource',
name: '权限', name: '权限',
type: 'select', type: 'cascader',
cascaderProps: {
multiple: true,
checkStrictly: false
},
getItems: (self: any) => { getItems: (self: any) => {
return self.bean ? self.bean.resources : [] return self.bean ? self.bean.resources : []
}, },
multiple: true,
must: false must: false
}, },
], ],

View File

@ -1,8 +1,29 @@
import type { TableData } from 'lib/type/TableData' import type { TableData } from 'lib/type/TableData'
import "./index.less"
const data: TableData = { const data: TableData = {
rowKey: "id",
defaultExpandAll: true,
async fetchFun(self, data) { async fetchFun(self, data) {
const res = await self.api?.getDataList(data) const res = await self.api?.getDataList(data)
if (self.bean) {
const items = res.data.items || []
const data = items.map((item: any) => {
return {
name: item.name,
key: String(item.id),
id: item.id,
pid: String(item.pid),
color: 'category',
create_time: item.create_time,
method: item.method,
type: item.type,
path: item.path,
}
})
self.bean.categoryList = self.methods?.getTree(data)
res.data.items = self.bean.categoryList
self.bean.allList = data
}
return res return res
}, },
addNods: [ addNods: [
@ -10,6 +31,36 @@ const data: TableData = {
], ],
launchTask: [ launchTask: [
], ],
methods: {
getTree(arr: any) {
// 构建一个map来存储所有节点
const map: any = {}
const roots: any[] = []
// 先创建所有节点的映射
arr.forEach((item: any) => {
map[item.key] = { ...item, children: [] }
})
// 构建树结构
arr.forEach((item: any) => {
const node = map[item.key]
if (item.pid === 0 || item.pid === '0') {
// 如果是根节点添加到roots数组
roots.push(node)
} else {
// 如果有父节点添加到父节点的children中
if (map[item.pid]) {
map[item.pid].children.push(node)
} else {
// 如果找不到父节点,也作为根节点处理
roots.push(node)
}
}
})
return roots
},
},
fliter: [ fliter: [
{ {
key: 'id', key: 'id',
@ -42,6 +93,15 @@ const data: TableData = {
form: { form: {
title: '新建', title: '新建',
data: [ data: [
{
key: 'pid',
name: '父级',
type: 'cascader',
must: false,
getItems(self: TableData) {
return self.bean ? self.bean.categoryList : []
}
},
{ {
key: 'name', key: 'name',
name: '名称', name: '名称',
@ -63,7 +123,7 @@ const data: TableData = {
key: 'path', key: 'path',
name: '路径', name: '路径',
type: 'input', type: 'input',
must: true must: false
}, },
{ {
key: 'method', key: 'method',
@ -84,6 +144,12 @@ const data: TableData = {
width: '80px', width: '80px',
showJson: '*' showJson: '*'
}, },
{
key: 'pid',
name: 'PID',
width: '80px',
showJson: '*'
},
{ {
key: 'name', key: 'name',
name: '名称', name: '名称',
@ -117,6 +183,15 @@ const data: TableData = {
type: 'warning', type: 'warning',
primary: 'id', primary: 'id',
data: [ data: [
{
key: 'pid',
name: '父级',
type: 'cascader',
must: false,
getItems(self: TableData) {
return self.bean ? self.bean.categoryList : []
}
},
{ {
key: 'name', key: 'name',
name: '名称', name: '名称',
@ -138,7 +213,7 @@ const data: TableData = {
key: 'path', key: 'path',
name: '路径', name: '路径',
type: 'input', type: 'input',
must: true must: false
}, },
{ {
key: 'method', key: 'method',