import { omit, cloneDeep } from 'lodash';
interface Row {
property: string;
type: string;
23699: string | null;
24116: string | null;
24373: string | null;
25642: string | null;
24759: string | null;
}
const cells = [23699, 24116, 24373, 24373, 25642, 24759];
class Comp {
highlightRow1: Row = {
23699: null,
24116: null,
24373: null,
24759: null,
25642: null,
property: 'a',
type: 'string',
};
highlightRow2: Row = {
23699: null,
24116: null,
24373: null,
24759: null,
25642: null,
property: 'b',
type: 'string',
};
// 出事渲染
init(rowData: Row[]) {
rowData.forEach((row) => {
if (row.property === this.highlightRow1.property) {
this.highlightRow1 = cloneDeep(row);
}
if (row.property === this.highlightRow2.property) {
this.highlightRow2 = cloneDeep(row);
}
});
}
emit(val: any) {
console.log(val);
}
change(data: { property: string; data: Row }) {
const { property, data: row } = data;
if (property === this.highlightRow1.property) {
this.highlightRow1 = Object.assign(
this.highlightRow1,
omit(cloneDeep(row), ['property', 'type'])
);
} else {
this.highlightRow2 = Object.assign(
this.highlightRow2,
omit(cloneDeep(row), ['property', 'type'])
);
}
}
rowParam: [prev: string, cur: string] = ['a', 'b'];
copyAM(rowData: Row[]) {
const [__, curProperty] = this.rowParam;
// 判断是否是黄色第一行
const isRowOne = () => curProperty === this.highlightRow1.property;
// 上一行
let lastRow: Row | undefined;
// 处理黄色第一行
if (isRowOne()) {
// 拿到黄色上一行
const currentIndex = rowData.findIndex(
(item) => item.property === this.highlightRow1.property
);
lastRow = rowData[currentIndex - 1];
// 把上一行的数字属性的值,复制到黄色第一行
this.highlightRow1 = Object.assign(
this.highlightRow1,
omit(cloneDeep(lastRow), ['property', 'type'])
);
cells.forEach((cellId) => {
this.emit({
id: cellId,
property: this.highlightRow1.property,
value: this.highlightRow1[cellId as keyof Row],
});
});
} else {
// 处理黄色第二行
this.highlightRow2 = Object.assign(
this.highlightRow2,
omit(cloneDeep(this.highlightRow1), ['property', 'type'])
);
cells.forEach((cellId) => {
this.emit({
id: cellId,
property: this.highlightRow2.property,
value: this.highlightRow2[cellId as keyof Row],
});
});
}
}
}
console.log(Comp);
export default {};
copyRow
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 人们问爱因斯坦为何能在1905年提出那么多改变人类认识世界的理论,他谦虚地回答道: “并不是我很聪明,只是我和问题...
- 国际黄金行情走势分析: 周一(3月8日)亚洲时段,现货黄金延续上周五纽约时段涨势,最高触及1714美元附近,目前交...