From 9b8766452cf4c14ef4cd425355873e4bf3e74510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E5=B0=8F=E5=A4=A9?= <1638245306@qq.com> Date: Wed, 8 Feb 2023 17:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96:=20?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86=E6=8C=89=E9=92=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/role_menu_button_permission.py | 4 +- web/src/utils/service.ts | 2 +- web/src/utils/tools.ts | 13 +- web/src/views/system/menu/api.ts | 2 +- web/src/views/system/menu/crud.tsx | 145 +++++++++++------- web/src/views/system/menu/index.vue | 8 +- web/src/views/system/role/curd.tsx | 2 +- 7 files changed, 109 insertions(+), 67 deletions(-) diff --git a/backend/dvadmin/system/views/role_menu_button_permission.py b/backend/dvadmin/system/views/role_menu_button_permission.py index 3416ac0..9d631a5 100644 --- a/backend/dvadmin/system/views/role_menu_button_permission.py +++ b/backend/dvadmin/system/views/role_menu_button_permission.py @@ -23,7 +23,7 @@ class RoleMenuButtonPermissionSerializer(CustomModelSerializer): class Meta: model = RoleMenuButtonPermission - fields = ['id', 'name', 'value', 'api', 'method'] + fields = "__all__" read_only_fields = ["id"] @@ -34,7 +34,7 @@ class RoleMenuButtonPermissionInitSerializer(CustomModelSerializer): class Meta: model = RoleMenuButtonPermission - fields = ['id', 'name', 'value', 'api', 'method', 'menu'] + fields = "__all__" read_only_fields = ["id"] class RoleMenuButtonPermissionCreateUpdateSerializer(CustomModelSerializer): diff --git a/web/src/utils/service.ts b/web/src/utils/service.ts index 04b936e..cba2009 100644 --- a/web/src/utils/service.ts +++ b/web/src/utils/service.ts @@ -33,7 +33,7 @@ function createService() { // 根据 code 进行判断 if (code === undefined) { // 如果没有 code 代表这不是项目后端开发的接口 - errorCreate(`非标准返回:${dataAxios}, ${response.config.url}`); + errorCreate(`非标准返回:${dataAxios}, ${response.config.url}`,false); return dataAxios; } else { // 有 code 代表这是一个后端接口 可以进行进一步的判断 diff --git a/web/src/utils/tools.ts b/web/src/utils/tools.ts index 80fa784..439b927 100644 --- a/web/src/utils/tools.ts +++ b/web/src/utils/tools.ts @@ -48,19 +48,22 @@ export function responseError(data = {}, msg = "请求失败", code = 500) { * @description 记录和显示错误 * @param {Error} error 错误对象 */ -export function errorLog(error) { +export function errorLog(error:any,notification=true) { // 打印到控制台 console.error(error); // 显示提示 - uiContext.get().notification.error({ message: error.message }); + if(notification){ + uiContext.get().notification.error({ message: error.message }); + } + } /** * @description 创建一个错误 * @param {String} msg 错误信息 */ -export function errorCreate(msg) { +export function errorCreate(msg:any,notification=true) { const error = new Error(msg); - errorLog(error); - throw error; + errorLog(error,notification); + // throw error; } diff --git a/web/src/views/system/menu/api.ts b/web/src/views/system/menu/api.ts index ca8781b..1df5890 100644 --- a/web/src/views/system/menu/api.ts +++ b/web/src/views/system/menu/api.ts @@ -6,7 +6,7 @@ export function GetList(query: PageQuery) { return request({ url: apiPrefix, method: 'get', - params: query, + params: query }); } export function GetObj(id: InfoReq) { diff --git a/web/src/views/system/menu/crud.tsx b/web/src/views/system/menu/crud.tsx index 4f930db..893c807 100644 --- a/web/src/views/system/menu/crud.tsx +++ b/web/src/views/system/menu/crud.tsx @@ -1,15 +1,12 @@ import * as api from "./api"; import { dict, PageQuery, AddReq, DelReq, EditReq, CrudExpose, CrudOptions, } from "@fast-crud/fast-crud"; -import { apiPrefix as menuPrefix } from './api' -import { request } from "/@/utils/service"; -import XEUtils from "xe-utils"; import { dictionary } from "/@/utils/dictionary"; import iconSelector from '/@/components/iconSelector/index.vue' interface CreateCrudOptionsTypes { crudOptions: CrudOptions; } -export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExpose }): CreateCrudOptionsTypes { +export const createCrudOptions = function ({ crudExpose,menuButtonRef }: { crudExpose: CrudExpose,menuButtonRef:any }): CreateCrudOptionsTypes { //验证路由地址 const validateWebPath = (rule: string, value: string, callback: Function) => { const isLink = crudExpose.getFormData().is_link @@ -26,10 +23,8 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp } } - - const pageRequest = async (query: PageQuery) => { - return await api.GetList(query); + return await api.GetList({}); }; const editRequest = async ({ form, row }: EditReq) => { form.id = row.id; @@ -41,6 +36,18 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp const addRequest = async ({ form }: AddReq) => { return await api.AddObj(form); }; + + /** + * 懒加载 + * @param row + * @returns {Promise} + */ + const loadContentMethod = (tree:any, treeNode:any, resolve:any)=>{ + api.GetList({ parent: tree.id }).then((res:any) => { + resolve(res.data) + }) + } + return { crudOptions: { request: { @@ -49,21 +56,49 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp editRequest, delRequest }, + pagination:{ + show:false + }, + table:{ + rowKey:'id', + lazy:true, + load:loadContentMethod, + treeProps:{children: 'children', hasChildren: 'hasChild'} + }, + rowHandle: { + buttons: { + custom: { + text: "按钮配置", + type:'warning', + tooltip: { + placement: "top", + content: "按钮配置" + }, + click: (context:any):void => { + const {row} = context + menuButtonRef.value.drawer=true + menuButtonRef.value.selectOptions = row + menuButtonRef.value.initGet() + + } + } + }, + }, columns: { _index: { title: '序号', form: { show: false }, column: { - //type: 'index', + type: 'index', align: 'center', - width: '70px', + width: '80px', columnSetDisabled: true, //禁止在列设置中选择 - formatter: (context) => { - //计算序号,你可以自定义计算规则,此处为翻页累加 - let index = context.index ?? 1; - let pagination = crudExpose.crudBinding.value.pagination; - return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1; - }, + // formatter: (context) => { + // //计算序号,你可以自定义计算规则,此处为翻页累加 + // let index = context.index ?? 1; + // let pagination = crudExpose.crudBinding.value.pagination; + // return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1; + // }, }, }, search: { @@ -89,46 +124,46 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp } }, }, - parent: { - title: '父级菜单', - column: { - show: false - }, - type: 'dict-cascader', - dict: dict({ - url: menuPrefix, - value: "id", - label: "name", - children: "children", - isTree: true, - getData: async ({ url }: { url: string }) => { - return request({ - url: url, - params: { limit: 999, status: 1, is_catalog: 1 }, - }).then((ret: any) => { - const responseData = ret.data; - const result = XEUtils.toArrayTree(responseData, { - parentKey: "parent", - strict: true, - }); - return [{ id: null, name: "根节点", children: result }]; - }); - } - }), - form: { - component: { - filterable: true, - placeholder: '请选择父级菜单', - props: { - props: { - checkStrictly: true, - value: "id", - label: "name", - } - } - }, - } - }, + // parent: { + // title: '父级菜单', + // column: { + // show: false + // }, + // type: 'dict-cascader', + // dict: dict({ + // url: menuPrefix, + // value: "id", + // label: "name", + // children: "children", + // isTree: true, + // getData: async ({ url }: { url: string }) => { + // return request({ + // url: url, + // params: { limit: 100, status: 1, is_catalog: 1 }, + // }).then((ret: any) => { + // const responseData = ret.data; + // const result = XEUtils.toArrayTree(responseData, { + // parentKey: "parent", + // strict: true, + // }); + // return [{ id: null, name: "根节点", children: result }]; + // }); + // } + // }), + // form: { + // component: { + // filterable: true, + // placeholder: '请选择父级菜单', + // props: { + // props: { + // checkStrictly: true, + // value: "id", + // label: "name", + // } + // } + // }, + // } + // }, name: { title: '菜单名称', search: { diff --git a/web/src/views/system/menu/index.vue b/web/src/views/system/menu/index.vue index 1fa8634..1680ba0 100644 --- a/web/src/views/system/menu/index.vue +++ b/web/src/views/system/menu/index.vue @@ -1,13 +1,17 @@