@puresnake/snake-ui 0.0.0-stage → 0.0.1

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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/changelog.md +1 -0
  3. package/components/snake-activity-list/snake-activity-list.vue +365 -0
  4. package/components/snake-activity-list/types.ts +29 -0
  5. package/components/snake-auxiliary-segmentation/snake-auxiliary-segmentation.vue +44 -0
  6. package/components/snake-auxiliary-segmentation/types.ts +5 -0
  7. package/components/snake-button/snake-button.vue +357 -0
  8. package/components/snake-button/types.ts +103 -0
  9. package/components/snake-button-sort/snake-button-sort.vue +72 -0
  10. package/components/snake-button-sort/types.ts +22 -0
  11. package/components/snake-calendar/snake-calendar.vue +998 -0
  12. package/components/snake-calendar/types.ts +189 -0
  13. package/components/snake-cell-group/snake-cell-group.vue +55 -0
  14. package/components/snake-cell-group/types.ts +19 -0
  15. package/components/snake-cell-item/snake-cell-item.vue +159 -0
  16. package/components/snake-cell-item/types.ts +66 -0
  17. package/components/snake-checkbox/snake-checkbox.vue +264 -0
  18. package/components/snake-checkbox/types.ts +70 -0
  19. package/components/snake-checkbox-group/snake-checkbox-group.vue +154 -0
  20. package/components/snake-checkbox-group/types.ts +52 -0
  21. package/components/snake-cms/blocks/v2/cms-v2-carousel.vue +87 -0
  22. package/components/snake-cms/blocks/v2/cms-v2-coupon.vue +25 -0
  23. package/components/snake-cms/blocks/v2/cms-v2-custom.vue +12 -0
  24. package/components/snake-cms/blocks/v2/cms-v2-divider.vue +33 -0
  25. package/components/snake-cms/blocks/v2/cms-v2-floatbutton.vue +28 -0
  26. package/components/snake-cms/blocks/v2/cms-v2-goods-list.vue +150 -0
  27. package/components/snake-cms/blocks/v2/cms-v2-hotzone.vue +41 -0
  28. package/components/snake-cms/blocks/v2/cms-v2-images.vue +41 -0
  29. package/components/snake-cms/blocks/v2/cms-v2-magiccube.vue +93 -0
  30. package/components/snake-cms/blocks/v2/cms-v2-notice.vue +80 -0
  31. package/components/snake-cms/blocks/v2/cms-v2-popup.vue +46 -0
  32. package/components/snake-cms/blocks/v2/cms-v2-richtext.vue +18 -0
  33. package/components/snake-cms/blocks/v2/cms-v2-search.vue +115 -0
  34. package/components/snake-cms/blocks/v2/cms-v2-video.vue +25 -0
  35. package/components/snake-cms/blocks/v2/shared.ts +84 -0
  36. package/components/snake-cms/snake-cms.vue +409 -0
  37. package/components/snake-cms/types.ts +50 -0
  38. package/components/snake-commodity-search/snake-commodity-search.vue +234 -0
  39. package/components/snake-commodity-search/types.ts +11 -0
  40. package/components/snake-config-provider/snake-config-provider.vue +61 -0
  41. package/components/snake-config-provider/types.ts +22 -0
  42. package/components/snake-count-down/snake-count-down.vue +231 -0
  43. package/components/snake-count-down/types.ts +103 -0
  44. package/components/snake-coupon/snake-coupon.vue +209 -0
  45. package/components/snake-coupon/types.ts +21 -0
  46. package/components/snake-custom-module/snake-custom-module.vue +25 -0
  47. package/components/snake-custom-module/types.ts +11 -0
  48. package/components/snake-drop-menu/snake-drop-menu.vue +123 -0
  49. package/components/snake-drop-menu/types.ts +95 -0
  50. package/components/snake-drop-menu-item/snake-drop-menu-item.vue +181 -0
  51. package/components/snake-drop-menu-item/types.ts +48 -0
  52. package/components/snake-empty/snake-empty.vue +100 -0
  53. package/components/snake-empty/types.ts +48 -0
  54. package/components/snake-filter-sorts/filter-page.vue +695 -0
  55. package/components/snake-filter-sorts/snake-filter-sorts.vue +185 -0
  56. package/components/snake-filter-sorts/types.ts +57 -0
  57. package/components/snake-floating-bubble/snake-floating-bubble.vue +157 -0
  58. package/components/snake-floating-bubble/types.ts +43 -0
  59. package/components/snake-follow/snake-follow.vue +18 -0
  60. package/components/snake-follow/types.ts +2 -0
  61. package/components/snake-form/snake-form.vue +124 -0
  62. package/components/snake-form/types.ts +96 -0
  63. package/components/snake-form-item/snake-form-item.vue +331 -0
  64. package/components/snake-form-item/types.ts +70 -0
  65. package/components/snake-goods-list/snake-goods-list.vue +792 -0
  66. package/components/snake-goods-list/types.ts +55 -0
  67. package/components/snake-graphic-navigation/snake-graphic-navigation.vue +198 -0
  68. package/components/snake-graphic-navigation/types.ts +43 -0
  69. package/components/snake-icon/icon-names.ts +222 -0
  70. package/components/snake-icon/snake-icon.vue +220 -0
  71. package/components/snake-icon/types.ts +45 -0
  72. package/components/snake-image/snake-image.vue +230 -0
  73. package/components/snake-image/types.ts +70 -0
  74. package/components/snake-images/snake-images.vue +80 -0
  75. package/components/snake-images/types.ts +5 -0
  76. package/components/snake-index-anchor/snake-index-anchor.vue +83 -0
  77. package/components/snake-index-anchor/types.ts +14 -0
  78. package/components/snake-index-list/anchor-registry.ts +80 -0
  79. package/components/snake-index-list/snake-index-list.vue +259 -0
  80. package/components/snake-index-list/types.ts +115 -0
  81. package/components/snake-index-list-panel/snake-index-list-panel.vue +277 -0
  82. package/components/snake-index-list-panel/types.ts +10 -0
  83. package/components/snake-input/snake-input.vue +225 -0
  84. package/components/snake-input/types.ts +99 -0
  85. package/components/snake-jump-applet/snake-jump-applet.vue +99 -0
  86. package/components/snake-jump-applet/types.ts +17 -0
  87. package/components/snake-line/snake-line.vue +42 -0
  88. package/components/snake-line/types.ts +30 -0
  89. package/components/snake-line-progress/snake-line-progress.vue +105 -0
  90. package/components/snake-line-progress/types.ts +26 -0
  91. package/components/snake-link/snake-link.vue +74 -0
  92. package/components/snake-link/types.ts +30 -0
  93. package/components/snake-list-switching/components/tree-select/index.vue +156 -0
  94. package/components/snake-list-switching/snake-list-switching.vue +1285 -0
  95. package/components/snake-list-switching/types.ts +11 -0
  96. package/components/snake-loading/snake-loading.vue +241 -0
  97. package/components/snake-loading/types.ts +34 -0
  98. package/components/snake-loadmore/snake-loadmore.vue +103 -0
  99. package/components/snake-loadmore/types.ts +56 -0
  100. package/components/snake-magic-cube/snake-magic-cube.vue +622 -0
  101. package/components/snake-magic-cube/types.ts +5 -0
  102. package/components/snake-modal/snake-modal.vue +434 -0
  103. package/components/snake-modal/types.ts +71 -0
  104. package/components/snake-navbar/snake-navbar.vue +194 -0
  105. package/components/snake-navbar/types.ts +54 -0
  106. package/components/snake-no-network/snake-no-network.vue +125 -0
  107. package/components/snake-no-network/types.ts +27 -0
  108. package/components/snake-notice/snake-notice.vue +44 -0
  109. package/components/snake-notice/types.ts +5 -0
  110. package/components/snake-notice-bar/snake-notice-bar.vue +336 -0
  111. package/components/snake-notice-bar/types.ts +82 -0
  112. package/components/snake-overlay/snake-overlay.vue +73 -0
  113. package/components/snake-overlay/types.ts +35 -0
  114. package/components/snake-page-popup/snake-page-popup.vue +146 -0
  115. package/components/snake-page-popup/types.ts +28 -0
  116. package/components/snake-parse/audio/audio.vue +286 -0
  117. package/components/snake-parse/audio/context.js +11 -0
  118. package/components/snake-parse/audio/index.js +34 -0
  119. package/components/snake-parse/node/node.vue +830 -0
  120. package/components/snake-parse/parser.js +1480 -0
  121. package/components/snake-parse/snake-parse.vue +548 -0
  122. package/components/snake-parse/static/app-plus/snake-parse/js/handler.js +109 -0
  123. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.js +0 -0
  124. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.min.js +1 -0
  125. package/components/snake-parse/static/app-plus/snake-parse/local.html +3 -0
  126. package/components/snake-parse/style/index.js +132 -0
  127. package/components/snake-parse/style/parser.js +175 -0
  128. package/components/snake-parse/types.ts +49 -0
  129. package/components/snake-picture-ads/snake-picture-ads.vue +292 -0
  130. package/components/snake-picture-ads/types.ts +5 -0
  131. package/components/snake-popup/snake-popup.vue +348 -0
  132. package/components/snake-popup/types.ts +88 -0
  133. package/components/snake-qr-code/qrcode.ts +1214 -0
  134. package/components/snake-qr-code/snake-qr-code.vue +408 -0
  135. package/components/snake-qr-code/types.ts +78 -0
  136. package/components/snake-radio/snake-radio.vue +271 -0
  137. package/components/snake-radio/types.ts +64 -0
  138. package/components/snake-radio-group/snake-radio-group.vue +98 -0
  139. package/components/snake-radio-group/types.ts +48 -0
  140. package/components/snake-read-more/snake-read-more.vue +140 -0
  141. package/components/snake-read-more/types.ts +53 -0
  142. package/components/snake-rich-text/snake-rich-text.vue +24 -0
  143. package/components/snake-rich-text/types.ts +5 -0
  144. package/components/snake-root-portal/snake-root-portal.vue +92 -0
  145. package/components/snake-root-portal/types.ts +9 -0
  146. package/components/snake-search/snake-search.vue +202 -0
  147. package/components/snake-search/types.ts +84 -0
  148. package/components/snake-select/snake-select.vue +371 -0
  149. package/components/snake-select/types.ts +75 -0
  150. package/components/snake-skeleton/snake-skeleton.vue +104 -0
  151. package/components/snake-skeleton/types.ts +32 -0
  152. package/components/snake-skeleton-item/snake-skeleton-item.vue +90 -0
  153. package/components/snake-skeleton-item/types.ts +30 -0
  154. package/components/snake-slider/snake-slider.vue +249 -0
  155. package/components/snake-slider/types.ts +59 -0
  156. package/components/snake-sticky/snake-sticky.vue +178 -0
  157. package/components/snake-sticky/types.ts +48 -0
  158. package/components/snake-subsection/snake-subsection.vue +188 -0
  159. package/components/snake-subsection/types.ts +54 -0
  160. package/components/snake-swiper/snake-swiper.vue +229 -0
  161. package/components/snake-swiper/types.ts +79 -0
  162. package/components/snake-switch/snake-switch.vue +100 -0
  163. package/components/snake-switch/types.ts +41 -0
  164. package/components/snake-tabbar/snake-tabbar.vue +306 -0
  165. package/components/snake-tabbar/types.ts +93 -0
  166. package/components/snake-tabs/snake-tabs.vue +305 -0
  167. package/components/snake-tabs/types.ts +79 -0
  168. package/components/snake-text/snake-text.vue +292 -0
  169. package/components/snake-text/types.ts +100 -0
  170. package/components/snake-textarea/snake-textarea.vue +171 -0
  171. package/components/snake-textarea/types.ts +79 -0
  172. package/components/snake-toast/snake-toast.vue +330 -0
  173. package/components/snake-toast/types.ts +55 -0
  174. package/components/snake-tooltip/position.ts +33 -0
  175. package/components/snake-tooltip/snake-tooltip.vue +339 -0
  176. package/components/snake-tooltip/types.ts +80 -0
  177. package/components/snake-transition/snake-transition.vue +315 -0
  178. package/components/snake-transition/types.ts +65 -0
  179. package/components/snake-upload/snake-upload.vue +1801 -0
  180. package/components/snake-upload/types.ts +256 -0
  181. package/components/snake-videos/snake-videos.vue +122 -0
  182. package/components/snake-videos/types.ts +7 -0
  183. package/iconfont.css +881 -0
  184. package/index.d.ts +7 -0
  185. package/index.scss +26 -0
  186. package/index.ts +94 -0
  187. package/libs/cms/blocks.ts +103 -0
  188. package/libs/cms/config.ts +25 -0
  189. package/libs/cms/index.ts +7 -0
  190. package/libs/cms/normalize.ts +135 -0
  191. package/libs/cms/resolve.ts +12 -0
  192. package/libs/cms/types.ts +164 -0
  193. package/libs/cms/use-commerce.ts +385 -0
  194. package/libs/cms/v2.ts +193 -0
  195. package/libs/config/index.ts +4 -0
  196. package/libs/config/modal.ts +93 -0
  197. package/libs/config/state.ts +33 -0
  198. package/libs/config/theme.ts +351 -0
  199. package/libs/config/toast.ts +71 -0
  200. package/libs/config/types.ts +135 -0
  201. package/libs/config/zIndex.ts +44 -0
  202. package/libs/css/color.scss +105 -0
  203. package/libs/css/common.scss +171 -0
  204. package/libs/css/style.h5.scss +7 -0
  205. package/libs/css/style.mp.scss +7 -0
  206. package/libs/css/style.theme.scss +70 -0
  207. package/libs/css/style.vue.scss +140 -0
  208. package/libs/form/async-validator.min.d.ts +75 -0
  209. package/libs/form/async-validator.min.js +3 -0
  210. package/libs/form/index.ts +3 -0
  211. package/libs/form/path.ts +40 -0
  212. package/libs/form/types.ts +51 -0
  213. package/libs/form/validate.ts +149 -0
  214. package/libs/foundation.ts +96 -0
  215. package/libs/function/$parent.ts +33 -0
  216. package/libs/function/clipboard.ts +13 -0
  217. package/libs/function/color.ts +55 -0
  218. package/libs/function/debounce.ts +34 -0
  219. package/libs/function/deepClone.ts +30 -0
  220. package/libs/function/deepMerge.ts +25 -0
  221. package/libs/function/emitter.ts +30 -0
  222. package/libs/function/format.ts +27 -0
  223. package/libs/function/getParent.ts +53 -0
  224. package/libs/function/getRect.ts +29 -0
  225. package/libs/function/guid.ts +11 -0
  226. package/libs/function/index.ts +31 -0
  227. package/libs/function/queryParams.ts +73 -0
  228. package/libs/function/random.ts +6 -0
  229. package/libs/function/randomArray.ts +14 -0
  230. package/libs/function/route.ts +155 -0
  231. package/libs/function/sleep.ts +7 -0
  232. package/libs/function/style.ts +58 -0
  233. package/libs/function/styleUtils.ts +83 -0
  234. package/libs/function/system.ts +14 -0
  235. package/libs/function/test.ts +202 -0
  236. package/libs/function/throttle.ts +36 -0
  237. package/libs/function/timeFormat.ts +27 -0
  238. package/libs/function/timeFrom.ts +27 -0
  239. package/libs/function/toast.ts +10 -0
  240. package/libs/function/trim.ts +11 -0
  241. package/libs/function/type2icon.ts +11 -0
  242. package/libs/function/unit.ts +45 -0
  243. package/libs/hooks/index.ts +11 -0
  244. package/libs/hooks/useChildren.ts +125 -0
  245. package/libs/hooks/useColor.ts +5 -0
  246. package/libs/hooks/useDebounce.ts +5 -0
  247. package/libs/hooks/useLocale.ts +13 -0
  248. package/libs/hooks/useModal.ts +131 -0
  249. package/libs/hooks/useParent.ts +62 -0
  250. package/libs/hooks/useRect.ts +44 -0
  251. package/libs/hooks/useRouter.ts +5 -0
  252. package/libs/hooks/useTheme.ts +31 -0
  253. package/libs/hooks/useThrottle.ts +5 -0
  254. package/libs/hooks/useToast.ts +116 -0
  255. package/libs/index.ts +18 -0
  256. package/libs/request/auto-http.ts +1 -0
  257. package/libs/request/index.ts +343 -0
  258. package/libs/runtime/accessors.ts +55 -0
  259. package/libs/runtime/context.ts +40 -0
  260. package/libs/runtime/index.ts +18 -0
  261. package/libs/runtime/types.ts +49 -0
  262. package/libs/util/calendar.ts +6 -0
  263. package/locale/index.ts +130 -0
  264. package/locale/lang/en-US.ts +67 -0
  265. package/locale/lang/zh-CN.ts +67 -0
  266. package/package.json +130 -5
  267. package/plugins/index.ts +1 -0
  268. package/plugins/root/README.md +86 -0
  269. package/plugins/root/index.ts +123 -0
  270. package/plugins/root/page.ts +77 -0
  271. package/plugins/root/root.ts +53 -0
  272. package/plugins/root/utils.ts +137 -0
  273. package/readme.md +79 -0
  274. package/theme.scss +118 -0
  275. package/types/components.d.ts +236 -0
  276. package/types/global.d.ts +21 -0
  277. package/types/index.d.ts +6 -0
  278. package/types/uni-app.d.ts +16 -0
  279. package/README.md +0 -3
