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