Преглед изворни кода

改成登录成功之后,才获取相关权限

获取物理数据合并到一个方法里去
shish пре 2 месеци
родитељ
комит
3fed3041c7

+ 1 - 0
ghsApp/.hbuilderx/launch.json

@@ -27,6 +27,7 @@
             "type" : "uni-app:app-ios"
         },
         {
+            "customPlaygroundType" : "local",
             "playground" : "custom",
             "type" : "uni-app:app-android"
         },

+ 5 - 107
ghsApp/src/admin/home/login.vue

@@ -109,7 +109,6 @@ import { mapActions } from "vuex";
 import { getShopInfo} from "@/utils/auth";
 import {appLogin} from '@/api/common'
 import { getDictionaries,postWxCode } from '@/api/mini'
-import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 
 export default {
@@ -202,17 +201,6 @@ 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()
-				}
 			}
 		},
 		// 检查并提示用户阅读协议
@@ -226,18 +214,6 @@ 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()
 							if(callback && typeof callback === 'function'){
@@ -323,6 +299,9 @@ export default {
 						that.setUserShopAll()
 
 						uni.navigateBack()
+						// #ifdef APP-PLUS
+						that.$util.afterAppLoginSuccess({ auto: 0 })
+						// #endif
 					}
 				});
 			} else {
@@ -349,17 +328,6 @@ export default {
 						},
 						// 登录成功
 						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=>{
@@ -388,14 +356,7 @@ export default {
 									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 : ''
-									const deviceId = uni.getStorageSync('deviceId')
-									if(currentClientId != ''){
-										replaceClientId({id:currentClientId, deviceId:deviceId, auto:0})
-									}
+									that.$util.afterAppLoginSuccess({ auto: 0 })
 									// #endif
 								}
 							})
@@ -469,76 +430,13 @@ export default {
 						uni.navigateBack()
 
 						// #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, deviceId:deviceId, auto:0})
-						}
+						that.$util.afterAppLoginSuccess({ 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>

+ 9 - 1
ghsApp/src/admin/home/pwdLogin.vue

@@ -58,7 +58,6 @@ import { mapActions } from "vuex";
 import { getShopInfo} from "@/utils/auth";
 import {appLogin} from '@/api/common'
 import { getDictionaries,postWxCode } from '@/api/mini'
-import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 import CaptchaVerify from "@/components/CaptchaVerify.vue";
 
@@ -214,6 +213,9 @@ export default {
 						that.setUserShopAll()
 
 						uni.navigateBack()
+						// #ifdef APP-PLUS
+						that.$util.afterAppLoginSuccess({ auto: 0 })
+						// #endif
 					}
 				});
 			} else {
@@ -273,6 +275,9 @@ export default {
 									getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 									that.setUserShopAll()
 									uni.navigateBack()
+									// #ifdef APP-PLUS
+									that.$util.afterAppLoginSuccess({ auto: 0 })
+									// #endif
 								}
 							})
 						},
@@ -351,6 +356,9 @@ export default {
 					getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 					that.setUserShopAll()
 					uni.navigateBack()
+					// #ifdef APP-PLUS
+					that.$util.afterAppLoginSuccess({ auto: 0 })
+					// #endif
 				}
 			})
 

+ 9 - 1
ghsApp/src/admin/home/smsLogin.vue

@@ -58,7 +58,6 @@ import { mapActions } from "vuex";
 import { getShopInfo} from "@/utils/auth";
 import {appLogin} from '@/api/common'
 import { getDictionaries,postWxCode } from '@/api/mini'
-import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 import CaptchaVerify from "@/components/CaptchaVerify.vue";
 
@@ -211,6 +210,9 @@ export default {
 						that.setUserShopAll()
 
 						uni.navigateBack()
+						// #ifdef APP-PLUS
+						that.$util.afterAppLoginSuccess({ auto: 0 })
+						// #endif
 					}
 				});
 			} else {
@@ -270,6 +272,9 @@ export default {
 									getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 									that.setUserShopAll()
 									uni.navigateBack()
+									// #ifdef APP-PLUS
+									that.$util.afterAppLoginSuccess({ auto: 0 })
+									// #endif
 								}
 							})
 						},
@@ -348,6 +353,9 @@ export default {
 					getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 					that.setUserShopAll()
 					uni.navigateBack()
+					// #ifdef APP-PLUS
+					that.$util.afterAppLoginSuccess({ auto: 0 })
+					// #endif
 				}
 			})
 

+ 2 - 2
ghsApp/src/manifest.json

@@ -2,7 +2,7 @@
     "name" : "销花宝",
     "appid" : "__UNI__BD781B0",
     "description" : "鲜花批发销售管理系统",
