//@ts-nocheck import { defineComponent, inject } from "vue"; import { xU } from "../../ventoseUtils"; import { usefnObserveDomResize } from "../../compositionAPI/useDomResize"; import { xVirTableTd } from "./xVirTableTd"; export type t_rowPayload = { rowIndex: number; rowData: object; }; export const xVirTableBody = defineComponent({ props: ["columnOrder", "columns", "rowHeight", "selectedConfigs", "selected"], emits: ["selectedChange", "update:scrollHeight", "scroll"], inject: ["xVirTable"], components: { xVirTableTd }, setup() { const { fnObserveDomResize, fnUnobserveDomResize } = usefnObserveDomResize(); return { uniqBy: inject("uniqBy"), configs: inject("configs"), rowCache: {}, fnObserveDomResize, fnUnobserveDomResize }; }, data(vm) { this.debounceSetPerBlockHeight = xU.debounce(function ( viewportHeight: number ) { this.viewportHeight = viewportHeight; this.perBlockRowCount = Math.ceil(viewportHeight / this.rowHeight); this.perBlockHeight = this.perBlockRowCount * this.rowHeight; this.setHeight(); }, 64); return { isLoading: false, perBlockHeight: 1, perBlockRowCount: 0, blockInViewCount: 0, styleWrapperAll: { height: 0, position: "relative" }, virs1: [], virs2: [], virs3: [] }; }, mounted() { /* 监听body高度变化 */ this.fnObserveDomResize(this.$refs.wrapper, () => { this.xVirTable.layoutDebounce(); this.debounceSetPerBlockHeight(this.$refs.wrapper.offsetHeight); }); this.$watch( () => { return `${this.configs.dataSource.length}_${this.perBlockHeight}_${this.perBlockRowCount}_${this.styleWrapper1}_${this.styleWrapper2}_${this.styleWrapper3}`; }, () => { this.updateCell(); } ); }, beforeUnmount() { this.fnUnobserveDomResize(this.$refs.wrapper); }, computed: { fnIsSelected() { const { isSelect, prop } = this.selectedConfigs || {}; if (xU.isFunction(isSelect)) { return rowInfo => { return isSelect.call(this, { ...rowInfo, selected: this.selected }); }; } else { /* 默认处理方式 */ return ({ rowData }) => { const id = rowData[prop]; return this.selected.includes(id); }; } }, fnIsDisabled() { const { isDisabled } = this.selectedConfigs || {}; if (xU.isFunction(isDisabled)) { return (...args) => { return isDisabled.apply(this, args); }; } else { return () => { return false; }; } }, positionBlock() { return this.blockInViewCount % 3; }, /* style */ styleWrapper1() { if (this.positionBlock === 0) { return `transform:translateY(${ this.blockInViewCount * this.perBlockHeight }px)`; } if (this.positionBlock === 1) { return `transform:translateY(${ (this.blockInViewCount + 2) * this.perBlockHeight }px)`; } return `transform:translateY(${ (this.blockInViewCount + 1) * this.perBlockHeight }px)`; }, styleWrapper2() { if (this.positionBlock === 0) { return `transform:translateY(${ (this.blockInViewCount + 1) * this.perBlockHeight }px)`; } if (this.positionBlock === 1) { return `transform:translateY(${ this.blockInViewCount * this.perBlockHeight }px)`; } return `transform:translateY(${ (this.blockInViewCount - 1) * this.perBlockHeight }px)`; }, styleWrapper3() { if (this.positionBlock === 0) { return `transform:translateY(${ (this.blockInViewCount + 2) * this.perBlockHeight }px)`; } if (this.positionBlock === 1) { return `transform:translateY(${ (this.blockInViewCount + 1) * this.perBlockHeight }px)`; } return `transform:translateY(${ this.blockInViewCount * this.perBlockHeight }px)`; }, vDomBodyTr1() { return this.genTr(this.virs1); }, vDomBodyTr2() { return this.genTr(this.virs2); }, vDomBodyTr3() { return this.genTr(this.virs3); } }, methods: { clearCacheRow() { const props = xU.filter(this.rowCache, (value, prop) => /^blockId/.test(prop) ); xU.each(props, prop => delete this.rowCache[prop]); }, onClickRow(payload: t_rowPayload) { if (this?.configs?.onClickRow) { this.configs.onClickRow(payload); } }, genTr(rows) { const vDomBlock = (() => { if (!this.uniqBy) { return xU.map(rows, (data: object, rowIndex: number) => { const { __virRowIndex } = data; const payload = { rowIndex: __virRowIndex, rowData: data }; return (