店铺赋权

This commit is contained in:
BabyBoy 2025-09-08 18:15:47 +08:00
parent 5b30555a04
commit dd936a8e06
5 changed files with 65 additions and 57 deletions

View File

@ -24,8 +24,9 @@ export interface RoleVO extends BaseEntity {
deptCheckStrictly: boolean; deptCheckStrictly: boolean;
status: string; status: string;
delFlag: string; delFlag: string;
tenantId: string;
remark?: any; remark?: any;
flag: boolean; has: boolean;
menuIds?: Array<string | number>; menuIds?: Array<string | number>;
deptIds?: Array<string | number>; deptIds?: Array<string | number>;
admin: boolean; admin: boolean;

View File

@ -1,9 +1,10 @@
import { DeptTreeVO, DeptVO } from './../dept/types'; import { DeptTreeVO, DeptVO } from './../dept/types';
import { RoleVO } from '@/api/system/role/types'; import { UserForm, UserInfoVO, UserQuery, UserVO } from './types';
import request from '@/utils/request';
import { AxiosPromise } from 'axios'; import { AxiosPromise } from 'axios';
import { UserForm, UserQuery, UserVO, UserInfoVO } from './types'; import { RoleVO } from '@/api/system/role/types';
import { parseStrEmpty } from '@/utils/ruoyi'; import { parseStrEmpty } from '@/utils/ruoyi';
import request from '@/utils/request';
/** /**
* *
@ -175,6 +176,28 @@ export const getAuthRole = (userId: string | number): AxiosPromise<{ user: UserV
method: 'get' method: 'get'
}); });
}; };
/**
*
* @param userId ID
*/
export const gettenantList = (userId: string | number, type: number, data: any): AxiosPromise<{ total: number; records: RoleVO[] }> => {
return request({
url: '/system/user/tenantList/' + userId + '/' + type,
method: 'get',
params: data
});
};
/**
*
* @param data ID
*/
export const updateTenant = (data: { userId: string; tenantIds: any }) => {
return request({
url: '/system/user/tenant',
method: 'post',
data: data
});
};
/** /**
* *

View File

@ -20,13 +20,13 @@
<el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option> <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option>
<template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template> <template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
</el-select> </el-select>
<el-button :style="{ margin: '10px' }" @click="isStae = true">设置默认租户</el-button> <!-- <el-button :style="{ margin: '10px' }" @click="isStae = true">设置默认租户</el-button>
<el-dialog title="设置默认租户" v-model="isStae" width="500px" append-to-body> <el-dialog title="设置默认租户" v-model="isStae" width="500px" append-to-body>
<div v-for="item in tenantList" :key="item.tenantId" :style="{ display: 'flex', justifyItems: 'space-between', width: '100%' }"> <div v-for="item in tenantList" :key="item.tenantId" :style="{ display: 'flex', justifyItems: 'space-between', width: '100%' }">
<div class="flex align-center width" v-if="item.companyName">{{ item.companyName }}</div> <div class="flex align-center width" v-if="item.companyName">{{ item.companyName }}</div>
<el-button :style="{ margin: '10px' }" @click="issteFun(item.tenantId)" v-if="item.companyName">{{ '设置为默认租户' }}</el-button> <el-button :style="{ margin: '10px' }" @click="issteFun(item.tenantId)" v-if="item.companyName">{{ '设置为默认租户' }}</el-button>
</div> </div>
</el-dialog> </el-dialog> -->
<search-menu ref="searchMenuRef" /> <search-menu ref="searchMenuRef" />
<el-tooltip content="搜索" effect="dark" placement="bottom"> <el-tooltip content="搜索" effect="dark" placement="bottom">
<div class="right-menu-item hover-effect" @click="openSearchMenu"> <div class="right-menu-item hover-effect" @click="openSearchMenu">

View File

@ -233,6 +233,7 @@ const dataScopeRef = ref<ElFormInstance>();
const menuRef = ref<ElTreeInstance>(); const menuRef = ref<ElTreeInstance>();
const deptRef = ref<ElTreeInstance>(); const deptRef = ref<ElTreeInstance>();
const initForm: RoleForm = { const initForm: RoleForm = {
roleId: undefined, roleId: undefined,
roleSort: 1, roleSort: 1,
@ -242,7 +243,7 @@ const initForm: RoleForm = {
menuCheckStrictly: true, menuCheckStrictly: true,
deptCheckStrictly: true, deptCheckStrictly: true,
remark: '', remark: '',
dataScope: '1', dataScope: '5',
menuIds: [], menuIds: [],
deptIds: [] deptIds: []
}; };

View File

@ -1,33 +1,15 @@
<template> <template>
<div class="p-2"> <div class="p-2">
<div class="panel">
3333
<h4 class="panel-title">基本信息</h4>
<el-form :model="form" :inline="true">
<el-row :gutter="10">
<el-col :span="2.5">
<el-form-item label="用户昵称" prop="nickName">
<el-input v-model="form.nickName" disabled />
</el-form-item>
</el-col>
<el-col :span="2.5">
<el-form-item label="登录账号" prop="userName">
<el-input v-model="form.userName" disabled />
</el-form-item>
</el-col>
</el-row>
</el-form>
</div>
<div class="panel"> <div class="panel">
<h4 class="panel-title">店铺信息</h4> <h4 class="panel-title">店铺信息</h4>
<div> <div>
<el-table <el-table
ref="tableRef" ref="tableRef"
row-key="tenantId"
@row-click="clickRow"
v-loading="loading" v-loading="loading"
border border
:row-key="getRowKey" :data="roles"
:data="roles.slice((pageNum - 1) * pageSize, pageNum * pageSize)"
@row-click="clickRow"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
<el-table-column label="序号" width="55" type="index" align="center"> <el-table-column label="序号" width="55" type="index" align="center">
@ -35,17 +17,10 @@
<span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span> <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column type="selection" :reserve-selection="true" :selectable="checkSelectable" width="55"></el-table-column> <el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
<el-table-column label="角色编号" align="center" prop="roleId" /> <el-table-column label="店铺名称" align="center" prop="tenantName" />
<el-table-column label="角色名称" align="center" prop="roleName" />
<el-table-column label="权限字符" align="center" prop="roleKey" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template #default="scope">
<span>{{ proxy.parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
</el-table> </el-table>
<pagination v-show="total > 0" v-model:page="pageNum" v-model:limit="pageSize" :total="total" /> <pagination v-show="total > 0" v-model:page="params.current" v-model:limit="params.size" :total="total" />
<div style="text-align: center; margin-left: -120px; margin-top: 30px"> <div style="text-align: center; margin-left: -120px; margin-top: 30px">
<el-button type="primary" @click="submitForm()">提交</el-button> <el-button type="primary" @click="submitForm()">提交</el-button>
<el-button @click="close()">返回</el-button> <el-button @click="close()">返回</el-button>
@ -58,10 +33,11 @@
<script setup name="AuthRole" lang="ts"> <script setup name="AuthRole" lang="ts">
import { RoleVO } from '@/api/system/role/types'; import { RoleVO } from '@/api/system/role/types';
import { getAuthRole, updateAuthRole } from '@/api/system/user'; import { gettenantList, updateTenant } from '@/api/system/user';
import { UserForm } from '@/api/system/user/types'; import { UserForm } from '@/api/system/user/types';
import { RouteLocationNormalized } from 'vue-router'; import { RouteLocationNormalized } from 'vue-router';
import { parseTime } from '@/utils/ruoyi'; import { parseTime } from '@/utils/ruoyi';
import { currentTaskAllUser } from '@/api/workflow/task';
const route = useRoute(); const route = useRoute();
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@ -83,23 +59,27 @@ const tableRef = ref<ElTableInstance>();
/** 单击选中行数据 */ /** 单击选中行数据 */
const clickRow = (row: RoleVO) => { const clickRow = (row: RoleVO) => {
if (checkSelectable(row)) { if (checkSelectable(row)) {
row.flag = !row.flag; row.has = !row.has;
tableRef.value?.toggleRowSelection(row, row.flag); tableRef.value?.toggleRowSelection(row, row.has);
} }
}; };
/** 多选框选中数据 */ /** 多选框选中数据 */
/** 检查角色状态 */
const checkSelectable = (row: RoleVO): boolean => {
return row.has;
};
// const handleSelectionChange = (selection: RoleVO[]) => {
// selection.forEach((item: any) => {
// roleIds.value.push(item.tenantId);
// });
// };
const handleSelectionChange = (selection: RoleVO[]) => { const handleSelectionChange = (selection: RoleVO[]) => {
roleIds.value = selection.map((item) => item.roleId); roleIds.value = selection.map((item) => item.tenantId);
}; };
/** 保存选中的数据编号 */ /** 保存选中的数据编号 */
const getRowKey = (row: RoleVO): string => { const getRowKey = (row: RoleVO): string => {
return String(row.roleId); return String(row.tenantId);
}; };
/** 检查角色状态 */
const checkSelectable = (row: RoleVO): boolean => {
return row.status === '0';
};
/** 关闭按钮 */
const close = () => { const close = () => {
const obj: RouteLocationNormalized = { const obj: RouteLocationNormalized = {
fullPath: '', fullPath: '',
@ -116,24 +96,27 @@ const close = () => {
}; };
/** 提交按钮 */ /** 提交按钮 */
const submitForm = async () => { const submitForm = async () => {
const userId = form.value.userId; const userId = route.params && route.params.userId;
const rIds = roleIds.value.join(','); await updateTenant({ userId: userId as string, tenantIds: roleIds.value });
await updateAuthRole({ userId: userId as string, roleIds: rIds });
proxy?.$modal.msgSuccess('授权成功'); proxy?.$modal.msgSuccess('授权成功');
close(); close();
}; };
const params = ref({
size: 10,
current: 1
});
const getList = async () => { const getList = async () => {
const userId = route.params && route.params.userId; const userId = route.params && route.params.userId;
if (userId) { if (userId) {
loading.value = true; loading.value = true;
const res = await getAuthRole(userId as string); const res = await gettenantList(userId as string, 0, params.value);
Object.assign(form.value, res.data.user); console.log(res.data);
Object.assign(roles.value, res.data.roles); roles.value = res.data.records;
total.value = roles.value.length; total.value = res.data.total;
// console.log(roles.value);
await nextTick(() => { await nextTick(() => {
roles.value.forEach((row) => { roles.value.forEach((row) => {
if (row?.flag) { if (row?.has) {
tableRef.value?.toggleRowSelection(row, true); tableRef.value?.toggleRowSelection(row, true);
} }
}); });