|
|
@ -1,12 +1,9 @@ |
|
|
//获取应用实例
|
|
|
//获取应用实例
|
|
|
import Dialog from '../../components/dialog/dialog' |
|
|
import Dialog from '../../components/dialog/dialog' |
|
|
import { config, wechatApplet, getUserInfo, loginWechat, authCaptcha, verifyCaptcha, bindingAdmin, bindingAccount } from "../api/user" |
|
|
|
|
|
// import { loginToken, cconfig } from "../api/cloud"
|
|
|
|
|
|
// import { mconfig } from "../api/mall"
|
|
|
|
|
|
import { pconfig } from "../api/payment" |
|
|
|
|
|
|
|
|
import { config, postCaptcha, loginCaptcha, loginPwd, verifyCode } from "../api/user" |
|
|
|
|
|
import { sconfig, loginToken, getBaseInfo } from "../api/saas" |
|
|
const util = require('../../utils/util') |
|
|
const util = require('../../utils/util') |
|
|
const storage = require('../../utils/storage') |
|
|
const storage = require('../../utils/storage') |
|
|
const event = require('../../utils/event') |
|
|
|
|
|
const app = getApp() |
|
|
const app = getApp() |
|
|
|
|
|
|
|
|
Page({ |
|
|
Page({ |
|
|
@ -23,145 +20,106 @@ Page({ |
|
|
captcha: null |
|
|
captcha: null |
|
|
}, |
|
|
}, |
|
|
loging: false, |
|
|
loging: false, |
|
|
regist: false, |
|
|
|
|
|
qrPage: null, |
|
|
qrPage: null, |
|
|
metaData: null, |
|
|
metaData: null, |
|
|
code: null, |
|
|
|
|
|
checked: true, |
|
|
|
|
|
height: app.globalData.fragmentHeight |
|
|
|
|
|
|
|
|
code: null |
|
|
}, |
|
|
}, |
|
|
/************************************** 初始化登录流程 ********************************************/ |
|
|
/************************************** 初始化登录流程 ********************************************/ |
|
|
onLoad: function (options) { |
|
|
onLoad: function (options) { |
|
|
var json = storage.get('metaData') |
|
|
|
|
|
if(options.code && json){ |
|
|
|
|
|
//分享带code进入的,
|
|
|
|
|
|
this.setData({ code: options.code, height: app.globalData.fragmentHeight }) |
|
|
|
|
|
storage.remove('metaData') |
|
|
|
|
|
var form = JSON.parse(json) |
|
|
|
|
|
this.data.metaData = form.metaData |
|
|
|
|
|
this.data.qrPage = form.redirectUrl |
|
|
|
|
|
} else { |
|
|
|
|
|
this.setData({ height: app.globalData.fragmentHeight }) |
|
|
|
|
|
} |
|
|
|
|
|
this.wxLogin() |
|
|
|
|
|
}, |
|
|
|
|
|
onEvent: function (message) { |
|
|
|
|
|
if (message.what == 888) { |
|
|
|
|
|
this.initAccountInfo() |
|
|
|
|
|
|
|
|
const updateManager = wx.getUpdateManager() |
|
|
|
|
|
updateManager.onCheckForUpdate() |
|
|
|
|
|
updateManager.onUpdateReady(function () { |
|
|
|
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
|
|
|
updateManager.applyUpdate() |
|
|
|
|
|
}) |
|
|
|
|
|
if(options.q){ |
|
|
|
|
|
//扫二维码进入的,
|
|
|
|
|
|
let q = decodeURIComponent(options.q) |
|
|
|
|
|
this.data.code = q.substring(q.indexOf('?')) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
wxLogin: function(){ |
|
|
|
|
|
wx.login({ |
|
|
|
|
|
success: res => { |
|
|
|
|
|
// 获取openId
|
|
|
|
|
|
wechatApplet({ authCode: res.code }).then(result => { |
|
|
|
|
|
storage.put('tmpAuthToken', result.data.tmpAuthToken, 98) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
onReady: function () { |
|
|
|
|
|
wx.getSystemInfo({ |
|
|
|
|
|
success: e => { |
|
|
|
|
|
app.globalData.isIos = this.checkIos(e) |
|
|
|
|
|
app.globalData.dev = e.platform == 'devtools' |
|
|
|
|
|
|
|
|
|
|
|
let custom = wx.getMenuButtonBoundingClientRect() |
|
|
|
|
|
app.globalData.Custom = custom |
|
|
|
|
|
// 顶部操作栏高度
|
|
|
|
|
|
app.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight + (app.globalData.isIos ? 4 : 0) |
|
|
|
|
|
let windowHeight = e.windowHeight * (750 / e.windowWidth) |
|
|
|
|
|
|
|
|
|
|
|
let safeBottom = e.windowHeight - e.safeArea.bottom |
|
|
|
|
|
if(safeBottom > e.windowHeight){ |
|
|
|
|
|
safeBottom = 34 |
|
|
|
|
|
} |
|
|
|
|
|
app.globalData.safeBottom = safeBottom * (750 / e.windowWidth) |
|
|
|
|
|
// 状态栏高度
|
|
|
|
|
|
app.globalData.StatusBar = e.statusBarHeight * (750 / e.windowWidth) |
|
|
|
|
|
let statusBarHeight = app.globalData.CustomBar * (750 / e.windowWidth) |
|
|
|
|
|
app.globalData.statusBarHeight = statusBarHeight |
|
|
|
|
|
// fragmentHeight:指的是整个页面statusBarHeight以下的高度
|
|
|
|
|
|
app.globalData.fragmentHeight = windowHeight - statusBarHeight |
|
|
|
|
|
app.globalData.safeFragmentHeight = windowHeight - statusBarHeight - app.globalData.safeBottom |
|
|
|
|
|
app.globalData.windowWidth = e.windowWidth |
|
|
|
|
|
|
|
|
|
|
|
if(this.data.code){ |
|
|
|
|
|
this.fetchQrCode(this.data.code) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.fetchUserInfo() |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
// 获取用户信息,进行登录
|
|
|
|
|
|
|
|
|
checkIos: function (e) { |
|
|
|
|
|
if ('ios' === e.platform) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
if (e.system.startsWith('iOS')) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
}, |
|
|
|
|
|
/************************************** 获取用户信息,进行登录 ********************************************/ |
|
|
fetchUserInfo: function(){ |
|
|
fetchUserInfo: function(){ |
|
|
config.header = { 'Authorization': 'QNT ' + app.globalData.token } |
|
|
|
|
|
|
|
|
var authorization = app.globalData.token || storage.get('Authorization') |
|
|
|
|
|
if (util.isEmpty(authorization)) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
app.globalData.token = authorization |
|
|
|
|
|
config.header = { 'Authorization': 'QNT ' + authorization } |
|
|
this.setData({ loging: true}) |
|
|
this.setData({ loging: true}) |
|
|
getUserInfo().then(result => { |
|
|
|
|
|
this.setData({ loging: false}) |
|
|
|
|
|
if(!result.data.mobile){ |
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
//小白用户;注册流程;
|
|
|
|
|
|
this.setData({ regist: true }) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if (result.data.token) { |
|
|
|
|
|
storage.put('Authorization', result.data.token) |
|
|
|
|
|
app.globalData.token = result.data.token |
|
|
|
|
|
} |
|
|
|
|
|
app.accountInfo = result.data |
|
|
|
|
|
if(result.data.enterpriseId){ |
|
|
|
|
|
// 企业不一致
|
|
|
|
|
|
var invaild = false |
|
|
|
|
|
if(this.data.metaData && this.data.metaData.enterpriseId){ |
|
|
|
|
|
invaild = result.data.enterpriseId != this.data.metaData.enterpriseId |
|
|
|
|
|
} else if(this.data.metaData && this.data.metaData.joiningEnterprisePublicInvitationId){ |
|
|
|
|
|
invaild = result.data.enterpriseId != this.data.metaData.joiningEnterprisePublicInvitationId |
|
|
|
|
|
} |
|
|
|
|
|
if(invaild){ |
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
Dialog.alert({ title: '温馨提示', message: '您已经绑定过企业,现在就进入?' }).then(() => { |
|
|
|
|
|
this.toIndex() |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.toIndex() |
|
|
|
|
|
} |
|
|
|
|
|
} else if(this.data.metaData){ |
|
|
|
|
|
// 如果有metaData
|
|
|
|
|
|
|
|
|
loginToken({loginToken: app.globalData.token}).then(result => { |
|
|
|
|
|
sconfig.header = { 'Authorization': 'QNT ' + result.data.token } |
|
|
|
|
|
getBaseInfo().then(result => { |
|
|
|
|
|
this.setData({ loging: false}) |
|
|
|
|
|
app.userInfo = result.data |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
this.setData({ metaData: this.data.metaData, qrPage: this.data.qrPage, regist: false, loging: false }) |
|
|
|
|
|
} else { |
|
|
|
|
|
//如果绑定过手机号码;
|
|
|
|
|
|
|
|
|
wx.redirectTo({ url: '/pages/index/index' }) |
|
|
|
|
|
}).catch(err => { |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
this.toIndex() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
util.showToast(err) |
|
|
|
|
|
app.globalData.token = null |
|
|
|
|
|
storage.remove('Authorization') |
|
|
|
|
|
config.header = null |
|
|
|
|
|
this.setData({ loging: false}) |
|
|
|
|
|
}) |
|
|
}).catch(err => { |
|
|
}).catch(err => { |
|
|
//异常回调
|
|
|
|
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
|
|
|
util.showToast(err) |
|
|
|
|
|
app.globalData.token = null |
|
|
|
|
|
storage.remove('Authorization') |
|
|
|
|
|
config.header = null |
|
|
this.setData({ loging: false}) |
|
|
this.setData({ loging: false}) |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
toIndex: function(){ |
|
|
|
|
|
loginToken({loginToken: app.globalData.token}).then(result => { |
|
|
|
|
|
mconfig.header = { 'Authorization': 'QNT ' + result.data } |
|
|
|
|
|
cconfig.header = { 'Authorization': 'QNT ' + result.data } |
|
|
|
|
|
pconfig.header = { 'Authorization': 'QNT ' + result.data } |
|
|
|
|
|
// 登录完成...
|
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
event.emit('EventMessage', { what: 888, desc: 'Logined' }) |
|
|
|
|
|
wx.navigateBack() |
|
|
|
|
|
}).catch(err => { |
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
onBoxChange: function({detail}){ |
|
|
|
|
|
this.setData({ checked: detail }) |
|
|
|
|
|
}, |
|
|
|
|
|
/************************************** 注册流程 ********************************************/ |
|
|
/************************************** 注册流程 ********************************************/ |
|
|
readAgreement: function () { |
|
|
readAgreement: function () { |
|
|
wx.navigateTo({ url: '/pages/htmls/agreement/index' }) |
|
|
wx.navigateTo({ url: '/pages/htmls/agreement/index' }) |
|
|
}, |
|
|
}, |
|
|
onGotUserInfo: function (e) { |
|
|
|
|
|
if(!this.data.checked){ |
|
|
|
|
|
util.showToast('请阅读并同意《服务与隐私协议》') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if(this.data.loging){ |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
this.setData({ loging: true }) |
|
|
|
|
|
if(this.data.form.tmpAuthToken){ |
|
|
|
|
|
this.registAccount() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
loginWechat({ encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then(result => { |
|
|
|
|
|
storage.put('Authorization', result.data.token) |
|
|
|
|
|
app.globalData.token = result.data.token |
|
|
|
|
|
this.data.form.tmpAuthToken = result.data.tmpAuthToken |
|
|
|
|
|
if(e.currentTarget.id == 'btn-login'){ |
|
|
|
|
|
this.registAccount() |
|
|
|
|
|
} else { |
|
|
|
|
|
this.fetchUserInfo() |
|
|
|
|
|
} |
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
if(error.data && error.data.tmpAuthToken){ |
|
|
|
|
|
this.data.form.tmpAuthToken = error.data.tmpAuthToken |
|
|
|
|
|
this.setData({ regist: true, loging: false }) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.setData({ loging: false }) |
|
|
|
|
|
} |
|
|
|
|
|
util.showToast(error.message) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
inputFocus: function(e) { |
|
|
inputFocus: function(e) { |
|
|
storage.put('keyboardHeight', e.detail.height) |
|
|
|
|
|
|
|
|
app.globalData.keyboardHeight = e.detail.height |
|
|
}, |
|
|
}, |
|
|
bindInput: function (e) { |
|
|
bindInput: function (e) { |
|
|
this.data.form[e.target.id] = e.detail.value |
|
|
this.data.form[e.target.id] = e.detail.value |
|
|
@ -191,16 +149,13 @@ Page({ |
|
|
onFinished: function(){ |
|
|
onFinished: function(){ |
|
|
this.setData({ second: '重新获取验证码', codeEnable: true }) |
|
|
this.setData({ second: '重新获取验证码', codeEnable: true }) |
|
|
}, |
|
|
}, |
|
|
loginFrom: function(){ |
|
|
|
|
|
this.setData({ regist: true }) |
|
|
|
|
|
}, |
|
|
|
|
|
fetchCaptcha: function(){ |
|
|
fetchCaptcha: function(){ |
|
|
if (!(/^1\d{10}$/.test(this.data.form.account)) || this.data.form.account.length < 11) { |
|
|
if (!(/^1\d{10}$/.test(this.data.form.account)) || this.data.form.account.length < 11) { |
|
|
util.showToast('请输入11位手机号码') |
|
|
util.showToast('请输入11位手机号码') |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
wx.showLoading({ title: '正在获取', mask: true }) |
|
|
wx.showLoading({ title: '正在获取', mask: true }) |
|
|
authCaptcha({ verifiableAccount: this.data.form.account, verifiableAccountType: 1, purpose: 1 }).then(result => { |
|
|
|
|
|
|
|
|
postCaptcha({ verifiableAccount: this.data.form.account, verifiableAccountType: 1, purpose: 1 }).then(result => { |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
this.setData({ codeEnable: false }) |
|
|
this.setData({ codeEnable: false }) |
|
|
util.showToast('验证码已经发送') |
|
|
util.showToast('验证码已经发送') |
|
|
@ -227,45 +182,53 @@ Page({ |
|
|
} |
|
|
} |
|
|
wx.showLoading({ title: '登录中', mask: true }) |
|
|
wx.showLoading({ title: '登录中', mask: true }) |
|
|
this.setData({ loging: true }) |
|
|
this.setData({ loging: true }) |
|
|
// this.data.form.password = md5.hexMD5(this.data.form.password).toUpperCase()
|
|
|
|
|
|
if (this.data.type == 1) { |
|
|
if (this.data.type == 1) { |
|
|
verifyCaptcha(this.data.form).then(result => { |
|
|
|
|
|
wx.setStorageSync('Authorization', result.data.token) |
|
|
|
|
|
|
|
|
loginCaptcha(this.data.form).then(result => { |
|
|
|
|
|
storage.put('Authorization', result.data.token) |
|
|
app.globalData.token = result.data.token |
|
|
app.globalData.token = result.data.token |
|
|
this.fetchUserInfo() |
|
|
this.fetchUserInfo() |
|
|
}).catch(error => { |
|
|
}).catch(error => { |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
this.setData({ loging: false }) |
|
|
|
|
|
|
|
|
console.log(error) |
|
|
util.showToast(error) |
|
|
util.showToast(error) |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
// authorize/by-password 密码登录
|
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
/************************************** 二维码流程 ********************************************/ |
|
|
|
|
|
bindAccount: function(){ |
|
|
|
|
|
if (util.isEmpty(this.data.form.userName)) { |
|
|
|
|
|
util.showToast('请输入您的姓名,以便于识别') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
this.setData({ loging: true }) |
|
|
|
|
|
this.data.metaData.userName = this.data.form.userName |
|
|
|
|
|
if(this.data.qrPage == '/page/index/yaoqing'){ |
|
|
|
|
|
bindingAdmin(this.data.metaData).then(result => { |
|
|
|
|
|
this.data.metaData = null |
|
|
|
|
|
|
|
|
loginPwd(this.data.form).then(result => { |
|
|
|
|
|
storage.put('Authorization', result.data.token) |
|
|
|
|
|
app.globalData.token = result.data.token |
|
|
this.fetchUserInfo() |
|
|
this.fetchUserInfo() |
|
|
}).catch(error => { |
|
|
}).catch(error => { |
|
|
this.setData({loging: false}) |
|
|
|
|
|
|
|
|
wx.hideLoading() |
|
|
util.showToast(error) |
|
|
util.showToast(error) |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
changeType: function () { |
|
|
|
|
|
if (this.data.type == 1) { |
|
|
|
|
|
this.setData({ type: 0, ['form.captcha']: null, loginEnable: true }) |
|
|
} else { |
|
|
} else { |
|
|
bindingAccount(this.data.metaData).then(result => { |
|
|
|
|
|
this.data.metaData = null |
|
|
|
|
|
this.fetchUserInfo() |
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
this.setData({loging: false}) |
|
|
|
|
|
util.showToast(error) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
this.setData({ type: 1, ['form.password']: null, loginEnable: true }) |
|
|
} |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
/************************************** 二维码流程 ********************************************/ |
|
|
|
|
|
fetchQrCode: function(code){ |
|
|
|
|
|
verifyCode(code).then(result => { |
|
|
|
|
|
this.data.code = null |
|
|
|
|
|
if(result.data.redirectUrl == '/login'){ |
|
|
|
|
|
// 根据userId来获取用户信息;并且直接登录
|
|
|
|
|
|
app.globalData.token = result.data.metaData.token |
|
|
|
|
|
storage.put('Authorization', app.globalData.token) |
|
|
|
|
|
this.fetchUserInfo() |
|
|
|
|
|
} else { |
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
if(!result.data.message){ |
|
|
|
|
|
result.data.message = '二维码解析失败,请重新扫码' |
|
|
|
|
|
} |
|
|
|
|
|
util.showToast(result.data.message) |
|
|
|
|
|
} |
|
|
|
|
|
}).catch(err => { |
|
|
|
|
|
//异常回调
|
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |