@shijiu/jsview-vue 0.9.254 → 0.9.267

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 (168) hide show
  1. package/dom/bin/package.json +11 -11
  2. package/dom/browser-root-style.css +21 -21
  3. package/loader/jsview-main.js +41 -41
  4. package/loader/jsview.config.default.js +37 -37
  5. package/loader/jsview.default.config.js +37 -37
  6. package/package.json +1 -5
  7. package/samples/AdvanceMetroWidget/App.vue +122 -122
  8. package/samples/AdvanceMetroWidget/Frame.vue +100 -100
  9. package/samples/AdvanceMetroWidget/Item.vue +57 -57
  10. package/samples/AdvanceMetroWidget/data.js +136 -136
  11. package/samples/AnimPicture/App.vue +223 -223
  12. package/samples/Basic/App.vue +128 -128
  13. package/samples/Basic/components/TitleBar.vue +28 -28
  14. package/samples/Basic/components/anim/AnimGroup.vue +67 -67
  15. package/samples/Basic/components/anim/AnimKeyframeBasic.vue +101 -101
  16. package/samples/Basic/components/anim/AnimKeyframeComposite.vue +52 -52
  17. package/samples/Basic/components/anim/AnimTransition.vue +116 -116
  18. package/samples/Basic/components/div/DivBackground.vue +14 -14
  19. package/samples/Basic/components/div/DivClip.vue +80 -80
  20. package/samples/Basic/components/div/DivCssScoped.vue +26 -26
  21. package/samples/Basic/components/div/DivCssVar.vue +49 -49
  22. package/samples/Basic/components/div/DivGroup1.vue +32 -32
  23. package/samples/Basic/components/div/DivGroup2.vue +40 -40
  24. package/samples/Basic/components/div/DivLayout.vue +11 -11
  25. package/samples/Basic/components/div/DivRadius.vue +46 -46
  26. package/samples/Basic/components/text/TextAlign.vue +47 -47
  27. package/samples/Basic/components/text/TextFontStyle.vue +57 -57
  28. package/samples/Basic/components/text/TextGroup.vue +31 -31
  29. package/samples/Basic/components/text/TextOverflow.vue +77 -77
  30. package/samples/BasicFocusControl/App.vue +124 -124
  31. package/samples/BasicFocusControl/components/BaseBlock.vue +50 -50
  32. package/samples/BasicFocusControl/components/MainArea.vue +97 -97
  33. package/samples/BasicFocusControl/components/MainAreaLeftBlock.vue +20 -20
  34. package/samples/BasicFocusControl/components/MainAreaRightBlock.vue +29 -29
  35. package/samples/BasicFocusControl/components/SideBar.vue +72 -72
  36. package/samples/BasicFocusControl/components/SideBarBlock.vue +29 -29
  37. package/samples/ClassNameDemo/App.vue +119 -119
  38. package/samples/ClassNameDemo/components/ContentItem.vue +252 -252
  39. package/samples/ClassNameDemo/components/LoadingView.vue +43 -43
  40. package/samples/ClassNameDemo/components/TitleView.vue +24 -24
  41. package/samples/ClassNameDemo/data.js +24 -24
  42. package/samples/ColorSpace/App.vue +134 -134
  43. package/samples/DemoHomepage/App.vue +31 -31
  44. package/samples/DemoHomepage/components/BodyFrame.vue +81 -81
  45. package/samples/DemoHomepage/components/Dialog.vue +93 -93
  46. package/samples/DemoHomepage/components/Item.vue +76 -76
  47. package/samples/DemoHomepage/components/TabFrame.vue +86 -86
  48. package/samples/DemoHomepage/router.js +132 -132
  49. package/samples/DemoHomepage/views/Homepage.vue +186 -186
  50. package/samples/FlipCard/App.vue +80 -80
  51. package/samples/FlipCard/FlipCard.vue +123 -123
  52. package/samples/FlipCard/data.js +12 -12
  53. package/samples/FlowMultiWidget/App.vue +90 -90
  54. package/samples/FlowMultiWidget/components/Block.vue +106 -106
  55. package/samples/FlowMultiWidget/components/FlowPage.vue +59 -59
  56. package/samples/FlowMultiWidget/components/Item.vue +102 -102
  57. package/samples/FlowMultiWidget/components/MenuItem.vue +71 -71
  58. package/samples/FlowMultiWidget/components/MyMenu.vue +89 -89
  59. package/samples/FlowMultiWidget/data.js +446 -446
  60. package/samples/HashHistory/App.vue +124 -124
  61. package/samples/HashHistory/components/HorizontalButtonList.vue +113 -113
  62. package/samples/HashHistory/components/Item.vue +73 -73
  63. package/samples/HashHistory/router.js +29 -29
  64. package/samples/HashHistory/views/BasePage.vue +18 -18
  65. package/samples/HashHistory/views/MainPage.vue +67 -67
  66. package/samples/HashHistory/views/SubPage.vue +78 -78
  67. package/samples/HashHistory/views/SubPageFirst.vue +9 -9
  68. package/samples/HashHistory/views/SubPageSecond.vue +9 -9
  69. package/samples/LongImage/App.vue +96 -96
  70. package/samples/LongImage/Button.vue +153 -153
  71. package/samples/LongImage/LongImageScroll.vue +126 -126
  72. package/samples/LongImage/Scroll.vue +15 -15
  73. package/samples/LongText/App.vue +111 -111
  74. package/samples/LongText/Button.vue +153 -153
  75. package/samples/LongText/LongTextScroll.vue +224 -224
  76. package/samples/LongText/Scroll.vue +15 -15
  77. package/samples/Preload/App.vue +145 -145
  78. package/samples/Preload/data.js +22 -22
  79. package/samples/Preload/preloadItem.vue +21 -21
  80. package/samples/QrcodeDemo/App.vue +72 -72
  81. package/samples/SimpleWidgetDemo/App.vue +203 -203
  82. package/samples/SimpleWidgetDemo/Item.vue +82 -82
  83. package/samples/SimpleWidgetDemo/components/ContentItem.vue +411 -411
  84. package/samples/SimpleWidgetDemo/components/MyTab.vue +116 -116
  85. package/samples/SimpleWidgetDemo/data.js +110 -110
  86. package/samples/SprayView/App.vue +269 -269
  87. package/samples/SpriteImage/App.vue +174 -174
  88. package/samples/SpriteImage/images/egg_break.json +116 -116
  89. package/samples/TextBox/App.vue +178 -178
  90. package/samples/TextBox/RenderCenter.vue +108 -108
  91. package/samples/TextBox/RenderLeft.vue +108 -108
  92. package/samples/TextBox/RenderOneLine.vue +119 -119
  93. package/samples/TextBox/RenderRight.vue +106 -106
  94. package/samples/TextShadowDemo/App.vue +97 -97
  95. package/samples/TextureSize/App.vue +141 -141
  96. package/samples/ThrowMoveDemo/AccelerateDemo.vue +117 -117
  97. package/samples/ThrowMoveDemo/App.vue +113 -113
  98. package/samples/ThrowMoveDemo/LRParabolicDemo.vue +115 -115
  99. package/samples/ThrowMoveDemo/TargetDemo.vue +116 -116
  100. package/samples/ThrowMoveDemo/UDParabolicDemo.vue +121 -121
  101. package/samples/TransitPage/App.vue +40 -40
  102. package/samples/VideoDemo/App.vue +137 -137
  103. package/samples/VideoDemo/components/Button.vue +68 -68
  104. package/samples/VideoDemo/components/Controllor.vue +195 -195
  105. package/samples/VideoDemo/components/VideoFrame.vue +152 -152
  106. package/scripts/common.js +57 -115
  107. package/scripts/jsview-install-local-packages.js +73 -73
  108. package/scripts/jsview-post-build.js +127 -127
  109. package/scripts/jsview-post-install.js +78 -78
  110. package/scripts/jsview-run-android.js +64 -64
  111. package/utils/JsViewEngineWidget/bin/index.js +1 -1
  112. package/utils/JsViewEngineWidget/bin/package.json +11 -11
  113. package/utils/JsViewVueTools/JsvHashHistory.js +111 -111
  114. package/utils/JsViewVueTools/JsvRuntimeBridge.js +417 -417
  115. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserPreload.vue +80 -80
  116. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserQrcode.vue +147 -147
  117. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserSpray.vue +54 -54
  118. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/ApicDataBase.js +28 -28
  119. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/BrowserApic.vue +123 -123
  120. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/GifData.js +83 -83
  121. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/LoopToolBase.js +25 -25
  122. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/NormalLoopTool.js +61 -61
  123. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/PartLoopTool.js +119 -119
  124. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/Viewer.js +106 -106
  125. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/WebpData.js +141 -141
  126. package/utils/JsViewVueWidget/BrowserDebugWidget/WidgetLoader.js +20 -20
  127. package/utils/JsViewVueWidget/JsvActorMove/ActorControlBase.js +204 -204
  128. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMove.vue +63 -63
  129. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMoveControl.js +426 -426
  130. package/utils/JsViewVueWidget/JsvActorMove/index.js +12 -12
  131. package/utils/JsViewVueWidget/JsvApic/JsvApic.vue +178 -178
  132. package/utils/JsViewVueWidget/JsvApic/index.js +17 -17
  133. package/utils/JsViewVueWidget/JsvMarquee.vue +196 -196
  134. package/utils/JsViewVueWidget/JsvNinePatch.vue +76 -76
  135. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +350 -350
  136. package/utils/JsViewVueWidget/JsvPreload/index.js +21 -21
  137. package/utils/JsViewVueWidget/JsvQrcode/JsvQrcode.vue +140 -140
  138. package/utils/JsViewVueWidget/JsvQrcode/index.js +18 -18
  139. package/utils/JsViewVueWidget/JsvSpray/JsvSpray.vue +139 -139
  140. package/utils/JsViewVueWidget/JsvSpray/index.js +14 -14
  141. package/utils/JsViewVueWidget/JsvSpriteAnim/JsvSpriteAnim.vue +447 -447
  142. package/utils/JsViewVueWidget/JsvSpriteAnim/SpriteController.js +56 -56
  143. package/utils/JsViewVueWidget/JsvSpriteAnim/index.js +6 -6
  144. package/utils/JsViewVueWidget/JsvSwiper/Indicator.vue +34 -34
  145. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +494 -494
  146. package/utils/JsViewVueWidget/JsvSwiper/index.js +9 -9
  147. package/utils/JsViewVueWidget/JsvSwiper3D/Indicator.vue +34 -34
  148. package/utils/JsViewVueWidget/JsvSwiper3D/JsvSwiper.vue +403 -403
  149. package/utils/JsViewVueWidget/JsvSwiper3D/index.js +9 -9
  150. package/utils/JsViewVueWidget/JsvTextBox.vue +110 -110
  151. package/utils/JsViewVueWidget/JsvVideo.vue +35 -35
  152. package/patches/node_modules/@babel/preset-env/lib/available-plugins.js +0 -219
  153. package/patches/node_modules/@vue/cli-plugin-typescript/index.js +0 -100
  154. package/patches/node_modules/@vue/cli-service/lib/commands/serve.js +0 -395
  155. package/patches/node_modules/@vue/cli-service/lib/config/app.js +0 -272
  156. package/patches/node_modules/@vue/cli-service/lib/config/assets.js +0 -70
  157. package/patches/node_modules/@vue/cli-service/lib/config/base.js +0 -212
  158. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -2566
  159. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js +0 -274
  160. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1596
  161. package/patches/node_modules/postcss-js/objectifier.js +0 -90
  162. package/patches/node_modules/vue-loader/dist/resolveScript.js +0 -70
  163. package/scripts/deploy-fast-pack.js +0 -17
  164. package/scripts/deploy-fast-publish.js +0 -44
  165. package/scripts/deploy-git-commit-empty.js +0 -21
  166. package/scripts/deploy-prepare.js +0 -56
  167. package/scripts/make-js.sh +0 -181
  168. package/vetur.config.js +0 -5
