Commit 22429140bdb72f522f85cdc17672fab472376392

Authored by xingyu
1 parent cb091d18

fix: components i18n

yudao-ui-admin-vue3/src/components/Form/src/helper.ts
1 -// import { useI18n } from '@/hooks/web/useI18n' 1 +import { useI18n } from '@/hooks/web/useI18n'
2 import type { Slots } from 'vue' 2 import type { Slots } from 'vue'
3 import { getSlot } from '@/utils/tsxHelper' 3 import { getSlot } from '@/utils/tsxHelper'
4 import { PlaceholderMoel } from './types' 4 import { PlaceholderMoel } from './types'
5 5
6 -// const { t } = useI18n()  
7 -  
8 /** 6 /**
9 * 7 *
10 * @param schema 对应组件数据 8 * @param schema 对应组件数据
@@ -12,12 +10,12 @@ import { PlaceholderMoel } from './types' @@ -12,12 +10,12 @@ import { PlaceholderMoel } from './types'
12 * @description 用于自动设置placeholder 10 * @description 用于自动设置placeholder
13 */ 11 */
14 export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => { 12 export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
  13 + const { t } = useI18n()
15 const textMap = ['Input', 'Autocomplete', 'InputNumber', 'InputPassword'] 14 const textMap = ['Input', 'Autocomplete', 'InputNumber', 'InputPassword']
16 const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect'] 15 const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
17 if (textMap.includes(schema?.component as string)) { 16 if (textMap.includes(schema?.component as string)) {
18 return { 17 return {
19 - // placeholder: t('common.inputText')  
20 - placeholder: '请输入' 18 + placeholder: t('common.inputText')
21 } 19 }
22 } 20 }
23 if (selectMap.includes(schema?.component as string)) { 21 if (selectMap.includes(schema?.component as string)) {
@@ -29,16 +27,13 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => { @@ -29,16 +27,13 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
29 ) 27 )
30 ) { 28 ) {
31 return { 29 return {
32 - // startPlaceholder: t('common.startTimeText'),  
33 - // endPlaceholder: t('common.endTimeText'),  
34 - startPlaceholder: '开始时间',  
35 - endPlaceholder: '结束时间', 30 + startPlaceholder: t('common.startTimeText'),
  31 + endPlaceholder: t('common.endTimeText'),
36 rangeSeparator: '-' 32 rangeSeparator: '-'
37 } 33 }
38 } else { 34 } else {
39 return { 35 return {
40 - // placeholder: t('common.selectText')  
41 - placeholder: '请选择' 36 + placeholder: t('common.selectText')
42 } 37 }
43 } 38 }
44 } 39 }
yudao-ui-admin-vue3/src/config/axios/index.ts
@@ -5,7 +5,6 @@ import { config } from '@/config/axios/config' @@ -5,7 +5,6 @@ import { config } from '@/config/axios/config'
5 import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth' 5 import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth'
6 import errorCode from './errorCode' 6 import errorCode from './errorCode'
7 import { useI18n } from '@/hooks/web/useI18n' 7 import { useI18n } from '@/hooks/web/useI18n'
8 -const { t } = useI18n()  
9 8
10 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE 9 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
11 const BASE_URL = import.meta.env.VITE_BASE_URL 10 const BASE_URL = import.meta.env.VITE_BASE_URL
@@ -46,25 +45,27 @@ service.interceptors.request.use( @@ -46,25 +45,27 @@ service.interceptors.request.use(
46 const tenantId = getTenantId() 45 const tenantId = getTenantId()
47 if (tenantId) (config as Recordable).headers.common['tenant-id'] = tenantId 46 if (tenantId) (config as Recordable).headers.common['tenant-id'] = tenantId
48 } 47 }
  48 + const params = config.params || {}
  49 + const data = config.data || false
49 if ( 50 if (
50 - config.method === 'post' && 51 + config.method?.toUpperCase() === 'POST' &&
51 config!.headers!['Content-Type'] === 'application/x-www-form-urlencoded' 52 config!.headers!['Content-Type'] === 'application/x-www-form-urlencoded'
52 ) { 53 ) {
53 - config.data = qs.stringify(config.data) 54 + config.data = qs.stringify(data)
54 } 55 }
55 // get参数编码 56 // get参数编码
56 - if (config.method === 'get' && config.params) { 57 + if (config.method?.toUpperCase() === 'GET' && config.params) {
57 let url = config.url as string 58 let url = config.url as string
  59 + // 给 get 请求加上时间戳参数,避免从缓存中拿数据
  60 + // const now = new Date().getTime()
  61 + // params = params.substring(0, url.length - 1) + `?_t=${now}`
58 url += '?' 62 url += '?'
59 - const keys = Object.keys(config.params) 63 + const keys = Object.keys(params)
60 for (const key of keys) { 64 for (const key of keys) {
61 - if (config.params[key] !== void 0 && config.params[key] !== null) {  
62 - url += `${key}=${encodeURIComponent(config.params[key])}&` 65 + if (params[key] !== void 0 && params[key] !== null) {
  66 + url += `${key}=${encodeURIComponent(params[key])}&`
63 } 67 }
64 } 68 }
65 - // 给 get 请求加上时间戳参数,避免从缓存中拿数据  
66 - // const now = new Date().getTime()  
67 - // url = url.substring(0, url.length - 1) + `?_t=${now}`  
68 config.params = {} 69 config.params = {}
69 config.url = url 70 config.url = url
70 } 71 }
@@ -85,6 +86,7 @@ service.interceptors.response.use( @@ -85,6 +86,7 @@ service.interceptors.response.use(
85 // 返回“[HTTP]请求没有返回值”; 86 // 返回“[HTTP]请求没有返回值”;
86 throw new Error() 87 throw new Error()
87 } 88 }
  89 + const { t } = useI18n()
88 // 未设置状态码则默认成功状态 90 // 未设置状态码则默认成功状态
89 const code = data.code || result_code 91 const code = data.code || result_code
90 // 获取错误信息 92 // 获取错误信息
@@ -134,6 +136,7 @@ service.interceptors.response.use( @@ -134,6 +136,7 @@ service.interceptors.response.use(
134 (error: AxiosError) => { 136 (error: AxiosError) => {
135 console.log('err' + error) // for debug 137 console.log('err' + error) // for debug
136 let { message } = error 138 let { message } = error
  139 + const { t } = useI18n()
137 if (message === 'Network Error') { 140 if (message === 'Network Error') {
138 message = t('sys.api.errorMessage') 141 message = t('sys.api.errorMessage')
139 } else if (message.includes('timeout')) { 142 } else if (message.includes('timeout')) {
@@ -146,6 +149,7 @@ service.interceptors.response.use( @@ -146,6 +149,7 @@ service.interceptors.response.use(
146 } 149 }
147 ) 150 )
148 function handleAuthorized() { 151 function handleAuthorized() {
  152 + const { t } = useI18n()
149 if (!isRelogin.show) { 153 if (!isRelogin.show) {
150 isRelogin.show = true 154 isRelogin.show = true
151 ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), { 155 ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), {