diff --git a/src/common/scanMixin.js b/src/common/scanMixin.js index 7cd1918..5afa151 100644 --- a/src/common/scanMixin.js +++ b/src/common/scanMixin.js @@ -55,6 +55,13 @@ export default { dataKey: 'barcode_string', needSetup: false }, + { + brand: 'nlscan', + name: '新大陆', + action: 'nlscan.action.SCANNER_RESULT', + dataKey: 'SCAN_BARCODE1', + needSetup: false + }, { ...PHONE_SCAN_CONFIG }, ]; }, diff --git a/src/pages/sys/login/index.vue b/src/pages/sys/login/index.vue index 6607bc2..0de7f03 100644 --- a/src/pages/sys/login/index.vue +++ b/src/pages/sys/login/index.vue @@ -8,22 +8,20 @@ - + + + + + item.label === '正式环境') || {}).value || config.productionApiUrl), customApiUrl: 'http://192.168.1.66:50002/hcscm_weave/pda/v1', - apiUrlList: config.isDevelopment ? config.devApiUrlOptions : [], + apiUrlList: config.devApiUrlOptions, phoneNo: '', //username: '', //password: '', @@ -168,16 +168,13 @@ export default { }, onShow() { - // 只在开发环境读取存储的URL - if (config.isDevelopment) { - uni.getStorage({ - key: 'ApiUrl', - success: (e) => { - util.updateApiUrl(e.data); - this.selectedApiUrl = e.data; - } - }); - } + uni.getStorage({ + key: 'ApiUrl', + success: (e) => { + util.updateApiUrl(e.data); + this.selectedApiUrl = e.data; + } + }); uni.getStorage({ key: 'UserInfo', @@ -300,21 +297,12 @@ export default { title: '登录中...' }); - let currentApiUrl; - - if (config.isDevelopment) { - // 开发环境:使用选择的URL - currentApiUrl = this.selectedApiUrl === 'custom' ? this.customApiUrl : this.selectedApiUrl; - if (!currentApiUrl || currentApiUrl.length === 0) { - this.$u.toast('请输入服务器地址'); - return; - } - // 更新store中的URL - this.$store.dispatch('updateApiUrl', currentApiUrl); - } else { - // 生产环境:使用固定的生产URL - currentApiUrl = config.productionApiUrl; + const currentApiUrl = this.selectedApiUrl === 'custom' ? this.customApiUrl : this.selectedApiUrl; + if (!currentApiUrl || currentApiUrl.length === 0) { + this.$u.toast('请输入服务器地址'); + return; } + this.$store.dispatch('updateApiUrl', currentApiUrl); if (this.login.username.length == 0) { this.$u.toast('请输入账号'); @@ -339,14 +327,11 @@ export default { var aLoginUserData = res; //console.log('--aLoginUserData->>' + JSON.stringify(aLoginUserData)); - // 只在开发环境保存 apiurl 到本地存储 - if (config.isDevelopment) { - uni.setStorage({ - key: 'ApiUrl', - data: currentApiUrl - }); - util.updateApiUrl(currentApiUrl); - } + uni.setStorage({ + key: 'ApiUrl', + data: currentApiUrl + }); + util.updateApiUrl(currentApiUrl); // 保存 token 到本地存储 uni.setStorageSync('RemoteTokenData', aLoginUserData); @@ -456,18 +441,14 @@ export default { }, handleBlurInputUrl(e) { - // 只在开发环境处理自定义URL - if (config.isDevelopment) { - const url = e.detail.value.trim(); - if (url) { - this.customApiUrl = url; - // 保存到本地存储 - uni.setStorage({ - key: 'ApiUrl', - data: url - }); - util.updateApiUrl(url); - } + const url = e.detail.value.trim(); + if (url) { + this.customApiUrl = url; + uni.setStorage({ + key: 'ApiUrl', + data: url + }); + util.updateApiUrl(url); } }, } diff --git a/src/pages/sys/user/scan-settings.vue b/src/pages/sys/user/scan-settings.vue index 9e7c920..7f38437 100644 --- a/src/pages/sys/user/scan-settings.vue +++ b/src/pages/sys/user/scan-settings.vue @@ -83,7 +83,7 @@ export default { const res = await this.$u.api.dictionary.getDetailEnumList({ dictionary_id: DICTIONARY_TYPE_SCANNER, }); - const list = Array.isArray(res) ? res : []; + const list = Array.isArray(res) ? res : (Array.isArray(res && res.list) ? res.list : []); const builtinConfigs = this.getScannerConfigs(); if (list.length) { this.configList = list @@ -98,6 +98,7 @@ export default { this.useFallbackConfigList(); } this.ensurePhoneScanOption(); + this.ensureNlscanOption(); this.initFormFromSaved(); }, useFallbackConfigList() { @@ -110,6 +111,24 @@ export default { this.configList.push(phoneConfig); } }, + ensureNlscanOption() { + const nlscanConfig = this.getScannerConfigs().find((item) => item.brand === 'nlscan'); + if (!nlscanConfig) { + return; + } + const exists = this.configList.some((item) => { + return item.brand === nlscanConfig.brand || item.action === nlscanConfig.action; + }); + if (exists) { + return; + } + const phoneIndex = this.configList.findIndex((item) => item.brand === PHONE_SCAN_BRAND); + if (phoneIndex >= 0) { + this.configList.splice(phoneIndex, 0, nlscanConfig); + return; + } + this.configList.push(nlscanConfig); + }, initFormFromSaved() { const savedConfig = getScanConfig(this.getScannerConfigs()); if (savedConfig) { diff --git a/src/store/index.js b/src/store/index.js index b52c4d9..59bfb1e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -21,18 +21,15 @@ try{ // 初始化API URL function initApiUrl() { - if (config.isDevelopment) { - // 开发环境:从存储读取,如果没有则使用测试环境 - try { - const savedApiUrl = uni.getStorageSync('ApiUrl'); - return savedApiUrl || config.devApiUrlOptions[0].value; - } catch (e) { - console.log('读取存储的 apiurl 失败', e); - return config.devApiUrlOptions[0].value; - } - } else { - // 生产环境:使用固定的生产URL - return config.productionApiUrl; + const fallbackUrl = config.isDevelopment + ? config.devApiUrlOptions[0].value + : ((config.devApiUrlOptions.find(item => item.label === '正式环境') || {}).value || config.productionApiUrl); + try { + const savedApiUrl = uni.getStorageSync('ApiUrl'); + return savedApiUrl || fallbackUrl; + } catch (e) { + console.log('读取存储的 apiurl 失败', e); + return fallbackUrl; } } @@ -105,13 +102,7 @@ const store = new Vuex.Store({ state.vuex_notificationAudio = audio; }, SET_API_URL(state, url) { - // 生产环境不允许修改URL - if (!config.isDevelopment) { - console.warn('生产环境不允许修改API URL'); - return; - } state.apiurl = url - // 同时保存到本地存储 uni.setStorageSync('ApiUrl', url) } },