サイドバーメニューからアカウントを作成できるように (#5910)

* メニューからアカウントを作成できるようにした

* i18n

* Update signup.vue

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
Xeltica 2020-02-15 01:33:09 +09:00 committed by GitHub
parent 8689a998aa
commit 4f1981df03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 10 deletions

View File

@ -397,6 +397,7 @@ doing: "やっています"
category: "カテゴリ" category: "カテゴリ"
tags: "タグ" tags: "タグ"
docSource: "このドキュメントのソース" docSource: "このドキュメントのソース"
createAccount: "アカウントを作成"
_ago: _ago:
unknown: "謎" unknown: "謎"

View File

@ -364,10 +364,15 @@ export default Vue.extend({
icon: faCog, icon: faCog,
}, null, { }, null, {
type: 'item', type: 'item',
text: this.$t('addAcount'),
icon: faPlus, icon: faPlus,
text: this.$t('addAcount'),
action: () => { this.addAcount() }, action: () => { this.addAcount() },
}], ...accountItems], }, {
type: 'item',
icon: faPlus,
text: this.$t('createAccount'),
action: () => { this.createAccount() },
}, null, ...accountItems, ]],
align: 'left', align: 'left',
fixed: true, fixed: true,
width: 240, width: 240,
@ -507,9 +512,20 @@ export default Vue.extend({
}); });
}, },
async switchAccount(account) { async createAccount() {
const token = this.$store.state.device.accounts.find(x => x.id === account.id).token; this.$root.new(await import('./components/signup-dialog.vue').then(m => m.default)).$once('signup', res => {
this.$root.api('i', {}, token).then(i => { this.$store.dispatch('addAcount', res);
this.switchAccountWithToken(res.i);
});
},
async switchAccount(account: any) {
const token = this.$store.state.device.accounts.find((x: any) => x.id === account.id).token;
this.switchAccountWithToken(token);
},
switchAccountWithToken(token: string) {
this.$root.api('i', {}, token).then((i: any) => {
this.$store.dispatch('switchAccount', { this.$store.dispatch('switchAccount', {
...i, ...i,
token: token token: token

View File

@ -1,7 +1,7 @@
<template> <template>
<x-window @closed="() => { $emit('closed'); destroyDom(); }"> <x-window ref="window" @closed="() => { $emit('closed'); destroyDom(); }">
<template #header>{{ $t('signup') }}</template> <template #header>{{ $t('signup') }}</template>
<x-signup/> <x-signup :auto-set="autoSet" @signup="onSignup"/>
</x-window> </x-window>
</template> </template>
@ -18,5 +18,20 @@ export default Vue.extend({
XSignup, XSignup,
XWindow, XWindow,
}, },
props: {
autoSet: {
type: Boolean,
required: false,
default: false,
}
},
methods: {
onSignup(res) {
this.$emit('signup', res);
this.$refs.window.close();
}
}
}); });
</script> </script>

View File

@ -84,6 +84,14 @@ export default Vue.extend({
} }
}, },
props: {
autoSet: {
type: Boolean,
required: false,
default: false,
}
},
computed: { computed: {
meta() { meta() {
return this.$store.state.instance.meta; return this.$store.state.instance.meta;
@ -97,6 +105,15 @@ export default Vue.extend({
} }
}, },
created() {
if (this.autoSet) {
this.$once('signup', res => {
localStorage.setItem('i', res.i);
location.reload();
});
}
},
mounted() { mounted() {
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script'); const script = document.createElement('script');
@ -166,8 +183,7 @@ export default Vue.extend({
username: this.username, username: this.username,
password: this.password password: this.password
}).then(res => { }).then(res => {
localStorage.setItem('i', res.i); this.$emit('signup', res);
location.href = '/';
}); });
}).catch(() => { }).catch(() => {
this.submitting = false; this.submitting = false;

View File

@ -62,7 +62,9 @@ export default Vue.extend({
}, },
signup() { signup() {
this.$root.new(XSignupDialog); this.$root.new(XSignupDialog, {
autoSet: true
});
} }
} }
}); });