From 482fb1a0d105d2eea90da4470c5d89fb2b570c2c Mon Sep 17 00:00:00 2001
From: Bunny <1319900154@qq.com>
Date: Sat, 26 Oct 2024 15:11:36 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20=E6=89=B9=E9=87=8F?=
=?UTF-8?q?=E4=B8=BA=E8=8F=9C=E5=8D=95=E5=88=86=E9=85=8D=E8=A7=92=E8=89=B2?=
=?UTF-8?q?,=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E8=8F=9C=E5=8D=95?=
=?UTF-8?q?=E8=A7=92=E8=89=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/html/button.html | 740 ------------------
src/api/v1/menu.ts | 5 +
src/store/system/menu.ts | 17 +-
.../system/menu/assign-router-to-role.vue | 4 +-
src/views/system/menu/index.vue | 42 +-
src/views/system/menu/utils/columns.tsx | 30 +-
src/views/system/menu/utils/hooks.tsx | 95 ++-
7 files changed, 151 insertions(+), 782 deletions(-)
delete mode 100644 public/html/button.html
diff --git a/public/html/button.html b/public/html/button.html
deleted file mode 100644
index a4505ce..0000000
--- a/public/html/button.html
+++ /dev/null
@@ -1,740 +0,0 @@
-
-
-
-
-
-
-
-
-
JAVA攻城狮
-
Golang工程师!
-
js攻城狮
-
-
-
-
python攻城狮
-
python攻城狮
-
python攻城狮
-
python攻城狮
-
python攻城狮
-
-
php攻城狮
-
php攻城狮
-
php攻城狮
-
php攻城狮
-
php攻城狮
-
-
kotlin攻城狮
-
kotlin攻城狮
-
kotlin攻城狮
-
kotlin攻城狮
-
kotlin攻城狮
-
C语言攻城狮
-
-
-
-
diff --git a/src/api/v1/menu.ts b/src/api/v1/menu.ts
index fd5a4f8..f6e2f5d 100644
--- a/src/api/v1/menu.ts
+++ b/src/api/v1/menu.ts
@@ -23,6 +23,11 @@ export const fetchAssignRolesToRouter = (data: any) => {
return http.request>('post', `routerRole/assignRolesToRouter`, { data });
};
+/** 菜单管理-清除选中菜单所有角色 */
+export const fetchClearAllRolesSelect = (data: any) => {
+ return http.request>('delete', `routerRole/clearAllRolesSelect`, { data });
+};
+
/** 菜单管理-更新菜单 */
export const fetchUpdateMenu = (data?: any) => {
return http.request>('put', `router/updateMenu`, { data });
diff --git a/src/store/system/menu.ts b/src/store/system/menu.ts
index f9d6045..c76ab9b 100644
--- a/src/store/system/menu.ts
+++ b/src/store/system/menu.ts
@@ -1,7 +1,16 @@
import { defineStore } from 'pinia';
import { storeMessage } from '@/utils/message';
import { handleTree } from '@/utils/tree';
-import { fetchAddMenu, fetchAssignRolesToRouter, fetchDeletedMenuByIds, fetchGetMenusList, fetchGetRoleListByRouterId, fetchUpdateMenu, fetchUpdateMenuByIdWithRank } from '@/api/v1/menu';
+import {
+ fetchAddMenu,
+ fetchAssignRolesToRouter,
+ fetchClearAllRolesSelect,
+ fetchDeletedMenuByIds,
+ fetchGetMenusList,
+ fetchGetRoleListByRouterId,
+ fetchUpdateMenu,
+ fetchUpdateMenuByIdWithRank,
+} from '@/api/v1/menu';
import { isAllEmpty } from '@pureadmin/utils';
import { $t } from '@/plugins/i18n';
@@ -66,5 +75,11 @@ export const userMenuStore = defineStore('menuStore', {
const result = await fetchAssignRolesToRouter(data);
return storeMessage(result);
},
+
+ /** 清除选中菜单所有角色 */
+ async clearAllRolesSelect(data: any) {
+ const result = await fetchClearAllRolesSelect(data);
+ return storeMessage(result);
+ },
},
});
diff --git a/src/views/system/menu/assign-router-to-role.vue b/src/views/system/menu/assign-router-to-role.vue
index 5dfa0d9..2710caf 100644
--- a/src/views/system/menu/assign-router-to-role.vue
+++ b/src/views/system/menu/assign-router-to-role.vue
@@ -22,7 +22,9 @@ const getRoleListByRouterId = async () => {
// 根据用户id查询角色信息
const routerId = props.routerId;
- assignRoles.value = await menuStore.getRoleListByRouterId({ routerId });
+ if (routerId) {
+ assignRoles.value = await menuStore.getRoleListByRouterId({ routerId });
+ }
};
onMounted(() => {
diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
index 4c91233..6526c82 100644
--- a/src/views/system/menu/index.vue
+++ b/src/views/system/menu/index.vue
@@ -6,7 +6,20 @@ import Delete from '@iconify-icons/ep/delete';
import EditPen from '@iconify-icons/ep/edit-pen';
import Refresh from '@iconify-icons/ep/refresh';
import AddFill from '@iconify-icons/ri/add-circle-line';
-import { assignRolesToRouter, handleDelete, onAdd, onChangeMenuRank, onchangeVisible, onSearch, onUpdate, switchLoadMap } from '@/views/system/menu/utils/hooks';
+import {
+ assignBatchRolesToRouter,
+ assignRolesToRouter,
+ clearAllRolesSelect,
+ onAdd,
+ onChangeMenuRank,
+ onchangeVisible,
+ onDelete,
+ onSearch,
+ onUpdate,
+ selectIds,
+ switchLoadMap,
+ tableRef,
+} from '@/views/system/menu/utils/hooks';
import PureTable from '@pureadmin/table';
import { columns } from '@/views/system/menu/utils/columns';
import { userMenuStore } from '@/store/system/menu';
@@ -19,7 +32,6 @@ import { FormInstance } from 'element-plus';
import { usePublicHooks } from '@/views/hooks';
const formRef = ref();
-const tableRef = ref();
const routerStore = userMenuStore();
// 用户是否停用样式
const { switchStyle } = usePublicHooks();
@@ -34,6 +46,14 @@ const resetForm = async (formEl: FormInstance | undefined) => {
await onSearch();
};
+/**
+ * * 选择多行
+ * @param rows
+ */
+const onSelectionChange = (rows: Array) => {
+ selectIds.value = rows.map((row: any) => row.id);
+};
+
onMounted(() => {
onSearch();
});
@@ -50,10 +70,18 @@ onMounted(() => {
{{ $t('buttons.reset') }}
-
+
+
{{ $t('addNew') }}
+
+
+ {{ $t('assignBatchRolesToRouter') }}
+
+
+ {{ $t('clearAllRolesSelect') }}
+
{
row-key="id"
showOverflowTooltip
table-layout="auto"
+ @selection-change="onSelectionChange"
>
{
+
{{ $t('modify') }}
+
+
{{ $t('addNew') }}
-
+
+
+
{{ $t('delete') }}
diff --git a/src/views/system/menu/utils/columns.tsx b/src/views/system/menu/utils/columns.tsx
index fea83b5..ec2fc04 100644
--- a/src/views/system/menu/utils/columns.tsx
+++ b/src/views/system/menu/utils/columns.tsx
@@ -3,10 +3,38 @@ import type { FormRules } from 'element-plus';
import { ElTag } from 'element-plus';
import { $t } from '@/plugins/i18n';
import { isAllEmpty } from '@pureadmin/utils';
-import { getMenuType } from '@/views/system/menu/utils/hooks';
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
+/**
+ * 标签栏菜单类型匹配
+ * @param type
+ * @param text
+ */
+const getMenuType = (type: number, text: boolean = false): any => {
+ switch (type) {
+ case 0:
+ return text ? '菜单' : 'primary';
+ case 1:
+ return text ? 'iframe' : 'warning';
+ case 2:
+ return text ? '外链' : 'danger';
+ }
+};
+
+/** 格式化菜单选项 */
+export const formatHigherMenuOptions = (treeList: any) => {
+ if (!treeList || !treeList.length) return;
+ const newTreeList = [];
+ for (let i = 0; i < treeList.length; i++) {
+ treeList[i].title = $t(treeList[i].title);
+ formatHigherMenuOptions(treeList[i].children);
+ newTreeList.push(treeList[i]);
+ }
+ return newTreeList;
+};
+
export const columns: TableColumnList = [
+ { type: 'selection', align: 'left' },
{
label: '菜单名称',
prop: 'title',
diff --git a/src/views/system/menu/utils/hooks.tsx b/src/views/system/menu/utils/hooks.tsx
index 50604e5..d605f3e 100644
--- a/src/views/system/menu/utils/hooks.tsx
+++ b/src/views/system/menu/utils/hooks.tsx
@@ -7,29 +7,17 @@ import { cloneDeep, deviceDetection } from '@pureadmin/utils';
import { userMenuStore } from '@/store/system/menu';
import AssignRouterToRole from '@/views/system/menu/assign-router-to-role.vue';
import { messageBox } from '@/utils/message';
+import { formatHigherMenuOptions } from '@/views/system/menu/utils/columns';
// 用户是否停用加载集合
export const switchLoadMap = ref({});
+// 选择多行
+export const selectIds = ref([]);
+export const tableRef = ref();
+const assignRouterToRolesRef = ref();
+const dialogFormRef = ref();
const menuStore = userMenuStore();
const routerStore = userMenuStore();
-const assignRouterToRolesRef = ref();
-const formRef = ref();
-
-/**
- * 标签栏菜单类型匹配
- * @param type
- * @param text
- */
-export const getMenuType = (type: number, text: boolean = false): any => {
- switch (type) {
- case 0:
- return text ? '菜单' : 'primary';
- case 1:
- return text ? 'iframe' : 'warning';
- case 2:
- return text ? '外链' : 'danger';
- }
-};
/** 获取菜单数据 */
export const onSearch = async () => {
@@ -38,17 +26,6 @@ export const onSearch = async () => {
menuStore.loading = false;
};
-export const formatHigherMenuOptions = (treeList: any) => {
- if (!treeList || !treeList.length) return;
- const newTreeList = [];
- for (let i = 0; i < treeList.length; i++) {
- treeList[i].title = $t(treeList[i].title);
- formatHigherMenuOptions(treeList[i].children);
- newTreeList.push(treeList[i]);
- }
- return newTreeList;
-};
-
/** 添加菜单 */
export function onAdd(parentId: any = 0) {
addDialog({
@@ -72,9 +49,9 @@ export function onAdd(parentId: any = 0) {
draggable: true,
closeOnClickModal: false,
fullscreenIcon: true,
- contentRenderer: () => h(editForm, { ref: formRef }),
+ contentRenderer: () => h(editForm, { ref: dialogFormRef }),
beforeSure: (done, { options }) => {
- const menuFormRef = formRef.value.menuFormRef;
+ const menuFormRef = dialogFormRef.value.menuFormRef;
const curData = options.props.formInline as FormItemProps;
menuFormRef.validate(async (valid: any) => {
if (!valid) return;
@@ -118,9 +95,9 @@ export const onUpdate = (row?: FormItemProps) => {
fullscreen: deviceDetection(),
fullscreenIcon: true,
closeOnClickModal: false,
- contentRenderer: () => h(editForm, { ref: formRef }),
+ contentRenderer: () => h(editForm, { ref: dialogFormRef }),
beforeSure: (done, { options }) => {
- const menuFormRef = formRef.value.menuFormRef;
+ const menuFormRef = dialogFormRef.value.menuFormRef;
const curData = options.props.formInline as FormItemProps;
delete curData.higherMenuOptions;
@@ -145,7 +122,7 @@ export const onUpdate = (row?: FormItemProps) => {
* * 删除菜单
* @param row
*/
-export const handleDelete = async row => {
+export const onDelete = async row => {
// 是否确认删除
const result = await messageBox({
title: $t('confirmDelete'),
@@ -239,7 +216,7 @@ export const assignRolesToRouter = (row: any) => {
contentRenderer: () => ,
beforeSure: async (done: any) => {
// 分配用户角色
- const data = { routerId: row.id, roleIds: assignRouterToRolesRef.value.assignRoles };
+ const data = { routerIds: [row.id], roleIds: assignRouterToRolesRef.value.assignRoles };
const result = await menuStore.assignRolesToRouter(data);
// 更新成功关闭弹窗
@@ -248,3 +225,51 @@ export const assignRolesToRouter = (row: any) => {
},
});
};
+
+/** 批量为路由分配角色 */
+export const assignBatchRolesToRouter = () => {
+ addDialog({
+ title: $t('assignBatchRolesToRouter'),
+ width: '45%',
+ draggable: true,
+ closeOnClickModal: false,
+ fullscreenIcon: true,
+ contentRenderer: () => ,
+ beforeSure: async (done: any) => {
+ // 表格功能
+ const { clearSelection } = tableRef.value.getTableRef();
+
+ // 分配用户角色
+ const data = { routerIds: selectIds.value, roleIds: assignRouterToRolesRef.value.assignRoles };
+ const result = await menuStore.assignRolesToRouter(data);
+
+ // 更新成功关闭弹窗
+ if (!result) return;
+ clearSelection();
+ done();
+ },
+ });
+};
+
+/** 清除选中所以角色 */
+export const clearAllRolesSelect = async () => {
+ // 表格功能
+ const { clearSelection } = tableRef.value.getTableRef();
+
+ const confirm = await messageBox({
+ title: $t('batchUpdates'),
+ showMessage: false,
+ confirmMessage: undefined,
+ cancelMessage: $t('cancel'),
+ });
+
+ // 取消修改
+ if (!confirm) return;
+
+ // 分配用户角色
+ const result = await menuStore.clearAllRolesSelect(selectIds.value);
+
+ // 更新成功关闭弹窗
+ if (!result) return;
+ clearSelection();
+};