Commit d9a0d920 by 李伟康

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

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