@@ -1,351 +1,351 @@
1
- <!--
2
- * 【模块 export 内容】
3
- * JsvPreload:Vue高阶组件,图片预加载的控件
4
- * preloadList {ObjectArray}: 预加载的信息列表,单个内容通过buildPreloadInfo构建
5
- * downloadList {ObjectArray}: 预下载的信息列表,单个内容通过buildDownloadInfo构建
6
- * onPreloading {Function(float percent)}: 预加载中回调,返回预加载进度
7
- * onPreloadDone {Function()}: 预加载完成回调
8
- * onDownloadDone {Function(pathes)}: 预下载完成回调,pathes为下载好回调的地址
9
- *
10
- * 注意事项:
11
- * 指定加载时的尺寸(0为不指定),与img标签中的 jsv_img_scaledown_tex 属性一起使用
12
- * 指定加载色空间,与div标签中的 jsv_img_color_space 一起使用。
13
- * 因为,同样url情况下,jsv_img_scaledown_tex 和 jsv_img_color_space 启用后,不同的尺寸不同颜色空间
14
- * 对应着各自不同的图片内存缓存
15
- *
16
- * 静态函数:
17
- * buildPreloadInfo: 静态函数,创建预加载信息项,用于制作JsvPreload的preloadList属性列表信息
18
- * 参数:
19
- * url {string}: (必填)图片url
20
- * width {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
21
- * height {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
22
- * color_type {string}: 图片存储颜色空间,去掉alpha通道可节省内存,例如"RGB_565"等,与img标签jsv_img_color_space配合,默认值"RGBA_8888"
23
- * net_setting {object}: (未实现)网络加载参数,cookie, refer等,默认值 null
24
- *
25
- * buildDownloadInfo: 函数,创建预下载信息项,用于制作JsvPreload的downloadList属性列表信息
26
- * 参数:
27
- * url {string}: (必填)图片url
28
- * width {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
29
- * height {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
30
- * color_type {string}: 图片存储颜色空间,去掉alpha通道可节省内存,例如"RGB_565"等,与img标签jsv_img_color_space配合,默认值"RGBA_8888"
31
- * net_setting {object}: (未实现)网络加载参数,cookie, refer等,默认值 null
32
- -->
33
- <script>
34
- import { Forge, ForgeExtension } from "../../../dom/jsv-forge-define";
35
-
36
- const CONST_FORMAT_TOKEN = "_JsvP_";
37
- const buildPreloadInfo = (
38
- url,
39
- width = 0,
40
- height = 0,
41
- color_type = "RGBA_8888",
42
- net_setting = null
43
- ) => {
44
- return {
45
- url,
46
- width,
47
- height,
48
- colorType: color_type,
49
- netSetting: net_setting,
50
- magicToken: CONST_FORMAT_TOKEN, // 用于格式校验
51
- };
52
- };
53
-
54
- const buildDownloadInfo = (url, net_setting = null) => {
55
- return {
56
- url,
57
- netSetting: net_setting,
58
- magicToken: CONST_FORMAT_TOKEN, // 用于格式校验
59
- };
60
- };
61
-
62
- export { buildPreloadInfo, buildDownloadInfo };
63
-
64
- export default {
65
- props: {
66
- preloadList: Object,
67
- downloadList: Object,
68
- onPreloading: Function,
69
- onPreloadDone: Function,
70
- onDownloadDone: Function,
71
- sprayStyle: Object,
72
- },
73
- data() {
74
- return {
75
- preloadViewList: [],
76
- downloadViewList: [],
77
- preloadStateList: [],
78
- downloadStateList: [],
79
- preloadResultMap: {},
80
- CONST_FORMAT_TOKEN: "_JsvP_",
81
- preloadIsNullNum: 0, // 纪录传入的preload为null的数量,由于vue不支持在子组件修改props值,所有在删除值为null时,需要++,这样才能保证与传入数据的length相等从而触发回调
82
- };
83
- },
84
- methods: {
85
- _releaseForgeView() {
86
- if (window.JsView) {
87
- if (this.preloadViewList.length > 0) {
88
- for (const view_info of this.preloadViewList) {
89
- if (view_info) {
90
- // 当预加载url为null时view_info为null
91
- const id = view_info.viewId;
92
- // UnMarkImportant & UnregisterLoadImageCallback(这两个API同版本加入)
93
- if (
94
- view_info.textureRef &&
95
- view_info.textureRef.DisableBackgroundLoad
96
- ) {
97
- view_info.textureRef.DisableBackgroundLoad(this);
98
- view_info.textureRef.UnregisterLoadImageCallback(
99
- view_info.callToken
100
- );
101
- }
102
- ForgeExtension.RootActivity.ViewStore.remove(id);
103
- }
104
- }
105
- this.preloadViewList = [];
106
- }
107
-
108
- if (this.downloadViewList.length > 0) {
109
- for (const view_info of this.downloadViewList) {
110
- if (view_info) {
111
- // 当预加载url为null时view_info为null
112
- const id = view_info.viewId;
113
- // UnMarkImportant & UnregisterLoadImageCallback(这两个API同版本加入)
114
- if (
115
- view_info.textureRef &&
116
- view_info.textureRef.DisableBackgroundLoad
117
- ) {
118
- view_info.textureRef.DisableBackgroundLoad(this);
119
- view_info.textureRef.UnregisterLoadImageCallback(
120
- view_info.callToken
121
- );
122
- }
123
- ForgeExtension.RootActivity.ViewStore.remove(id);
124
- }
125
- }
126
- this.downloadViewList = [];
127
- }
128
- } else {
129
- this.preloadViewList = [];
130
- this.downloadViewList = [];
131
- this.preloadStateList = [];
132
- this.downloadStateList = [];
133
- }
134
- },
135
-
136
- // shouldComponentUpdate(nextProps, nextState) {
137
- // if (
138
- // nextProps.preloadList.length === this.preloadList.length &&
139
- // nextProps.downloadList.length === this.downloadList.length
140
- // ) {
141
- // let same = true;
142
- // for (let i = 0; i < nextProps.preloadList.length; i++) {
143
- // if (nextProps.preloadList[i].url !== this.preloadList[i].url) {
144
- // same = false;
145
- // break;
146
- // }
147
- // }
148
- // for (let i = 0; i < nextProps.downloadList.length; i++) {
149
- // if (nextProps.downloadList[i].url !== this.downloadList[i].url) {
150
- // same = false;
151
- // break;
152
- // }
153
- // }
154
- // return !same;
155
- // }
156
- // return true;
157
- // },
158
-
159
- _checkPreload() {
160
- let loadedNum = 0;
161
- this.preloadStateList.forEach((state) => {
162
- loadedNum = state ? ++loadedNum : loadedNum;
163
- });
164
- if (this.onPreloading) {
165
- this.onPreloading(loadedNum / this.preloadStateList.length);
166
- }
167
- if (
168
- this.onPreloadDone &&
169
- loadedNum === this.preloadStateList.length - this.preloadIsNullNum
170
- ) {
171
- this.onPreloadDone(this.preloadResultMap);
172
- }
173
- },
174
-
175
- _getPreloadViewIdList() {
176
- if (!this.preloadList) {
177
- return;
178
- }
179
- this.preloadStateList = new Array(this.preloadList.length).fill(false);
180
- // 直接在map前将为null的值删除掉
181
- let preloadListData = this.preloadList;
182
- for (let i = 0; i < preloadListData.length; i++) {
183
- if (!preloadListData[i]) {
184
- preloadListData.splice(i, 1);
185
- this.preloadIsNullNum++;
186
- }
187
- }
188
- this.preloadViewList = preloadListData.map((item, index) => {
189
- if (item.magicToken !== this.CONST_FORMAT_TOKEN) {
190
- console.error(
191
- "Error:format mismatch, data should comes from function buildPreloadInfo()"
192
- );
193
- }
194
- const base_url = item.url;
195
- let image_url = base_url;
196
- if (base_url && base_url.indexOf("http") < 0) {
197
- // 包含http和https两种请求
198
- if (window.JsView.React.UrlRef) {
199
- image_url = new window.JsView.React.UrlRef(base_url).href;
200
- }
201
- }
202
- let target_size = null;
203
- if (item.width !== 0 && item.height !== 0) {
204
- target_size = { width: item.width, height: item.height };
205
- }
206
- let texture = null;
207
- if (
208
- image_url &&
209
- (image_url.toLowerCase().indexOf(".webp") >= 0 ||
210
- image_url.toLowerCase().indexOf(".gif") >= 0)
211
- ) {
212
- texture = ForgeExtension.TextureManager.GetGifImage(image_url, false);
213
- } else {
214
- texture = ForgeExtension.TextureManager.GetImage2(
215
- image_url,
216
- false,
217
- target_size,
218
- item.colorType
219
- );
220
- }
221
- if (!texture) {
222
- console.error(
223
- "Error: Preload view build texture failed for " + image_url
224
- );
225
- this.preloadStateList[index] = true; // 无法创建texture的图片先认为加载完成
226
- return;
227
- }
228
- const callback_token = texture.RegisterLoadImageCallback(
229
- null,
230
- (params) => {
231
- console.log(`preload succeed ${image_url}`, params);
232
- this.preloadStateList[index] = true;
233
- this.preloadResultMap[item.url] = {
234
- width: params.width,
235
- height: params.height,
236
- };
237
- console.log(`preload succeed ${item.url}, params:${params}`);
238
- this._checkPreload();
239
- }
240
- );
241
- if (texture.EnableBackgroundLoad) {
242
- texture.EnableBackgroundLoad(this);
243
- }
244
- const texture_setting = new Forge.ExternalTextureSetting(texture);
245
- const preload_view = new Forge.PreloadView(texture_setting);
246
- return {
247
- viewId: ForgeExtension.RootActivity.ViewStore.add(
248
- new Forge.ViewInfo(preload_view, {
249
- x: 0,
250
- y: 0,
251
- width: 0,
252
- height: 0,
253
- })
254
- ),
255
- textureRef: texture,
256
- callToken: callback_token,
257
- };
258
- });
259
- },
260
-
261
- _checkDownload() {
262
- for (const state of this.downloadStateList) {
263
- if (!state) return;
264
- }
265
- if (this.$props.onDownloadDone) {
266
- console.log("zhang $props downloadStateList =",this.downloadStateList)
267
- this.$props.onDownloadDone(this.downloadStateList);
268
- }
269
- },
270
-
271
- _getDownloadViewIdList() {
272
- if (!this.downloadList) {
273
- return;
274
- }
275
- this.downloadStateList = new Array(this.downloadList.length).fill(null);
276
- // 直接在map前将url为null的值清除掉
277
- let downloadListData = this.downloadList;
278
- for (let i = 0; i < downloadListData.length; i++) {
279
- if (!downloadListData[i].url) {
280
- downloadListData.splice(i, 1);
281
- }
282
- }
283
- this.downloadViewList = downloadListData.map((item, index) => {
284
- if (item.magicToken !== this.CONST_FORMAT_TOKEN) {
285
- console.error(
286
- "Error:format mismatch, data should comes from function buildDownloadInfo()"
287
- );
288
- }
289
- const base_url = item.url;
290
- let image_url = base_url;
291
- if (base_url && base_url.indexOf("http") < 0) {
292
- // 包含http和https两种请求
293
- if (window.JsView.React.UrlRef) {
294
- image_url = new window.JsView.React.UrlRef(base_url).href;
295
- }
296
- }
297
- const texture =
298
- ForgeExtension.TextureManager.GetDownloadTexture(image_url);
299
- if (!texture) {
300
- console.error("Error: Down view build texture failed for " + image_url);
301
- // 无法创建texture的图片先认为加载完成
302
- this.downloadStateList[index] = "invalid";
303
- return;
304
- }
305
- const callback_token = texture.RegisterLoadImageCallback(null, (texture_info) => {
306
- console.log("zhang texture_info =",texture_info);
307
- this.downloadStateList[index] = texture_info.extra.absolutePath;
308
- this._checkDownload();
309
- });
310
- if (texture.EnableBackgroundLoad) {
311
- texture.EnableBackgroundLoad(this);
312
- }
313
- const texture_setting = new Forge.TextureSetting(texture); // Download类型的释放跟随view一同释放
314
- const preload_view = new Forge.PreloadView(texture_setting);
315
-
316
- return {
317
- viewId: ForgeExtension.RootActivity.ViewStore.add(
318
- new Forge.ViewInfo(preload_view, {
319
- x: 0,
320
- y: 0,
321
- width: 0,
322
- height: 0,
323
- })
324
- ),
325
- textureRef: texture,
326
- callToken: callback_token,
327
- };
328
- });
329
- },
330
- },
331
- created() {
332
- this._releaseForgeView();
333
- this._getPreloadViewIdList();
334
- this._getDownloadViewIdList();
335
- },
336
- beforeUnmount() {
337
- this._releaseForgeView();
338
- },
339
- };
340
- </script>
341
-
342
- <template>
343
- <div>
344
- <div v-for="item in preloadViewList" :key="item.viewId" :id="item.viewId">
345
- <div v-if="item.viewId" :jsv_innerview="item.viewId"></div>
346
- </div>
347
- <div v-for="item in downloadViewList" :key="item.viewId" :id="item.viewId">
348
- <div v-if="item.viewId" :jsv_innerview="item.viewId"></div>
349
- </div>
350
- </div>
1
+ <!--
2
+ * 【模块 export 内容】
3
+ * JsvPreload:Vue高阶组件,图片预加载的控件
4
+ * preloadList {ObjectArray}: 预加载的信息列表,单个内容通过buildPreloadInfo构建
5
+ * downloadList {ObjectArray}: 预下载的信息列表,单个内容通过buildDownloadInfo构建
6
+ * onPreloading {Function(float percent)}: 预加载中回调,返回预加载进度
7
+ * onPreloadDone {Function()}: 预加载完成回调
8
+ * onDownloadDone {Function(pathes)}: 预下载完成回调,pathes为下载好回调的地址
9
+ *
10
+ * 注意事项:
11
+ * 指定加载时的尺寸(0为不指定),与img标签中的 jsv_img_scaledown_tex 属性一起使用
12
+ * 指定加载色空间,与div标签中的 jsv_img_color_space 一起使用。
13
+ * 因为,同样url情况下,jsv_img_scaledown_tex 和 jsv_img_color_space 启用后,不同的尺寸不同颜色空间
14
+ * 对应着各自不同的图片内存缓存
15
+ *
16
+ * 静态函数:
17
+ * buildPreloadInfo: 静态函数,创建预加载信息项,用于制作JsvPreload的preloadList属性列表信息
18
+ * 参数:
19
+ * url {string}: (必填)图片url
20
+ * width {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
21
+ * height {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
22
+ * color_type {string}: 图片存储颜色空间,去掉alpha通道可节省内存,例如"RGB_565"等,与img标签jsv_img_color_space配合,默认值"RGBA_8888"
23
+ * net_setting {object}: (未实现)网络加载参数,cookie, refer等,默认值 null
24
+ *
25
+ * buildDownloadInfo: 函数,创建预下载信息项,用于制作JsvPreload的downloadList属性列表信息
26
+ * 参数:
27
+ * url {string}: (必填)图片url
28
+ * width {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
29
+ * height {int}: 图片内存存储区域宽度,默认为0(同图片源文件宽度)
30
+ * color_type {string}: 图片存储颜色空间,去掉alpha通道可节省内存,例如"RGB_565"等,与img标签jsv_img_color_space配合,默认值"RGBA_8888"
31
+ * net_setting {object}: (未实现)网络加载参数,cookie, refer等,默认值 null
32
+ -->
33
+ <script>
34
+ import { Forge, ForgeExtension } from "../../../dom/jsv-forge-define";
35
+
36
+ const CONST_FORMAT_TOKEN = "_JsvP_";
37
+ const buildPreloadInfo = (
38
+ url,
39
+ width = 0,
40
+ height = 0,
41
+ color_type = "RGBA_8888",
42
+ net_setting = null
43
+ ) => {
44
+ return {
45
+ url,
46
+ width,
47
+ height,
48
+ colorType: color_type,
49
+ netSetting: net_setting,
50
+ magicToken: CONST_FORMAT_TOKEN, // 用于格式校验
51
+ };
52
+ };
53
+
54
+ const buildDownloadInfo = (url, net_setting = null) => {
55
+ return {
56
+ url,
57
+ netSetting: net_setting,
58
+ magicToken: CONST_FORMAT_TOKEN, // 用于格式校验
59
+ };
60
+ };
61
+
62
+ export { buildPreloadInfo, buildDownloadInfo };
63
+
64
+ export default {
65
+ props: {
66
+ preloadList: Object,
67
+ downloadList: Object,
68
+ onPreloading: Function,
69
+ onPreloadDone: Function,
70
+ onDownloadDone: Function,
71
+ sprayStyle: Object,
72
+ },
73
+ data() {
74
+ return {
75
+ preloadViewList: [],
76
+ downloadViewList: [],
77
+ preloadStateList: [],
78
+ downloadStateList: [],
79
+ preloadResultMap: {},
80
+ CONST_FORMAT_TOKEN: "_JsvP_",
81
+ preloadIsNullNum: 0, // 纪录传入的preload为null的数量,由于vue不支持在子组件修改props值,所有在删除值为null时,需要++,这样才能保证与传入数据的length相等从而触发回调
82
+ };
83
+ },
84
+ methods: {
85
+ _releaseForgeView() {
86
+ if (window.JsView) {
87
+ if (this.preloadViewList.length > 0) {
88
+ for (const view_info of this.preloadViewList) {
89
+ if (view_info) {
90
+ // 当预加载url为null时view_info为null
91
+ const id = view_info.viewId;
92
+ // UnMarkImportant & UnregisterLoadImageCallback(这两个API同版本加入)
93
+ if (
94
+ view_info.textureRef &&
95
+ view_info.textureRef.DisableBackgroundLoad
96
+ ) {
97
+ view_info.textureRef.DisableBackgroundLoad(this);
98
+ view_info.textureRef.UnregisterLoadImageCallback(
99
+ view_info.callToken
100
+ );
101
+ }
102
+ ForgeExtension.RootActivity.ViewStore.remove(id);
103
+ }
104
+ }
105
+ this.preloadViewList = [];
106
+ }
107
+
108
+ if (this.downloadViewList.length > 0) {
109
+ for (const view_info of this.downloadViewList) {
110
+ if (view_info) {
111
+ // 当预加载url为null时view_info为null
112
+ const id = view_info.viewId;
113
+ // UnMarkImportant & UnregisterLoadImageCallback(这两个API同版本加入)
114
+ if (
115
+ view_info.textureRef &&
116
+ view_info.textureRef.DisableBackgroundLoad
117
+ ) {
118
+ view_info.textureRef.DisableBackgroundLoad(this);
119
+ view_info.textureRef.UnregisterLoadImageCallback(
120
+ view_info.callToken
121
+ );
122
+ }
123
+ ForgeExtension.RootActivity.ViewStore.remove(id);
124
+ }
125
+ }
126
+ this.downloadViewList = [];
127
+ }
128
+ } else {
129
+ this.preloadViewList = [];
130
+ this.downloadViewList = [];
131
+ this.preloadStateList = [];
132
+ this.downloadStateList = [];
133
+ }
134
+ },
135
+
136
+ // shouldComponentUpdate(nextProps, nextState) {
137
+ // if (
138
+ // nextProps.preloadList.length === this.preloadList.length &&
139
+ // nextProps.downloadList.length === this.downloadList.length
140
+ // ) {
141
+ // let same = true;
142
+ // for (let i = 0; i < nextProps.preloadList.length; i++) {
143
+ // if (nextProps.preloadList[i].url !== this.preloadList[i].url) {
144
+ // same = false;
145
+ // break;
146
+ // }
147
+ // }
148
+ // for (let i = 0; i < nextProps.downloadList.length; i++) {
149
+ // if (nextProps.downloadList[i].url !== this.downloadList[i].url) {
150
+ // same = false;
151
+ // break;
152
+ // }
153
+ // }
154
+ // return !same;
155
+ // }
156
+ // return true;
157
+ // },
158
+
159
+ _checkPreload() {
160
+ let loadedNum = 0;
161
+ this.preloadStateList.forEach((state) => {
162
+ loadedNum = state ? ++loadedNum : loadedNum;
163
+ });
164
+ if (this.onPreloading) {
165
+ this.onPreloading(loadedNum / this.preloadStateList.length);
166
+ }
167
+ if (
168
+ this.onPreloadDone &&
169
+ loadedNum === this.preloadStateList.length - this.preloadIsNullNum
170
+ ) {
171
+ this.onPreloadDone(this.preloadResultMap);
172
+ }
173
+ },
174
+
175
+ _getPreloadViewIdList() {
176
+ if (!this.preloadList) {
177
+ return;
178
+ }
179
+ this.preloadStateList = new Array(this.preloadList.length).fill(false);
180
+ // 直接在map前将为null的值删除掉
181
+ let preloadListData = this.preloadList;
182
+ for (let i = 0; i < preloadListData.length; i++) {
183
+ if (!preloadListData[i]) {
184
+ preloadListData.splice(i, 1);
185
+ this.preloadIsNullNum++;
186
+ }
187
+ }
188
+ this.preloadViewList = preloadListData.map((item, index) => {
189
+ if (item.magicToken !== this.CONST_FORMAT_TOKEN) {
190
+ console.error(
191
+ "Error:format mismatch, data should comes from function buildPreloadInfo()"
192
+ );
193
+ }
194
+ const base_url = item.url;
195
+ let image_url = base_url;
196
+ if (base_url && base_url.indexOf("http") < 0) {
197
+ // 包含http和https两种请求
198
+ if (window.JsView.React.UrlRef) {
199
+ image_url = new window.JsView.React.UrlRef(base_url).href;
200
+ }
201
+ }
202
+ let target_size = null;
203
+ if (item.width !== 0 && item.height !== 0) {
204
+ target_size = { width: item.width, height: item.height };
205
+ }
206
+ let texture = null;
207
+ if (
208
+ image_url &&
209
+ (image_url.toLowerCase().indexOf(".webp") >= 0 ||
210
+ image_url.toLowerCase().indexOf(".gif") >= 0)
211
+ ) {
212
+ texture = ForgeExtension.TextureManager.GetGifImage(image_url, false);
213
+ } else {
214
+ texture = ForgeExtension.TextureManager.GetImage2(
215
+ image_url,
216
+ false,
217
+ target_size,
218
+ item.colorType
219
+ );
220
+ }
221
+ if (!texture) {
222
+ console.error(
223
+ "Error: Preload view build texture failed for " + image_url
224
+ );
225
+ this.preloadStateList[index] = true; // 无法创建texture的图片先认为加载完成
226
+ return;
227
+ }
228
+ const callback_token = texture.RegisterLoadImageCallback(
229
+ null,
230
+ (params) => {
231
+ console.log(`preload succeed ${image_url}`, params);
232
+ this.preloadStateList[index] = true;
233
+ this.preloadResultMap[item.url] = {
234
+ width: params.width,
235
+ height: params.height,
236
+ };
237
+ console.log(`preload succeed ${item.url}, params:${params}`);
238
+ this._checkPreload();
239
+ }
240
+ );
241
+ if (texture.EnableBackgroundLoad) {
242
+ texture.EnableBackgroundLoad(this);
243
+ }
244
+ const texture_setting = new Forge.ExternalTextureSetting(texture);
245
+ const preload_view = new Forge.PreloadView(texture_setting);
246
+ return {
247
+ viewId: ForgeExtension.RootActivity.ViewStore.add(
248
+ new Forge.ViewInfo(preload_view, {
249
+ x: 0,
250
+ y: 0,
251
+ width: 0,
252
+ height: 0,
253
+ })
254
+ ),
255
+ textureRef: texture,
256
+ callToken: callback_token,
257
+ };
258
+ });
259
+ },
260
+
261
+ _checkDownload() {
262
+ for (const state of this.downloadStateList) {
263
+ if (!state) return;
264
+ }
265
+ if (this.$props.onDownloadDone) {
266
+ console.log("zhang $props downloadStateList =",this.downloadStateList)
267
+ this.$props.onDownloadDone(this.downloadStateList);
268
+ }
269
+ },
270
+
271
+ _getDownloadViewIdList() {
272
+ if (!this.downloadList) {
273
+ return;
274
+ }
275
+ this.downloadStateList = new Array(this.downloadList.length).fill(null);
276
+ // 直接在map前将url为null的值清除掉
277
+ let downloadListData = this.downloadList;
278
+ for (let i = 0; i < downloadListData.length; i++) {
279
+ if (!downloadListData[i].url) {
280
+ downloadListData.splice(i, 1);
281
+ }
282
+ }
283
+ this.downloadViewList = downloadListData.map((item, index) => {
284
+ if (item.magicToken !== this.CONST_FORMAT_TOKEN) {
285
+ console.error(
286
+ "Error:format mismatch, data should comes from function buildDownloadInfo()"
287
+ );
288
+ }
289
+ const base_url = item.url;
290
+ let image_url = base_url;
291
+ if (base_url && base_url.indexOf("http") < 0) {
292
+ // 包含http和https两种请求
293
+ if (window.JsView.React.UrlRef) {
294
+ image_url = new window.JsView.React.UrlRef(base_url).href;
295
+ }
296
+ }
297
+ const texture =
298
+ ForgeExtension.TextureManager.GetDownloadTexture(image_url);
299
+ if (!texture) {
300
+ console.error("Error: Down view build texture failed for " + image_url);
301
+ // 无法创建texture的图片先认为加载完成
302
+ this.downloadStateList[index] = "invalid";
303
+ return;
304
+ }
305
+ const callback_token = texture.RegisterLoadImageCallback(null, (texture_info) => {
306
+ console.log("zhang texture_info =",texture_info);
307
+ this.downloadStateList[index] = texture_info.extra.absolutePath;
308
+ this._checkDownload();
309
+ });
310
+ if (texture.EnableBackgroundLoad) {
311
+ texture.EnableBackgroundLoad(this);
312
+ }
313
+ const texture_setting = new Forge.TextureSetting(texture); // Download类型的释放跟随view一同释放
314
+ const preload_view = new Forge.PreloadView(texture_setting);
315
+
316
+ return {
317
+ viewId: ForgeExtension.RootActivity.ViewStore.add(
318
+ new Forge.ViewInfo(preload_view, {
319
+ x: 0,
320
+ y: 0,
321
+ width: 0,
322
+ height: 0,
323
+ })
324
+ ),
325
+ textureRef: texture,
326
+ callToken: callback_token,
327
+ };
328
+ });
329
+ },
330
+ },
331
+ created() {
332
+ this._releaseForgeView();
333
+ this._getPreloadViewIdList();
334
+ this._getDownloadViewIdList();
335
+ },
336
+ beforeUnmount() {
337
+ this._releaseForgeView();
338
+ },
339
+ };
340
+ </script>
341
+
342
+ <template>
343
+ <div>
344
+ <div v-for="item in preloadViewList" :key="item.viewId" :id="item.viewId">
345
+ <div v-if="item.viewId" :jsv_innerview="item.viewId"></div>
346
+ </div>
347
+ <div v-for="item in downloadViewList" :key="item.viewId" :id="item.viewId">
348
+ <div v-if="item.viewId" :jsv_innerview="item.viewId"></div>
349
+ </div>
350
+ </div>
351
351
  </template>