fix: components i18n

pull/2/head
xingyu 2022-07-21 15:02:15 +08:00
parent cb091d1853
commit 22429140bd
2 changed files with 22 additions and 23 deletions

View File

@ -1,10 +1,8 @@
// import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import type { Slots } from 'vue' import type { Slots } from 'vue'
import { getSlot } from '@/utils/tsxHelper' import { getSlot } from '@/utils/tsxHelper'
import { PlaceholderMoel } from './types' import { PlaceholderMoel } from './types'
// const { t } = useI18n()
/** /**
* *
* @param schema * @param schema
@ -12,12 +10,12 @@ import { PlaceholderMoel } from './types'
* @description placeholder * @description placeholder
*/ */
export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => { export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
const { t } = useI18n()
const textMap = ['Input', 'Autocomplete', 'InputNumber', 'InputPassword'] const textMap = ['Input', 'Autocomplete', 'InputNumber', 'InputPassword']
const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect'] const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
if (textMap.includes(schema?.component as string)) { if (textMap.includes(schema?.component as string)) {
return { return {
// placeholder: t('common.inputText') placeholder: t('common.inputText')
placeholder: '请输入'
} }
} }
if (selectMap.includes(schema?.component as string)) { if (selectMap.includes(schema?.component as string)) {
@ -29,16 +27,13 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
) )
) { ) {
return { return {
// startPlaceholder: t('common.startTimeText'), startPlaceholder: t('common.startTimeText'),
// endPlaceholder: t('common.endTimeText'), endPlaceholder: t('common.endTimeText'),
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
rangeSeparator: '-' rangeSeparator: '-'
} }
} else { } else {
return { return {
// placeholder: t('common.selectText') placeholder: t('common.selectText')
placeholder: '请选择'
} }
} }
} }

View File

@ -5,7 +5,6 @@ import { config } from '@/config/axios/config'
import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth' import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth'
import errorCode from './errorCode' import errorCode from './errorCode'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
const { t } = useI18n()
const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
const BASE_URL = import.meta.env.VITE_BASE_URL const BASE_URL = import.meta.env.VITE_BASE_URL
@ -46,25 +45,27 @@ service.interceptors.request.use(
const tenantId = getTenantId() const tenantId = getTenantId()
if (tenantId) (config as Recordable).headers.common['tenant-id'] = tenantId if (tenantId) (config as Recordable).headers.common['tenant-id'] = tenantId
} }
const params = config.params || {}
const data = config.data || false
if ( if (
config.method === 'post' && config.method?.toUpperCase() === 'POST' &&
config!.headers!['Content-Type'] === 'application/x-www-form-urlencoded' config!.headers!['Content-Type'] === 'application/x-www-form-urlencoded'
) { ) {
config.data = qs.stringify(config.data) config.data = qs.stringify(data)
} }
// get参数编码 // get参数编码
if (config.method === 'get' && config.params) { if (config.method?.toUpperCase() === 'GET' && config.params) {
let url = config.url as string let url = config.url as string
url += '?'
const keys = Object.keys(config.params)
for (const key of keys) {
if (config.params[key] !== void 0 && config.params[key] !== null) {
url += `${key}=${encodeURIComponent(config.params[key])}&`
}
}
// 给 get 请求加上时间戳参数,避免从缓存中拿数据 // 给 get 请求加上时间戳参数,避免从缓存中拿数据
// const now = new Date().getTime() // const now = new Date().getTime()
// url = url.substring(0, url.length - 1) + `?_t=${now}` // params = params.substring(0, url.length - 1) + `?_t=${now}`
url += '?'
const keys = Object.keys(params)
for (const key of keys) {
if (params[key] !== void 0 && params[key] !== null) {
url += `${key}=${encodeURIComponent(params[key])}&`
}
}
config.params = {} config.params = {}
config.url = url config.url = url
} }
@ -85,6 +86,7 @@ service.interceptors.response.use(
// 返回“[HTTP]请求没有返回值”; // 返回“[HTTP]请求没有返回值”;
throw new Error() throw new Error()
} }
const { t } = useI18n()
// 未设置状态码则默认成功状态 // 未设置状态码则默认成功状态
const code = data.code || result_code const code = data.code || result_code
// 获取错误信息 // 获取错误信息
@ -134,6 +136,7 @@ service.interceptors.response.use(
(error: AxiosError) => { (error: AxiosError) => {
console.log('err' + error) // for debug console.log('err' + error) // for debug
let { message } = error let { message } = error
const { t } = useI18n()
if (message === 'Network Error') { if (message === 'Network Error') {
message = t('sys.api.errorMessage') message = t('sys.api.errorMessage')
} else if (message.includes('timeout')) { } else if (message.includes('timeout')) {
@ -146,6 +149,7 @@ service.interceptors.response.use(
} }
) )
function handleAuthorized() { function handleAuthorized() {
const { t } = useI18n()
if (!isRelogin.show) { if (!isRelogin.show) {
isRelogin.show = true isRelogin.show = true
ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), { ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), {