自营商家和合作商家入口分开,添加智能柜角色切换

This commit is contained in:
weiwei committed 2025-04-22 18:31:18 +08:00
1 parent e34cc2736c
commit 1a74921af9
5 files changed
+119 -96

No files matched your search

+57 -53
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import isDevEnv from "./sheep/utils/isDevEnv"
import { getAppInfo } from "@@/utils/getAppInfo"
import getLaunchParam from "@/sheep/utils/getLaunchParam"
// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
// onLaunch(() => {})
@@ -38,7 +39,7 @@ const tabbar: TabbarItem[] = [
text: "合作商家",
iconPath: "/static/tabbar/coopMerchant.png",
selectedIconPath: "/static/tabbar/coopMerchant-select.png",
launchParam: ["selfMerchant"],
launchParam: ["coopMerchant"],
auth: ["user"],
},
{
@@ -47,14 +48,14 @@ const tabbar: TabbarItem[] = [
iconPath: "/static/tabbar/cabinet.png",
selectedIconPath: "/static/tabbar/cabinet-select.png",
launchParam: [],
auth: ["cabinetAdmin"],
auth: ["doorAdmin"],
},
{
pagePath: "pages/tabbar/order",
text: "订单",
iconPath: "/static/tabbar/order.png",
selectedIconPath: "/static/tabbar/order-select.png",
launchParam: ["canteen", "selfMerchant"],
launchParam: ["canteen", "selfMerchant", "coopMerchant"],
auth: ["user"],
},
{
@@ -79,15 +80,10 @@ const tabbar: TabbarItem[] = [
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant", "coopMerchant"],
auth: ["user", "merchant"],
auth: ["user", "merchant", "doorAdmin"],
},
]
// 获取启动参数
const getLaunchParam = () => {
return new URL(window.location.href).searchParams.get("launchParam")
}
// 设置tabbar项目
const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
uni.setTabBarItem({
@@ -101,28 +97,26 @@ const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
}
// 根据启动参数设置tabbar项目
const setTabbarByLaunchParam = (launchParam: string) => {
tabbar.forEach((item, index) => {
const visible = item.launchParam.includes(launchParam)
setTabbarItem(index, item, visible)
})
}
// 根据用户角色设置tabbar项目
const setTabbarByUserRole = (role: string) => {
tabbar.forEach((item, index) => {
let visible = false
if (item.auth.includes("cabinetAdmin")) {
if (uni.getStorageSync("isHardDoorAdmin") == "true") {
visible = true
} else {
visible = false
}
} else {
visible = item.auth.includes(role)
}
setTabbarItem(index, item, visible)
})
const setTabbar = (launchParam?: string, auth?: string) => {
if (launchParam && !auth) {
tabbar.forEach((item, index) => {
const visible = item.launchParam.includes(launchParam)
setTabbarItem(index, item, visible)
})
return
}
if (!launchParam && auth) {
tabbar.forEach((item, index) => {
const visible = item.auth.includes(auth)
setTabbarItem(index, item, visible)
})
}
if (launchParam && auth) {
tabbar.forEach((item, index) => {
const visible = item.launchParam.includes(launchParam) && item.auth.includes(auth)
setTabbarItem(index, item, visible)
})
}
}
export default {
@@ -135,17 +129,16 @@ export default {
const appInfo = await getAppInfo()
if (appInfo == "zzd") {
// 浙政钉环境
const launchParam = getLaunchParam()
console.log("app launch 启动路径参数", launchParam)
switch (launchParam) {
switch (getLaunchParam()) {
case "canteen":
uni.switchTab({ url: "/pages/tabbar/canteen" })
break
case "selfMerchant":
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
break
case "coopMerchant":
uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
break
default:
break
}
@@ -156,7 +149,10 @@ export default {
case "merchant":
return uni.switchTab({ url: "/pages/tabbar/individualOrder" })
case "user":
return uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
if (getLaunchParam() === "selfMerchant") return uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
if (getLaunchParam() === "coopMerchant") return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
case "doorAdmin":
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
default:
return uni.redirectTo({ url: "/pages/user/userRole" })
}
@@ -175,13 +171,12 @@ export default {
}
const launchParam = getLaunchParam()
console.log("tabbar launch 启动路径参数", launchParam)
const appInfo = await getAppInfo()
if (appInfo == "zzd") {
// 浙政钉环境
if (launchParam) {
setTabbarByLaunchParam(launchParam)
setTabbar(launchParam)
uni.showTabBar()
} else {
uni.hideTabBar()
@@ -190,20 +185,29 @@ export default {
} else if (appInfo == "sh") {
// 是诗画环境
const userRole = uni.getStorageSync("userRole")
switch (userRole) {
case "user":
setTabbarByUserRole("user")
uni.showTabBar()
break
case "merchant":
setTabbarByUserRole("merchant")
uni.showTabBar()
break
default:
uni.hideTabBar()
uni.removeStorageSync("userRole")
uni.showToast({ title: "用户身份未确认", icon: "none" })
break
if (launchParam) {
switch (userRole) {
case "user":
setTabbar(launchParam, "user")
uni.showTabBar()
break
case "merchant":
setTabbar(undefined, "merchant")
uni.showTabBar()
break
case "doorAdmin":
setTabbar(undefined, "doorAdmin")
uni.showTabBar()
break
default:
uni.hideTabBar()
uni.removeStorageSync("userRole")
uni.showToast({ title: "用户身份未确认", icon: "none" })
break
}
} else {
uni.hideTabBar()
uni.showToast({ title: "启动参数不合法", icon: "none" })
}
}
},