🐛 cell 获取错误

This commit is contained in:
Vanessa 2023-12-29 14:08:35 +08:00
parent cbe09a1fd9
commit 74083b30ad
5 changed files with 50 additions and 63 deletions

View file

@ -54,15 +54,6 @@
} }
} }
.custom-attr__avarrow {
height: 12px;
width: 12px;
color: var(--b3-theme-on-surface);
margin: 0 5px;
flex-shrink: 0;
align-self: center;
}
.custom-attr__avvalue { .custom-attr__avvalue {
cursor: pointer; cursor: pointer;
transition: var(--b3-transition); transition: var(--b3-transition);

View file

@ -32,12 +32,14 @@ export const genAVValueHTML = (value: IAVCellValue) => {
}); });
break; break;
case "date": case "date":
if (value[value.type].isNotEmpty) { html = `<span class="av__celltext" data-value='${JSON.stringify(value[value.type])}'>`;
html = `<span data-content="${value[value.type].content}">${dayjs(value[value.type].content).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}</span>`; if (value[value.type] && value[value.type].isNotEmpty) {
html += dayjs(value[value.type].content).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
} }
if (value[value.type].hasEndDate && value[value.type].isNotEmpty2 && value[value.type].isNotEmpty) { if (value[value.type] && value[value.type].hasEndDate && value[value.type].isNotEmpty && value[value.type].isNotEmpty2) {
html += `<svg class="custom-attr__avarrow"><use xlink:href="#iconForward"></use></svg><span data-content="${value[value.type].content2}">${dayjs(value[value.type].content2).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}</span>`; html += `<svg class="av__cellicon"><use xlink:href="#iconForward"></use></svg>${dayjs(value[value.type].content2).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
} }
html += "</span>";
break; break;
case "created": case "created":
case "updated": case "updated":

View file

@ -3,6 +3,7 @@ import * as dayjs from "dayjs";
import {updateAttrViewCellAnimation} from "./action"; import {updateAttrViewCellAnimation} from "./action";
import {genAVValueHTML} from "./blockAttr"; import {genAVValueHTML} from "./blockAttr";
import {hasClosestByClassName} from "../../util/hasClosest"; import {hasClosestByClassName} from "../../util/hasClosest";
import {genCellValueByElement, getTypeByCellElement} from "./cell";
export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => { export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
let hasEndDate = true; let hasEndDate = true;
@ -63,6 +64,7 @@ export const bindDateEvent = (options: {
protyle: IProtyle, protyle: IProtyle,
data: IAV, data: IAV,
menuElement: HTMLElement, menuElement: HTMLElement,
blockElement: Element,
cellElements: HTMLElement[] cellElements: HTMLElement[]
}) => { }) => {
const inputElements: NodeListOf<HTMLInputElement> = options.menuElement.querySelectorAll("input"); const inputElements: NodeListOf<HTMLInputElement> = options.menuElement.querySelectorAll("input");
@ -72,6 +74,7 @@ export const bindDateEvent = (options: {
cellElements: options.cellElements, cellElements: options.cellElements,
data: options.data, data: options.data,
protyle: options.protyle, protyle: options.protyle,
blockElement: options.blockElement,
value: { value: {
isNotEmpty: inputElements[0].value !== "", isNotEmpty: inputElements[0].value !== "",
content: new Date(inputElements[0].dataset.value).getTime(), content: new Date(inputElements[0].dataset.value).getTime(),
@ -85,6 +88,7 @@ export const bindDateEvent = (options: {
cellElements: options.cellElements, cellElements: options.cellElements,
data: options.data, data: options.data,
protyle: options.protyle, protyle: options.protyle,
blockElement: options.blockElement,
value: { value: {
isNotEmpty2: inputElements[1].value !== "", isNotEmpty2: inputElements[1].value !== "",
content2: new Date(inputElements[1].dataset.value).getTime(), content2: new Date(inputElements[1].dataset.value).getTime(),
@ -101,6 +105,7 @@ export const bindDateEvent = (options: {
setDateValue({ setDateValue({
cellElements: options.cellElements, cellElements: options.cellElements,
data: options.data, data: options.data,
blockElement: options.blockElement,
protyle: options.protyle, protyle: options.protyle,
value: { value: {
hasEndDate: inputElements[2].checked, hasEndDate: inputElements[2].checked,
@ -127,6 +132,7 @@ export const bindDateEvent = (options: {
setDateValue({ setDateValue({
cellElements: options.cellElements, cellElements: options.cellElements,
data: options.data, data: options.data,
blockElement: options.blockElement,
protyle: options.protyle, protyle: options.protyle,
value: { value: {
isNotTime: !inputElements[3].checked isNotTime: !inputElements[3].checked
@ -139,73 +145,54 @@ export const setDateValue = (options: {
cellElements: HTMLElement[], cellElements: HTMLElement[],
data: IAV data: IAV
protyle: IProtyle, protyle: IProtyle,
value: IAVCellDateValue value: IAVCellDateValue,
blockElement: Element
}) => { }) => {
let cellIndex: number;
Array.from((hasClosestByClassName(options.cellElements[0], "av__row") as HTMLElement).querySelectorAll(".av__cell")).find((item: HTMLElement, index) => {
if (item.dataset.id === options.cellElements[0].dataset.id) {
cellIndex = index;
return true;
}
});
const colId = options.cellElements[0].dataset.colId; const colId = options.cellElements[0].dataset.colId;
const cellDoOperations: IOperation[] = []; const cellDoOperations: IOperation[] = [];
const cellUndoOperations: IOperation[] = []; const cellUndoOperations: IOperation[] = [];
options.cellElements.forEach(item => { options.cellElements.forEach((item, elementIndex) => {
let cellData: IAVCell; if (!options.blockElement.contains(item)) {
let oldValue; item = options.cellElements[elementIndex] = options.blockElement.querySelector(`.av__cell[data-id="${item.dataset.id}"]`) as HTMLElement;
}
const cellValue = genCellValueByElement(getTypeByCellElement(item) || item.dataset.type as TAVCol, item);
const oldValue = JSON.parse(JSON.stringify(cellValue))
const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id; const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id;
options.data.view.rows.find(row => { cellValue.date = Object.assign(cellValue.date || {
if (row.id === rowID) { isNotEmpty2: false,
if (typeof cellIndex === "number") { isNotEmpty: false
cellData = row.cells[cellIndex]; }, options.value);
// 为空时 cellId 每次请求都不一致
cellData.id = item.dataset.id;
if (!cellData.value) {
cellData.value = {
type: cellData.valueType
};
} else {
cellData.value.id = item.dataset.id;
}
} else {
cellData = row.cells.find(cellItem => {
if (item.dataset.id === cellItem.id) {
return true;
}
});
}
oldValue = Object.assign({}, cellData.value.date);
cellData.value.date = Object.assign(cellData.value.date || {
isNotEmpty2: false,
isNotEmpty: false
}, options.value);
return true;
}
});
cellDoOperations.push({ cellDoOperations.push({
action: "updateAttrViewCell", action: "updateAttrViewCell",
id: cellData.id, id: cellValue.id,
keyID: colId, keyID: colId,
rowID, rowID,
avID: options.data.id, avID: options.data.id,
data: cellData.value data: cellValue
}); });
cellUndoOperations.push({ cellUndoOperations.push({
action: "updateAttrViewCell", action: "updateAttrViewCell",
id: cellData.id, id: cellValue.id,
keyID: colId, keyID: colId,
rowID, rowID,
avID: options.data.id, avID: options.data.id,
data: { data: oldValue
date: oldValue });
options.data.view.rows.find(row => {
if (row.id === rowID) {
row.cells.find(cell => {
if (cell.id === cellValue.id) {
cell.value = cellValue;
return true;
}
});
return true;
} }
}); });
if (item.classList.contains("custom-attr__avvalue")) { if (item.classList.contains("custom-attr__avvalue")) {
item.innerHTML = genAVValueHTML(cellData.value); item.innerHTML = genAVValueHTML(cellValue);
} else { } else {
updateAttrViewCellAnimation(item, cellData.value); updateAttrViewCellAnimation(item, cellValue);
} }
}); });
transaction(options.protyle, cellDoOperations, cellUndoOperations); transaction(options.protyle, cellDoOperations, cellUndoOperations);

View file

@ -93,7 +93,13 @@ export const openMenuPanel = (options: {
if (options.type === "select") { if (options.type === "select") {
bindSelectEvent(options.protyle, data, menuElement, options.cellElements, options.blockElement); bindSelectEvent(options.protyle, data, menuElement, options.cellElements, options.blockElement);
} else if (options.type === "date") { } else if (options.type === "date") {
bindDateEvent({protyle: options.protyle, data, menuElement, cellElements: options.cellElements}); bindDateEvent({
protyle: options.protyle,
data,
menuElement,
cellElements: options.cellElements,
blockElement: options.blockElement
});
} else if (options.type === "asset") { } else if (options.type === "asset") {
bindAssetEvent({protyle: options.protyle, data, menuElement, cellElements: options.cellElements}); bindAssetEvent({protyle: options.protyle, data, menuElement, cellElements: options.cellElements});
setTimeout(() => { setTimeout(() => {
@ -999,6 +1005,7 @@ export const openMenuPanel = (options: {
cellElements: options.cellElements, cellElements: options.cellElements,
data, data,
protyle: options.protyle, protyle: options.protyle,
blockElement: options.blockElement,
value: { value: {
isNotEmpty2: false, isNotEmpty2: false,
isNotEmpty: false, isNotEmpty: false,

View file

@ -60,7 +60,7 @@ export const removeCellOption = (protyle: IProtyle, data: IAV, cellElements: HTM
} }
const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id; const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id;
const cellValue = genCellValueByElement(getTypeByCellElement(item) || item.dataset.type as TAVCol, item); const cellValue = genCellValueByElement(getTypeByCellElement(item) || item.dataset.type as TAVCol, item);
const oldValue = Object.assign({}, cellValue.mSelect); const oldValue = JSON.parse(JSON.stringify(cellValue));
if (elementIndex === 0) { if (elementIndex === 0) {
cellValue.mSelect?.find((item: { content: string }, index: number) => { cellValue.mSelect?.find((item: { content: string }, index: number) => {
if (item.content === target.dataset.content) { if (item.content === target.dataset.content) {
@ -450,7 +450,7 @@ export const addColOptionOrCell = (protyle: IProtyle, data: IAV, cellElements: H
return; return;
} }
const cellValue = genCellValueByElement(colData.type, item); const cellValue = genCellValueByElement(colData.type, item);
const oldValue = Object.assign({}, cellValue); const oldValue = JSON.parse(JSON.stringify(cellValue));
if (index === 0) { if (index === 0) {
if (colData.type === "mSelect") { if (colData.type === "mSelect") {
let hasOption = false; let hasOption = false;