Add swiper for admin file

This commit is contained in:
ThatOneCalculator 2022-09-09 15:26:33 -07:00
parent 837e662d42
commit 02bd60b1de

View file

@ -1,68 +1,88 @@
<template> <template>
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template> <template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer v-if="file" :content-max="600" :margin-min="16" :margin-max="32"> <swiper
<div v-if="tab === 'overview'" class="cxqhhsmd _formRoot"> :modules="[Virtual]"
<a class="_formBlock thumbnail" :href="file.url" target="_blank"> :space-between="20"
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/> :virtual="true"
</a> @swiper="setSwiperRef"
<div class="_formBlock"> @slide-change="onSlideChange"
<MkKeyValue :copy="file.type" oneline style="margin: 1em 0;"> >
<template #key>MIME Type</template> <swiper-slide>
<template #value><span class="_monospace">{{ file.type }}</span></template> <MkSpacer :content-max="600" :margin-min="16" :margin-max="32">
</MkKeyValue> <div class="cxqhhsmd _formRoot">
<MkKeyValue oneline style="margin: 1em 0;"> <a class="_formBlock thumbnail" :href="file.url" target="_blank">
<template #key>Size</template> <MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
<template #value><span class="_monospace">{{ bytes(file.size) }}</span></template> </a>
</MkKeyValue> <div class="_formBlock">
<MkKeyValue :copy="file.id" oneline style="margin: 1em 0;"> <MkKeyValue :copy="file.type" oneline style="margin: 1em 0;">
<template #key>ID</template> <template #key>MIME Type</template>
<template #value><span class="_monospace">{{ file.id }}</span></template> <template #value><span class="_monospace">{{ file.type }}</span></template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue :copy="file.md5" oneline style="margin: 1em 0;"> <MkKeyValue oneline style="margin: 1em 0;">
<template #key>MD5</template> <template #key>Size</template>
<template #value><span class="_monospace">{{ file.md5 }}</span></template> <template #value><span class="_monospace">{{ bytes(file.size) }}</span></template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;"> <MkKeyValue :copy="file.id" oneline style="margin: 1em 0;">
<template #key>{{ i18n.ts.createdAt }}</template> <template #key>ID</template>
<template #value><span class="_monospace"><MkTime :time="file.createdAt" mode="detail" style="display: block;"/></span></template> <template #value><span class="_monospace">{{ file.id }}</span></template>
</MkKeyValue> </MkKeyValue>
</div> <MkKeyValue :copy="file.md5" oneline style="margin: 1em 0;">
<MkA v-if="file.user" class="user" :to="`/user-info/${file.user.id}`"> <template #key>MD5</template>
<MkUserCardMini :user="file.user"/> <template #value><span class="_monospace">{{ file.md5 }}</span></template>
</MkA> </MkKeyValue>
<div class="_formBlock"> <MkKeyValue oneline style="margin: 1em 0;">
<MkSwitch v-model="isSensitive" @update:modelValue="toggleIsSensitive">NSFW</MkSwitch> <template #key>{{ i18n.ts.createdAt }}</template>
</div> <template #value><span class="_monospace"><MkTime :time="file.createdAt" mode="detail" style="display: block;"/></span></template>
</MkKeyValue>
</div>
<MkA v-if="file.user" class="user" :to="`/user-info/${file.user.id}`">
<MkUserCardMini :user="file.user"/>
</MkA>
<div class="_formBlock">
<MkSwitch v-model="isSensitive" @update:modelValue="toggleIsSensitive">NSFW</MkSwitch>
</div>
<div class="_formBlock"> <div class="_formBlock">
<MkButton danger @click="del"><i class="fas fa-trash-alt"></i> {{ i18n.ts.delete }}</MkButton> <MkButton danger @click="del"><i class="fas fa-trash-alt"></i> {{ i18n.ts.delete }}</MkButton>
</div> </div>
</div> </div>
<div v-else-if="tab === 'ip' && info" class="_formRoot"> </MkSpacer>
<MkInfo v-if="!iAmAdmin" warn>{{ i18n.ts.requireAdminForView }}</MkInfo> </swiper-slide>
<MkKeyValue v-if="info.requestIp" class="_formBlock _monospace" :copy="info.requestIp" oneline> <swiper-slide>
<template #key>IP</template> <MkSpacer :content-max="600" :margin-min="16" :margin-max="32">
<template #value>{{ info.requestIp }}</template> <div v-if="info" class="_formRoot">
</MkKeyValue> <MkInfo v-if="!iAmAdmin" warn>{{ i18n.ts.requireAdminForView }}</MkInfo>
<FormSection v-if="info.requestHeaders"> <MkKeyValue v-if="info.requestIp" class="_formBlock _monospace" :copy="info.requestIp" oneline>
<template #label>Headers</template> <template #key>IP</template>
<MkKeyValue v-for="(v, k) in info.requestHeaders" :key="k" class="_formBlock _monospace"> <template #value>{{ info.requestIp }}</template>
<template #key>{{ k }}</template> </MkKeyValue>
<template #value>{{ v }}</template> <FormSection v-if="info.requestHeaders">
</MkKeyValue> <template #label>Headers</template>
</FormSection> <MkKeyValue v-for="(v, k) in info.requestHeaders" :key="k" class="_formBlock _monospace">
</div> <template #key>{{ k }}</template>
<div v-else-if="tab === 'raw'" class="_formRoot"> <template #value>{{ v }}</template>
<MkObjectView v-if="info" tall :value="info"> </MkKeyValue>
</MkObjectView> </FormSection>
</div> </div>
</MkSpacer> </MkSpacer>
</swiper-slide>
<swiper-slide>
<MkSpacer :content-max="600" :margin-min="16" :margin-max="32">
<div class="_formRoot">
<MkObjectView v-if="info" tall :value="info">
</MkObjectView>
</div>
</MkSpacer>
</swiper-slide>
</swiper>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import MkSwitch from '@/components/form/switch.vue'; import MkSwitch from '@/components/form/switch.vue';
import MkObjectView from '@/components/MkObjectView.vue'; import MkObjectView from '@/components/MkObjectView.vue';
@ -77,8 +97,13 @@ import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { acct } from '@/filters/user'; import { acct } from '@/filters/user';
import { iAmAdmin, iAmModerator } from '@/account'; import { iAmAdmin, iAmModerator } from '@/account';
import 'swiper/scss';
import 'swiper/scss/virtual';
let tab = $ref('overview'); let tab = $ref('overview');
let tabs = ['overview'];
if (iAmModerator) tabs.push('ip');
tabs.push('raw');
let file: any = $ref(null); let file: any = $ref(null);
let info: any = $ref(null); let info: any = $ref(null);
let isSensitive: boolean = $ref(false); let isSensitive: boolean = $ref(false);
@ -138,6 +163,21 @@ definePageMetadata(computed(() => ({
title: file ? i18n.ts.file + ': ' + file.name : i18n.ts.file, title: file ? i18n.ts.file + ': ' + file.name : i18n.ts.file,
icon: 'fas fa-file', icon: 'fas fa-file',
}))); })));
let swiperRef = null;
function setSwiperRef(swiper) {
swiperRef = swiper;
syncSlide(tabs.indexOf(tab));
}
function onSlideChange() {
tab = tabs[swiperRef.activeIndex];
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>