misskey/src/client/app/common/views/components/profile-editor.vue

280 lines
7.6 KiB
Vue
Raw Normal View History

2018-05-19 11:31:13 +00:00
<template>
2018-06-14 07:48:49 +00:00
<ui-card>
<div slot="title"><fa icon="user"/> {{ $t('title') }}</div>
2018-06-14 05:52:37 +00:00
2018-11-09 09:32:09 +00:00
<section class="esokaraujimuwfttfzgocmutcihewscl">
<div class="header" :style="bannerStyle">
<mk-avatar class="avatar" :user="$store.state.i" :disable-preview="true" :disable-link="true"/>
</div>
2018-09-05 04:47:26 +00:00
<ui-form :disabled="saving">
<ui-input v-model="name" :max="30">
<span>{{ $t('name') }}</span>
2018-09-05 04:47:26 +00:00
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="username" readonly>
<span>{{ $t('account') }}</span>
2018-09-05 04:47:26 +00:00
<span slot="prefix">@</span>
<span slot="suffix">@{{ host }}</span>
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="location">
<span>{{ $t('location') }}</span>
<span slot="prefix"><fa icon="map-marker-alt"/></span>
2018-09-05 04:47:26 +00:00
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input v-model="birthday" type="date">
<span slot="title">{{ $t('birthday') }}</span>
<span slot="prefix"><fa icon="birthday-cake"/></span>
2018-09-05 04:47:26 +00:00
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-textarea v-model="description" :max="500">
<span>{{ $t('description') }}</span>
2018-09-05 04:47:26 +00:00
</ui-textarea>
2018-06-14 05:52:37 +00:00
2018-12-03 11:08:18 +00:00
<ui-select v-model="lang">
<span slot="label">{{ $t('language') }}</span>
<span slot="icon"><fa icon="language"/></span>
<option v-for="lang in unique(Object.values(langmap).map(x => x.nativeName)).map(name => Object.keys(langmap).find(k => langmap[k].nativeName == name))" :value="lang" :key="lang">{{ langmap[lang].nativeName }}</option>
</ui-select>
2018-09-05 04:47:26 +00:00
<ui-input type="file" @change="onAvatarChange">
<span>{{ $t('avatar') }}</span>
<span slot="icon"><fa icon="image"/></span>
<span slot="desc" v-if="avatarUploading">{{ $t('uploading') }}<mk-ellipsis/></span>
2018-09-05 04:47:26 +00:00
</ui-input>
2018-06-14 05:52:37 +00:00
2018-09-05 04:47:26 +00:00
<ui-input type="file" @change="onBannerChange">
<span>{{ $t('banner') }}</span>
<span slot="icon"><fa icon="image"/></span>
<span slot="desc" v-if="bannerUploading">{{ $t('uploading') }}<mk-ellipsis/></span>
2018-09-05 04:47:26 +00:00
</ui-input>
2018-06-14 05:52:37 +00:00
<ui-button @click="save(true)">{{ $t('save') }}</ui-button>
2018-09-05 04:47:26 +00:00
</ui-form>
</section>
2018-09-13 09:23:44 +00:00
<section>
<header>{{ $t('advanced') }}</header>
2018-09-13 09:23:44 +00:00
<div>
<ui-switch v-model="isCat" @change="save(false)">{{ $t('is-cat') }}</ui-switch>
<ui-switch v-model="isBot" @change="save(false)">{{ $t('is-bot') }}</ui-switch>
<ui-switch v-model="alwaysMarkNsfw">{{ $t('@.always-mark-nsfw') }}</ui-switch>
2018-09-13 09:23:44 +00:00
</div>
</section>
<section>
<header>{{ $t('privacy') }}</header>
2018-09-13 09:23:44 +00:00
<div>
<ui-switch v-model="isLocked" @change="save(false)">{{ $t('is-locked') }}</ui-switch>
2018-12-28 18:12:22 +00:00
<ui-switch v-model="carefulBot" :disabled="isLocked" @change="save(false)">{{ $t('careful-bot') }}</ui-switch>
<ui-switch v-model="autoAcceptFollowed" :disabled="!isLocked && !carefulBot" @change="save(false)">{{ $t('auto-accept-followed') }}</ui-switch>
2018-09-13 09:23:44 +00:00
</div>
</section>
2018-11-29 07:23:45 +00:00
<section v-if="enableEmail">
2018-11-29 07:23:45 +00:00
<header>{{ $t('email') }}</header>
<div>
<template v-if="$store.state.i.email != null">
<ui-info v-if="$store.state.i.emailVerified">{{ $t('email-verified') }}</ui-info>
<ui-info v-else warn>{{ $t('email-not-verified') }}</ui-info>
</template>
<ui-input v-model="email" type="email"><span>{{ $t('email-address') }}</span></ui-input>
<ui-button @click="updateEmail()">{{ $t('save') }}</ui-button>
</div>
</section>
2018-06-14 07:48:49 +00:00
</ui-card>
2018-05-19 11:31:13 +00:00
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import { apiUrl, host } from '../../../config';
2018-11-11 03:35:30 +00:00
import { toUnicode } from 'punycode';
2018-12-03 11:08:18 +00:00
import langmap from 'langmap';
import { unique } from '../../../../../prelude/array';
2018-05-19 11:31:13 +00:00
export default Vue.extend({
i18n: i18n('common/views/components/profile-editor.vue'),
2018-11-29 07:23:45 +00:00
2018-05-19 11:31:13 +00:00
data() {
return {
2018-12-03 11:08:18 +00:00
unique,
langmap,
2018-11-11 03:35:30 +00:00
host: toUnicode(host),
enableEmail: false,
2018-11-29 07:23:45 +00:00
email: null,
2018-05-19 11:31:13 +00:00
name: null,
2018-05-20 08:37:30 +00:00
username: null,
2018-05-19 11:31:13 +00:00
location: null,
description: null,
2018-12-03 11:08:18 +00:00
lang: null,
2018-05-19 11:31:13 +00:00
birthday: null,
2018-05-20 05:01:47 +00:00
avatarId: null,
bannerId: null,
2018-05-21 02:08:08 +00:00
isCat: false,
isBot: false,
2018-09-13 09:23:44 +00:00
isLocked: false,
2018-10-13 11:11:00 +00:00
carefulBot: false,
autoAcceptFollowed: false,
2018-05-20 05:01:47 +00:00
saving: false,
2018-06-14 22:56:56 +00:00
avatarUploading: false,
bannerUploading: false
2018-05-19 11:31:13 +00:00
};
},
2018-05-20 00:04:48 +00:00
computed: {
alwaysMarkNsfw: {
get() { return this.$store.state.i.settings.alwaysMarkNsfw; },
2018-11-08 23:13:34 +00:00
set(value) { this.$root.api('i/update', { alwaysMarkNsfw: value }); }
},
2018-11-09 09:32:09 +00:00
bannerStyle(): any {
if (this.$store.state.i.bannerUrl == null) return {};
return {
backgroundColor: this.$store.state.i.bannerColor && this.$store.state.i.bannerColor.length == 3 ? `rgb(${ this.$store.state.i.bannerColor.join(',') })` : null,
backgroundImage: `url(${ this.$store.state.i.bannerUrl })`
};
},
},
2018-05-19 11:31:13 +00:00
created() {
this.$root.getMeta().then(meta => {
this.enableEmail = meta.enableEmail;
});
2018-11-29 07:23:45 +00:00
this.email = this.$store.state.i.email;
this.name = this.$store.state.i.name;
2018-05-27 04:49:09 +00:00
this.username = this.$store.state.i.username;
this.location = this.$store.state.i.profile.location;
this.description = this.$store.state.i.description;
2018-12-03 11:08:18 +00:00
this.lang = this.$store.state.i.lang;
2018-05-27 04:49:09 +00:00
this.birthday = this.$store.state.i.profile.birthday;
this.avatarId = this.$store.state.i.avatarId;
this.bannerId = this.$store.state.i.bannerId;
this.isCat = this.$store.state.i.isCat;
this.isBot = this.$store.state.i.isBot;
2018-09-13 09:23:44 +00:00
this.isLocked = this.$store.state.i.isLocked;
2018-10-13 11:11:00 +00:00
this.carefulBot = this.$store.state.i.carefulBot;
this.autoAcceptFollowed = this.$store.state.i.autoAcceptFollowed;
2018-05-19 11:31:13 +00:00
},
2018-05-20 00:04:48 +00:00
methods: {
2018-05-20 05:01:47 +00:00
onAvatarChange([file]) {
2018-06-14 22:56:56 +00:00
this.avatarUploading = true;
2018-05-20 05:01:47 +00:00
const data = new FormData();
data.append('file', file);
2018-05-27 04:49:09 +00:00
data.append('i', this.$store.state.i.token);
2018-05-20 05:01:47 +00:00
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
2018-08-19 04:32:02 +00:00
.then(response => response.json())
.then(f => {
this.avatarId = f.id;
this.avatarUploading = false;
})
.catch(e => {
this.avatarUploading = false;
alert('%18n:@upload-failed%');
});
2018-05-20 05:01:47 +00:00
},
onBannerChange([file]) {
2018-06-14 22:56:56 +00:00
this.bannerUploading = true;
2018-05-20 05:01:47 +00:00
const data = new FormData();
data.append('file', file);
2018-05-27 04:49:09 +00:00
data.append('i', this.$store.state.i.token);
2018-05-20 05:01:47 +00:00
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
2018-08-19 04:32:02 +00:00
.then(response => response.json())
.then(f => {
this.bannerId = f.id;
this.bannerUploading = false;
})
.catch(e => {
this.bannerUploading = false;
alert('%18n:@upload-failed%');
});
2018-05-20 05:01:47 +00:00
},
2018-09-13 09:23:44 +00:00
save(notify) {
2018-05-19 11:31:13 +00:00
this.saving = true;
2018-11-08 23:13:34 +00:00
this.$root.api('i/update', {
2018-05-19 11:31:13 +00:00
name: this.name || null,
location: this.location || null,
description: this.description || null,
2018-12-03 11:08:18 +00:00
lang: this.lang,
2018-05-20 05:01:47 +00:00
birthday: this.birthday || null,
2018-11-28 19:54:36 +00:00
avatarId: this.avatarId || undefined,
bannerId: this.bannerId || undefined,
2018-11-08 23:41:06 +00:00
isCat: !!this.isCat,
isBot: !!this.isBot,
isLocked: !!this.isLocked,
carefulBot: !!this.carefulBot,
autoAcceptFollowed: !!this.autoAcceptFollowed
2018-05-20 05:01:47 +00:00
}).then(i => {
2018-05-19 11:31:13 +00:00
this.saving = false;
2018-05-27 04:49:09 +00:00
this.$store.state.i.avatarId = i.avatarId;
this.$store.state.i.avatarUrl = i.avatarUrl;
this.$store.state.i.bannerId = i.bannerId;
this.$store.state.i.bannerUrl = i.bannerUrl;
2018-05-20 05:01:47 +00:00
2018-09-13 09:23:44 +00:00
if (notify) {
2018-12-02 06:28:52 +00:00
this.$root.dialog({
2018-10-10 12:23:38 +00:00
type: 'success',
text: this.$t('saved')
2018-10-10 12:23:38 +00:00
});
2018-09-13 09:23:44 +00:00
}
2018-05-19 11:31:13 +00:00
});
2018-11-29 07:23:45 +00:00
},
updateEmail() {
2018-12-02 11:10:53 +00:00
this.$root.dialog({
2018-11-29 11:19:02 +00:00
title: this.$t('@.enter-password'),
2018-12-02 11:10:53 +00:00
input: {
type: 'password'
}
}).then(({ canceled, result: password }) => {
if (canceled) return;
2018-11-29 11:19:02 +00:00
this.$root.api('i/update_email', {
password: password,
email: this.email == '' ? null : this.email
});
2018-11-29 07:23:45 +00:00
});
2018-05-19 11:31:13 +00:00
}
}
});
</script>
2018-11-09 09:32:09 +00:00
<style lang="stylus" scoped>
.esokaraujimuwfttfzgocmutcihewscl
> .header
height 150px
overflow hidden
background-size cover
background-position center
border-radius 4px
> .avatar
position absolute
top 0
bottom 0
left 0
right 0
display block
width 72px
height 72px
margin auto
</style>