wip: coding

This commit is contained in:
kailong321200875 2023-10-07 08:48:10 +08:00
parent cd774ccc0c
commit 90eb00f869
2 changed files with 33 additions and 13 deletions

View File

@ -1,7 +1,8 @@
<script lang="ts" setup>
import { propTypes } from '@/utils/propTypes'
import { useDesign } from '@/hooks/web/useDesign'
import { ref, nextTick, unref } from 'vue'
import { ref, nextTick, unref, onMounted } from 'vue'
import { isString } from '@/utils/is'
const { getPrefixCls } = useDesign()
@ -11,6 +12,7 @@ const prop = defineProps({
data: propTypes.arrayOf(propTypes.any),
reset: propTypes.bool.def(false),
width: propTypes.number.def(200),
height: propTypes.number.def(0),
gap: propTypes.number.def(20),
getContainer: propTypes.func.def(() => document.body),
props: propTypes.objectOf(propTypes.string).def({
@ -27,7 +29,7 @@ const heights = ref<number[]>([])
const cols = ref(0)
const filterWaterfall = async () => {
const { props, width, gap, getContainer } = prop
const { props, width, gap, getContainer, height } = prop
const data = prop.data as any[]
await nextTick()
@ -38,20 +40,37 @@ const filterWaterfall = async () => {
const length = data.length
for (let i = 0; i < length; i++) {
if (i + 1 < unref(cols)) {
//
const height = data[i][props.height as string]
if (height) {
heights.value.push(height)
if (height || data[i][props.height as string]) {
// 使
// data[i][props.height as string]
const itemHeight = isString(data[i][props.height as string])
? Number(data[i][props.height as string].replace(/[^0-9]/gi, ''))
: data[i][props.height as string]
heights.value[i] = height || itemHeight
} else {
await nextTick()
//
const itemEl = container.querySelector(`.${prefixCls}-item__${i}`)
const rectObject = itemEl?.clientHeight
console.log(rectObject)
itemEl?.addEventListener('load', () => {
const clientRect = itemEl?.getBoundingClientRect()
console.log(clientRect)
})
// const imgEl = new Image()
// imgEl.src = data[i][props.src as string]
// imgEl.onload = async () => {
// // const itemEl = container.querySelector(`.${prefixCls}-item__${i}`)
// const clientRect = itemEl?.getBoundingClientRect()
// if (clientRect) {
// heights.value[i] = clientRect?.height
// }
// }
}
}
}
}
onMounted(() => {
filterWaterfall()
})
</script>
<template>
@ -60,8 +79,11 @@ filterWaterfall()
v-for="(item, $index) in data"
:class="`${prefixCls}-item__${$index}`"
:key="`water-${$index}`"
:style="{
width: `${width}px`
}"
>
<img :src="item[props.src as string]" alt="" srcset="" />
<img :src="item[props.src as string]" class="w-full block" alt="" srcset="" />
</div>
</div>
</template>

View File

@ -1,5 +1,3 @@
// import type { Plugin } from 'vue'
/**
*
* @param component