Add swiper for admin file

This commit is contained in:
ThatOneCalculator 2022-09-09 15:26:33 -07:00
parent d5ed3dbe9d
commit 038c367fd7
1 changed files with 96 additions and 56 deletions

View File

@ -1,8 +1,16 @@
<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]"
:space-between="20"
:virtual="true"
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide>
<MkSpacer :content-max="600" :margin-min="16" :margin-max="32">
<div class="cxqhhsmd _formRoot">
<a class="_formBlock thumbnail" :href="file.url" target="_blank"> <a class="_formBlock thumbnail" :href="file.url" target="_blank">
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/> <MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
</a> </a>
@ -39,7 +47,11 @@
<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>
</swiper-slide>
<swiper-slide>
<MkSpacer :content-max="600" :margin-min="16" :margin-max="32">
<div v-if="info" class="_formRoot">
<MkInfo v-if="!iAmAdmin" warn>{{ i18n.ts.requireAdminForView }}</MkInfo> <MkInfo v-if="!iAmAdmin" warn>{{ i18n.ts.requireAdminForView }}</MkInfo>
<MkKeyValue v-if="info.requestIp" class="_formBlock _monospace" :copy="info.requestIp" oneline> <MkKeyValue v-if="info.requestIp" class="_formBlock _monospace" :copy="info.requestIp" oneline>
<template #key>IP</template> <template #key>IP</template>
@ -53,16 +65,24 @@
</MkKeyValue> </MkKeyValue>
</FormSection> </FormSection>
</div> </div>
<div v-else-if="tab === 'raw'" class="_formRoot"> </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 v-if="info" tall :value="info">
</MkObjectView> </MkObjectView>
</div> </div>
</MkSpacer> </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>