update: 更新权限控制

This commit is contained in:
admin 2024-04-12 15:53:44 +08:00
parent 8b7f25969a
commit 9110ec39c1
6 changed files with 196 additions and 82 deletions

View File

@ -1,6 +1,14 @@
<template> <template>
<Box> <Box
<view v-for="(item, index) in list" :key="index"> v-if="
isShowModule(list[0].child.concat(list[1].child).concat(list[2].child))
"
>
<view
v-for="(item, index) in list"
:key="index"
v-show="isShowModule(item.child)"
>
<view class="title"> <view class="title">
<Title :title="item.title" /> <Title :title="item.title" />
</view> </view>
@ -9,8 +17,10 @@
v-for="(child, index) in item.child" v-for="(child, index) in item.child"
:key="index" :key="index"
@click="(child as any).fn(child)" @click="(child as any).fn(child)"
v-show="isShowModule([{title: child.title}])"
:class="{'box': isShowModule([{title: child.title}])}"
> >
<view> <view v-if="isShowModule([{title: child.title}])">
<up-image <up-image
:src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pagesStatistics/${child.icon}`" :src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pagesStatistics/${child.icon}`"
mode="aspectFill" mode="aspectFill"
@ -18,19 +28,30 @@
height="60rpx" height="60rpx"
></up-image> ></up-image>
</view> </view>
<view>{{ child.title }}</view> <view v-if="isShowModule([{title: child.title}])">{{ child.title }}</view>
</view> </view>
</view> </view>
<view class="line" v-show="index < list.length - 1"></view> <view class="line" v-show="index < list.length - 1"></view>
</view> </view>
</Box> </Box>
<!-- 当收货 出货 常用app全部为空 显示暂无权限 -->
<up-empty
v-else
mode="permission"
icon="http://cdn.uviewui.com/uview/empty/permission.png"
:text="'暂无相关权限, 请联系管理员'"
>
</up-empty>
<TabBar></TabBar> <TabBar></TabBar>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import Box from "@/components/Box/index.vue"; import Box from "@/components/Box/index.vue";
import Title from "@/components/Title/index.vue"; import Title from "@/components/Title/index.vue";
import TabBar from "@/components/TabBar/index.vue"; import TabBar from "@/components/TabBar/index.vue";
import { useMemberStore } from "@/store/index";
import { ProfileApi } from "@/services";
const store = useMemberStore();
const list = reactive([ const list = reactive([
{ {
title: "收货", title: "收货",
@ -111,6 +132,27 @@ const list = reactive([
], ],
}, },
]); ]);
// app
const isShowModule = (list: any) => {
let flag = false;
list.forEach((item: any) => {
if (store.profile.menusNameList.indexOf(item.title) > -1) {
flag = true;
return;
}
});
return flag;
};
onMounted(() => {
//
ProfileApi.getUserInfo().then((res:any) => {
if (res.code === 200) {
store.setProfile({...res.data, token: store.profile.token});
}
});
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.title { .title {
@ -121,7 +163,7 @@ const list = reactive([
display: flex; display: flex;
margin: 22rpx 0rpx; margin: 22rpx 0rpx;
padding: 0rpx 20rpx; padding: 0rpx 20rpx;
> view { .box {
width: 142rpx; width: 142rpx;
height: 142rpx; height: 142rpx;
background: #f9f9f9; background: #f9f9f9;
@ -143,7 +185,7 @@ const list = reactive([
width: 100%; width: 100%;
} }
} }
> view + view { > .box + .box {
margin-left: 32rpx; margin-left: 32rpx;
} }
::v-deep .u-transition { ::v-deep .u-transition {

View File

@ -16,7 +16,9 @@
backgroundSize: 'cover', backgroundSize: 'cover',
}" --> }" -->
<view class="panel" v-for="(item, index) in summaryList" :key="index"> <view class="panel" v-for="(item, index) in summaryList" :key="index">
<image :src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pages/${item.imgUrl}`" /> <image
:src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pages/${item.imgUrl}`"
/>
<view class="box"> <view class="box">
<view class="num">{{ item.num }}</view> <view class="num">{{ item.num }}</view>
<view class="title">{{ item.title }}</view> <view class="title">{{ item.title }}</view>
@ -25,18 +27,26 @@
</view> </view>
<view class="data-detail"> <view class="data-detail">
<view class="p-15"> <view
class="p-15"
v-if="isShowModule(receiveList) || isShowModule(shipmentList)"
>
<!-- 收货入库 --> <!-- 收货入库 -->
<view v-if="isShowModule(receiveList)">
<text class="title">收货入库</text> <text class="title">收货入库</text>
<view class="data-receive"> <view class="data-receive">
<up-row justify="center" gutter="10"> <up-row justify="flex-start" gutter="10">
<up-col <up-col
span="3" span="3"
v-for="(item, index) in receiveList" v-for="(item, index) in receiveList"
:key="index" :key="index"
@click="(item as any).fn()" @click="(item as any).fn()"
:customStyle="{
display: isShowModule([{ title: item.title }]) ? '' : 'none',
}"
> >
<view <view
v-if="isShowModule([{ title: item.title }])"
class="box" class="box"
:style="{ :style="{
backgroundColor: boxStyleList[index].backgroundColor, backgroundColor: boxStyleList[index].backgroundColor,
@ -57,18 +67,24 @@
</up-col> </up-col>
</up-row> </up-row>
</view> </view>
</view>
<!-- 出货入库 --> <!-- 出货入库 -->
<view v-if="isShowModule(shipmentList)">
<text class="title title-shipment">出货销售</text> <text class="title title-shipment">出货销售</text>
<view class="data-shipment"> <view class="data-shipment">
<up-row justify="center" gutter="10"> <up-row justify="flex-start" gutter="10">
<up-col <up-col
span="3" span="3"
v-for="(item, index) in shipmentList" v-for="(item, index) in shipmentList"
:key="index" :key="index"
@click="(item as any).fn()" @click="(item as any).fn()"
:customStyle="{
display: isShowModule([{ title: item.title }]) ? '' : 'none',
}"
> >
<view <view
v-if="isShowModule([{ title: item.title }])"
class="box" class="box"
:style="{ :style="{
backgroundColor: boxStyleList[index].backgroundColor, backgroundColor: boxStyleList[index].backgroundColor,
@ -90,29 +106,49 @@
</up-row> </up-row>
</view> </view>
</view> </view>
</view>
<!-- 线条 --> <!-- 线条 -->
<view class="line"> </view> <view class="line"> </view>
<!-- 常用应用 --> <!-- 常用应用 -->
<view class="app-list"> <view class="app-list" v-if="isShowModule(appList)">
<view class="name">常用应用</view> <view class="name">常用应用</view>
<u-grid :border="false" col="4"> <u-grid :border="false" col="4">
<u-grid-item <u-grid-item
v-for="(item, listIndex) in appList" v-for="(item, listIndex) in appList"
:key="listIndex" :key="listIndex"
@click="item.fn" @click="item.fn"
:customStyle="{
display: isShowModule([{ title: item.title }]) ? '' : 'none',
}"
> >
<up-image <up-image
v-if="isShowModule([{ title: item.title }])"
:src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pagesHome/${item.icon}`" :src="`https://backend-common.obs.cn-east-3.myhuaweicloud.com/static/pagesHome/${item.icon}`"
width="60rpx" width="60rpx"
height="60rpx" height="60rpx"
></up-image> ></up-image>
<text class="grid-text">{{ item.title }}</text> <text
class="grid-text"
v-if="isShowModule([{ title: item.title }])"
>{{ item.title }}</text
>
</u-grid-item> </u-grid-item>
</u-grid> </u-grid>
</view> </view>
</view> </view>
<!-- 当收货 出货 常用app全部为空 显示暂无权限 -->
<up-empty
v-if="
!isShowModule(receiveList.concat(shipmentList)) &&
!isShowModule(appList)
"
mode="permission"
icon="http://cdn.uviewui.com/uview/empty/permission.png"
:text="'暂无相关权限, 请联系管理员'"
>
</up-empty>
</view> </view>
<TabBar /> <TabBar />
@ -120,8 +156,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { useMemberStore } from "@/store/index"; import { useMemberStore } from "@/store/index";
import { ReceiveApi, ShipmentApi } from "@/services/index"; import { ProfileApi, ReceiveApi, ShipmentApi } from "@/services/index";
import TabBar from '@/components/TabBar/index.vue' import TabBar from "@/components/TabBar/index.vue";
const store = useMemberStore(); const store = useMemberStore();
const navbarRect = reactive({ const navbarRect = reactive({
height: 32, height: 32,
@ -438,9 +474,6 @@ const appList = reactive([
}, },
}, },
]); ]);
// //
ReceiveApi.countOrderByMonth().then((res) => { ReceiveApi.countOrderByMonth().then((res) => {
if (res.code === 200) { if (res.code === 200) {
@ -479,6 +512,19 @@ ShipmentApi.countOrderByMonth().then((res) => {
shipmentList[3].num = toBeSettled; shipmentList[3].num = toBeSettled;
} }
}); });
// app
const isShowModule = (list: any) => {
let flag = false;
list.forEach((item: any) => {
if (store.profile.menusNameList.indexOf(item.title) > -1) {
flag = true;
return;
}
});
return flag;
};
onMounted(() => { onMounted(() => {
// #ifdef APP-PLUS || MP-WEIXIN // #ifdef APP-PLUS || MP-WEIXIN
let menuButtonInfo = uni.getMenuButtonBoundingClientRect(); let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
@ -486,7 +532,12 @@ onMounted(() => {
navbarRect.top = menuButtonInfo.top; navbarRect.top = menuButtonInfo.top;
getSafeHeight(); getSafeHeight();
// #endif // #endif
// //
ProfileApi.getUserInfo().then((res: any) => {
if (res.code === 200) {
store.setProfile({ ...res.data, token: store.profile.token });
}
});
}); });
</script> </script>
@ -533,7 +584,7 @@ onMounted(() => {
} }
.data-detail { .data-detail {
margin-top: 15rpx; margin-top: 15rpx;
box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12); // box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
border-radius: 13rpx; border-radius: 13rpx;
position: relative; position: relative;
.title { .title {

View File

@ -1,5 +1,6 @@
// 存放路径: src/services/home.ts // 存放路径: src/services/home.ts
import type { User } from "@/types/user";
import { http } from "@/utils/http"; import { http } from "@/utils/http";
// 登陆 // 登陆
@ -180,11 +181,10 @@ export const getUserListByPage = (data: any) => {
}; };
// 获取用户信息 // 获取用户信息
export const getUserInfo = (data: any) => { export const getUserInfo = () => {
return http({ return http({
method: "GET", method: "GET",
url: "/api/user/getUserInfo", url: "/api/user/getUserInfo",
data
}); });
}; };

View File

@ -1,23 +1,26 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
import _ from "underscore";
import type { LoginResult } from "@/types/user";
// 定义 Store // 定义 Store
export const useMemberStore = defineStore( export const useMemberStore = defineStore(
"member", "member",
() => { () => {
// 会员信息 // 会员信息
const profile = ref({ const profile = ref<LoginResult>({
token: '', token: '',
userInfo: { userInfo: {
userName: "", userName: "",
factory_name: "", factoryName: "",
}, },
menusList:[],
menusNameList: []
}); });
// 保存会员信息,登录时使用 // 保存会员信息,登录时使用
const setProfile = (val: any) => { const setProfile = (val: any) => {
profile.value = val; profile.value = val;
profile.value.menusNameList = _.pluck(val.menusList, "name");
}; };
// 清理会员信息,退出时使用 // 清理会员信息,退出时使用

10
src/types/global.d.ts vendored
View File

@ -22,3 +22,13 @@ export type Result = {
} }
export type ComType = {[attrName: string]: any } export type ComType = {[attrName: string]: any }
export type BaseField = {
updateTime: string;
createTime: string;
createUserId: number;
createUserName: string;
updateUserId: number;
updateUserName: string;
isDeleted: boolean;
}

26
src/types/user.d.ts vendored
View File

@ -1,4 +1,4 @@
interface User { export type User = {
name: string; name: string;
gender: number; // 性别1=男2=女 gender: number; // 性别1=男2=女
phone: string; phone: string;
@ -11,16 +11,9 @@ interface User {
userName: string; userName: string;
password: string; password: string;
state: number; // 状态 1=有效 0=无效 state: number; // 状态 1=有效 0=无效
updateTime: string;
createTime: string;
createUserId: number;
createUserName: string;
updateUserId: number;
updateUserName: string;
isDeleted: boolean;
cardCode?: string; // 卡号 cardCode?: string; // 卡号
roleVos?: array roleVos?: array
} } & BaseField;
interface Customer { interface Customer {
name?: string, name?: string,
@ -28,3 +21,18 @@ interface Customer {
contacts?:string, contacts?:string,
cardCode?: string, cardCode?: string,
} }
export type MenusItem = {
id: number,
name: string,
[attrName: string]: any;
}
export type LoginResult = {
menusList: array<MenusItem>
token: string,
userId?:string,
userInfo: User,
userName?: string,
[attrName: string]: any;
}