| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <script setup>
- import loginMethods from '@/utils/login'
- import permissionListener from '@/utils/authorize/permissionListener.js'
- import { initLog } from '@/utils/flow'
- import { useThemeStore } from '@/stores/theme'
- const themeStore = useThemeStore()
- onLaunch(async () => {
- // 初始化埋点请求数据
- initLog()
- // eslint-disable-next-line no-console, no-restricted-syntax
- console.log('mall4j.v240506')
- // #ifdef H5
- uni.getSystemInfo({
- success: function ({ platform }) {
- // 客户端平台,值域为:ios、android
- if (platform === 'ios') {
- uni.setStorageSync('bbcIosUrl', window.location.href.split('#')[0])
- }
- }
- })
- // 判断浏览器环境
- const ua = navigator.userAgent.toLowerCase()
- if (ua.search(/MicroMessenger/i) > -1 && !uni.getStorageSync('bbcAppType')) {
- // 微信环境
- uni.setStorageSync('bbcAppType', AppType.MP)
- } else {
- if (!uni.getStorageSync('bbcAppType')) {
- uni.setStorageSync('bbcAppType', AppType.H5)
- }
- }
- // #endif
- // 获取系统支付设置
- util.getSysPaySwitch(true)
- // 获取网站配置
- useWebConfigStore().getUniWebConfig()
- // 获取通联支付设置
- util.getAllinpayConfig(1)
- // #ifdef MP-WEIXIN
- uni.setStorageSync('bbcAppType', AppType.MINI)
- // 微信小程序检查升级
- checkMiniUpdate()
- // #endif
- // APP模式下保持竖屏
- // #ifdef APP-PLUS
- plus.screen.lockOrientation('portrait-primary')
- uni.getSystemInfo({
- success: (sysInfo) => {
- if (sysInfo.platform === 'android') {
- uni.setStorageSync('bbcAppType', AppType.ANDROID)
- } else {
- uni.setStorageSync('bbcAppType', AppType.IOS)
- }
- }
- })
- // #endif
- // #ifdef MP-WEIXIN || H5
- setTimeout(() => {
- loginMethods.weChatLogin()
- })
- // #endif
- uni.getSystemInfo({
- success: function (res) {
- // px转换到rpx的比例
- const pxToRpxScale = 750 / res.windowWidth
- const systems = {
- ktxStatusHeight: res.statusBarHeight * pxToRpxScale, // 状态栏的高度
- navigationHeight: 44 * pxToRpxScale, // 导航栏的高度
- ktxWindowWidth: res.windowWidth * pxToRpxScale, // window的宽度
- ktxWindowHeight: res.windowHeight * pxToRpxScale, // window的高度
- ktxScreentHeight: res.screenHeight * pxToRpxScale // 屏幕的高度
- }
- const app = createApp()
- app.config.globalProperties.$system = systems
- app.config.globalProperties.$lineHeight = systems.ktxStatusHeight + systems.navigationHeight
- provide('$system', systems)
- provide('$lineHeight', systems.ktxStatusHeight + systems.navigationHeight)
- }
- })
- // 全局变量
- nextTick(() => initGlobalData())
- // 请求购物车数据
- useCartCountStore().updateCartCount()
- // 初始化主题
- if (!themeStore.themeColor || themeStore.themeColor === '#F81A1A') {
- await themeStore.init()
- }
- })
- onShow((options) => {
- permissionListener?.listenerFunc()
- // #ifdef MP-WEIXIN
- // 通联支付从通联微信小程序返回后接收的参数
- if (uni.getStorageSync('bbcPaySettlementType') !== 1) {
- // 非通联支付模式下不处理
- return
- }
- if (options.referrerInfo && options.referrerInfo.extraData) {
- let backMerchantUrl = options.referrerInfo.extraData.backMerchantUrl
- if (backMerchantUrl) {
- backMerchantUrl = decodeURIComponent(backMerchantUrl)
- const result = backMerchantUrl.split('?')[1].split('&')
- const query = {}
- for (let i = 0; i < result.length; i++) {
- const item = result[i].split('=')
- query[item[0]] = item[1]
- }
- if (Number(query.isSignSuccess) === 1 && query.bizContent) {
- // 获取内存中的签约编号
- const acctProtocolNo = uni.getStorageSync('bbcAllinpayAcctProtocolNo')
- const bizContent = JSON.parse(decodeURIComponent(query.bizContent))
- if (bizContent.acctProtocolNo !== acctProtocolNo) {
- uni.showToast({
- title: $t('signSuccess'),
- icon: 'none'
- })
- uni.setStorageSync('bbcAllinpayAcctProtocolNo', bizContent.acctProtocolNo)
- }
- } else if (Number(query.isSignSuccess) === 0) {
- uni.showToast({
- title: $t('signFail'),
- icon: 'none'
- })
- }
- }
- }
- // #endif
- })
- onHide(() => {
- permissionListener?.stopFunc()
- })
- // 页面不存在时触发
- onPageNotFound(() => {
- uni.reLaunch({
- url: '/pages/index/index'
- })
- })
- const initGlobalData = () => {
- const appType = uni.getStorageSync('bbcAppType')
- // 全局请求队列
- getApp().globalData.requestQueue = []
- // 是否正在进行登录
- getApp().globalData.isLanding = false
- // 购物车商品数量
- getApp().globalData.totalCartCount = 0
- // 当前请求数量
- getApp().globalData.currentReqCounts = 0
- // 是否重新加载页面数据
- getApp().globalData.isRefreshPage = false
- // 直播间socket任务
- getApp().globalData.imSocketTask = null
- getApp().globalData.reloadHomePopupAd = true // 是否重新加载首页弹窗
- getApp().globalData.reloadPageData = false // 是否重新加载页面数据
- // 悟空im设备标识 0.app 1.其他;相同用户相同设备标记的主设备登录会互相踢
- getApp().globalData.wukongDeviceFlag = appType === AppType.ANDROID || appType === AppType.IOS ? 0 : 1
- }
- /**
- * 微信小程序检查升级
- */
- const checkMiniUpdate = () => {
- const updateManager = wx.getUpdateManager()
- updateManager.onUpdateReady(function () {
- wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: function (res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(function () {
- // 新版本下载失败
- uni.showToast({
- title: '新版本下载失败,请重试',
- duration: 2000,
- icon: 'none'
- })
- })
- }
- </script>
- <!-- eslint-disable-next-line vue-scoped-css/enforce-style-type -->
- <style>
- /*每个页面公共样式 */
- /* #ifndef APP-PLUS-NVUE */
- @import url('./app.css');
- @import url('./theme/index.css');
- /* #endif */
- @import "@/static/iconfont/iconfont.css";
- </style>
|