2021-04-26 02:10:45 +00:00
|
|
|
<template>
|
2022-01-04 13:42:04 +00:00
|
|
|
<div>
|
2021-04-26 02:10:45 +00:00
|
|
|
<FormSuspense :p="init">
|
2021-09-29 15:50:45 +00:00
|
|
|
<FormInput v-model="title">
|
2022-01-04 13:42:04 +00:00
|
|
|
<template #label>{{ $ts.title }}</template>
|
2021-04-26 02:10:45 +00:00
|
|
|
</FormInput>
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
<FormTextarea v-model="description" :max="500">
|
2022-01-04 13:42:04 +00:00
|
|
|
<template #label>{{ $ts.description }}</template>
|
2021-04-26 02:10:45 +00:00
|
|
|
</FormTextarea>
|
|
|
|
|
|
|
|
<FormGroup>
|
2022-01-04 18:09:20 +00:00
|
|
|
<div v-for="file in files" :key="file.id" class="_formGroup wqugxsfx" :style="{ backgroundImage: file ? `url(${ file.thumbnailUrl })` : null }">
|
2021-04-26 02:10:45 +00:00
|
|
|
<div class="name">{{ file.name }}</div>
|
2021-11-19 10:36:12 +00:00
|
|
|
<button v-tooltip="$ts.remove" class="remove _button" @click="remove(file)"><i class="fas fa-times"></i></button>
|
2021-04-26 02:10:45 +00:00
|
|
|
</div>
|
2021-11-19 10:36:12 +00:00
|
|
|
<FormButton primary @click="selectFile"><i class="fas fa-plus"></i> {{ $ts.attachFile }}</FormButton>
|
2021-04-26 02:10:45 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
<FormSwitch v-model="isSensitive">{{ $ts.markAsSensitive }}</FormSwitch>
|
2021-04-26 02:10:45 +00:00
|
|
|
|
2021-11-19 10:36:12 +00:00
|
|
|
<FormButton v-if="postId" primary @click="save"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
|
|
|
|
<FormButton v-else primary @click="save"><i class="fas fa-save"></i> {{ $ts.publish }}</FormButton>
|
2021-04-26 02:10:45 +00:00
|
|
|
|
2021-11-19 10:36:12 +00:00
|
|
|
<FormButton v-if="postId" danger @click="del"><i class="fas fa-trash-alt"></i> {{ $ts.delete }}</FormButton>
|
2021-04-26 02:10:45 +00:00
|
|
|
</FormSuspense>
|
2022-01-04 13:42:04 +00:00
|
|
|
</div>
|
2021-04-26 02:10:45 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, inject, watch } from 'vue';
|
2022-01-04 13:42:04 +00:00
|
|
|
import FormButton from '@/components/ui/button.vue';
|
|
|
|
import FormInput from '@/components/form/input.vue';
|
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
|
|
|
import FormSwitch from '@/components/form/switch.vue';
|
|
|
|
import FormGroup from '@/components/form/group.vue';
|
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
2021-12-09 16:22:22 +00:00
|
|
|
import { selectFiles } from '@/scripts/select-file';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
2022-06-20 08:38:49 +00:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
postId?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let init = $ref(null);
|
|
|
|
let files = $ref([]);
|
|
|
|
let description = $ref(null);
|
|
|
|
let title = $ref(null);
|
|
|
|
let isSensitive = $ref(false);
|
|
|
|
|
|
|
|
function selectFile(evt) {
|
|
|
|
selectFiles(evt.currentTarget ?? evt.target, null).then(selected => {
|
|
|
|
files = files.concat(selected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(file) {
|
|
|
|
files = files.filter(f => f.id !== file.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
if (props.postId) {
|
|
|
|
await os.apiWithDialog('gallery/posts/update', {
|
|
|
|
postId: props.postId,
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
fileIds: files.map(file => file.id),
|
|
|
|
isSensitive: isSensitive,
|
|
|
|
});
|
|
|
|
mainRouter.push(`/gallery/${props.postId}`);
|
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('gallery/posts/create', {
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
fileIds: files.map(file => file.id),
|
|
|
|
isSensitive: isSensitive,
|
|
|
|
});
|
|
|
|
router.push(`/gallery/${created.id}`);
|
2021-04-26 02:10:45 +00:00
|
|
|
}
|
2022-06-20 08:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts.deleteConfirm,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('gallery/posts/delete', {
|
|
|
|
postId: props.postId,
|
|
|
|
});
|
|
|
|
mainRouter.push('/gallery');
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(() => props.postId, () => {
|
|
|
|
init = () => props.postId ? os.api('gallery/posts/show', {
|
|
|
|
postId: props.postId,
|
|
|
|
}).then(post => {
|
|
|
|
files = post.files;
|
|
|
|
title = post.title;
|
|
|
|
description = post.description;
|
|
|
|
isSensitive = post.isSensitive;
|
|
|
|
}) : Promise.resolve(null);
|
|
|
|
}, { immediate: true });
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => props.postId ? {
|
|
|
|
title: i18n.ts.edit,
|
|
|
|
icon: 'fas fa-pencil-alt',
|
|
|
|
} : {
|
|
|
|
title: i18n.ts.postToGallery,
|
|
|
|
icon: 'fas fa-pencil-alt',
|
|
|
|
}));
|
2021-04-26 02:10:45 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.wqugxsfx {
|
|
|
|
height: 200px;
|
|
|
|
background-size: contain;
|
|
|
|
background-position: center;
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
left: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remove {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|