refac: defineComponent => vue3 setup

This commit is contained in:
2022-07-12 00:28:08 +09:00
parent 87e063e03e
commit b31ee022af
7 changed files with 565 additions and 643 deletions
+17 -16
View File
@@ -1,9 +1,5 @@
<template> <template>
<div <div :class="[`chiefBox${chiefLevel}`, 'subRows']" :style="style" @click="onClick">
:class="[`chiefBox${chiefLevel}`, 'subRows']"
:style="style"
@click="$emit('click', this)"
>
<div <div
class="bg1 nameHeader" class="bg1 nameHeader"
:style="{ :style="{
@@ -33,15 +29,14 @@
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { getNpcColor } from "@/common_legacy"; import { getNpcColor } from "@/common_legacy";
import type { ChiefResponse } from "@/defs/API/NationCommand"; import type { ChiefResponse } from "@/defs/API/NationCommand";
import { mb_strwidth } from "@/util/mb_strwidth"; import { mb_strwidth } from "@/util/mb_strwidth";
import { defineComponent, type PropType } from "vue"; import type { PropType } from "vue";
import VueTypes from "vue-types"; import VueTypes from "vue-types";
export default defineComponent({ defineProps({
props: {
chiefLevel: VueTypes.integer.isRequired, chiefLevel: VueTypes.integer.isRequired,
style: VueTypes.object.isRequired, style: VueTypes.object.isRequired,
officer: { officer: {
@@ -49,11 +44,17 @@ export default defineComponent({
default: undefined, default: undefined,
}, },
isMe: VueTypes.bool.isRequired, isMe: VueTypes.bool.isRequired,
}, });
emits: ["click"],
methods: { const emit = defineEmits<{
mb_strwidth, (event: "click", value: HTMLElement): void,
getNpcColor, }>();
},
}); function onClick(event: MouseEvent){
if(!event.target){
return;
}
const elem = event.target as HTMLElement;
emit("click", elem);
}
</script> </script>
+81 -110
View File
@@ -234,19 +234,8 @@
<BottomBar title="내무부" /> <BottomBar title="내무부" />
</BContainer> </BContainer>
</template> </template>
<script lang="ts">
import TipTap from "./components/TipTap.vue";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
import { computed, defineComponent, reactive, ref, toRefs } from "vue";
import { isString } from "lodash";
import { type diplomacyState, diplomacyStateInfo, type NationStaticItem } from "./defs";
import { SammoAPI } from "./SammoAPI";
import { joinYearMonth } from "@/util/joinYearMonth";
import { parseYearMonth } from "@/util/parseYearMonth";
import { useToast, BContainer } from "bootstrap-vue-3";
import { unwrap } from "./util/unwrap";
<script lang="ts">
type NationItem = NationStaticItem & { type NationItem = NationStaticItem & {
cityCnt: number; cityCnt: number;
diplomacy: { diplomacy: {
@@ -292,31 +281,50 @@ declare const staticValues: {
max: number; max: number;
}; };
}; };
</script>
<script setup lang="ts">
import TipTap from "./components/TipTap.vue";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
import { computed, reactive, ref, toRefs } from "vue";
import { isString } from "lodash";
import { type diplomacyState, diplomacyStateInfo, type NationStaticItem } from "./defs";
import { SammoAPI } from "./SammoAPI";
import { joinYearMonth } from "@/util/joinYearMonth";
import { parseYearMonth } from "@/util/parseYearMonth";
import { useToast, BContainer } from "bootstrap-vue-3";
import { unwrap } from "./util/unwrap";
export default defineComponent({ const toasts = unwrap(useToast());
components: { const self = reactive(staticValues);
TopBackBar, const {
BottomBar, editable,
TipTap, nationMsg,
BContainer, scoutMsg,
}, nationID,
setup() { year,
const toasts = unwrap(useToast()); month,
const self = reactive(staticValues); nationsList,
gold,
rice,
income,
policy,
warSettingCnt,
} = toRefs(self);
let oldNationMsg = staticValues.nationMsg; let oldNationMsg = staticValues.nationMsg;
const inEditNationMsg = ref(false); const inEditNationMsg = ref(false);
function enableEditNationMsg() { function enableEditNationMsg() {
inEditNationMsg.value = true; inEditNationMsg.value = true;
} }
function rollbackNationMsg() { function rollbackNationMsg() {
inEditNationMsg.value = false; inEditNationMsg.value = false;
self.nationMsg = oldNationMsg; self.nationMsg = oldNationMsg;
} }
async function saveNationMsg() { async function saveNationMsg() {
const msg = self.nationMsg; const msg = self.nationMsg;
try { try {
await SammoAPI.Nation.SetNotice({ await SammoAPI.Nation.SetNotice({
@@ -337,19 +345,19 @@ export default defineComponent({
} }
console.error(e); console.error(e);
} }
} }
let oldScoutMsg = staticValues.scoutMsg; let oldScoutMsg = staticValues.scoutMsg;
const inEditScoutMsg = ref(false); const inEditScoutMsg = ref(false);
function enableEditScoutMsg() { function enableEditScoutMsg() {
inEditScoutMsg.value = true; inEditScoutMsg.value = true;
} }
function rollbackScoutMsg() { function rollbackScoutMsg() {
inEditScoutMsg.value = false; inEditScoutMsg.value = false;
self.scoutMsg = oldScoutMsg; self.scoutMsg = oldScoutMsg;
} }
async function saveScoutMsg() { async function saveScoutMsg() {
const msg = self.scoutMsg; const msg = self.scoutMsg;
try { try {
await SammoAPI.Nation.SetScoutMsg({ await SammoAPI.Nation.SetScoutMsg({
@@ -370,9 +378,9 @@ export default defineComponent({
} }
console.error(e); console.error(e);
} }
} }
const trackTiptapFormHeight = (target: string) => { const trackTiptapFormHeight = (target: string) => {
let form: HTMLElement | null = null; let form: HTMLElement | null = null;
let outerForm: HTMLElement | null = null; let outerForm: HTMLElement | null = null;
function handler() { function handler() {
@@ -396,34 +404,36 @@ export default defineComponent({
window.addEventListener("orientationchange", handler, true); window.addEventListener("orientationchange", handler, true);
return handler; return handler;
}; };
const trackNationMsgHeight = trackTiptapFormHeight("#noticeForm");
const trackScoutMsgHeight = trackTiptapFormHeight("#scoutMsgForm");
const incomeGoldCity = computed(() => { const incomeGoldCity = computed(() => {
return (self.income.gold.city * self.policy.rate) / 100; return (self.income.gold.city * self.policy.rate) / 100;
}); });
const incomeGold = computed(() => { const incomeGold = computed(() => {
return incomeGoldCity.value + self.income.gold.war; return incomeGoldCity.value + self.income.gold.war;
}); });
const incomeRiceCity = computed(() => { const incomeRiceCity = computed(() => {
return (self.income.rice.city * self.policy.rate) / 100; return (self.income.rice.city * self.policy.rate) / 100;
}); });
const incomeRiceWall = computed(() => { const incomeRiceWall = computed(() => {
return (self.income.rice.wall * self.policy.rate) / 100; return (self.income.rice.wall * self.policy.rate) / 100;
}); });
const incomeRice = computed(() => { const incomeRice = computed(() => {
return incomeRiceCity.value + incomeRiceWall.value; return incomeRiceCity.value + incomeRiceWall.value;
}); });
const outcomeByBill = computed(() => { const outcomeByBill = computed(() => {
return (self.outcome * self.policy.bill) / 100; return (self.outcome * self.policy.bill) / 100;
}); });
let oldRate = staticValues.policy.rate; let oldRate = staticValues.policy.rate;
async function setRate() { async function setRate() {
const rate = self.policy.rate; const rate = self.policy.rate;
try { try {
await SammoAPI.Nation.SetRate({ amount: rate }); await SammoAPI.Nation.SetRate({ amount: rate });
@@ -441,13 +451,13 @@ export default defineComponent({
} }
console.error(e); console.error(e);
} }
} }
function rollbackRate() { function rollbackRate() {
self.policy.rate = oldRate; self.policy.rate = oldRate;
} }
let oldBill = staticValues.policy.bill; let oldBill = staticValues.policy.bill;
async function setBill() { async function setBill() {
const bill = self.policy.bill; const bill = self.policy.bill;
try { try {
await SammoAPI.Nation.SetBill({ amount: bill }); await SammoAPI.Nation.SetBill({ amount: bill });
@@ -465,13 +475,13 @@ export default defineComponent({
} }
console.error(e); console.error(e);
} }
} }
function rollbackBill() { function rollbackBill() {
self.policy.bill = oldBill; self.policy.bill = oldBill;
} }
let oldSecretLimit = staticValues.policy.secretLimit; let oldSecretLimit = staticValues.policy.secretLimit;
async function setSecretLimit() { async function setSecretLimit() {
const secretLimit = self.policy.secretLimit; const secretLimit = self.policy.secretLimit;
try { try {
await SammoAPI.Nation.SetSecretLimit({ amount: secretLimit }); await SammoAPI.Nation.SetSecretLimit({ amount: secretLimit });
@@ -490,12 +500,12 @@ export default defineComponent({
self.policy.secretLimit = oldSecretLimit; self.policy.secretLimit = oldSecretLimit;
console.error(e); console.error(e);
} }
} }
function rollbackSecretLimit() { function rollbackSecretLimit() {
self.policy.secretLimit = oldSecretLimit; self.policy.secretLimit = oldSecretLimit;
} }
async function setBlockWar() { async function setBlockWar() {
try { try {
const result = await SammoAPI.Nation.SetBlockWar({ value: self.policy.blockWar }); const result = await SammoAPI.Nation.SetBlockWar({ value: self.policy.blockWar });
self.warSettingCnt.remain = result.availableCnt; self.warSettingCnt.remain = result.availableCnt;
@@ -513,9 +523,9 @@ export default defineComponent({
self.policy.blockWar = !self.policy.blockWar; self.policy.blockWar = !self.policy.blockWar;
console.error(e); console.error(e);
} }
} }
async function setBlockScout() { async function setBlockScout() {
try { try {
await SammoAPI.Nation.SetBlockScout({ value: self.policy.blockScout }); await SammoAPI.Nation.SetBlockScout({ value: self.policy.blockScout });
toasts.info({ toasts.info({
@@ -532,45 +542,6 @@ export default defineComponent({
self.policy.blockScout = !self.policy.blockScout; self.policy.blockScout = !self.policy.blockScout;
console.error(e); console.error(e);
} }
} }
return {
toasts,
...toRefs(self),
inEditNationMsg,
inEditScoutMsg,
enableEditNationMsg,
rollbackNationMsg,
saveNationMsg,
enableEditScoutMsg,
rollbackScoutMsg,
saveScoutMsg,
diplomacyStateInfo,
joinYearMonth,
parseYearMonth,
trackNationMsgHeight: trackTiptapFormHeight("#noticeForm"),
trackScoutMsgHeight: trackTiptapFormHeight("#scoutMsgForm"),
incomeGoldCity,
incomeGold,
incomeRiceCity,
incomeRiceWall,
incomeRice,
outcomeByBill,
setRate,
rollbackRate,
setBill,
rollbackBill,
setSecretLimit,
rollbackSecretLimit,
setBlockWar,
setBlockScout,
};
},
methods: {},
});
</script> </script>
+18 -21
View File
@@ -13,9 +13,9 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
/// https://github.com/andi23rosca/drag-select-vue/blob/master/src/DragSelect.vue /// https://github.com/andi23rosca/drag-select-vue/blob/master/src/DragSelect.vue
import { defineComponent, ref, watch, onMounted, onBeforeUnmount, type PropType } from "vue"; import { ref, watch, onMounted, onBeforeUnmount, type PropType } from "vue";
import VueTypes from "vue-types"; import VueTypes from "vue-types";
function getDimensions(p1: coord, p2: coord): rect { function getDimensions(p1: coord, p2: coord): rect {
@@ -36,8 +36,7 @@ function collisionCheck(node1: DOMRect, node2: DOMRect): boolean {
type coord = { x: number; y: number }; type coord = { x: number; y: number };
type rect = { width: number; height: number }; type rect = { width: number; height: number };
export default defineComponent({ const props = defineProps({
props: {
attribute: VueTypes.string.isRequired, attribute: VueTypes.string.isRequired,
color: VueTypes.string.def("#4299E1"), color: VueTypes.string.def("#4299E1"),
opacity: VueTypes.number.def(0.7), opacity: VueTypes.number.def(0.7),
@@ -51,23 +50,28 @@ export default defineComponent({
required: false, required: false,
default: false, default: false,
}, },
}, });
emits: ["update:modelValue", "dragDone", "dragStart"],
setup(props, { emit }) {
const intersected = ref<Set<string>>(props.modelValue);
const container = ref<HTMLElement>();
watch(intersected, (val) => { const emit = defineEmits<{
(event: "update:modelValue", value: Set<string>): void;
(event: "dragDone", value: Set<string>): void;
(event: "dragStart"): void;
}>();
const intersected = ref<Set<string>>(props.modelValue);
const container = ref<HTMLElement>();
watch(intersected, (val) => {
emit("update:modelValue", val); emit("update:modelValue", val);
}); });
watch(props.modelValue, (val) => { watch(props.modelValue, (val) => {
if (intersected.value === val) { if (intersected.value === val) {
return; return;
} }
intersected.value = val; intersected.value = val;
}); });
onMounted(() => { onMounted(() => {
if (!container.value) { if (!container.value) {
console.error(`Container is not referenced.`); console.error(`Container is not referenced.`);
return; return;
@@ -210,12 +214,5 @@ export default defineComponent({
document.removeEventListener("mouseup", endDrag); document.removeEventListener("mouseup", endDrag);
document.removeEventListener("touchend", endDrag); document.removeEventListener("touchend", endDrag);
}); });
});
return {
intersected,
container,
};
},
}); });
</script> </script>
+12 -14
View File
@@ -5,17 +5,16 @@
<template v-if="key !== 0"> , </template> <template v-if="key !== 0"> , </template>
<a <a
:style="{ color: colorMap[distance as keyof typeof colorMap] ?? undefined, textDecoration:'underline' }" :style="{ color: colorMap[distance as keyof typeof colorMap] ?? undefined, textDecoration:'underline' }"
@click="$emit('selected', cityID)" @click="emit('selected', cityID)"
>{{ citiesMap.get(cityID)?.name }}</a >{{ citiesMap.get(cityID)?.name }}</a
> >
</template> </template>
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent, type PropType } from "vue"; import type { PropType } from "vue";
export default defineComponent({ defineProps({
props: {
distanceList: { distanceList: {
type: Object as PropType<Record<number, number[]>>, type: Object as PropType<Record<number, number[]>>,
required: true, required: true,
@@ -24,16 +23,15 @@ export default defineComponent({
type: Object as PropType<Map<number, { name: string }>>, type: Object as PropType<Map<number, { name: string }>>,
required: true, required: true,
}, },
}, });
emits: ["selected"],
data() { const emit = defineEmits<{
return { (event: "selected", value: number): void;
colorMap: { }>();
const colorMap = {
1: "magenta", 1: "magenta",
2: "orange", 2: "orange",
3: "yellow", 3: "yellow",
}, };
};
},
});
</script> </script>
+26 -30
View File
@@ -56,57 +56,53 @@
<div class="crewTypeInfo text-start" v-html="crewType.info.join('<br>')" /> <div class="crewTypeInfo text-start" v-html="crewType.info.join('<br>')" />
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent, ref } from "vue"; import { onMounted, ref, watch } from "vue";
import VueTypes from "vue-types"; import VueTypes from "vue-types";
export default defineComponent({ const props = defineProps({
props: {
crewType: VueTypes.object.isRequired, crewType: VueTypes.object.isRequired,
leadership: VueTypes.number.isRequired, leadership: VueTypes.number.isRequired,
commandName: VueTypes.string.isRequired, commandName: VueTypes.string.isRequired,
currentCrewType: VueTypes.number.def(-1), currentCrewType: VueTypes.number.def(-1),
crew: VueTypes.number.def(0), crew: VueTypes.number.def(0),
goldCoeff: VueTypes.number.isRequired, goldCoeff: VueTypes.number.isRequired,
}, });
emits: ["submitOutput", "update:amount"],
setup(props, { emit }) {
const amount = ref(0);
function beHalf() { const emit = defineEmits<{
(event: "submitOutput", e: Event, amount: number, crewtypeID: number): void;
(event: "update:amount", value: number): void;
}>();
const amount = ref(0);
function beHalf() {
amount.value = Math.ceil(props.leadership * 0.5); amount.value = Math.ceil(props.leadership * 0.5);
} }
function beFilled() { function beFilled() {
if (props.crewType.id == props.currentCrewType) { if (props.crewType.id == props.currentCrewType) {
amount.value = Math.max(1, props.leadership - Math.floor(props.crew / 100)); amount.value = Math.max(1, props.leadership - Math.floor(props.crew / 100));
} else { } else {
amount.value = props.leadership; amount.value = props.leadership;
} }
} }
function beFull() { function beFull() {
amount.value = Math.floor(props.leadership * 1.2); amount.value = Math.floor(props.leadership * 1.2);
} }
function doSubmit(e: Event) { function doSubmit(e: Event) {
emit("submitOutput", e, amount.value, props.crewType.id); emit("submitOutput", e, amount.value, props.crewType.id);
} }
onMounted(() => {
beFilled(); beFilled();
return {
amount,
beHalf,
beFilled,
beFull,
doSubmit,
};
},
watch: {
amount(val: number) {
this.$emit("update:amount", val);
},
},
}); });
watch(amount, (value) => {
emit("update:amount", value);
});
</script> </script>
+55 -100
View File
@@ -1,20 +1,12 @@
<template> <template>
<TopBackBar <TopBackBar v-model:searchable="searchable" :title="commandName" :type="procEntryMode" />
v-model:searchable="searchable"
:title="commandName"
:type="procEntryMode"
/>
<div class="bg0"> <div class="bg0">
<div v-if="commandName == '몰수'"> <div v-if="commandName == '몰수'">
장수의 자금이나 군량을 몰수합니다.<br> 장수의 자금이나 군량을 몰수합니다.<br />
몰수한것은 국가재산으로 귀속됩니다.<br> 몰수한것은 국가재산으로 귀속됩니다.<br />
</div>
<div v-else-if="commandName == '포상'">
국고로 장수에게 자금이나 군량을 지급합니다.<br>
</div>
<div v-else-if="commandName == '증여'">
자신의 자금이나 군량을 다른 장수에게 증여합니다.<br>
</div> </div>
<div v-else-if="commandName == '포상'">국고로 장수에게 자금이나 군량을 지급합니다.<br /></div>
<div v-else-if="commandName == '증여'">자신의 자금이나 군량을 다른 장수에게 증여합니다.<br /></div>
<div class="row"> <div class="row">
<div class="col-12 col-md-5"> <div class="col-12 col-md-5">
장수 : 장수 :
@@ -29,49 +21,44 @@
<div class="col-2 col-md-1"> <div class="col-2 col-md-1">
자원 : 자원 :
<b-button-group> <b-button-group>
<b-button <b-button :pressed="isGold" @click="isGold = true"> </b-button>
:pressed="isGold" <b-button :pressed="!isGold" @click="isGold = false"> </b-button>
@click="isGold=true"
>
</b-button>
<b-button
:pressed="!isGold"
@click="isGold=false"
>
</b-button>
</b-button-group> </b-button-group>
</div> </div>
<div class="col-7 col-md-4"> <div class="col-7 col-md-4">
금액 : 금액 :
<SelectAmount <SelectAmount v-model="amount" :amountGuide="amountGuide" :maxAmount="maxAmount" :minAmount="minAmount" />
v-model="amount"
:amountGuide="amountGuide"
:maxAmount="maxAmount"
:minAmount="minAmount"
/>
</div> </div>
<div class="col-3 col-md-2 d-grid"> <div class="col-3 col-md-2 d-grid">
<b-button <b-button variant="primary" @click="submit">
variant="primary"
@click="submit"
>
{{ commandName }} {{ commandName }}
</b-button> </b-button>
</div> </div>
</div> </div>
</div> </div>
<BottomBar <BottomBar :title="commandName" :type="procEntryMode" />
:title="commandName"
:type="procEntryMode"
/>
</template> </template>
<script lang="ts"> <script lang="ts">
declare const procRes: {
distanceList: Record<number, number[]>;
cities: [number, string][];
generals: procGeneralRawItemList;
generalsKey: procGeneralKey[];
minAmount: number;
maxAmount: number;
amountGuide: number[];
};
declare const staticValues: {
commandName: string;
entryInfo: ["General" | "Nation", unknown];
};
</script>
<script setup lang="ts">
import SelectGeneral from "@/processing/SelectGeneral.vue"; import SelectGeneral from "@/processing/SelectGeneral.vue";
import SelectAmount from "@/processing/SelectAmount.vue"; import SelectAmount from "@/processing/SelectAmount.vue";
import { defineComponent, ref } from "vue"; import { ref } from "vue";
import { unwrap } from "@/util/unwrap"; import { unwrap } from "@/util/unwrap";
import type { Args } from "@/processing/args"; import type { Args } from "@/processing/args";
import TopBackBar from "@/components/TopBackBar.vue"; import TopBackBar from "@/components/TopBackBar.vue";
@@ -84,58 +71,33 @@ import {
type procGeneralRawItemList, type procGeneralRawItemList,
} from "./processingRes"; } from "./processingRes";
import { getNpcColor } from "@/common_legacy"; import { getNpcColor } from "@/common_legacy";
declare const commandName: string;
declare const entryInfo: ['General'|'Nation', unknown];
declare const procRes: { const citiesMap = ref(new Map<
distanceList: Record<number, number[]>;
cities: [number, string][];
generals: procGeneralRawItemList;
generalsKey: procGeneralKey[];
minAmount: number;
maxAmount: number;
amountGuide: number[];
};
export default defineComponent({
components: {
SelectGeneral,
SelectAmount,
TopBackBar,
BottomBar,
},
setup() {
const citiesMap = new Map<
number, number,
{ {
name: string; name: string;
info?: string; info?: string;
} }
>(); >());
for (const [id, name] of procRes.cities) { for (const [id, name] of procRes.cities) {
citiesMap.set(id, { name }); citiesMap.value.set(id, { name });
} }
const generalList = convertGeneralList( const generalList = convertGeneralList(procRes.generalsKey, procRes.generals);
procRes.generalsKey, const amount = ref(1000);
procRes.generals const isGold = ref(true);
);
const amount = ref(1000);
const isGold = ref(true);
const selectedGeneralID = ref(generalList[0].no); const selectedGeneralID = ref(generalList[0].no);
function textHelpGeneral(gen: procGeneralItem): string { function textHelpGeneral(gen: procGeneralItem): string {
const nameColor = getNpcColor(gen.npc); const nameColor = getNpcColor(gen.npc);
const name = nameColor const name = nameColor ? `<span style="color:${nameColor}">${gen.name}</span>` : gen.name;
? `<span style="color:${nameColor}">${gen.name}</span>` return `${name} (금${unwrap(gen.gold).toLocaleString()}/쌀${unwrap(gen.rice).toLocaleString()}) (${gen.leadership}/${
: gen.name; gen.strength
return `${name} (금${unwrap(gen.gold).toLocaleString()}/${unwrap(gen.rice).toLocaleString()}) (${ }/${gen.intel})`;
gen.leadership }
}/${gen.strength}/${gen.intel})`;
}
async function submit(e: Event) { async function submit(e: Event) {
const event = new CustomEvent<Args>("customSubmit", { const event = new CustomEvent<Args>("customSubmit", {
detail: { detail: {
amount: amount.value, amount: amount.value,
@@ -144,24 +106,17 @@ export default defineComponent({
}, },
}); });
unwrap(e.target).dispatchEvent(event); unwrap(e.target).dispatchEvent(event);
} }
const { commandName,entryInfo } = staticValues;
const searchable = getProcSearchable();
const procEntryMode: "chief" | "normal" = entryInfo[0] == "Nation" ? "chief" : "normal";
const {
minAmount,
maxAmount,
amountGuide
} = procRes;
return {
procEntryMode: <'chief'|'normal'>(entryInfo[0] == 'Nation'?'chief':'normal'),
searchable: getProcSearchable(),
amount,
isGold,
selectedGeneralID,
citiesMap: ref(citiesMap),
distanceList: procRes.distanceList,
minAmount: ref(procRes.minAmount),
maxAmount: ref(procRes.maxAmount),
amountGuide: procRes.amountGuide,
generalList,
commandName,
textHelpGeneral,
submit,
};
},
});
</script> </script>
+20 -16
View File
@@ -32,29 +32,33 @@
</b-button> </b-button>
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent } from "vue"; import { ref, watch } from "vue";
import VueTypes from "vue-types"; import VueTypes from "vue-types";
export default defineComponent({ const props = defineProps({
props: {
modelValue: VueTypes.number.isRequired, modelValue: VueTypes.number.isRequired,
minAmount: VueTypes.number.isRequired, minAmount: VueTypes.number.isRequired,
maxAmount: VueTypes.number.isRequired, maxAmount: VueTypes.number.isRequired,
amountGuide: VueTypes.arrayOf(Number).def([1000, 2000, 5000, 10000]), amountGuide: VueTypes.arrayOf(Number).def([1000, 2000, 5000, 10000]),
step: VueTypes.number.def(1), step: VueTypes.number.def(1),
}, });
emits: ["update:modelValue"],
data() { const emit = defineEmits<{
return { (event: "update:modelValue", value: number): void;
amount: this.modelValue, }>();
};
}, const amount = ref(props.modelValue);
watch: {
amount(val: number) { watch(
this.$emit("update:modelValue", val); () => props.modelValue,
}, (value) => {
}, amount.value = value;
}
);
watch(amount, (value) => {
emit("update:modelValue", value);
}); });
</script> </script>