|
| 1 | +<template> |
| 2 | + <div class="plot-data" v-if="dataItem"> |
| 3 | + <div class="selectors"> |
| 4 | + <select v-model="dataItem.fnType" @change="fnTypeChange(dataItem)"> |
| 5 | + <option :value="undefined">{{ fnTypeArr[0].label }}</option> |
| 6 | + <option v-for="type in fnTypeArr.slice(1)" :value="type.value"> |
| 7 | + {{ type.label }} |
| 8 | + </option> |
| 9 | + </select> |
| 10 | + <select v-model="dataItem.graphType"> |
| 11 | + <option |
| 12 | + v-if="!getFnType(dataItem.fnType).notAllowedInIntervel" |
| 13 | + :value="undefined" |
| 14 | + > |
| 15 | + {{ graphTypeArr[0].label }} |
| 16 | + </option> |
| 17 | + <option |
| 18 | + v-if="dataItem.fnType !== 'implicit'" |
| 19 | + v-for="type in graphTypeArr.slice(1)" |
| 20 | + :value="type.value" |
| 21 | + > |
| 22 | + {{ type.label }} |
| 23 | + </option> |
| 24 | + </select> |
| 25 | + <button class="delete" @click="emit('delete')">删除</button> |
| 26 | + </div> |
| 27 | + |
| 28 | + <div class="inputs"> |
| 29 | + <div v-for="input in getFnType(dataItem.fnType).inputs" class="input-box"> |
| 30 | + <span class="input-title">{{ input.title }}</span> |
| 31 | + <input |
| 32 | + type="text" |
| 33 | + v-model="dataItem[input.value]" |
| 34 | + :placeholder="input.placeholder" |
| 35 | + /> |
| 36 | + </div> |
| 37 | + <template v-if="getFnType(dataItem.fnType).coord"> |
| 38 | + <div |
| 39 | + v-for="input in getFnType(dataItem.fnType).coord" |
| 40 | + class="input-box coord" |
| 41 | + > |
| 42 | + <span class="coord-label">{{ input.label }}</span> |
| 43 | + <input |
| 44 | + type="number" |
| 45 | + @input="handleCoordInput(dataItem!, input.value, 0, $event)" |
| 46 | + :placeholder="input.placeholder1" |
| 47 | + /> |
| 48 | + <span class="coord-label">{{ input.sep }}</span> |
| 49 | + <input |
| 50 | + type="number" |
| 51 | + @input="handleCoordInput(dataItem!, input.value, 1, $event)" |
| 52 | + :placeholder="input.placeholder2" |
| 53 | + /> |
| 54 | + <span class="coord-label">{{ input.fin }}</span> |
| 55 | + </div> |
| 56 | + </template> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | +</template> |
| 60 | +<script setup lang="ts"> |
| 61 | +import type { FunctionPlotDatum } from "function-plot"; |
| 62 | +import { fnTypeArr, graphTypeArr, inputTypeArr,getFnType } from "../consts"; |
| 63 | +import type { CoordType } from "../consts"; |
| 64 | +const emit = defineEmits(["delete"]); |
| 65 | +const dataItem = defineModel<FunctionPlotDatum>(); |
| 66 | +
|
| 67 | +function fnTypeChange(dataItem: FunctionPlotDatum) { |
| 68 | + if (getFnType(dataItem.fnType).notAllowedInIntervel && !dataItem.graphType) |
| 69 | + dataItem.graphType = "polyline"; |
| 70 | + if (dataItem.fnType === "implicit") delete dataItem.graphType; |
| 71 | + inputTypeArr.forEach((key) => delete dataItem[key]); |
| 72 | + if (dataItem.fnType === "vector") dataItem.vector = [0, 0]; |
| 73 | +} |
| 74 | +function handleCoordInput( |
| 75 | + dataItem: FunctionPlotDatum, |
| 76 | + key: CoordType["value"], |
| 77 | + index: 0 | 1, |
| 78 | + event: Event |
| 79 | +) { |
| 80 | + const raw = (<HTMLInputElement>event.target).value; |
| 81 | + const newVal = Number(raw); |
| 82 | + if (!dataItem[key]) { |
| 83 | + const coord: [number, number] = [0, 0]; |
| 84 | + coord[index] = newVal; |
| 85 | + dataItem[key] = coord; |
| 86 | + } else { |
| 87 | + if (raw === "") { |
| 88 | + if (dataItem[key][(index + 1) % 2]) dataItem[key][index] = 0; |
| 89 | + else delete dataItem[key]; |
| 90 | + } else { |
| 91 | + dataItem[key][index] = newVal; |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | +</script> |
| 96 | + |
| 97 | +<style> |
| 98 | +.plot-data { |
| 99 | + border-bottom: var(--c-border) 1px solid; |
| 100 | + background: var(--c-bk2); |
| 101 | + position: relative; |
| 102 | + padding: 20px 15px; |
| 103 | +} |
| 104 | +.delete { |
| 105 | + position: absolute; |
| 106 | + top: 0; |
| 107 | + bottom: 0; |
| 108 | + right: 0; |
| 109 | + color: var(--c-text); |
| 110 | + padding: 8px 15px; |
| 111 | + border: none; |
| 112 | + background: var(--c-red); |
| 113 | + transition: all 0.2s; |
| 114 | + border-radius: 5px; |
| 115 | + opacity: 0.75; |
| 116 | +} |
| 117 | +.delete:hover { |
| 118 | + opacity: 1; |
| 119 | +} |
| 120 | +.delete:active { |
| 121 | + opacity: 0.2; |
| 122 | + transition: none; |
| 123 | +} |
| 124 | +.selectors { |
| 125 | + margin-bottom: 10px; |
| 126 | + position: relative; |
| 127 | +} |
| 128 | +.selectors select { |
| 129 | + border: var(--c-border) 1px solid; |
| 130 | + background: var(--c-bk3); |
| 131 | + border-radius: 5px; |
| 132 | + width: 30%; |
| 133 | + padding: 8px 8px; |
| 134 | + margin-right: 15px; |
| 135 | + color: var(--text); |
| 136 | + font-size: 15px; |
| 137 | +} |
| 138 | +.selectors select:focus { |
| 139 | + border-color: var(--c-accent); |
| 140 | +} |
| 141 | +.inputs { |
| 142 | + display: flex; |
| 143 | + flex-direction: column; |
| 144 | + gap: 10px; |
| 145 | +} |
| 146 | +.inputs .input-box { |
| 147 | + position: relative; |
| 148 | + display: flex; |
| 149 | +} |
| 150 | +.inputs .input-box .input-title { |
| 151 | + font-family: "JetBrains Mono"; |
| 152 | + font-style: italic; |
| 153 | + letter-spacing: 5px; |
| 154 | + font-size: 20px; |
| 155 | + font-weight: bold; |
| 156 | + margin: auto 5px; |
| 157 | + height: fit-content; |
| 158 | +} |
| 159 | +.inputs input { |
| 160 | + color: var(--c-text); |
| 161 | + background: var(--c-bk1); |
| 162 | + border: var(--c-border) 1px solid; |
| 163 | + height: 100%; |
| 164 | + line-height: 100%; |
| 165 | + font-size: 20px; |
| 166 | + border-radius: 5px; |
| 167 | + display: block; |
| 168 | + width: 100%; |
| 169 | + text-indent: 10px; |
| 170 | + font-family: "JetBrains Mono"; |
| 171 | + padding: 10px 0; |
| 172 | +} |
| 173 | +.inputs input:placeholder-shown { |
| 174 | + border-color: var(--c-red); |
| 175 | +} |
| 176 | +.inputs input:focus { |
| 177 | + border-color: var(--c-accent); |
| 178 | +} |
| 179 | +.add-data { |
| 180 | + padding-top: 10px; |
| 181 | + padding-bottom: 10px; |
| 182 | +} |
| 183 | +.add-data:hover { |
| 184 | + background: var(--c-bk3); |
| 185 | +} |
| 186 | +.add-data:active { |
| 187 | + background: var(--c-bk1); |
| 188 | +} |
| 189 | +</style> |
0 commit comments