diff --git a/src/views/home/content/Content.vue b/src/views/home/content/Content.vue index 3805e0c..37ce72e 100644 --- a/src/views/home/content/Content.vue +++ b/src/views/home/content/Content.vue @@ -4,18 +4,15 @@ import { Download as DownloadIcon, Upload as UploadIcon } from '@vicons/tabler' import { Icon } from '@vicons/utils' import { useInfiniteScroll } from '@vueuse/core' import dayjs from 'dayjs' - -// import imagesloaded from 'imagesloaded' +import imagesloaded from 'imagesloaded' import { cloneDeep, debounce } from 'lodash-es' - -// import Masonry from 'masonry-layout' +import Masonry from 'masonry-layout' import { NIcon, useMessage } from 'naive-ui' import type { Component } from 'vue' import { computed, h, nextTick, - onBeforeMount, onMounted, onUnmounted, onUpdated, @@ -57,9 +54,9 @@ const listData = ref([]) const timer = ref() const showClose = ref(false) const deviceHeight = ref(600) -// let _masonry: null | Masonry = null -// let _imagesload: any -// const masonryRef = ref(null) +let _masonry: null | Masonry = null +let _imagesload: any +const masonryRef = ref(null) const el = ref(null) const viewMode = ref('masonry') const pagination = reactive({ @@ -104,36 +101,36 @@ const listStyle = computed(() => { } }) -// const layout = debounce(() => { -// if (masonryRef.value == null || el.value == null) -// return - -// if (_masonry !== null) -// (_masonry as any).addItems() - -// _masonry = new Masonry(masonryRef.value as any, { -// itemSelector: '.grid-item', -// gutter: 17, -// columnWidth: 182, -// percentPosition: true, -// stagger: 10, -// }) -// loading.value = false -// // 暂时注释,请忽略 -// _imagesload = imagesloaded('.grid-item') - -// _imagesload.on('done', (instance) => { -// (_masonry as any).layout() -// if (!el.value) -// return -// loading.value = false -// }) - -// _imagesload.on('fail', (instance) => { -// message.error('图片错误') -// loading.value = false -// }) -// }, 300) +const layout = debounce(() => { + if (masonryRef.value == null || el.value == null) + return + + if (_masonry !== null) + (_masonry as any).addItems() + + _masonry = new Masonry(masonryRef.value as any, { + itemSelector: '.grid-item', + gutter: 17, + columnWidth: 182, + percentPosition: true, + stagger: 10, + }) + loading.value = false + // 暂时注释,请忽略 + _imagesload = imagesloaded('.grid-item') + + _imagesload.on('done', (instance) => { + (_masonry as any).layout() + if (!el.value) + return + loading.value = false + }) + + _imagesload.on('fail', (instance) => { + message.error('图片错误') + loading.value = false + }) +}, 300) useInfiniteScroll( el as any, @@ -143,25 +140,12 @@ useInfiniteScroll( { distance: 10, canLoadMore: () => canloadMore }, ) -onBeforeMount(async () => { - const more = await featchList() - more.forEach((item) => { - item.calHeight = 182 * item.high / item.wide - }) - listData.value = more - const tmore = await featchList() - tmore.forEach((item) => { - item.calHeight = 182 * item.high / item.wide - }) - listData.value = listData.value.concat(tmore) -}) - onUpdated(() => { - // nextTick(() => { - // setTimeout(() => { - // layout() - // }, 50) - // }) + nextTick(() => { + setTimeout(() => { + layout() + }, 50) + }) }) const timeRange = ref('') @@ -173,6 +157,14 @@ const timeLabel = computed(() => { return item?.label }) +const viewLabel = computed(() => { + const item = viewOptions.find((option) => { + return option.value === viewMode.value + }) + + return item?.label +}) + const isAllowDownload = ref(true) const calNum = ref(0) const searchValue = ref('') @@ -262,48 +254,46 @@ async function featchList(userSearchId?: string) { const list = data.map((item) => { return { - calHeight: 0, imgUrl: item.imgurl, - thumburl: item.serverThumbnailUrl, + thumburl: item.serverThumbnailUrl || item.imgurl || bgLoadingImg, upname: item.upname, ocrPictureclass: item.ocrPictureclass, uphead: item.uphead, similar: item.similarityscore || -1, imgName: item.imgname, states: item.states, - wide: item.wide, - high: item.high, loadOver: false, + isRepeatHis: item.isRepeatHis, } }) - loading.value = false + return list } catch (error) { canloadMore = false - loading.value = false return [] } } async function loadMore() { - console.log('loading.value加兹安', loading.value, el.value) if (loading.value || el.value == null) return - canloadMore = false + const more = await featchList() - more.forEach((item) => { - item.calHeight = 182 * item.high / item.wide - }) - // listData.value.push(...more) - listData.value = listData.value.concat(more) - console.log('listData.value出来了', listData.value) + // if(isInitSeaerch.value) { + // listData.value = [] + // isInitSeaerch.value = false + // } + + console.log(more) + listData.value.push(...more) + console.log(listData.value) } const gridHeight = computed(() => { let height = '' if (viewMode.value === 'masonry') - height = 'auto' + height = '' else if (viewMode.value === 'horizontalVersion') height = '145px' else if (viewMode.value === 'verticalVersion') @@ -491,13 +481,9 @@ function reset() { canloadMore = true filterId = null - // layout() + layout() } -watch(listData.value, (newVal, oldVal) => { - console.log('最新的val', newVal) -}) - async function refreshHandler(filtersearchId?: any) { reset() @@ -657,16 +643,6 @@ const dropdownOptions = ref([ }, ]) -function finish() { - console.log('finish') -} - -function scroll() { - -} - -const masonryRef = ref(null) - defineExpose({ showLoginSuccessModal, closeLoginSuccessModal, @@ -739,117 +715,137 @@ defineExpose({ {{ totalCount }} 项 - -
- -
- 加载错误 - -