feat(admin): 新增UUID生成工具并优化模板管理
- 新增 uuid.ts 工具函数,提供原生和兼容性 UUID 生成方案 - 更新模板详情页面,使用 generateUUID() 替代 crypto.randomUUID() - 模板列表新增页码字段显示 - 优化模板列表组件代码格式,改进可读性 - 更新 Git 提交消息规范文档,强制使用中文描述和具体要求
This commit is contained in:
16
apps/admin/src/utils/uuid.ts
Normal file
16
apps/admin/src/utils/uuid.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 生成UUID的兼容函数
|
||||
* 优先使用原生 crypto.randomUUID,如果不支持则使用兼容方案
|
||||
*/
|
||||
export function generateUUID(): string {
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||
return crypto.randomUUID()
|
||||
}
|
||||
|
||||
// 兼容性回退方案 - 生成符合 UUID v4 格式的字符串
|
||||
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)
|
||||
})
|
||||
}
|
||||
@ -7,6 +7,7 @@ import { onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useRouterPush } from '@/hooks/common/router'
|
||||
import { fetchAddTemplate, fetchTemplateDetail } from '@/service/api/template'
|
||||
import { generateUUID } from '@/utils/uuid'
|
||||
import { useUpload } from './hooks/useUpload'
|
||||
import TemplateCanvas from './modules/TemplateCanvas.vue'
|
||||
import TemplateSettings from './modules/TemplateSettings.vue'
|
||||
@ -64,7 +65,7 @@ function handleUploadTrigger() {
|
||||
* 处理区域生成
|
||||
*/
|
||||
function handleGenerate() {
|
||||
const groupId = crypto.randomUUID()
|
||||
const groupId = generateUUID()
|
||||
const newRegions: Region[] = []
|
||||
|
||||
// 计算起始编号:查找现有的最大 Qx 编号
|
||||
@ -85,7 +86,7 @@ function handleGenerate() {
|
||||
for (let c = 0; c < genSettings.value.cols; c++) {
|
||||
const index = maxNum + r * genSettings.value.cols + c + 1 // 计算当前区域的编号
|
||||
newRegions.push({
|
||||
id: crypto.randomUUID(),
|
||||
id: generateUUID(),
|
||||
groupId,
|
||||
x: currentX + c * (genSettings.value.w + genSettings.value.gapX),
|
||||
y: currentY + r * (genSettings.value.h + genSettings.value.gapY),
|
||||
|
||||
@ -66,6 +66,11 @@ const { columns, columnChecks, data, getData, getDataByPage, loading, mobilePagi
|
||||
title: '模板ID',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
key: 'PageNo',
|
||||
title: '页码',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
key: 'competitionId',
|
||||
title: '关联比赛',
|
||||
|
||||
Reference in New Issue
Block a user