2020-08-18 22:44:21 +09:00
|
|
|
<template>
|
2021-12-23 16:10:13 +09:00
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div class="_formRoot">
|
|
|
|
<MkInput v-model="name" class="_formBlock">
|
|
|
|
<template #label>{{ $ts.name }}</template>
|
|
|
|
</MkInput>
|
2020-08-18 22:44:21 +09:00
|
|
|
|
2021-12-23 16:10:13 +09:00
|
|
|
<MkTextarea v-model="description" class="_formBlock">
|
|
|
|
<template #label>{{ $ts.description }}</template>
|
|
|
|
</MkTextarea>
|
2020-08-18 22:44:21 +09:00
|
|
|
|
2021-12-23 16:10:13 +09:00
|
|
|
<div class="banner">
|
|
|
|
<MkButton v-if="bannerId == null" @click="setBannerImage"><i class="fas fa-plus"></i> {{ $ts._channel.setBanner }}</MkButton>
|
|
|
|
<div v-else-if="bannerUrl">
|
|
|
|
<img :src="bannerUrl" style="width: 100%;"/>
|
|
|
|
<MkButton @click="removeBannerImage()"><i class="fas fa-trash-alt"></i> {{ $ts._channel.removeBanner }}</MkButton>
|
2020-08-18 22:44:21 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-23 16:10:13 +09:00
|
|
|
<div class="_formBlock">
|
2021-11-19 19:36:12 +09:00
|
|
|
<MkButton primary @click="save()"><i class="fas fa-save"></i> {{ channelId ? $ts.save : $ts.create }}</MkButton>
|
2020-08-18 22:44:21 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-23 16:10:13 +09:00
|
|
|
</MkSpacer>
|
2020-08-18 22:44:21 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-08-18 22:44:21 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-08-18 22:44:21 +09:00
|
|
|
components: {
|
|
|
|
MkTextarea, MkButton, MkInput,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
channelId: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 12:54:12 +09:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.channelId ? {
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts._channel.edit,
|
2021-04-20 23:22:59 +09:00
|
|
|
icon: 'fas fa-satellite-dish',
|
2021-12-23 16:10:13 +09:00
|
|
|
bg: 'var(--bg)',
|
2020-10-17 20:12:00 +09:00
|
|
|
} : {
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts._channel.create,
|
2021-04-20 23:22:59 +09:00
|
|
|
icon: 'fas fa-satellite-dish',
|
2021-12-23 16:10:13 +09:00
|
|
|
bg: 'var(--bg)',
|
2020-10-17 20:12:00 +09:00
|
|
|
}),
|
2020-08-18 22:44:21 +09:00
|
|
|
channel: null,
|
|
|
|
name: null,
|
|
|
|
description: null,
|
|
|
|
bannerUrl: null,
|
|
|
|
bannerId: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
async bannerId() {
|
|
|
|
if (this.bannerId == null) {
|
|
|
|
this.bannerUrl = null;
|
|
|
|
} else {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.bannerUrl = (await os.api('drive/files/show', {
|
2020-08-18 22:44:21 +09:00
|
|
|
fileId: this.bannerId,
|
|
|
|
})).url;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async created() {
|
|
|
|
if (this.channelId) {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.channel = await os.api('channels/show', {
|
2020-08-18 22:44:21 +09:00
|
|
|
channelId: this.channelId,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.name = this.channel.name;
|
|
|
|
this.description = this.channel.description;
|
|
|
|
this.bannerId = this.channel.bannerId;
|
|
|
|
this.bannerUrl = this.channel.bannerUrl;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
save() {
|
|
|
|
const params = {
|
|
|
|
name: this.name,
|
|
|
|
description: this.description,
|
|
|
|
bannerId: this.bannerId,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.channelId) {
|
|
|
|
params.channelId = this.channelId;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('channels/update', params)
|
2020-08-18 22:44:21 +09:00
|
|
|
.then(channel => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-08-18 22:44:21 +09:00
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('channels/create', params)
|
2020-08-18 22:44:21 +09:00
|
|
|
.then(channel => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-08-18 22:44:21 +09:00
|
|
|
this.$router.push(`/channels/${channel.id}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-05-26 22:53:09 +09:00
|
|
|
setBannerImage(evt) {
|
|
|
|
selectFile(evt.currentTarget ?? evt.target, null).then(file => {
|
2020-08-18 22:44:21 +09:00
|
|
|
this.bannerId = file.id;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeBannerImage() {
|
|
|
|
this.bannerId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|