feat: 开放服务器切换并修复扫码方式列表
This commit is contained in:
parent
3f2481d1eb
commit
fa0ff1614b
@ -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 },
|
||||
];
|
||||
},
|
||||
|
||||
@ -8,22 +8,20 @@
|
||||
<!-- <u-tabs :list="list" :is-scroll="false" :current="current" @change="onClickItem"></u-tabs> -->
|
||||
<!-- <view v-if="current === 0"> -->
|
||||
<view class="list">
|
||||
<template v-if="isDevelopment">
|
||||
<view class="list-call">
|
||||
<view class="iconfont icon-link" style="font-size: 22px;color:#5473e8;"></view>
|
||||
<view style="width: 100%;">
|
||||
<view class="server-selector" @click="showServerPicker">
|
||||
<text>{{ getApiUrlLabel() }}</text>
|
||||
<view class="iconfont icon-arrow-down" style="font-size: 16px;"></view>
|
||||
</view>
|
||||
<view class="list-call">
|
||||
<view class="iconfont icon-link" style="font-size: 22px;color:#5473e8;"></view>
|
||||
<view style="width: 100%;">
|
||||
<view class="server-selector" @click="showServerPicker">
|
||||
<text>{{ getApiUrlLabel() }}</text>
|
||||
<view class="iconfont icon-arrow-down" style="font-size: 16px;"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-call" v-if="selectedApiUrl === 'custom'">
|
||||
<!-- 当选择自定义时显示输入框 -->
|
||||
<input class="u-input" type="text" v-model="customApiUrl" maxlength="100" placeholder="请输入服务器地址"
|
||||
@blur="handleBlurInputUrl" />
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
<view class="list-call" v-if="selectedApiUrl === 'custom'">
|
||||
<!-- 当选择自定义时显示输入框 -->
|
||||
<input class="u-input" type="text" v-model="customApiUrl" maxlength="100" placeholder="请输入服务器地址"
|
||||
@blur="handleBlurInputUrl" />
|
||||
</view>
|
||||
<view class="list-call">
|
||||
<view class="iconfont icon-avatar" style="font-size: 22px;color:#5473e8;"></view>
|
||||
<input class="u-input" type="text" v-model="login.username" maxlength="32"
|
||||
@ -136,10 +134,12 @@ export default {
|
||||
password: ""
|
||||
},
|
||||
showApiUrlPicker: false,
|
||||
// 根据环境设置默认URL和选项
|
||||
selectedApiUrl: config.isDevelopment ? config.devApiUrlOptions[0].value : config.productionApiUrl,
|
||||
// 暂时在打包后也展示服务器选项;生产包默认正式环境
|
||||
selectedApiUrl: config.isDevelopment
|
||||
? config.devApiUrlOptions[0].value
|
||||
: ((config.devApiUrlOptions.find(item => 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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user