lex-xin 9 месяцев назад
Родитель
Сommit
e5ba7e3d41
1 измененных файлов с 14 добавлено и 1 удалено
  1. 14 1
      src/components/editor/index.tsx

+ 14 - 1
src/components/editor/index.tsx

@@ -8,6 +8,19 @@ import dayjs from 'dayjs'
 import { getUploadSign, onOnlyFileUpload } from '@/utils/oss-file-upload'
 
 // type InsertFnType = (url: string, poster = '') => void
+/** 生成 uuid */
+export const UUID = () => {
+  let d = new Date().getTime()
+  if (window.performance && typeof window.performance.now === "function") {
+     d += performance.now() //use high-precision timer if available
+  }
+  const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
+     const r = (d + Math.random() * 16) % 16 | 0
+     d = Math.floor(d / 16)
+     return (c == "x" ? r : (r & 0x3) | 0x8).toString(16)
+  })
+  return uuid
+}
 
 export default defineComponent({
   name: 'editor',
@@ -61,7 +74,7 @@ export default defineComponent({
       acl: 'public-read',
       name: ''
     }) as any
-    const idKey = props.id || new Date().getTime()
+    const idKey = props.id || UUID()
     const loading = ref(false)
     const ossUploadUrl = `https://${props.bucketName}.ks3-cn-beijing.ksyuncs.com/`
     const changeEditor = ref(false)