Skip to content

Commit 1aae907

Browse files
aQingYun7insummer
authored andcommitted
fix:解决water-flow组件bug (#358)
1 parent b52c387 commit 1aae907

File tree

9 files changed

+108
-6
lines changed

9 files changed

+108
-6
lines changed
File renamed without changes.

components/water-flow/index.json renamed to dist/water-flow/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"component": true,
33
"usingComponents": {},
44
"componentGenerics": {
5-
"l-water-flow-item": true
5+
"l-water-flow-item": "true"
66
}
77
}
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"component": true,
3-
"componentGenerics": {
4-
"l-water-flow-item": true
5-
}
6-
}
2+
"component": true,
3+
"usingComponents": {},
4+
"componentGenerics": {
5+
"l-water-flow-item": "true"
6+
}
7+
}

src/water-flow/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// pages/components/water/index.js
2+
Component({
3+
/**
4+
* 组件的属性列表
5+
*/
6+
properties: {
7+
columnGap: {
8+
type: String,
9+
value: '20rpx'
10+
}
11+
},
12+
13+
/**
14+
* 组件的初始数据
15+
*/
16+
data: {
17+
data: [],
18+
leftData: [],
19+
rightData: []
20+
},
21+
22+
attached() {
23+
this._init()
24+
},
25+
26+
/**
27+
* 组件的方法列表
28+
*/
29+
methods: {
30+
_init() {
31+
wx.lin = wx.lin || {}
32+
wx.lin.renderWaterFlow = (data = [], success) => {
33+
if (Object.prototype.toString.call(data) !== '[object Array]') {
34+
console.error("[data]参数类型错误,渲染失败");
35+
return false;
36+
}
37+
this._select(data).then(() => {
38+
success && success()
39+
})
40+
}
41+
},
42+
_select(data) {
43+
const query = wx.createSelectorQuery().in(this)
44+
this.columnNodes = query.selectAll('#left, #right')
45+
46+
return new Promise((resolve, reject) => {
47+
this._render(data, 0, () => {
48+
resolve()
49+
})
50+
})
51+
},
52+
_render(data, i, success) {
53+
if (data.length > i) {
54+
this.columnNodes.boundingClientRect().exec(res => {
55+
const rects = res[0]
56+
const leftHeight = rects[0].height
57+
const rightHeight = rects[1].height
58+
59+
if (leftHeight <= rightHeight) {
60+
this.data.leftData.push(data[i])
61+
} else {
62+
this.data.rightData.push(data[i])
63+
}
64+
65+
this.setData({
66+
leftData: this.data.leftData,
67+
rightData: this.data.rightData
68+
}, _ => {
69+
this._render(data, ++i, success)
70+
})
71+
})
72+
} else {
73+
success && success()
74+
}
75+
}
76+
}
77+
})

src/water-flow/index.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"component": true,
3+
"usingComponents": {},
4+
"componentGenerics": {
5+
"l-water-flow-item": "true"
6+
}
7+
}

src/water-flow/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.water-flow-container{display:flex;width:100%;box-sizing:border-box}.water-column{flex:1}

src/water-flow/index.wxml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<view class="l-class water-flow-container">
2+
<view class="water-column" style="margin-right:{{columnGap}}">
3+
<view id="left">
4+
<block wx:for="{{leftData}}" wx:key="{{index}}">
5+
<l-water-flow-item data="{{item}}" />
6+
</block>
7+
</view>
8+
</view>
9+
<view class="water-column">
10+
<view id="right">
11+
<block wx:for="{{rightData}}" wx:key="{{index}}">
12+
<l-water-flow-item data="{{item}}" />
13+
</block>
14+
</view>
15+
</view>
16+
</view>

0 commit comments

Comments
 (0)