Skip to content

Commit 5be1e4b

Browse files
committed
添加颜色支持
1 parent ef263f5 commit 5be1e4b

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/components/dataBlock.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
:fnType="fnType"
5656
:blockFolded="blockFolded"
5757
/>
58+
<OptInputs
59+
v-if="fnType.optInput"
60+
:dataItem="dataItem"
61+
:fnType="fnType"
62+
:blockFolded="blockFolded"
63+
/>
5864
</div>
5965
</div>
6066
</template>
@@ -66,6 +72,7 @@ import StrInputs from "./dataBlockInner/strInputs.vue";
6672
import CoordInputs from "./dataBlockInner/coordInputs.vue";
6773
import SwitchInputs from "./dataBlockInner/switchInputs.vue";
6874
import CoordArrInputs from "./dataBlockInner/coordArrInputs.vue";
75+
import OptInputs from "./dataBlockInner/optInputs.vue";
6976
7077
const emit = defineEmits(["delete"]);
7178
const dataItem = defineModel<FunctionPlotDatum>();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<div
3+
v-if="!blockFolded"
4+
v-for="input in fnType.optInput ?? []"
5+
class="input-box opt-input optional"
6+
>
7+
<span class="coord-label optin-label">{{ input.label }}</span>
8+
<input
9+
:type="input.type"
10+
:value="dataItem[input.value] ?? ''"
11+
@input="handleCoordInput(dataItem!, input, $event)"
12+
:placeholder="input.placeholder"
13+
/>
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import { FnType, OptInput } from "../../consts";
19+
import { FunctionPlotDatum } from "function-plot";
20+
21+
const { dataItem, fnType } = defineProps<{
22+
dataItem: FunctionPlotDatum;
23+
fnType: FnType;
24+
blockFolded: boolean;
25+
}>();
26+
27+
function handleCoordInput(
28+
dataItem: FunctionPlotDatum,
29+
input: OptInput,
30+
event: Event
31+
) {
32+
const raw = (<HTMLInputElement>event.target).value;
33+
if (raw === "") {
34+
delete dataItem[input.value];
35+
return;
36+
}
37+
if (input.type === "number") dataItem[input.value] = Number(raw);
38+
else dataItem[input.value] = raw;
39+
}
40+
</script>
41+
42+
<style>
43+
.input-box.opt-input {
44+
display: flex;
45+
color: #bbb;
46+
gap: 10px;
47+
}
48+
.input-box.opt-input span {
49+
font-size: 18px;
50+
margin: auto 5px;
51+
flex-shrink: 0;
52+
}
53+
.input-box.opt-input input {
54+
min-width: 3em;
55+
padding: 6px 0;
56+
font-size: 18px;
57+
flex-shrink: 1;
58+
}
59+
</style>

src/consts.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ export type CoordArr = {
5252
placeholder: [string, string];
5353
};
5454

55+
export type OptInput = {
56+
label: string;
57+
placeholder?: string;
58+
vif?: keyof FunctionPlotDatum;
59+
} & ({ value: "color"; type: "text" } | { value: "nSamples"; type: "number" });
60+
5561
export type FnType = {
5662
value: FunctionPlotDatum["fnType"] | "text";
5763
label: string;
5864
inputs: InputType[];
5965
coord?: CoordType[];
6066
coordArr?: CoordArr;
6167
switches?: SwitchType[];
68+
optInput?: OptInput[];
6269
notAllowedInInterval?: boolean;
6370
};
6471

@@ -96,6 +103,13 @@ export const fnTypeArr = [
96103
folded: true,
97104
},
98105
],
106+
optInput: [
107+
{
108+
value: "color",
109+
type: "text",
110+
label: "颜色",
111+
},
112+
],
99113
},
100114
{
101115
value: "implicit",

0 commit comments

Comments
 (0)