initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { ref } from 'vue'
|
||||
import { getCaptchaImage } from '@/api/system'
|
||||
|
||||
interface formData {
|
||||
captcha_code: string,
|
||||
captcha_key: string
|
||||
}
|
||||
|
||||
export function useCaptcha(formData: formData) {
|
||||
const image = ref('')
|
||||
|
||||
const refresh = async () => {
|
||||
try {
|
||||
await getCaptchaImage().then((res: any) => {
|
||||
if (res.code == 1) {
|
||||
formData.captcha_key = res.data.captcha_key
|
||||
formData.captcha_code = ''
|
||||
image.value = res.data.img.replace(/\r\n/g, '')
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
image,
|
||||
refresh
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useRoute } from 'vue-router'
|
||||
import Language from '~/utils/language'
|
||||
|
||||
export function t(message: string) {
|
||||
const i18n = useNuxtApp().$getI18n()
|
||||
const route = useRoute()
|
||||
const file = new Language(i18n).getFileKey((route?.meta.plugin || 'app'), route?.path || '')
|
||||
const key = `${file}.${message}`
|
||||
return i18n.global.t(key) != key ? i18n.global.t(key) : i18n.global.t(message)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { LocationQueryRaw } from 'vue-router'
|
||||
import storage from '@/utils/storage'
|
||||
|
||||
export function useLogin() {
|
||||
/**
|
||||
* 设置登录返回页
|
||||
*/
|
||||
const setLoginBack = (route: LocationQueryRaw) => {
|
||||
storage.set({
|
||||
key: 'loginBack',
|
||||
data: {
|
||||
path: route.path,
|
||||
query: route.query
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行登录后跳转
|
||||
*/
|
||||
const handleLoginBack = (callbak:any) => {
|
||||
if(callbak) callbak()
|
||||
}
|
||||
|
||||
return {
|
||||
setLoginBack,
|
||||
handleLoginBack
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { reactive, ref } from 'vue'
|
||||
import { sendSmsVerificationCode } from '@/api/system'
|
||||
|
||||
export function useSendSms() {
|
||||
const canGetCode = ref(true),
|
||||
text = ref(t('get_sms_code')),
|
||||
seconds = ref(90);
|
||||
|
||||
let timer: number | undefined = undefined;
|
||||
|
||||
const send = async (param: requestMobileParam) => {
|
||||
if (!canGetCode.value) return
|
||||
canGetCode.value = false
|
||||
|
||||
let result: string | boolean = false
|
||||
await sendSmsVerificationCode(param).then((res: any) => {
|
||||
if (res.code == 1) {
|
||||
start()
|
||||
result = res.data.key
|
||||
} else {
|
||||
reset()
|
||||
result = false
|
||||
}
|
||||
}).catch(() => {
|
||||
result = false
|
||||
reset()
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始
|
||||
*/
|
||||
const start = () => {
|
||||
timer = setInterval(() => {
|
||||
if (seconds.value > 0) {
|
||||
seconds.value -= 1
|
||||
text.value = `${seconds.value}${t('sms_code_change_text')}`
|
||||
} else {
|
||||
reset()
|
||||
}
|
||||
}, 1000) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
const reset = () => {
|
||||
clearInterval(timer)
|
||||
seconds.value = 90
|
||||
canGetCode.value = true
|
||||
text.value = t('getSmsCode')
|
||||
}
|
||||
|
||||
return {
|
||||
send,
|
||||
text,
|
||||
canGetCode
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user