使用uuid包来生成uuidv4

This commit is contained in:
于小丘
2025-10-13 09:26:16 +08:00
parent a22ad985dc
commit 374f2a92aa
5 changed files with 44 additions and 52 deletions
@@ -11,6 +11,7 @@
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { v4 as uuidv4 } from 'uuid';
import { useConfigStore } from "@/store";
import { getEnvBaseUrl, sm2Encrypt } from "@/utils";
import { toast } from "@/utils/toast";
@@ -114,18 +115,9 @@ function closeAreaCodeSheet() {
showAreaCodeSheet.value = false;
}
// 生成UUID
function generateUUID() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
// 获取图形验证码
async function refreshCaptcha() {
const uuid = generateUUID();
const uuid = uuidv4();
formData.value.captchaId = uuid;
captchaImage.value = `${getEnvBaseUrl()}/user/captcha?uuid=${uuid}&t=${Date.now()}`;
}
+10 -18
View File
@@ -9,15 +9,16 @@
</route>
<script lang="ts" setup>
import type { LoginData } from '@/api/auth'
import { computed, onMounted, ref } from 'vue'
import { login } from '@/api/auth'
import { useConfigStore } from '@/store'
import { getEnvBaseUrl } from '@/utils'
import { toast } from '@/utils/toast'
import type { LoginData } from '@/api/auth';
import { computed, onMounted, ref } from 'vue';
import { v4 as uuidv4 } from 'uuid';
import { login } from '@/api/auth';
import { useConfigStore } from '@/store';
import { getEnvBaseUrl } from '@/utils';
import { toast } from '@/utils/toast';
// 导入国际化相关功能
import { t, changeLanguage, getSupportedLanguages, initI18n } from '@/i18n'
import type { Language } from '@/store/lang'
import { t, changeLanguage, getSupportedLanguages, initI18n } from '@/i18n';
import type { Language } from '@/store/lang';
// 导入SM2加密工具
import { sm2Encrypt } from '@/utils'
@@ -123,15 +124,6 @@ function goToForgotPassword() {
})
}
// 生成UUID
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0
const v = c === 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
}
let skipReLaunch = false // 全局或组件作用域
//跳转至服务端设置页面
@@ -143,7 +135,7 @@ function goToServerSetting() {
// 获取验证码
async function refreshCaptcha() {
const uuid = generateUUID()
const uuid = uuidv4();
formData.value.captchaId = uuid
captchaImage.value = `${getEnvBaseUrl()}/user/captcha?uuid=${uuid}&t=${Date.now()}`
}
@@ -9,15 +9,16 @@
</route>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import { register, sendSmsCode } from '@/api/auth'
import { useConfigStore } from '@/store'
import { getEnvBaseUrl } from '@/utils'
import { toast } from '@/utils/toast'
import { computed, onMounted, ref } from 'vue';
import { register, sendSmsCode } from '@/api/auth';
import { v4 as uuidv4 } from 'uuid';
import { useConfigStore } from '@/store';
import { getEnvBaseUrl } from '@/utils';
import { toast } from '@/utils/toast';
// 导入国际化相关功能
import { t, initI18n } from '@/i18n'
import { t, initI18n } from '@/i18n';
// 导入SM2加密工具
import { sm2Encrypt } from '@/utils'
import { sm2Encrypt } from '@/utils';
// 获取屏幕边界到安全区域距离
let safeAreaInsets
@@ -124,20 +125,11 @@ function closeAreaCodeSheet() {
showAreaCodeSheet.value = false
}
// 生成UUID
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
// 获取验证码
async function refreshCaptcha() {
const uuid = generateUUID()
formData.value.captchaId = uuid
captchaImage.value = `${getEnvBaseUrl()}/user/captcha?uuid=${uuid}&t=${Date.now()}`
const uuid = uuidv4();
formData.value.captchaId = uuid;
captchaImage.value = `${getEnvBaseUrl()}/user/captcha?uuid=${uuid}&t=${Date.now()}`;
}
// 发送短信验证码