feat: 开放服务器切换并修复扫码方式列表

This commit is contained in:
2026-10-06 17:27:48 +08:00
parent 55f13bb47b
commit 8ec38126e6
4 changed files with 84 additions and 83 deletions
+45 -61
View File
@@ -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"
@@ -137,10 +135,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/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);
}
},
}
+20 -1
View File
@@ -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) {