|
@@ -1,7 +1,7 @@
|
|
// pages/index/index.js
|
|
// pages/index/index.js
|
|
import { homePage } from '../../api/index'
|
|
import { homePage } from '../../api/index'
|
|
import { createQRcode } from "../../api/document"
|
|
import { createQRcode } from "../../api/document"
|
|
-// import { ittLogin, bindMobile, bindBaseInfo } from '../../api/my'
|
|
|
|
|
|
+import { ittLogin, bindMobile, bindBaseInfo } from '../../api/my'
|
|
const app = getApp()
|
|
const app = getApp()
|
|
Page({
|
|
Page({
|
|
|
|
|
|
@@ -19,72 +19,241 @@ Page({
|
|
QRCodeBase64: '',
|
|
QRCodeBase64: '',
|
|
qrcodeDialog: false,
|
|
qrcodeDialog: false,
|
|
qrUserName: '',
|
|
qrUserName: '',
|
|
- phoneAuthShow: false
|
|
|
|
|
|
+ phoneAuthShow: false,
|
|
|
|
+ userAuthShow: false,
|
|
|
|
+ avatarUrl: '',
|
|
|
|
+ nickName: ''
|
|
},
|
|
},
|
|
|
|
|
|
onShow () {
|
|
onShow () {
|
|
app.globalData.selectedInex = 0
|
|
app.globalData.selectedInex = 0
|
|
- if (app.globalData.userInfo.login) {
|
|
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ onLoad () {
|
|
|
|
+ this.init()
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 初始化函数,判读需不需要获取wx.login => code
|
|
|
|
+ init () {
|
|
|
|
+ console.log(app.globalData.accessToken, 'index onlaod')
|
|
|
|
+ const accessToken = app.globalData.accessToken
|
|
|
|
+ if (accessToken) {
|
|
|
|
+ var isNeedPhone = wx.getStorageSync('isNeedPhone')
|
|
|
|
+ var isNeedHeadImg = wx.getStorageSync('isNeedHeadImg')
|
|
|
|
+ var headImg = wx.getStorageSync('headImg')
|
|
|
|
+ var userName = wx.getStorageSync('userName')
|
|
|
|
+ var phoneNumber = wx.getStorageSync('phoneNumber')
|
|
|
|
+ app.globalData.isNeedPhone = isNeedPhone
|
|
|
|
+ app.globalData.isNeedHeadImg = isNeedHeadImg
|
|
|
|
+ app.globalData.userInfo.headImg= headImg
|
|
|
|
+ app.globalData.userInfo.userName = userName
|
|
|
|
+ app.globalData.userInfo.phoneNumber = phoneNumber
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
|
|
+ this.handleAuth()
|
|
|
|
+ } else {
|
|
|
|
+ this.appCodeLoginFn()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 是否需要权限判断 手机号 头像 昵称
|
|
|
|
+ handleAuth () {
|
|
|
|
+ // 不需要手机号授权 有头像和昵称
|
|
|
|
+ const resIsNeedPhone = app.globalData.isNeedPhone
|
|
|
|
+ const resHeadImg = app.globalData.userInfo.headImg
|
|
|
|
+ const that = this
|
|
|
|
+ if (!resIsNeedPhone && resHeadImg !== '') {
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
this.initIndexData()
|
|
this.initIndexData()
|
|
} else {
|
|
} else {
|
|
- wx.reLaunch({
|
|
|
|
- url: '/pages/my/my'
|
|
|
|
- })
|
|
|
|
|
|
+ if (resIsNeedPhone) { // true 代表需要手机号授权
|
|
|
|
+ that.setData({
|
|
|
|
+ phoneAuthShow: true
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ if (resHeadImg == '') { // 需要授权头像
|
|
|
|
+ that.setData({
|
|
|
|
+ userAuthShow: true
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- onLoad () {
|
|
|
|
- //this.ittLoginFn()
|
|
|
|
|
|
+ // 获取本地存储你的头像 昵称 手机号 以及 accessToken 信息
|
|
|
|
+ appLoginFn () {
|
|
|
|
+ console.log('使用已存在的accessToekn登录')
|
|
|
|
+ this.initIndexData()
|
|
},
|
|
},
|
|
|
|
|
|
- ittLoginFn () {
|
|
|
|
- // var that = this
|
|
|
|
|
|
+ // 使用wx.login => code => accessToken
|
|
|
|
+ appCodeLoginFn () {
|
|
|
|
+ var that = this
|
|
wx.login({
|
|
wx.login({
|
|
success (loginCode) {
|
|
success (loginCode) {
|
|
if (loginCode.code) {
|
|
if (loginCode.code) {
|
|
- var data = {
|
|
|
|
- code: loginCode.code
|
|
|
|
- }
|
|
|
|
- wx.showLoading({
|
|
|
|
- title: '登录中...',
|
|
|
|
- mask: true
|
|
|
|
- })
|
|
|
|
- ittLogin(data).then(res => {
|
|
|
|
- wx.hideLoading()
|
|
|
|
- app.globalData.accessToken = res.data.accessToken
|
|
|
|
- app.globalData.phoneAuth = !res.data.isNeedPhone
|
|
|
|
- app.globalData.headAuth = res.data.headImg ? true : false
|
|
|
|
- app.globalData.userInfo.headImg= res.data.headImg
|
|
|
|
- app.globalData.userInfo.userName = res.data.userName
|
|
|
|
- app.globalData.userInfo.phoneNumber = res.data.phoneNumber
|
|
|
|
- //const resIsNeedPhone = res.data.isNeedPhone
|
|
|
|
- // const resHeadImg = res.data.headImg
|
|
|
|
- console.log(app.globalData.phoneAuth, app.globalData.headAuth);
|
|
|
|
- }).catch(e => {
|
|
|
|
- wx.hideLoading()
|
|
|
|
- })
|
|
|
|
|
|
+ that.ittLoginFn(loginCode.code)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
- getPhoneNumber (e) {
|
|
|
|
- console.log(e.detail.code)
|
|
|
|
|
|
+ // 登录函数
|
|
|
|
+ ittLoginFn (code) {
|
|
|
|
+ var that = this
|
|
|
|
+ var data = {
|
|
|
|
+ code: code
|
|
|
|
+ }
|
|
|
|
+ wx.showLoading({
|
|
|
|
+ title: '登录中...',
|
|
|
|
+ mask: true
|
|
|
|
+ })
|
|
|
|
+ ittLogin(data).then(res => {
|
|
|
|
+ const response = res.data
|
|
|
|
+ const accessToken = response.accessToken
|
|
|
|
+ const isNeedPhone = response.isNeedPhone
|
|
|
|
+ const isNeedHeadImg = response.headImg ? true : false
|
|
|
|
+ const headImg = response.headImg
|
|
|
|
+ const userName = response.userName
|
|
|
|
+ const phoneNumber = response.phoneNumber
|
|
|
|
+ app.globalData.accessToken = accessToken
|
|
|
|
+ app.globalData.isNeedPhone = isNeedPhone
|
|
|
|
+ app.globalData.isNeedHeadImg = isNeedHeadImg
|
|
|
|
+ app.globalData.userInfo.headImg= headImg
|
|
|
|
+ app.globalData.userInfo.userName = userName
|
|
|
|
+ app.globalData.userInfo.phoneNumber = phoneNumber
|
|
|
|
+ wx.setStorageSync('accessToken', accessToken)
|
|
|
|
+ wx.setStorageSync('isNeedPhone', isNeedPhone)
|
|
|
|
+ wx.setStorageSync('isNeedHeadImg', isNeedHeadImg)
|
|
|
|
+ wx.setStorageSync('headImg', headImg)
|
|
|
|
+ wx.setStorageSync('userName', userName)
|
|
|
|
+ wx.setStorageSync('phoneNumber', phoneNumber)
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ that.handleAuth()
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 拉起手机号授权弹窗
|
|
|
|
+ getPhoneNumber (e) {
|
|
|
|
+ var phonePermission = e.detail.errMsg.split(':')[1]
|
|
|
|
+ if (phonePermission == 'ok') {
|
|
|
|
+ var phoneCode = e.detail.code
|
|
|
|
+ this.bindMobileFn(phoneCode)
|
|
|
|
+ } else {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '授权失败',
|
|
|
|
+ icon: 'error'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 绑定手机号
|
|
|
|
+ bindMobileFn (phoneCode) {
|
|
|
|
+ var that = this
|
|
|
|
+ var data = {
|
|
|
|
+ mobileCode: phoneCode
|
|
|
|
+ }
|
|
|
|
+ wx.showLoading({
|
|
|
|
+ title: '加载中...',
|
|
|
|
+ mask: true
|
|
|
|
+ })
|
|
|
|
+ bindMobile(data).then(res => {
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ const resPhoneNumber = res.data
|
|
|
|
+ app.globalData.userInfo.phoneNumber = resPhoneNumber
|
|
|
|
+ wx.setStorageSync('phoneNumber', resPhoneNumber)
|
|
|
|
+ that.setData({
|
|
|
|
+ phoneAuthShow: false
|
|
|
|
+ })
|
|
|
|
+ if (app.globalData.userInfo.headImg == '') {
|
|
|
|
+ // 需要授权头像
|
|
|
|
+ that.setData({
|
|
|
|
+ userAuthShow: true
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
|
|
+ }
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ wx.showModal({
|
|
|
|
+ content: e,
|
|
|
|
+ confirmColor: '#333',
|
|
|
|
+ showCancel: false
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 获取用户头像和昵称权限 该api将于2022年10月25号之后失效
|
|
|
|
+ getUserinfo () {
|
|
|
|
+ var that = this
|
|
|
|
+ wx.getUserProfile({
|
|
|
|
+ desc: '用于获取用户权益'
|
|
|
|
+ }).then(res => {
|
|
|
|
+ const _avatarUrl = res.userInfo.avatarUrl
|
|
|
|
+ const _nickName = res.userInfo.nickName
|
|
|
|
+ that.setData({
|
|
|
|
+ avatarUrl: _avatarUrl,
|
|
|
|
+ nickname: _nickName
|
|
|
|
+ })
|
|
|
|
+ that.handleConfirmNickname()
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '授权失败',
|
|
|
|
+ icon: 'error'
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 提交用户头像和昵称到后台
|
|
|
|
+ handleConfirmNickname () {
|
|
|
|
+ var that = this
|
|
|
|
+ var data = {
|
|
|
|
+ avatarUrl: that.data.avatarUrl,
|
|
|
|
+ nickName: that.data.nickname
|
|
|
|
+ }
|
|
|
|
+ wx.showLoading({
|
|
|
|
+ title: '加载中...',
|
|
|
|
+ mask: true
|
|
|
|
+ })
|
|
|
|
+ bindBaseInfo(data).then(res => {
|
|
|
|
+ const _headImg = that.data.confirmAvatarUrl
|
|
|
|
+ const _userName = that.data.confirmNickname
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
|
|
+ app.globalData.userInfo.headImg = _headImg
|
|
|
|
+ app.globalData.userInfo.userName = _userName
|
|
|
|
+ wx.setStorageSync('headImg', _headImg)
|
|
|
|
+ wx.setStorageSync('userName', _userName)
|
|
|
|
+ that.setData({
|
|
|
|
+ userAuthShow: false
|
|
|
|
+ })
|
|
|
|
+ that.initIndexData()
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ wx.showModal({
|
|
|
|
+ content: e,
|
|
|
|
+ confirmColor: '#333',
|
|
|
|
+ showCancel: false
|
|
|
|
+ })
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
- onPullDownRefresh () {
|
|
|
|
|
|
+ /* onPullDownRefresh () {
|
|
wx.vibrateShort({
|
|
wx.vibrateShort({
|
|
type: 'medium'
|
|
type: 'medium'
|
|
})
|
|
})
|
|
this.initIndexData(true)
|
|
this.initIndexData(true)
|
|
- },
|
|
|
|
|
|
+ }, */
|
|
|
|
+
|
|
onShareAppMessage () {
|
|
onShareAppMessage () {
|
|
return {
|
|
return {
|
|
title: 'ITTHealth',
|
|
title: 'ITTHealth',
|
|
path: '/pages/index/index'
|
|
path: '/pages/index/index'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // 获取首页信息
|
|
|
|
|
|
+ // 获取首页信息 档案 剩余次数
|
|
initIndexData (pullDownRefresh = false) {
|
|
initIndexData (pullDownRefresh = false) {
|
|
var that = this
|
|
var that = this
|
|
wx.showLoading({
|
|
wx.showLoading({
|
|
@@ -113,10 +282,7 @@ Page({
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- // 打开地图选择位置。
|
|
|
|
- openMap () {
|
|
|
|
- wx.chooseLocation()
|
|
|
|
- },
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 处理套餐 购买 or 预约
|
|
* 处理套餐 购买 or 预约
|
|
* useNumber: 0-购买 1-预约
|
|
* useNumber: 0-购买 1-预约
|