123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- const { miniLogin } = require('../../api/common')
- const { login, sessionStorageKey } = require('../../api/request')
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- booLock: false
- },
- wxCode: '',
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getWxCode()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- async getPhoneNumber(e) {
- const isTab = app.globalData.tabBarList.map(item => item.pagePath)
- const { errMsg, encryptedData, iv } = e.detail
- if (errMsg === 'getPhoneNumber:ok') {
- this.setData({
- booLock: true
- })
- try {
- const { status, data } = await miniLogin({
- wxCode: this.wxCode,
- encryptedData,
- iv
- })
- if (status) {
- try {
- wx.setStorageSync(sessionStorageKey, data.token)
- } catch (err) {}
- await app.fetchUserData()
- const pages = getCurrentPages()
- if (pages.length > 1) {
- const route = pages[pages.length - 2]
- route.bindCallBack && route.bindCallBack()
- if (isTab.findIndex(item => item === route.route) > -1) {
- wx.reLaunch({
- url: '/' + route.route
- })
- } else {
- wx.navigateBack({
- delta: 1
- })
- }
- }
- } else {
- wx.showToast({
- title: '登录出错了,请重试',
- icon: 'none'
- })
- this.getWxCode()
- }
- } catch (e) {
- this.getWxCode()
- }
- this.setData({
- booLock: false
- })
- }
- },
- async getWxCode() {
- try {
- this.wxCode = await login()
- } catch (e) {}
- }
- })
|