Files
pj_h5_cloud/src/App.vue
T
2025-04-02 10:12:49 +08:00

281 lines
6.9 KiB
Vue

<script lang="ts">
import user from "./sheep/api/user"
import isDevEnv from "./sheep/utils/isDevEnv"
// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
// onLaunch(() => {})
// onShow(() => {})
// onHide(() => {})
const tabbar = [
{
pagePath: "pages/tabbar/canteen",
text: "食堂",
iconPath: "/static/tabbar/canteen.png",
selectedIconPath: "/static/tabbar/canteen-select.png",
authPath: ["pages/tabbar/canteen"],
auth: [],
},
{
pagePath: "pages/tabbar/selfMerchant",
text: "自营商家",
iconPath: "/static/tabbar/selfMerchant.png",
selectedIconPath: "/static/tabbar/selfMerchant-select.png",
authPath: ["pages/tabbar/selfMerchant"],
auth: [],
},
{
pagePath: "pages/tabbar/coopMerchant",
text: "合作商家",
iconPath: "/static/tabbar/coopMerchant.png",
selectedIconPath: "/static/tabbar/coopMerchant-select.png",
authPath: ["pages/tabbar/selfMerchant"],
auth: ["user"],
},
{
pagePath: "pages/tabbar/order",
text: "订单",
iconPath: "/static/tabbar/order.png",
selectedIconPath: "/static/tabbar/order-select.png",
authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"],
auth: ["user"],
},
{
pagePath: "pages/tabbar/flowStatistics",
text: "流水统计",
iconPath: "/static/tabbar/order.png",
selectedIconPath: "/static/tabbar/order-select.png",
authPath: [],
auth: ["merchant"],
},
{
pagePath: "pages/tabbar/individualOrder",
text: "订单",
iconPath: "/static/tabbar/order.png",
selectedIconPath: "/static/tabbar/order-select.png",
authPath: [],
auth: ["merchant"],
},
{
pagePath: "pages/tabbar/my",
text: "我的",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"],
auth: ["user", "merchant"],
},
]
export default {
async onLaunch() {
if (isDevEnv()) return
console.log("环境判断")
// 诗画浦江获取用户信息进行环境判断
const res = await (window as any).CP2.getAppInfo()
if (res.code == 0) {
// 不是诗画环境
const launchParam = new URL(window.location.href).searchParams.get("launchParam")
console.log("app launch 启动路径参数", launchParam)
switch (launchParam) {
case "canteen":
uni.switchTab({ url: "/pages/tabbar/canteen" })
break
case "selfMerchant":
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
break
default:
break
}
} else {
// 是诗画环境
const userRole = uni.getStorageSync("userRole")
if (userRole && userRole == "user") uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
if (userRole && userRole == "merchant") uni.switchTab({ url: "/pages/tabbar/individualOrder" })
const res = await user.isMerchant()
if (res.code == 0) {
if (res.data) {
return uni.redirectTo({ url: "/pages/user/userRole" })
} else {
uni.setStorageSync("userRole", "user")
uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
}
} else {
uni.showToast({ title: "角色身份判断失败", icon: "none" })
}
}
},
onShow() {},
onHide() {},
methods: {
async _initTabbar() {
if (isDevEnv()) {
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: true,
})
})
return
}
const launchParam = new URL(window.location.href).searchParams.get("launchParam")
console.log("tabbar launch 启动路径参数", launchParam)
// 诗画浦江获取用户信息进行环境判断
const res = await (window as any).CP2.getAppInfo()
if (res.code == 0) {
// 不是诗画环境
switch (launchParam) {
case "canteen":
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => {
if (authPath.includes("pages/tabbar/canteen")) {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: true,
})
} else {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: false,
})
}
})
break
case "selfMerchant":
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => {
if (authPath.includes("pages/tabbar/selfMerchant")) {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: true,
})
} else {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: false,
})
}
})
break
default:
uni.hideTabBar()
uni.showToast({ title: "启动参数不合法", icon: "none" })
break
}
} else {
// 是诗画环境
const userRole = uni.getStorageSync("userRole")
switch (userRole) {
case "user":
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => {
if (auth.includes("user")) {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: true,
})
} else {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: false,
})
}
})
break
case "merchant":
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => {
if (auth.includes("merchant")) {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: true,
})
} else {
uni.setTabBarItem({
index,
pagePath,
text,
iconPath,
selectedIconPath,
visible: false,
})
}
})
break
default:
uni.hideTabBar()
uni.showToast({ title: "用户身份未确认", icon: "none" })
break
}
}
},
},
}
</script>
<style lang="scss">
@import "@/sheep/scss/global.scss";
@import url(@/uni_modules/tm-ui/css/remixicon.min.css);
$theme-green: #06be36;
$theme-blue: #0094ff;
$theme-gray: #999;
.botder_btn {
border: 1px solid #999;
color: #999;
font-weight: 500;
font-size: 28rpx;
border-radius: 10rpx;
padding: 8rpx 15rpx;
}
.prefix_title {
font-size: 32rpx;
font-weight: 500;
color: #333;
&::before {
content: "";
display: inline-block;
width: 8rpx;
height: 24rpx;
background: $theme-blue;
border-radius: 4rpx;
margin-right: 10rpx;
}
}
</style>