修改
This commit is contained in:
1 parent
374717bc5c
commit
29b92a3e61
2 files changed
+331
-441
No files matched your search
+154
-156
@@ -67,181 +67,179 @@ const tabbar = [
|
||||
]
|
||||
|
||||
export default {
|
||||
onLaunch() {
|
||||
async onLaunch() {
|
||||
if (isDevEnv()) return
|
||||
|
||||
console.log("环境判断")
|
||||
// 诗画浦江获取用户信息进行环境判断
|
||||
;(window as any).CP2.getAppInfo().then(async (res) => {
|
||||
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
|
||||
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 {
|
||||
// 是诗画环境
|
||||
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" })
|
||||
}
|
||||
uni.showToast({ title: "角色身份判断失败", icon: "none" })
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
onShow() {},
|
||||
onHide() {},
|
||||
|
||||
methods: {
|
||||
_initTabbar() {
|
||||
// const launchPath = uni.getLaunchOptionsSync().path
|
||||
// console.log("启动路径", launchPath)
|
||||
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)
|
||||
|
||||
// 诗画浦江获取用户信息进行环境判断
|
||||
;(window as any).CP2.getAppInfo().then((res) => {
|
||||
if (res.code == 0) {
|
||||
// 不是诗画环境
|
||||
if (isDevEnv()) {
|
||||
tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => {
|
||||
uni.setTabBarItem({
|
||||
index,
|
||||
pagePath,
|
||||
text,
|
||||
iconPath,
|
||||
selectedIconPath,
|
||||
visible: true,
|
||||
})
|
||||
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,
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
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,
|
||||
})
|
||||
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,
|
||||
})
|
||||
}
|
||||
} 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
|
||||
}
|
||||
}
|
||||
})
|
||||
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
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user