-    "versionName" : "1.2.96",
+    "versionName" : "1.2.97",
     "versionCode" : 1291,
     "transformPx" : true,
     /* 5+App特有相关 */
@@ -235,7 +235,7 @@
         "optimization" : {
             "subPackages" : true
         },
-        "lazyCodeLoading":"requiredComponents",
+        "lazyCodeLoading" : "requiredComponents",
         "uniStatistics" : {
             "enable" : false
         },

+ 3 - 76
ghsApp/src/mixins/globalMixins.js

@@ -4,7 +4,6 @@ import { pageTo, isLogin } from '@/utils/util.js'
 import { getShopInfo, wxMiniLogin } from '@/utils/auth'
 import { postWxCode, getDictionaries } from '@/api/mini'
 import { getStaffApi,hasTokenAutoLogin } from '@/api/common'
-import { replaceClientId } from '@/api/admin'
 import { codePay} from "@/api/order/index";
 
 export default {
@@ -99,17 +98,6 @@ export default {
             return
           }
 
-          //获取设备ID,并保存到storage
-          console.log('GlobalMixins -- 获取设备ID');
-          const systemInfo = uni.getSystemInfoSync();
-          if (systemInfo.platform === 'ios') {
-            this.getIosDeviceId()
-          } else if (systemInfo.platform === 'android') {
-            this.androidRegister();
-            //this.androidGetIdCodes();
-            this.androidGetOAID()
-          }
-
 					getDictionaries({ token: subRes.data.token }).then(res => {
 						if (!that.$util.isEmpty(res)) {
               store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
@@ -122,14 +110,6 @@ export default {
           this.listenPDAkd()
           this.setUserShopAll()
           this.init()
-
-          //更新 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: 1})
-          }
         })
       }
       // #endif 
@@ -238,65 +218,12 @@ export default {
         getShopInfo(true)
         //获取门店信息
         this.setUserShopAll();
+        // #ifdef APP-PLUS
+        this.$util.afterAppLoginSuccess({ auto: 0 })
+        // #endif
         uni.reLaunch({url:'/admin/home/workbench'})
       })
     },
