fix: 更新菜单项属性名称为label,并调整权限判断逻辑

This commit is contained in:
傅光孟 2026-02-27 17:57:51 +08:00
parent 627d0b006a
commit 685bcc76a8
3 changed files with 73 additions and 21 deletions

View File

@ -4,9 +4,9 @@
<text class="date"> 数据更新时间{{ date }} </text>
</view>
<u-grid class="menu" :col="5" :border="false" align="center">
<u-grid-item v-for="menu in menus" @click="goto(menu.path, menu.auth)">
<u-grid-item v-for="menu in menus" @click="goto(menu)">
<image :src="menu.icon" class="menu-icon"></image>
<text class="menu-text">{{ menu.name }}</text>
<text class="menu-text">{{ menu.label }}</text>
</u-grid-item>
</u-grid>
</view>
@ -24,33 +24,33 @@ import { useUserStore } from "@/stores/user";
const menus = reactive([
{
name: "海外先机",
label: "海外先机",
name: "hwxj",
icon: MENUICON1,
// auth: "menu1",
path: "/pages/foreign/index",
},
{
name: "编辑精选",
label: "编辑精选",
name: "bjjx",
icon: MENUICON2,
// auth: "menu2",
path: "/pages/recommend/index",
},
{
name: "宏观知微",
label: "宏观知微",
name: "hgzw",
icon: MENUICON3,
// auth: "menu3",
path: "/pages/macroscopic/index",
},
{
name: "热门行业",
label: "热门行业",
name: "rthx",
icon: MENUICON4,
// auth: "menu4",
path: "/pages/industry/index",
},
{
name: "风口概念",
label: "风口概念",
name: "fkgn",
icon: MENUICON5,
// auth: "menu5",
path: "/pages/concept/index",
},
]);
@ -61,7 +61,7 @@ const userInfos = computed(() => {
});
const emit = defineEmits(["onShow"]);
const goto = (path: string, auth: string) => {
const goto = (menu: any) => {
if (!userStore.isLogin) {
emit("onShow");
return;
@ -76,8 +76,17 @@ const goto = (path: string, auth: string) => {
return;
}
const isAuth = userInfos.value?.auth?.findIndex((item) => item.name === menu.name);
if (isAuth === -1 || userInfos.value?.auth[isAuth]?.enabled === 0) {
uni.showToast({
title: "暂未开通本栏目",
icon: "none",
});
return;
}
uni.navigateTo({
url: path,
url: menu.path,
});
};
</script>

View File

@ -36,11 +36,14 @@
<script setup lang="ts">
import { getTopNews } from "@/api/newsInfo";
import dayjs from "dayjs";
import { onMounted, reactive, ref } from "vue";
import { computed, onMounted, reactive, ref } from "vue";
import { useUserStore } from "@/stores/user";
const emit = defineEmits(["onShow"]);
const userStore = useUserStore();
const userInfos = computed(() => {
return userStore.getUserInfos();
});
//
const loading = ref(false);
const newsListAll = ref([]); //
@ -78,6 +81,16 @@ const navigateTo = () => {
emit("onShow");
return;
}
const isAuth = userInfos.value?.auth?.findIndex((item) => item.name === 'znzx');
if (isAuth === -1 || userInfos.value?.auth[isAuth]?.enabled === 0) {
uni.showToast({
title: "暂未开通本栏目",
icon: "none",
});
return;
}
uni.navigateTo({
url: "/pages/topNews/index",
});

View File

@ -7,9 +7,10 @@ type IUserInfos = {
id?: string;
phone: string;
name?: string;
auth: string[];
auth: any[];
role: string[];
accountType: number;
permissions?: any[];
};
const storeSetup = () => {
@ -23,7 +24,36 @@ const storeSetup = () => {
});
const setUserInfos = (payload: Partial<IUserInfos>) => {
userInfos.value = { ...userInfos.value, ...payload };
// 权限暂时写死,后续根据接口返回的权限进行调整
const auth = [
{
name: "hwxj",
enabled: 1,
},
{
name: "bjjx",
enabled: 1,
},
{
name: "hgzw",
enabled: 1,
},
{
name: "znzx",
enabled: 1,
},
{
name: "rthx",
enabled: 1,
},
{
name: "fkgn",
enabled: 1,
},
];
// 获取权限
// const auth = payload.permissions || [];
userInfos.value = { ...userInfos.value, ...payload, auth };
Session.set("userInfos", userInfos.value);
};
@ -53,10 +83,10 @@ const storeSetup = () => {
// 试用 | 正式
const isUserType = computed(() => {
// 0:测试 1:正式 判断账号类型
return getUserInfos()?.accountType === 1 ? true : false;
// return getUserInfos()?.accountType === 1 ? true : false;
// 为了兼容之前的版本,暂时不区分账号类型,先放开正式账号和测试账号的限制
// return true;
return true;
});
// 登录
@ -86,7 +116,7 @@ const storeSetup = () => {
});
setToken(result.data.token);
setUserInfos({ ...result.data });
// 为了兼容之前的版本,暂时保留 userPhone 字段
Session.set("userPhone", data.phone);