2021-05-04 14:15:57 +02:00
|
|
|
<template>
|
2022-06-20 10:38:49 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<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>
|
|
|
|
<option value="square">square</option>
|
|
|
|
<option value="horizontal">horizontal</option>
|
|
|
|
<option value="horizontal-big">horizontal-big</option>
|
|
|
|
</FormRadios>
|
|
|
|
<!--
|
2021-10-23 21:03:07 +02:00
|
|
|
<div style="margin: 32px 0;">
|
2022-05-14 14:33:41 +02: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 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
-->
|
2022-06-20 10:38:49 +02:00
|
|
|
<FormSplit>
|
|
|
|
<MkInput v-model="ad.ratio" type="number">
|
|
|
|
<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">
|
|
|
|
<MkButton class="button" inline primary style="margin-right: 12px;" @click="save(ad)"><i class="fas fa-save"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline danger @click="remove(ad)"><i class="fas fa-trash-alt"></i> {{ i18n.ts.remove }}</MkButton>
|
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2021-05-04 14:15:57 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 14:33:41 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-06-20 10:38:49 +02:00
|
|
|
import XHeader from './_header_.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
2021-12-10 07:33:01 +01:00
|
|
|
import FormRadios from '@/components/form/radios.vue';
|
2021-12-30 13:47:48 +01:00
|
|
|
import FormSplit from '@/components/form/split.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-05-14 14:33:41 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-05-14 14:33:41 +02:00
|
|
|
let ads: any[] = $ref([]);
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-05-14 14:33:41 +02:00
|
|
|
os.api('admin/ad/list').then(adsResponse => {
|
|
|
|
ads = adsResponse;
|
|
|
|
});
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-05-14 14:33:41 +02:00
|
|
|
function add() {
|
|
|
|
ads.unshift({
|
|
|
|
id: null,
|
|
|
|
memo: '',
|
|
|
|
place: 'square',
|
|
|
|
priority: 'middle',
|
|
|
|
ratio: 1,
|
|
|
|
url: '',
|
|
|
|
imageUrl: null,
|
|
|
|
expiresAt: null,
|
|
|
|
});
|
|
|
|
}
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-05-14 14:33:41 +02: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 10:38:49 +02:00
|
|
|
id: ad.id,
|
2021-05-04 14:15:57 +02:00
|
|
|
});
|
2022-05-14 14:33:41 +02:00
|
|
|
});
|
|
|
|
}
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-05-14 14:33:41 +02:00
|
|
|
function save(ad) {
|
|
|
|
if (ad.id == null) {
|
|
|
|
os.apiWithDialog('admin/ad/create', {
|
|
|
|
...ad,
|
2022-06-20 10:38:49 +02:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2022-05-14 14:33:41 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.apiWithDialog('admin/ad/update', {
|
|
|
|
...ad,
|
2022-06-20 10:38:49 +02:00
|
|
|
expiresAt: new Date(ad.expiresAt).getTime(),
|
2022-05-14 14:33:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 14:15:57 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
|
|
|
icon: 'fas fa-plus',
|
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.ads,
|
|
|
|
icon: 'fas fa-audio-description',
|
2021-05-04 14:15:57 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.uqshojas {
|
2021-12-10 07:33:01 +01:00
|
|
|
> .ad {
|
|
|
|
padding: 32px;
|
|
|
|
|
|
|
|
&:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 14:15:57 +02:00
|
|
|
}
|
|
|
|
</style>
|