diff --git a/src/locales/en-US.js b/src/locales/en-US.js
index 69f6f0d..ac029df 100644
--- a/src/locales/en-US.js
+++ b/src/locales/en-US.js
@@ -587,6 +587,11 @@ export default {
checkUpdate: 'Check Updates',
cleanCache: 'Clear Cache',
logout: 'Log Out',
+ serverAddress: 'Server Address',
+ serverAddressHint: 'Enter the backend API address for the current account',
+ serverAddressPlaceholder: 'Enter backend address',
+ serverAddressRequired: 'Please enter the backend address',
+ serverAddressSaved: 'Server address saved. Please log in again',
mobile: 'Mobile',
scanner: 'Scanner',
zhCN: 'Chinese',
diff --git a/src/locales/zh-CN.js b/src/locales/zh-CN.js
index fe3943d..6156eb4 100644
--- a/src/locales/zh-CN.js
+++ b/src/locales/zh-CN.js
@@ -587,6 +587,11 @@ export default {
checkUpdate: '检查更新',
cleanCache: '清理缓存',
logout: '退出登录',
+ serverAddress: '服务器地址',
+ serverAddressHint: '请输入当前账号对应的后端接口地址',
+ serverAddressPlaceholder: '请输入后端访问地址',
+ serverAddressRequired: '请输入后端访问地址',
+ serverAddressSaved: '服务器地址已保存,请重新登录',
mobile: '手机',
scanner: '扫码器',
zhCN: '中文',
diff --git a/src/pages_mine/pages/setting/index.vue b/src/pages_mine/pages/setting/index.vue
index 5d8e23b..e749f95 100644
--- a/src/pages_mine/pages/setting/index.vue
+++ b/src/pages_mine/pages/setting/index.vue
@@ -9,6 +9,13 @@
{{ translateWithParams('setting.currentLanguage', { language: currentLanguageLabel }) }}
+
+
+ {{ serverAddress || t('setting.serverAddressPlaceholder') }}
+
@@ -39,6 +60,8 @@ import { useI18n } from 'vue-i18n'
import useUserStore from '@/store/modules/user'
import { getCurrentLocale, setLocale, translateWithParams } from '@/locales'
import NavBar from '@/components/common/NavBar.vue'
+import { removeToken } from '@/utils/auth'
+import { SERVER_BASE_URL_STORAGE_KEY, getBaseUrl } from '@/utils/request'
const userStore = useUserStore()
const { t } = useI18n()
@@ -46,7 +69,9 @@ const { t } = useI18n()
const pageTitle = computed(() => t('nav.setting'))
const windowHeight = ref(uni.getSystemInfoSync().windowHeight);
const popup = ref(null);
+const serverPopup = ref(null)
const currentLocale = ref(getCurrentLocale())
+const serverAddress = ref(getBaseUrl())
const currentLanguageLabel = computed(() => currentLocale.value === 'en-US' ? t('setting.enUS') : t('setting.zhCN'))
function handleToPwd() {
@@ -88,6 +113,36 @@ function handleLanguageChange() {
})
}
+function openServerDialog() {
+ serverPopup.value?.open()
+}
+
+function handleServerAddressSave(value) {
+ const nextAddress = value.trim()
+ if (!nextAddress) {
+ uni.showToast({
+ title: t('setting.serverAddressRequired'),
+ icon: 'none',
+ duration: 1500
+ })
+ return false
+ }
+ uni.setStorageSync(SERVER_BASE_URL_STORAGE_KEY, nextAddress)
+ serverAddress.value = nextAddress
+ uni.showToast({
+ title: t('setting.serverAddressSaved'),
+ icon: 'none',
+ duration: 1200
+ })
+ removeToken()
+ setTimeout(() => {
+ uni.reLaunch({
+ url: '/pages/login'
+ })
+ }, 1200)
+ return true
+}
+
function handleLogout() {
popup.value.open();
};
@@ -120,4 +175,10 @@ function dialogClose() {
color: #303133;
font-size: 32rpx;
}
+
+.server-address-text {
+ max-width: 400rpx;
+ text-align: right;
+ word-break: break-all;
+}
diff --git a/src/utils/request.ts b/src/utils/request.ts
index dc65cfe..2e621db 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -6,7 +6,12 @@ import { RequestConfig, ResponseData } from '@/types/request'
import modal from '@/plugins/modal'
let timeout = 300000
-const baseUrl = config.baseUrl
+
+export const SERVER_BASE_URL_STORAGE_KEY = 'serverBaseUrl'
+
+export function getBaseUrl() {
+ return uni.getStorageSync(SERVER_BASE_URL_STORAGE_KEY) || config.baseUrl
+}
const request = (config: RequestConfig): Promise> => {
// 是否需要设置 token
@@ -30,7 +35,7 @@ const request = (config: RequestConfig): Promise> => {
uni.request({
method: config.method || 'GET',
timeout: config.timeout || timeout,
- url: (config.baseUrl || baseUrl) + config.url,
+ url: (config.baseUrl || getBaseUrl()) + config.url,
data: config.data,
header: config.header,
dataType: 'json'
diff --git a/src/utils/upload.ts b/src/utils/upload.ts
index 7e3c2a6..6a1e8e8 100644
--- a/src/utils/upload.ts
+++ b/src/utils/upload.ts
@@ -4,9 +4,9 @@ import errorCode from '@/utils/errorCode'
import { toast, showConfirm, tansParams } from '@/utils/common'
import { ResponseData, RequestUploadConfig } from '@/types/request'
import modal from '@/plugins/modal'
+import { getBaseUrl } from '@/utils/request'
let timeout = 10000
-const baseUrl = config.baseUrl
const upload = (config: RequestUploadConfig): Promise> => {
// 是否需要设置 token
@@ -28,7 +28,7 @@ const upload = (config: RequestUploadConfig): Promise> => {
}
uni.uploadFile({
timeout: config.timeout || timeout,
- url: baseUrl + config.url,
+ url: getBaseUrl() + config.url,
filePath: config.filePath,
name: config.name || 'file',
header: config.header,