@soei/flyweight 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -5
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +95 -62
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/Flyweight.vue +68 -29
package/README.md
CHANGED
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
# 享元模式
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 更新日志
|
|
4
|
+
|
|
5
|
+
### `0.0.2`
|
|
6
|
+
|
|
7
|
+
- #### 优化了 `Vue3` 的 `兼容` 问题
|
|
8
|
+
|
|
9
|
+
`Vue3` 引入方式
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script>
|
|
13
|
+
import { Flyweight } from "@soei/flyweight";
|
|
14
|
+
</script>
|
|
15
|
+
<!-- 非 <style scoped> scoped-->
|
|
16
|
+
<style>
|
|
17
|
+
@import "@soei/flyweight/dist/style.css";
|
|
18
|
+
</style>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`或` 源码引入
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import Flyweight from "@soei/flyweight/src/Flyweight.vue";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`或`
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
// main.js
|
|
31
|
+
import "@soei/flyweight/dist/style.css";
|
|
32
|
+
import flyweight from "@soei/flyweight";
|
|
33
|
+
Vue.use(flyweight);
|
|
34
|
+
// use.vue
|
|
35
|
+
<s-flyweight ...></s-flyweight>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## `安装`
|
|
4
39
|
|
|
5
40
|
```
|
|
6
41
|
npm i @soei/flyweight
|
|
7
42
|
|
|
8
43
|
```
|
|
9
44
|
|
|
10
|
-
|
|
45
|
+
## `引用`
|
|
11
46
|
|
|
12
47
|
```javascript
|
|
13
48
|
// 引入方式 vue2
|
|
14
49
|
import Flyweight from "@soei/flyweight/src/Flyweight.vue";
|
|
15
|
-
// 引入方式
|
|
50
|
+
// 引入方式 Vue3
|
|
16
51
|
import { Flyweight } from "@soei/flyweight";
|
|
17
52
|
```
|
|
18
53
|
|
|
19
|
-
|
|
54
|
+
## `使用`
|
|
20
55
|
|
|
21
56
|
```html
|
|
22
57
|
<Flyweight
|
|
@@ -31,3 +66,72 @@ import { Flyweight } from "@soei/flyweight";
|
|
|
31
66
|
<template #default="{data, index}"> ...todo </template>
|
|
32
67
|
</Flyweight>
|
|
33
68
|
```
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<Flyweight [attrs]></Flyweight>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## `index` 和 `view` 只生效一个
|
|
75
|
+
|
|
76
|
+
### _`index`_ 定位索引
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// 格式
|
|
80
|
+
Number;
|
|
81
|
+
:index="10";
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### _`view`_ 指定显示哪个索引
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// 格式
|
|
88
|
+
{
|
|
89
|
+
// 定位属性
|
|
90
|
+
id: Number,
|
|
91
|
+
// 定位属性字段名称
|
|
92
|
+
picker: String
|
|
93
|
+
}
|
|
94
|
+
:view="{id: 10, picker: 'id'}";
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### _`flys`_ 显示的`数据列表`
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// 格式
|
|
101
|
+
Array;
|
|
102
|
+
:flys="[]";
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### _`width`_ 单个容器 `宽度`
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
// 格式
|
|
109
|
+
Number;
|
|
110
|
+
// 默认: 0, 占整行
|
|
111
|
+
:width="100";
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### _`height`_ 单个容器 `高度`
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
// 格式
|
|
118
|
+
Number;
|
|
119
|
+
// 默认: 100
|
|
120
|
+
:height="10";
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### _`offset`_ 偏移量 _[`左右`, `上下`]_
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
// 格式
|
|
127
|
+
Array = [左右, 上下];
|
|
128
|
+
:offset="[0, 30]";
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### `@onend` 拉到`底部`时的回调
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// 格式
|
|
135
|
+
Function;
|
|
136
|
+
@onend="function(){}";
|
|
137
|
+
```
|
package/dist/Flyweight.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("@soei/util"),h=require("vue");const p=(e,t)=>{const i=e.__vccOpts||e;for(const[r,s]of t)i[r]=s;return i};let m=e=>e==null||e==null,x=(...e)=>{console.info("::::FLYWEIGHT",...e)};const k={name:"Flyweight",props:{flys:{type:Array,default:()=>[]},width:{type:Number,default:0},height:{type:Number,default:100},offset:{type:Array,default:()=>[0,0]},lazy:{type:Number,default:100},view:{type:Object,default:()=>null},index:{type:Number,default:0}},computed:{flyweight(){return this.$refs.flyweight}},data(){return{flyweights:[],actice:!1,Height:null,column:1,row:1,fwheight:10,count:0,task:[]}},watch:{flys(e){this.count=e.length,this.re();let t=this.task.shift();t&&this.$nextTick(()=>{this.setview(t)})},view:{handler(e){this.setview(e)},immediate:!0},index(e){this.setindex(e)}},mounted(){this.flyweights=[],this.$set||(this.$set=(e,t,i)=>{e[t]=i}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){x(e)}},methods:{cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){f.runer([this.cheackflys,t=>{t=t||{};let i=t.index||f.each(this.flys,(r,s,n,l)=>{if(s[n]==l)return r},t.picker,t.id);m(i)||this.setindex(i)}],this,e)},setindex(e){f.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let i=t/this.column>>0,r=this.fwheight;(this.flyweight.scrollTop/r>>0)+this.row-i-1>0||(this.flyweight.scrollTop=i*r,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{f.runer(e)},t||this.lazy)},run(e){let t=f.picker(e.target,"scrollTop=>top");f.each(this.flyweights,(i,r,s,n,l,o,u,d)=>{if(s=i/l>>0,u=s+n*(+(s<o%n)+(o/n>>0)),d=u*l+i%l,d>=this.count){this.lazyrun(()=>this.$emit("onend",!0));return}r.index=u,r.top=r.index*this.fwheight,r.data=this.flys[d]},null,this.row,this.column,t.top/this.fwheight>>0)},scroll(e){this.run(e||{target:this.flyweight})},re(){let e=this.flyweight,t=f.picker(e,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let[i,r]=this.offset,s=this.width;s==0&&(s=t.width);let n=s+i,l=this.height+r,o=t.width/n>>0,u=t.height/l>>0;this.row=u+2,this.column=o,this.fwheight=l;let d=t.width%n/(o-1)>>0;this.Height=Math.ceil(this.count/o)*l;let y=Math.min(this.count,o*this.row),a=y-1,c,g;for(;y-- >0;)c=a-y,g=this.flys[c],e=this.flyweights[c],this.$set(this.flyweights,c,{data:g,top:(c/o>>0)*l,left:c%o*(n+d),index:c/o>>0});this.flyweights.length=a+1,this.scroll()})}}};function _(e,t,i,r,s,n){return h.openBlock(),h.createElementBlock("div",{ref:"flyweight",class:h.normalizeClass(["flyweight",{"flyweight-active":s.actice}]),style:h.normalizeStyle({"--width":i.width?i.width+"px":"100%","--height":i.height+"px"}),onScroll:t[0]||(t[0]=(...l)=>n.scroll&&n.scroll(...l))},[h.createElementVNode("div",{class:"flyweight-all",style:h.normalizeStyle({"--flyweight-height":s.Height+"px"})},[(h.openBlock(!0),h.createElementBlock(h.Fragment,null,h.renderList(s.flyweights,(l,o)=>(h.openBlock(),h.createElementBlock("div",{key:o,style:h.normalizeStyle({top:l.top+"px",left:l.left+"px"})},[h.renderSlot(e.$slots,"default",{data:l.data,index:l.index},void 0,!0)],4))),128))],4),s.flyweights.length?h.renderSlot(e.$slots,"end",{key:0},void 0,!0):h.createCommentVNode("",!0)],38)}const w=p(k,[["render",_],["__scopeId","data-v-d96197a5"]]),v=[w],z={install(e){v.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=w;exports.default=z;
|
package/dist/Flyweight.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { openBlock as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
for (const [
|
|
6
|
-
l
|
|
7
|
-
return
|
|
1
|
+
import { runer as d, each as m, picker as x } from "@soei/util";
|
|
2
|
+
import { openBlock as y, createElementBlock as g, normalizeClass as k, normalizeStyle as w, createElementVNode as v, Fragment as z, renderList as b, renderSlot as _, createCommentVNode as T } from "vue";
|
|
3
|
+
const N = (t, e) => {
|
|
4
|
+
const i = t.__vccOpts || t;
|
|
5
|
+
for (const [l, s] of e)
|
|
6
|
+
i[l] = s;
|
|
7
|
+
return i;
|
|
8
8
|
};
|
|
9
|
-
let
|
|
9
|
+
let $ = (t) => t == null || t == null, F = (...t) => {
|
|
10
10
|
console.info("::::FLYWEIGHT", ...t);
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const H = {
|
|
13
|
+
name: "Flyweight",
|
|
13
14
|
props: {
|
|
14
15
|
flys: {
|
|
15
16
|
type: Array,
|
|
@@ -33,7 +34,7 @@ const N = {
|
|
|
33
34
|
},
|
|
34
35
|
view: {
|
|
35
36
|
type: Object,
|
|
36
|
-
default: () =>
|
|
37
|
+
default: () => null
|
|
37
38
|
},
|
|
38
39
|
index: {
|
|
39
40
|
type: Number,
|
|
@@ -49,122 +50,154 @@ const N = {
|
|
|
49
50
|
return {
|
|
50
51
|
flyweights: [],
|
|
51
52
|
actice: !1,
|
|
52
|
-
|
|
53
|
+
Height: null,
|
|
53
54
|
column: 1,
|
|
54
55
|
row: 1,
|
|
55
56
|
fwheight: 10,
|
|
56
|
-
count: 0
|
|
57
|
+
count: 0,
|
|
58
|
+
task: []
|
|
57
59
|
};
|
|
58
60
|
},
|
|
59
61
|
watch: {
|
|
60
62
|
flys(t) {
|
|
61
63
|
this.count = t.length, this.re();
|
|
64
|
+
let e = this.task.shift();
|
|
65
|
+
e && this.$nextTick(() => {
|
|
66
|
+
this.setview(e);
|
|
67
|
+
});
|
|
62
68
|
},
|
|
63
|
-
view
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.$emit("update:index", e);
|
|
69
|
+
view: {
|
|
70
|
+
handler(t) {
|
|
71
|
+
this.setview(t);
|
|
72
|
+
},
|
|
73
|
+
immediate: !0
|
|
69
74
|
},
|
|
70
75
|
index(t) {
|
|
71
|
-
|
|
72
|
-
(this.flyweight.scrollTop / this.fwheight >> 0) + this.row - e - 1 > 0 || (this.flyweight.scrollTop = e * this.fwheight);
|
|
76
|
+
this.setindex(t);
|
|
73
77
|
}
|
|
74
78
|
},
|
|
75
79
|
mounted() {
|
|
76
|
-
this.flyweights = []
|
|
80
|
+
this.flyweights = [], this.$set || (this.$set = (t, e, i) => {
|
|
81
|
+
t[e] = i;
|
|
82
|
+
}), this.setindex(this.index);
|
|
77
83
|
try {
|
|
78
84
|
new ResizeObserver(() => {
|
|
79
85
|
this.re(), this.$emit("resize");
|
|
80
86
|
}).observe(this.flyweight);
|
|
81
87
|
} catch (t) {
|
|
82
|
-
|
|
88
|
+
F(t);
|
|
83
89
|
}
|
|
84
90
|
},
|
|
85
91
|
methods: {
|
|
92
|
+
cheackflys(t) {
|
|
93
|
+
if (!this.flys.length)
|
|
94
|
+
return t && this.task.push(t), !0;
|
|
95
|
+
},
|
|
96
|
+
setview(t) {
|
|
97
|
+
d([this.cheackflys, (e) => {
|
|
98
|
+
e = e || {};
|
|
99
|
+
let i = e.index || m(this.flys, (l, s, n, h) => {
|
|
100
|
+
if (s[n] == h)
|
|
101
|
+
return l;
|
|
102
|
+
}, e.picker, e.id);
|
|
103
|
+
$(i) || this.setindex(i);
|
|
104
|
+
}], this, t);
|
|
105
|
+
},
|
|
106
|
+
setindex(t) {
|
|
107
|
+
d([this.cheackflys, ({ index: e }) => {
|
|
108
|
+
this.$nextTick(() => {
|
|
109
|
+
let i = e / this.column >> 0, l = this.fwheight;
|
|
110
|
+
(this.flyweight.scrollTop / l >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * l, this.scroll());
|
|
111
|
+
});
|
|
112
|
+
}], this, { index: t });
|
|
113
|
+
},
|
|
86
114
|
lazyrun(t, e) {
|
|
87
115
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
88
|
-
|
|
116
|
+
d(t);
|
|
89
117
|
}, e || this.lazy);
|
|
90
118
|
},
|
|
91
119
|
run(t) {
|
|
92
|
-
let e =
|
|
93
|
-
|
|
120
|
+
let e = x(t.target, "scrollTop=>top");
|
|
121
|
+
m(
|
|
94
122
|
this.flyweights,
|
|
95
|
-
(l, s,
|
|
96
|
-
if (
|
|
97
|
-
(+(
|
|
98
|
-
|
|
99
|
-
|
|
123
|
+
(i, l, s, n, h, r, f, c) => {
|
|
124
|
+
if (s = i / h >> 0, f = s + n * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
125
|
+
(+(s < r % n) + (r / n >> 0)), c = f * h + i % h, c >= this.count) {
|
|
126
|
+
this.lazyrun(() => this.$emit("onend", !0));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
l.index = f, l.top = l.index * this.fwheight, l.data = this.flys[c];
|
|
100
130
|
},
|
|
101
131
|
null,
|
|
102
132
|
this.row,
|
|
103
133
|
this.column,
|
|
104
134
|
/* 显示区域第一行的索引 */
|
|
105
135
|
e.top / this.fwheight >> 0
|
|
106
|
-
)
|
|
136
|
+
);
|
|
107
137
|
},
|
|
108
138
|
scroll(t) {
|
|
109
|
-
this.run(t);
|
|
139
|
+
this.run(t || { target: this.flyweight });
|
|
110
140
|
},
|
|
111
141
|
re() {
|
|
112
|
-
let t = this.flyweight, e =
|
|
142
|
+
let t = this.flyweight, e = x(t, "clientHeight=>height,clientWidth=>width");
|
|
113
143
|
this.$nextTick(() => {
|
|
114
|
-
let [
|
|
115
|
-
|
|
116
|
-
let
|
|
117
|
-
this.row = f + 2, this.column =
|
|
118
|
-
let c = e.width %
|
|
144
|
+
let [i, l] = this.offset, s = this.width;
|
|
145
|
+
s == 0 && (s = e.width);
|
|
146
|
+
let n = s + i, h = this.height + l, r = e.width / n >> 0, f = e.height / h >> 0;
|
|
147
|
+
this.row = f + 2, this.column = r, this.fwheight = h;
|
|
148
|
+
let c = e.width % n / (r - 1) >> 0;
|
|
149
|
+
this.Height = Math.ceil(this.count / r) * h;
|
|
150
|
+
let u = Math.min(this.count, r * this.row), a = u - 1, o, p;
|
|
119
151
|
for (; u-- > 0; )
|
|
120
|
-
o =
|
|
121
|
-
data:
|
|
122
|
-
top: (o /
|
|
123
|
-
left: o %
|
|
124
|
-
index: o /
|
|
152
|
+
o = a - u, p = this.flys[o], t = this.flyweights[o], this.$set(this.flyweights, o, {
|
|
153
|
+
data: p,
|
|
154
|
+
top: (o / r >> 0) * h,
|
|
155
|
+
left: o % r * (n + c),
|
|
156
|
+
index: o / r >> 0
|
|
125
157
|
});
|
|
126
|
-
this.flyweights.length =
|
|
158
|
+
this.flyweights.length = a + 1, this.scroll();
|
|
127
159
|
});
|
|
128
160
|
}
|
|
129
161
|
}
|
|
130
162
|
};
|
|
131
|
-
function O(t, e, l, s,
|
|
132
|
-
return
|
|
163
|
+
function O(t, e, i, l, s, n) {
|
|
164
|
+
return y(), g("div", {
|
|
133
165
|
ref: "flyweight",
|
|
134
|
-
class:
|
|
135
|
-
"flyweight-active":
|
|
166
|
+
class: k(["flyweight", {
|
|
167
|
+
"flyweight-active": s.actice
|
|
136
168
|
}]),
|
|
137
|
-
style:
|
|
138
|
-
"--width":
|
|
139
|
-
"--height":
|
|
169
|
+
style: w({
|
|
170
|
+
"--width": i.width ? i.width + "px" : "100%",
|
|
171
|
+
"--height": i.height + "px"
|
|
140
172
|
}),
|
|
141
|
-
onScroll: e[0] || (e[0] = (...h) =>
|
|
173
|
+
onScroll: e[0] || (e[0] = (...h) => n.scroll && n.scroll(...h))
|
|
142
174
|
}, [
|
|
143
175
|
v("div", {
|
|
144
176
|
class: "flyweight-all",
|
|
145
|
-
style:
|
|
146
|
-
"--flyweight-height":
|
|
177
|
+
style: w({
|
|
178
|
+
"--flyweight-height": s.Height + "px"
|
|
147
179
|
})
|
|
148
180
|
}, [
|
|
149
|
-
(
|
|
150
|
-
key:
|
|
151
|
-
style:
|
|
181
|
+
(y(!0), g(z, null, b(s.flyweights, (h, r) => (y(), g("div", {
|
|
182
|
+
key: r,
|
|
183
|
+
style: w({
|
|
152
184
|
top: h.top + "px",
|
|
153
185
|
left: h.left + "px"
|
|
154
186
|
})
|
|
155
187
|
}, [
|
|
156
|
-
|
|
188
|
+
_(t.$slots, "default", {
|
|
157
189
|
data: h.data,
|
|
158
190
|
index: h.index
|
|
159
191
|
}, void 0, !0)
|
|
160
192
|
], 4))), 128))
|
|
161
|
-
], 4)
|
|
193
|
+
], 4),
|
|
194
|
+
s.flyweights.length ? _(t.$slots, "end", { key: 0 }, void 0, !0) : T("", !0)
|
|
162
195
|
], 38);
|
|
163
196
|
}
|
|
164
|
-
const E = /* @__PURE__ */
|
|
197
|
+
const E = /* @__PURE__ */ N(H, [["render", O], ["__scopeId", "data-v-d96197a5"]]), L = [E], S = {
|
|
165
198
|
install(t) {
|
|
166
|
-
|
|
167
|
-
t.component("s-" + e.
|
|
199
|
+
L.forEach((e) => {
|
|
200
|
+
t.component("s-" + e.name.toLowerCase(), e);
|
|
168
201
|
});
|
|
169
202
|
}
|
|
170
203
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-d96197a5]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-d96197a5]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-d96197a5]>*{width:var(--width);height:var(--height);position:absolute}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soei/flyweight",
|
|
3
3
|
"private": false,
|
|
4
|
-
"
|
|
4
|
+
"description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight",
|
|
5
|
+
"version": "0.0.2",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/Flyweight.cjs",
|
|
7
8
|
"module": "dist/Flyweight.js",
|
|
@@ -20,7 +21,6 @@
|
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@vitejs/plugin-vue": "^4.2.3",
|
|
23
|
-
"sass": "^1.69.5",
|
|
24
24
|
"scss": "^0.2.4",
|
|
25
25
|
"vite": "^4.4.5"
|
|
26
26
|
}
|
package/src/Flyweight.vue
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
'--height': height + 'px'
|
|
7
7
|
}" @scroll="scroll">
|
|
8
8
|
<div class="flyweight-all" :style="{
|
|
9
|
-
'--flyweight-height':
|
|
9
|
+
'--flyweight-height': Height + 'px'
|
|
10
10
|
}">
|
|
11
11
|
<div v-for="(item, index) in flyweights" :key="index" :style="{
|
|
12
12
|
top: item.top + 'px',
|
|
@@ -15,17 +15,23 @@
|
|
|
15
15
|
<slot :data="item.data" :index="item.index"></slot>
|
|
16
16
|
</div>
|
|
17
17
|
</div>
|
|
18
|
+
<slot name="end" v-if="flyweights.length"></slot>
|
|
18
19
|
</div>
|
|
19
20
|
</template>
|
|
20
21
|
|
|
21
22
|
<script>
|
|
22
23
|
import { each, picker, runer } from '@soei/util';
|
|
23
24
|
|
|
25
|
+
let isNil = (data) => {
|
|
26
|
+
return data == null || data == undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
let Log = (...args) => {
|
|
25
30
|
console.info('::::FLYWEIGHT', ...args);
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export default {
|
|
34
|
+
name: 'Flyweight',
|
|
29
35
|
props: {
|
|
30
36
|
flys: {
|
|
31
37
|
type: Array,
|
|
@@ -49,7 +55,7 @@ export default {
|
|
|
49
55
|
},
|
|
50
56
|
view: {
|
|
51
57
|
type: Object,
|
|
52
|
-
default: () => (
|
|
58
|
+
default: () => (null)
|
|
53
59
|
},
|
|
54
60
|
index: {
|
|
55
61
|
type: Number,
|
|
@@ -65,38 +71,42 @@ export default {
|
|
|
65
71
|
return {
|
|
66
72
|
flyweights: [],
|
|
67
73
|
actice: false,
|
|
68
|
-
|
|
74
|
+
Height: null,
|
|
69
75
|
column: 1,
|
|
70
76
|
row: 1,
|
|
71
77
|
fwheight: 10,
|
|
72
78
|
|
|
73
|
-
count: 0
|
|
79
|
+
count: 0,
|
|
80
|
+
task: []
|
|
74
81
|
}
|
|
75
82
|
},
|
|
76
83
|
watch: {
|
|
77
84
|
flys(data) {
|
|
78
85
|
this.count = data.length;
|
|
79
86
|
this.re();
|
|
87
|
+
let task = this.task.shift();
|
|
88
|
+
if (task) {
|
|
89
|
+
this.$nextTick(() => {
|
|
90
|
+
this.setview(task);
|
|
91
|
+
})
|
|
92
|
+
}
|
|
80
93
|
},
|
|
81
|
-
view
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// runer('dispatchEvent', window, new Event('resize', { view: this.flyweight, bubbles: true, cancelable: true }));
|
|
87
|
-
this.$emit('update:index', index);
|
|
94
|
+
view: {
|
|
95
|
+
handler(data) {
|
|
96
|
+
this.setview(data)
|
|
97
|
+
},
|
|
98
|
+
immediate: true
|
|
88
99
|
},
|
|
89
100
|
index(index) {
|
|
90
|
-
|
|
91
|
-
let first = this.flyweight.scrollTop / this.fwheight >> 0;
|
|
92
|
-
let offset = first + this.row - line - 1
|
|
93
|
-
// Log(data, first, line, offset);
|
|
94
|
-
if (offset > 0 ) return;
|
|
95
|
-
this.flyweight.scrollTop = line * this.fwheight;
|
|
101
|
+
this.setindex(index);
|
|
96
102
|
}
|
|
97
103
|
},
|
|
98
104
|
mounted() {
|
|
99
105
|
this.flyweights = [];
|
|
106
|
+
this.$set || (this.$set = (list, index, value) => {
|
|
107
|
+
list[index] = value;
|
|
108
|
+
})
|
|
109
|
+
this.setindex(this.index);
|
|
100
110
|
try {
|
|
101
111
|
const resizeObserver = new ResizeObserver(() => {
|
|
102
112
|
this.re();
|
|
@@ -109,6 +119,37 @@ export default {
|
|
|
109
119
|
}
|
|
110
120
|
},
|
|
111
121
|
methods: {
|
|
122
|
+
cheackflys(data) {
|
|
123
|
+
let length = this.flys.length;
|
|
124
|
+
if (!length) {
|
|
125
|
+
data && this.task.push(data);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
setview(data) {
|
|
130
|
+
runer([this.cheackflys, (data) => {
|
|
131
|
+
data = data || {};
|
|
132
|
+
let index = data.index || each(this.flys, (k, v, attr, value) => {
|
|
133
|
+
if (v[attr] == value) return k;
|
|
134
|
+
}, data.picker, data.id);
|
|
135
|
+
|
|
136
|
+
isNil(index) || this.setindex(index);
|
|
137
|
+
}], this, data)
|
|
138
|
+
},
|
|
139
|
+
setindex(index) {
|
|
140
|
+
runer([this.cheackflys, ({ index }) => {
|
|
141
|
+
this.$nextTick(() => {
|
|
142
|
+
let line = index / this.column >> 0;
|
|
143
|
+
let height = this.fwheight;
|
|
144
|
+
let first = this.flyweight.scrollTop / height >> 0;
|
|
145
|
+
let offset = first + this.row - line - 1;
|
|
146
|
+
if (offset > 0) return;
|
|
147
|
+
this.flyweight.scrollTop = line * height;
|
|
148
|
+
|
|
149
|
+
this.scroll()
|
|
150
|
+
})
|
|
151
|
+
}], this, { index: index })
|
|
152
|
+
},
|
|
112
153
|
lazyrun(back, time) {
|
|
113
154
|
clearTimeout(this.time);
|
|
114
155
|
this.time = setTimeout(() => {
|
|
@@ -117,7 +158,7 @@ export default {
|
|
|
117
158
|
},
|
|
118
159
|
run(e) {
|
|
119
160
|
let position = picker(e.target, 'scrollTop=>top');
|
|
120
|
-
|
|
161
|
+
each(this.flyweights, (k, v, offset, row, column, first, index, i) => {
|
|
121
162
|
offset = k / column >> 0;
|
|
122
163
|
index = offset + row * (
|
|
123
164
|
/* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
@@ -127,9 +168,9 @@ export default {
|
|
|
127
168
|
);
|
|
128
169
|
i = index * column + k % column;
|
|
129
170
|
|
|
130
|
-
// Log(k, i, index);
|
|
131
171
|
if (i >= this.count) {
|
|
132
|
-
|
|
172
|
+
this.lazyrun(() => this.$emit('onend', true));
|
|
173
|
+
return /* true */;
|
|
133
174
|
}
|
|
134
175
|
v.index = index;
|
|
135
176
|
v.top = v.index * this.fwheight;
|
|
@@ -140,17 +181,15 @@ export default {
|
|
|
140
181
|
this.column,
|
|
141
182
|
/* 显示区域第一行的索引 */
|
|
142
183
|
position.top / this.fwheight >> 0
|
|
143
|
-
)
|
|
144
|
-
this.lazyrun(() => this.$emit('onend', true))
|
|
145
|
-
}
|
|
184
|
+
)
|
|
146
185
|
},
|
|
147
186
|
scroll(e) {
|
|
148
|
-
this.run(e);
|
|
187
|
+
this.run(e || { target: this.flyweight });
|
|
149
188
|
},
|
|
189
|
+
|
|
150
190
|
re() {
|
|
151
191
|
let flyweight = this.flyweight;
|
|
152
192
|
let wh = picker(flyweight, 'clientHeight=>height,clientWidth=>width');
|
|
153
|
-
// Log(wh, wh.width / this.width, wh.height / this.height);
|
|
154
193
|
this.$nextTick(() => {
|
|
155
194
|
let [x, y] = this.offset,
|
|
156
195
|
W = this.width;
|
|
@@ -164,10 +203,10 @@ export default {
|
|
|
164
203
|
this.row = row + 2/* 上下各一行补位 */;
|
|
165
204
|
this.column = column;
|
|
166
205
|
this.fwheight = height;
|
|
167
|
-
/* 总高度 */
|
|
168
|
-
this.H = (this.count / column) * height;
|
|
169
206
|
/* 偏移量 */
|
|
170
207
|
let margin = (wh.width % width) / (column - 1) >> 0;
|
|
208
|
+
/* 总高度 */
|
|
209
|
+
this.Height = Math.ceil(this.count / column) * height;
|
|
171
210
|
/* 计算数量 */
|
|
172
211
|
let count = Math.min(this.count, column * this.row),
|
|
173
212
|
length = count - 1,
|
|
@@ -182,11 +221,11 @@ export default {
|
|
|
182
221
|
top: (index / column >> 0) * height,
|
|
183
222
|
left: (index % column) * (width + margin),
|
|
184
223
|
index: index / column >> 0
|
|
185
|
-
})
|
|
224
|
+
})
|
|
186
225
|
}
|
|
187
226
|
this.flyweights.length = length + 1;
|
|
188
227
|
|
|
189
|
-
this.scroll(
|
|
228
|
+
this.scroll()
|
|
190
229
|
});
|
|
191
230
|
}
|
|
192
231
|
}
|