feat: 부대장인 경우 부대이름으로 검색 가능

This commit is contained in:
2022-07-10 21:52:54 +09:00
parent 50b1db75f0
commit 3da0a7d950
+100 -73
View File
@@ -19,32 +19,32 @@
:maxHeight="400" :maxHeight="400"
:searchable="searchable" :searchable="searchable"
> >
<template #option="props"> <template #option="prop">
<!-- eslint-disable-next-line vue/no-v-html --> <!-- eslint-disable-next-line vue/no-v-html -->
<div v-if="props.option.title" v-html="props.option.title" /> <div v-if="prop.option.title" v-html="prop.option.title" />
<div <div
v-if="props.option.$groupLabel !== undefined" v-if="prop.option.$groupLabel !== undefined"
class="margin-filler" class="margin-filler"
:style="{ :style="{
backgroundColor: groupByNation?.get(props.option.$groupLabel)?.color, backgroundColor: groupByNation?.get(prop.option.$groupLabel)?.color,
color: isBrightColor(groupByNation?.get(props.option.$groupLabel)?.color ?? '#ffffff') ? 'black' : 'white', color: isBrightColor(groupByNation?.get(prop.option.$groupLabel)?.color ?? '#ffffff') ? 'black' : 'white',
}" }"
> >
{{ groupByNation?.get(props.option.$groupLabel)?.name }} {{ groupByNation?.get(prop.option.$groupLabel)?.name }}
</div> </div>
</template> </template>
<template #singleLabel="props"> <template #singleLabel="prop">
{{ props.option.simpleName }} {{ prop.option.simpleName }}
{{ groupByNation ? `[${groupByNation.get(props.option.obj.nationID)?.name}]` : undefined }} {{ groupByNation ? `[${groupByNation.get(prop.option.obj.nationID)?.name}]` : undefined }}
</template> </template>
</v-multiselect> </v-multiselect>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { getNpcColor } from "@/common_legacy"; import { getNpcColor } from "@/common_legacy";
import { convertSearch초성 } from "@/util/convertSearch초성"; import { convertSearch초성 } from "@/util/convertSearch초성";
import { isBrightColor } from "@/util/isBrightColor"; import { isBrightColor } from "@/util/isBrightColor";
import { unwrap } from "@/util/unwrap"; import { unwrap } from "@/util/unwrap";
import { defineComponent, type PropType } from "vue"; import { ref, watch, type PropType } from "vue";
import VueTypes from "vue-types"; import VueTypes from "vue-types";
import type { procGeneralItem, procGeneralList, procNationItem } from "./processingRes"; import type { procGeneralItem, procGeneralList, procNationItem } from "./processingRes";
@@ -56,95 +56,122 @@ type SelectedGeneral = {
obj: procGeneralItem; obj: procGeneralItem;
}; };
export default defineComponent({ const props = defineProps({
props: { modelValue: VueTypes.number.isRequired,
modelValue: VueTypes.number.isRequired, generals: {
generals: { type: Array as PropType<procGeneralList>,
type: Array as PropType<procGeneralList>, required: true,
required: true,
},
textHelper: {
type: Function as PropType<(item: procGeneralItem) => string>,
required: false,
default: undefined,
},
groupByNation: {
type: Map as PropType<Map<number, procNationItem>>,
required: false,
default: undefined,
},
searchable: {
type: Boolean,
required: false,
default: true,
},
}, },
emits: ["update:modelValue"], textHelper: {
data() { type: Function as PropType<(item: procGeneralItem) => string>,
const forFind: ( required: false,
| SelectedGeneral default: undefined,
| { },
values: SelectedGeneral[]; groupByNation: {
nationID: number; type: Map as PropType<Map<number, procNationItem>>,
} required: false,
)[] = []; default: undefined,
const forFindGroup = new Map<number, SelectedGeneral[]>(); },
const targets = new Map<number, SelectedGeneral>(); searchable: {
type: Boolean,
required: false,
default: true,
},
troops: {
type: Object as PropType<Record<number, { troop_leader: number; nation: number; name: string }>>,
required: false,
default: undefined,
},
});
let selectedGeneral; const emit = defineEmits<{
(event: "update:modelValue", value: number): void;
}>();
for (const gen of this.generals) { const selectedGeneral = ref<SelectedGeneral>();
let groupArray = forFind; const targets = new Map<number, SelectedGeneral>();
if (this.groupByNation) {
watch(
() => props.modelValue,
(val) => {
const target = targets.get(val);
selectedGeneral.value = target;
}
);
watch(selectedGeneral, (val) => {
if (val === undefined) {
return;
}
emit("update:modelValue", val.value);
});
const forFind = ref<
(
| SelectedGeneral
| {
values: SelectedGeneral[];
nationID: number;
}
)[]
>([]);
const forFindGroup = ref(new Map<number, SelectedGeneral[]>());
watch(
() => props.generals,
(generals) => {
const tmpFind: typeof forFind["value"] = [];
const tmpFindGroup = new Map<number, SelectedGeneral[]>();
for (const gen of generals) {
let groupArray = tmpFind;
if (props.groupByNation) {
const nationID = gen.nationID ?? 0; const nationID = gen.nationID ?? 0;
if (!forFindGroup.has(nationID)) { if (!tmpFindGroup.has(nationID)) {
const nationItem = unwrap(this.groupByNation.get(nationID)); const nationItem = unwrap(props.groupByNation.get(nationID));
let tmpArr: SelectedGeneral[] = []; let tmpArr: SelectedGeneral[] = [];
forFindGroup.set(nationID, tmpArr); tmpFindGroup.set(nationID, tmpArr);
groupArray = tmpArr; groupArray = tmpArr;
forFind.push({ tmpFind.push({
nationID: nationItem.id, nationID: nationItem.id,
values: tmpArr, values: tmpArr,
}); });
} else { } else {
groupArray = unwrap(forFindGroup.get(nationID)); groupArray = unwrap(tmpFindGroup.get(nationID));
} }
} }
const nameColor = getNpcColor(gen.npc); const nameColor = getNpcColor(gen.npc);
const name = nameColor ? `<span style="color:${nameColor}">${gen.name}</span>` : gen.name; const name = nameColor ? `<span style="color:${nameColor}">${gen.name}</span>` : gen.name;
const searchText = convertSearch초성(gen.name);
if (gen.no == gen.troopID && props.troops !== undefined && gen.no in props.troops) {
const troopName = props.troops[gen.no].name;
console.log(troopName);
searchText.push(...convertSearch초성(troopName));
}
const obj: SelectedGeneral = { const obj: SelectedGeneral = {
value: gen.no, value: gen.no,
title: this.textHelper ? this.textHelper(gen) : `${name} (${gen.leadership}/${gen.strength}/${gen.intel})`, title: props.textHelper ? props.textHelper(gen) : `${name} (${gen.leadership}/${gen.strength}/${gen.intel})`,
simpleName: gen.name, simpleName: gen.name,
searchText: convertSearch초성(gen.name).join("|"), searchText: searchText.join("|"),
obj: gen, obj: gen,
}; };
if (gen.no == this.modelValue) { if (gen.no == props.modelValue) {
selectedGeneral = obj; selectedGeneral.value = obj;
} }
groupArray.push(obj); groupArray.push(obj);
targets.set(gen.no, obj); targets.set(gen.no, obj);
} }
return {
selectedGeneral, forFindGroup.value = tmpFindGroup;
forFind, forFind.value = tmpFind;
targets,
isBrightColor,
};
}, },
watch: { { immediate: true }
modelValue(val: number) { );
const target = this.targets.get(val);
this.selectedGeneral = target;
},
selectedGeneral(val: SelectedGeneral) {
this.$emit("update:modelValue", val.value);
},
},
});
</script> </script>
<style lang="scss"> <style lang="scss">
@import "@scss/common/break_500px.scss"; @import "@scss/common/break_500px.scss";