2021-04-25 21:10:45 -05:00
|
|
|
<template>
|
|
|
|
<FormBase>
|
|
|
|
<FormSuspense :p="init">
|
2021-09-29 10:50:45 -05:00
|
|
|
<FormInput v-model="title">
|
2021-04-25 21:10:45 -05:00
|
|
|
<span>{{ $ts.title }}</span>
|
|
|
|
</FormInput>
|
|
|
|
|
2021-09-29 10:50:45 -05:00
|
|
|
<FormTextarea v-model="description" :max="500">
|
2021-04-25 21:10:45 -05:00
|
|
|
<span>{{ $ts.description }}</span>
|
|
|
|
</FormTextarea>
|
|
|
|
|
|
|
|
<FormGroup>
|
2021-09-29 10:50:45 -05:00
|
|
|
<div v-for="file in files" :key="file.id" class="_debobigegoItem _debobigegoPanel wqugxsfx" :style="{ backgroundImage: file ? `url(${ file.thumbnailUrl })` : null }">
|
2021-04-25 21:10:45 -05:00
|
|
|
<div class="name">{{ file.name }}</div>
|
2021-11-19 04:36:12 -06:00
|
|
|
<button v-tooltip="$ts.remove" class="remove _button" @click="remove(file)"><i class="fas fa-times"></i></button>
|
2021-04-25 21:10:45 -05:00
|
|
|
</div>
|
2021-11-19 04:36:12 -06:00
|
|
|
<FormButton primary @click="selectFile"><i class="fas fa-plus"></i> {{ $ts.attachFile }}</FormButton>
|
2021-04-25 21:10:45 -05:00
|
|
|
</FormGroup>
|
|
|
|
|
2021-09-29 10:50:45 -05:00
|
|
|
<FormSwitch v-model="isSensitive">{{ $ts.markAsSensitive }}</FormSwitch>
|
2021-04-25 21:10:45 -05:00
|
|
|
|
2021-11-19 04:36:12 -06: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-25 21:10:45 -05:00
|
|
|
|
2021-11-19 04:36:12 -06:00
|
|
|
<FormButton v-if="postId" danger @click="del"><i class="fas fa-trash-alt"></i> {{ $ts.delete }}</FormButton>
|
2021-04-25 21:10:45 -05:00
|
|
|
</FormSuspense>
|
|
|
|
</FormBase>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-11 11:02:25 -06:00
|
|
|
import FormButton from '@/components/debobigego/button.vue';
|
|
|
|
import FormInput from '@/components/debobigego/input.vue';
|
|
|
|
import FormTextarea from '@/components/debobigego/textarea.vue';
|
|
|
|
import FormSwitch from '@/components/debobigego/switch.vue';
|
|
|
|
import FormTuple from '@/components/debobigego/tuple.vue';
|
|
|
|
import FormBase from '@/components/debobigego/base.vue';
|
|
|
|
import FormGroup from '@/components/debobigego/group.vue';
|
|
|
|
import FormSuspense from '@/components/debobigego/suspense.vue';
|
2021-12-09 10:22:22 -06:00
|
|
|
import { selectFiles } from '@/scripts/select-file';
|
2021-11-11 11:02:25 -06:00
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2021-04-25 21:10:45 -05:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormButton,
|
|
|
|
FormInput,
|
|
|
|
FormTextarea,
|
|
|
|
FormSwitch,
|
|
|
|
FormBase,
|
|
|
|
FormGroup,
|
|
|
|
FormSuspense,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
postId: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
[symbols.PAGE_INFO]: computed(() => this.postId ? {
|
|
|
|
title: this.$ts.edit,
|
|
|
|
icon: 'fas fa-pencil-alt'
|
|
|
|
} : {
|
|
|
|
title: this.$ts.postToGallery,
|
|
|
|
icon: 'fas fa-pencil-alt'
|
|
|
|
}),
|
|
|
|
init: null,
|
|
|
|
files: [],
|
|
|
|
description: null,
|
|
|
|
title: null,
|
|
|
|
isSensitive: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
postId: {
|
|
|
|
handler() {
|
|
|
|
this.init = () => this.postId ? os.api('gallery/posts/show', {
|
|
|
|
postId: this.postId
|
|
|
|
}).then(post => {
|
|
|
|
this.files = post.files;
|
|
|
|
this.title = post.title;
|
|
|
|
this.description = post.description;
|
|
|
|
this.isSensitive = post.isSensitive;
|
|
|
|
}) : Promise.resolve(null);
|
|
|
|
},
|
|
|
|
immediate: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
selectFile(e) {
|
2021-12-09 10:22:22 -06:00
|
|
|
selectFiles(e.currentTarget || e.target, null).then(files => {
|
2021-04-25 21:10:45 -05:00
|
|
|
this.files = this.files.concat(files);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
remove(file) {
|
|
|
|
this.files = this.files.filter(f => f.id !== file.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
async save() {
|
|
|
|
if (this.postId) {
|
|
|
|
await os.apiWithDialog('gallery/posts/update', {
|
|
|
|
postId: this.postId,
|
|
|
|
title: this.title,
|
|
|
|
description: this.description,
|
|
|
|
fileIds: this.files.map(file => file.id),
|
|
|
|
isSensitive: this.isSensitive,
|
|
|
|
});
|
|
|
|
this.$router.push(`/gallery/${this.postId}`);
|
|
|
|
} else {
|
|
|
|
const post = await os.apiWithDialog('gallery/posts/create', {
|
|
|
|
title: this.title,
|
|
|
|
description: this.description,
|
|
|
|
fileIds: this.files.map(file => file.id),
|
|
|
|
isSensitive: this.isSensitive,
|
|
|
|
});
|
|
|
|
this.$router.push(`/gallery/${post.id}`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async del() {
|
2021-11-18 03:45:58 -06:00
|
|
|
const { canceled } = await os.confirm({
|
2021-04-25 21:10:45 -05:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$ts.deleteConfirm,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('gallery/posts/delete', {
|
|
|
|
postId: this.postId,
|
|
|
|
});
|
|
|
|
this.$router.push(`/gallery`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</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>
|