@shijiu/jsview-vue 0.9.246 → 0.9.254

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 (173) 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 +6 -6
  7. package/patches/node_modules/@babel/preset-env/lib/available-plugins.js +218 -218
  8. package/patches/node_modules/@vue/cli-plugin-typescript/index.js +100 -100
  9. package/patches/node_modules/@vue/cli-service/lib/commands/serve.js +395 -395
  10. package/patches/node_modules/@vue/cli-service/lib/config/app.js +272 -272
  11. package/patches/node_modules/@vue/cli-service/lib/config/assets.js +70 -70
  12. package/patches/node_modules/@vue/cli-service/lib/config/base.js +212 -212
  13. package/patches/node_modules/postcss-js/objectifier.js +90 -90
  14. package/patches/node_modules/vue-loader/dist/resolveScript.js +70 -70
  15. package/samples/AdvanceMetroWidget/App.vue +122 -122
  16. package/samples/AdvanceMetroWidget/Frame.vue +100 -100
  17. package/samples/AdvanceMetroWidget/Item.vue +57 -57
  18. package/samples/AdvanceMetroWidget/data.js +136 -136
  19. package/samples/AnimPicture/App.vue +223 -223
  20. package/samples/Basic/App.vue +128 -128
  21. package/samples/Basic/components/TitleBar.vue +28 -28
  22. package/samples/Basic/components/anim/AnimGroup.vue +67 -67
  23. package/samples/Basic/components/anim/AnimKeyframeBasic.vue +101 -101
  24. package/samples/Basic/components/anim/AnimKeyframeComposite.vue +52 -52
  25. package/samples/Basic/components/anim/AnimTransition.vue +116 -116
  26. package/samples/Basic/components/div/DivBackground.vue +14 -14
  27. package/samples/Basic/components/div/DivClip.vue +80 -80
  28. package/samples/Basic/components/div/DivCssScoped.vue +26 -26
  29. package/samples/Basic/components/div/DivCssVar.vue +49 -49
  30. package/samples/Basic/components/div/DivGroup1.vue +32 -32
  31. package/samples/Basic/components/div/DivGroup2.vue +40 -40
  32. package/samples/Basic/components/div/DivLayout.vue +11 -11
  33. package/samples/Basic/components/div/DivRadius.vue +46 -46
  34. package/samples/Basic/components/text/TextAlign.vue +47 -47
  35. package/samples/Basic/components/text/TextFontStyle.vue +57 -57
  36. package/samples/Basic/components/text/TextGroup.vue +31 -31
  37. package/samples/Basic/components/text/TextOverflow.vue +77 -77
  38. package/samples/BasicFocusControl/App.vue +124 -124
  39. package/samples/BasicFocusControl/components/BaseBlock.vue +50 -50
  40. package/samples/BasicFocusControl/components/MainArea.vue +97 -97
  41. package/samples/BasicFocusControl/components/MainAreaLeftBlock.vue +20 -20
  42. package/samples/BasicFocusControl/components/MainAreaRightBlock.vue +29 -29
  43. package/samples/BasicFocusControl/components/SideBar.vue +72 -72
  44. package/samples/BasicFocusControl/components/SideBarBlock.vue +29 -29
  45. package/samples/ClassNameDemo/App.vue +119 -119
  46. package/samples/ClassNameDemo/components/ContentItem.vue +252 -252
  47. package/samples/ClassNameDemo/components/LoadingView.vue +43 -43
  48. package/samples/ClassNameDemo/components/TitleView.vue +24 -24
  49. package/samples/ClassNameDemo/data.js +24 -24
  50. package/samples/ColorSpace/App.vue +134 -134
  51. package/samples/DemoHomepage/App.vue +31 -31
  52. package/samples/DemoHomepage/components/BodyFrame.vue +81 -81
  53. package/samples/DemoHomepage/components/Dialog.vue +93 -93
  54. package/samples/DemoHomepage/components/Item.vue +76 -76
  55. package/samples/DemoHomepage/components/TabFrame.vue +86 -86
  56. package/samples/DemoHomepage/router.js +132 -132
  57. package/samples/DemoHomepage/views/Homepage.vue +186 -186
  58. package/samples/FlipCard/App.vue +80 -80
  59. package/samples/FlipCard/FlipCard.vue +123 -123
  60. package/samples/FlipCard/data.js +12 -12
  61. package/samples/FlowMultiWidget/App.vue +90 -90
  62. package/samples/FlowMultiWidget/components/Block.vue +106 -106
  63. package/samples/FlowMultiWidget/components/FlowPage.vue +59 -59
  64. package/samples/FlowMultiWidget/components/Item.vue +102 -102
  65. package/samples/FlowMultiWidget/components/MenuItem.vue +71 -71
  66. package/samples/FlowMultiWidget/components/MyMenu.vue +89 -89
  67. package/samples/FlowMultiWidget/data.js +446 -446
  68. package/samples/HashHistory/App.vue +124 -124
  69. package/samples/HashHistory/components/HorizontalButtonList.vue +113 -113
  70. package/samples/HashHistory/components/Item.vue +73 -73
  71. package/samples/HashHistory/router.js +29 -29
  72. package/samples/HashHistory/views/BasePage.vue +18 -18
  73. package/samples/HashHistory/views/MainPage.vue +67 -67
  74. package/samples/HashHistory/views/SubPage.vue +78 -78
  75. package/samples/HashHistory/views/SubPageFirst.vue +9 -9
  76. package/samples/HashHistory/views/SubPageSecond.vue +9 -9
  77. package/samples/LongImage/App.vue +96 -96
  78. package/samples/LongImage/Button.vue +153 -153
  79. package/samples/LongImage/LongImageScroll.vue +126 -126
  80. package/samples/LongImage/Scroll.vue +15 -15
  81. package/samples/LongText/App.vue +111 -111
  82. package/samples/LongText/Button.vue +153 -153
  83. package/samples/LongText/LongTextScroll.vue +224 -224
  84. package/samples/LongText/Scroll.vue +15 -15
  85. package/samples/Preload/App.vue +145 -145
  86. package/samples/Preload/data.js +22 -22
  87. package/samples/Preload/preloadItem.vue +21 -21
  88. package/samples/QrcodeDemo/App.vue +72 -72
  89. package/samples/SimpleWidgetDemo/App.vue +203 -203
  90. package/samples/SimpleWidgetDemo/Item.vue +82 -82
  91. package/samples/SimpleWidgetDemo/components/ContentItem.vue +411 -411
  92. package/samples/SimpleWidgetDemo/components/MyTab.vue +116 -116
  93. package/samples/SimpleWidgetDemo/data.js +110 -110
  94. package/samples/SprayView/App.vue +269 -269
  95. package/samples/SpriteImage/App.vue +174 -174
  96. package/samples/SpriteImage/images/egg_break.json +116 -116
  97. package/samples/TextBox/App.vue +178 -178
  98. package/samples/TextBox/RenderCenter.vue +108 -108
  99. package/samples/TextBox/RenderLeft.vue +108 -108
  100. package/samples/TextBox/RenderOneLine.vue +119 -119
  101. package/samples/TextBox/RenderRight.vue +106 -106
  102. package/samples/TextShadowDemo/App.vue +97 -97
  103. package/samples/TextureSize/App.vue +141 -141
  104. package/samples/ThrowMoveDemo/AccelerateDemo.vue +117 -117
  105. package/samples/ThrowMoveDemo/App.vue +113 -113
  106. package/samples/ThrowMoveDemo/LRParabolicDemo.vue +115 -115
  107. package/samples/ThrowMoveDemo/TargetDemo.vue +116 -116
  108. package/samples/ThrowMoveDemo/UDParabolicDemo.vue +121 -121
  109. package/samples/TransitPage/App.vue +40 -40
  110. package/samples/VideoDemo/App.vue +137 -137
  111. package/samples/VideoDemo/components/Button.vue +68 -68
  112. package/samples/VideoDemo/components/Controllor.vue +195 -195
  113. package/samples/VideoDemo/components/VideoFrame.vue +152 -152
  114. package/scripts/common.js +115 -92
  115. package/scripts/deploy-fast-pack.js +17 -0
  116. package/scripts/deploy-fast-publish.js +44 -0
  117. package/scripts/{git-commit-empty.js → deploy-git-commit-empty.js} +21 -21
  118. package/scripts/{pre-pack.js → deploy-prepare.js} +56 -39
  119. package/scripts/{install-local-packages.js → jsview-install-local-packages.js} +73 -73
  120. package/scripts/{post-build.js → jsview-post-build.js} +127 -127
  121. package/scripts/{post-install.js → jsview-post-install.js} +78 -78
  122. package/scripts/{run-android.js → jsview-run-android.js} +64 -64
  123. package/scripts/make-js.sh +181 -181
  124. package/utils/JsViewEngineWidget/bin/index.js +1 -1
  125. package/utils/JsViewEngineWidget/bin/package.json +11 -11
  126. package/utils/JsViewVueTools/JsvHashHistory.js +111 -111
  127. package/utils/JsViewVueTools/JsvRuntimeBridge.js +417 -417
  128. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserPreload.vue +80 -80
  129. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserQrcode.vue +147 -147
  130. package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserSpray.vue +54 -54
  131. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/ApicDataBase.js +28 -28
  132. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/BrowserApic.vue +123 -123
  133. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/GifData.js +83 -83
  134. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/LoopToolBase.js +25 -25
  135. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/NormalLoopTool.js +61 -61
  136. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/PartLoopTool.js +119 -119
  137. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/Viewer.js +106 -106
  138. package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/WebpData.js +141 -141
  139. package/utils/JsViewVueWidget/BrowserDebugWidget/WidgetLoader.js +20 -20
  140. package/utils/JsViewVueWidget/JsvActorMove/ActorControlBase.js +204 -204
  141. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMove.vue +63 -63
  142. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMoveControl.js +426 -426
  143. package/utils/JsViewVueWidget/JsvActorMove/index.js +12 -12
  144. package/utils/JsViewVueWidget/JsvApic/JsvApic.vue +178 -178
  145. package/utils/JsViewVueWidget/JsvApic/index.js +17 -17
  146. package/utils/JsViewVueWidget/JsvMarquee.vue +196 -196
  147. package/utils/JsViewVueWidget/JsvNinePatch.vue +76 -76
  148. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +350 -350
  149. package/utils/JsViewVueWidget/JsvPreload/index.js +21 -21
  150. package/utils/JsViewVueWidget/JsvQrcode/JsvQrcode.vue +140 -140
  151. package/utils/JsViewVueWidget/JsvQrcode/index.js +18 -18
  152. package/utils/JsViewVueWidget/JsvSpray/JsvSpray.vue +139 -139
  153. package/utils/JsViewVueWidget/JsvSpray/index.js +14 -14
  154. package/utils/JsViewVueWidget/JsvSpriteAnim/JsvSpriteAnim.vue +447 -447
  155. package/utils/JsViewVueWidget/JsvSpriteAnim/SpriteController.js +56 -56
  156. package/utils/JsViewVueWidget/JsvSpriteAnim/index.js +6 -6
  157. package/utils/JsViewVueWidget/JsvSwiper/Indicator.vue +34 -34
  158. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +494 -494
  159. package/utils/JsViewVueWidget/JsvSwiper/index.js +9 -9
  160. package/utils/JsViewVueWidget/JsvSwiper3D/Indicator.vue +34 -34
  161. package/utils/JsViewVueWidget/JsvSwiper3D/JsvSwiper.vue +403 -403
  162. package/utils/JsViewVueWidget/JsvSwiper3D/index.js +9 -9
  163. package/utils/JsViewVueWidget/JsvTextBox.vue +110 -110
  164. package/utils/JsViewVueWidget/JsvVideo.vue +35 -35
  165. package/vetur.config.js +5 -5
  166. package/.gitmodules +0 -6
  167. package/README.md +0 -15
  168. package/doc/IMPORT_CHANGE_LOG.txt +0 -3
  169. package/doc/about-project-postinstall.md +0 -0
  170. package/doc/git_commit.md +0 -15
  171. package/doc/test_version_up.txt +0 -1
  172. package/scripts/update-version.js +0 -32
  173. package/shijiu-jsview-vue-0.9.246.tgz +0 -0
@@ -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>