Commit cff736f656a0ed4fd3a46d4678f552fee0f0a9f3

Authored by xingyu4j
1 parent 40f73003

feat: vue3 add captcha support i18n

yudao-ui-admin-vue3/src/components/Verifition/src/Verify.vue
... ... @@ -5,7 +5,7 @@
5 5 :style="{ 'max-width': parseInt(imgSize.width) + 30 + 'px' }"
6 6 >
7 7 <div class="verifybox-top" v-if="mode == 'pop'">
8   - 请完成安全验证
  8 + {{ t('captcha.verification') }}
9 9 <span class="verifybox-close" @click="closeBox">
10 10 <i class="iconfont icon-close"></i>
11 11 </span>
... ... @@ -38,6 +38,7 @@
38 38 * */
39 39 import { VerifySlide, VerifyPoints } from './Verify'
40 40 import { computed, ref, toRefs, watchEffect } from 'vue'
  41 +import { useI18n } from '@/hooks/web/useI18n'
41 42  
42 43 export default {
43 44 name: 'Vue3Verify',
... ... @@ -83,6 +84,7 @@ export default {
83 84 }
84 85 },
85 86 setup(props) {
  87 + const { t } = useI18n()
86 88 const { captchaType, mode } = toRefs(props)
87 89 const clickShow = ref(false)
88 90 const verifyType = ref(undefined)
... ... @@ -129,6 +131,7 @@ export default {
129 131 })
130 132  
131 133 return {
  134 + t,
132 135 clickShow,
133 136 verifyType,
134 137 componentType,
... ...
yudao-ui-admin-vue3/src/components/Verifition/src/Verify/VerifyPoints.vue
... ... @@ -66,6 +66,7 @@ import { resetSize } from &#39;./../utils/util&#39;
66 66 import { aesEncrypt } from './../utils/ase'
67 67 import { reqGet, reqCheck } from './../api/index'
68 68 import { onMounted, reactive, ref, nextTick, toRefs, getCurrentInstance } from 'vue'
  69 +import { useI18n } from '@/hooks/web/useI18n'
69 70 export default {
70 71 name: 'VerifyPoints',
71 72 props: {
... ... @@ -102,6 +103,7 @@ export default {
102 103 }
103 104 },
104 105 setup(props) {
  106 + const { t } = useI18n()
105 107 const { mode, captchaType } = toRefs(props)
106 108 const { proxy } = getCurrentInstance()
107 109 let secretKey = ref(''), //后端返回的ase加密秘钥
... ... @@ -174,7 +176,7 @@ export default {
174 176 if (res.repCode == '0000') {
175 177 barAreaColor.value = '#4cae4c'
176 178 barAreaBorderColor.value = '#5cb85c'
177   - text.value = '验证成功'
  179 + text.value = t('captcha.success')
178 180 bindingClick.value = false
179 181 if (mode.value == 'pop') {
180 182 setTimeout(() => {
... ... @@ -187,7 +189,7 @@ export default {
187 189 proxy.$parent.$emit('error', proxy)
188 190 barAreaColor.value = '#d9534f'
189 191 barAreaBorderColor.value = '#d9534f'
190   - text.value = '验证失败'
  192 + text.value = t('captcha.fail')
191 193 setTimeout(() => {
192 194 refresh()
193 195 }, 700)
... ... @@ -219,7 +221,7 @@ export default {
219 221 checkPosArr.splice(0, checkPosArr.length)
220 222 num.value = 1
221 223 getPictrue()
222   - text.value = '验证失败'
  224 + text.value = t('captcha.fail')
223 225 showRefresh.value = true
224 226 }
225 227  
... ... @@ -234,7 +236,7 @@ export default {
234 236 backToken.value = res.repData.token
235 237 secretKey.value = res.repData.secretKey
236 238 poinTextList.value = res.repData.wordList
237   - text.value = '请依次点击【' + poinTextList.value.join(',') + '】'
  239 + text.value = t('captcha.point') + '【' + poinTextList.value.join(',') + '】'
238 240 } else {
239 241 text.value = res.repMsg
240 242 }
... ...
yudao-ui-admin-vue3/src/components/Verifition/src/Verify/VerifySlide.vue
... ... @@ -79,6 +79,7 @@
79 79 import { aesEncrypt } from './../utils/ase'
80 80 import { resetSize } from './../utils/util'
81 81 import { reqGet, reqCheck } from './../api/index'
  82 +import { useI18n } from '@/hooks/web/useI18n'
82 83 import {
83 84 computed,
84 85 onMounted,
... ... @@ -111,7 +112,7 @@ export default {
111 112 },
112 113 explain: {
113 114 type: String,
114   - default: '向右滑动完成验证'
  115 + default: ''
115 116 },
116 117 imgSize: {
117 118 type: Object,
... ... @@ -142,6 +143,7 @@ export default {
142 143 }
143 144 },
144 145 setup(props) {
  146 + const { t } = useI18n()
145 147 const { mode, captchaType, type, blockSize, explain } = toRefs(props)
146 148 const { proxy } = getCurrentInstance()
147 149 let secretKey = ref(''), //后端返回的ase加密秘钥
... ... @@ -181,7 +183,11 @@ export default {
181 183 return proxy.$el.querySelector('.verify-bar-area')
182 184 })
183 185 function init() {
184   - text.value = explain.value
  186 + if (explain.value === '') {
  187 + text.value = t('captcha.slide')
  188 + } else {
  189 + text.value = explain.value
  190 + }
185 191 getPictrue()
186 192 nextTick(() => {
187 193 let { imgHeight, imgWidth, barHeight, barWidth } = resetSize(proxy)
... ... @@ -311,9 +317,8 @@ export default {
311 317 }, 1500)
312 318 }
313 319 passFlag.value = true
314   - tipWords.value = `${((endMovetime.value - startMoveTime.value) / 1000).toFixed(
315   - 2
316   - )}s验证成功`
  320 + tipWords.value = `${((endMovetime.value - startMoveTime.value) / 1000).toFixed(2)}s
  321 + ${t('captcha.success')}`
317 322 var captchaVerification = secretKey.value
318 323 ? aesEncrypt(
319 324 backToken.value + '---' + JSON.stringify({ x: moveLeftDistance, y: 5.0 }),
... ... @@ -335,7 +340,7 @@ export default {
335 340 refresh()
336 341 }, 1000)
337 342 proxy.$parent.$emit('error', proxy)
338   - tipWords.value = '验证失败'
  343 + tipWords.value = t('captcha.fail')
339 344 setTimeout(() => {
340 345 tipWords.value = ''
341 346 }, 1000)
... ...
yudao-ui-admin-vue3/src/locales/en.ts
... ... @@ -128,6 +128,13 @@ export default {
128 128 btnRegister: 'Sign up',
129 129 SmsSendMsg: 'code has been sent'
130 130 },
  131 + captcha: {
  132 + verification: 'Please complete security verification',
  133 + slide: 'Swipe right to complete verification',
  134 + point: 'Please click',
  135 + success: 'Verification succeeded',
  136 + fail: 'verification failed'
  137 + },
131 138 router: {
132 139 login: 'Login',
133 140 home: 'Home',
... ... @@ -191,7 +198,6 @@ export default {
191 198 yield: 'Yield',
192 199 dynamic: 'Dynamic',
193 200 push: 'push',
194   - pushCode: 'push code to Github',
195 201 follow: 'Follow'
196 202 },
197 203 form: {
... ...
yudao-ui-admin-vue3/src/locales/zh-CN.ts
... ... @@ -128,6 +128,13 @@ export default {
128 128 btnRegister: '注册',
129 129 SmsSendMsg: '验证码已发送'
130 130 },
  131 + captcha: {
  132 + verification: '请完成安全验证',
  133 + slide: '向右滑动完成验证',
  134 + point: '请依次点击',
  135 + success: '验证成功',
  136 + fail: '验证失败'
  137 + },
131 138 router: {
132 139 login: '登录',
133 140 home: '首页',
... ... @@ -191,7 +198,6 @@ export default {
191 198 yield: '产量',
192 199 dynamic: '动态',
193 200 push: '推送',
194   - pushCode: '推送 代码到 Github',
195 201 follow: '关注'
196 202 },
197 203 form: {
... ...