@shijiu/jsview-vue 1.9.650 → 1.9.720

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.
Files changed (157) hide show
  1. package/package.json +7 -18
  2. package/samples/AnimPicture/App.vue +5 -5
  3. package/samples/Basic/components/div/DivLayout.vue +1 -1
  4. package/samples/Basic/components/text/TextOverflow.vue +10 -5
  5. package/samples/BasicFocusControl/components/BaseBlock.vue +2 -2
  6. package/samples/Collision/App.vue +452 -0
  7. package/samples/DemoHomepage/components/BodyFrame.vue +2 -0
  8. package/samples/DemoHomepage/router.js +21 -1
  9. package/samples/DemoHomepage/views/Homepage.vue +3 -7
  10. package/samples/FilterDemo/App.vue +1 -1
  11. package/samples/FlipCard/App.vue +2 -2
  12. package/samples/FlipCard/FlipCard.vue +2 -2
  13. package/samples/GridDemo/App.vue +3 -3
  14. package/samples/GridDemo/ButtonBlock.vue +2 -2
  15. package/samples/GridDemo/FocusItem.vue +2 -2
  16. package/samples/GridDemo/Item.vue +1 -1
  17. package/samples/HashHistory/App.vue +10 -3
  18. package/samples/HashHistory/components/Item.vue +1 -1
  19. package/samples/ImpactStop/App.vue +435 -0
  20. package/samples/Input/App.vue +8 -17
  21. package/samples/Input/InputPanel.vue +19 -12
  22. package/samples/LongImage/Button.vue +1 -1
  23. package/samples/LongImage/ButtonItem.vue +1 -1
  24. package/samples/LongImage/LongImageScroll.vue +2 -2
  25. package/samples/LongText/App.vue +1 -1
  26. package/samples/LongText/Button.vue +1 -1
  27. package/samples/LongText/ButtonItem.vue +1 -1
  28. package/samples/LongText/LongTextScroll.vue +3 -3
  29. package/samples/Marquee/App.vue +176 -40
  30. package/samples/Marquee/longText.js +14 -0
  31. package/samples/MetroWidgetDemos/Advanced/App.vue +5 -6
  32. package/samples/MetroWidgetDemos/Advanced/ButtonItem.vue +3 -3
  33. package/samples/MetroWidgetDemos/Advanced/Buttons.vue +5 -5
  34. package/samples/MetroWidgetDemos/Advanced/Mixed.vue +4 -4
  35. package/samples/MetroWidgetDemos/Advanced/widgets/Item.vue +83 -0
  36. package/samples/MetroWidgetDemos/Advanced/widgets/WidgetItem.vue +89 -0
  37. package/samples/MetroWidgetDemos/Advanced/{Widgets.vue → widgets/Widgets.vue} +56 -11
  38. package/samples/MetroWidgetDemos/Advanced/widgets/focus1.png +0 -0
  39. package/samples/MetroWidgetDemos/Item.vue +20 -2
  40. package/samples/MetroWidgetDemos/PerformanceTest/App.vue +4 -4
  41. package/samples/MetroWidgetDemos/PerformanceTest/components/ContentItem.vue +1 -1
  42. package/samples/MetroWidgetDemos/PerformanceTest/components/MyTab.vue +1 -1
  43. package/samples/MetroWidgetDemos/PingPong/App.vue +3 -3
  44. package/samples/MetroWidgetDemos/PingPong/AppPage.vue +17 -2
  45. package/samples/MetroWidgetDemos/PingPong/AppTab.vue +3 -10
  46. package/samples/MetroWidgetDemos/PingPong/{Item.vue → TabItem.vue} +3 -11
  47. package/samples/MetroWidgetDemos/PingPong/ViewSwiper.vue +2 -2
  48. package/samples/MetroWidgetDemos/Simple/AbsoluteTemplate.vue +2 -2
  49. package/samples/MetroWidgetDemos/Simple/App.vue +2 -2
  50. package/samples/MetroWidgetDemos/Simple/RelativeTemplate.vue +6 -6
  51. package/samples/MetroWidgetDemos/WidgetItem.vue +2 -2
  52. package/samples/MetroWidgetDemos/data.js +2 -1
  53. package/samples/NinePatchDemo/App.vue +2 -2
  54. package/samples/NinePatchDemo/Item.vue +1 -1
  55. package/samples/Preload/App.vue +17 -12
  56. package/samples/Preload/Item.vue +1 -1
  57. package/samples/QrcodeDemo/App.vue +1 -1
  58. package/samples/ScaleDownNeon/App.vue +107 -0
  59. package/samples/SoundPool/App.vue +1 -1
  60. package/samples/TextBox/App.vue +9 -82
  61. package/samples/TextBox/RenderCenter.vue +40 -16
  62. package/samples/TextBox/RenderLeft.vue +48 -19
  63. package/samples/TextBox/RenderOneLine.vue +30 -49
  64. package/samples/TextBox/RenderRight.vue +40 -16
  65. package/samples/TextShadowDemo/App.vue +11 -17
  66. package/samples/TextureAnimation/App2.vue +43 -15
  67. package/samples/TextureAnimation/assets/light.png +0 -0
  68. package/samples/TextureAnimation/assets/light2.png +0 -0
  69. package/samples/TextureSize/App.vue +3 -3
  70. package/samples/TouchSample/MetroWidgetHorizontal.vue +1 -1
  71. package/samples/TouchSample/MetroWidgetVertical.vue +1 -1
  72. package/samples/TransitPage/App.vue +1 -1
  73. package/samples/VideoDemo/App.vue +8 -8
  74. package/samples/VideoDemo/components/Button.vue +1 -1
  75. package/samples/VisibleSensorDemo/App.vue +94 -27
  76. package/tsconfig.json +6 -6
  77. package/utils/JsViewEngineWidget/JsvFocusBlock.vue +55 -59
  78. package/utils/JsViewEngineWidget/JsvFocusManager.js +1 -1
  79. package/utils/JsViewEngineWidget/MetroWidget/Const.js +11 -0
  80. package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +226 -107
  81. package/utils/JsViewEngineWidget/TemplateParser.js +227 -178
  82. package/utils/JsViewEngineWidget/WidgetCommon.js +13 -5
  83. package/utils/JsViewEngineWidget/index.js +3 -2
  84. package/utils/JsViewPlugin/BrowserPluginLoader.js +1 -1
  85. package/utils/JsViewPlugin/JsvPlayer/JsvMedia.js +95 -12
  86. package/utils/JsViewPlugin/JsvPlayer/JsvPlayer.vue +23 -2
  87. package/utils/JsViewPlugin/JsvPlayer/JsvPlayerBrowser.vue +1 -1
  88. package/utils/JsViewPlugin/JsvPlayer/index.js +22 -1
  89. package/utils/JsViewPlugin/JsvPlayer/version.js +4 -4
  90. package/utils/JsViewVueTools/JsvImpactTracer.js +113 -0
  91. package/utils/JsViewVueTools/JsvStyleClass.js +1 -1
  92. package/utils/JsViewVueTools/index.js +2 -1
  93. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserPreload.vue +11 -1
  94. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserSpray.vue +1 -1
  95. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserTextureAnim.vue +7 -9
  96. package/utils/JsViewVueWidget/JsvActorMove/ActorControlBase.js +1 -1
  97. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMove.vue +3 -3
  98. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMoveControl.js +1 -1
  99. package/utils/JsViewVueWidget/JsvApic/JsvApic.vue +5 -5
  100. package/utils/JsViewVueWidget/JsvFilterView.vue +1 -1
  101. package/utils/JsViewVueWidget/JsvGrid.vue +3 -11
  102. package/utils/JsViewVueWidget/JsvInput/Cursor.vue +5 -3
  103. package/utils/JsViewVueWidget/JsvInput/JsvInput.vue +15 -14
  104. package/utils/JsViewVueWidget/JsvMarquee.vue +180 -207
  105. package/utils/JsViewVueWidget/JsvMaskClipDiv.vue +2 -2
  106. package/utils/JsViewVueWidget/JsvNativeSharedDiv.vue +35 -27
  107. package/utils/JsViewVueWidget/JsvNinePatch.vue +1 -2
  108. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +38 -42
  109. package/utils/JsViewVueWidget/JsvQrcode/JsvQrcode.vue +1 -1
  110. package/utils/JsViewVueWidget/JsvSpray/JsvSpray.vue +1 -1
  111. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +24 -8
  112. package/utils/JsViewVueWidget/JsvSwiper3D/JsvSwiper.vue +23 -3
  113. package/utils/JsViewVueWidget/JsvTextBox.vue +20 -86
  114. package/utils/JsViewVueWidget/JsvTextureAnim/JsvTextureAnim.vue +2 -9
  115. package/utils/JsViewVueWidget/JsvTouchContainer.vue +6 -7
  116. package/utils/JsViewVueWidget/JsvTransparentDiv.vue +1 -1
  117. package/utils/JsViewVueWidget/JsvVisibleSensor/JsvVisibleSensor.vue +6 -6
  118. package/utils/JsViewVueWidget/index.js +8 -8
  119. package/utils/JsViewVueWidget/utils/index.js +8 -0
  120. package/utils/JsViewVueWidget/utils/text.js +19 -0
  121. package/dom/bin/jsview-browser-debug-dom.min.js +0 -1
  122. package/dom/bin/jsview-dom.min.js +0 -1
  123. package/dom/bin/jsview-forge-define.min.js +0 -1
  124. package/dom/browser-root-style.css +0 -21
  125. package/dom/jsv-browser-debug-dom.js +0 -8
  126. package/dom/jsv-dom.js +0 -6
  127. package/dom/jsv-forge-define.js +0 -6
  128. package/dom/target_core_revision.mjs +0 -15
  129. package/loader/header_script_loader.js +0 -134
  130. package/loader/jsview-main.js +0 -42
  131. package/loader/jsview.config.default.js +0 -37
  132. package/loader/jsview.default.config.js +0 -37
  133. package/loader/loader.js +0 -179
  134. package/loader/loader_webkit.js +0 -40
  135. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -17609
  136. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js +0 -335
  137. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-style-format.js +0 -446
  138. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-style-types.js +0 -91
  139. package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -8038
  140. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1700
  141. package/patches/node_modules/postcss-js/objectifier.js +0 -90
  142. package/patches/node_modules/vite/dist/node/chunks/dep-0fc8e132.js +0 -63147
  143. package/patches/node_modules/vite/dist/node/jsview.vite.config.js +0 -53
  144. package/patches/node_modules/vue-router/dist/vue-router.mjs +0 -3595
  145. package/scripts/common.js +0 -58
  146. package/scripts/jsview-install-local-packages.js +0 -73
  147. package/scripts/jsview-jsmap-serve.js +0 -105
  148. package/scripts/jsview-post-build.js +0 -183
  149. package/scripts/jsview-post-install.js +0 -102
  150. package/scripts/jsview-run-android.js +0 -67
  151. package/utils/JsViewEngineWidget/MetroPage.js +0 -2128
  152. package/utils/JsViewEngineWidget/SimpleWidget/ContentView.vue +0 -51
  153. package/utils/JsViewEngineWidget/SimpleWidget/Dispatcher.js +0 -19
  154. package/utils/JsViewEngineWidget/SimpleWidget/DivWrapper.vue +0 -53
  155. package/utils/JsViewEngineWidget/SimpleWidget/ItemView.vue +0 -142
  156. package/utils/JsViewEngineWidget/SimpleWidget/RootView.vue +0 -140
  157. package/utils/JsViewEngineWidget/SimpleWidget/SimpleWidget.vue +0 -1629
