Files
biz-mobile-cloud-zax/src/App.vue
T
2026-07-07 17:06:07 +08:00

179 lines
4.9 KiB
Vue

<script>
import { adApi, userApi } from "@@/api"
import { storageConstant } from "@@/constant"
import pinia from "@@/stores/index"
import { useRiderPushBannerStore } from "@@/stores/rider-push-banner"
import { globalWebSocket } from "@/sheep/utils/global-websocket"
import { handleCanteenDeliveryWebSocketFrame } from "@/sheep/utils/canteen-delivery-ws-push"
import jgPush from "@/sheep/utils/jg-push"
import { clearAppBadgeNumber } from "@/sheep/utils/appTool"
export default {
data() {
return {
isVisibleAd: false,
system: uni.getSystemInfoSync(),
}
},
async onLaunch() {
this._initTabbar()
// #ifdef APP-PLUS
this.reportSplashAd()
// 初始化极光推送服务
await jgPush.initialize({
debug: true,
autoInitService: true,
enableCrashHandler: true,
requestAndroidPermission: true,
requestIOSNotificationPermission: true,
})
clearAppBadgeNumber()
// #endif
this._initGlobalWs()
},
onShow() {
this._syncTabbar()
this._initGlobalWs()
},
onHide() {
},
methods: {
_initGlobalWs() {
try {
const tokenStorage = uni.getStorageSync(storageConstant.TOKEN)
const token = tokenStorage?.access_token || tokenStorage?.accessToken || tokenStorage?.token
if (!token) return
const riderBanner = useRiderPushBannerStore(pinia)
globalWebSocket.start({
uri: import.meta.env.VITE_WS_URI || "/admin/ws/info",
heartbeat: import.meta.env.VITE_WS_HEARTBEAT !== "false",
maxReconnect: -1,
onMessage: (text) => {
try {
uni.vibrateShort()
} catch { }
const results = handleCanteenDeliveryWebSocketFrame(text)
if (results.length === 0) {
uni.showToast({ title: "收到新消息", icon: "none", duration: 3500 })
} else {
for (const r of results) {
if (
r.handled &&
(r.kind === "order_assigned" ||
r.kind === "merchant_new_order" ||
r.kind === "merchant_scheduled_remind")
) {
riderBanner.showFromBanner(r.banner)
} else if (r.handled && r.kind === "other_biz") {
uni.showToast({ title: r.toastTitle, icon: "none", duration: 4000 })
}
}
}
console.log("[WS] message:", text)
},
})
} catch (e) {
console.log("[WS] init failed", e)
}
},
async _getUserInfo() {
const { data: userData } = await userApi.userInfo()
uni.setStorageSync(storageConstant.USERINFO, userData)
this.isVisibleAd = true
if (userData && userData.userTags) {
const vip = userData.userTags.find((item) => item.bizType == "10")
if (vip) {
this.isVisibleAd = false
}
}
return userData
},
async _initTabbar() {
const tabbarStore = await this._getTabbarStore()
tabbarStore?.init()
},
async _syncTabbar() {
const tabbarStore = await this._getTabbarStore()
tabbarStore?.syncByCurrentRoute()
},
async _getTabbarStore() {
// #ifdef APP-NVUE
return null
// #endif
const { useTabbarStore } = await import("@@/stores/tabbar")
return useTabbarStore(pinia)
},
async reportSplashAd() {
try {
const userInfo = uni.getStorageSync(storageConstant.USERINFO)
if (!userInfo || !userInfo.sysUser) {
return
}
const platform = uni.getSystemInfoSync()?.platform
const { code } = await adApi.reportAdView({
userId: userInfo.sysUser.userId,
adId: "",
adType: "80",
visitPlatform: platform,
visitStartTime: "",
visitEndTime: "",
extra: "",
})
if (code == 0) {
console.log("|上报开屏广告|成功的回调code:", code)
}
} catch (error) {
console.log("|上报开屏广告|失败的回调error:", error)
}
},
},
}
</script>
<style lang="scss">
// tm-ui
@import url(@/uni_modules/tm-ui/css/remixicon.min.css);
@import url(@/uni_modules/tm-ui/css/tmui.css);
// 全局
@import "@/sheep/scss/global.scss";
$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;
}
.primary_btn {
border: 1px solid white;
background: $theme-blue;
color: white;
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>