2020-08-18 15:44:21 +02:00
|
|
|
<template>
|
2022-06-20 10:38:49 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div class="_formRoot">
|
|
|
|
<MkInput v-model="name" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.name }}</template>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkInput>
|
|
|
|
|
|
|
|
<MkTextarea v-model="description" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.description }}</template>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkTextarea>
|
|
|
|
|
|
|
|
<div class="banner">
|
2022-11-07 03:30:26 +01:00
|
|
|
<MkButton v-if="bannerId == null" @click="setBannerImage"><i class="ph-plus-bold"></i> {{ i18n.ts._channel.setBanner }}</MkButton>
|
2022-06-20 10:38:49 +02:00
|
|
|
<div v-else-if="bannerUrl">
|
|
|
|
<img :src="bannerUrl" style="width: 100%;"/>
|
2022-11-07 03:30:26 +01:00
|
|
|
<MkButton @click="removeBannerImage()"><i class="ph-trash-bold"></i> {{ i18n.ts._channel.removeBanner }}</MkButton>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="_formBlock">
|
2022-11-07 03:30:26 +01:00
|
|
|
<MkButton primary @click="save()"><i class="ph-floppy-disk-back-bold"></i> {{ channelId ? i18n.ts.save : i18n.ts.create }}</MkButton>
|
2020-08-18 15:44:21 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-08-18 15:44:21 +02:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, inject, watch } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as os from '@/os';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
channelId?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let channel = $ref(null);
|
|
|
|
let name = $ref(null);
|
|
|
|
let description = $ref(null);
|
|
|
|
let bannerUrl = $ref<string | null>(null);
|
|
|
|
let bannerId = $ref<string | null>(null);
|
|
|
|
|
|
|
|
watch(() => bannerId, async () => {
|
|
|
|
if (bannerId == null) {
|
|
|
|
bannerUrl = null;
|
|
|
|
} else {
|
|
|
|
bannerUrl = (await os.api('drive/files/show', {
|
|
|
|
fileId: bannerId,
|
|
|
|
})).url;
|
2020-08-18 15:44:21 +02:00
|
|
|
}
|
|
|
|
});
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
async function fetchChannel() {
|
|
|
|
if (props.channelId == null) return;
|
|
|
|
|
|
|
|
channel = await os.api('channels/show', {
|
|
|
|
channelId: props.channelId,
|
|
|
|
});
|
|
|
|
|
|
|
|
name = channel.name;
|
|
|
|
description = channel.description;
|
|
|
|
bannerId = channel.bannerId;
|
|
|
|
bannerUrl = channel.bannerUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchChannel();
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
const params = {
|
|
|
|
name: name,
|
|
|
|
description: description,
|
|
|
|
bannerId: bannerId,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (props.channelId) {
|
|
|
|
params.channelId = props.channelId;
|
|
|
|
os.api('channels/update', params).then(() => {
|
|
|
|
os.success();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.api('channels/create', params).then(created => {
|
|
|
|
os.success();
|
|
|
|
router.push(`/channels/${created.id}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBannerImage(evt) {
|
|
|
|
selectFile(evt.currentTarget ?? evt.target, null).then(file => {
|
|
|
|
bannerId = file.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeBannerImage() {
|
|
|
|
bannerId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => props.channelId ? {
|
|
|
|
title: i18n.ts._channel.edit,
|
2022-11-07 03:30:26 +01:00
|
|
|
icon: 'ph-television-bold',
|
2022-06-20 10:38:49 +02:00
|
|
|
} : {
|
|
|
|
title: i18n.ts._channel.create,
|
2022-11-07 03:30:26 +01:00
|
|
|
icon: 'ph-television-bold',
|
2022-06-20 10:38:49 +02:00
|
|
|
}));
|
2020-08-18 15:44:21 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|