app.js
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-28 14:45:31
* @FilePath: /jgdl/src/app.js
* @Description: 文件描述
*/
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './app.less'
import { routerStore } from '@/stores/router'
import Taro from '@tarojs/taro'
const App = createApp({
// 对应 onLaunch
onLaunch(options) {
// 未授权状态跳转授权页面,首页不需要权限
const path = options.path;
const query = options.query;
// 缓存没有权限的地址
const router = routerStore();
router.add(path);
// 检查是否有sessionid
const sessionid = wx.getStorageSync("sessionid");
// 如果没有sessionid且不是auth页面本身,才跳转到授权页面
if (!sessionid && path !== 'pages/auth/index') {
// 添加延迟避免与页面初始化冲突
setTimeout(() => {
if (path === 'pages/productDetail/index') {
Taro.navigateTo({
url: `./pages/auth/index?url=${path}&id=${query.id}`,
})
} else {
Taro.navigateTo({
url: './pages/auth/index?url=' + path,
})
}
}, 100);
}
},
onShow(options) {
// 处理确认收货组件回调
if (options && options.referrerInfo && options.referrerInfo.extraData) {
const { status, errormsg, req_extradata } = options.referrerInfo.extraData
if (status === 'success') {
// 确认收货成功,通过事件总线通知订单页面
Taro.eventCenter.trigger('confirmReceiveSuccess', {
merchantId: req_extradata.merchant_id,
transactionId: req_extradata.transaction_id,
merchantTradeNo: req_extradata.merchant_trade_no,
})
} else if (status === 'fail') {
Taro.showToast({
title: errormsg || '确认收货失败',
icon: 'error',
duration: 2000
})
}
// status === 'cancel' 时用户取消操作,不需要特殊处理
}
},
// 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖
});
App.use(createPinia())
export default App