modal-floder-view.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <ui-group v-if="floders.length">
  3. <ui-group-option>
  4. <span @click="canAll && (showAll = !showAll)" :class="{ ['fun-ctrl']: canAll }">
  5. <template v-if="canAll">
  6. <UpOutlined v-if="showAll" />
  7. <DownOutlined v-else />
  8. </template>
  9. {{ root.title }}
  10. </span>
  11. </ui-group-option>
  12. <ui-group-option>
  13. <div class="items">
  14. <div
  15. class="img-item"
  16. v-for="(_, i) in showLen"
  17. :key="floders[i].filesId"
  18. :style="{ '--rawLen': samLen }"
  19. >
  20. <div class="img-item-content">
  21. <div>
  22. <Sign
  23. :media="{ url: floders[i].filesUrl }"
  24. @click="clickHandler(floders[i])"
  25. />
  26. </div>
  27. <!-- <img :src="floders[i].filesUrl" /> -->
  28. </div>
  29. </div>
  30. </div>
  31. </ui-group-option>
  32. </ui-group>
  33. <Tabs v-if="!emptyTabs" v-model:activeKey="activeTab" class="f-tabs">
  34. <template v-for="children in root.children">
  35. <TabPane
  36. :tab="children.title"
  37. :key="children.id"
  38. v-if="getFlatFloders(children).length"
  39. >
  40. <ModalFloderView :root="children" @preview="(v: any) => emit('preview', v)" />
  41. </TabPane>
  42. </template>
  43. </Tabs>
  44. <template v-for="c in children" :key="c.id">
  45. <ModalFloderView
  46. :root="c"
  47. v-if="isLastLevel(c)"
  48. @preview="(v: any) => emit('preview', v)"
  49. />
  50. </template>
  51. </template>
  52. <script lang="ts" setup>
  53. import { Floder, FloderRoot, getFlatFloders } from "@/store";
  54. import { computed, ref } from "vue";
  55. import { TabPane, Tabs } from "ant-design-vue";
  56. import { DownOutlined, UpOutlined } from "@ant-design/icons-vue";
  57. import Sign from "@/components/static-preview/sign.vue";
  58. const props = defineProps<{ root: FloderRoot }>();
  59. const emit = defineEmits<{ (e: "preview", v: [Floder, FloderRoot]): void }>();
  60. const isLastLevel = (root: FloderRoot) => {
  61. return !root.children?.length;
  62. };
  63. const emptyTabs = computed(
  64. () => props.root.children?.every((r) => isLastLevel(r)) && !props.root.flat
  65. );
  66. const oneTabs = computed(() => {
  67. if (!emptyTabs.value) return null;
  68. return props.root.children!.find((i) => !isLastLevel(i));
  69. });
  70. const clickHandler = (floder: Floder) => {
  71. emit("preview", [floder, props.root]);
  72. };
  73. const activeTab = ref(oneTabs.value?.id);
  74. const floders = computed(() => {
  75. if (props.root.flat) {
  76. return getFlatFloders(props.root);
  77. } else {
  78. return props.root.floders;
  79. }
  80. });
  81. const children = computed(() => {
  82. if (props.root.flat) {
  83. return [];
  84. } else {
  85. return props.root.children;
  86. }
  87. });
  88. const len = computed(() => floders.value.length);
  89. const showAll = ref(false);
  90. const samLen = 6;
  91. const showLen = computed(() => (showAll.value ? len.value : Math.min(samLen, len.value)));
  92. const canAll = computed(() => len.value > samLen);
  93. </script>
  94. <style lang="scss" scoped>
  95. .items {
  96. display: flex;
  97. flex-wrap: wrap;
  98. }
  99. .img-item {
  100. width: calc(100% / var(--rawLen));
  101. padding-right: 5px;
  102. .img-item-content {
  103. padding-top: 56.25%;
  104. position: relative;
  105. cursor: pointer;
  106. > div {
  107. position: absolute;
  108. width: 100%;
  109. height: 100%;
  110. left: 0;
  111. top: 0;
  112. object-fit: cover;
  113. }
  114. }
  115. }
  116. .mySwiper {
  117. --swiper-pagination-fraction-color: #000;
  118. --swiper-theme-color: #03ad98;
  119. --swiper-navigation-size: 30px;
  120. }
  121. </style>
  122. <style>
  123. .f-tabs.ant-tabs-top > .ant-tabs-nav {
  124. margin-bottom: 30px;
  125. }
  126. .f-tabs.ant-tabs-top > .ant-tabs-nav::before {
  127. display: none !important;
  128. }
  129. </style>