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> <script lang="ts" setup>
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { useDesign } from '@/hooks/web/useDesign' 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() const { getPrefixCls } = useDesign()
@ -11,6 +12,7 @@ const prop = defineProps({
data: propTypes.arrayOf(propTypes.any), data: propTypes.arrayOf(propTypes.any),
reset: propTypes.bool.def(false), reset: propTypes.bool.def(false),
width: propTypes.number.def(200), width: propTypes.number.def(200),
height: propTypes.number.def(0),
gap: propTypes.number.def(20), gap: propTypes.number.def(20),
getContainer: propTypes.func.def(() => document.body), getContainer: propTypes.func.def(() => document.body),
props: propTypes.objectOf(propTypes.string).def({ props: propTypes.objectOf(propTypes.string).def({
@ -27,7 +29,7 @@ const heights = ref<number[]>([])
const cols = ref(0) const cols = ref(0)
const filterWaterfall = async () => { const filterWaterfall = async () => {
const { props, width, gap, getContainer } = prop const { props, width, gap, getContainer, height } = prop
const data = prop.data as any[] const data = prop.data as any[]
await nextTick() await nextTick()
@ -38,20 +40,37 @@ const filterWaterfall = async () => {
const length = data.length const length = data.length
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if (i + 1 < unref(cols)) { if (i + 1 < unref(cols)) {
// if (height || data[i][props.height as string]) {
const height = data[i][props.height as string] // 使
if (height) { // data[i][props.height as string]
heights.value.push(height) 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 { } else {
await nextTick() //
const itemEl = container.querySelector(`.${prefixCls}-item__${i}`) const itemEl = container.querySelector(`.${prefixCls}-item__${i}`)
const rectObject = itemEl?.clientHeight itemEl?.addEventListener('load', () => {
console.log(rectObject) 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() filterWaterfall()
})
</script> </script>
<template> <template>
@ -60,8 +79,11 @@ filterWaterfall()
v-for="(item, $index) in data" v-for="(item, $index) in data"
:class="`${prefixCls}-item__${$index}`" :class="`${prefixCls}-item__${$index}`"
:key="`water-${$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>
</div> </div>
</template> </template>

View File

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