style: simplify spread threshold controls
This commit is contained in:
parent
4c66262211
commit
b4440e2ca3
@ -187,10 +187,8 @@ export function ensurePluginToolbar(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const thresholdTitle = createToolbarGroupTitle(document, "传播指标筛选");
|
const thresholdTitle = createToolbarGroupTitle(document, "传播指标筛选");
|
||||||
const thresholdRule = createSpreadThresholdRule(document);
|
|
||||||
|
|
||||||
firstRow.append(dataGroup, videoGroup, exportStatusText);
|
firstRow.append(dataGroup, videoGroup, exportStatusText);
|
||||||
secondRow.append(thresholdTitle, thresholdRule, thresholdGroup);
|
secondRow.append(thresholdTitle, thresholdGroup);
|
||||||
panel.append(firstRow, secondRow);
|
panel.append(firstRow, secondRow);
|
||||||
|
|
||||||
root.append(
|
root.append(
|
||||||
@ -335,11 +333,17 @@ function createSpreadThresholdInput(
|
|||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.type = "number";
|
input.type = "number";
|
||||||
input.min = "0";
|
input.min = "0";
|
||||||
input.step = "0.01";
|
input.step = getSpreadThresholdStep(key);
|
||||||
input.dataset.pluginSpreadThreshold = key;
|
input.dataset.pluginSpreadThreshold = key;
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSpreadThresholdStep(
|
||||||
|
key: keyof SpreadThresholdFilter["thresholds"]
|
||||||
|
): string {
|
||||||
|
return key === "finishRate" || key === "interactionRate" ? "0.1" : "1";
|
||||||
|
}
|
||||||
|
|
||||||
function createSpreadThresholdControls(
|
function createSpreadThresholdControls(
|
||||||
document: Document,
|
document: Document,
|
||||||
inputs: Record<keyof SpreadThresholdFilter["thresholds"], HTMLInputElement>
|
inputs: Record<keyof SpreadThresholdFilter["thresholds"], HTMLInputElement>
|
||||||
@ -390,21 +394,6 @@ function createSpreadThresholdConjunction(document: Document): HTMLElement {
|
|||||||
return conjunction;
|
return conjunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSpreadThresholdRule(document: Document): HTMLElement {
|
|
||||||
const rule = document.createElement("span");
|
|
||||||
rule.dataset.pluginSpreadThresholdRule = "and-gte";
|
|
||||||
applySpreadThresholdRuleStyles(rule);
|
|
||||||
|
|
||||||
const emphasis = document.createElement("strong");
|
|
||||||
emphasis.textContent = "AND";
|
|
||||||
|
|
||||||
const detail = document.createElement("small");
|
|
||||||
detail.textContent = "每项取值 >= 输入值";
|
|
||||||
|
|
||||||
rule.append("全部满足", emphasis, detail);
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
function readSpreadThresholdInputs(
|
function readSpreadThresholdInputs(
|
||||||
root: HTMLElement
|
root: HTMLElement
|
||||||
): Record<keyof SpreadThresholdFilter["thresholds"], HTMLInputElement> {
|
): Record<keyof SpreadThresholdFilter["thresholds"], HTMLInputElement> {
|
||||||
@ -985,32 +974,6 @@ function applySpreadThresholdConjunctionStyles(conjunction: HTMLElement): void {
|
|||||||
conjunction.style.flex = "0 0 auto";
|
conjunction.style.flex = "0 0 auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
function applySpreadThresholdRuleStyles(rule: HTMLElement): void {
|
|
||||||
rule.style.display = "flex";
|
|
||||||
rule.style.alignItems = "center";
|
|
||||||
rule.style.height = "32px";
|
|
||||||
rule.style.padding = "0 10px";
|
|
||||||
rule.style.border = "1px solid #d9efe7";
|
|
||||||
rule.style.borderRadius = "8px";
|
|
||||||
rule.style.background = "#f0fbf6";
|
|
||||||
rule.style.color = "#0f8a5f";
|
|
||||||
rule.style.fontSize = "12px";
|
|
||||||
rule.style.fontWeight = "900";
|
|
||||||
rule.style.whiteSpace = "nowrap";
|
|
||||||
rule.style.flex = "0 0 auto";
|
|
||||||
|
|
||||||
Array.from(rule.children).forEach((child) => {
|
|
||||||
if (child instanceof rule.ownerDocument.defaultView!.HTMLElement) {
|
|
||||||
child.style.marginLeft = child.tagName === "SMALL" ? "6px" : "3px";
|
|
||||||
if (child.tagName === "SMALL") {
|
|
||||||
child.style.color = "#64748b";
|
|
||||||
child.style.fontSize = "12px";
|
|
||||||
child.style.fontWeight = "700";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyStatusStyles(statusText: HTMLElement): void {
|
function applyStatusStyles(statusText: HTMLElement): void {
|
||||||
statusText.style.color = "#64748b";
|
statusText.style.color = "#64748b";
|
||||||
statusText.style.fontSize = "12px";
|
statusText.style.fontSize = "12px";
|
||||||
|
|||||||
@ -463,12 +463,7 @@ describe("market-content-entry", () => {
|
|||||||
]);
|
]);
|
||||||
expect(titles[0]?.style.background).toBe("rgb(238, 245, 255)");
|
expect(titles[0]?.style.background).toBe("rgb(238, 245, 255)");
|
||||||
expect(titles[1]?.style.background).toBe("rgb(238, 245, 255)");
|
expect(titles[1]?.style.background).toBe("rgb(238, 245, 255)");
|
||||||
expect(
|
expect(document.querySelector("[data-plugin-spread-threshold-rule]")).toBeNull();
|
||||||
document.querySelector("[data-plugin-spread-threshold-rule]")?.textContent
|
|
||||||
).toContain("全部满足AND");
|
|
||||||
expect(
|
|
||||||
document.querySelector("[data-plugin-spread-threshold-rule]")?.textContent
|
|
||||||
).toContain("每项取值 >= 输入值");
|
|
||||||
expect(operators).toEqual(["≥", "≥", "≥", "≥", "≥", "≥", "≥"]);
|
expect(operators).toEqual(["≥", "≥", "≥", "≥", "≥", "≥", "≥"]);
|
||||||
expect(conjunctions).toEqual(["且", "且", "且", "且", "且", "且"]);
|
expect(conjunctions).toEqual(["且", "且", "且", "且", "且", "且"]);
|
||||||
expect(thresholdInputs.map((input) => input.placeholder)).toEqual([
|
expect(thresholdInputs.map((input) => input.placeholder)).toEqual([
|
||||||
@ -480,6 +475,15 @@ describe("market-content-entry", () => {
|
|||||||
"",
|
"",
|
||||||
""
|
""
|
||||||
]);
|
]);
|
||||||
|
expect(thresholdInputs.map((input) => input.step)).toEqual([
|
||||||
|
"1",
|
||||||
|
"1",
|
||||||
|
"1",
|
||||||
|
"1",
|
||||||
|
"0.1",
|
||||||
|
"0.1",
|
||||||
|
"1"
|
||||||
|
]);
|
||||||
expect(thresholdControls.map((control) => control.textContent)).toEqual([
|
expect(thresholdControls.map((control) => control.textContent)).toEqual([
|
||||||
"评论≥条",
|
"评论≥条",
|
||||||
"时长≥秒",
|
"时长≥秒",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user