2021-05-04 07:15:57 -05:00
|
|
|
<template>
|
2022-06-20 03:38:49 -05:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="900">
|
|
|
|
<div class="uqshojas">
|
2023-01-05 22:40:17 -06:00
|
|
|
<div v-for="ad in ads" class="_panel _gaps_m ad">
|
2022-06-20 03:38:49 -05:00
|
|
|
<MkAd v-if="ad.url" :specify="ad"/>
|
2023-01-05 06:04:56 -06:00
|
|
|
<MkInput v-model="ad.url" type="url">
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #label>URL</template>
|
|
|
|
</MkInput>
|
2023-01-05 06:04:56 -06:00
|
|
|
<MkInput v-model="ad.imageUrl">
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #label>{{ i18n.ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
2023-01-07 00:09:46 -06:00
|
|
|
<MkRadios v-model="ad.place">
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #label>Form</template>
|
|
|
|
<option value="square">square</option>
|
|
|
|
<option value="horizontal">horizontal</option>
|
|
|
|
<option value="horizontal-big">horizontal-big</option>
|
2023-01-07 00:09:46 -06:00
|
|
|
</MkRadios>
|
2022-06-20 03:38:49 -05:00
|
|
|
<!--
|
2021-10-23 14:03:07 -05:00
|
|
|
<div style="margin: 32px 0;">
|
2022-05-14 07:33:41 -05:00
|
|
|
{{ i18n.ts.priority }}
|
|
|
|
<MkRadio v-model="ad.priority" value="high">{{ i18n.ts.high }}</MkRadio>
|
|
|
|
<MkRadio v-model="ad.priority" value="middle">{{ i18n.ts.middle }}</MkRadio>
|
|
|
|
<MkRadio v-model="ad.priority" value="low">{{ i18n.ts.low }}</MkRadio>
|
2021-10-23 14:03:07 -05:00
|
|
|
</div>
|
|
|
|
-->
|
2022-06-20 03:38:49 -05:00
|
|
|
<FormSplit>
|
|
|
|
<MkInput v-model="ad.ratio" type="number">
|
|
|
|
<template #label>{{ i18n.ts.ratio }}</template>
|
|
|
|
</MkInput>
|
2023-02-14 23:31:59 -06:00
|
|
|
<MkInput v-model="ad.startsAt" type="datetime-local">
|
2023-02-14 23:29:40 -06:00
|
|
|
<template #label>{{ i18n.ts.startingperiod }}</template>
|
|
|
|
</MkInput>
|
2023-02-09 02:54:30 -06:00
|
|
|
<MkInput v-model="ad.expiresAt" type="datetime-local">
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #label>{{ i18n.ts.expiration }}</template>
|
|
|
|
</MkInput>
|
|
|
|
</FormSplit>
|
2023-01-05 06:04:56 -06:00
|
|
|
<MkTextarea v-model="ad.memo">
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #label>{{ i18n.ts.memo }}</template>
|
|
|
|
</MkTextarea>
|
2023-01-05 06:04:56 -06:00
|
|
|
<div class="buttons">
|
2022-12-19 04:01:30 -06:00
|
|
|
<MkButton class="button" inline primary style="margin-right: 12px;" @click="save(ad)"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline danger @click="remove(ad)"><i class="ti ti-trash"></i> {{ i18n.ts.remove }}</MkButton>
|
2022-06-20 03:38:49 -05:00
|
|
|
</div>
|
2021-10-23 14:03:07 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-20 03:38:49 -05:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2021-05-04 07:15:57 -05:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 07:33:41 -05:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-06-20 03:38:49 -05:00
|
|
|
import XHeader from './_header_.vue';
|
2022-09-06 04:21:49 -05:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 00:09:46 -06:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
2021-12-30 06:47:48 -06:00
|
|
|
import FormSplit from '@/components/form/split.vue';
|
2021-11-11 11:02:25 -06:00
|
|
|
import * as os from '@/os';
|
2022-05-14 07:33:41 -05:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 03:38:49 -05:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-05-14 07:33:41 -05:00
|
|
|
let ads: any[] = $ref([]);
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2023-02-11 17:23:14 -06:00
|
|
|
// ISO形式はTZがUTCになってしまうので、TZ分ずらして時間を初期化
|
|
|
|
const localTime = new Date();
|
|
|
|
const localTimeDiff = localTime.getTimezoneOffset() * 60 * 1000;
|
|
|
|
|
2022-05-14 07:33:41 -05:00
|
|
|
os.api('admin/ad/list').then(adsResponse => {
|
2023-02-09 02:54:30 -06:00
|
|
|
ads = adsResponse.map(r => {
|
2023-02-14 23:29:40 -06:00
|
|
|
const exdate = new Date(r.expiresAt);
|
2023-02-14 23:31:59 -06:00
|
|
|
const stdate = new Date(r.startsAt);
|
2023-02-14 23:29:40 -06:00
|
|
|
exdate.setMilliseconds(exdate.getMilliseconds() - localTimeDiff);
|
|
|
|
stdate.setMilliseconds(stdate.getMilliseconds() - localTimeDiff);
|
2023-02-09 02:54:30 -06:00
|
|
|
return {
|
|
|
|
...r,
|
2023-02-14 23:29:40 -06:00
|
|
|
expiresAt: exdate.toISOString().slice(0, 16),
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: stdate.toISOString().slice(0, 16),
|
2023-02-09 02:54:30 -06:00
|
|
|
};
|
|
|
|
});
|
2022-05-14 07:33:41 -05:00
|
|
|
});
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-05-14 07:33:41 -05:00
|
|
|
function add() {
|
|
|
|
ads.unshift({
|
|
|
|
id: null,
|
|
|
|
memo: '',
|
|
|
|
place: 'square',
|
|
|
|
priority: 'middle',
|
|
|
|
ratio: 1,
|
|
|
|
url: '',
|
|
|
|
imageUrl: null,
|
|
|
|
expiresAt: null,
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: null,
|
2022-05-14 07:33:41 -05:00
|
|
|
});
|
|
|
|
}
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-05-14 07:33:41 -05: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 03:38:49 -05:00
|
|
|
id: ad.id,
|
2021-05-04 07:15:57 -05:00
|
|
|
});
|
2022-05-14 07:33:41 -05:00
|
|
|
});
|
|
|
|
}
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-05-14 07:33:41 -05:00
|
|
|
function save(ad) {
|
|
|
|
if (ad.id == null) {
|
|
|
|
os.apiWithDialog('admin/ad/create', {
|
|
|
|
...ad,
|
2022-06-20 03:38:49 -05:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: new Date(ad.startsAt).getTime(),
|
2022-05-14 07:33:41 -05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.apiWithDialog('admin/ad/update', {
|
|
|
|
...ad,
|
2022-06-20 03:38:49 -05:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2023-02-14 23:31:59 -06:00
|
|
|
startsAt: new Date(ad.startsAt).getTime(),
|
2022-05-14 07:33:41 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 07:15:57 -05:00
|
|
|
|
2022-06-20 03:38:49 -05:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-plus',
|
2022-06-20 03:38:49 -05:00
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.ads,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-ad',
|
2021-05-04 07:15:57 -05:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 03:29:39 -06:00
|
|
|
<style lang="scss" scoped>
|
2021-05-04 07:15:57 -05:00
|
|
|
.uqshojas {
|
2021-12-10 00:33:01 -06:00
|
|
|
> .ad {
|
|
|
|
padding: 32px;
|
|
|
|
|
|
|
|
&:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 07:15:57 -05:00
|
|
|
}
|
|
|
|
</style>
|