修复
This commit is contained in:
1 parent
e1365d6850
commit
6ee2503332
2 files changed
+172
-119
No files matched your search
+145
-109
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue"
|
||||
import { APPENV } from "@/sheep/constant"
|
||||
import { INTEGRATED_ENTRIES, getIntegratedPageByLaunchParam } from "@/sheep/constant/integrated-entry"
|
||||
import { getAppInfo, getLaunchParam, getUrlQueryParam, isDevEnv } from "@/sheep/utils/app"
|
||||
@@ -67,13 +68,18 @@ const moduleList = [
|
||||
})),
|
||||
]
|
||||
|
||||
/** loading | ok(已跳转离开) | error */
|
||||
const bootStatus = ref<"loading" | "error">("loading")
|
||||
const bootMessage = ref("加载中...")
|
||||
let jumping = false
|
||||
|
||||
onShow(() => {
|
||||
const fromUrl = getUrlQueryParam("launchParam")
|
||||
if (fromUrl) {
|
||||
uni.setStorageSync("launchParam", fromUrl)
|
||||
}
|
||||
if (!isDevEnv()) {
|
||||
jumpByParam()
|
||||
void jumpByParam()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -87,115 +93,141 @@ async function jumpIntegratedSubPage(launchParam: string): Promise<boolean> {
|
||||
return true
|
||||
}
|
||||
|
||||
function failBoot(msg: string) {
|
||||
bootStatus.value = "error"
|
||||
bootMessage.value = msg
|
||||
uni.hideTabBar()
|
||||
}
|
||||
|
||||
const jumpByParam = async () => {
|
||||
const appInfo = await getAppInfo() // 环境判断
|
||||
const launchParam = getLaunchParam() // 获取启动参数
|
||||
if (jumping) return
|
||||
jumping = true
|
||||
bootStatus.value = "loading"
|
||||
bootMessage.value = "加载中..."
|
||||
try {
|
||||
const appInfo = await getAppInfo()
|
||||
const launchParam = getLaunchParam()
|
||||
|
||||
// 浙政钉环境(诗画不走此分支)
|
||||
if (appInfo == APPENV.ZZD) {
|
||||
const { tryZzdEntryLogin } = await import("@/sheep/utils/request")
|
||||
const zzdR = await tryZzdEntryLogin()
|
||||
if (zzdR !== "ok") return
|
||||
if (await jumpIntegratedSubPage(launchParam)) return
|
||||
switch (launchParam) {
|
||||
case "thirdApp":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/thirdApp/happyMall" })
|
||||
case "canteen": // 食堂
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/canteen" })
|
||||
break
|
||||
case "selfMerchant": // 自营商家
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
break
|
||||
case "onlineShop": // 在线商城
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/onlineShop" })
|
||||
break
|
||||
case "coopMerchant": // 合作商家
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
|
||||
break
|
||||
case "integrated": // 综合服务
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/integrated" })
|
||||
break
|
||||
case "prosperityShop": // 共富商城
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/prosperityShop" })
|
||||
break
|
||||
case "prosperityShopMchList": // 共富商城(商家模式)
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/prosperityShopMchList" })
|
||||
break
|
||||
default:
|
||||
if (!launchParam) {
|
||||
uni.showToast({ title: "缺少入口参数,请从工作台重新进入", icon: "none", duration: 3500 })
|
||||
} else {
|
||||
uni.showToast({ title: "暂不支持的入口:" + launchParam, icon: "none", duration: 3500 })
|
||||
}
|
||||
uni.hideTabBar()
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 诗画环境
|
||||
if (appInfo == APPENV.SH) {
|
||||
const userRole = uni.getStorageSync("userRole") // 获取用户角色
|
||||
|
||||
if (!launchParam) return uni.hideTabBar()
|
||||
if (launchParam == "thirdApp") return uni.reLaunch({ url: "/pages/thirdApp/happyMall" })
|
||||
|
||||
switch (userRole) {
|
||||
case "merchant":
|
||||
return uni.switchTab({ url: "/pages/tabbar/individualOrder" })
|
||||
case "user":
|
||||
// 注意:case 之间不能 fallthrough;以前 canteen 未处理会掉进 doorAdmin → 智能柜
|
||||
if (launchParam === "canteen") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/canteen" })
|
||||
}
|
||||
if (launchParam === "selfMerchant") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
}
|
||||
if (launchParam === "onlineShop") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/onlineShop" })
|
||||
}
|
||||
if (launchParam === "prosperityShop") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/prosperityShop" })
|
||||
}
|
||||
if (launchParam === "prosperityShopMchList") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/prosperityShopMchList" })
|
||||
}
|
||||
if (launchParam === "coopMerchant") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
}
|
||||
if (launchParam === "integrated") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/integrated" })
|
||||
}
|
||||
if (launchParam === "cabinet") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
|
||||
}
|
||||
if (await jumpIntegratedSubPage(launchParam)) return
|
||||
uni.showToast({ title: "暂不支持的入口:" + launchParam, icon: "none", duration: 3500 })
|
||||
if (appInfo == APPENV.ZZD) {
|
||||
const { tryZzdEntryLogin } = await import("@/sheep/utils/request")
|
||||
const zzdR = await tryZzdEntryLogin()
|
||||
if (zzdR === "sms") return
|
||||
if (zzdR !== "ok") {
|
||||
failBoot("登录失败,请关闭后从工作台重新进入,或点击下方重试")
|
||||
return
|
||||
case "doorAdmin":
|
||||
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
|
||||
default:
|
||||
return uni.redirectTo({ url: "/pages/user/userRole" })
|
||||
}
|
||||
if (await jumpIntegratedSubPage(launchParam)) return
|
||||
switch (launchParam) {
|
||||
case "thirdApp":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/thirdApp/happyMall" })
|
||||
case "canteen":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/canteen" })
|
||||
break
|
||||
case "selfMerchant":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
break
|
||||
case "onlineShop":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/onlineShop" })
|
||||
break
|
||||
case "coopMerchant":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
|
||||
break
|
||||
case "integrated":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/integrated" })
|
||||
break
|
||||
case "prosperityShop":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/prosperityShop" })
|
||||
break
|
||||
case "prosperityShopMchList":
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
uni.switchTab({ url: "/pages/tabbar/prosperityShopMchList" })
|
||||
break
|
||||
default:
|
||||
if (!launchParam) {
|
||||
failBoot("缺少入口参数,请从浙政钉工作台对应应用重新进入(勿直接打开无 launchParam 的链接)")
|
||||
} else {
|
||||
failBoot("暂不支持的入口:" + launchParam)
|
||||
}
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (appInfo == APPENV.SH) {
|
||||
const userRole = uni.getStorageSync("userRole")
|
||||
|
||||
if (!launchParam) {
|
||||
failBoot("缺少入口参数,请从门户重新进入")
|
||||
return
|
||||
}
|
||||
if (launchParam == "thirdApp") return uni.reLaunch({ url: "/pages/thirdApp/happyMall" })
|
||||
|
||||
switch (userRole) {
|
||||
case "merchant":
|
||||
return uni.switchTab({ url: "/pages/tabbar/individualOrder" })
|
||||
case "user":
|
||||
if (launchParam === "canteen") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/canteen" })
|
||||
}
|
||||
if (launchParam === "selfMerchant") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
}
|
||||
if (launchParam === "onlineShop") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/onlineShop" })
|
||||
}
|
||||
if (launchParam === "prosperityShop") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/prosperityShop" })
|
||||
}
|
||||
if (launchParam === "prosperityShopMchList") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/prosperityShopMchList" })
|
||||
}
|
||||
if (launchParam === "coopMerchant") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
}
|
||||
if (launchParam === "integrated") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.reLaunch({ url: "/pages/tabbar/integrated" })
|
||||
}
|
||||
if (launchParam === "cabinet") {
|
||||
uni.setStorageSync("launchParam", launchParam)
|
||||
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
|
||||
}
|
||||
if (await jumpIntegratedSubPage(launchParam)) return
|
||||
failBoot("暂不支持的入口:" + launchParam)
|
||||
return
|
||||
case "doorAdmin":
|
||||
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
|
||||
default:
|
||||
return uni.redirectTo({ url: "/pages/user/userRole" })
|
||||
}
|
||||
}
|
||||
|
||||
failBoot("无法识别运行环境(非浙政钉/诗画容器),请从工作台或门户重新进入")
|
||||
} catch (e) {
|
||||
console.warn("[jumpByParam]", e)
|
||||
failBoot("进入失败,请重试")
|
||||
} finally {
|
||||
jumping = false
|
||||
}
|
||||
}
|
||||
|
||||
const doRetry = () => {
|
||||
void jumpByParam()
|
||||
}
|
||||
|
||||
const doModuleJump = (item: any) => {
|
||||
uni.setStorageSync("launchParam", item.launchParam)
|
||||
uni.reLaunch({ url: item.pagePath })
|
||||
@@ -204,20 +236,24 @@ const doModuleJump = (item: any) => {
|
||||
|
||||
<template>
|
||||
<crud-layout mainIsScroll bg="/static/page/blue-bg.png">
|
||||
<view class="w-full h-full flex-col-center">
|
||||
<view class="w-full h-full flex-col-center px-40rpx">
|
||||
<tm-sheet v-if="isDevEnv()" :margin="[0]">
|
||||
<view class="flex-row items-center justify-center flex-wrap">
|
||||
<view class="w-half flex justify-center py-2 rounded-1" v-for="(item, index) in moduleList"
|
||||
:key="index">
|
||||
<view class="w-half text-center rounded-1 active:bg-#e8e8e8 duration-200"
|
||||
@tap="doModuleJump(item)">
|
||||
<view class="w-half flex justify-center py-2 rounded-1" v-for="(item, index) in moduleList" :key="index">
|
||||
<view class="w-half text-center rounded-1 active:bg-#e8e8e8 duration-200" @tap="doModuleJump(item)">
|
||||
<image class="w-80 h-80 px-2 pt-2" :src="item.iconPath" />
|
||||
<tm-text font-size="32">{{ item.text }}</tm-text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</tm-sheet>
|
||||
<view v-else>加载中...</view>
|
||||
<template v-else>
|
||||
<view v-if="bootStatus === 'loading'" class="text-center sub-text-30 color-#666">加载中...</view>
|
||||
<view v-else class="text-center">
|
||||
<view class="sub-text-30 color-#333 mb-40rpx lh-1.5">{{ bootMessage }}</view>
|
||||
<view class="bg-#0094ff color-white! rounded-40rpx py-20rpx px-60rpx inline-block" @tap="doRetry">重试</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</crud-layout>
|
||||
</template>
|
||||
+27
-10
@@ -2,7 +2,6 @@
|
||||
|
||||
import { APPENV } from "../constant"
|
||||
|
||||
// export default () => import.meta.env.VITE_DEV_ENV === "dev"
|
||||
export const isDevEnv = (): boolean => process.env.NODE_ENV === "development"
|
||||
|
||||
/**
|
||||
@@ -25,23 +24,41 @@ export const getLaunchParam = (): string => {
|
||||
return getUrlQueryParam("launchParam") || uni.getStorageSync("launchParam") || ""
|
||||
}
|
||||
|
||||
// 检测app信息判断运行环境
|
||||
function looksLikeZzdContainer(): boolean {
|
||||
if (typeof window === "undefined") return false
|
||||
if ((window as { dd?: unknown }).dd) return true
|
||||
const ua = navigator.userAgent || ""
|
||||
return /DingTalk|浙政钉|taurusapp/i.test(ua)
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测运行环境。
|
||||
* 优先 CP2(诗画/部分容器):code===0 → 浙政钉,否则 → 诗画。
|
||||
* CP2 不可用时:有 dd / 浙政钉 UA → 浙政钉,避免误判 unknown 导致导航页一直「加载中」。
|
||||
*/
|
||||
export const getAppInfo = async (): Promise<string> => {
|
||||
if (import.meta.env.VITE_DEV_FORCE_ZZD === "true") {
|
||||
return APPENV.ZZD
|
||||
}
|
||||
try {
|
||||
const res = await (window as any).CP2.getAppInfo()
|
||||
// 浙政钉环境
|
||||
if (res.code === 0) {
|
||||
console.log("环境:浙政钉-zzd")
|
||||
return APPENV.ZZD
|
||||
} else {
|
||||
// 诗画环境
|
||||
const cp2 = (window as { CP2?: { getAppInfo?: () => Promise<{ code?: number }> } }).CP2
|
||||
if (cp2?.getAppInfo) {
|
||||
const res = await cp2.getAppInfo()
|
||||
if (res?.code === 0) {
|
||||
console.log("环境:浙政钉-zzd")
|
||||
return APPENV.ZZD
|
||||
}
|
||||
console.log("环境:诗画浦江-sh")
|
||||
return APPENV.SH
|
||||
}
|
||||
} catch (error) {
|
||||
return "unknown"
|
||||
console.warn("[getAppInfo] CP2.getAppInfo 失败,回退容器探测", error)
|
||||
}
|
||||
|
||||
if (looksLikeZzdContainer()) {
|
||||
console.log("环境:浙政钉-zzd(dd/UA)")
|
||||
return APPENV.ZZD
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
Reference in new issue
Block a user