import Apis from '@/common/apis/index' const mobileReg = /^1[3456789]\d{9}$/ export default { async initData() { try { uni.showLoading({ title: '加载中...' }) const res = await Apis.GetAssociation() this.users = res.data uni.hideLoading() } catch (e) { //TODO handle the exception } }, // 获取code login() { uni.showLoading({ title: '', mask: true }); let me = this uni.login({ async success(res) { if (res.code) { try { await Apis.wechatUserLogin({ code: res.code }) uni.hideLoading() } catch (err) { console.error(err) me.login() } } else { console.error(res.errMsg) me.login() } }, fail(res) { console.error(res) me.login() } }) }, // 手机号授权登录 async getPhoneNumber(event) { try { if (!uni.getStorageSync('userInfo') || !uni.getStorageSync('token')) { await this.login() } let me = this if (event.detail.errMsg === 'getPhoneNumber:ok') { uni.showLoading({ title: '正在登录...', mask: true }); let params = { refer_code: uni.getStorageSync('referCode') || '', iv: event.detail.iv, encryptedData: event.detail.encryptedData } await Apis.wechatMobileLogin(params) this.onGetUserInfo() } } catch (error) { console.error(error) } }, async onGetUserInfo() { const res = await Apis.getWechatUserInfo(); // 登录IM this.$imLogin.onImLogin(res.data) // 初始化Linkflow let userProfile = uni.getStorageSync('userProfile') || '' // 更新用户基本信息 let userInfo = res.data if (userProfile) { await Apis.updateWechatInfo(userProfile) userInfo = { ...res.data, ...userProfile } } uni.setStorageSync('userInfo', userInfo); this.$store.dispatch('LinkflowUserInfo'); this.$store.dispatch('LinkflowSendEvent', { event: 'UDE_357UY5NKYLE', attrs: { attr1: res.data.name, attr2: res.data.mobile, attr3: res.data.gender } }) var pages = getCurrentPages(); if (pages.length <= 1) { // 页面栈的实例小于一个页面 uni.reLaunch({ url: '../index/index' }) } else { this.onBackPage() } uni.hideLoading() }, onBackPage() { uni.navigateBack({ delta: 1 }) }, onEnterPage(page) { if (!this.userInfo) { return uni.navigateTo({ url: '../login/index' }) } switch (page) { case 'addPatient': uni.navigateTo({ url: '../addPatient/index' }) break case 'setting': uni.navigateTo({ url: '../setting/index' }) break } }, bindUnbundle(){ uni.showModal({ title: '提示', content: '确定解绑此学生信息吗?', success (res) { if (res.confirm) { console.log('用户点击确定'); } else if (res.cancel) { console.log('用户点击取消'); } } }); }, }