-    // #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 != ''){ // 注意:Android 10+取消了获取IMEI的API
-            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
 	},
 	mounted() {
 		if (this.mInit) {

+ 136 - 0
ghsApp/src/utils/appDevice.js

@@ -0,0 +1,136 @@
+import { replaceClientId } from '@/api/admin'
+
+function isInvalidOaid(OAID) {
+	if (!OAID) {
+		return true
+	}
+	// OAID 无效占位:只包含 0 和 -
+	return /^[0|-]+$/.test(OAID)
+}
+
+function getIosDeviceId(onComplete) {
+	// #ifdef APP-PLUS
+	const keychain = uni.requireNativePlugin('Univalsoft-DeviceId')
+	keychain.getDeviceIDCallback((ret) => {
+		const deviceId = ret ? ret : ''
+		if (deviceId) {
+			uni.setStorageSync('deviceId', deviceId)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+function androidRegister() {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.register(res => {
+		console.log('Ba-IdCode register', res)
+	})
+	// #endif
+}
+
+function androidGetIdCodes(onComplete) {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.getIdCodes(res => {
+		if (res.data && res.data.AndroidID && res.data.AndroidID !== '') {
+			uni.setStorageSync('deviceId', res.data.AndroidID)
+		} else if (res.data && res.data.GUID && res.data.GUID !== '') {
+			uni.setStorageSync('deviceId', res.data.GUID)
+		} else if (res.data && res.data.IMEI && res.data.IMEI !== '') {
+			uni.setStorageSync('deviceId', res.data.IMEI)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+function androidGetOAID(onComplete) {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.getOAID((res) => {
+		const OAID = (res.data && res.data.OAID) ? res.data.OAID : ''
+		if (isInvalidOaid(OAID)) {
+			androidGetIdCodes(onComplete)
+			return
+		}
+		if (OAID) {
+			uni.setStorageSync('deviceId', OAID)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+/**
+ * 登录成功后获取设备标识(仅 App 端)
+ */
+export function setupAppDeviceId(onComplete) {
+	// #ifdef APP-PLUS
+	const systemInfo = uni.getSystemInfoSync()
+	if (systemInfo.platform === 'ios') {
+		getIosDeviceId(onComplete)
+	} else if (systemInfo.platform === 'android') {
+		androidRegister()
+		androidGetOAID(onComplete)
+	} else if (onComplete) {
+		onComplete()
+	}
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+/**
+ * 登录成功后同步推送 clientId(仅 App 端)
+ */
+export function syncAppPushClientId(auto = 0) {
+	// #ifdef APP-PLUS
+	try {
+		const clientInfo = plus.push.getClientInfo()
+		const currentClientId = clientInfo && clientInfo.clientid ? clientInfo.clientid : ''
+		const deviceId = uni.getStorageSync('deviceId')
+		if (currentClientId) {
+			replaceClientId({ id: currentClientId, deviceId: deviceId, auto: auto })
+		}
+	} catch (e) {
+		console.log('syncAppPushClientId error', e)
+	}
+	// #endif
+}
+
+/**
+ * 用户登录成功后:获取设备 ID 并同步推送 clientId
+ * @param {{ auto?: number }} options auto=1 表示静默恢复登录,auto=0 表示用户主动登录
+ */
+export function afterAppLoginSuccess(options = {}) {
+	const auto = options.auto !== undefined ? options.auto : 0
+	setupAppDeviceId(() => {
+		syncAppPushClientId(auto)
+	})
+}

+ 3 - 1
ghsApp/src/utils/util.js

@@ -2,6 +2,7 @@ import CONSTANT from "@/constant";
 import { mobileReg } from "@/utils/tools/validate";
 import { getMiniAppUrl, isWxBrowser } from "@/utils/common";
 import permision from "@/utils/wa-permission_1.1/permission.js";
+import { afterAppLoginSuccess } from "@/utils/appDevice.js";
 // 是否为空
 const isEmpty = val => {
 	if (val instanceof Array) {
@@ -571,5 +572,6 @@ export default {
 	callUp,
 	hitRemind,
 	confirmModal,
-	isScanEnv
+	isScanEnv,
+	afterAppLoginSuccess
 };

+ 9 - 120
hdApp/src/admin/home/login.vue

@@ -98,7 +98,6 @@ import { mapActions } from "vuex";
 import { getShopInfo} from "@/utils/auth";
 import {appLogin} from '@/api/common'
 import { getDictionaries,postWxCode } from '@/api/mini'
-import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 import { ghsInfo } from "@/api/ghs/index";
 export default {
@@ -192,20 +191,6 @@ export default {
 				this.agree = 0
 			}else{
 				this.agree = 1
-
-				// #ifdef APP-PLUS
-				//获取设备ID,并保存到storage
-				console.log('GlobalMixins -- 获取设备ID');
-				const systemInfo = uni.getSystemInfoSync();
-				if (systemInfo.platform === 'ios') {
-					this.getIosDeviceId()
-				} else if (systemInfo.platform === 'android') {
-					this.androidRegister();
-					//this.androidGetIdCodes();
-					this.androidGetOAID()
-				}
-				console.log('GlobalMixins -- 获取设备ID 结束');
-				// #endif
 			}
 		},
 		// 检查并提示用户阅读协议
@@ -219,19 +204,6 @@ export default {
 					cancelText: '不同意',
 					success(res) {
 						if (res.confirm) {
-							//获取设备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()
-							}
-							console.log('GlobalMixins -- 获取设备ID 结束6666');
-
-							// 用户选择同意
 							that.agree = 1
 							that.$forceUpdate()
 							if(callback && typeof callback === 'function'){
@@ -318,6 +290,9 @@ export default {
 							uni.removeStorageSync('manualLogout')
 							getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 							that.setUserShopAll()
+							// #ifdef APP-PLUS
+							that.$util.afterAppLoginSuccess({ auto: 0 })
+							// #endif
 
 							if(this.option.fromType && this.option.fromType == 2){
 								//跳转失信人员页面
@@ -369,18 +344,6 @@ export default {
 								}
 							},
 							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()
-								}
-								
-								console.log(res)
 								let openid = res.authResult.openid
 								let access_token = res.authResult.access_token
 								phoneLogin({openid,access_token}).then(subRes=>{
@@ -409,6 +372,9 @@ export default {
 										uni.removeStorageSync('manualLogout')
 										getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 										that.setUserShopAll()
+										// #ifdef APP-PLUS
+										that.$util.afterAppLoginSuccess({ auto: 0 })
+										// #endif
 
 										//返回上一页带参数
 										let pages = getCurrentPages();
@@ -420,17 +386,6 @@ export default {
 											// H5 直接访问登录页,没有上一页,回首页
 											uni.reLaunch({ url: '/admin/home/workbench' })
 										}
-
-										// #ifdef APP-PLUS
-										//保存安卓的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})
-											console.log("mobileLogin - clientId ---------- ", currentClientId)
-										}
-										// #endif
 									}
 								})
 							},
@@ -510,6 +465,9 @@ export default {
 
 						getShopInfo(true).then(res => { uni.setNavigationBarTitle({ title: res.name }) })
 						that.setUserShopAll()
+						// #ifdef APP-PLUS
+						that.$util.afterAppLoginSuccess({ auto: 0 })
+						// #endif
 
 						//返回上一页带参数
 						let pages = getCurrentPages();
@@ -521,81 +479,12 @@ export default {
 							// H5 直接访问登录页,没有上一页,回首页
 							uni.reLaunch({ url: '/admin/home/workbench' })
 						}
-
-						// #ifdef APP-PLUS
-						//保存安卓的clientId
-						const clientInfo = plus.push.getClientInfo()
-						let currentClientId = !that.$util.isEmpty(clientInfo.clientid) ? clientInfo.clientid : ''
-						const deviceId = uni.getStorageSync('deviceId')
-						console.log("loginFun - deviceId ---------- ", deviceId)
-						if(currentClientId != ''){
-							replaceClientId({id:currentClientId, deviceId:deviceId, auto:0})
-							console.log("loginFun - clientId ---------- ", currentClientId)
-						}
-						// #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>

+ 0 - 74
hdApp/src/mixins/globalMixins.js

@@ -3,7 +3,6 @@ import { pageTo } from '@/utils/util.js'
 import { getShopInfo, wxLoginFn } from '@/utils/auth'
 import { getDictionaries } from '@/api/mini'
 import { hasTokenAutoLogin } from '@/api/common'
-import { replaceClientId } from '@/api/admin'
 import constant from '@/constant'
 import { iconSrc } from '@/utils/iconSrc'
 export default {
@@ -90,17 +89,6 @@ export default {
 				hasTokenAutoLogin().then(subRes=>{
 					//有几个地方涉及登陆,需要统一方法,请搜索关键词 uni_login
 					if(subRes.code == 1){
-						//获取设备ID,并保存到storage
-						console.log('GlobalMixins -- 获取设备ID');
-						const systemInfo = uni.getSystemInfoSync();
-						if (systemInfo.platform === 'ios') {
-							this.getIosDeviceId()
-						} else if (systemInfo.platform === 'android') {
-							this.androidRegister();
-							//this.androidGetIdCodes();
-							this.androidGetOAID()
-						}
-						
 						uni.setStorageSync('shopId', subRes.data.admin.currentShopId)
 						getDictionaries({ token: subRes.data.token }).then(res => {
 							if (that.$util.isEmpty(res)) {
@@ -112,14 +100,6 @@ export default {
 						that.$store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
 						that.setUserShopAll()
 						that.init()
-
-						//更新 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: 1})
-						}
 					}
 				})
 			}
@@ -131,59 +111,5 @@ export default {
 	methods: {
 		...mapActions(['setUserShopAll']),
 		iconSrc,
-
-		// #ifdef APP-PLUS
-		getIosDeviceId() {
-			const keychain = uni.requireNativePlugin('Univalsoft-DeviceId'); 
-			keychain.getDeviceIDCallback((ret)=>{
-				let deviceId = ret ? ret : '';
-				if(deviceId != ''){
-					uni.setStorageSync('deviceId', deviceId)
-				}
-			})
-		},
-		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
 	}
 }

+ 3 - 0
hdApp/src/pagesClient/official/apply.vue

@@ -653,6 +653,9 @@ export default {
             uni.setNavigationBarTitle({ title: res.name })
           })
           that.setUserShopAll()
+          // #ifdef APP-PLUS
+          that.$util.afterAppLoginSuccess({ auto: 0 })
+          // #endif
 
         }
 

+ 136 - 0
hdApp/src/utils/appDevice.js

@@ -0,0 +1,136 @@
+import { replaceClientId } from '@/api/admin'
+
+function isInvalidOaid(OAID) {
+	if (!OAID) {
+		return true
+	}
+	// OAID 无效占位:只包含 0 和 -
+	return /^[0|-]+$/.test(OAID)
+}
+
+function getIosDeviceId(onComplete) {
+	// #ifdef APP-PLUS
+	const keychain = uni.requireNativePlugin('Univalsoft-DeviceId')
+	keychain.getDeviceIDCallback((ret) => {
+		const deviceId = ret ? ret : ''
+		if (deviceId) {
+			uni.setStorageSync('deviceId', deviceId)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+function androidRegister() {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.register(res => {
+		console.log('Ba-IdCode register', res)
+	})
+	// #endif
+}
+
+function androidGetIdCodes(onComplete) {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.getIdCodes(res => {
+		if (res.data && res.data.AndroidID && res.data.AndroidID !== '') {
+			uni.setStorageSync('deviceId', res.data.AndroidID)
+		} else if (res.data && res.data.GUID && res.data.GUID !== '') {
+			uni.setStorageSync('deviceId', res.data.GUID)
+		} else if (res.data && res.data.IMEI && res.data.IMEI !== '') {
+			uni.setStorageSync('deviceId', res.data.IMEI)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+function androidGetOAID(onComplete) {
+	// #ifdef APP-PLUS
+	const idCode = uni.requireNativePlugin('Ba-IdCode')
+	idCode.getOAID((res) => {
+		const OAID = (res.data && res.data.OAID) ? res.data.OAID : ''
+		if (isInvalidOaid(OAID)) {
+			androidGetIdCodes(onComplete)
+			return
+		}
+		if (OAID) {
+			uni.setStorageSync('deviceId', OAID)
+		}
+		if (onComplete) {
+			onComplete()
+		}
+	})
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+/**
+ * 登录成功后获取设备标识(仅 App 端)
+ */
+export function setupAppDeviceId(onComplete) {
+	// #ifdef APP-PLUS
+	const systemInfo = uni.getSystemInfoSync()
+	if (systemInfo.platform === 'ios') {
+		getIosDeviceId(onComplete)
+	} else if (systemInfo.platform === 'android') {
+		androidRegister()
+		androidGetOAID(onComplete)
+	} else if (onComplete) {
+		onComplete()
+	}
+	// #endif
+	// #ifndef APP-PLUS
+	if (onComplete) {
+		onComplete()
+	}
+	// #endif
+}
+
+/**
+ * 登录成功后同步推送 clientId(仅 App 端)
+ */
+export function syncAppPushClientId(auto = 0) {
+	// #ifdef APP-PLUS
+	try {
+		const clientInfo = plus.push.getClientInfo()
+		const currentClientId = clientInfo && clientInfo.clientid ? clientInfo.clientid : ''
+		const deviceId = uni.getStorageSync('deviceId')
+		if (currentClientId) {
+			replaceClientId({ id: currentClientId, deviceId: deviceId, auto: auto })
+		}
+	} catch (e) {
+		console.log('syncAppPushClientId error', e)
+	}
+	// #endif
+}
+
+/**
+ * 用户登录成功后:获取设备 ID 并同步推送 clientId
+ * @param {{ auto?: number }} options auto=1 表示静默恢复登录,auto=0 表示用户主动登录
+ */
+export function afterAppLoginSuccess(options = {}) {
+	const auto = options.auto !== undefined ? options.auto : 0
+	setupAppDeviceId(() => {
+		syncAppPushClientId(auto)
+	})
+}

+ 3 - 1
hdApp/src/utils/util.js

@@ -2,6 +2,7 @@ import CONSTANT from "@/constant";
 import { mobileReg } from "@/utils/tools/validate";
 import { getMiniAppUrl, isWxBrowser } from "@/utils/common";
 import permision from "@/utils/wa-permission_1.1/permission.js";
+import { afterAppLoginSuccess } from "@/utils/appDevice.js";
 // 是否为空
 const isEmpty = val => {
 	if (val instanceof Array) {
@@ -573,5 +574,6 @@ export default {
 	isScanEnv,
 	hitRemind,
 	noStockRemind,
-	callUp
+	callUp,
+	afterAppLoginSuccess
 };

+ 1 - 1
开发http/ghsApp/src/manifest.json

@@ -3,7 +3,7 @@
     "appid" : "__UNI__BD781B0",
     "description" : "鲜花批发销售管理系统",
     "versionName" : "1.2.96",
-    "versionCode" : 1296,
+    "versionCode" : 1297,
     "transformPx" : true,
     /* 5+App特有相关 */
     "app-plus" : {

+ 2 - 2
开发https/ghsApp/src/manifest.json

@@ -2,8 +2,8 @@
     "name" : "销花宝",
     "appid" : "__UNI__BD781B0",
     "description" : "鲜花批发销售管理系统",
-    "versionName" : "1.2.96",
-    "versionCode" : 1296,
+    "versionName" : "1.2.97",
+    "versionCode" : 1297,
     "transformPx" : true,
     /* 5+App特有相关 */
     "app-plus" : {

+ 2 - 2
线上/ghsApp/src/manifest.json

@@ -2,8 +2,8 @@
     "name" : "销花宝",
     "appid" : "__UNI__BD781B0",
     "description" : "鲜花批发销售管理系统",
-    "versionName" : "1.2.96",
-    "versionCode" : 1296,
+    "versionName" : "1.2.97",
+    "versionCode" : 1297,
     "transformPx" : true,
     /* 5+App特有相关 */
     "app-plus" : {