Skip to content

Commit

Permalink
feat: 持久化数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue committed Jan 26, 2022
1 parent fbe9980 commit 35f9591
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/hooks/usePersistedstate.ts
Original file line number Diff line number Diff line change
@@ -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)

/**
* 持久化表单设计器配置
Expand All @@ -8,7 +9,9 @@ import { IFormConfig } from '@pack/typings/v-form-component'
export function usePersistedstate(config: Ref<IFormConfig>) {
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,
Expand Down
11 changes: 7 additions & 4 deletions packages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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方法的组件
Expand All @@ -24,14 +25,16 @@ export function withInstall<T extends { name: string }>(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}`
}

/**
Expand Down

0 comments on commit 35f9591

Please sign in to comment.