diff --git a/atable/src/stores/table.ts b/atable/src/stores/table.ts index bc416165..f76b1961 100644 --- a/atable/src/stores/table.ts +++ b/atable/src/stores/table.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { type CSSProperties, computed, ref } from 'vue' import type { CellContext, TableColumn, TableConfig, TableDisplay, TableModal, TableRow } from '../types' +import { generateHash } from '../utils' /** * Create a table store @@ -18,7 +19,7 @@ export const createTableStore = (initData: { display?: TableDisplay[] modal?: TableModal }) => { - const id = initData.id || crypto.randomUUID() + const id = initData.id || generateHash() const createStore = defineStore(`table-${id}`, () => { // util functions const createTableObject = () => { diff --git a/atable/src/utils.ts b/atable/src/utils.ts index e97b8406..6f3616a9 100644 --- a/atable/src/utils.ts +++ b/atable/src/utils.ts @@ -2,3 +2,7 @@ export const isHtmlString = (htmlString: string) => { const $document = new DOMParser().parseFromString(htmlString, 'text/html') return Array.from($document.body.childNodes).some(node => node.nodeType === 1) } + +export const generateHash = (length = 8) => { + return Array.from({ length }, () => Math.floor(Math.random() * 16).toString(16)).join('') +}