@@ -0,0 +1,548 @@
1
+ <template>
2
+ <view id="_root" :class="(selectable ? '_select ' : '') + '_root'" :style="containerStyle">
3
+ <slot v-if="!nodes[0]" />
4
+ <!-- #ifndef APP-PLUS-NVUE -->
5
+ <node v-else :childs="nodes" :opts="[lazyLoad, loadingImg, errorImg, showImgMenu, selectable]" name="span" />
6
+ <!-- #endif -->
7
+ <!-- #ifdef APP-PLUS-NVUE -->
8
+ <web-view
9
+ ref="web"
10
+ src="/uni_modules/snake-ui/components/snake-parse/static/app-plus/snake-parse/local.html"
11
+ :style="'margin-top:-2px;height:' + height + 'px'"
12
+ @onPostMessage="_onMessage"
13
+ />
14
+ <!-- #endif -->
15
+ </view>
16
+ </template>
17
+
18
+ <script>
19
+ /**
20
+ * mp-html v2.5.2
21
+ * @component SnakeParse
22
+ * @description 富文本组件
23
+ * @see /components/parse
24
+ * @tutorial https://github.com/jin-yufeng/mp-html
25
+ * @property {String} container-style 容器的样式
26
+ * @property {String} content 用于渲染的 html 字符串
27
+ * @property {Boolean} copy-link 是否允许外部链接被点击时自动复制
28
+ * @property {String} domain 主域名,用于拼接链接
29
+ * @property {String} error-img 图片出错时的占位图链接
30
+ * @property {Boolean} lazy-load 是否开启图片懒加载
31
+ * @property {string} loading-img 图片加载过程中的占位图链接
32
+ * @property {Boolean} pause-video 是否在播放一个视频时自动暂停其他视频
33
+ * @property {Boolean} preview-img 是否允许图片被点击时自动预览
34
+ * @property {Boolean} scroll-table 是否给每个表格添加一个滚动层使其能单独横向滚动
35
+ * @property {Boolean | String} selectable 是否开启长按复制
36
+ * @property {Boolean} set-title 是否将 title 标签的内容设置到页面标题
37
+ * @property {Boolean} show-img-menu 是否允许图片被长按时显示菜单
38
+ * @property {Object} tag-style 标签的默认样式
39
+ * @property {Boolean | Number} use-anchor 是否使用锚点链接
40
+ * @event {Function} load dom 结构加载完毕时触发
41
+ * @event {Function} ready 所有图片加载完毕时触发
42
+ * @event {Function} imgtap 图片被点击时触发
43
+ * @event {Function} linktap 链接被点击时触发
44
+ * @event {Function} play 音视频播放时触发
45
+ * @event {Function} error 媒体加载出错时触发
46
+ * @event {Function} pause 音视频暂停时触发
47
+ * @event {Function} fullscreenchange 视频全屏状态变化时触发
48
+ */
49
+ // #ifndef APP-PLUS-NVUE
50
+ import node from './node/node';
51
+ // #endif
52
+ import Parser from './parser';
53
+ import audio from './audio';
54
+ import style from './style';
55
+
56
+ // Kept local so snake-parse has no uView runtime dependency.
57
+ const plugins = [audio, style];
58
+ // #ifdef APP-PLUS-NVUE
59
+ const dom = weex.requireModule('dom');
60
+ // #endif
61
+ export default {
62
+ name: 'SnakeParse',
63
+ provide() {
64
+ return {
65
+ snakeParseRoot: this
66
+ };
67
+ },
68
+ data() {
69
+ return {
70
+ nodes: [],
71
+ // #ifdef APP-PLUS-NVUE
72
+ height: 3
73
+ // #endif
74
+ };
75
+ },
76
+ props: {
77
+ containerStyle: {
78
+ type: String,
79
+ default: ''
80
+ },
81
+ content: {
82
+ type: String,
83
+ default: ''
84
+ },
85
+ copyLink: {
86
+ type: [Boolean, String],
87
+ default: true
88
+ },
89
+ domain: String,
90
+ errorImg: {
91
+ type: String,
92
+ default: ''
93
+ },
94
+ lazyLoad: {
95
+ type: [Boolean, String],
96
+ default: false
97
+ },
98
+ loadingImg: {
99
+ type: String,
100
+ default: ''
101
+ },
102
+ pauseVideo: {
103
+ type: [Boolean, String],
104
+ default: true
105
+ },
106
+ previewImg: {
107
+ type: [Boolean, String],
108
+ default: true
109
+ },
110
+ scrollTable: [Boolean, String],
111
+ selectable: [Boolean, String],
112
+ setTitle: {
113
+ type: [Boolean, String],
114
+ default: true
115
+ },
116
+ showImgMenu: {
117
+ type: [Boolean, String],
118
+ default: true
119
+ },
120
+ tagStyle: Object,
121
+ useAnchor: [Boolean, Number]
122
+ },
123
+ // #ifdef VUE3
124
+ emits: ['load', 'ready', 'imgtap', 'linktap', 'play', 'error'],
125
+ // #endif
126
+ // #ifndef APP-PLUS-NVUE
127
+ components: {
128
+ node
129
+ },
130
+ // #endif
131
+ watch: {
132
+ content(content) {
133
+ this.setContent(content);
134
+ }
135
+ },
136
+ created() {
137
+ this.plugins = [];
138
+ for (let i = plugins.length; i--;) {
139
+ this.plugins.push(new plugins[i](this));
140
+ }
141
+ },
142
+ mounted() {
143
+ if (this.content && !this.nodes.length) {
144
+ this.setContent(this.content);
145
+ }
146
+ },
147
+ beforeDestroy() {
148
+ this._hook('onDetached');
149
+ },
150
+ methods: {
151
+ /**
152
+ * @description 将锚点跳转的范围限定在一个 scroll-view 内
153
+ * @param {Object} page scroll-view 所在页面的示例
154
+ * @param {String} selector scroll-view 的选择器
155
+ * @param {String} scrollTop scroll-view scroll-top 属性绑定的变量名
156
+ */
157
+ in(page, selector, scrollTop) {
158
+ // #ifndef APP-PLUS-NVUE
159
+ if (page && selector && scrollTop) {
160
+ this._in = {
161
+ page,
162
+ selector,
163
+ scrollTop
164
+ };
165
+ }
166
+ // #endif
167
+ },
168
+
169
+ /**
170
+ * @description 锚点跳转
171
+ * @param {String} id 要跳转的锚点 id
172
+ * @param {Number} offset 跳转位置的偏移量
173
+ * @returns {Promise}
174
+ */
175
+ navigateTo(id, offset) {
176
+ return new Promise((resolve, reject) => {
177
+ if (!this.useAnchor) {
178
+ reject(Error('Anchor is disabled'));
179
+ return;
180
+ }
181
+ offset = offset || parseInt(this.useAnchor) || 0;
182
+ // #ifdef APP-PLUS-NVUE
183
+ if (!id) {
184
+ dom.scrollToElement(this.$refs.web, {
185
+ offset
186
+ });
187
+ resolve();
188
+ } else {
189
+ this._navigateTo = {
190
+ resolve,
191
+ reject,
192
+ offset
193
+ };
194
+ this.$refs.web.evalJs(
195
+ 'uni.postMessage({data:{action:"getOffset",offset:(document.getElementById(' +
196
+ id +
197
+ ')||{}).offsetTop}})'
198
+ );
199
+ }
200
+ // #endif
201
+ // #ifndef APP-PLUS-NVUE
202
+ let deep = ' ';
203
+ // #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO
204
+ deep = '>>>';
205
+ // #endif
206
+ const selector = uni
207
+ .createSelectorQuery()
208
+ // #ifndef MP-ALIPAY
209
+ .in(this._in ? this._in.page : this)
210
+ // #endif
211
+ .select((this._in ? this._in.selector : '._root') + (id ? `${deep}#${id}` : ''))
212
+ .boundingClientRect();
213
+ if (this._in) {
214
+ selector.select(this._in.selector).scrollOffset().select(this._in.selector).boundingClientRect();
215
+ } else {
216
+ // 获取 scroll-view 的位置和滚动距离
217
+ selector.selectViewport().scrollOffset(); // 获取窗口的滚动距离
218
+ }
219
+ selector.exec(res => {
220
+ if (!res[0]) {
221
+ reject(Error('Label not found'));
222
+ return;
223
+ }
224
+ const scrollTop = res[1].scrollTop + res[0].top - (res[2] ? res[2].top : 0) + offset;
225
+ if (this._in) {
226
+ // scroll-view 跳转
227
+ this._in.page[this._in.scrollTop] = scrollTop;
228
+ } else {
229
+ // 页面跳转
230
+ uni.pageScrollTo({
231
+ scrollTop,
232
+ duration: 300
233
+ });
234
+ }
235
+ resolve();
236
+ });
237
+ // #endif
238
+ });
239
+ },
240
+
241
+ /**
242
+ * @description 获取文本内容
243
+ * @return {String}
244
+ */
245
+ getText(nodes) {
246
+ let text = '';
247
+ (function traversal(nodes) {
248
+ for (let i = 0; i < nodes.length; i++) {
249
+ const node = nodes[i];
250
+ if (node.type === 'text') {
251
+ text += node.text.replace(/&amp;/g, '&');
252
+ } else if (node.name === 'br') {
253
+ text += '\n';
254
+ } else {
255
+ // 块级标签前后加换行
256
+ const isBlock =
257
+ node.name === 'p' ||
258
+ node.name === 'div' ||
259
+ node.name === 'tr' ||
260
+ node.name === 'li' ||
261
+ (node.name[0] === 'h' && node.name[1] > '0' && node.name[1] < '7');
262
+ if (isBlock && text && text[text.length - 1] !== '\n') {
263
+ text += '\n';
264
+ }
265
+ // 递归获取子节点的文本
266
+ if (node.children) {
267
+ traversal(node.children);
268
+ }
269
+ if (isBlock && text[text.length - 1] !== '\n') {
270
+ text += '\n';
271
+ } else if (node.name === 'td' || node.name === 'th') {
272
+ text += '\t';
273
+ }
274
+ }
275
+ }
276
+ })(nodes || this.nodes);
277
+ return text;
278
+ },
279
+
280
+ /**
281
+ * @description 获取内容大小和位置
282
+ * @return {Promise}
283
+ */
284
+ getRect() {
285
+ return new Promise((resolve, reject) => {
286
+ uni.createSelectorQuery()
287
+ // #ifndef MP-ALIPAY
288
+ .in(this)
289
+ // #endif
290
+ .select('#_root')
291
+ .boundingClientRect()
292
+ .exec(res => (res[0] ? resolve(res[0]) : reject(Error('Root label not found'))));
293
+ });
294
+ },
295
+
296
+ /**
297
+ * @description 暂停播放媒体
298
+ */
299
+ pauseMedia() {
300
+ for (let i = (this._videos || []).length; i--;) {
301
+ this._videos[i].pause();
302
+ }
303
+ // #ifdef APP-PLUS
304
+ const command = 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].pause()';
305
+ // #ifndef APP-PLUS-NVUE
306
+ let page = this.$parent;
307
+ while (!page.$scope) page = page.$parent;
308
+ page.$scope.$getAppWebview().evalJS(command);
309
+ // #endif
310
+ // #ifdef APP-PLUS-NVUE
311
+ this.$refs.web.evalJs(command);
312
+ // #endif
313
+ // #endif
314
+ },
315
+
316
+ /**
317
+ * @description 设置媒体播放速率
318
+ * @param {Number} rate 播放速率
319
+ */
320
+ setPlaybackRate(rate) {
321
+ this.playbackRate = rate;
322
+ for (let i = (this._videos || []).length; i--;) {
323
+ this._videos[i].playbackRate(rate);
324
+ }
325
+ // #ifdef APP-PLUS
326
+ const command =
327
+ 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].playbackRate=' + rate;
328
+ // #ifndef APP-PLUS-NVUE
329
+ let page = this.$parent;
330
+ while (!page.$scope) page = page.$parent;
331
+ page.$scope.$getAppWebview().evalJS(command);
332
+ // #endif
333
+ // #ifdef APP-PLUS-NVUE
334
+ this.$refs.web.evalJs(command);
335
+ // #endif
336
+ // #endif
337
+ },
338
+
339
+ /**
340
+ * @description 设置内容
341
+ * @param {String} content html 内容
342
+ * @param {Boolean} append 是否在尾部追加
343
+ */
344
+ setContent(content, append) {
345
+ if (!append || !this.imgList) {
346
+ this.imgList = [];
347
+ }
348
+ const nodes = new Parser(this).parse(content);
349
+ // #ifdef APP-PLUS-NVUE
350
+ if (this._ready) {
351
+ this._set(nodes, append);
352
+ }
353
+ // #endif
354
+ this.nodes = append ? (this.nodes || []).concat(nodes) : nodes;
355
+
356
+ // #ifndef APP-PLUS-NVUE
357
+ this._videos = [];
358
+ this.$nextTick(() => {
359
+ this._hook('onLoad');
360
+ this.$emit('load');
361
+ });
362
+
363
+ if (this.lazyLoad || this.imgList._unloadimgs < this.imgList.length / 2) {
364
+ // 设置懒加载,每 350ms 获取高度,不变则认为加载完毕
365
+ let height = 0;
366
+ const callback = rect => {
367
+ if (!rect || !rect.height) rect = {};
368
+ // 350ms 总高度无变化就触发 ready 事件
369
+ if (rect.height === height) {
370
+ this.$emit('ready', rect);
371
+ } else {
372
+ height = rect.height;
373
+ setTimeout(() => {
374
+ this.getRect().then(callback).catch(callback);
375
+ }, 350);
376
+ }
377
+ };
378
+ this.getRect().then(callback).catch(callback);
379
+ } else {
380
+ // 未设置懒加载,等待所有图片加载完毕
381
+ if (!this.imgList._unloadimgs) {
382
+ this.getRect()
383
+ .then(rect => {
384
+ this.$emit('ready', rect);
385
+ })
386
+ .catch(() => {
387
+ this.$emit('ready', {});
388
+ });
389
+ }
390
+ }
391
+ // #endif
392
+ },
393
+
394
+ /**
395
+ * @description 调用插件钩子函数
396
+ */
397
+ _hook(name) {
398
+ for (let i = plugins.length; i--;) {
399
+ if (this.plugins[i][name]) {
400
+ this.plugins[i][name]();
401
+ }
402
+ }
403
+ },
404
+
405
+ // #ifdef APP-PLUS-NVUE
406
+ /**
407
+ * @description 设置内容
408
+ */
409
+ _set(nodes, append) {
410
+ this.$refs.web.evalJs(
411
+ 'setContent(' +
412
+ JSON.stringify(nodes).replace(/%22/g, '') +
413
+ ',' +
414
+ JSON.stringify([
415
+ this.containerStyle.replace(/(?:margin|padding)[^;]+/g, ''),
416
+ this.errorImg,
417
+ this.loadingImg,
418
+ this.pauseVideo,
419
+ this.scrollTable,
420
+ this.selectable
421
+ ]) +
422
+ ',' +
423
+ append +
424
+ ')'
425
+ );
426
+ },
427
+
428
+ /**
429
+ * @description 接收到 web-view 消息
430
+ */
431
+ _onMessage(e) {
432
+ const message = e.detail.data[0];
433
+ switch (message.action) {
434
+ // web-view 初始化完毕
435
+ case 'onJSBridgeReady':
436
+ this._ready = true;
437
+ if (this.nodes) {
438
+ this._set(this.nodes);
439
+ }
440
+ break;
441
+ // 内容 dom 加载完毕
442
+ case 'onLoad':
443
+ this.height = message.height;
444
+ this._hook('onLoad');
445
+ this.$emit('load');
446
+ break;
447
+ // 所有图片加载完毕
448
+ case 'onReady':
449
+ this.getRect()
450
+ .then(res => {
451
+ this.$emit('ready', res);
452
+ })
453
+ .catch(() => {
454
+ this.$emit('ready', {});
455
+ });
456
+ break;
457
+ // 总高度发生变化
458
+ case 'onHeightChange':
459
+ this.height = message.height;
460
+ break;
461
+ // 图片点击
462
+ case 'onImgTap':
463
+ this.$emit('imgtap', message.attrs);
464
+ if (this.previewImg) {
465
+ uni.previewImage({
466
+ current: parseInt(message.attrs.i),
467
+ urls: this.imgList
468
+ });
469
+ }
470
+ break;
471
+ // 链接点击
472
+ case 'onLinkTap': {
473
+ const href = message.attrs.href;
474
+ this.$emit('linktap', message.attrs);
475
+ if (href) {
476
+ // 锚点跳转
477
+ if (href[0] === '#') {
478
+ if (this.useAnchor) {
479
+ dom.scrollToElement(this.$refs.web, {
480
+ offset: message.offset
481
+ });
482
+ }
483
+ } else if (href.includes('://')) {
484
+ // 打开外链
485
+ if (this.copyLink) {
486
+ plus.runtime.openWeb(href);
487
+ }
488
+ } else {
489
+ uni.navigateTo({
490
+ url: href,
491
+ fail() {
492
+ uni.switchTab({
493
+ url: href
494
+ });
495
+ }
496
+ });
497
+ }
498
+ }
499
+ break;
500
+ }
501
+ case 'onPlay':
502
+ this.$emit('play');
503
+ break;
504
+ // 获取到锚点的偏移量
505
+ case 'getOffset':
506
+ if (typeof message.offset === 'number') {
507
+ dom.scrollToElement(this.$refs.web, {
508
+ offset: message.offset + this._navigateTo.offset
509
+ });
510
+ this._navigateTo.resolve();
511
+ } else {
512
+ this._navigateTo.reject(Error('Label not found'));
513
+ }
514
+ break;
515
+ // 点击
516
+ case 'onClick':
517
+ this.$emit('tap');
518
+ this.$emit('click');
519
+ break;
520
+ // 出错
521
+ case 'onError':
522
+ this.$emit('error', {
523
+ source: message.source,
524
+ attrs: message.attrs
525
+ });
526
+ }
527
+ }
528
+ // #endif
529
+ }
530
+ };
531
+ </script>
532
+
533
+ <style>
534
+ /* #ifndef APP-PLUS-NVUE */
535
+ /* 根节点样式 */
536
+ ._root {
537
+ padding: 1px 0;
538
+ overflow-x: auto;
539
+ overflow-y: hidden;
540
+ -webkit-overflow-scrolling: touch;
541
+ }
542
+
543
+ /* 长按复制 */
544
+ ._select {
545
+ user-select: text;
546
+ }
547
+ /* #endif */
548
+ </style>
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+ function t(t) {
3
+ for (var e = Object.create(null), n = t.attributes.length; n--;) e[t.attributes[n].name] = t.attributes[n].value;
4
+ return e;
5
+ }
6
+ function e() {
7
+ (a[1] && ((this.src = a[1]), (this.onerror = null)),
8
+ (this.onclick = null),
9
+ (this.ontouchstart = null),
10
+ uni.postMessage({ data: { action: 'onError', source: 'img', attrs: t(this) } }));
11
+ }
12
+ function n() {
13
+ ((window.unloadimgs -= 1), 0 === window.unloadimgs && uni.postMessage({ data: { action: 'onReady' } }));
14
+ }
15
+ function o(r, s, c) {
16
+ for (var d = 0; d < r.length; d++)
17
+ !(function () {
18
+ var u,
19
+ l = r[d];
20
+ if (l.type && 'node' !== l.type) u = document.createTextNode(l.text.replace(/&amp;/g, '&'));
21
+ else {
22
+ var g = l.name;
23
+ ('svg' === g && (c = 'http://www.w3.org/2000/svg'),
24
+ ('html' !== g && 'body' !== g) || (g = 'div'),
25
+ (u = c ? document.createElementNS(c, g) : document.createElement(g)));
26
+ for (var p in l.attrs) u.setAttribute(p, l.attrs[p]);
27
+ if ((l.children && o(l.children, u, c), 'img' === g)) {
28
+ if (
29
+ ((window.unloadimgs += 1),
30
+ (u.onload = n),
31
+ (u.onerror = n),
32
+ !u.src && u.getAttribute('data-src') && (u.src = u.getAttribute('data-src')),
33
+ l.attrs.ignore ||
34
+ (u.onclick = function (e) {
35
+ (e.stopPropagation(),
36
+ uni.postMessage({ data: { action: 'onImgTap', attrs: t(this) } }));
37
+ }),
38
+ a[2])
39
+ ) {
40
+ var h = new Image();
41
+ ((h.src = u.src),
42
+ (u.src = a[2]),
43
+ (h.onload = function () {
44
+ u.src = this.src;
45
+ }),
46
+ (h.onerror = function () {
47
+ u.onerror();
48
+ }));
49
+ }
50
+ u.onerror = e;
51
+ } else if ('a' === g)
52
+ u.addEventListener(
53
+ 'click',
54
+ function (e) {
55
+ (e.stopPropagation(), e.preventDefault());
56
+ var n,
57
+ o = this.getAttribute('href');
58
+ (o && '#' === o[0] && (n = (document.getElementById(o.substr(1)) || {}).offsetTop),
59
+ uni.postMessage({ data: { action: 'onLinkTap', attrs: t(this), offset: n } }));
60
+ },
61
+ !0
62
+ );
63
+ else if ('video' === g || 'audio' === g)
64
+ (i.push(u),
65
+ l.attrs.autoplay || l.attrs.controls || u.setAttribute('controls', 'true'),
66
+ (u.onplay = function () {
67
+ if ((uni.postMessage({ data: { action: 'onPlay' } }), a[3]))
68
+ for (var t = 0; t < i.length; t++) i[t] !== this && i[t].pause();
69
+ }),
70
+ (u.onerror = function () {
71
+ uni.postMessage({ data: { action: 'onError', source: g, attrs: t(this) } });
72
+ }));
73
+ else if ('table' === g && a[4] && !u.style.cssText.includes('inline')) {
74
+ var f = document.createElement('div');
75
+ ((f.style.overflow = 'auto'), f.appendChild(u), (u = f));
76
+ } else 'svg' === g && (c = void 0);
77
+ }
78
+ s.appendChild(u);
79
+ })();
80
+ }
81
+ document.addEventListener('UniAppJSBridgeReady', function () {
82
+ ((document.body.onclick = function () {
83
+ return uni.postMessage({ data: { action: 'onClick' } });
84
+ }),
85
+ uni.postMessage({ data: { action: 'onJSBridgeReady' } }));
86
+ });
87
+ var a,
88
+ i = [];
89
+ ((window.setContent = function (t, e, n) {
90
+ var r = document.getElementById('content');
91
+ (e[0] && (document.body.style.cssText = e[0]),
92
+ e[5] || (r.style.userSelect = 'none'),
93
+ n || ((r.innerHTML = ''), (i = [])),
94
+ (a = e),
95
+ (window.unloadimgs = 0));
96
+ var s = document.createDocumentFragment();
97
+ (o(t, s), r.appendChild(s));
98
+ var c = r.scrollHeight;
99
+ (uni.postMessage({ data: { action: 'onLoad', height: c } }),
100
+ window.unloadimgs || uni.postMessage({ data: { action: 'onReady', height: c } }),
101
+ clearInterval(window.timer),
102
+ (window.timer = setInterval(function () {
103
+ r.scrollHeight !== c &&
104
+ ((c = r.scrollHeight), uni.postMessage({ data: { action: 'onHeightChange', height: c } }));
105
+ }, 350)));
106
+ }),
107
+ (window.onunload = function () {
108
+ clearInterval(window.timer);
109
+ }));
@@ -0,0 +1,3 @@
1
+ <head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"><style>body,html{width:100%;height:100%;overflow-x:scroll;overflow-y:hidden}body{margin:0}video{width:300px;height:225px}img{max-width:100%;-webkit-touch-callout:none}</style></head><body><div id="content" style="overflow:hidden"></div><script type="text/javascript" src="./js/uni.webview.min.js"></script><script type="text/javascript" src="./js/handler.js"></script></body>
2
+
3
+