feat:我的-后端地址配置

master
黄伟杰 2 weeks ago
parent 85a54b8a3d
commit 3bd415f713

@ -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',

@ -587,6 +587,11 @@ export default {
checkUpdate: '检查更新',
cleanCache: '清理缓存',
logout: '退出登录',
serverAddress: '服务器地址',
serverAddressHint: '请输入当前账号对应的后端接口地址',
serverAddressPlaceholder: '请输入后端访问地址',
serverAddressRequired: '请输入后端访问地址',
serverAddressSaved: '服务器地址已保存,请重新登录',
mobile: '手机',
scanner: '扫码器',
zhCN: '中文',

@ -9,6 +9,13 @@
</view>
<view class="text-grey">{{ translateWithParams('setting.currentLanguage', { language: currentLanguageLabel }) }}</view>
</view>
<view class="list-cell list-cell-arrow" @click="openServerDialog">
<view class="menu-item-box">
<view class="iconfont icon-global menu-icon"></view>
<view>{{ t('setting.serverAddress') }}</view>
</view>
<view class="text-grey server-address-text">{{ serverAddress || t('setting.serverAddressPlaceholder') }}</view>
</view>
<view class="list-cell list-cell-arrow" @click="handleToPwd">
<view class="menu-item-box">
<view class="iconfont icon-password menu-icon"></view>
@ -30,6 +37,20 @@
@confirm="dialogConfirm" @close="dialogClose">
</uni-popup-dialog>
</uni-popup>
<uni-popup ref="serverPopup" type="dialog">
<uni-popup-dialog
mode="input"
type="info"
:title="t('setting.serverAddress')"
:content="t('setting.serverAddressHint')"
:placeholder="t('setting.serverAddressPlaceholder')"
:value="serverAddress"
:confirmText="t('functionCommon.save')"
:cancelText="t('common.close')"
@confirm="handleServerAddressSave"
>
</uni-popup-dialog>
</uni-popup>
</view>
</template>
@ -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;
}
</style>

@ -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 = <T>(config: RequestConfig): Promise<ResponseData<T>> => {
// 是否需要设置 token
@ -30,7 +35,7 @@ const request = <T>(config: RequestConfig): Promise<ResponseData<T>> => {
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'

@ -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 = <T>(config: RequestUploadConfig): Promise<ResponseData<T>> => {
// 是否需要设置 token
@ -28,7 +28,7 @@ const upload = <T>(config: RequestUploadConfig): Promise<ResponseData<T>> => {
}
uni.uploadFile({
timeout: config.timeout || timeout,
url: baseUrl + config.url,
url: getBaseUrl() + config.url,
filePath: config.filePath,
name: config.name || 'file',
header: config.header,

Loading…
Cancel
Save