@@ -1,2128 +0,0 @@
1
- /*
2
- * @Author: ChenChanghua
3
- * @Date: 2021-06-02 10:43:57
4
- * @LastEditors: ChenChanghua
5
- * @LastEditTime: 2021-06-29 18:07:43
6
- * @Description: file content
7
- */
8
- import Forge from "./ForgeDefine";
9
- import { TemplateParser } from "./TemplateParser";
10
- import { SingleRangeModel } from "./RangeModel";
11
- import {
12
- EdgeDirection,
13
- SlideStyle,
14
- VERTICAL,
15
- HORIZONTAL,
16
- BaseDispatcher,
17
- } from "./WidgetCommon";
18
- import FDiv from "./FDiv.vue";
19
-
20
- let empty_func = () => {};
21
-
22
- let Event = {
23
- ShowLoadingView: 0,
24
- ShowLoadingViewDone: 1,
25
- UpdatePage: 2,
26
- UpdatePageDone: 3,
27
- };
28
-
29
- class EventHub {
30
- constructor() {
31
- this._runCallbacks = this._runCallbacks.bind(this);
32
-
33
- this._EventCallbackMap = {};
34
- this._EventCallbackMap[Event.ShowLoadingView] = [];
35
- this._EventCallbackMap[Event.ShowLoadingViewDone] = [];
36
- this._EventCallbackMap[Event.UpdatePage] = [];
37
- this._EventCallbackMap[Event.UpdatePageDone] = [];
38
- }
39
-
40
- registerEvent(event, callback) {
41
- this._EventCallbackMap[event].push(callback);
42
- }
43
-
44
- unregisterEvent(event, callback) {
45
- for (let i = 0; i < this._EventCallbackMap[event].length; i++) {
46
- if (this._EventCallbackMap[event][i] === callback) {
47
- this._EventCallbackMap[event].splice(i, 1);
48
- break;
49
- }
50
- }
51
- }
52
-
53
- _runCallbacks(event) {
54
- for (let callback of this._EventCallbackMap[event]) {
55
- callback();
56
- }
57
- }
58
-
59
- dispatch(event, sync) {
60
- if (sync) {
61
- this._runCallbacks(event);
62
- } else {
63
- setTimeout(() => {
64
- this._runCallbacks(event);
65
- }, 0);
66
- }
67
- }
68
- }
69
- let eventHub = new EventHub();
70
-
71
- class MetroPageDispatcher extends BaseDispatcher {}
72
- MetroPageDispatcher.Type = {
73
- setFocusId: Symbol("setFocusId"),
74
- setFocusRect: Symbol("setFocusRect"),
75
- updateItem: Symbol("updateItem"),
76
- slideToItem: Symbol("slideTo"),
77
- };
78
-
79
- let PAGE_INFO_TOKEN = 0;
80
- class PageData {
81
- constructor(
82
- _width,
83
- _height,
84
- _direction,
85
- _padding,
86
- _layoutType,
87
- _data,
88
- _measure_func,
89
- _visible_range
90
- ) {
91
- this._VisibleRange = _visible_range;
92
- this._Direction = _direction;
93
- this._PageList = [];
94
- let line_max =
95
- _direction === VERTICAL
96
- ? _width - _padding.left - _padding.right
97
- : _height - _padding.top - _padding.bottom;
98
- let layout_type = _layoutType ? _layoutType : "relative";
99
- this._TemplateParser = new TemplateParser(
100
- _direction,
101
- line_max,
102
- layout_type,
103
- _width,
104
- _height
105
- );
106
- for (let i = 0; i < _data.length; i++) {
107
- let block_item = _measure_func(_data[i]);
108
- this._TemplateParser.ParseTemplateItem(block_item, _data[i]);
109
- }
110
- this._TemplateParser.CalculateNeighborWhenAddStop();
111
- this._splitPages(this._TemplateParser.GetTemplate().List, 0, 0);
112
- }
113
-
114
- addItems(_new_data, _measure_func, _start_index) {
115
- for (let i = _start_index; i < _new_data.length; i++) {
116
- let block_item = _measure_func(_new_data[i]);
117
- this._TemplateParser.ParseTemplateItem(block_item, _new_data[i]);
118
- }
119
- this._TemplateParser.CalculateNeighborWhenAddStop();
120
- //todo 动态添加item时的分页
121
- let start_index = 0;
122
- let start_line = 0;
123
- if (this._PageList.length > 0) {
124
- let last_page = this._PageList.splice(this._PageList.length - 1, 1)[0];
125
- start_index = last_page.startIndex;
126
- start_line = last_page.top;
127
- }
128
- this._splitPages(
129
- this._TemplateParser.GetTemplate().List,
130
- start_index,
131
- start_line
132
- );
133
- }
134
-
135
- _splitPages(_template_list, _start_index, _start_line) {
136
- let start_line = _start_line;
137
- let start_index = _start_index;
138
- let data_list = _template_list;
139
- while (start_index < data_list.length) {
140
- let visible_info = this._TemplateParser.GetVisibleItemList(
141
- start_line,
142
- start_line + this._VisibleRange - 1,
143
- start_index
144
- );
145
- let page_bottom = 0;
146
- let page_top = -1;
147
- for (
148
- let i = visible_info.visibleStart;
149
- i < visible_info.visibleEnd + 1;
150
- i++
151
- ) {
152
- let item = data_list[i];
153
- let item_bottom =
154
- this._Direction == VERTICAL
155
- ? item.yPos + item.height - 1
156
- : item.xPos + item.width - 1;
157
- let item_top = this._Direction == VERTICAL ? item.yPos : item.xPos;
158
- if (page_bottom < item_bottom) {
159
- page_bottom = item_bottom;
160
- }
161
- if (page_top === -1 || item_top < item_top) {
162
- page_top = item_top;
163
- }
164
- }
165
- if (page_bottom > start_line + this._VisibleRange - 1) {
166
- let new_visible_info = this._TemplateParser.GetVisibleItemList(
167
- start_line + this._VisibleRange,
168
- page_bottom,
169
- visible_info.visibleEnd
170
- );
171
- visible_info.visibleEnd = new_visible_info.visibleEnd;
172
- start_line = page_bottom + 1;
173
- } else {
174
- start_line = start_line + this._VisibleRange;
175
- }
176
- start_index = visible_info.visibleEnd + 1;
177
-
178
- //添加page信息
179
- let page_info = {
180
- token: PAGE_INFO_TOKEN++,
181
- top: page_top,
182
- bottom: page_bottom,
183
- direction: this._Direction,
184
- startIndex: visible_info.visibleStart,
185
- endIndex: visible_info.visibleEnd,
186
- itemList: data_list.slice(
187
- visible_info.visibleStart,
188
- visible_info.visibleEnd + 1
189
- ),
190
- };
191
- //清理重复的item
192
- if (this._PageList.length > 0) {
193
- let pre_page = this._PageList[this._PageList.length - 1];
194
- if (page_info.startIndex < pre_page.startIndex) {
195
- page_info.startIndex = pre_page.startIndex + 1;
196
- }
197
- }
198
- if (page_info.endIndex >= page_info.startIndex) {
199
- this._PageList.push(page_info);
200
- }
201
- }
202
- }
203
-
204
- getPageByIndex(page_list, focus_index) {
205
- for (let i = 0; i < page_list.length; i++) {
206
- if (
207
- focus_index >= page_list[i].startIndex &&
208
- focus_index <= page_list[i].endIndex
209
- ) {
210
- return i;
211
- }
212
- }
213
- return -1;
214
- }
215
-
216
- getPageList(visible_start, visible_end, direction, count = 5) {
217
- if (this._PageList.length < count) {
218
- return this._PageList;
219
- }
220
-
221
- let already_find = false;
222
- let start_index = -1;
223
- let end_index = -1;
224
- for (let index = 0; index < this._PageList.length; index++) {
225
- if (
226
- this._PageList[index].top <= visible_end &&
227
- this._PageList[index].bottom >= visible_start
228
- ) {
229
- if (!already_find) {
230
- start_index = index;
231
- }
232
- already_find = true;
233
- } else if (already_find) {
234
- end_index = index;
235
- break;
236
- }
237
- }
238
- if (start_index < 0) {
239
- console.error("getPageList: no page is visible.");
240
- return [];
241
- }
242
- if (end_index < 0) {
243
- end_index = this._PageList.length;
244
- }
245
-
246
- if (end_index - start_index > count) {
247
- console.error("getPageList error " + count);
248
- } else {
249
- let need_add = count - (end_index - start_index);
250
- if (direction > 0) {
251
- end_index += need_add;
252
- if (end_index > this._PageList.length) {
253
- end_index = this._PageList.length;
254
- start_index -= count - (end_index - start_index);
255
- }
256
- } else {
257
- start_index -= need_add;
258
- if (start_index < 0) {
259
- start_index = 0;
260
- end_index += count - (end_index - start_index);
261
- }
262
- }
263
- }
264
- return this._PageList.slice(start_index, end_index);
265
- }
266
- }
267
-
268
- const MetroPageItem = {
269
- name: "MetroPageItem",
270
- props: {
271
- x: {
272
- type: Number,
273
- default: 0,
274
- },
275
- y: {
276
- type: Number,
277
- default: 0,
278
- },
279
- width: {
280
- type: Number,
281
- default: 0,
282
- },
283
- height: {
284
- type: Number,
285
- default: 0,
286
- },
287
- mountStateUpdate: {
288
- type: Function,
289
- default: empty_func,
290
- },
291
- renderFunc: {
292
- type: Function,
293
- default: empty_func,
294
- },
295
- setControlFunc: {
296
- type: Function,
297
- default: empty_func,
298
- },
299
- onClick: {
300
- type: Function,
301
- default: empty_func,
302
- },
303
- index: {
304
- type: Number,
305
- },
306
- },
307
- setup() {},
308
- data() {
309
- return {
310
- zIndex: 0,
311
- };
312
- },
313
- methods: {
314
- _setZIndex(z) {
315
- this.zIndex = z;
316
- },
317
- },
318
- render() {
319
- // console.log("item render ", this.index)
320
- return (
321
- <div
322
- key={this.$props.x + "_" + this.$props.y}
323
- style={{
324
- left: this.$props.x,
325
- top: this.$props.y,
326
- width: this.$props.width,
327
- height: this.$props.height,
328
- visibility: "inherit",
329
- zIndex: this.zIndex,
330
- }}
331
- >
332
- {this.$props.renderFunc()}
333
- </div>
334
- );
335
- },
336
- created() {
337
- console.log("item created", this.index);
338
- this.$props.setControlFunc(this._setZIndex);
339
- },
340
- mounted() {
341
- this.$props.mountStateUpdate(true);
342
- },
343
- beforeUnmount() {
344
- this.$props.mountStateUpdate(false);
345
- },
346
- };
347
-
348
- //为了避免重复render添加一层组件做隔离
349
- const MetroItemPage = {
350
- name: "MetroItemPage",
351
- components: {
352
- [MetroPageItem.name]: MetroPageItem,
353
- },
354
- props: ["data", "renderFunc"],
355
- render() {
356
- return (
357
- <template>{this.data.map((item) => this.renderFunc(item))}</template>
358
- );
359
- },
360
- };
361
-
362
- const MetroPageSubPage = {
363
- name: "MetroPageSubPage",
364
- components: {
365
- [MetroItemPage.name]: MetroItemPage,
366
- },
367
- props: {
368
- register: {
369
- type: Function,
370
- default: empty_func,
371
- },
372
- renderFunc: {
373
- type: Function,
374
- default: empty_func,
375
- },
376
- idx: {
377
- type: Number,
378
- },
379
- },
380
- data() {
381
- return {
382
- renderList: [],
383
- };
384
- },
385
- setup() {
386
- return {
387
- pageInfo: [],
388
- timeoutId: -1,
389
- updateDone: false,
390
- onUpdateDone: empty_func,
391
- };
392
- },
393
- methods: {
394
- _clearPreTask() {
395
- clearTimeout(this.timeoutId);
396
- },
397
- _updateInBatch() {
398
- if (this.pageInfo) {
399
- if (
400
- !this.renderList ||
401
- this.renderList.length < this.pageInfo.itemList.length
402
- ) {
403
- this.timeoutId = setTimeout(() => {
404
- let end_index = 0;
405
- if (!this.renderList) {
406
- end_index = 1;
407
- } else {
408
- end_index = this.renderList.length + 1;
409
- }
410
- this.renderList = this.pageInfo.itemList.slice(0, end_index);
411
- this._updateInBatch();
412
- }, 0);
413
- }
414
- }
415
- },
416
- updatePage(pageInfo, onUpdateDone, inBatch) {
417
- if (!pageInfo) {
418
- return;
419
- }
420
- this.updateDone = false;
421
- this.onUpdateDone = onUpdateDone;
422
- this._clearPreTask();
423
- if (inBatch) {
424
- this.pageInfo = pageInfo;
425
- this.renderList = pageInfo.itemList.slice(0, 1);
426
- this._updateInBatch();
427
- } else {
428
- this.pageInfo = pageInfo;
429
- this.renderList = pageInfo.itemList;
430
- }
431
- },
432
- ifUpdateDone() {
433
- return this.updateDone;
434
- },
435
- getPageDataToken() {
436
- return this.pageInfo ? this.pageInfo.token : -1;
437
- },
438
- },
439
- render() {
440
- return this.renderList ? (
441
- <template>
442
- <MetroItemPage data={this.renderList} renderFunc={this.renderFunc} />
443
- </template>
444
- ) : null;
445
- },
446
- created() {
447
- this.$props.register(this);
448
- },
449
- mounted() {
450
- this.updateDone = true;
451
- },
452
- beforeUnmount() {
453
- this._clearPreTask();
454
- },
455
- updated() {
456
- if (
457
- this.renderList &&
458
- this.pageInfo &&
459
- this.renderList.length == this.pageInfo.itemList.length
460
- ) {
461
- this.updateDone = true;
462
- if (this.onUpdateDone) {
463
- this.onUpdateDone();
464
- this.onUpdateDone = null;
465
- }
466
- }
467
- },
468
- };
469
-
470
- const MetroPageRoot = {
471
- name: "MetroPageRoot",
472
- components: {
473
- [MetroPageSubPage.name]: MetroPageSubPage,
474
- },
475
- props: {
476
- x: {
477
- type: Number,
478
- default: 0,
479
- },
480
- y: {
481
- type: Number,
482
- default: 0,
483
- },
484
- width: {
485
- type: Number,
486
- default: 0,
487
- },
488
- height: {
489
- type: Number,
490
- default: 0,
491
- },
492
- registerRootView: {
493
- type: Function,
494
- default: empty_func,
495
- },
496
- renderFunc: {
497
- type: Function,
498
- default: empty_func,
499
- },
500
- },
501
- data() {
502
- return {
503
- focusPageIndex: -1,
504
- };
505
- },
506
- setup() {
507
- return {
508
- element: null,
509
- pageList: new Array(5),
510
- };
511
- },
512
- methods: {
513
- _pageUpdateDoneCallback() {
514
- console.log("_pageUpdateDoneCallback");
515
- },
516
- _showLoadingViewCallback() {
517
- console.log("_showLoadingViewCallback");
518
- },
519
- _registerFunc(index) {
520
- return (page) => (this.pageList[index] = page);
521
- },
522
- updateFocusPage(page_info) {
523
- for (let index = 0; index < this.pageList.length; index++) {
524
- if (
525
- this.pageList[index].getPageDataToken() === page_info.token &&
526
- index !== this.focusPageIndex
527
- ) {
528
- console.log("root view update focus page", page_info);
529
- this.focusPageIndex = index;
530
- break;
531
- }
532
- }
533
- },
534
- ifPageUpdateDone(page_token) {
535
- this._tmp = 123;
536
- for (let page of this.pageList) {
537
- if (page.getPageDataToken() === page_token) {
538
- return page.ifUpdateDone();
539
- }
540
- }
541
- //未找到对应的page
542
- console.error("can not find page", page_token);
543
- return false;
544
- },
545
- updatePages(page_data_list, update_in_batch) {
546
- console.log("update pages", page_data_list);
547
- let new_list = page_data_list.concat();
548
- let inbatch_set;
549
- if (update_in_batch instanceof Array) {
550
- inbatch_set = update_in_batch;
551
- } else {
552
- inbatch_set = new Array(new_list.length).fill(update_in_batch);
553
- }
554
- let page_index = [0, 1, 2, 3, 4];
555
- for (let i = page_index.length - 1; i >= 0; i--) {
556
- let pre_page = this.pageList[page_index[i]].getPageDataToken();
557
- for (let j = new_list.length - 1; j >= 0; j--) {
558
- if (pre_page == new_list[j].token) {
559
- page_index.splice(i, 1);
560
- new_list.splice(j, 1);
561
- inbatch_set.splice(j, 1);
562
- }
563
- }
564
- }
565
-
566
- if (page_index.length === 0) {
567
- return;
568
- }
569
-
570
- let callback = () => {
571
- let all_page_updated = true;
572
- for (let page of this.pageList) {
573
- if (!page.ifUpdateDone()) {
574
- all_page_updated = false;
575
- break;
576
- }
577
- }
578
-
579
- if (all_page_updated) {
580
- eventHub.dispatch(Event.UpdatePageDone);
581
- }
582
- };
583
- for (let i = 0; i < page_index.length; i++) {
584
- if (i < new_list.length) {
585
- this.pageList[page_index[i]].updatePage(
586
- new_list[i],
587
- callback,
588
- inbatch_set[i]
589
- );
590
- } else {
591
- this.pageList[page_index[i]].updatePage(null, callback, false);
592
- }
593
- }
594
- },
595
- updatePosition(x, y, anim_info) {
596
- if (this.element) {
597
- let pre_pos = this.element.jsvMaskView.GetLayoutParams();
598
- this.element.jsvMaskView.ResetLayoutParams({
599
- x: x,
600
- y: y,
601
- });
602
- if (anim_info) {
603
- let delta_x = Math.abs(pre_pos.MarginLeft - x);
604
- let delta_y = Math.abs(pre_pos.MarginTop - y);
605
- let duration = Math.round(
606
- delta_x === 0
607
- ? delta_y / anim_info.speed
608
- : delta_x / anim_info.speed
609
- );
610
- let slide_animation = new Forge.TranslateAnimation(
611
- pre_pos.MarginLeft - x,
612
- 0,
613
- pre_pos.MarginTop - y,
614
- 0,
615
- duration,
616
- anim_info.easing
617
- );
618
- slide_animation.SetAnimationListener(
619
- new Forge.AnimationListener(
620
- anim_info.onstart,
621
- anim_info.onend,
622
- null
623
- )
624
- );
625
- this.element.jsvMaskView.StartAnimation(slide_animation);
626
- }
627
- }
628
- },
629
- _ifPageVisible(index) {
630
- if (this.pageList[index]) {
631
- return this.pageList[index].ifUpdateDone();
632
- } else {
633
- return true;
634
- }
635
- },
636
- },
637
- render() {
638
- let pageIndexs = [0, 1, 2, 3, 4];
639
- return (
640
- <div
641
- key="metroPageRoot"
642
- style={{ left: this.$props.x, top: this.$props.y }}
643
- >
644
- <div key="position" ref={(ele) => (this.element = ele)}>
645
- <div
646
- key="touchcontainer"
647
- // ref={this._initTouchRef}
648
- style={{
649
- width: this.$props.width,
650
- height: this.$props.height,
651
- }}
652
- >
653
- {pageIndexs.map((index) => (
654
- <div
655
- style={{
656
- zIndex: this.focusPageIndex == index ? 5 : 0,
657
- visibility: this._ifPageVisible(index) ? "inherit" : "hidden",
658
- }}
659
- >
660
- <metro-page-sub-page
661
- key={"page" + index}
662
- idx={index}
663
- register={this._registerFunc(index)}
664
- renderFunc={this.$props.renderFunc}
665
- />
666
- </div>
667
- ))}
668
- </div>
669
- </div>
670
- </div>
671
- );
672
- },
673
- created() {
674
- this.$props.registerRootView(this);
675
- },
676
- mounted() {
677
- eventHub.registerEvent(
678
- Event.ShowLoadingView,
679
- this._showLoadingViewCallback
680
- );
681
- eventHub.registerEvent(Event.UpdatePageDone, this._pageUpdateDoneCallback);
682
- },
683
- beforeUnmount() {
684
- eventHub.unregisterEvent(
685
- Event.ShowLoadingView,
686
- this._showLoadingViewCallback
687
- );
688
- eventHub.unregisterEvent(
689
- Event.UpdatePageDone,
690
- this._pageUpdateDoneCallback
691
- );
692
- },
693
- };
694
-
695
- const _getPadding = function(padding) {
696
- let result = {
697
- left: 0,
698
- right: 0,
699
- top: 0,
700
- bottom: 0,
701
- };
702
-
703
- if (typeof padding !== "undefined" && padding !== null) {
704
- Object.assign(result, padding);
705
- }
706
- return result;
707
- };
708
-
709
- // const _getTemplateParser = function(
710
- // _width,
711
- // _height,
712
- // _direction,
713
- // _padding,
714
- // _layoutType
715
- // ) {
716
- // let padding = _getPadding(_padding);
717
- // let line_max =
718
- // _direction === VERTICAL
719
- // ? _width - padding.left - padding.right
720
- // : _height - padding.top - padding.bottom;
721
- // let layout_type = _layoutType ? _layoutType : "relative";
722
- // return new TemplateParser(_direction, line_max, layout_type, _width, _height);
723
- // };
724
-
725
- // const _AddTemplateItem = function(
726
- // _data,
727
- // _measure_func,
728
- // _template_parser,
729
- // _start_index
730
- // ) {
731
- // for (let i = _start_index; i < _data.length; i++) {
732
- // let block_item = _measure_func(_data[i]);
733
- // _template_parser.ParseTemplateItem(block_item, _data[i]);
734
- // }
735
- // _template_parser.CalculateNeighborWhenAddStop();
736
- // };
737
-
738
- const _mountStateUpdate = (item) => (state) => (item.mounted = state);
739
-
740
- const MetroPage = {
741
- name: "MetroPage",
742
- components: {
743
- [MetroPageItem.name]: MetroPageItem,
744
- [MetroPageRoot.name]: MetroPageRoot,
745
- FDiv,
746
- },
747
- props: {
748
- branchName: {
749
- type: String,
750
- required: true,
751
- },
752
- direction: {
753
- default: HORIZONTAL,
754
- },
755
- onClick: {
756
- type: Function,
757
- default: empty_func,
758
- },
759
- loopFocus: {
760
- type: Boolean,
761
- default: false,
762
- },
763
- loadViewSize: {
764
- type: Object,
765
- default() {
766
- return { width: 0, height: 0 };
767
- },
768
- },
769
- onFocusPosChange: {
770
- type: Function,
771
- default: empty_func,
772
- },
773
- onItemFocus: {
774
- type: Function,
775
- default: empty_func,
776
- },
777
- onItemBlur: {
778
- type: Function,
779
- default: empty_func,
780
- },
781
- onEdge: {
782
- type: Function,
783
- default: empty_func,
784
- },
785
- slideStyle: {
786
- default: SlideStyle.seamLess,
787
- },
788
- padding: {
789
- type: Object,
790
- default() {
791
- return {};
792
- },
793
- },
794
- onFocus: {
795
- type: Function,
796
- default: empty_func,
797
- },
798
- onBlur: {
799
- type: Function,
800
- default: empty_func,
801
- },
802
- data: {
803
- type: Array,
804
- required: true,
805
- },
806
- enableTouch: {
807
- type: Boolean,
808
- default: false,
809
- },
810
- flingPageEdge: {
811
- type: Number,
812
- default: 1 / 4,
813
- },
814
- flingPageWidth: {
815
- type: Number,
816
- default: -1,
817
- },
818
- measures: {
819
- type: Function,
820
- required: true,
821
- },
822
- baseAnchor: {
823
- type: Object,
824
- },
825
- width: {
826
- type: Number,
827
- required: true,
828
- },
829
- height: {
830
- type: Number,
831
- required: true,
832
- },
833
- layoutType: {
834
- type: String,
835
- default: "relative",
836
- },
837
- dispatcher: {
838
- type: BaseDispatcher,
839
- },
840
- },
841
- setup(props) {
842
- let pageData = new PageData(
843
- props.width,
844
- props.height,
845
- props.direction,
846
- props.padding,
847
- props.layoutType,
848
- props.data,
849
- props.measures,
850
- props.direction === VERTICAL ? props.height : props.width
851
- );
852
- return {
853
- pageData,
854
- isFocus: false,
855
- visibleItemList: [],
856
- itemControlFuncMap: [],
857
- itemRefList: [],
858
- prePages: [],
859
-
860
- enterFocusId: -1,
861
- enterFocusRect: null,
862
- focusId: -1,
863
- preFocusId: -1,
864
- preEdgeRect: null,
865
- visibleStart: -1,
866
- visibleRange: 0,
867
- searchBaseItem: -1,
868
-
869
- keyLock: {
870
- lockTime: -1,
871
- unlockTime: -1,
872
- lockEventTime: -1,
873
- keyEventTime: -1,
874
- locked: false,
875
- },
876
- };
877
- },
878
- data() {
879
- return {
880
- loadingView: {
881
- show: false,
882
- position: null,
883
- },
884
- };
885
- },
886
- methods: {
887
- _getQueryObj(id) {
888
- return {
889
- id: id,
890
- queryPosition: this._queryPosition,
891
- queryTempPosition: this._queryTemplatePosition,
892
- };
893
- },
894
-
895
- _queryPosition(id) {
896
- let item = this.pageData._TemplateParser.GetItem(id);
897
- let x_offset =
898
- this.$props.direction === VERTICAL ? 0 : -this.visibleStart;
899
- let y_offset =
900
- this.$props.direction === VERTICAL ? -this.visibleStart : 0;
901
- return {
902
- xPos: item.xPos + x_offset,
903
- yPos: item.yPos + y_offset,
904
- width: item.width,
905
- height: item.height,
906
- };
907
- },
908
-
909
- _queryTemplatePosition(id) {
910
- let item = this.pageData._TemplateParser.GetItem(id);
911
- return {
912
- xPos: item.xPos,
913
- yPos: item.yPos,
914
- width: item.width,
915
- height: item.height,
916
- };
917
- },
918
-
919
- _dispathcEvent(event) {
920
- let id_list;
921
- switch (event.type) {
922
- case MetroPageDispatcher.Type.setFocusId:
923
- this.enterFocusId = event.data;
924
- break;
925
- case MetroPageDispatcher.Type.setFocusRect:
926
- this.enterFocusRect = event.data;
927
- break;
928
- case MetroPageDispatcher.Type.updateItem:
929
- id_list = event.data;
930
- if (id_list) {
931
- for (let id of id_list) {
932
- if (this.focusId === id) {
933
- this._updateFocusItem();
934
- }
935
- }
936
- }
937
- break;
938
- case MetroPageDispatcher.Type.slideToItem:
939
- if (event.data) {
940
- this._slideViewToAnchor(event.data);
941
- }
942
- break;
943
- default:
944
- break;
945
- }
946
- },
947
-
948
- _getVisibleItemList(id, start, end) {
949
- let visible_info = this.pageData._TemplateParser.GetVisibleItemList(
950
- start,
951
- end,
952
- id
953
- );
954
- return this.pageData._TemplateParser
955
- .GetTemplate()
956
- .List.slice(visible_info.visibleStart, visible_info.visibleEnd + 1);
957
- },
958
-
959
- _calculateNearestItemByRect(template_item_list, enter_rect_info) {
960
- let edge_direction = enter_rect_info.direction;
961
- let rect = enter_rect_info.rect;
962
- var direction = "";
963
- var point = { x: 0, y: 0 };
964
- switch (edge_direction) {
965
- case EdgeDirection.left:
966
- direction = "left";
967
- point.x = rect.x;
968
- point.y = rect.y + rect.height / 4;
969
- break;
970
- case EdgeDirection.right:
971
- direction = "right";
972
- point.x = rect.x + rect.width;
973
- point.y = rect.y + rect.height / 4;
974
- break;
975
- case EdgeDirection.top:
976
- direction = "up";
977
- point.x = rect.x + rect.width / 4;
978
- point.y = rect.y;
979
- break;
980
- case EdgeDirection.bottom:
981
- direction = "down";
982
- point.x = rect.x + rect.width / 4;
983
- point.y = rect.y + rect.height;
984
- break;
985
- default:
986
- break;
987
- }
988
-
989
- var src_x_range = new SingleRangeModel(point.x, point.x);
990
- var src_y_range = new SingleRangeModel(point.y, point.y);
991
-
992
- var min_distance_item = null;
993
- var min_distance = -1;
994
- var min_direction_weighted = 0;
995
- var distance = 0;
996
- var direction_weighted = 0; // 根据进入方向决定的权值,用于保证
997
-
998
- let key_pos = this.$props.direction === VERTICAL ? "yPos" : "xPos";
999
- let key_width = this.$props.direction === VERTICAL ? "height" : "width";
1000
- for (let item of template_item_list) {
1001
- let full_show =
1002
- item[key_pos] >= this.visibleStart &&
1003
- item[key_pos] + item[key_width] - 1 <=
1004
- this.visibleStart + this.visibleRange - 1;
1005
- if (full_show) {
1006
- let x_pos =
1007
- this.$props.direction === VERTICAL
1008
- ? item.xPos
1009
- : item.xPos - this.visibleStart;
1010
- let y_pos =
1011
- this.$props.direction === VERTICAL
1012
- ? item.yPos - this.visibleStart
1013
- : item.yPos;
1014
- var target_x_range = new SingleRangeModel(
1015
- x_pos,
1016
- x_pos + item.width - 1
1017
- );
1018
- var target_y_range = new SingleRangeModel(
1019
- y_pos,
1020
- y_pos + item.height - 1
1021
- );
1022
- switch (direction) {
1023
- case "left":
1024
- if (point.x < x_pos + item.width - 1) {
1025
- // 这个点在item左侧,不可能左移到item
1026
- continue;
1027
- }
1028
- if (point.y < y_pos) {
1029
- //1.该点在其上,计算point和item右上角的距离
1030
- distance =
1031
- Math.pow(point.x - (x_pos + item.width - 1), 2) +
1032
- Math.pow(y_pos - point.y, 2);
1033
- } else if (src_y_range.IsInterAct(target_y_range)) {
1034
- //2.该点在其中,计算point和item右边框的垂直距离
1035
- distance = Math.pow(point.x - (x_pos + item.width - 1), 2);
1036
- } else if (point.y > y_pos + item.height - 1) {
1037
- //3.该点在其下,计算point到item右下角的距离
1038
- distance =
1039
- Math.pow(point.x - (x_pos + item.width - 1), 2) +
1040
- Math.pow(point.y - (y_pos + item.height - 1), 2);
1041
- }
1042
- // point与item右边框的距离作为权值
1043
- direction_weighted = Math.abs(point.x - (x_pos + item.width - 1));
1044
- break;
1045
- case "right":
1046
- if (point.x > x_pos) {
1047
- // 这个点在item右侧,不可能右移到item
1048
- continue;
1049
- }
1050
- if (point.y < y_pos) {
1051
- //1.该点在其上, 计算point和item左上角的距离
1052
- distance =
1053
- Math.pow(x_pos - point.x, 2) + Math.pow(y_pos - point.y, 2);
1054
- } else if (src_y_range.IsInterAct(target_y_range)) {
1055
- //2.该点在其中,计算point和item左边框的垂直距离
1056
- distance = Math.pow(x_pos - point.x, 2);
1057
- //(x2-x1)^2
1058
- } else if (point.y > y_pos + item.height - 1) {
1059
- //3.该点在其下,计算point和item左下角的距离
1060
- distance =
1061
- Math.pow(x_pos - point.x, 2) +
1062
- Math.pow(point.y - (y_pos + item.height - 1), 2);
1063
- }
1064
- // point与item左边框的距离作为权值
1065
- direction_weighted = Math.abs(point.x - x_pos);
1066
- break;
1067
- case "up":
1068
- if (point.y < y_pos + item.height - 1) {
1069
- // 这个点在item上侧,不可能上移到item
1070
- continue;
1071
- }
1072
- if (point.x < x_pos) {
1073
- //1.该点在其前,计算point和item右下角的距离
1074
- distance =
1075
- Math.pow(point.x - x_pos, 2) +
1076
- Math.pow(point.y - (y_pos + item.height - 1), 2);
1077
- } else if (src_x_range.IsInterAct(target_x_range)) {
1078
- //2.该点在其中,计算point和item下边框的垂直距离
1079
- distance = Math.pow(point.y - (y_pos + item.height - 1), 2);
1080
- } else if (point.x > x_pos + item.width - 1) {
1081
- //3.该点在其后,计算point和item左下角的距离
1082
- distance =
1083
- Math.pow(point.x - (x_pos + item.width - 1), 2) +
1084
- Math.pow(point.y - (y_pos + item.height - 1), 2);
1085
- }
1086
- // point与item下边框的距离作为权值
1087
- direction_weighted = Math.abs(
1088
- point.y - (y_pos + item.height - 1)
1089
- );
1090
- break;
1091
- case "down":
1092
- if (point.y > y_pos) {
1093
- // 这个点在item下侧,不可能下移到item
1094
- continue;
1095
- }
1096
- if (point.x < x_pos) {
1097
- //1.该点在其前,计算point和item右上角的距离
1098
- distance =
1099
- Math.pow(point.x - x_pos, 2) + Math.pow(y_pos - point.y, 2);
1100
- } else if (src_x_range.IsInterAct(target_x_range)) {
1101
- //2.该点在其中,计算point和item上边框的垂直距离
1102
- distance = Math.pow(y_pos - point.y, 2);
1103
- } else if (point.x > x_pos + item.width - 1) {
1104
- //3.该点在其后,计算point和item左上角的距离
1105
- distance =
1106
- Math.pow(point.x - (x_pos + item.width - 1), 2) +
1107
- Math.pow(y_pos - point.y, 2);
1108
- }
1109
- // point与item上边框的距离作为权值
1110
- direction_weighted = Math.abs(point.y - y_pos);
1111
- break;
1112
- default:
1113
- console.log("direction is error:" + direction);
1114
- break;
1115
- }
1116
- if (min_distance < 0) {
1117
- // 设置首个找到的项目
1118
- min_distance = distance;
1119
- min_direction_weighted = direction_weighted;
1120
- min_distance_item = item;
1121
- } else {
1122
- if (
1123
- min_direction_weighted > direction_weighted ||
1124
- (min_direction_weighted === direction_weighted &&
1125
- min_distance > distance)
1126
- ) {
1127
- // 先进行权值比较,在权值相等时,再比较距离
1128
- min_distance = distance;
1129
- min_direction_weighted = direction_weighted;
1130
- min_distance_item = item;
1131
- }
1132
- }
1133
- }
1134
- }
1135
-
1136
- if (min_distance_item) {
1137
- return min_distance_item.id;
1138
- } else {
1139
- return 0;
1140
- }
1141
- },
1142
-
1143
- _onClick(index) {
1144
- let item = this.pageData._TemplateParser.GetItem(index);
1145
- if (!item.hasSub && this.$props.onClick) {
1146
- this.$props.onClick(item.data);
1147
- }
1148
- },
1149
-
1150
- onKeyDown(ev) {
1151
- this.keyLock.keyEventTime = ev.timeStamp;
1152
- if (
1153
- this.keyLock.lockEventTime > 0 &&
1154
- this.keyLock.lockTime > 0 &&
1155
- ev.timeStamp <
1156
- this.keyLock.lockEventTime +
1157
- (this.keyLock.unlockTime - this.keyLock.lockTime)
1158
- ) {
1159
- return true;
1160
- }
1161
- //todo unlock后超过200毫秒的事件丢弃
1162
- if (this.keyLock.locked) {
1163
- if (
1164
- ev.keyCode === 37 ||
1165
- ev.keyCode === 38 ||
1166
- ev.keyCode === 39 ||
1167
- ev.keyCode === 40 ||
1168
- ev.keyCode === 13
1169
- ) {
1170
- return true;
1171
- } else {
1172
- return false;
1173
- }
1174
- }
1175
- switch (ev.keyCode) {
1176
- case 37:
1177
- this._moveToNext(-1, 0);
1178
- break;
1179
- case 38:
1180
- this._moveToNext(0, -1);
1181
- break;
1182
- case 39:
1183
- this._moveToNext(1, 0);
1184
- break;
1185
- case 40:
1186
- this._moveToNext(0, 1);
1187
- break;
1188
- case 13:
1189
- this._onClick(this.focusId);
1190
- break;
1191
- default:
1192
- //只接受上下左右确定键
1193
- return false;
1194
- }
1195
- return true;
1196
- },
1197
-
1198
- onKeyUp(ev) {
1199
- if (this.keyLock.locked) {
1200
- return true;
1201
- }
1202
- let direction = 0;
1203
- switch (ev.keyCode) {
1204
- case 37:
1205
- direction = this.$props.direction === VERTICAL ? 0 : -1;
1206
- break;
1207
- case 38:
1208
- direction = this.$props.direction === VERTICAL ? -1 : 0;
1209
- break;
1210
- case 39:
1211
- direction = this.$props.direction === VERTICAL ? 0 : 1;
1212
- break;
1213
- case 40:
1214
- direction = this.$props.direction === VERTICAL ? 1 : 0;
1215
- break;
1216
- default:
1217
- return;
1218
- }
1219
- if (direction !== 0) {
1220
- let pages = this.pageData.getPageList(
1221
- this.visibleStart - this.visibleRange,
1222
- this.visibleStart + 2 * this.visibleRange - 1,
1223
- direction
1224
- );
1225
- this.prePages = pages;
1226
- this.rootView.updatePages(pages, true);
1227
- }
1228
- },
1229
-
1230
- _reportVisibleEvent(
1231
- baseItemId,
1232
- cur_visible_start,
1233
- cur_visible_end,
1234
- do_anim,
1235
- need_update_root
1236
- ) {
1237
- this.visibleStart = cur_visible_start;
1238
- //可见的item设置visibility
1239
- let x = this.$props.direction === VERTICAL ? 0 : -this.visibleStart;
1240
- let y = this.$props.direction === VERTICAL ? -this.visibleStart : 0;
1241
- if (!do_anim) {
1242
- if (need_update_root) {
1243
- this.rootView.updatePosition(x, y, do_anim, this._onTransitionEnd);
1244
- }
1245
- } else {
1246
- //更新rootview
1247
- this.rootView.updatePosition(x, y, do_anim, this._onTransitionEnd);
1248
- }
1249
- },
1250
-
1251
- _moveToNext(horizontal_direction, vertical_direction, item_edge_rect) {
1252
- let template = this.pageData._TemplateParser.GetTemplate();
1253
- let focus_index = template.IdsMap[this.focusId];
1254
- let next_index = this.pageData._TemplateParser.GetNextItem(
1255
- this.focusId,
1256
- vertical_direction,
1257
- horizontal_direction,
1258
- this.$props.loopFocus
1259
- );
1260
-
1261
- if (next_index >= 0) {
1262
- let direction =
1263
- this.$props.direction === VERTICAL
1264
- ? vertical_direction
1265
- : horizontal_direction;
1266
- let next_item = this.pageData._TemplateParser.GetItem(next_index);
1267
- let visible_info = this._CalculateSlide(
1268
- next_item,
1269
- direction,
1270
- this.visibleStart
1271
- );
1272
- let new_visible_start = visible_info.visibleStart;
1273
- let pre_visible_start = this.visibleStart;
1274
- let need_update_foucs = true;
1275
-
1276
- if (direction !== 0) {
1277
- //direction 方向的按键才触发page更新处理
1278
- let focus_page_index = this.pageData.getPageByIndex(
1279
- this.prePages,
1280
- next_index
1281
- );
1282
- let focus_page = this.prePages[focus_page_index];
1283
- let next_page_index = focus_page_index + direction;
1284
- let next_page = null;
1285
- if (next_page_index < this.prePages.length && next_page_index >= 0) {
1286
- next_page = this.prePages[next_page_index];
1287
- }
1288
-
1289
- let pos_key = this.$props.direction === VERTICAL ? "yPos" : "xPos";
1290
- let size_key =
1291
- this.$props.direction === VERTICAL ? "height" : "width";
1292
- let next_item_key_pos =
1293
- direction > 0
1294
- ? next_item[pos_key] + next_item[size_key] - 1
1295
- : next_item[pos_key];
1296
- let if_page_end =
1297
- direction > 0
1298
- ? next_item_key_pos >= focus_page.bottom
1299
- : next_item_key_pos <= focus_page.top;
1300
- let need_show_loading = false;
1301
-
1302
- let focus_page_done = this.rootView.ifPageUpdateDone(
1303
- focus_page.token
1304
- );
1305
-
1306
- if (focus_page) {
1307
- this.rootView.updateFocusPage(focus_page);
1308
- } else {
1309
- return;
1310
- }
1311
- if (!focus_page_done) {
1312
- need_update_foucs = false;
1313
- need_show_loading = true;
1314
- let cur_item = this.pageData._TemplateParser.GetItem(this.focusId);
1315
- next_item_key_pos =
1316
- direction > 0
1317
- ? cur_item[pos_key] + cur_item[size_key] - 1
1318
- : cur_item[pos_key];
1319
- this.keyLock.lockTime = Date.now();
1320
- this.keyLock.lockEventTime = this.keyLock.keyEventTime;
1321
- this.keyLock.locked = true;
1322
- } else {
1323
- if (next_page == null) {
1324
- //没有下一页
1325
- if (!visible_info.toEdge && direction !== 0 && if_page_end) {
1326
- //加载新的page
1327
- let pages = this.pageData.getPageList(
1328
- this.visibleStart - this.visibleRange,
1329
- this.visibleStart + 2 * this.visibleRange - 1,
1330
- direction
1331
- );
1332
- let page_changed = false;
1333
- if (this.prePages) {
1334
- for (let i = 0; i < pages.length; i++) {
1335
- if (pages[i].token !== this.prePages[i].token) {
1336
- page_changed = true;
1337
- break;
1338
- }
1339
- }
1340
- } else {
1341
- page_changed = true;
1342
- }
1343
- if (page_changed) {
1344
- this.prePages = pages;
1345
- this.keyLock.lockTime = Date.now();
1346
- this.keyLock.lockEventTime = this.keyLock.keyEventTime;
1347
- this.keyLock.locked = true;
1348
- }
1349
- need_show_loading = true;
1350
- }
1351
- } else if (!this.rootView.ifPageUpdateDone(next_page.token)) {
1352
- //下一页未加载完
1353
- if (if_page_end) {
1354
- //到达page边缘,等待页面加载
1355
- this.keyLock.locked = true;
1356
- this.keyLock.lockTime = Date.now();
1357
- this.keyLock.lockEventTime = this.keyLock.keyEventTime;
1358
-
1359
- need_show_loading = true;
1360
- }
1361
- } else {
1362
- //下一页存在
1363
- }
1364
- }
1365
-
1366
- if (need_show_loading) {
1367
- //计算展示loading view时的滚动距离
1368
- if (this.$props.loadViewSize && this.$slots.loadingView) {
1369
- let loading_view_pos = {
1370
- x: 0,
1371
- y: 0,
1372
- };
1373
- let padding = _getPadding(this.$props.padding);
1374
- let padding_pos =
1375
- this.$props.direction === VERTICAL
1376
- ? padding["top"]
1377
- : padding["left"];
1378
- let w_key =
1379
- this.$props.direction === VERTICAL ? "height" : "width";
1380
- if (direction > 0) {
1381
- new_visible_start =
1382
- next_item_key_pos -
1383
- this.visibleRange +
1384
- 1 +
1385
- this.$props.loadViewSize[w_key] +
1386
- padding_pos;
1387
- let loading_pos_key =
1388
- this.$props.direction === VERTICAL ? "y" : "x";
1389
- loading_view_pos[loading_pos_key] =
1390
- this.visibleRange - this.$props.loadViewSize[w_key];
1391
- } else {
1392
- new_visible_start =
1393
- next_item_key_pos -
1394
- this.$props.loadViewSize[w_key] +
1395
- padding_pos;
1396
- }
1397
-
1398
- eventHub.dispatch(Event.ShowLoadingView, true);
1399
- this.loadingView.show = true;
1400
- this.loadingView.position = loading_view_pos;
1401
- eventHub.dispatch(Event.ShowLoadingViewDone);
1402
- }
1403
- }
1404
- }
1405
-
1406
- this.visibleStart = new_visible_start;
1407
- if (pre_visible_start !== this.visibleStart) {
1408
- let anim_info = {
1409
- speed: 1.5,
1410
- easing: null,
1411
- onstart: null,
1412
- onend: null,
1413
- };
1414
- if (this.$props.direction === HORIZONTAL) {
1415
- this.rootView.updatePosition(-this.visibleStart, 0, anim_info);
1416
- } else {
1417
- this.rootView.updatePosition(0, -this.visibleStart, anim_info);
1418
- }
1419
- }
1420
-
1421
- let target_focus_item = need_update_foucs
1422
- ? next_item
1423
- : this.pageData._TemplateParser.GetItem(this.focusId);
1424
- //更新焦点位置
1425
- if (this.$props.onFocusPosChange) {
1426
- this.$props.onFocusPosChange(
1427
- target_focus_item.data,
1428
- this._queryPosition(target_focus_item.id)
1429
- );
1430
- }
1431
-
1432
- if (need_update_foucs) {
1433
- this.searchBaseItem = next_index;
1434
- this.preFocusId = this.focusId;
1435
- this.focusId = next_item.id;
1436
-
1437
- if (next_item.hasSub) {
1438
- let rect;
1439
- let x_off_set =
1440
- template.List[focus_index].xPos - template.List[next_index].xPos;
1441
- let y_off_set =
1442
- template.List[focus_index].yPos - template.List[next_index].yPos;
1443
- if (item_edge_rect) {
1444
- item_edge_rect.rect.x += x_off_set;
1445
- item_edge_rect.rect.y += y_off_set;
1446
- rect = item_edge_rect;
1447
- } else {
1448
- rect = {
1449
- direction: null,
1450
- rect: {
1451
- x: x_off_set,
1452
- y: y_off_set,
1453
- width: template.List[focus_index].width,
1454
- height: template.List[focus_index].height,
1455
- },
1456
- };
1457
- }
1458
- this.preEdgeRect = rect;
1459
- } else {
1460
- this._updateBlurItem();
1461
- this._updateFocusItem();
1462
- }
1463
-
1464
- if (this.preFocusId >= 0 && this.$props.onItemBlur) {
1465
- let data = this.pageData._TemplateParser.GetItem(this.preFocusId)
1466
- .data;
1467
- this.$props.onItemBlur(
1468
- data,
1469
- this._getQueryObj(this.preFocusId),
1470
- this.itemRefList[this.preFocusId]
1471
- );
1472
- }
1473
-
1474
- if (this.isFocus) {
1475
- if (this.$props.onItemFocus) {
1476
- this.$props.onItemFocus(
1477
- next_item.data,
1478
- this.preEdgeRect,
1479
- this._getQueryObj(next_item.id),
1480
- this.itemRefList[next_item.id]
1481
- );
1482
- }
1483
- }
1484
- }
1485
- } else {
1486
- if (this.$props.onEdge) {
1487
- let x_off_set =
1488
- this.$props.direction === VERTICAL ? 0 : this.visibleStart;
1489
- let y_off_set =
1490
- this.$props.direction === VERTICAL ? this.visibleStart : 0;
1491
- let edge;
1492
- if (horizontal_direction === 1) {
1493
- edge = EdgeDirection.right;
1494
- }
1495
- if (horizontal_direction === -1) {
1496
- edge = EdgeDirection.left;
1497
- }
1498
- if (vertical_direction === 1) {
1499
- edge = EdgeDirection.bottom;
1500
- }
1501
- if (vertical_direction === -1) {
1502
- edge = EdgeDirection.top;
1503
- }
1504
- let rect = {
1505
- x: template.List[focus_index].xPos - x_off_set,
1506
- y: template.List[focus_index].yPos - y_off_set,
1507
- width: template.List[focus_index].width,
1508
- height: template.List[focus_index].height,
1509
- };
1510
- this.$props.onEdge({ direction: edge, rect: rect });
1511
- }
1512
- }
1513
- },
1514
-
1515
- _CalculateSlide(target_item, direction, visible_start) {
1516
- let pre_visible_start = visible_start;
1517
- let cur_visible_start = pre_visible_start;
1518
- let template_list = this.pageData._TemplateParser.GetTemplate().List;
1519
- let last_item = template_list[template_list.length - 1];
1520
- let pos_key = this.$props.direction === VERTICAL ? "yPos" : "xPos";
1521
- let width_key = this.$props.direction === VERTICAL ? "height" : "width";
1522
- let padding_key = this.$props.direction === VERTICAL ? "bottom" : "right";
1523
- let visible_range =
1524
- this.$props.direction === VERTICAL
1525
- ? this.$props.height
1526
- : this.$props.width;
1527
- let move_to_edge = false;
1528
-
1529
- let last_item_off_set;
1530
- switch (this.$props.slideStyle) {
1531
- case SlideStyle.seamLess:
1532
- last_item_off_set =
1533
- last_item[pos_key] +
1534
- last_item[width_key] -
1535
- visible_range +
1536
- _getPadding(this.$props.padding)[padding_key];
1537
- if (direction > 0) {
1538
- if (
1539
- target_item[pos_key] + target_item[width_key] >
1540
- pre_visible_start + (visible_range * 4) / 5
1541
- ) {
1542
- cur_visible_start =
1543
- target_item[pos_key] +
1544
- target_item[width_key] -
1545
- (visible_range * 4) / 5;
1546
- }
1547
- } else if (direction < 0) {
1548
- if (target_item[pos_key] < pre_visible_start + visible_range / 5) {
1549
- cur_visible_start = target_item[pos_key] - visible_range / 5;
1550
- }
1551
- } else {
1552
- //不是沿widget方向的移动
1553
- if (target_item[pos_key] < pre_visible_start) {
1554
- cur_visible_start = target_item[pos_key] - visible_range / 5;
1555
- } else if (
1556
- target_item[pos_key] + target_item[width_key] >
1557
- pre_visible_start + visible_range
1558
- ) {
1559
- cur_visible_start =
1560
- target_item[pos_key] +
1561
- target_item[width_key] -
1562
- (visible_range * 4) / 5;
1563
- }
1564
- }
1565
- if (cur_visible_start > last_item_off_set) {
1566
- move_to_edge = true;
1567
- cur_visible_start = last_item_off_set;
1568
- }
1569
- if (cur_visible_start < 0) {
1570
- move_to_edge = true;
1571
- cur_visible_start = 0;
1572
- }
1573
- break;
1574
- case SlideStyle.wholePage:
1575
- if (direction > 0) {
1576
- if (
1577
- target_item[pos_key] + target_item[width_key] >
1578
- pre_visible_start + visible_range + 1
1579
- ) {
1580
- cur_visible_start = target_item[pos_key];
1581
- }
1582
- } else if (direction < 0) {
1583
- if (target_item[pos_key] < pre_visible_start) {
1584
- cur_visible_start =
1585
- target_item[pos_key] + target_item[width_key] - visible_range;
1586
- if (cur_visible_start < 0) {
1587
- move_to_edge = true;
1588
- cur_visible_start = 0;
1589
- }
1590
- }
1591
- }
1592
- break;
1593
- case SlideStyle.seamlessFixedId:
1594
- break;
1595
- default:
1596
- break;
1597
- }
1598
- return {
1599
- toEdge: move_to_edge,
1600
- visibleStart: cur_visible_start,
1601
- };
1602
- },
1603
-
1604
- _OnFocusableItemEdge(edge_info) {
1605
- let horizontal_direction = 0;
1606
- let vertical_direction = 0;
1607
- switch (edge_info.direction) {
1608
- case EdgeDirection.left:
1609
- horizontal_direction = -1;
1610
- break;
1611
- case EdgeDirection.right:
1612
- horizontal_direction = 1;
1613
- break;
1614
- case EdgeDirection.top:
1615
- vertical_direction = -1;
1616
- break;
1617
- case EdgeDirection.bottom:
1618
- vertical_direction = 1;
1619
- break;
1620
- default:
1621
- break;
1622
- }
1623
- this._moveToNext(horizontal_direction, vertical_direction, edge_info);
1624
- },
1625
-
1626
- _ifValidEnterRect(rect_info) {
1627
- return rect_info && rect_info.direction && rect_info.rect;
1628
- },
1629
-
1630
- _setZIndex(index, z_index) {
1631
- let visible_item = this.itemControlFuncMap[index];
1632
- if (visible_item && visible_item.zIndexFunc) {
1633
- visible_item.zIndexFunc(z_index);
1634
- }
1635
- },
1636
-
1637
- _onFocus() {
1638
- let focus_id =
1639
- typeof this.enterFocusId !== "undefined" &&
1640
- this.enterFocusId >= 0 &&
1641
- this.enterFocusId <
1642
- this.pageData._TemplateParser.GetTemplate().List.length
1643
- ? this.enterFocusId
1644
- : this.focusId;
1645
- focus_id = this._ifValidEnterRect(this.enterFocusRect)
1646
- ? this._calculateNearestItemByRect(
1647
- this.visibleItemList,
1648
- this.enterFocusRect
1649
- )
1650
- : focus_id;
1651
-
1652
- this.isFocus = true;
1653
- this.focusId = focus_id;
1654
- this.preFocusId = -1;
1655
- this._updateFocusItem();
1656
-
1657
- let focus_item = this.pageData._TemplateParser.GetItem(focus_id);
1658
- if (this.$props.onItemFocus) {
1659
- if (focus_item.mounted) {
1660
- this.$props.onItemFocus(
1661
- focus_item.data,
1662
- null,
1663
- this._getQueryObj(focus_item.id),
1664
- this.itemRefList[focus_item.id]
1665
- );
1666
- } else {
1667
- Promise.resolve().then(() => {
1668
- this.$props.onItemFocus(
1669
- focus_item.data,
1670
- null,
1671
- this._getQueryObj(focus_item.id),
1672
- this.itemRefList[focus_item.id]
1673
- );
1674
- this._updateFocusItem();
1675
- });
1676
- }
1677
- }
1678
-
1679
- if (this.$props.onFocusPosChange) {
1680
- this.$props.onFocusPosChange(
1681
- focus_item.data,
1682
- this._queryPosition(focus_item.id)
1683
- );
1684
- }
1685
-
1686
- if (this.$props.onFocus) {
1687
- this.$props.onFocus();
1688
- }
1689
- },
1690
-
1691
- _onBlur() {
1692
- this.isFocus = false;
1693
- this.enterFocusId = -1;
1694
- this.enterFocusRect = null;
1695
-
1696
- this.preFocusId = this.focusId;
1697
- this.preEdgeRect = null;
1698
- this._updateBlurItem();
1699
- if (this.$props.onItemBlur) {
1700
- let data = this.pageData._TemplateParser.GetItem(this.preFocusId).data;
1701
- this.$props.onItemBlur(
1702
- data,
1703
- this._getQueryObj(this.preFocusId),
1704
- this.itemRefList[this.preFocusId]
1705
- );
1706
- }
1707
- if (this.$props.onBlur) {
1708
- this.$props.onBlur();
1709
- }
1710
- },
1711
-
1712
- _onTransitionEnd(event) {
1713
- //todo
1714
- empty_func(event);
1715
- },
1716
-
1717
- _drawItem(item) {
1718
- let item_view = this.itemRefList[item.id];
1719
- if (!item_view) {
1720
- item_view = {};
1721
- this.itemRefList[item.id] = item_view;
1722
- }
1723
- return function() {
1724
- console.log("render func ", item.id);
1725
- return this.$slots.renderItem({
1726
- data: item.data,
1727
- onEdge: this._OnFocusableItemEdge,
1728
- query: this._getQueryObj(item.id),
1729
- refObj: item_view,
1730
- });
1731
- }.bind(this);
1732
- },
1733
-
1734
- _updateFocusItem() {
1735
- let focus_item = this.pageData._TemplateParser.GetItem(this.focusId);
1736
- if (focus_item) {
1737
- this._setZIndex(
1738
- this.pageData._TemplateParser.GetTemplate().IdsMap[this.focusId],
1739
- this.$props.data.length
1740
- );
1741
- }
1742
- },
1743
-
1744
- _updateBlurItem() {
1745
- this._setZIndex(
1746
- this.pageData._TemplateParser.GetTemplate().IdsMap[this.preFocusId],
1747
- 0
1748
- );
1749
- },
1750
-
1751
- _BaseAnchorInfo2Pos(anchor_info, visible_start, visible_range) {
1752
- let id = anchor_info.id;
1753
- let target_pos = {
1754
- xPos: this.$props.direction === VERTICAL ? 0 : visible_start,
1755
- yPos: this.$props.direction === VERTICAL ? visible_start : 0,
1756
- };
1757
- if (typeof id !== "undefined" && id !== null) {
1758
- let template_list = this.pageData._TemplateParser.GetTemplate().List;
1759
- let item = template_list[id];
1760
- let last_item = template_list[template_list.length - 1];
1761
- if (item) {
1762
- let type =
1763
- typeof anchor_info.type !== "undefined"
1764
- ? anchor_info.type
1765
- : "start";
1766
- let key_pos = this.$props.direction === VERTICAL ? "yPos" : "xPos";
1767
- let key_width =
1768
- this.$props.direction === VERTICAL ? "height" : "width";
1769
- let padding_key =
1770
- this.$props.direction === VERTICAL ? "bottom" : "right";
1771
- switch (type) {
1772
- case "start":
1773
- target_pos[key_pos] = item[key_pos];
1774
- break;
1775
- case "center":
1776
- target_pos[key_pos] =
1777
- item[key_pos] - visible_range / 2 + item[key_width] / 2;
1778
- break;
1779
- case "end":
1780
- target_pos[key_pos] =
1781
- item[key_pos] +
1782
- item[key_width] -
1783
- 1 -
1784
- visible_range +
1785
- _getPadding(this.$props.padding)[padding_key];
1786
- break;
1787
- default:
1788
- break;
1789
- }
1790
- let last_item_off_set =
1791
- last_item[key_pos] +
1792
- last_item[key_width] -
1793
- visible_range +
1794
- _getPadding(this.$props.padding)[padding_key];
1795
- target_pos[key_pos] =
1796
- target_pos[key_pos] > last_item_off_set
1797
- ? last_item_off_set
1798
- : target_pos[key_pos];
1799
- target_pos[key_pos] =
1800
- target_pos[key_pos] < 0 ? 0 : target_pos[key_pos];
1801
- }
1802
- }
1803
- return target_pos;
1804
- },
1805
-
1806
- _slideViewToAnchor(anchor_info) {
1807
- if (
1808
- anchor_info.id < 0 ||
1809
- anchor_info.id >=
1810
- this.pageData._TemplateParser.GetTemplate().List.length
1811
- ) {
1812
- return;
1813
- }
1814
- let pos = this._BaseAnchorInfo2Pos(
1815
- anchor_info,
1816
- this.visibleStart,
1817
- this.visibleRange
1818
- );
1819
- this.visibleStart =
1820
- this.$props.direction === VERTICAL ? pos.yPos : pos.xPos;
1821
-
1822
- let do_anim =
1823
- typeof anchor_info.doAnim === "undefined" ||
1824
- anchor_info.doAnim === null ||
1825
- anchor_info.doAnim;
1826
- let anim_info = null;
1827
- if (do_anim) {
1828
- anim_info = {
1829
- speed: 1.5,
1830
- easing: null,
1831
- onstart: null,
1832
- onend: null,
1833
- };
1834
- }
1835
-
1836
- this.rootView.updatePosition(-pos.xPos, -pos.yPos, anim_info);
1837
- this.searchBaseItem = anchor_info.id;
1838
-
1839
- let pages = this.pageData.getPageList(
1840
- this.visibleStart - this.visibleRange,
1841
- this.visibleStart + 2 * this.visibleRange - 1,
1842
- 1
1843
- );
1844
- this.prePages = pages;
1845
- this.rootView.updatePages(pages, false);
1846
- },
1847
-
1848
- _updateFocusByDragInfo(viewX, viewY) {
1849
- let enterFocusRect = null;
1850
- //模拟最小区域作为输入区域
1851
- if (this.$props.direction === VERTICAL) {
1852
- enterFocusRect = {
1853
- direction: EdgeDirection.top,
1854
- rect: {
1855
- x: this.$props.left - viewX,
1856
- y: this.$props.top - viewY,
1857
- width: 10,
1858
- height: 10,
1859
- },
1860
- };
1861
- } else {
1862
- enterFocusRect = {
1863
- direction: EdgeDirection.left,
1864
- rect: {
1865
- x: this.$props.left - viewX,
1866
- y: this.$props.top - viewY,
1867
- width: 10,
1868
- height: 10,
1869
- },
1870
- };
1871
- }
1872
- this.focusId = this._calculateNearestItemByRect(
1873
- this.visibleItemList,
1874
- enterFocusRect
1875
- );
1876
- },
1877
-
1878
- _tryReoprtVisibleEvent(msg) {
1879
- if (typeof msg.viewY != "undefined" && typeof msg.viewX != "undefined") {
1880
- if (this.$props.direction === VERTICAL) {
1881
- this.visibleStart = -msg.viewY;
1882
- } else {
1883
- this.visibleStart = -msg.viewX;
1884
- }
1885
- if (this.visibleStart < 0) {
1886
- this.visibleStart = 0;
1887
- }
1888
- }
1889
-
1890
- let cur_visible_start = this.visibleStart - this.visibleRange * 2;
1891
- let cur_visible_end = this.visibleStart + this.visibleRange * 3 - 1;
1892
- let baseItemId = this.searchBaseItem ? this.searchBaseItem : 0;
1893
- this._reportVisibleEvent(
1894
- baseItemId,
1895
- cur_visible_start,
1896
- cur_visible_end,
1897
- false
1898
- );
1899
- },
1900
-
1901
- _getTouchListener() {
1902
- if (!this.$props.enableTouch) {
1903
- return null;
1904
- }
1905
- let callback = {
1906
- OnDragStart: (msg) => {
1907
- //console.log("MetroPage Container OnDragStart:" + JSON.stringify(msg));
1908
- Promise.resolve().then(() => {
1909
- this._tryReoprtVisibleEvent(msg);
1910
- Forge.sRenderBridge.InstantPerformSwap();
1911
- });
1912
- return true;
1913
- },
1914
- OnMoved: (msg) => {
1915
- Promise.resolve().then(() => {
1916
- this._tryReoprtVisibleEvent(msg);
1917
- Forge.sRenderBridge.InstantPerformSwap();
1918
- });
1919
- return true;
1920
- },
1921
- OnDragEnd: (msg) => {
1922
- //console.log("MetroPage Container OnDragEnd:" + JSON.stringify(msg));
1923
- this._tryReoprtVisibleEvent(msg);
1924
- this._updateFocusByDragInfo(msg["viewX"], msg["viewY"]);
1925
- this._onTransitionEnd();
1926
- return true;
1927
- },
1928
- OnFling: (msg) => {
1929
- //console.log("MetroPage Container OnFling:" + JSON.stringify(msg));
1930
- this._tryReoprtVisibleEvent(msg);
1931
- this._updateFocusByDragInfo(msg["viewX"], msg["viewY"]);
1932
- this._onTransitionEnd();
1933
- return true;
1934
- },
1935
- OnRelease: (msg) => {
1936
- empty_func(msg);
1937
- //console.log("MetroPage Container OnRelease:" + JSON.stringify(msg));
1938
- return true;
1939
- },
1940
- };
1941
- return callback;
1942
- },
1943
-
1944
- _registerItemControlFunc(id) {
1945
- return (zindex_func) => {
1946
- this.itemControlFuncMap[id] = {
1947
- zIndexFunc: zindex_func,
1948
- };
1949
- };
1950
- },
1951
- _renderFunc(item) {
1952
- return (
1953
- <metro-page-item
1954
- // key={item.id}
1955
- x={item.xPos}
1956
- y={item.yPos}
1957
- w={item.width}
1958
- h={item.height}
1959
- index={item.id}
1960
- enableTouch={this.$props.enableTouch}
1961
- onClick={this._onClick}
1962
- setControlFunc={this._registerItemControlFunc(item.id)}
1963
- renderFunc={this._drawItem(item)}
1964
- mountStateUpdate={_mountStateUpdate(item)}
1965
- />
1966
- );
1967
- },
1968
-
1969
- _registerRootView(ref) {
1970
- this.rootView = ref;
1971
- },
1972
-
1973
- _showLoadingPageDoneCallback() {
1974
- this.rootView.updatePages(this.prePages, false);
1975
- },
1976
-
1977
- _updatePageDoneCallback() {
1978
- this.keyLock.unlockTime = Date.now();
1979
- this.keyLock.locked = false;
1980
- if (this.loadingView.show) {
1981
- this.loadingView.show = false;
1982
- this.loadingView.position = null;
1983
- }
1984
- },
1985
- },
1986
- render() {
1987
- const template_list = this.pageData._TemplateParser.GetTemplate().List;
1988
- const last_item = template_list[template_list.length - 1];
1989
- const touchListener = this._getTouchListener();
1990
- let padding = _getPadding(this.$props.padding);
1991
- const touchcontainer_w =
1992
- this.$props.direction === VERTICAL
1993
- ? this.$props.width
1994
- : last_item.xPos + last_item.width;
1995
- const touchcontainer_h =
1996
- this.$props.direction === VERTICAL
1997
- ? last_item.yPos + last_item.height
1998
- : this.$props.height;
1999
-
2000
- return (
2001
- <FDiv
2002
- branchName={this.branchName}
2003
- onFocus={this._onFocus}
2004
- onBlur={this._onBlur}
2005
- onKeyDown={this.onKeyDown}
2006
- onKeyUp={this.onKeyUp}
2007
- >
2008
- <div
2009
- style={{
2010
- left: this.$props.left,
2011
- top: this.$props.top,
2012
- width: this.$props.width,
2013
- height: this.$props.height,
2014
- overflow: "hidden",
2015
- }}
2016
- >
2017
- <metro-page-root
2018
- x={padding.left}
2019
- y={padding.top}
2020
- w={touchcontainer_w}
2021
- h={touchcontainer_h}
2022
- flingPageWidth={this.$props.flingPageWidth}
2023
- flingPageEdge={this.$props.flingPageEdge}
2024
- slidePile={
2025
- new Forge.RectArea(
2026
- 0,
2027
- 0,
2028
- this.$props.width - padding.left - padding.right,
2029
- this.$props.height - padding.top - padding.bottom
2030
- )
2031
- }
2032
- touchListener={touchListener}
2033
- registerRootView={this._registerRootView}
2034
- renderFunc={this._renderFunc}
2035
- />
2036
- {this.loadingView.show ? (
2037
- <div
2038
- style={{
2039
- left: this.loadingView.position.x,
2040
- top: this.loadingView.position.y,
2041
- }}
2042
- >
2043
- {this.$slots.loadingView()}
2044
- </div>
2045
- ) : null}
2046
- </div>
2047
- </FDiv>
2048
- );
2049
- },
2050
- created() {
2051
- let init_focus_id = 0;
2052
- let cur_visible_start = 0;
2053
- let visible_range =
2054
- this.$props.direction === VERTICAL
2055
- ? this.$props.height
2056
- : this.$props.width;
2057
- this.visibleItemList = this._getVisibleItemList(
2058
- init_focus_id,
2059
- cur_visible_start,
2060
- cur_visible_start + visible_range - 1
2061
- );
2062
- if (typeof this.$props.baseAnchor !== "undefined") {
2063
- let pos = this._BaseAnchorInfo2Pos(
2064
- this.$props.baseAnchor,
2065
- 0,
2066
- visible_range
2067
- );
2068
- cur_visible_start =
2069
- this.$props.direction === VERTICAL ? pos.yPos : pos.xPos;
2070
- this.visibleItemList = this._getVisibleItemList(
2071
- this.$props.baseAnchor.id,
2072
- cur_visible_start,
2073
- cur_visible_start + visible_range - 1
2074
- );
2075
- }
2076
- if (this.$props.initFocusId) {
2077
- init_focus_id = this.$props.initFocusId;
2078
- if (typeof this.$props.baseAnchor === "undefined") {
2079
- cur_visible_start = this._CalculateSlide(
2080
- this.pageData._TemplateParser.GetItem(init_focus_id),
2081
- 1,
2082
- 0
2083
- ).visibleStart;
2084
- this.visibleItemList = this._getVisibleItemList(
2085
- init_focus_id,
2086
- cur_visible_start,
2087
- cur_visible_start + visible_range - 1
2088
- );
2089
- }
2090
- }
2091
- this.focusId = init_focus_id;
2092
- this.visibleStart = cur_visible_start;
2093
- this.visibleRange = visible_range;
2094
- },
2095
- mounted() {
2096
- //注册事件
2097
- eventHub.registerEvent(
2098
- Event.ShowLoadingViewDone,
2099
- this._showLoadingPageDoneCallback
2100
- );
2101
- eventHub.registerEvent(Event.UpdatePageDone, this._updatePageDoneCallback);
2102
-
2103
- let visible_start = this.visibleStart;
2104
- let visible_end = this.visibleStart + this.visibleRange - 1;
2105
- let pages = this.pageData.getPageList(visible_start, visible_end, 1);
2106
- this.prePages = pages;
2107
- let load_type_list = new Array(pages.length);
2108
- for (let i = 0; i < pages.length; i++) {
2109
- load_type_list[i] = !(
2110
- pages[i].top <= visible_end + this.visibleRange &&
2111
- pages[i].bottom >= visible_start
2112
- );
2113
- }
2114
- this.rootView.updatePages(pages, load_type_list);
2115
- if (this.visibleStart !== 0) {
2116
- let x = this.$props.direction === VERTICAL ? 0 : -this.visibleStart;
2117
- let y = this.$props.direction === VERTICAL ? -this.visibleStart : 0;
2118
- this.rootView.updatePosition(x, y);
2119
- }
2120
- },
2121
- beforeUnmount() {
2122
- if (this.$props.dispatcher) {
2123
- this.$props.dispatcher.unregisterComponent();
2124
- }
2125
- },
2126
- };
2127
-
2128
- export { MetroPage };