2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
|
|
|
<div class="ztgjmzrw">
|
2021-04-22 22:29:33 +09:00
|
|
|
<MkButton @click="add()" primary style="margin: 0 auto 16px auto;"><i class="fas fa-plus"></i> {{ $ts.add }}</MkButton>
|
|
|
|
<section class="_card _gap announcements" v-for="announcement in announcements">
|
|
|
|
<div class="_content announcement">
|
2021-08-06 22:29:19 +09:00
|
|
|
<MkInput v-model="announcement.title">
|
|
|
|
<template #label>{{ $ts.title }}</template>
|
2021-04-22 22:29:33 +09:00
|
|
|
</MkInput>
|
2021-08-06 22:29:19 +09:00
|
|
|
<MkTextarea v-model="announcement.text">
|
|
|
|
<template #label>{{ $ts.text }}</template>
|
2021-04-22 22:29:33 +09:00
|
|
|
</MkTextarea>
|
2021-08-06 22:29:19 +09:00
|
|
|
<MkInput v-model="announcement.imageUrl">
|
|
|
|
<template #label>{{ $ts.imageUrl }}</template>
|
2021-04-22 22:29:33 +09:00
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">{{ $t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
|
|
|
<MkButton class="button" inline @click="save(announcement)" primary><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline @click="remove(announcement)"><i class="fas fa-trash-alt"></i> {{ $ts.remove }}</MkButton>
|
|
|
|
</div>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2021-04-22 22:29:33 +09:00
|
|
|
</section>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2021-03-23 17:30:14 +09:00
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
2021-09-30 00:50:45 +09:00
|
|
|
import MkInput from '@client/components/form/input.vue';
|
|
|
|
import MkTextarea from '@client/components/form/textarea.vue';
|
2021-03-23 17:30:14 +09:00
|
|
|
import * as os from '@client/os';
|
2021-04-10 12:54:12 +09:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkTextarea,
|
|
|
|
},
|
|
|
|
|
2021-04-22 22:29:33 +09:00
|
|
|
emits: ['info'],
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 12:54:12 +09:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts.announcements,
|
2021-10-02 23:11:21 +09:00
|
|
|
icon: 'fas fa-broadcast-tower',
|
|
|
|
bg: 'var(--bg)',
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
announcements: [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('admin/announcements/list').then(announcements => {
|
2020-01-30 04:37:25 +09:00
|
|
|
this.announcements = announcements;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-04-22 22:29:33 +09:00
|
|
|
mounted() {
|
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
methods: {
|
|
|
|
add() {
|
|
|
|
this.announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
|
|
|
imageUrl: null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
remove(announcement) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
this.announcements = this.announcements.filter(x => x != announcement);
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('admin/announcements/delete', announcement);
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('admin/announcements/create', announcement).then(() => {
|
|
|
|
os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'success',
|
2020-12-26 10:47:36 +09:00
|
|
|
text: this.$ts.saved
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('admin/announcements/update', announcement).then(() => {
|
|
|
|
os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'success',
|
2020-12-26 10:47:36 +09:00
|
|
|
text: this.$ts.saved
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2021-04-22 22:29:33 +09:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ztgjmzrw {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
</style>
|