|
@@ -1,7 +1,7 @@
|
|
|
// app.js
|
|
|
import {
|
|
|
loginLog,
|
|
|
- userLogin,
|
|
|
+ androidLogin,
|
|
|
getMyInfo,
|
|
|
bindDevice
|
|
|
} from '~/api/user'
|
|
@@ -14,11 +14,8 @@ import {
|
|
|
let storeBindings
|
|
|
App({
|
|
|
async onLaunch() {
|
|
|
- // #if MP
|
|
|
- wx.setStorageSync('channelCode', '3001')
|
|
|
- this.updateApplet()
|
|
|
- // #elif ANDROID
|
|
|
- wx.setStorageSync('channelCode', '3001')
|
|
|
+ // #if ANDROID
|
|
|
+ wx.setStorageSync('channelCode', '3016')
|
|
|
this.initPlugin()
|
|
|
// #endif
|
|
|
this.getNavbarInfo()
|
|
@@ -31,115 +28,29 @@ App({
|
|
|
actions: ['setUser']
|
|
|
})
|
|
|
}
|
|
|
- let {
|
|
|
- path,
|
|
|
- scene,
|
|
|
- query
|
|
|
- } = wx.getEnterOptionsSync()
|
|
|
- //判断是不是扫海报进入
|
|
|
- if (query.scene && [1047, 1048].includes(scene) && path == 'pages/index/index') {
|
|
|
- let params = decodeURIComponent(query.scene).split('&')
|
|
|
- if (params.length == 1) {
|
|
|
- this.login(params[0])
|
|
|
- } else {
|
|
|
- this.login()
|
|
|
- }
|
|
|
- } else {
|
|
|
- let shareUid = options.query.uid || ''
|
|
|
- let userChannelCode = '3001'
|
|
|
- // console.log("朋友圈广告进入");
|
|
|
- if ([1045, 1046, 1084].includes(scene)) {
|
|
|
- userChannelCode = '4001'
|
|
|
- }
|
|
|
- this.login(shareUid, userChannelCode)
|
|
|
- }
|
|
|
+ this.login()
|
|
|
},
|
|
|
- async login(shareUid, userChannelCode = '3001') {
|
|
|
+ async login() {
|
|
|
let uid = wx.getStorageSync('uid')
|
|
|
if (uid) {
|
|
|
let userInfo = await getMyInfo()
|
|
|
- this.setUser(userInfo.user)
|
|
|
- this.globalData.userInfo = userInfo.user
|
|
|
- this.deviceLogin()
|
|
|
+ console.log(userInfo);
|
|
|
+ this.setUser(userInfo)
|
|
|
+ this.globalData.userInfo = userInfo
|
|
|
if (getApp().callBack) {
|
|
|
getApp().callBack();
|
|
|
}
|
|
|
} else {
|
|
|
- // #if MP
|
|
|
- this.getWXCode().then(async res => {
|
|
|
- if (res.code) {
|
|
|
- // 获取openid
|
|
|
- let data = {
|
|
|
- code: res.code,
|
|
|
- userChannelCode
|
|
|
- }
|
|
|
- if (shareUid != 'undefined' && shareUid) {
|
|
|
- data.shareUid = 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
|
|
|
- this.deviceLogin()
|
|
|
- if (getApp().callBack) {
|
|
|
- getApp().callBack(userRes);
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- // #elif ANDROID
|
|
|
- this.setUser({
|
|
|
- grade: 'PRIMARY_FIRST_GRADE'
|
|
|
- })
|
|
|
- // #endif
|
|
|
- }
|
|
|
- },
|
|
|
- getWXCode() {
|
|
|
- return new Promise((reslove, reject) => {
|
|
|
- wx.login({
|
|
|
- success: async (res) => {
|
|
|
- if (res.code) {
|
|
|
- reslove(res)
|
|
|
- } else {
|
|
|
- reject(res.errMsg)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- })
|
|
|
- },
|
|
|
- // 音箱端登录
|
|
|
- deviceLogin() {
|
|
|
- // #if MP
|
|
|
- let {
|
|
|
- path,
|
|
|
- scene,
|
|
|
- query
|
|
|
- } = wx.getEnterOptionsSync()
|
|
|
- // 1047 扫描小程序码 1048长按图片识别小程序码
|
|
|
- var gradeObj = Object.keys({
|
|
|
- "PRESCHOOL": "学前班",
|
|
|
- "PRIMARY_FIRST_GRADE": "一年级",
|
|
|
- "PRIMARY_SECOND_GRADE": "二年级",
|
|
|
- "PRIMARY_THREE_GRADE": "三年级",
|
|
|
- "PRIMARY_SENIOR_GRADE": "四年级",
|
|
|
- "PRIMARY_FIVE_GRADE": "五年级",
|
|
|
- "PRIMARY_SIX_GRADE": "六年级",
|
|
|
- })
|
|
|
- if (query.scene && [1047, 1048].includes(scene) && path == 'pages/index/index') {
|
|
|
- let params = decodeURIComponent(query.scene).split('&')
|
|
|
- if (params.length > 1) {
|
|
|
- bindDevice({
|
|
|
- deviceCode: params[0],
|
|
|
- channelCode: params[1],
|
|
|
- grade: gradeObj[params[2]],
|
|
|
- uid: wx.getStorageSync('uid')
|
|
|
- }).then(res => {
|
|
|
- console.log(res);
|
|
|
- })
|
|
|
+ let userRes = await androidLogin({extOpenId:'1234567',channel:'3016',grade:'PRIMARY_FIRST_GRADE'})
|
|
|
+ console.log(userRes);
|
|
|
+ this.setUser(userRes)
|
|
|
+ wx.setStorageSync('uid', userRes.uid)
|
|
|
+ wx.setStorageSync('user', userRes)
|
|
|
+ this.globalData.userInfo = userRes
|
|
|
+ if (getApp().callBack) {
|
|
|
+ getApp().callBack(userRes);
|
|
|
}
|
|
|
}
|
|
|
- // #endif
|
|
|
},
|
|
|
getNavbarInfo() {
|
|
|
// 获取系统信息
|
|
@@ -155,36 +66,6 @@ App({
|
|
|
this.globalData.windowWidth = systemInfo.windowWidth
|
|
|
this.globalData.windowHeight = systemInfo.windowHeight
|
|
|
},
|
|
|
- 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) {
|
|
|
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
- updateManager.applyUpdate()
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- updateManager.onUpdateFailed(function () {
|
|
|
- // 新的版本下载失败
|
|
|
- wx.showModal({
|
|
|
- title: '已经有新版本了哟~',
|
|
|
- content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
initPlugin() {
|
|
|
let miniAppPluginId = 'wxf1a06dafa3350688'
|
|
|
//根据模块ID初始化模块
|