diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 97d288eb..331e58c5 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -1,3 +1,5 @@ +import { JSONStringify, JSONParse } from './utils' + /** * * 存储本地会话数据 * @param k 键名 @@ -6,7 +8,7 @@ */ export const setLocalStorage = (k: string, v: T) => { try { - window.localStorage.setItem(k, JSON.stringify(v)) + window.localStorage.setItem(k, JSONStringify(v)) } catch (error) { return false } @@ -20,7 +22,7 @@ export const setLocalStorage = (k: string, v: T) => { export const getLocalStorage = (k: string) => { const item = window.localStorage.getItem(k) try { - return item ? JSON.parse(item) : item + return item ? JSONParse(item) : item } catch (err) { return item } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 9c24f19c..2fc3edba 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -272,7 +272,7 @@ export const setKeyboardDressShow = (keyCode?: number) => { * * JSON序列化,支持函数和 undefined * @param data */ -export const JSONStringify = (data: object) => { +export const JSONStringify = (data: T) => { return JSON.stringify( data, (key, val) => { diff --git a/src/views/chart/ContentEdit/components/EditTools/index.vue b/src/views/chart/ContentEdit/components/EditTools/index.vue index fc435ad2..79d2eb6c 100644 --- a/src/views/chart/ContentEdit/components/EditTools/index.vue +++ b/src/views/chart/ContentEdit/components/EditTools/index.vue @@ -172,18 +172,18 @@ const updateToSession = (id: string) => { // 配置列表 const btnList: BtnListType[] = [ - { - key: 'export', - type: TypeEnum.BUTTON, - name: '导出', - icon: ShareIcon, - handle: exportHandle - }, { key: 'import', type: TypeEnum.IMPORTUPLOAD, name: '导入', - icon: DownloadIcon + icon: ShareIcon + }, + { + key: 'export', + type: TypeEnum.BUTTON, + name: '导出', + icon: DownloadIcon, + handle: exportHandle }, { key: 'edit',