1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-16 07:38:18 +09:00
cherrypick/packages/client/src/pages/settings/accounts.vue

150 lines
3.3 KiB
Vue
Raw Normal View History

2021-04-23 13:01:52 +09:00
<template>
<FormBase>
<FormSuspense :p="init">
<FormButton @click="addAccount" primary><i class="fas fa-plus"></i> {{ $ts.addAccount }}</FormButton>
2021-09-30 00:50:45 +09:00
<div class="_debobigegoItem _button" v-for="account in accounts" :key="account.id" @click="menu(account, $event)">
<div class="_debobigegoPanel lcjjdxlm">
2021-04-23 13:01:52 +09:00
<div class="avatar">
<MkAvatar :user="account" class="avatar"/>
</div>
<div class="body">
<div class="name">
<MkUserName :user="account"/>
</div>
<div class="acct">
<MkAcct :user="account"/>
</div>
</div>
</div>
</div>
</FormSuspense>
</FormBase>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
2021-11-12 02:02:25 +09:00
import FormSuspense from '@/components/debobigego/suspense.vue';
import FormLink from '@/components/debobigego/link.vue';
import FormBase from '@/components/debobigego/base.vue';
import FormGroup from '@/components/debobigego/group.vue';
import FormButton from '@/components/debobigego/button.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
import { getAccounts, addAccount, login } from '@/account';
2021-04-23 13:01:52 +09:00
export default defineComponent({
components: {
FormBase,
FormSuspense,
FormButton,
},
emits: ['info'],
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.accounts,
icon: 'fas fa-users',
2021-09-30 00:50:45 +09:00
bg: 'var(--bg)',
2021-04-23 13:01:52 +09:00
},
storedAccounts: getAccounts().then(accounts => accounts.filter(x => x.id !== this.$i.id)),
2021-04-23 13:01:52 +09:00
accounts: null,
init: async () => os.api('users/show', {
userIds: (await this.storedAccounts).map(x => x.id)
2021-04-23 13:01:52 +09:00
}).then(accounts => {
this.accounts = accounts;
}),
};
},
mounted() {
this.$emit('info', this[symbols.PAGE_INFO]);
},
methods: {
menu(account, ev) {
2021-08-08 12:19:10 +09:00
os.popupMenu([{
2021-04-23 13:01:52 +09: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),
}], ev.currentTarget || ev.target);
},
addAccount(ev) {
2021-08-08 12:19:10 +09:00
os.popupMenu([{
2021-04-23 13:01:52 +09:00
text: this.$ts.existingAccount,
action: () => { this.addExistingAccount(); },
}, {
text: this.$ts.createAccount,
action: () => { this.createAccount(); },
}], ev.currentTarget || ev.target);
},
addExistingAccount() {
2021-11-12 02:02:25 +09:00
os.popup(import('@/components/signin-dialog.vue'), {}, {
2021-04-23 13:01:52 +09:00
done: res => {
addAccount(res.id, res.i);
os.success();
},
}, 'closed');
},
createAccount() {
2021-11-12 02:02:25 +09:00
os.popup(import('@/components/signup-dialog.vue'), {}, {
2021-04-23 13:01:52 +09:00
done: res => {
addAccount(res.id, res.i);
this.switchAccountWithToken(res.i);
},
}, 'closed');
},
async switchAccount(account: any) {
const storedAccounts = await getAccounts();
2021-04-23 13:01:52 +09: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>