2021-04-23 07:01:52 +03:00
|
|
|
<template>
|
2022-01-04 11:21:00 +02:00
|
|
|
<div class="_formRoot">
|
2021-04-23 07:01:52 +03:00
|
|
|
<FormSuspense :p="init">
|
2021-11-19 12:36:12 +02:00
|
|
|
<FormButton primary @click="addAccount"><i class="fas fa-plus"></i> {{ $ts.addAccount }}</FormButton>
|
2021-04-23 07:01:52 +03:00
|
|
|
|
2022-01-04 11:21:00 +02: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 07:01:52 +03:00
|
|
|
</div>
|
2022-01-04 11:21:00 +02:00
|
|
|
<div class="acct">
|
|
|
|
<MkAcct :user="account"/>
|
2021-04-23 07:01:52 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</FormSuspense>
|
2022-01-04 11:21:00 +02:00
|
|
|
</div>
|
2021-04-23 07:01:52 +03:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-05-01 16:51:07 +03:00
|
|
|
import { defineAsyncComponent, defineComponent } from 'vue';
|
2022-01-04 11:21:00 +02:00
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
|
|
|
import FormButton from '@/components/ui/button.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
|
|
|
import { getAccounts, addAccount, login } from '@/account';
|
2021-04-23 07:01:52 +03:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormSuspense,
|
|
|
|
FormButton,
|
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
[symbols.PAGE_INFO]: {
|
|
|
|
title: this.$ts.accounts,
|
|
|
|
icon: 'fas fa-users',
|
2021-09-29 18:50:45 +03:00
|
|
|
bg: 'var(--bg)',
|
2021-04-23 07:01:52 +03:00
|
|
|
},
|
2021-08-20 13:38:16 +03:00
|
|
|
storedAccounts: getAccounts().then(accounts => accounts.filter(x => x.id !== this.$i.id)),
|
2021-04-23 07:01:52 +03:00
|
|
|
accounts: null,
|
2021-08-20 13:38:16 +03:00
|
|
|
init: async () => os.api('users/show', {
|
|
|
|
userIds: (await this.storedAccounts).map(x => x.id)
|
2021-04-23 07:01:52 +03:00
|
|
|
}).then(accounts => {
|
|
|
|
this.accounts = accounts;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
menu(account, ev) {
|
2021-08-08 06:19:10 +03:00
|
|
|
os.popupMenu([{
|
2021-04-23 07:01:52 +03:00
|
|
|
text: this.$ts.switch,
|
|
|
|
icon: 'fas fa-exchange-alt',
|
|
|
|
action: () => this.switchAccount(account),
|
|
|
|
}, {
|
|
|
|
text: this.$ts.remove,
|
|
|
|
icon: 'fas fa-trash-alt',
|
|
|
|
danger: true,
|
|
|
|
action: () => this.removeAccount(account),
|
2022-01-28 04:53:12 +02:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2021-04-23 07:01:52 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
addAccount(ev) {
|
2021-08-08 06:19:10 +03:00
|
|
|
os.popupMenu([{
|
2021-04-23 07:01:52 +03:00
|
|
|
text: this.$ts.existingAccount,
|
|
|
|
action: () => { this.addExistingAccount(); },
|
|
|
|
}, {
|
|
|
|
text: this.$ts.createAccount,
|
|
|
|
action: () => { this.createAccount(); },
|
2022-01-28 04:53:12 +02:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2021-04-23 07:01:52 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
addExistingAccount() {
|
2022-05-01 16:51:07 +03:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/signin-dialog.vue')), {}, {
|
2021-04-23 07:01:52 +03:00
|
|
|
done: res => {
|
|
|
|
addAccount(res.id, res.i);
|
|
|
|
os.success();
|
|
|
|
},
|
|
|
|
}, 'closed');
|
|
|
|
},
|
|
|
|
|
|
|
|
createAccount() {
|
2022-05-01 16:51:07 +03:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/signup-dialog.vue')), {}, {
|
2021-04-23 07:01:52 +03:00
|
|
|
done: res => {
|
|
|
|
addAccount(res.id, res.i);
|
|
|
|
this.switchAccountWithToken(res.i);
|
|
|
|
},
|
|
|
|
}, 'closed');
|
|
|
|
},
|
|
|
|
|
2021-08-20 13:38:16 +03:00
|
|
|
async switchAccount(account: any) {
|
|
|
|
const storedAccounts = await getAccounts();
|
2021-04-23 07:01:52 +03:00
|
|
|
const token = storedAccounts.find(x => x.id === account.id).token;
|
|
|
|
this.switchAccountWithToken(token);
|
|
|
|
},
|
|
|
|
|
|
|
|
switchAccountWithToken(token: string) {
|
|
|
|
login(token);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</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>
|