123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // app.js
- import {
- loginLog,
- androidLogin,
- getMyInfo,
- bindDevice
- } from '~/api/user'
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- let storeBindings
- App({
- async onLaunch() {
- // #if ANDROID
- wx.setStorageSync('channelCode', '3016')
- this.initPlugin()
- // #endif
- this.getNavbarInfo()
- await loginLog()
- },
- async onShow(options) {
- if (!this.storeBindings) {
- this.storeBindings = createStoreBindings(this, {
- store,
- actions: ['setUser']
- })
- }
- this.login()
- },
- async login() {
- let uid = wx.getStorageSync('uid')
- if (uid) {
- let userInfo = await getMyInfo()
- console.log(userInfo, 'zzz');
- this.setUser(userInfo.user)
- this.globalData.userInfo = userInfo.user
- if (getApp().callBack) {
- getApp().callBack(userInfo.users);
- }
- } else {
- let userRes = await androidLogin({
- extOpenId: 'test1234567',
- channel: '3016',
- grade: 'PRIMARY_FIRST_GRADE'
- })
- this.setUser(userRes.user)
- wx.setStorageSync('uid', userRes.user.uid)
- wx.setStorageSync('user', userRes.user)
- this.globalData.userInfo = userRes.user
- if (getApp().callBack) {
- getApp().callBack(userRes.user);
- }
- }
- },
- getNavbarInfo() {
- // 获取系统信息
- const systemInfo = wx.getSystemInfoSync();
- // 胶囊按钮位置信息
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
- // 导航栏高度 = 状态栏高度 + 44
- this.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
- this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
- this.globalData.menuTop = menuButtonInfo.top;
- this.globalData.menuHeight = menuButtonInfo.height;
- // 设备显示区域的宽度,单位px
- this.globalData.windowWidth = systemInfo.windowWidth
- this.globalData.windowHeight = systemInfo.windowHeight
- },
- initPlugin() {
- let miniAppPluginId = 'wxf1a06dafa3350688'
- //根据模块ID初始化模块
- wx.miniapp.loadNativePlugin({
- pluginId: miniAppPluginId,
- channelCode: '3016',
- success: (plugin) => {
- this.globalData.plugin = plugin
- console.log('前端', plugin)
- this.globalData.plugin.initPlugin(({}), (res) => {
- if (res === "success") {
- console.log("初始化plugin成功")
- } else {
- console.log("初始化plugin失败")
- }
- })
- },
- fail: (e) => {
- console.log('load plugin fail', e)
- }
- })
- },
- globalData: {
- userInfo: null,
- isIOS: false, // 判断设备是否为苹果
- navBarHeight: 0, // 导航栏高度
- menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
- menuTop: 0, // 胶囊距底部间距(保持底部间距一致)
- menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
- windowWidth: 0,
- windowHeight: 0,
- plugin: {}
- }
- })
|