Commit d921a692 authored by 武广's avatar 武广

feat: 添加数据改变自动保存功能

parent 1239037a
...@@ -171,7 +171,7 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -171,7 +171,7 @@ const EditFormTable = forwardRef((props, ref) => {
return ( return (
<> <>
<Form form={form} scrollToFirstError component={false}> <Form form={form} scrollToFirstError component={false} onValuesChange={props.onValuesChange}>
<EditableContext.Provider value={form}> <EditableContext.Provider value={form}>
<Table <Table
scroll={{ y: 300, x: 1000 }} scroll={{ y: 300, x: 1000 }}
......
...@@ -175,7 +175,7 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -175,7 +175,7 @@ const FormAttr = forwardRef((props, ref) => {
<> <>
<div className={styles.attrbox + (isMore ? styles.attrboxMore : '')}> <div className={styles.attrbox + (isMore ? styles.attrboxMore : '')}>
{categoryAttrs.length > 0 && ( {categoryAttrs.length > 0 && (
<Form form={form} initialValues={initAttrData}> <Form form={form} initialValues={initAttrData} onValuesChange={props.onValuesChange}>
<Row> <Row>
{categoryAttrs.map(k => ( {categoryAttrs.map(k => (
<Col span={12} key={k.id}> <Col span={12} key={k.id}>
......
...@@ -82,6 +82,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -82,6 +82,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
description: '', description: '',
}} }}
scrollToFirstError scrollToFirstError
onValuesChange={props.onValuesChange}
> >
<Form.Item <Form.Item
name="categoryId" name="categoryId"
......
...@@ -270,7 +270,7 @@ const FormPackage = forwardRef((props, ref) => { ...@@ -270,7 +270,7 @@ const FormPackage = forwardRef((props, ref) => {
return ( return (
<div className={styles.formPackageBox}> <div className={styles.formPackageBox}>
<Form style={{ marginBottom: 10 }} form={form}> <Form style={{ marginBottom: 10 }} form={form} onValuesChange={props.onValuesChange}>
<Form.List name="lists"> <Form.List name="lists">
{(fields, { add, remove }) => ( {(fields, { add, remove }) => (
<> <>
......
...@@ -322,6 +322,7 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -322,6 +322,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const bacthFirst = form.getFieldValue('bacthFirst'); const bacthFirst = form.getFieldValue('bacthFirst');
const bacthSecon = form.getFieldValue('bacthSecon'); const bacthSecon = form.getFieldValue('bacthSecon');
const resetObject = batchTableSourceData({ batchItem, tableData, bacthSecon, bacthFirst }); const resetObject = batchTableSourceData({ batchItem, tableData, bacthSecon, bacthFirst });
props.onValuesChange({ tableList: resetObject });
setTableData(resetObject); setTableData(resetObject);
}; };
...@@ -384,7 +385,12 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -384,7 +385,12 @@ const FormPriceOrStock = forwardRef((props, ref) => {
return ( return (
<> <>
<Form form={form} autoComplete="off" initialValues={initSpecReced()}> <Form
form={form}
autoComplete="off"
initialValues={initSpecReced()}
onValuesChange={props.onValuesChange}
>
<SpecificationTemplate <SpecificationTemplate
form={form} form={form}
label="一级规格" label="一级规格"
...@@ -422,11 +428,17 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -422,11 +428,17 @@ const FormPriceOrStock = forwardRef((props, ref) => {
setTableData={setTableData} setTableData={setTableData}
defaultColumns={defaultColumns} defaultColumns={defaultColumns}
initData={tableData} initData={tableData}
onValuesChange={props.onValuesChange}
/> />
{customer.isCard && ( {customer.isCard && (
<> <>
<Title title="套餐内容" key="tctitle" /> <Title title="套餐内容" key="tctitle" />
<FormPackage ref={packageRef} initData={tableData} key="tc" /> <FormPackage
ref={packageRef}
initData={tableData}
key="tc"
onValuesChange={props.onValuesChange}
/>
</> </>
)} )}
</> </>
......
...@@ -89,6 +89,7 @@ const FormRuleSetting = forwardRef((props, ref) => { ...@@ -89,6 +89,7 @@ const FormRuleSetting = forwardRef((props, ref) => {
tips: '', // 温馨提示 tips: '', // 温馨提示
}} }}
scrollToFirstError scrollToFirstError
onValuesChange={props.onValuesChange}
> >
<Form.Item name="purchaseTime" label="购买时间" {...rangeConfig}> <Form.Item name="purchaseTime" label="购买时间" {...rangeConfig}>
<RangePicker <RangePicker
......
...@@ -117,6 +117,7 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -117,6 +117,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
imageList: {}, imageList: {},
detailImageList: [], detailImageList: [],
}} }}
onValuesChange={props.onValuesChange}
> >
<Form.Item <Form.Item
name="commonImageList" name="commonImageList"
......
...@@ -120,6 +120,7 @@ const FormSettlementOthers = forwardRef((props, ref) => { ...@@ -120,6 +120,7 @@ const FormSettlementOthers = forwardRef((props, ref) => {
name="register" name="register"
initialValues={initValue} initialValues={initValue}
scrollToFirstError scrollToFirstError
onValuesChange={props.onValuesChange}
> >
<Form.Item <Form.Item
name="appointment" name="appointment"
......
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
merchantProductEdit, merchantProductEdit,
getByProductType, getByProductType,
} from './service'; } from './service';
import { isUrl, filterSendData, clearCurrent } from './utils'; import { isUrl, filterSendData, clearCurrent, onAutoSaveValue } from './utils';
import { ServiceContext } from './context'; import { ServiceContext } from './context';
import { GOOD_MANAGE } from '@/../config/permission.config'; import { GOOD_MANAGE } from '@/../config/permission.config';
...@@ -64,8 +64,20 @@ const ServiceGoods = options => { ...@@ -64,8 +64,20 @@ const ServiceGoods = options => {
const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset()); const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset());
const onValuesChange = e => {
if (!isEdit) {
onAutoSaveValue(e);
}
};
const productChange = task => { const productChange = task => {
setProductType(task.type); setProductType(task.type);
onAutoSaveValue(
{
type: task.type,
},
!0,
);
const timer = setTimeout(() => { const timer = setTimeout(() => {
resetForm(); resetForm();
clearTimeout(timer); clearTimeout(timer);
...@@ -280,11 +292,18 @@ const ServiceGoods = options => { ...@@ -280,11 +292,18 @@ const ServiceGoods = options => {
afterAddressList={afterAddressList} afterAddressList={afterAddressList}
specListData={specListData} specListData={specListData}
onCategoryChange={onCategoryChange} onCategoryChange={onCategoryChange}
onValuesChange={onValuesChange}
/> />
{[1, 2].includes(productType) && [ {[1, 2].includes(productType) && [
<Title title="商品属性" key="attrtitle" />, <Title title="商品属性" key="attrtitle" />,
<FormAttr key="attr" ref={attrRef} categoryIds={categoryIds} initData={editData} />, <FormAttr
key="attr"
ref={attrRef}
categoryIds={categoryIds}
initData={editData}
onValuesChange={onValuesChange}
/>,
]} ]}
<Title title="价格与库存" /> <Title title="价格与库存" />
...@@ -294,6 +313,7 @@ const ServiceGoods = options => { ...@@ -294,6 +313,7 @@ const ServiceGoods = options => {
onSpecChange={onSpecCommonImgEvent} onSpecChange={onSpecCommonImgEvent}
editData={editData.infoSpecData} editData={editData.infoSpecData}
skuList={editData.skuList} skuList={editData.skuList}
onValuesChange={onValuesChange}
/> />
<Title title="规则设置" /> <Title title="规则设置" />
...@@ -302,6 +322,7 @@ const ServiceGoods = options => { ...@@ -302,6 +322,7 @@ const ServiceGoods = options => {
ref={settingRef} ref={settingRef}
editData={editData.serviceItem} editData={editData.serviceItem}
supplierIdList={supplierIdList} supplierIdList={supplierIdList}
onValuesChange={onValuesChange}
/> />
)} )}
...@@ -309,9 +330,14 @@ const ServiceGoods = options => { ...@@ -309,9 +330,14 @@ const ServiceGoods = options => {
ref={picturesRef} ref={picturesRef}
specKeyItem={specKeyList} specKeyItem={specKeyList}
editData={editData.infoImageData} editData={editData.infoImageData}
onValuesChange={onValuesChange}
/> />
{productType === 4 && ( {productType === 4 && (
<FormSettlementOthers ref={settleOtrRef} editData={editData.settlementItem} /> <FormSettlementOthers
ref={settleOtrRef}
editData={editData.settlementItem}
onValuesChange={onValuesChange}
/>
)} )}
</ServiceContext.Provider> </ServiceContext.Provider>
</WrapperContainer> </WrapperContainer>
......
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 { debounce, getObjectType } from '@/utils/utils';
export const clearCurrent = currentList => currentList.filter(item => item.current); export const clearCurrent = currentList => currentList.filter(item => item.current);
...@@ -248,3 +251,37 @@ export const createProductData = (props, isEdit) => { ...@@ -248,3 +251,37 @@ export const createProductData = (props, isEdit) => {
// } // }
return list; return list;
}; };
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) || {};
console.log('e :>> ', e);
const key = Object.keys(e)[0];
if (getObjectType(e[key]) === 'Array') {
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('已自动保存至缓存');
};
...@@ -64,6 +64,21 @@ export function isClass(o) { ...@@ -64,6 +64,21 @@ export function isClass(o) {
return Object.prototype.toString.call(o).slice(8, -1); return Object.prototype.toString.call(o).slice(8, -1);
} }
export function debounce(fn, delay = 500) {
let timer = null;
return function fun(...args) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
fn.apply(this, args);
}, delay);
};
}
// 深拷贝 // 深拷贝
export function deepClone(obj) { export function deepClone(obj) {
let result; let result;
...@@ -110,3 +125,5 @@ export const getClientInfo = () => { ...@@ -110,3 +125,5 @@ export const getClientInfo = () => {
height: document.body.clientHeight, height: document.body.clientHeight,
}; };
}; };
export const getObjectType = v => Object.prototype.toString.call(v).replace(/\[object |]/g, '');
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