2021-05-04 21:15:57 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
2022-11-07 12:04:15 +09:00
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkSpacer :content-max="900">
|
|
|
|
<div class="uqshojas">
|
|
|
|
<div v-for="ad in ads" class="_panel _formRoot ad">
|
|
|
|
<MkAd v-if="ad.url" :specify="ad"/>
|
|
|
|
<MkInput v-model="ad.url" type="url" class="_formBlock">
|
|
|
|
<template #label>URL</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model="ad.imageUrl" class="_formBlock">
|
|
|
|
<template #label>{{ i18n.ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<FormRadios v-model="ad.place" class="_formBlock">
|
|
|
|
<template #label>Form</template>
|
2023-02-24 20:58:45 +09:00
|
|
|
<option value="widget">widget</option>
|
|
|
|
<option value="inline">inline</option>
|
|
|
|
<option value="inline-big">inline-big</option>
|
2022-06-20 17:38:49 +09:00
|
|
|
</FormRadios>
|
|
|
|
<FormSplit>
|
2023-02-24 20:58:45 +09:00
|
|
|
<MkInput :disabled="ad.place === 'widget'" v-model="ad.ratio" type="number">
|
2022-06-20 17:38:49 +09:00
|
|
|
<template #label>{{ i18n.ts.ratio }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model="ad.expiresAt" type="date">
|
|
|
|
<template #label>{{ i18n.ts.expiration }}</template>
|
|
|
|
</MkInput>
|
|
|
|
</FormSplit>
|
|
|
|
<MkTextarea v-model="ad.memo" class="_formBlock">
|
|
|
|
<template #label>{{ i18n.ts.memo }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<div class="buttons _formBlock">
|
2023-03-12 06:01:04 +09:00
|
|
|
<MkButton class="button" inline primary style="margin-right: 12px;" @click="save(ad)"><i class="ph-floppy-disk-back ph-bold ph-lg"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline danger @click="remove(ad)"><i class="ph-trash ph-bold ph-lg"></i> {{ i18n.ts.remove }}</MkButton>
|
2022-06-20 17:38:49 +09:00
|
|
|
</div>
|
2021-10-24 04:03:07 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2021-05-04 21:15:57 +09:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from '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';
|
2021-12-10 15:33:01 +09:00
|
|
|
import FormRadios from '@/components/form/radios.vue';
|
2021-12-30 21:47:48 +09:00
|
|
|
import FormSplit from '@/components/form/split.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-05-14 21:33:41 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-02-24 20:58:45 +09:00
|
|
|
import { formatDateTimeString } from '@/scripts/format-time-string';
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
let ads: any[] = $ref([]);
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
os.api('admin/ad/list').then(adsResponse => {
|
|
|
|
ads = adsResponse;
|
2023-02-24 20:58:45 +09:00
|
|
|
// The date format should be changed to yyyy-MM-dd in order to be properly displayed
|
|
|
|
for (let i in ads) {
|
|
|
|
ads[i].expiresAt = ads[i].expiresAt.substr(0, 10);
|
|
|
|
}
|
2022-05-14 21:33:41 +09:00
|
|
|
});
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
function add() {
|
2023-02-24 20:58:45 +09:00
|
|
|
const tomorrow = formatDateTimeString(new Date(new Date().setDate(new Date().getDate() + 1)), 'yyyy-MM-dd');
|
2022-05-14 21:33:41 +09:00
|
|
|
ads.unshift({
|
|
|
|
id: null,
|
|
|
|
memo: '',
|
2023-02-24 20:58:45 +09:00
|
|
|
place: 'widget',
|
2022-05-14 21:33:41 +09:00
|
|
|
priority: 'middle',
|
|
|
|
ratio: 1,
|
|
|
|
url: '',
|
|
|
|
imageUrl: null,
|
2023-02-24 20:58:45 +09:00
|
|
|
expiresAt: tomorrow,
|
2022-05-14 21:33:41 +09:00
|
|
|
});
|
|
|
|
}
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
function remove(ad) {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: ad.url }),
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
ads = ads.filter(x => x !== ad);
|
|
|
|
os.apiWithDialog('admin/ad/delete', {
|
2022-06-20 17:38:49 +09:00
|
|
|
id: ad.id,
|
2021-05-04 21:15:57 +09:00
|
|
|
});
|
2022-05-14 21:33:41 +09:00
|
|
|
});
|
|
|
|
}
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-05-14 21:33:41 +09:00
|
|
|
function save(ad) {
|
|
|
|
if (ad.id == null) {
|
|
|
|
os.apiWithDialog('admin/ad/create', {
|
|
|
|
...ad,
|
2022-06-20 17:38:49 +09:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2022-05-14 21:33:41 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.apiWithDialog('admin/ad/update', {
|
|
|
|
...ad,
|
2022-06-20 17:38:49 +09:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2022-05-14 21:33:41 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 21:15:57 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: 'ph-plus ph-bold ph-lg',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.ads,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: 'ph-money ph-bold ph-lg',
|
2021-05-04 21:15:57 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.uqshojas {
|
2021-12-10 15:33:01 +09:00
|
|
|
> .ad {
|
|
|
|
padding: 32px;
|
|
|
|
|
|
|
|
&:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 21:15:57 +09:00
|
|
|
}
|
|
|
|
</style>
|