feat: 추방 기능 추가
This commit is contained in:
+122
-24
@@ -42,7 +42,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="troopAction">
|
||||
<div v-if="tryChangeTroopTarget != troop.troopID" class="d-grid">
|
||||
<div
|
||||
v-if="tryTroopActionTarget.type === undefined || tryTroopActionTarget.targetTroop !== troop.troopID"
|
||||
class="d-grid"
|
||||
>
|
||||
<BButton v-if="!me.troop" variant="primary" @click="joinTroop(troop.troopID)">부대 탑승</BButton>
|
||||
<BButton
|
||||
v-if="me.troop == troop.troopID"
|
||||
@@ -50,26 +53,48 @@
|
||||
@click="exitTroop()"
|
||||
>{{ me.no == me.troop ? "부대 해산" : "부대 탈퇴" }}</BButton
|
||||
>
|
||||
<BButton v-if="me.troop == troop.troopID && me.no == me.troop">부대원 추방...</BButton>
|
||||
<BButton
|
||||
v-if="me.troop == troop.troopID && me.no == me.troop"
|
||||
@click="openKickTroopMemberDialog(troop)"
|
||||
>부대원 추방...</BButton
|
||||
>
|
||||
<BButton variant="info" @click="openChangeTroopNameDialog(troop)"
|
||||
>부대명 변경...</BButton
|
||||
>
|
||||
</div>
|
||||
<div class="row gx-0">
|
||||
<template v-if="tryChangeTroopTarget == troop.troopID">
|
||||
<div class="col-12 bg1 center" style="padding:0.2em;">부대명 변경</div>
|
||||
<div class="col-12 d-grid">
|
||||
<BFormInput v-model="newTroopName" :trim="true" type="text" />
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="tryChangeTroopTarget != troop.troopID" class="col-12 d-grid">
|
||||
<BButton variant="info" @click="tryChangeTroopTarget = troop.troopID">부대명 변경</BButton>
|
||||
<div v-else-if="tryTroopActionTarget.type === 'changeName'" class="row gx-0">
|
||||
<div class="col-12 bg1 center" style="padding: 0.2em">부대명 변경</div>
|
||||
<div class="col-12 d-grid">
|
||||
<BFormInput v-model="newTroopName" :trim="true" type="text" />
|
||||
</div>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="secondary" @click="tryTroopActionTarget = { type: undefined, targetTroop: 0 }"
|
||||
>취소</BButton
|
||||
>
|
||||
</div>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="primary" @click="changeTroopName(troop)">변경</BButton>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="tryTroopActionTarget.type === 'kickMember'" class="row gx-0">
|
||||
<div class="col-12 bg1 center" style="padding: 0.2em">부대명 추방</div>
|
||||
<div class="col-12 d-grid">
|
||||
<BFormSelect v-model="kickTroopMemberID">
|
||||
<template v-for="member of troop.members" :key="member.no">
|
||||
<BFormSelectOption v-if="member.no != troop.troopID" :value="member.no">
|
||||
{{ member.name }}
|
||||
</BFormSelectOption>
|
||||
</template>
|
||||
</BFormSelect>
|
||||
</div>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="secondary" @click="tryTroopActionTarget = { type: undefined, targetTroop: 0 }"
|
||||
>취소</BButton
|
||||
>
|
||||
</div>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="primary" @click="kickTroopMember(troop)">추방</BButton>
|
||||
</div>
|
||||
<template v-else>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="secondary" @click="tryChangeTroopTarget = 0">취소</BButton>
|
||||
</div>
|
||||
<div class="col-6 d-grid">
|
||||
<BButton variant="primary" @click="changeTroopName()">변경</BButton>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -113,7 +138,7 @@ import TopBackBar from "@/components/TopBackBar.vue";
|
||||
import BottomBar from "@/components/BottomBar.vue";
|
||||
import { onMounted, provide, ref } from "vue";
|
||||
import { SammoAPI } from "./SammoAPI";
|
||||
import { BContainer, BButton, useToast, BFormInput } from "bootstrap-vue-3";
|
||||
import { BContainer, BButton, useToast, BFormInput, BFormSelect, BFormSelectOption } from "bootstrap-vue-3";
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { isString } from "lodash";
|
||||
import type { GeneralListItem, GeneralListItemP1 } from "./defs/API/Nation";
|
||||
@@ -201,8 +226,18 @@ const troopList = ref(new Map<number, TroopInfo>());
|
||||
const generalList = ref(new Map<number, GeneralListItem>());
|
||||
const nationInfo = ref<NationStaticItem>();
|
||||
|
||||
const tryChangeTroopTarget = ref(0);
|
||||
const newTroopName = ref("");
|
||||
const kickTroopMemberID = ref(0);
|
||||
|
||||
type TroopAction = {
|
||||
type: "kickMember" | "changeName" | undefined;
|
||||
targetTroop: number;
|
||||
};
|
||||
|
||||
const tryTroopActionTarget = ref<TroopAction>({
|
||||
type: undefined,
|
||||
targetTroop: 0,
|
||||
});
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
@@ -375,10 +410,18 @@ async function exitTroop() {
|
||||
await refresh();
|
||||
}
|
||||
|
||||
async function changeTroopName() {
|
||||
const troopID = tryChangeTroopTarget.value;
|
||||
function openChangeTroopNameDialog(troop: TroopInfo){
|
||||
tryTroopActionTarget.value = {
|
||||
type: 'changeName',
|
||||
targetTroop: troop.troopID
|
||||
}
|
||||
newTroopName.value = troop.troopName;
|
||||
}
|
||||
|
||||
async function changeTroopName(troop: TroopInfo) {
|
||||
const troopID = troop.troopID;
|
||||
const troopName = newTroopName.value;
|
||||
const oldTroopName = troopList.value.get(troopID)?.troopName ?? "??";
|
||||
const oldTroopName = troop.troopName;
|
||||
const josaRo = pick(troopName, "로");
|
||||
if (!confirm(`${oldTroopName} 부대의 이름을 ${troopName}${josaRo} 바꾸시겠습니까?`)) {
|
||||
return;
|
||||
@@ -404,6 +447,61 @@ async function changeTroopName() {
|
||||
}
|
||||
await refresh();
|
||||
}
|
||||
|
||||
|
||||
function openKickTroopMemberDialog(troop: TroopInfo){
|
||||
tryTroopActionTarget.value = {
|
||||
type: 'kickMember',
|
||||
targetTroop: troop.troopID
|
||||
}
|
||||
for(const member of troop.members){
|
||||
if(member.no == troop.troopID){
|
||||
continue;
|
||||
}
|
||||
kickTroopMemberID.value = member.no;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function kickTroopMember(troop: TroopInfo) {
|
||||
const kickMember = generalList.value.get(kickTroopMemberID.value);
|
||||
if(kickMember === undefined){
|
||||
toasts.danger({
|
||||
title: "오류",
|
||||
body: "잘못된 접근입니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const troopID = troop.troopID;
|
||||
const troopName = troop.troopName;
|
||||
|
||||
const generalID = kickMember.no;
|
||||
const generalName = kickMember.name;
|
||||
const josaUl = pick(generalName, "을");
|
||||
if (!confirm(`${troopName} 부대에서 ${generalName}${josaUl} 추방하시겠습니까?`)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await SammoAPI.Troop.KickFromTroop({
|
||||
troopID,
|
||||
generalID,
|
||||
});
|
||||
|
||||
toasts.info({
|
||||
title: "완료",
|
||||
body: `${generalName}${josaUl} 추방했습니다.`,
|
||||
});
|
||||
} catch (e) {
|
||||
if (isString(e)) {
|
||||
toasts.danger({
|
||||
title: "오류",
|
||||
body: e,
|
||||
});
|
||||
}
|
||||
console.error(e);
|
||||
}
|
||||
await refresh();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user