|
@@ -1,140 +1,141 @@
|
|
|
|
|
|
import {
|
|
|
- loginLog,
|
|
|
- userLogin,
|
|
|
- getMyInfo
|
|
|
+ loginLog,
|
|
|
+ userLogin,
|
|
|
+ getMyInfo
|
|
|
} from '~/api/user'
|
|
|
import {
|
|
|
- createStoreBindings
|
|
|
+ createStoreBindings
|
|
|
} from 'mobx-miniprogram-bindings'
|
|
|
import {
|
|
|
- store
|
|
|
+ store
|
|
|
} from '~/store/index'
|
|
|
let storeBindings
|
|
|
App({
|
|
|
- async onLaunch() {
|
|
|
- this.updateApplet()
|
|
|
- this.checkIsIos()
|
|
|
- this.getNavbarInfo()
|
|
|
- await loginLog()
|
|
|
- },
|
|
|
- async onShow(options) {
|
|
|
- if (!this.storeBindings) {
|
|
|
- this.storeBindings = createStoreBindings(this, {
|
|
|
- store,
|
|
|
- actions: ['setUser']
|
|
|
- })
|
|
|
- }
|
|
|
- let shareUid = options.query.uid || ''
|
|
|
- let uid = wx.getStorageSync('uid')
|
|
|
- if (uid) {
|
|
|
- let userInfo = await getMyInfo()
|
|
|
- this.setUser(userInfo.user)
|
|
|
- if (getApp().callBack) {
|
|
|
- getApp().callBack();
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.login(shareUid)
|
|
|
- }
|
|
|
- },
|
|
|
- login(shareUid) {
|
|
|
- wx.login({
|
|
|
- success: async (res) => {
|
|
|
- if (res.code) {
|
|
|
-
|
|
|
- let data = {
|
|
|
- code: res.code,
|
|
|
- shareUid
|
|
|
- }
|
|
|
- let userRes = await userLogin(data)
|
|
|
- this.setUser(userRes.data)
|
|
|
- wx.setStorageSync('uid', userRes.data.uid)
|
|
|
- wx.setStorageSync('user', userRes.data)
|
|
|
- this.globalData.userInfo = userRes.data
|
|
|
- if (getApp().callBack) {
|
|
|
- getApp().callBack(userRes);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- checkIsIos: function () {
|
|
|
- wx.getSystemInfo({
|
|
|
- success: (res) => {
|
|
|
-
|
|
|
- this.globalData.windowWidth = res.windowWidth
|
|
|
- this.globalData.windowHeight = res.windowHeight
|
|
|
- if (res.system.search('iOS') != -1) {
|
|
|
- this.globalData.isIOS = true
|
|
|
- }
|
|
|
- let {
|
|
|
- scene
|
|
|
- } = wx.getLaunchOptionsSync()
|
|
|
-
|
|
|
- if (scene != 1023) {
|
|
|
- let preTime = wx.getStorageSync('preDesktopTime')
|
|
|
- let flag = !preTime ? true : (new Date() - preTime) / 43200000 > 1 ? true : false
|
|
|
- if (flag || !preTime) {
|
|
|
- this.globalData.desktopTips = true
|
|
|
- wx.setStorage({
|
|
|
- key: "preDesktopTime",
|
|
|
- data: new Date()
|
|
|
+ async onLaunch() {
|
|
|
+ this.updateApplet()
|
|
|
+ this.checkIsIos()
|
|
|
+ this.getNavbarInfo()
|
|
|
+ await loginLog()
|
|
|
+ },
|
|
|
+ async onShow(options) {
|
|
|
+ if (!this.storeBindings) {
|
|
|
+ this.storeBindings = createStoreBindings(this, {
|
|
|
+ store,
|
|
|
+ actions: ['setUser']
|
|
|
})
|
|
|
- }
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- getNavbarInfo() {
|
|
|
-
|
|
|
- const systemInfo = wx.getSystemInfoSync();
|
|
|
-
|
|
|
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
|
|
|
-
|
|
|
- this.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
|
|
|
- this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
|
|
|
- this.globalData.menuTop = menuButtonInfo.top;
|
|
|
- this.globalData.menuHeight = menuButtonInfo.height;
|
|
|
- },
|
|
|
- updateApplet() {
|
|
|
-
|
|
|
- if (wx.canIUse('getUpdateManager')) {
|
|
|
- const updateManager = wx.getUpdateManager()
|
|
|
- updateManager.onCheckForUpdate(function (res) {
|
|
|
-
|
|
|
- if (res.hasUpdate) {
|
|
|
- updateManager.onUpdateReady(function () {
|
|
|
- wx.showModal({
|
|
|
- title: '更新提示',
|
|
|
- content: '新版本已经准备好,是否重启应用?',
|
|
|
- success: function (res) {
|
|
|
- if (res.confirm) {
|
|
|
-
|
|
|
- updateManager.applyUpdate()
|
|
|
+ let shareUid = options.query.uid || ''
|
|
|
+ console.log(shareUid,'shareUid');
|
|
|
+ let uid = wx.getStorageSync('uid')
|
|
|
+ if (uid) {
|
|
|
+ let userInfo = await getMyInfo()
|
|
|
+ this.setUser(userInfo.user)
|
|
|
+ if (getApp().callBack) {
|
|
|
+ getApp().callBack();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.login(shareUid)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ login(shareUid) {
|
|
|
+ wx.login({
|
|
|
+ success: async (res) => {
|
|
|
+ if (res.code) {
|
|
|
+
|
|
|
+ let data = {
|
|
|
+ code: res.code,
|
|
|
+ shareUid
|
|
|
+ }
|
|
|
+ let userRes = await userLogin(data)
|
|
|
+ this.setUser(userRes.data)
|
|
|
+ wx.setStorageSync('uid', userRes.data.uid)
|
|
|
+ wx.setStorageSync('user', userRes.data)
|
|
|
+ this.globalData.userInfo = userRes.data
|
|
|
+ if (getApp().callBack) {
|
|
|
+ getApp().callBack(userRes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkIsIos: function () {
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: (res) => {
|
|
|
+
|
|
|
+ this.globalData.windowWidth = res.windowWidth
|
|
|
+ this.globalData.windowHeight = res.windowHeight
|
|
|
+ if (res.system.search('iOS') != -1) {
|
|
|
+ this.globalData.isIOS = true
|
|
|
+ }
|
|
|
+ let {
|
|
|
+ scene
|
|
|
+ } = wx.getLaunchOptionsSync()
|
|
|
+
|
|
|
+ if (scene != 1023) {
|
|
|
+ let preTime = wx.getStorageSync('preDesktopTime')
|
|
|
+ let flag = !preTime ? true : (new Date() - preTime) / 43200000 > 1 ? true : false
|
|
|
+ if (flag || !preTime) {
|
|
|
+ this.globalData.desktopTips = true
|
|
|
+ wx.setStorage({
|
|
|
+ key: "preDesktopTime",
|
|
|
+ data: new Date()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getNavbarInfo() {
|
|
|
+
|
|
|
+ const systemInfo = wx.getSystemInfoSync();
|
|
|
+
|
|
|
+ const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
|
|
|
+
|
|
|
+ this.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
|
|
|
+ this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
|
|
|
+ this.globalData.menuTop = menuButtonInfo.top;
|
|
|
+ this.globalData.menuHeight = menuButtonInfo.height;
|
|
|
+ },
|
|
|
+ updateApplet() {
|
|
|
+
|
|
|
+ if (wx.canIUse('getUpdateManager')) {
|
|
|
+ const updateManager = wx.getUpdateManager()
|
|
|
+ updateManager.onCheckForUpdate(function (res) {
|
|
|
+
|
|
|
+ if (res.hasUpdate) {
|
|
|
+ updateManager.onUpdateReady(function () {
|
|
|
+ wx.showModal({
|
|
|
+ title: '更新提示',
|
|
|
+ content: '新版本已经准备好,是否重启应用?',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+
|
|
|
+ updateManager.applyUpdate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ updateManager.onUpdateFailed(function () {
|
|
|
+
|
|
|
+ wx.showModal({
|
|
|
+ title: '已经有新版本了哟~',
|
|
|
+ content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- updateManager.onUpdateFailed(function () {
|
|
|
-
|
|
|
- wx.showModal({
|
|
|
- title: '已经有新版本了哟~',
|
|
|
- content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
})
|
|
|
- })
|
|
|
}
|
|
|
- })
|
|
|
+ },
|
|
|
+ globalData: {
|
|
|
+ userInfo: null,
|
|
|
+ isIOS: false,
|
|
|
+ desktopTips: false,
|
|
|
+ navBarHeight: 0,
|
|
|
+ menuRight: 0,
|
|
|
+ menuTop: 0,
|
|
|
+ menuHeight: 0,
|
|
|
+ windowWidth: 0,
|
|
|
+ windowHeight: 0
|
|
|
}
|
|
|
- },
|
|
|
- globalData: {
|
|
|
- userInfo: null,
|
|
|
- isIOS: false,
|
|
|
- desktopTips: false,
|
|
|
- navBarHeight: 0,
|
|
|
- menuRight: 0,
|
|
|
- menuTop: 0,
|
|
|
- menuHeight: 0,
|
|
|
- windowWidth: 0,
|
|
|
- windowHeight: 0
|
|
|
- }
|
|
|
})
|