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