2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="900">
|
|
|
|
<div class="ztgjmzrw">
|
|
|
|
<section v-for="announcement in announcements" class="_card _gap announcements">
|
|
|
|
<div class="_content announcement">
|
|
|
|
<MkInput v-model="announcement.title">
|
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="announcement.text">
|
|
|
|
<template #label>{{ i18n.ts.text }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model="announcement.imageUrl">
|
|
|
|
<template #label>{{ i18n.ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">{{ i18n.t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
2022-11-07 11:49:47 +09:00
|
|
|
<MkButton class="button" inline primary @click="save(announcement)"><i class="ph-floppy-disk-back-bold ph-lg"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline @click="remove(announcement)"><i class="ph-trash-bold ph-lg"></i> {{ i18n.ts.remove }}</MkButton>
|
2022-06-20 17:38:49 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
2021-10-24 04:03:07 +09:00
|
|
|
</div>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-06-20 17:38:49 +09:00
|
|
|
import XHeader from './_header_.vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import * as os from '@/os';
|
2022-05-14 21:34:07 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
let announcements: any[] = $ref([]);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
os.api('admin/announcements/list').then(announcementResponse => {
|
|
|
|
announcements = announcementResponse;
|
|
|
|
});
|
2021-04-22 22:29:33 +09:00
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
function add() {
|
|
|
|
announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
2022-06-20 17:38:49 +09:00
|
|
|
imageUrl: null,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
function remove(announcement) {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
announcements = announcements.filter(x => x !== announcement);
|
|
|
|
os.api('admin/announcements/delete', announcement);
|
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
function save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
|
|
|
os.api('admin/announcements/create', announcement).then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.saved,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2022-05-14 21:34:07 +09:00
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: err,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.api('admin/announcements/update', announcement).then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.saved,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: err,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
2022-11-07 11:49:47 +09:00
|
|
|
icon: 'ph-plus-bold ph-lg',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2022-11-07 11:49:47 +09:00
|
|
|
icon: 'ph-megaphone-simple-bold ph-lg',
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|
2021-04-22 22:29:33 +09:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ztgjmzrw {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
</style>
|