| | |
| | | // pages/auth/auth.js |
| | | import { |
| | | wxLoginCustomer, |
| | | getDictData, |
| | | getWxMiniPhone |
| | | } from '../../api/index' |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | */ |
| | | data: { |
| | | agreementFalg: false, |
| | | primary: '' |
| | | }, |
| | | primary: '', |
| | | |
| | | showModal: false, |
| | | serviceHtml: '', |
| | | title: '', |
| | | privacyHtml: '', |
| | | activeHtml: '' |
| | | }, |
| | | initData(){ |
| | | getDictData({ |
| | | code: 'ZBOM_CUSTOMIZED', |
| | | label: 'SERVER_AGREEMENT' |
| | | }).then(res => { |
| | | this.setData({ |
| | | serviceHtml: res.data.code |
| | | }) |
| | | }) |
| | | getDictData({ |
| | | code: 'ZBOM_CUSTOMIZED', |
| | | label: 'PRIVACY_AGREEMENT' |
| | | }).then(res => { |
| | | this.setData({ |
| | | privacyHtml: res.data.code |
| | | }) |
| | | }) |
| | | }, |
| | | getPhoneNumber (e) { |
| | | console.log(e.detail) |
| | | console.log(e.detail.iv) |
| | | console.log(e.detail.encryptedData) |
| | | const data = { ...e.detail } |
| | | getWxMiniPhone({ |
| | | encryptedData: data.encryptedData, |
| | | iv: data.iv, |
| | | sessionKey: wx.getStorageSync('sessionKey'), |
| | | }) |
| | | }, |
| | | loginIn() { |
| | | const { agreementFalg } = this.data |
| | | if(!agreementFalg) return wx.showToast({ |
| | | title: '请先阅读并同意相关协议', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }) |
| | | wx.login({ |
| | | success: (res) => { |
| | | if (res.code) { |
| | | // 获取到用户登录凭证 code |
| | | const code = res.code; |
| | | wx.setStorageSync('code', res.code) |
| | | // 将 code 发送给后端服务器 |
| | | wxLoginCustomer({code}).then(ress => { |
| | | wx.setStorageSync('token', ress.data.token) |
| | | wx.setStorageSync('member', ress.data.member) |
| | | wx.redirectTo({ |
| | | url: '/pages/index/index', |
| | | }) |
| | | }) |
| | | } else { |
| | | console.error('获取用户登录凭证失败', res.errMsg); |
| | | } |
| | | }, |
| | | fail: (err) => { |
| | | console.error('调用 wx.login 失败', err); |
| | | }, |
| | | }) |
| | | }, |
| | | onOpen(e){ |
| | | console.log('e', e); |
| | | const { serviceHtml, privacyHtml } = this.data |
| | | const { index } = e.target.dataset |
| | | let activeHtml = index == '0' ? serviceHtml : privacyHtml |
| | | this.setData({ |
| | | activeHtml, |
| | | showModal: true |
| | | }) |
| | | }, |
| | | onClose(){ |
| | | this.setData({showModal: false}) |
| | | }, |
| | | agreementChange(e) { |
| | | this.setData({ |
| | | agreementFalg: e.detail, |
| | |
| | | this.setData({ |
| | | primary: app.primary |
| | | }) |
| | | this.initData() |
| | | }, |
| | | |
| | | /** |