Browse Source

fix: 权限管理

master
guoapeng 5 days ago
parent
commit
1cb33495ac
  1. 1
      src/apis/system.ts
  2. 18
      src/components/user/Edit/index.vue
  3. 2
      src/layouts/default.vue
  4. 63
      src/router/routes.ts
  5. 6
      src/types/system.d.ts
  6. 48
      src/views/setting/device/index.vue
  7. 35
      src/views/setting/index.vue
  8. 42
      src/views/setting/user/index.vue

1
src/apis/system.ts

@ -11,3 +11,4 @@ export const setTime = (params: { epochMilli?: number }): Promise<null> => http.
export const configList = (params: System.Page = { pageNum: 1, pageSize: 999 }): Promise<System.PageResponse<System.SystemConfig>> => http.post('/system-config/list', params)
export const updateConfig = (params: System.SystemConfig): Promise<number> => http.put('/system-config', params)
export const sync = (params: any): Promise<number> => http.post('/device/sync', params)
export const getDeviceInfo = (): Promise<System.DeviceInfo> => http.get('/device/device-info')

18
src/components/user/Edit/index.vue

@ -85,8 +85,6 @@ const okHandle = async () => {
await updateUser(form.value)
}
else {
form.value.deleted = 'DISABLE'
form.value.fixedUser = 'DISABLE'
await addUser(form.value)
}
// , 退
@ -112,8 +110,8 @@ const roleList = [
value: 'ADMIN',
},
{
label: '开发者',
value: 'DEVELOPER',
label: '仓库管理员',
value: 'STORE',
},
{
label: '普通用户',
@ -125,16 +123,16 @@ const roleList = [
<template lang="pug">
FtDialog(visible :title="data.id ? '编辑用户' : '新增用户'" width="40%" :ok-handle="okHandle" @cancel="cancel")
el-form(ref="formRef" :model="form" :rules="rules" label-width="auto")
el-form-item(label="账号" prop="username")
ft-input(v-model="form.username" maxlength="10" show-word-limit :disabled="data.id && form.fixedUser === 'ENABLE'" placeholder="请输入账号")
el-form-item(label="账号" prop="username" )
ft-input(v-model="form.username" maxlength="10" show-word-limit placeholder="请输入账号" :disabled="useSystemStore().systemStatus.currentUser.role !== 'ADMIN'")
el-form-item(label="用户名" prop="nickname")
ft-input(v-model="form.nickname" maxlength="10" show-word-limit :disabled="data.id && form.fixedUser === 'ENABLE'" placeholder="请输入用户名")
ft-input(v-model="form.nickname" maxlength="10" show-word-limit placeholder="请输入用户名")
el-form-item(label="角色" prop="role")
el-select(v-model="form.role" placeholder="请选择角色")
el-select(v-model="form.role" placeholder="请选择角色" :disabled="useSystemStore().systemStatus.currentUser.role !== 'ADMIN'")
el-option( v-for="item in roleList" :key="item.value" :label="item.label" :value="item.value")
el-form-item(label="密码" prop="password" v-if="useSystemStore().systemStatus.currentUser?.fixedUser === 'ENABLE'")
el-form-item(label="密码" prop="password")
ft-input(v-model="form.password" maxlength="6" autocomplete="new-password" show-word-limit show-password type="password" placeholder="请输入密码")
el-form-item(label="再次输入密码" prop="passwordAgain" v-if="useSystemStore().systemStatus.currentUser?.fixedUser === 'ENABLE'")
el-form-item(label="再次输入密码" prop="passwordAgain")
ft-input(v-model="form.passwordAgain" maxlength="6" autocomplete="new-password" show-word-limit show-password type="password" placeholder="请输入密码")
</template>

2
src/layouts/default.vue

@ -182,7 +182,7 @@ const remoteControlState = computed(() => {
img(src="../assets/images/logo.svg" alt="" @click="handleLogoClick")
div(class="menu-box")
el-tag(
v-for="item in menuList"
v-for="item in menuList.filter((item) => item.meta?.auth?.includes(systemStore.systemStatus.currentUser?.role))"
:key="item.path"
class="menu-tag"
:effect="router.currentRoute.value.path.includes(item.path) ? 'dark' : 'plain'"

63
src/router/routes.ts

@ -1,28 +1,5 @@
import type { RouteRecordRaw } from 'vue-router'
import n_debug from 'assets/images/menuIcon/n_debug.svg'
import n_expe from 'assets/images/menuIcon/n_expe.svg'
import n_home from 'assets/images/menuIcon/n_home.svg'
import n_liquid from 'assets/images/menuIcon/n_liquid.svg'
import n_liquid_config from 'assets/images/menuIcon/n_liquid_config.svg'
import n_log from 'assets/images/menuIcon/n_log.svg'
import n_ore from 'assets/images/menuIcon/n_ore.svg'
import n_point from 'assets/images/menuIcon/n_point.svg'
import n_ps from 'assets/images/menuIcon/n_ps.svg'
import n_setting from 'assets/images/menuIcon/n_setting.svg'
import n_user from 'assets/images/menuIcon/n_user.svg'
import s_debug from 'assets/images/menuIcon/s_debug.svg'
import s_expe from 'assets/images/menuIcon/s_expe.svg'
import s_home from 'assets/images/menuIcon/s_home.svg'
import s_liquid from 'assets/images/menuIcon/s_liquid.svg'
import s_liquid_config from 'assets/images/menuIcon/s_liquid_config.svg'
import s_log from 'assets/images/menuIcon/s_log.svg'
import s_ore from 'assets/images/menuIcon/s_ore.svg'
import s_point from 'assets/images/menuIcon/s_point.svg'
import s_ps from 'assets/images/menuIcon/s_ps.svg'
import s_setting from 'assets/images/menuIcon/s_setting.svg'
import s_user from 'assets/images/menuIcon/s_user.svg'
const authRoutes: RouteRecordRaw[] = [
{
path: '/home',
@ -31,8 +8,7 @@ const authRoutes: RouteRecordRaw[] = [
meta: {
isDefault: true,
title: '加液',
icon: n_home,
activeIcon: s_home,
auth: ['ADMIN', 'STORE', 'USER'],
},
},
{
@ -42,8 +18,7 @@ const authRoutes: RouteRecordRaw[] = [
meta: {
isDefault: true,
title: '溶液管理',
icon: n_liquid_config,
activeIcon: s_liquid_config,
auth: ['ADMIN', 'STORE', 'USER'],
},
},
{
@ -53,8 +28,7 @@ const authRoutes: RouteRecordRaw[] = [
meta: {
isDefault: true,
title: '加液配方',
icon: n_liquid,
activeIcon: s_liquid,
auth: ['ADMIN', 'STORE', 'USER'],
},
},
{
@ -64,8 +38,7 @@ const authRoutes: RouteRecordRaw[] = [
meta: {
isDefault: true,
title: '领液记录',
icon: n_liquid,
activeIcon: s_liquid,
auth: ['ADMIN', 'STORE'],
},
},
@ -76,31 +49,18 @@ const authRoutes: RouteRecordRaw[] = [
meta: {
isDefault: true,
title: '审计',
icon: n_liquid_config,
activeIcon: s_liquid_config,
},
},
{
path: '/channel',
name: 'channel',
component: () => import('views/channel/index.vue'),
meta: {
isDefault: false,
title: '通道配置',
icon: n_ore,
activeIcon: s_ore,
auth: ['ADMIN'],
},
},
{
path: '/setting',
name: 'setting',
redirect: '/setting/user',
redirect: '/setting/device',
component: () => import('views/setting/index.vue'),
meta: {
isDefault: true,
title: '设置',
icon: n_user,
activeIcon: s_user,
auth: ['ADMIN', 'STORE', 'USER'],
},
children: [
{
@ -121,15 +81,6 @@ const authRoutes: RouteRecordRaw[] = [
title: '设备信息',
},
},
{
path: 'handle',
name: 'handle',
component: () => import('views/setting/handle/index.vue'),
meta: {
isDefault: false,
title: '手柄绑定',
},
},
],
},
]

6
src/types/system.d.ts

@ -17,6 +17,12 @@ declare namespace System {
status: 'start' | 'success' | 'fail'
time: string
}
interface DeviceInfo {
backendSoftwareVersion?: string
deviceSoftwareVersion?: string
remoteControlSoftwareVersion?: string
deviceSn?: string
}
interface ChannelState {
channelCode: 'CHANNEL_1' | 'CHANNEL_2' | 'CHANNEL_3' | 'CHANNEL_4'

48
src/views/setting/device/index.vue

@ -1,4 +1,5 @@
<script setup lang="ts">
import { getDeviceInfo } from 'apis/system'
import { useSystemStore } from 'stores/systemStore'
import { computed } from 'vue'
@ -6,22 +7,57 @@ const systemStore = useSystemStore()
const version = computed(() => {
return __APP_VERSION__
})
const deviceInfo = ref<System.DeviceInfo>({})
onMounted(async () => {
deviceInfo.value = await getDeviceInfo()
})
</script>
<template>
<div>
<div class="device-box">
<p>
<span>软件版本: </span>
<span>{{ systemStore.systemStatus.version }}</span>
<span>{{ version }}</span>
<span>V{{ deviceInfo.backendSoftwareVersion || "--" }}</span>
</p>
<p>
<span>UI版本: </span>
<span>V{{ version || "--" }}</span>
</p>
<p>
<span>设备版本: </span>
<span>V{{ deviceInfo.deviceSoftwareVersion || "--" }}</span>
</p>
<p>
<span>手柄版本: </span>
<span>V{{ deviceInfo.remoteControlSoftwareVersion || "--" }}</span>
</p>
<p>
<span>设备SN: </span>
<span>{{ systemStore.systemStatus.system }}</span>
<span>设备SN: </span>
<span>{{ deviceInfo.deviceSn || "--" }}</span>
</p>
</div>
</template>
<style scoped lang="scss">
.device-box {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0 50px;
gap: 30px;
p{
width: 100%;
padding: 20px;
background: #F6FAFE;
span:first-child{
display: inline-block;
margin-right: 10px;
//width: 70px;
//text-align: right;
}
}
}
</style>

35
src/views/setting/index.vue

@ -1,4 +1,5 @@
<script setup lang="ts">
import { useSystemStore } from 'stores/systemStore'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
@ -7,22 +8,26 @@ const router = useRouter()
onMounted(async () => {
})
const activeName = ref('/user')
const activeName = ref('/device')
const settingList = ref([
{
label: '用户管理',
value: '/user',
},
{
label: '设备信息',
value: '/device',
},
// {
// label: '',
// value: '/handle',
// },
])
const settingList = ref(useSystemStore().systemStatus.currentUser.role === 'ADMIN'
? [
{
label: '设备信息',
value: '/device',
},
{
label: '用户管理',
value: '/user',
},
]
: [
{
label: '设备信息',
value: '/device',
},
])
const routerClickHandle = (path: string) => {
activeName.value = path

42
src/views/setting/user/index.vue

@ -8,7 +8,7 @@ import { useSystemStore } from 'stores/systemStore'
const systemStore = useSystemStore()
const btnList = systemStore.systemStatus.currentUser?.fixedUser === 'ENABLE'
const btnList = systemStore.systemStatus.currentUser?.role === 'ADMIN'
? [
{
name: '新增',
@ -29,12 +29,19 @@ const btnList = systemStore.systemStatus.currentUser?.fixedUser === 'ENABLE'
serverCondition: 2,
},
]
: []
: [
{
name: '编辑',
type: 'primary',
serverUrl: 'edit',
serverCondition: 1,
},
]
const columns = [
{
type: 'selection',
selectable: (row: any) => {
return (row.fixedUser !== 'ENABLE') || row.username === systemStore.systemStatus.currentUser?.username
return systemStore.systemStatus.currentUser.role === 'ADMIN' || row.username === systemStore.systemStatus.currentUser?.username
},
},
{
@ -45,6 +52,35 @@ const columns = [
title: '用户名',
key: 'nickname',
},
{
title: '角色',
key: 'role',
render: (row: any) => {
return h(ElTag, {
type: roleList.find(item => item.value === row.role)?.type,
}, {
default: () => roleList.find(item => item.value === row.role)?.label,
})
},
},
]
const roleList = [
{
label: '管理员',
value: 'ADMIN',
type: 'success',
},
{
label: '仓库管理员',
value: 'STORE',
type: 'primary',
},
{
label: '普通用户',
value: 'USER',
type: 'info',
},
]
const tableRef = ref()

Loading…
Cancel
Save