Skip to content

Commit

Permalink
feat(f): added a button to view guild info in the player list(and vic…
Browse files Browse the repository at this point in the history
…e versa) (#89)
  • Loading branch information
if1024 authored Feb 3, 2024
1 parent a95662d commit 0eaa96c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
26 changes: 18 additions & 8 deletions service/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,28 @@ func ListGuilds(db *bbolt.DB) ([]database.Guild, error) {
return guilds, nil
}

func GetGuild(db *bbolt.DB, adminPlayerUid string) (database.Guild, error) {
func GetGuild(db *bbolt.DB, playerUID string) (database.Guild, error) {
var guild database.Guild
err := db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte("guilds"))
v := b.Get([]byte(adminPlayerUid))
if v == nil {
return ErrNoRecord
}
if err := json.Unmarshal(v, &guild); err != nil {
return err

// 遍历bucket中的所有guild
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var g database.Guild
if err := json.Unmarshal(v, &g); err != nil {
return err
}

// 检查当前guild的players是否包含指定的player_uid
for _, player := range g.Players {
if player.PlayerUid == playerUID {
guild = g
return nil
}
}
}
return nil
return ErrNoRecord
})
if err != nil {
return database.Guild{}, err
Expand Down
4 changes: 4 additions & 0 deletions web/src/assets/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const messages = {
detail: "Detail",
confirm: "Confirm",
cancel: "Cancel",
viewGuild: "View Guild",
viewPlayer: "View Player",
},
pal: {
type: "Type",
Expand Down Expand Up @@ -121,6 +123,8 @@ const messages = {
detail: "详情",
confirm: "确认",
cancel: "取消",
viewGuild: "查看公会",
viewPlayer: "查看玩家",
},
pal: {
type: "类型",
Expand Down
47 changes: 41 additions & 6 deletions web/src/views/PcHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GroupWorkRound,
ContentCopyFilled,
SettingsPowerRound,
PersonSearchSharp
} from "@vicons/material";
import { GameController, LogOut, Ban, LanguageSharp } from "@vicons/ionicons5";
import { BroadcastTower } from "@vicons/fa";
Expand Down Expand Up @@ -102,11 +103,12 @@ const getPlayerList = async (is_update_info = true) => {
getPlayerInfo(playerList.value[0].player_uid);
}
};
const getGuildList = async () => {
const getGuildList = async (player_uid = '') => {
const { data } = await new ApiService().getGuildList();
guildList.value = data.value;
if (guildList.value.length > 0) {
getGuildInfo(guildList.value[0].admin_player_uid);
let uid = player_uid ? player_uid : guildList.value[0].admin_player_uid;
getGuildInfo(uid);
}
};
Expand Down Expand Up @@ -414,20 +416,27 @@ const handleShutdown = () => {
}
};
const toPlayers = async () => {
const toPlayers = async (uid = '') => {
if (currentDisplay.value === "players") {
return;
}
await getPlayerList();
currentDisplay.value = "players";
};
const toGuilds = async () => {
const toGuilds = async (uid = '') => {
if (currentDisplay.value === "guilds") {
return;
}
await getGuildList();
await getGuildList(uid);
currentDisplay.value = "guilds";
};
const guildToPlayers = async (uid) => {
if (currentDisplay.value === "players") {
return;
}
await getPlayerInfo(uid);
currentDisplay.value = "players";
};
/**
* check auth token
Expand Down Expand Up @@ -546,7 +555,7 @@ onMounted(async () => {
{{ $t("button.players") }}
</n-button>
<n-button
@click="toGuilds"
@click="toGuilds()"
:type="currentDisplay === 'guilds' ? 'primary' : 'tertiary'"
secondary
strong
Expand Down Expand Up @@ -725,6 +734,19 @@ onMounted(async () => {
<n-icon><ContentCopyFilled /></n-icon>
</template>
</n-button>
<n-button
@click="toGuilds(playerInfo.player_uid)"
class="ml-3"
size="small"
type="warning"
icon-placement="right"
ghost
>
{{ $t("button.viewGuild") }}
<template #icon>
<n-icon><PersonSearchSharp /></n-icon>
</template>
</n-button>
</template>
<template #avatar>
<n-avatar :src="getUserAvatar()" round></n-avatar>
Expand Down Expand Up @@ -940,6 +962,19 @@ onMounted(async () => {
>
{{ $t("status.master") }}
</n-tag>
<n-button
@click="guildToPlayers(player.player_uid)"
class="ml-3"
size="small"
type="warning"
icon-placement="right"
ghost
>
{{ $t("button.viewPlayer") }}
<template #icon>
<n-icon><PersonSearchSharp /></n-icon>
</template>
</n-button>
</n-space>
</n-list-item></n-list
>
Expand Down

0 comments on commit 0eaa96c

Please sign in to comment.