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 2 import type { Slots } from 'vue'
3 3 import { getSlot } from '@/utils/tsxHelper'
4 4 import { PlaceholderMoel } from './types'
5 5  
6   -// const { t } = useI18n()
7   -
8 6 /**
9 7 *
10 8 * @param schema 对应组件数据
... ... @@ -12,12 +10,12 @@ import { PlaceholderMoel } from './types'
12 10 * @description 用于自动设置placeholder
13 11 */
14 12 export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
  13 + const { t } = useI18n()
15 14 const textMap = ['Input', 'Autocomplete', 'InputNumber', 'InputPassword']
16 15 const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
17 16 if (textMap.includes(schema?.component as string)) {
18 17 return {
19   - // placeholder: t('common.inputText')
20   - placeholder: '请输入'
  18 + placeholder: t('common.inputText')
21 19 }
22 20 }
23 21 if (selectMap.includes(schema?.component as string)) {
... ... @@ -29,16 +27,13 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
29 27 )
30 28 ) {
31 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 32 rangeSeparator: '-'
37 33 }
38 34 } else {
39 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 5 import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth'
6 6 import errorCode from './errorCode'
7 7 import { useI18n } from '@/hooks/web/useI18n'
8   -const { t } = useI18n()
9 8  
10 9 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
11 10 const BASE_URL = import.meta.env.VITE_BASE_URL
... ... @@ -46,25 +45,27 @@ service.interceptors.request.use(
46 45 const tenantId = getTenantId()
47 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 50 if (
50   - config.method === 'post' &&
  51 + config.method?.toUpperCase() === 'POST' &&
51 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 56 // get参数编码
56   - if (config.method === 'get' && config.params) {
  57 + if (config.method?.toUpperCase() === 'GET' && config.params) {
57 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 62 url += '?'
59   - const keys = Object.keys(config.params)
  63 + const keys = Object.keys(params)
60 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 69 config.params = {}
69 70 config.url = url
70 71 }
... ... @@ -85,6 +86,7 @@ service.interceptors.response.use(
85 86 // 返回“[HTTP]请求没有返回值”;
86 87 throw new Error()
87 88 }
  89 + const { t } = useI18n()
88 90 // 未设置状态码则默认成功状态
89 91 const code = data.code || result_code
90 92 // 获取错误信息
... ... @@ -134,6 +136,7 @@ service.interceptors.response.use(
134 136 (error: AxiosError) => {
135 137 console.log('err' + error) // for debug
136 138 let { message } = error
  139 + const { t } = useI18n()
137 140 if (message === 'Network Error') {
138 141 message = t('sys.api.errorMessage')
139 142 } else if (message.includes('timeout')) {
... ... @@ -146,6 +149,7 @@ service.interceptors.response.use(
146 149 }
147 150 )
148 151 function handleAuthorized() {
  152 + const { t } = useI18n()
149 153 if (!isRelogin.show) {
150 154 isRelogin.show = true
151 155 ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), {
... ...