权限角色调整

This commit is contained in:
joylink_zhaoerwei 2024-10-21 17:18:51 +08:00
parent b6d345426f
commit fb18c04248
7 changed files with 61 additions and 13 deletions

View File

@ -100,7 +100,7 @@ export interface role {
roleConfig: {
lineId: number;
lineType: string;
};
}[];
}
interface userInfo {
remainingSecond: number;

View File

@ -1,7 +1,7 @@
<template>
<q-list bordered separator>
<div v-for="(menu, ii) in list" :key="ii">
<div v-if="menu.children">
<div v-if="menu.children && menu.show">
<q-expansion-item :icon="menu.icon" :label="menu.label">
<q-card>
<q-list bordered separator>
@ -24,7 +24,7 @@
</q-card>
</q-expansion-item>
</div>
<div v-else>
<div v-else-if="menu.show">
<q-item clickable :to="menu.path" exact>
<q-item-section avatar>
<q-icon :name="menu.icon"></q-icon>
@ -39,15 +39,20 @@
</template>
<script setup lang="ts">
import { getMonitorPath } from 'src/router/routes';
import { useUserStore } from 'src/stores/user-store';
import { reactive } from 'vue';
const userStore = useUserStore();
const list = reactive([
{
path: '/monitor',
show: true,
path: getMonitorPath(userStore.roles),
label: '监控',
icon: 'computer',
},
{
show: userStore.defaultRole == 'ADMIN',
path: '',
label: '数据管理',
icon: 'list_alt',
@ -85,6 +90,7 @@ const list = reactive([
],
},
{
show: true,
path: '',
label: '系统管理',
icon: 'dataset',

View File

@ -40,7 +40,7 @@
<div class="q-gutter-sm row items-center no-wrap">
<q-btn
v-show="route.path.includes('line/monitor/')"
v-show="showBackMonitor"
color="info"
label="返回"
@click="backConfirm"
@ -102,7 +102,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted } from 'vue';
import { ref, reactive, onMounted, onUnmounted, computed } from 'vue';
import SysMenu from 'src/components/SysMenu.vue';
import { useRouter, useRoute } from 'vue-router';
import { Dialog, DialogChainObject, useQuasar } from 'quasar';
@ -126,6 +126,8 @@ import {
} from 'src/components/webSocketConnect';
import { logout } from 'src/api/UserApi';
import { ApiError } from 'src/boot/axios';
import { useUserStore } from 'src/stores/user-store';
import { getMonitorPath } from 'src/router/routes';
const leftDrawerOpen = ref(false);
const router = useRouter();
@ -155,6 +157,14 @@ function onLeftResize(size: { width: number; height: number }) {
leftDrawerSize.height = size.height;
}
const showBackMonitor = computed(() => {
const userStore = useUserStore();
const isShow =
route.path.includes('line/monitor/') &&
getMonitorPath(userStore.roles) == '/monitor';
return isShow;
});
const watchInteract = () => {
lineNetStore.playAble = true;
document.removeEventListener('click', watchInteract);

View File

@ -15,7 +15,7 @@
binary-state-sort
@request="onRequest"
>
<template v-slot:top-right>
<!-- <template v-slot:top-right>
<q-input
dense
debounce="1000"
@ -43,7 +43,7 @@
/>
</div>
</q-td>
</template>
</template> -->
</q-table>
<q-dialog
@ -128,7 +128,6 @@ const columnDefs: QTableColumn[] = [
required: true,
align: 'center',
},
{ name: 'operations', label: '操作', field: 'operations', align: 'center' },
];
const operateDisabled = ref(false);

View File

@ -61,6 +61,7 @@ import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from 'src/stores/user-store';
import { handleRefreshToken } from 'src/utils/refreshToken';
import { getMonitorPath } from 'src/router/routes';
const $q = useQuasar();
const router = useRouter();
@ -85,7 +86,7 @@ async function doLogin() {
() => handleRefreshToken(),
userInfo.remainingSecond * 1000 - 10000
);
router.push({ name: 'home' });
router.replace(getMonitorPath(userInfo.roles));
} catch (err) {
visible.value = false;
const apiErr = err as ApiError;

View File

@ -39,7 +39,10 @@
</div>
</q-td>
</template>
<template v-slot:body-cell-operations="props">
<template
v-if="userStore.defaultRole == 'ADMIN'"
v-slot:body-cell-operations="props"
>
<q-td :props="props">
<div class="q-gutter-sm row justify-center">
<q-btn
@ -99,6 +102,7 @@ import { pageQuery, User } from '../api/UserApi';
import { errorNotify, successNotify } from '../utils/CommonNotify';
import { ApiError } from 'src/boot/axios';
import { pageQueryRole, userLinkRole } from 'src/api/AuthApi';
import { useUserStore } from 'src/stores/user-store';
const $q = useQuasar();
const props = withDefaults(
@ -110,8 +114,17 @@ const props = withDefaults(
const tableHeight = computed(() => {
return props.sizeHeight - 32;
});
const userStore = useUserStore();
onMounted(() => {
if (userStore.defaultRole == 'ADMIN') {
columnDefs.push({
name: 'operations',
label: '操作',
field: 'operations',
align: 'center',
});
}
tableRef.value.requestServerInteraction();
getAllRole();
});
@ -144,7 +157,6 @@ const columnDefs: QTableColumn[] = [
field: 'mobile',
align: 'center',
},
{ name: 'operations', label: '操作', field: 'operations', align: 'center' },
];
const tableRef = ref();

View File

@ -1,10 +1,11 @@
import { RouteRecordRaw } from 'vue-router';
import { role } from 'src/api/UserApi';
const routes: RouteRecordRaw[] = [
{
path: '/',
name: 'home',
redirect: '/monitor',
redirect: '/login',
// component: () => import('layouts/MainLayout.vue'),
// children: [{ path: '', component: () => import('pages/IndexPage.vue') }],
},
@ -167,3 +168,22 @@ const routes: RouteRecordRaw[] = [
];
export default routes;
export function getMonitorPath(roles: role[]) {
let monitorPath = '';
const allOCCLineIds: number[] = [];
for (let i = 0; i < roles.length; i++) {
const roleConfig = roles[i].roleConfig;
for (let j = 0; j < roleConfig.length; j++) {
if (roleConfig[j].lineType == 'NCC') {
monitorPath = '/monitor';
return monitorPath;
} else {
allOCCLineIds.push(roleConfig[j].lineId);
}
}
}
const minId = Math.min(...allOCCLineIds);
monitorPath = `/line/monitor/${minId}`;
return monitorPath;
}