|
|
@@ -67,6 +67,7 @@ import {appLogin} from '@/api/common'
|
|
|
import { getDictionaries,postWxCode } from '@/api/mini'
|
|
|
import { replaceClientId } from '@/api/admin'
|
|
|
import { phoneLogin,wxMobileLogin } from "@/api/auth";
|
|
|
+
|
|
|
export default {
|
|
|
name: "login",
|
|
|
components: {},
|
|
|
@@ -113,7 +114,6 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
// #endif
|
|
|
-
|
|
|
},
|
|
|
onUnload(){
|
|
|
uni.offNetworkStatusChange(this.dealLogin)
|
|
|
@@ -148,6 +148,17 @@ export default {
|
|
|
this.agree = 0
|
|
|
}else{
|
|
|
this.agree = 1
|
|
|
+
|
|
|
+ //获取设备ID,并保存到storage
|
|
|
+ console.log('agreeItem -- 获取设备ID');
|
|
|
+ const systemInfo = uni.getSystemInfoSync();
|
|
|
+ if (systemInfo.platform === 'ios') {
|
|
|
+ this.getIosDeviceId()
|
|
|
+ } else if (systemInfo.platform === 'android') {
|
|
|
+ this.androidRegister();
|
|
|
+ //this.androidGetIdCodes();
|
|
|
+ this.androidGetOAID()
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
// 检查并提示用户阅读协议
|
|
|
@@ -161,6 +172,17 @@ export default {
|
|
|
cancelText: '不同意',
|
|
|
success(res) {
|
|
|
if (res.confirm) {
|
|
|
+ //获取设备ID,并保存到storage
|
|
|
+ console.log('checkAgreement -- 获取设备ID');
|
|
|
+ const systemInfo = uni.getSystemInfoSync();
|
|
|
+ if (systemInfo.platform === 'ios') {
|
|
|
+ that.getIosDeviceId()
|
|
|
+ } else if (systemInfo.platform === 'android') {
|
|
|
+ that.androidRegister();
|
|
|
+ //that.androidGetIdCodes();
|
|
|
+ that.androidGetOAID()
|
|
|
+ }
|
|
|
+
|
|
|
// 用户选择同意
|
|
|
that.agree = 1
|
|
|
that.$forceUpdate()
|
|
|
@@ -202,143 +224,155 @@ export default {
|
|
|
that.hasMobileNet = false
|
|
|
}
|
|
|
},
|
|
|
- wxPhoneLogin(e){
|
|
|
- let that = this
|
|
|
- let currentMiniOpenId = uni.getStorageSync('currentMiniOpenId')
|
|
|
- if (e.detail.errMsg === "getPhoneNumber:ok") {
|
|
|
- wxMobileLogin({ iv: e.detail.iv, encryptedData: e.detail.encryptedData,miniOpenId:currentMiniOpenId }).then(subRes => {
|
|
|
- uni.hideLoading()
|
|
|
- if(subRes.data && subRes.data.hasNoOpenId && subRes.data.hasNoOpenId ==1){
|
|
|
- that.$util.confirmModal({content:'网络异常,请重新操作'},() => {
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- uni.clearStorage()
|
|
|
- that.$store.commit("setLoginInfo", {})
|
|
|
- that.$util.pageTo({url: "/admin/home/workbench",type: 3})
|
|
|
- // #endif
|
|
|
- // #ifdef APP-PLUS
|
|
|
- uni.clearStorage()
|
|
|
- that.$store.commit("setLoginInfo", {})
|
|
|
- plus.runtime.restart()
|
|
|
- // #endif
|
|
|
- })
|
|
|
- return false
|
|
|
- }
|
|
|
- let token = subRes.data.token || ''
|
|
|
- if (that.$util.isEmpty(token)) {
|
|
|
- that.$msg('请先注册')
|
|
|
- return false
|
|
|
- }
|
|
|
- //有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
|
|
|
- if(subRes.code == 1){
|
|
|
- if (that.$util.isEmpty(subRes)) {
|
|
|
+ wxPhoneLogin(e){
|
|
|
+ let that = this
|
|
|
+ let currentMiniOpenId = uni.getStorageSync('currentMiniOpenId')
|
|
|
+ if (e.detail.errMsg === "getPhoneNumber:ok") {
|
|
|
+ wxMobileLogin({ iv: e.detail.iv, encryptedData: e.detail.encryptedData,miniOpenId:currentMiniOpenId }).then(subRes => {
|
|
|
+ uni.hideLoading()
|
|
|
+ if(subRes.data && subRes.data.hasNoOpenId && subRes.data.hasNoOpenId ==1){
|
|
|
+ that.$util.confirmModal({content:'网络异常,请重新操作'},() => {
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ uni.clearStorage()
|
|
|
+ that.$store.commit("setLoginInfo", {})
|
|
|
+ that.$util.pageTo({url: "/admin/home/workbench",type: 3})
|
|
|
+ // #endif
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ uni.clearStorage()
|
|
|
+ that.$store.commit("setLoginInfo", {})
|
|
|
+ plus.runtime.restart()
|
|
|
+ // #endif
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ let token = subRes.data.token || ''
|
|
|
+ if (that.$util.isEmpty(token)) {
|
|
|
+ that.$msg('请先注册')
|
|
|
return false
|
|
|
}
|
|
|
- uni.setStorageSync('token', subRes.data.token)
|
|
|
- uni.setStorageSync('shopId', subRes.data.admin.currentGhsShopId)
|
|
|
- getDictionaries({ token: subRes.data.token }).then(res => {
|
|
|
- if (that.$util.isEmpty(res)) {
|
|
|
+ //有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
|
|
|
+ if(subRes.code == 1){
|
|
|
+ if (that.$util.isEmpty(subRes)) {
|
|
|
return false
|
|
|
}
|
|
|
- that.$store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
|
|
|
- that.$store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
|
|
|
- })
|
|
|
- that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
|
|
|
- getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
|
|
|
- that.setUserShopAll()
|
|
|
+ uni.setStorageSync('token', subRes.data.token)
|
|
|
+ uni.setStorageSync('shopId', subRes.data.admin.currentGhsShopId)
|
|
|
+ getDictionaries({ token: subRes.data.token }).then(res => {
|
|
|
+ if (that.$util.isEmpty(res)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ that.$store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
|
|
|
+ that.$store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
|
|
|
+ })
|
|
|
+ that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
|
|
|
+ getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
|
|
|
+ that.setUserShopAll()
|
|
|
|
|
|
- uni.navigateBack()
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.$msg("登录失败");
|
|
|
- }
|
|
|
- },
|
|
|
- mobileLogin(){
|
|
|
- let that = this
|
|
|
+ uni.navigateBack()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$msg("登录失败");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mobileLogin(){
|
|
|
+ let that = this
|
|
|
|
|
|
- uni.showLoading({mask:true})
|
|
|
- uni.preLogin({
|
|
|
- provider: 'univerify',
|
|
|
- success:()=>{
|
|
|
- uni.hideLoading()
|
|
|
- uni.login({
|
|
|
- provider: 'univerify',
|
|
|
- // 自定义登录框样式
|
|
|
- univerifyStyle: {
|
|
|
- "fullScreen": true,
|
|
|
- "privacyTerms": {
|
|
|
- "defaultCheckBoxState":false,
|
|
|
- "checkBoxSize":18
|
|
|
+ uni.showLoading({mask:true})
|
|
|
+ uni.preLogin({
|
|
|
+ provider: 'univerify',
|
|
|
+ success:()=>{
|
|
|
+ uni.hideLoading()
|
|
|
+ uni.login({
|
|
|
+ provider: 'univerify',
|
|
|
+ // 自定义登录框样式
|
|
|
+ univerifyStyle: {
|
|
|
+ "fullScreen": true,
|
|
|
+ "privacyTerms": {
|
|
|
+ "defaultCheckBoxState":false,
|
|
|
+ "checkBoxSize":18
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 登录成功
|
|
|
+ success:(res)=>{
|
|
|
+ //获取设备ID,并保存到storage
|
|
|
+ console.log('GlobalMixins -- 获取设备ID');
|
|
|
+ const systemInfo = uni.getSystemInfoSync();
|
|
|
+ if (systemInfo.platform === 'ios') {
|
|
|
+ that.getIosDeviceId()
|
|
|
+ } else if (systemInfo.platform === 'android') {
|
|
|
+ that.androidRegister();
|
|
|
+ //that.androidGetIdCodes();
|
|
|
+ that.androidGetOAID()
|
|
|
+ }
|
|
|
+
|
|
|
+ let openid = res.authResult.openid
|
|
|
+ let access_token = res.authResult.access_token
|
|
|
+ phoneLogin({openid,access_token}).then(subRes=>{
|
|
|
+ let token = subRes.data.token || ''
|
|
|
+ if (that.$util.isEmpty(token)) {
|
|
|
+ that.$msg('请先注册')
|
|
|
+ return false
|
|
|
}
|
|
|
- },
|
|
|
- // 登录成功
|
|
|
- success:(res)=>{
|
|
|
- let openid = res.authResult.openid
|
|
|
- let access_token = res.authResult.access_token
|
|
|
- phoneLogin({openid,access_token}).then(subRes=>{
|
|
|
- let token = subRes.data.token || ''
|
|
|
- if (that.$util.isEmpty(token)) {
|
|
|
- that.$msg('请先注册')
|
|
|
+ //有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
|
|
|
+ if(subRes.code == 1){
|
|
|
+ if (that.$util.isEmpty(subRes)) {
|
|
|
return false
|
|
|
}
|
|
|
- //有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
|
|
|
- if(subRes.code == 1){
|
|
|
- if (that.$util.isEmpty(subRes)) {
|
|
|
+ uni.setStorageSync('token', subRes.data.token)
|
|
|
+ uni.setStorageSync('shopId', subRes.data.admin.currentGhsShopId)
|
|
|
+ getDictionaries({ token: subRes.data.token }).then(res => {
|
|
|
+ if (that.$util.isEmpty(res)) {
|
|
|
return false
|
|
|
}
|
|
|
- uni.setStorageSync('token', subRes.data.token)
|
|
|
- uni.setStorageSync('shopId', subRes.data.admin.currentGhsShopId)
|
|
|
- getDictionaries({ token: subRes.data.token }).then(res => {
|
|
|
- if (that.$util.isEmpty(res)) {
|
|
|
- return false
|
|
|
- }
|
|
|
- that.$store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
|
|
|
- that.$store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
|
|
|
- })
|
|
|
- that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
|
|
|
- getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
|
|
|
- that.setUserShopAll()
|
|
|
- uni.navigateBack()
|
|
|
+ that.$store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
|
|
|
+ that.$store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
|
|
|
+ })
|
|
|
+ that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
|
|
|
+ getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
|
|
|
+ that.setUserShopAll()
|
|
|
+ uni.navigateBack()
|
|
|
|
|
|
- // #ifdef APP-PLUS
|
|
|
- //保存 clientId
|
|
|
- //let hasClientId = !that.$util.isEmpty(subRes.data.admin.clientId) ? subRes.data.admin.clientId : ''
|
|
|
- const clientInfo = plus.push.getClientInfo()
|
|
|
- let currentClientId = !that.$util.isEmpty(clientInfo.clientid) ? clientInfo.clientid : ''
|
|
|
- if(currentClientId != ''){
|
|
|
- replaceClientId({id:currentClientId, auto:0})
|
|
|
- }
|
|
|
- // #endif
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ //保存 clientId
|
|
|
+ //let hasClientId = !that.$util.isEmpty(subRes.data.admin.clientId) ? subRes.data.admin.clientId : ''
|
|
|
+ const clientInfo = plus.push.getClientInfo()
|
|
|
+ let currentClientId = !that.$util.isEmpty(clientInfo.clientid) ? clientInfo.clientid : ''
|
|
|
+ const deviceId = uni.getStorageSync('deviceId')
|
|
|
+ if(currentClientId != ''){
|
|
|
+ replaceClientId({id:currentClientId, deviceId:deviceId, auto:0})
|
|
|
}
|
|
|
- })
|
|
|
- },
|
|
|
- fail(res){
|
|
|
- uni.showToast({title:'已取消', duration: 3000, icon:'none'})
|
|
|
- //关闭一键登录弹出窗口
|
|
|
- uni.closeAuthView()
|
|
|
- console.log(res)
|
|
|
- },
|
|
|
- complete: (res) => {
|
|
|
- uni.hideLoading()
|
|
|
- uni.closeAuthView()
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- fail(res){
|
|
|
- //如果手机没有插入有效的sim卡,或者手机蜂窝数据网络关闭,都有可能造成预登录校验失败
|
|
|
- if (res.code == 30005) {
|
|
|
- uni.showToast({title: '请关闭WIFI,打开移动流量', duration: 3000, icon:'none'})
|
|
|
- } else if(res.code == 1000) {
|
|
|
- uni.showToast({title: '即将开通', duration: 3000, icon:'none'})
|
|
|
- } else if(res.code == 40004) {
|
|
|
- uni.showToast({title: '即将开通...', duration: 3000, icon:'none'})
|
|
|
- } else {
|
|
|
- uni.showToast({title: '登录失败...', duration: 3000, icon:'none'})
|
|
|
+ // #endif
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res){
|
|
|
+ uni.showToast({title:'已取消', duration: 3000, icon:'none'})
|
|
|
+ //关闭一键登录弹出窗口
|
|
|
+ uni.closeAuthView()
|
|
|
+ console.log(res)
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ uni.hideLoading()
|
|
|
+ uni.closeAuthView()
|
|
|
}
|
|
|
- console.log(res)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res){
|
|
|
+ //如果手机没有插入有效的sim卡,或者手机蜂窝数据网络关闭,都有可能造成预登录校验失败
|
|
|
+ if (res.code == 30005) {
|
|
|
+ uni.showToast({title: '请关闭WIFI,打开移动流量', duration: 3000, icon:'none'})
|
|
|
+ } else if(res.code == 1000) {
|
|
|
+ uni.showToast({title: '即将开通', duration: 3000, icon:'none'})
|
|
|
+ } else if(res.code == 40004) {
|
|
|
+ uni.showToast({title: '即将开通...', duration: 3000, icon:'none'})
|
|
|
+ } else {
|
|
|
+ uni.showToast({title: '登录失败...', duration: 3000, icon:'none'})
|
|
|
+ }
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
loginFun(){
|
|
|
let that = this
|
|
|
let mobile = this.mobile
|
|
|
@@ -360,7 +394,7 @@ export default {
|
|
|
this.checkAgreement(function(){
|
|
|
uni.showLoading({mask:true})
|
|
|
//有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
|
|
|
- appLogin({mobile, password}).then(subRes=>{
|
|
|
+ appLogin({mobile, password, deviceId: uni.getStorageSync('deviceId')}).then(subRes=>{
|
|
|
uni.hideLoading()
|
|
|
if(subRes.code == 1){
|
|
|
if (that.$util.isEmpty(subRes)) {
|
|
|
@@ -383,16 +417,74 @@ export default {
|
|
|
// #ifdef APP-PLUS
|
|
|
//保存 clientId
|
|
|
const clientInfo = plus.push.getClientInfo()
|
|
|
+ const deviceId = uni.getStorageSync('deviceId')
|
|
|
let currentClientId = !that.$util.isEmpty(clientInfo.clientid) ? clientInfo.clientid : ''
|
|
|
if(currentClientId != ''){
|
|
|
- replaceClientId({id:currentClientId, auto:0})
|
|
|
+ replaceClientId({id:currentClientId, deviceId:deviceId, auto:0})
|
|
|
}
|
|
|
// #endif
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ getIosDeviceId() {
|
|
|
+ const keychain = uni.requireNativePlugin('Univalsoft-DeviceId');
|
|
|
+ keychain.getDeviceIDCallback((ret)=>{
|
|
|
+ let deviceId = ret ? ret : '';
|
|
|
+ if(deviceId != ''){
|
|
|
+ uni.setStorageSync('deviceId', deviceId)
|
|
|
}
|
|
|
+ // uni.showToast({
|
|
|
+ // title:'GlobalMixins -- 调用方法 uuid ' + ret,
|
|
|
+ // icon: "none"
|
|
|
+ // })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ androidRegister() {
|
|
|
+ const idCode = uni.requireNativePlugin('Ba-IdCode');
|
|
|
+ idCode.register(res => {
|
|
|
+ console.log('Ba-IdCode register', res);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ androidGetIdCodes() {
|
|
|
+ const idCode = uni.requireNativePlugin('Ba-IdCode');
|
|
|
+ idCode.getIdCodes(res => {
|
|
|
+ console.log(res);
|
|
|
+ // if (res.data) {
|
|
|
+ // this.msgList.unshift(JSON.stringify(res.data))
|
|
|
+ // }
|
|
|
+ if(res.data.AndroidID && res.data.AndroidID != ''){
|
|
|
+ uni.setStorageSync('deviceId', res.data.AndroidID)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(res.data.GUID && res.data.GUID != ''){
|
|
|
+ uni.setStorageSync('deviceId', res.data.GUID)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(res.data.IMEI && res.data.IMEI != ''){
|
|
|
+ uni.setStorageSync('deviceId', res.data.IMEI)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ androidGetOAID() {
|
|
|
+ const idCode = uni.requireNativePlugin('Ba-IdCode');
|
|
|
+ idCode.getOAID((res) => {
|
|
|
+ let OAID = (res.data && res.data.OAID) ? res.data.OAID : '';
|
|
|
+
|
|
|
+ //OAID为空 或 OAID 只包含有0、-字符,不包含其他字符,则调用 getIdCodes 方法获取设备ID
|
|
|
+ if (OAID == '' || (!/^(0|-)$/.test(OAID)) ) {
|
|
|
+ this.androidGetIdCodes()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OAID) {
|
|
|
+ uni.setStorageSync('deviceId', OAID);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ // #endif
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|