整合前端仓库并保留提交历史

This commit is contained in:
2026-08-31 11:52:41 +08:00
172 changed files with 120216 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
import { hasAuth } from '~/plugins/permission'
/**
* 权限检查组合式函数
*/
export function useAuth() {
return {
/**
* 检查用户是否有权限
* @param permissions 权限码或权限码数组
* @returns 是否有权限
*/
hasAuth,
/**
* 检查用户是否没有权限
* @param permissions 权限码或权限码数组
* @returns 是否没有权限
*/
lacksAuth: (permissions: string | string[]) => !hasAuth(permissions)
}
}
+40
View File
@@ -0,0 +1,40 @@
import { ref } from 'vue'
import { getCaptchaImage } from '@/api/system'
interface CaptchaFormData {
captcha_code: string
captcha_key: string
}
interface CaptchaResponse {
code: number
msg: string
data: {
uuid: string
base64: string
}
}
export function useCaptcha(formData: CaptchaFormData) {
const image = ref('')
const refresh = async () => {
try {
const res = await getCaptchaImage() as CaptchaResponse
if (res.code === 0 && res.data) {
formData.captcha_key = res.data.uuid
formData.captcha_code = ''
image.value = res.data.base64.replace(/\r\n/g, '')
}
} catch (e) {
console.error('获取验证码失败:', e)
}
}
return {
image,
refresh
}
}
+9
View File
@@ -0,0 +1,9 @@
import { useRoute } from 'vue-router'
export function t(message: string) {
const nuxtApp: any = useNuxtApp()
const i18nInstance = nuxtApp.$getI18n()
// 直接使用 i18n 的 t 方法,让它自动根据 locale 选择对应的翻译
return i18nInstance.global.t(message)
}
+29
View File
@@ -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
}
}
+60
View File
@@ -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
}
}