From bcafc995f2e92f70db72e3a59cc727ef80686977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=9A=E7=90=AA?= Date: Fri, 15 Jul 2022 11:36:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9=E6=80=A7=E6=8F=90?= =?UTF-8?q?=E5=8D=87=EF=BC=8C=E5=AE=8C=E5=85=A8=E5=85=BC=E5=AE=B9=E6=97=A7?= =?UTF-8?q?=E7=89=88=E6=9C=ACuni-id=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 98208c4..77fcd5a 100644 --- a/src/index.js +++ b/src/index.js @@ -93,6 +93,17 @@ class UniID { if (this._clientInfo.platform === 'h5') { this._clientInfo.platform = 'web' } + let fallbackPlatform + switch (this._clientInfo.platform) { + case 'web': + fallbackPlatform = 'h5' + break + case 'app': + fallbackPlatform = 'app-plus' + break + default: + break + } const defaultConfig = { tokenExpiresIn: 7200, tokenExpiresThreshold: 1200, @@ -100,7 +111,12 @@ class UniID { passwordErrorRetryTime: 3600 } const argsRequired = ['tokenSecret', 'tokenExpiresIn'] - const config = Object.assign(defaultConfig, appConfig, appConfig[this._clientInfo.platform]) + const configList = [defaultConfig, appConfig] + if (fallbackPlatform && appConfig[fallbackPlatform]) { + configList.push(appConfig[fallbackPlatform]) + } + configList.push(appConfig[this._clientInfo.platform]) + const config = Object.assign(...configList) argsRequired.forEach((item) => { if (!config || !config[item]) { throw new Error(`Config parameter missing, ${item} is required`) -- GitLab