2021-04-23 06:01:52 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="_formRoot">
|
|
|
|
<FormSuspense :p="init">
|
|
|
|
<FormButton primary @click="addAccount"
|
|
|
|
><i class="ph-plus ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.addAccount }}</FormButton
|
|
|
|
>
|
|
|
|
|
2023-04-29 03:49:41 +02:00
|
|
|
<button
|
2023-04-08 02:01:42 +02:00
|
|
|
v-for="account in accounts"
|
|
|
|
:key="account.id"
|
|
|
|
class="_panel _button lcjjdxlm"
|
|
|
|
@click="menu(account, $event)"
|
|
|
|
>
|
|
|
|
<div class="avatar">
|
2023-04-29 03:49:41 +02:00
|
|
|
<MkAvatar :user="account" class="avatar" disableLink />
|
2021-04-23 06:01:52 +02:00
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="body">
|
|
|
|
<div class="name">
|
|
|
|
<MkUserName :user="account" />
|
|
|
|
</div>
|
|
|
|
<div class="acct">
|
|
|
|
<MkAcct :user="account" />
|
|
|
|
</div>
|
2021-04-23 06:01:52 +02:00
|
|
|
</div>
|
2023-04-29 03:49:41 +02:00
|
|
|
</button>
|
2023-04-08 02:01:42 +02:00
|
|
|
</FormSuspense>
|
|
|
|
</div>
|
2021-04-23 06:01:52 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { defineAsyncComponent, ref } from "vue";
|
|
|
|
import FormSuspense from "@/components/form/suspense.vue";
|
|
|
|
import FormButton from "@/components/MkButton.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import {
|
|
|
|
getAccounts,
|
|
|
|
addAccount as addAccounts,
|
|
|
|
removeAccount as _removeAccount,
|
|
|
|
login,
|
|
|
|
$i,
|
|
|
|
} from "@/account";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
const storedAccounts = ref<any>(null);
|
|
|
|
const accounts = ref<any>(null);
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
const init = async () => {
|
2023-04-08 02:01:42 +02:00
|
|
|
getAccounts()
|
|
|
|
.then((accounts) => {
|
|
|
|
storedAccounts.value = accounts.filter((x) => x.id !== $i!.id);
|
|
|
|
|
|
|
|
console.log(storedAccounts.value);
|
|
|
|
|
|
|
|
return os.api("users/show", {
|
|
|
|
userIds: storedAccounts.value.map((x) => x.id),
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
accounts.value = response;
|
|
|
|
console.log(accounts.value);
|
2022-05-03 13:33:40 +02:00
|
|
|
});
|
2022-06-10 07:36:55 +02:00
|
|
|
};
|
2022-05-03 13:33:40 +02:00
|
|
|
|
|
|
|
function menu(account, ev) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popupMenu(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: i18n.ts.switch,
|
|
|
|
icon: "ph-swap ph-bold ph-lg",
|
|
|
|
action: () => switchAccount(account),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: i18n.ts.remove,
|
|
|
|
icon: "ph-trash ph-bold ph-lg",
|
|
|
|
danger: true,
|
|
|
|
action: () => removeAccount(account),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ev.currentTarget ?? ev.target
|
|
|
|
);
|
2022-05-03 13:33:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addAccount(ev) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popupMenu(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: i18n.ts.existingAccount,
|
|
|
|
action: () => {
|
|
|
|
addExistingAccount();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: i18n.ts.createAccount,
|
|
|
|
action: () => {
|
|
|
|
createAccount();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ev.currentTarget ?? ev.target
|
|
|
|
);
|
2022-05-03 13:33:40 +02:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
function removeAccount(account) {
|
|
|
|
_removeAccount(account.id);
|
|
|
|
}
|
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
function addExistingAccount() {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(() => import("@/components/MkSigninDialog.vue")),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
done: (res) => {
|
|
|
|
addAccounts(res.id, res.i);
|
|
|
|
os.success();
|
|
|
|
},
|
2021-04-23 06:01:52 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
"closed"
|
|
|
|
);
|
2022-05-03 13:33:40 +02:00
|
|
|
}
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
function createAccount() {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(() => import("@/components/MkSignupDialog.vue")),
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
done: (res) => {
|
|
|
|
addAccounts(res.id, res.i);
|
|
|
|
switchAccountWithToken(res.i);
|
|
|
|
},
|
2021-04-23 06:01:52 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
"closed"
|
|
|
|
);
|
2022-05-03 13:33:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function switchAccount(account: any) {
|
|
|
|
const fetchedAccounts: any[] = await getAccounts();
|
2023-04-08 02:01:42 +02:00
|
|
|
const token = fetchedAccounts.find((x) => x.id === account.id).token;
|
2022-05-03 13:33:40 +02:00
|
|
|
switchAccountWithToken(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchAccountWithToken(token: string) {
|
|
|
|
login(token);
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.accounts,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-users ph-bold ph-lg",
|
2021-04-23 06:01:52 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.lcjjdxlm {
|
|
|
|
display: flex;
|
|
|
|
padding: 16px;
|
2023-04-29 03:49:41 +02:00
|
|
|
width: 100%;
|
|
|
|
text-align: unset;
|
2021-04-23 06:01:52 +02:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
display: block;
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin: 0 12px 0 0;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
width: calc(100% - 62px);
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|