Commit d9a0d920 by 李伟康

refactor(CustomerOpportunities): 优化表格标签显示逻辑

- 使用 Promise 重构标签查询逻辑,提高异步处理准确性
- 修改 showTagMore 方法参数结构,传递 listItem 数据对象
- 添加 .in(this) 作用域查询确保组件内元素定位准确
- 优化标签截取宽度计算逻辑,增加边界条件判断
- 移除 immediate watch 选项避免初始化时的重复执行
- 改进标签溢出检测算法,提升多行标签显示效果
1 parent 30c0796a
......@@ -86,14 +86,18 @@ export default {
watch: {
list: {
handler(val) {
let query = uni.createSelectorQuery().in(this)
this.tableData = val
this.$nextTick(() => {
val.forEach((item, index) => {
this.showTagMore(item.tagList, index)
query.select(`#tag-list-${index}`).boundingClientRect((data) => {
this.showTagMore(item.tagList, index, data)
}).exec()
})
})
},
immediate: true,
// immediate: true,
deep: true
}
},
......@@ -134,29 +138,35 @@ export default {
orderHandleTime(time) {
return time ? dayjs(time).format('YYYY-MM-DD') : ''
},
showTagMore(tags, index) {
let query = uni.createSelectorQuery(),
listItem = null,
showTagMore(tags, index, listItem) {
let query = uni.createSelectorQuery().in(this),
_this = this,
targetIndex = 0
this.$nextTick(() => {
try {
query.select(`#tag-list-${index}`).boundingClientRect((data) => {
listItem = data
}).exec()
tags?.forEach((tag, tagIndex) => {
query.select(`#tag-${index}-${tagIndex}`).boundingClientRect((data) => {
if (listItem && data.top > (listItem.height + listItem.top) && !targetIndex) targetIndex = tagIndex - 1
}).exec()
const promise = new Promise((resolve, reject) => {
tags?.map((tag, tagIndex) => {
query.select(`#tag-${index}-${tagIndex}`).boundingClientRect((data) => {
if (listItem && data.top > (listItem.height + listItem.top) && !targetIndex) {
targetIndex = tagIndex - 1
}
if (targetIndex) resolve(targetIndex)
}).exec()
})
})
if (targetIndex != 0) query.select(`#tag-${index}-${targetIndex}`).boundingClientRect((data) => {
let listWidth = listItem.left + listItem.width,
cutWidth = data.left + data.width
if (cutWidth + 34 < listWidth) targetIndex += 1
}).exec()
if (targetIndex) {
this.$set(this.tableData[index], 'tagList', tags.slice(0, targetIndex))
this.$set(this.tableData[index], 'hasMoreTags', true)
}
promise.then(cutIndex => {
console.log(cutIndex)
this.$nextTick(() => {
if (cutIndex != 0) query.select(`#tag-${index}-${cutIndex}`).boundingClientRect((data) => {
let listWidth = listItem.left + listItem.width,
cutWidth = data.left + data.width
if (cutWidth + 34 < listWidth) cutIndex += 1
_this.$set(_this.tableData[index], 'tagList', tags.slice(0, cutIndex))
_this.$set(_this.tableData[index], 'hasMoreTags', true)
}).exec()
})
})
} catch (error) {
console.log(error)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!