2021-04-23 13:01:52 +09:00
|
|
|
<template>
|
2022-01-04 18:21:00 +09:00
|
|
|
<div class="_formRoot">
|
2021-04-23 13:01:52 +09:00
|
|
|
<FormSuspense :p="init">
|
2022-12-19 13:53:41 +09:00
|
|
|
<FormButton primary @click="addAccount"><i class="ti ti-plus"></i> {{ i18n.ts.addAccount }}</FormButton>
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-01-04 18:21:00 +09:00
|
|
|
<div v-for="account in accounts" :key="account.id" class="_panel _button lcjjdxlm" @click="menu(account, $event)">
|
|
|
|
<div class="avatar">
|
|
|
|
<MkAvatar :user="account" class="avatar"/>
|
|
|
|
</div>
|
|
|
|
<div class="body">
|
|
|
|
<div class="name">
|
|
|
|
<MkUserName :user="account"/>
|
2021-04-23 13:01:52 +09:00
|
|
|
</div>
|
2022-01-04 18:21:00 +09:00
|
|
|
<div class="acct">
|
|
|
|
<MkAcct :user="account"/>
|
2021-04-23 13:01:52 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</FormSuspense>
|
2022-01-04 18:21:00 +09:00
|
|
|
</div>
|
2021-04-23 13:01:52 +09:00
|
|
|
</template>
|
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
<script lang="ts" setup>
|
2022-06-20 17:38:49 +09:00
|
|
|
import { defineAsyncComponent, ref } from 'vue';
|
2022-01-04 18:21:00 +09:00
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import FormButton from '@/components/MkButton.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { getAccounts, addAccount as addAccounts, removeAccount as _removeAccount, login, $i } from '@/account';
|
2022-05-03 20:33:40 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
const storedAccounts = ref<any>(null);
|
|
|
|
const accounts = ref<any>(null);
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
const init = async () => {
|
|
|
|
getAccounts().then(accounts => {
|
|
|
|
storedAccounts.value = accounts.filter(x => x.id !== $i!.id);
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
console.log(storedAccounts.value);
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
return os.api('users/show', {
|
2022-06-20 17:38:49 +09:00
|
|
|
userIds: storedAccounts.value.map(x => x.id),
|
2022-05-03 20:33:40 +09:00
|
|
|
});
|
|
|
|
}).then(response => {
|
|
|
|
accounts.value = response;
|
|
|
|
console.log(accounts.value);
|
|
|
|
});
|
2022-06-10 14:36:55 +09:00
|
|
|
};
|
2022-05-03 20:33:40 +09:00
|
|
|
|
|
|
|
function menu(account, ev) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.switch,
|
|
|
|
icon: 'fas fa-exchange-alt',
|
|
|
|
action: () => switchAccount(account),
|
|
|
|
}, {
|
|
|
|
text: i18n.ts.remove,
|
2022-12-19 13:53:41 +09:00
|
|
|
icon: 'ti ti-trash',
|
2022-05-03 20:33:40 +09:00
|
|
|
danger: true,
|
|
|
|
action: () => removeAccount(account),
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAccount(ev) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.existingAccount,
|
|
|
|
action: () => { addExistingAccount(); },
|
|
|
|
}, {
|
|
|
|
text: i18n.ts.createAccount,
|
|
|
|
action: () => { createAccount(); },
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
function removeAccount(account) {
|
|
|
|
_removeAccount(account.id);
|
|
|
|
}
|
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
function addExistingAccount() {
|
2022-08-31 00:24:33 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkSigninDialog.vue')), {}, {
|
2022-05-03 20:33:40 +09:00
|
|
|
done: res => {
|
|
|
|
addAccounts(res.id, res.i);
|
|
|
|
os.success();
|
2021-04-23 13:01:52 +09:00
|
|
|
},
|
2022-05-03 20:33:40 +09:00
|
|
|
}, 'closed');
|
|
|
|
}
|
2021-04-23 13:01:52 +09:00
|
|
|
|
2022-05-03 20:33:40 +09:00
|
|
|
function createAccount() {
|
2022-08-31 00:24:33 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkSignupDialog.vue')), {}, {
|
2022-05-03 20:33:40 +09:00
|
|
|
done: res => {
|
|
|
|
addAccounts(res.id, res.i);
|
|
|
|
switchAccountWithToken(res.i);
|
2021-04-23 13:01:52 +09:00
|
|
|
},
|
2022-05-03 20:33:40 +09:00
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function switchAccount(account: any) {
|
|
|
|
const fetchedAccounts: any[] = await getAccounts();
|
|
|
|
const token = fetchedAccounts.find(x => x.id === account.id).token;
|
|
|
|
switchAccountWithToken(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchAccountWithToken(token: string) {
|
|
|
|
login(token);
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.accounts,
|
|
|
|
icon: 'fas fa-users',
|
2021-04-23 13:01:52 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.lcjjdxlm {
|
|
|
|
display: flex;
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
> .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>
|