diff --git a/packages/hooks/usePersistedstate.ts b/packages/hooks/usePersistedstate.ts index 3ce9aab..f9ac84e 100644 --- a/packages/hooks/usePersistedstate.ts +++ b/packages/hooks/usePersistedstate.ts @@ -1,5 +1,6 @@ -import { watch, Ref } from '@vue/composition-api' +import { watch, Ref, ref } from '@vue/composition-api' import { IFormConfig } from '@pack/typings/v-form-component' +export const count = ref(0) /** * 持久化表单设计器配置 @@ -8,7 +9,9 @@ import { IFormConfig } from '@pack/typings/v-form-component' export function usePersistedstate(config: Ref) { const storageConfig = localStorage.getItem('$VFormDesignConfig') if (storageConfig) { - config.value = JSON.parse(storageConfig) + const configObj: IFormConfig = JSON.parse(storageConfig) + count.value = configObj.formItems.length + config.value = configObj } watch( config.value, diff --git a/packages/utils/index.ts b/packages/utils/index.ts index 8258b46..007a018 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -6,6 +6,7 @@ import { } from '../typings/v-form-component' import { cloneDeep, isArray, isFunction, isNumber, uniqueId } from 'lodash-es' import { del } from '@vue/composition-api' +import { count } from '@pack/hooks/usePersistedstate' /** * 组件install方法 * @param comp 需要挂载install方法的组件 @@ -24,14 +25,16 @@ export function withInstall(comp: T) { * @returns {string|boolean} 返回一个唯一 id 或者 false */ export function generateKey(formItem?: IVFormComponent): string | boolean { + count.value = count.value + 1 + if (formItem) { - const key = uniqueId(`${toLine(formItem.type)}_`) - formItem.key = key + const key = `${toLine(formItem.type)}_${count.value}` + formItem.key = `${key}+${randomUUID}` formItem.field = key - return true } - return uniqueId('key_') + + return `key_${count.value}` } /**