zhengyiming
2025-03-28 381c97332e567a1b95a9a5220275461d0ae3f74e
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { createApp } from 'vue';
 
import '@nutui/nutui-taro/dist/style.css';
import './app.scss';
 
import { setupStore } from '@/stores';
 
import { useSystemStore } from '@/stores/modules/system';
import { useUserStore } from '@/stores/modules/user';
import Taro from '@tarojs/taro';
import { VueQueryPlugin, VueQueryPluginOptions } from '@tanstack/vue-query';
import { myClient } from '@/constants/query';
import { VueLifeRechargePlugin } from '@life-payment/core-vue';
import { blLifeRecharge, LifeRechargeOptions } from '@/utils/blLifeRecharge';
import { isWeChat } from '@/utils/env';
 
window.uni = Taro;
 
function updateVersions() {
  const updateManager = Taro.getUpdateManager();
  updateManager.onCheckForUpdate(function (_res) {
    // 请求完新版本信息的回调
  });
  updateManager.onUpdateReady(function () {
    Taro.showModal({
      title: '更新提示',
      content: '新版本已经准备好,是否重启应用?',
      success: function (res) {
        if (res.confirm) {
          // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
          updateManager.applyUpdate();
        }
      },
    });
  });
  updateManager.onUpdateFailed(function () {
    // 新的版本下载失败
    Taro.showToast({
      title: '新的版本下载失败,请重新进入',
      icon: 'none',
      duration: 2000,
    });
  });
}
 
const App = createApp({
  // 可以使用所有的 Vue 生命周期方法
 
  mounted() {},
 
  // 对应 onLaunch
  onLaunch(options) {
    if (options.query?.channelId) {
      console.log('options: ', options);
      blLifeRecharge.accountModel.setChannlesNum(options.query.channelId);
    }
    // 如果是收藏进入
    if (options.query.collect) {
      Taro.reLaunch({
        url: '/pages/index/index',
      });
      return;
    }
    // 将启动参数放进到全局去
    const system = useSystemStore();
    system.init(options);
    system.setInfo(Taro.getSystemInfoSync());
  },
 
  // 对应 onShow
  onShow(options) {
    if (isWeChat) {
      updateVersions();
    }
  },
 
  // 对应 onHide
  onHide() {},
  // 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖
});
 
setupStore(App);
 
import { IconFont } from '@nutui/icons-vue-taro';
 
App.component('IconFont', IconFont); // 全局组件
 
const vueQueryPluginOptions: VueQueryPluginOptions = {
  queryClient: myClient,
};
 
App.use(VueQueryPlugin, vueQueryPluginOptions);
 
App.use(VueLifeRechargePlugin, {
  blLifeRecharge,
  // options: LifeRechargeOptions,
});
 
export default App;