2020-08-18 13:44:21 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-10-17 11:12:00 +00:00
|
|
|
<div class="_section">
|
2020-08-18 13:44:21 +00:00
|
|
|
<div class="_content">
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkInput v-model:value="name">{{ $ts.name }}</MkInput>
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkTextarea v-model:value="description">{{ $ts.description }}</MkTextarea>
|
2020-08-18 13:44:21 +00:00
|
|
|
|
|
|
|
<div class="banner">
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkButton v-if="bannerId == null" @click="setBannerImage"><Fa :icon="faPlus"/> {{ $ts._channel.setBanner }}</MkButton>
|
2020-08-18 13:44:21 +00:00
|
|
|
<div v-else-if="bannerUrl">
|
|
|
|
<img :src="bannerUrl" style="width: 100%;"/>
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkButton @click="removeBannerImage()"><Fa :icon="faTrashAlt"/> {{ $ts._channel.removeBanner }}</MkButton>
|
2020-08-18 13:44:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkButton @click="save()" primary><Fa :icon="faSave"/> {{ channelId ? $ts.save : $ts.create }}</MkButton>
|
2020-08-18 13:44:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2020-08-18 13:44:21 +00:00
|
|
|
import { faPlus, faSatelliteDish } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSave, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
2021-03-23 08:30:14 +00:00
|
|
|
import MkTextarea from '@client/components/ui/textarea.vue';
|
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
|
|
|
import MkInput from '@client/components/ui/input.vue';
|
|
|
|
import { selectFile } from '@client/scripts/select-file';
|
|
|
|
import * as os from '@client/os';
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-08-18 13:44:21 +00:00
|
|
|
components: {
|
|
|
|
MkTextarea, MkButton, MkInput,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
channelId: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-10-17 11:12:00 +00:00
|
|
|
INFO: computed(() => this.channelId ? {
|
2020-12-26 01:47:36 +00:00
|
|
|
title: this.$ts._channel.edit,
|
2020-11-03 11:36:12 +00:00
|
|
|
icon: faSatelliteDish,
|
2020-10-17 11:12:00 +00:00
|
|
|
} : {
|
2020-12-26 01:47:36 +00:00
|
|
|
title: this.$ts._channel.create,
|
2020-11-03 11:36:12 +00:00
|
|
|
icon: faSatelliteDish,
|
2020-10-17 11:12:00 +00:00
|
|
|
}),
|
2020-08-18 13:44:21 +00:00
|
|
|
channel: null,
|
|
|
|
name: null,
|
|
|
|
description: null,
|
|
|
|
bannerUrl: null,
|
|
|
|
bannerId: null,
|
|
|
|
faSave, faTrashAlt, faPlus,faSatelliteDish,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
async bannerId() {
|
|
|
|
if (this.bannerId == null) {
|
|
|
|
this.bannerUrl = null;
|
|
|
|
} else {
|
2020-10-17 11:12:00 +00:00
|
|
|
this.bannerUrl = (await os.api('drive/files/show', {
|
2020-08-18 13:44:21 +00:00
|
|
|
fileId: this.bannerId,
|
|
|
|
})).url;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async created() {
|
|
|
|
if (this.channelId) {
|
2020-10-17 11:12:00 +00:00
|
|
|
this.channel = await os.api('channels/show', {
|
2020-08-18 13:44:21 +00: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 11:12:00 +00:00
|
|
|
os.api('channels/update', params)
|
2020-08-18 13:44:21 +00:00
|
|
|
.then(channel => {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.success();
|
2020-08-18 13:44:21 +00:00
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.api('channels/create', params)
|
2020-08-18 13:44:21 +00:00
|
|
|
.then(channel => {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.success();
|
2020-08-18 13:44:21 +00:00
|
|
|
this.$router.push(`/channels/${channel.id}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setBannerImage(e) {
|
2020-10-17 11:12:00 +00:00
|
|
|
selectFile(e.currentTarget || e.target, null, false).then(file => {
|
2020-08-18 13:44:21 +00:00
|
|
|
this.bannerId = file.id;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeBannerImage() {
|
|
|
|
this.bannerId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|