diff --git a/src/common/scanMixin.js b/src/common/scanMixin.js index f104a7e..d0bb7d4 100644 --- a/src/common/scanMixin.js +++ b/src/common/scanMixin.js @@ -48,6 +48,13 @@ export default { dataKey: 'data', 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 5370bf7..a8515da 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/pda/v1', - apiUrlList: config.isDevelopment ? config.devApiUrlOptions : [], + apiUrlList: config.devApiUrlOptions, phoneNo: '', //username: '', //password: '', @@ -169,16 +169,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('请输入账号'); @@ -338,14 +326,14 @@ export default { console.log('login res', res) var aLoginUserData = res; - // 只在开发环境保存 apiurl 到本地存储 - if (config.isDevelopment) { - uni.setStorage({ - key: 'ApiUrl', - data: currentApiUrl - }); - util.updateApiUrl(currentApiUrl); - } + //console.log('--aLoginUserData->>' + JSON.stringify(aLoginUserData)); + uni.setStorage({ + key: 'ApiUrl', + data: currentApiUrl + }); + util.updateApiUrl(currentApiUrl); + // 保存 token 到本地存储 + uni.setStorageSync('RemoteTokenData', aLoginUserData); applyLoginData(aLoginUserData); @@ -445,18 +433,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 bf50be4..12e3e51 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -26,22 +26,19 @@ function normalizeApiUrl(url) { // 初始化API URL function initApiUrl() { - if (config.isDevelopment) { - // 开发环境:从存储读取,如果没有则使用测试环境 - try { - const savedApiUrl = uni.getStorageSync('ApiUrl'); - const url = normalizeApiUrl(savedApiUrl || config.devApiUrlOptions[0].value); - if (savedApiUrl && url !== savedApiUrl) { - uni.setStorageSync('ApiUrl', url); - } - return url; - } catch (e) { - console.log('读取存储的 apiurl 失败', e); - return config.devApiUrlOptions[0].value; + const fallbackUrl = config.isDevelopment + ? config.devApiUrlOptions[0].value + : ((config.devApiUrlOptions.find(item => item.label === '正式环境') || {}).value || config.productionApiUrl); + try { + const savedApiUrl = uni.getStorageSync('ApiUrl'); + const url = normalizeApiUrl(savedApiUrl || fallbackUrl); + if (savedApiUrl && url !== savedApiUrl) { + uni.setStorageSync('ApiUrl', url); } - } else { - // 生产环境:使用固定的生产URL - return normalizeApiUrl(config.productionApiUrl); + return url; + } catch (e) { + console.log('读取存储的 apiurl 失败', e); + return normalizeApiUrl(fallbackUrl); } } @@ -114,14 +111,8 @@ const store = new Vuex.Store({ state.vuex_notificationAudio = audio; }, SET_API_URL(state, url) { - // 生产环境不允许修改URL - if (!config.isDevelopment) { - console.warn('生产环境不允许修改API URL'); - return; - } const nextUrl = normalizeApiUrl(url); state.apiurl = nextUrl - // 同时保存到本地存储 uni.setStorageSync('ApiUrl', nextUrl) } },