Commit d82815ac authored by 武广's avatar 武广

fix: 修改缓存保存空数据问题

parent 4813ee40
...@@ -160,6 +160,7 @@ const ServiceGoods = options => { ...@@ -160,6 +160,7 @@ const ServiceGoods = options => {
const addResponse = await sendAsyncHttpRequest(sendData); const addResponse = await sendAsyncHttpRequest(sendData);
if (addResponse.data) { if (addResponse.data) {
message.success(`${isEdit ? '修改' : '添加'}成功!`); message.success(`${isEdit ? '修改' : '添加'}成功!`);
localStorage.remove(localAutoSaveKey);
handleCancel(true); handleCancel(true);
} }
setPageLoading(false); setPageLoading(false);
......
...@@ -2,7 +2,7 @@ import { message } from 'antd'; ...@@ -2,7 +2,7 @@ import { message } from 'antd';
import { sortBy } from 'lodash'; import { sortBy } from 'lodash';
import UUID from '../../utils/uuid'; import UUID from '../../utils/uuid';
import localStorage from '@/utils/localStorage'; import localStorage from '@/utils/localStorage';
import { debounce, getObjectType } from '@/utils/utils'; import { debounce, getObjectType, isClass } from '@/utils/utils';
export const clearCurrent = currentList => currentList.filter(item => item.current); export const clearCurrent = currentList => currentList.filter(item => item.current);
...@@ -258,6 +258,16 @@ export const createProductData = (props, isEdit, skuList) => { ...@@ -258,6 +258,16 @@ export const createProductData = (props, isEdit, skuList) => {
export const localAutoSaveKey = 'good-info-auto-save'; export const localAutoSaveKey = 'good-info-auto-save';
export const onAutoSaveValue = (e, isClear) => { export const onAutoSaveValue = (e, isClear) => {
const keys = Object.keys(e);
if (
e &&
isClass(e) === 'Object' &&
keys.length === 1 &&
isClass(e[keys[0]]) === 'Object' &&
Object.keys(e[keys[0]]) < 1
) {
return;
}
if (isClear) { if (isClear) {
localStorage.set(localAutoSaveKey, Object.assign({}, e)); localStorage.set(localAutoSaveKey, Object.assign({}, e));
} else { } else {
...@@ -265,41 +275,3 @@ export const onAutoSaveValue = (e, isClear) => { ...@@ -265,41 +275,3 @@ export const onAutoSaveValue = (e, isClear) => {
localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e)); localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e));
} }
}; };
// export const onAutoSaveValue = (e, isClear) => {
// const localkey = 'good-info-auto-save';
// if (isClear) {
// localStorage.set(localkey, Object.assign({}, e));
// } else {
// const info = localStorage.get(localkey) || {};
// const key = Object.keys(e)[0];
// if (info[key] === undefined) {
// info[key] = e[key];
// localStorage.set(localkey, Object.assign({}, info));
// return;
// }
// if (getObjectType(e[key]) === 'Array' && e[key].length && getObjectType(e[key][0]) === 'Object') {
// e[key].forEach((item, i) => {
// if (item !== null) {
// if (getObjectType(item) === 'Object') {
// const itemkeys = Object.keys(item);
// if (itemkeys.length > 1 || info[key][i] === null) {
// info[key][i] = item;
// } else {
// info[key][i][itemkeys[0]] = item[itemkeys[0]];
// }
// } else {
// info[key][i] = item;
// }
// }
// });
// localStorage.set(localkey, Object.assign({}, info));
// } else if (getObjectType(e[key]) === 'Object') {
// const okey = Object.keys(e[key])[0];
// info[key][okey] = e[key][okey];
// } else {
// localStorage.set(localkey, Object.assign({}, info, e));
// }
// }
// message.success('已自动保存至缓存');
// };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment