@didaoktv/didaoui-uniapp 2.13.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/components/dd-album/dd-album.vue +280 -228
- package/components/dd-avatar/dd-avatar.vue +132 -75
- package/components/dd-avatar-group/dd-avatar-group.vue +52 -30
- package/components/dd-barcode/dd-barcode.vue +884 -947
- package/components/dd-button/dd-button.vue +47 -21
- package/components/dd-canvas/dd-canvas.vue +1156 -985
- package/components/dd-car-keyboard/dd-car-keyboard.vue +12 -12
- package/components/dd-champion-card/dd-champion-card.vue +49 -21
- package/components/dd-checkbox-group/dd-checkbox-group.vue +2 -0
- package/components/dd-copy/dd-copy.vue +51 -56
- package/components/dd-cropper/dd-cropper.vue +1224 -1135
- package/components/dd-divider/dd-divider.vue +9 -2
- package/components/dd-form/dd-form.vue +2 -0
- package/components/dd-goods-sku/dd-goods-sku.vue +6 -1
- package/components/dd-icon/dd-icon.vue +1 -1
- package/components/dd-keyboard/dd-keyboard.vue +95 -46
- package/components/dd-link/dd-link.vue +72 -49
- package/components/dd-markdown/dd-markdown.vue +154 -154
- package/components/dd-number-keyboard/dd-number-keyboard.vue +109 -94
- package/components/dd-package-sku/dd-package-sku.vue +24 -1
- package/components/dd-parse/dd-parse.vue +473 -442
- package/components/dd-poster/dd-poster.vue +579 -567
- package/components/dd-pull-refresh/dd-pull-refresh.vue +1 -9
- package/components/dd-qrcode/dd-qrcode.vue +431 -405
- package/components/dd-radio-group/dd-radio-group.vue +1 -1
- package/components/dd-segmented-tab/dd-segmented-tab.vue +61 -16
- package/components/dd-signature/dd-signature.vue +377 -357
- package/components/dd-step/dd-step.vue +1 -1
- package/components/dd-sticky/dd-sticky.vue +5 -10
- package/components/dd-swipe-action/dd-swipe-action.vue +1 -9
- package/components/dd-swipe-item/dd-swipe-item.vue +2 -0
- package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -5
- package/components/dd-switch/dd-switch.vue +1 -1
- package/components/dd-text/dd-text.vue +304 -82
- package/components/dd-waterfall/dd-waterfall.vue +147 -0
- package/components/dd-waterfall/waterfall.ts +17 -0
- package/index.ts +4 -3
- package/libs/function/index.d.ts +88 -0
- package/libs/function/index.js +14 -0
- package/libs/function/test.d.ts +65 -0
- package/package.json +1 -1
- package/scss/_mixins.scss +8 -0
- package/scss/_theme-tokens.scss +7 -0
- package/scss/_variables.scss +283 -156
- package/components/dd-album/album.js +0 -19
- package/components/dd-album/props.js +0 -89
- package/components/dd-avatar/avatar.js +0 -19
- package/components/dd-avatar/props.js +0 -84
- package/components/dd-avatar-group/avatarGroup.js +0 -14
- package/components/dd-avatar-group/props.js +0 -57
- package/components/dd-keyboard/keyboard.js +0 -19
- package/components/dd-keyboard/props.js +0 -79
- package/components/dd-link/link.js +0 -17
- package/components/dd-link/props.js +0 -44
- package/components/dd-number-keyboard/numberKeyboard.js +0 -8
- package/components/dd-number-keyboard/props.js +0 -24
- package/components/dd-parse/props.js +0 -57
- package/components/dd-text/props.js +0 -120
- package/components/dd-text/text.js +0 -30
- package/components/dd-text/value.js +0 -87
- package/libs/config/color.js +0 -16
- package/libs/config/props.js +0 -184
- package/libs/mixin/button.js +0 -18
- package/libs/mixin/mixin.js +0 -44
- package/libs/mixin/mpMixin.js +0 -13
- package/libs/mixin/openType.js +0 -27
- package/libs/vue.js +0 -3
- package/scss/_dd-shared.scss +0 -40
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view id="
|
|
2
|
+
<view id="dd-parse-root" :class="'dd-parse__root' + (selectable ? ' dd-parse--select' : '')" :style="containerStyle">
|
|
3
3
|
<slot v-if="!nodes[0]" />
|
|
4
4
|
<!-- #ifndef APP-PLUS-NVUE -->
|
|
5
5
|
<node v-else :childs="nodes" :opts="[lazyLoad, loadingImg, errorImg, showImgMenu, selectable]" name="span" />
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</view>
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
|
-
<script>
|
|
13
|
+
<script setup lang="ts">
|
|
14
14
|
/**
|
|
15
15
|
* mp-html v2.5.1
|
|
16
16
|
* @description 富文本组件
|
|
@@ -38,487 +38,518 @@
|
|
|
38
38
|
* @event {Function} error 媒体加载出错时触发
|
|
39
39
|
*/
|
|
40
40
|
// #ifndef APP-PLUS-NVUE
|
|
41
|
+
// @ts-ignore node 以无扩展名方式导入 .vue 文件,vue-tsc 无法解析
|
|
41
42
|
import node from './node/node'
|
|
42
43
|
// #endif
|
|
44
|
+
// @ts-ignore parser.js 为 JS 实现且无类型声明,导入方式与原 Options API 一致
|
|
43
45
|
import Parser from './parser'
|
|
44
|
-
|
|
46
|
+
import { getCurrentInstance, nextTick, onMounted, onUnmounted, ref, shallowRef, toRefs, watch } from 'vue'
|
|
47
|
+
|
|
48
|
+
// 插件注册表(与实例 plugins 同为空数组,原实现两处均未被填充)
|
|
49
|
+
const plugins: any[] = []
|
|
45
50
|
// #ifdef APP-PLUS-NVUE
|
|
51
|
+
// @ts-ignore weex 为 nvue 运行时全局对象,@dcloudio/types 未声明
|
|
46
52
|
const dom = weex.requireModule('dom')
|
|
47
53
|
// #endif
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
54
|
+
|
|
55
|
+
// node 子组件依赖 $parent.$options.name === 'dd-parse' 定位根实例
|
|
56
|
+
defineOptions({ name: 'dd-parse' })
|
|
57
|
+
|
|
58
|
+
interface Props {
|
|
59
|
+
containerStyle?: string
|
|
60
|
+
content?: string
|
|
61
|
+
copyLink?: boolean | string
|
|
62
|
+
domain?: string
|
|
63
|
+
errorImg?: string
|
|
64
|
+
lazyLoad?: boolean | string
|
|
65
|
+
loadingImg?: string
|
|
66
|
+
pauseVideo?: boolean | string
|
|
67
|
+
previewImg?: boolean | string
|
|
68
|
+
scrollTable?: boolean | string
|
|
69
|
+
selectable?: boolean | string
|
|
70
|
+
setTitle?: boolean | string
|
|
71
|
+
showImgMenu?: boolean | string
|
|
72
|
+
tagStyle?: Record<string, any>
|
|
73
|
+
useAnchor?: boolean | number
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
77
|
+
containerStyle: '',
|
|
78
|
+
content: '',
|
|
79
|
+
copyLink: true,
|
|
80
|
+
errorImg: '',
|
|
81
|
+
lazyLoad: false,
|
|
82
|
+
loadingImg: '',
|
|
83
|
+
pauseVideo: true,
|
|
84
|
+
previewImg: true,
|
|
85
|
+
setTitle: true,
|
|
86
|
+
showImgMenu: true,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const emit = defineEmits<{
|
|
90
|
+
(e: 'load'): void
|
|
91
|
+
(e: 'ready', rect: any): void
|
|
92
|
+
(e: 'imgtap', attrs: any): void
|
|
93
|
+
(e: 'linktap', attrs: any): void
|
|
94
|
+
(e: 'play', info?: any): void
|
|
95
|
+
(e: 'error', err: any): void
|
|
96
|
+
}>()
|
|
97
|
+
|
|
98
|
+
const instance = getCurrentInstance()!
|
|
99
|
+
// Parser 与 node 子组件都以组件实例作为上下文读写这些状态
|
|
100
|
+
const vm = instance.proxy as any
|
|
101
|
+
|
|
102
|
+
const nodes = ref<any[]>([])
|
|
103
|
+
// #ifdef APP-PLUS-NVUE
|
|
104
|
+
const height = ref(3)
|
|
105
|
+
// #endif
|
|
106
|
+
const web = ref<any>(null)
|
|
107
|
+
// imgList/_videos 原实现是非响应式的实例属性(不参与渲染),用 shallowRef 保持原始数组
|
|
108
|
+
const imgList = shallowRef<any>([])
|
|
109
|
+
// node 子组件通过 $parent 读写
|
|
110
|
+
const _videos = shallowRef<any[]>([])
|
|
111
|
+
const playbackRate = ref<number | undefined>()
|
|
112
|
+
let _in: any = null
|
|
113
|
+
let _navigateTo: any = null
|
|
114
|
+
let _ready = false
|
|
115
|
+
|
|
116
|
+
// Parser 还会读写 imgList/plugins/nodes;script setup 的绑定不会出现在实例代理上,
|
|
117
|
+
// 这里以实例代理为底补上这三个键(props 仍走代理,与原 Options API 行为一致)
|
|
118
|
+
const parserCtx: any = new Proxy(vm, {
|
|
119
|
+
get(target, key) {
|
|
120
|
+
if (key === 'imgList') return imgList.value
|
|
121
|
+
if (key === 'plugins') return plugins
|
|
122
|
+
if (key === 'nodes') return nodes.value
|
|
123
|
+
return target[key]
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
watch(
|
|
128
|
+
() => props.content,
|
|
129
|
+
(content) => {
|
|
130
|
+
setContent(content)
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
onMounted(() => {
|
|
135
|
+
if (props.content && !nodes.value.length) {
|
|
136
|
+
setContent(props.content)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
onUnmounted(() => {
|
|
141
|
+
_hook('onDetached')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @description 规范化链接地址
|
|
146
|
+
* @param {any} href
|
|
147
|
+
* @return {String}
|
|
148
|
+
*/
|
|
149
|
+
function normalizeHref(href: any) {
|
|
150
|
+
return typeof href === 'string' ? href.trim() : ''
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @description 判断是否为外部链接
|
|
155
|
+
* @param {String} href
|
|
156
|
+
* @return {Boolean}
|
|
157
|
+
*/
|
|
158
|
+
function isExternalLink(href: string) {
|
|
159
|
+
return href.split('?')[0].includes('://')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @description 打开外部链接
|
|
164
|
+
* @param {String} href
|
|
165
|
+
*/
|
|
166
|
+
function openExternalLink(href: string) {
|
|
167
|
+
// #ifdef APP-PLUS
|
|
168
|
+
try {
|
|
169
|
+
plus.runtime.openWeb(href)
|
|
170
|
+
} catch (e) { }
|
|
107
171
|
// #endif
|
|
108
|
-
// #
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
172
|
+
// #ifdef APP-HARMONY
|
|
173
|
+
try {
|
|
174
|
+
plus.runtime.openURL(href)
|
|
175
|
+
} catch (e) { }
|
|
112
176
|
// #endif
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @description 将锚点跳转的范围限定在一个 scroll-view 内
|
|
181
|
+
* @param {Object} page scroll-view 所在页面的示例
|
|
182
|
+
* @param {String} selector scroll-view 的选择器
|
|
183
|
+
* @param {String} scrollTop scroll-view scroll-top 属性绑定的变量名
|
|
184
|
+
*/
|
|
185
|
+
function anchorIn(page: any, selector: any, scrollTop: any) {
|
|
186
|
+
// #ifndef APP-PLUS-NVUE
|
|
187
|
+
if (page && selector && scrollTop) {
|
|
188
|
+
_in = {
|
|
189
|
+
page,
|
|
190
|
+
selector,
|
|
191
|
+
scrollTop
|
|
116
192
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
193
|
+
}
|
|
194
|
+
// #endif
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @description 锚点跳转
|
|
199
|
+
* @param {String} id 要跳转的锚点 id
|
|
200
|
+
* @param {Number} offset 跳转位置的偏移量
|
|
201
|
+
* @returns {Promise}
|
|
202
|
+
*/
|
|
203
|
+
function navigateTo(id?: string, offset?: number) {
|
|
204
|
+
return new Promise<void>((resolve, reject) => {
|
|
205
|
+
if (!props.useAnchor) {
|
|
206
|
+
reject(Error('Anchor is disabled'))
|
|
207
|
+
return
|
|
122
208
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
|
|
209
|
+
offset = offset || parseInt(props.useAnchor as any) || 0
|
|
210
|
+
// #ifdef APP-PLUS-NVUE
|
|
211
|
+
if (!id) {
|
|
212
|
+
dom.scrollToElement(web.value, {
|
|
213
|
+
offset
|
|
214
|
+
})
|
|
215
|
+
resolve()
|
|
216
|
+
} else {
|
|
217
|
+
_navigateTo = {
|
|
218
|
+
resolve,
|
|
219
|
+
reject,
|
|
220
|
+
offset
|
|
221
|
+
}
|
|
222
|
+
web.value.evalJs('uni.postMessage({data:{action:"getOffset",offset:(document.getElementById(' + id + ')||{}).offsetTop}})')
|
|
127
223
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*/
|
|
138
|
-
normalizeHref(href) {
|
|
139
|
-
return typeof href === 'string' ? href.trim() : ''
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @description 判断是否为外部链接
|
|
144
|
-
* @param {String} href
|
|
145
|
-
* @return {Boolean}
|
|
146
|
-
*/
|
|
147
|
-
isExternalLink(href) {
|
|
148
|
-
return href.split('?')[0].includes('://')
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @description 打开外部链接
|
|
153
|
-
* @param {String} href
|
|
154
|
-
*/
|
|
155
|
-
openExternalLink(href) {
|
|
156
|
-
// #ifdef APP-PLUS
|
|
157
|
-
try {
|
|
158
|
-
plus.runtime.openWeb(href)
|
|
159
|
-
} catch (e) { }
|
|
160
|
-
// #endif
|
|
161
|
-
// #ifdef APP-HARMONY
|
|
162
|
-
try {
|
|
163
|
-
plus.runtime.openURL(href)
|
|
164
|
-
} catch (e) { }
|
|
224
|
+
// #endif
|
|
225
|
+
// #ifndef APP-PLUS-NVUE
|
|
226
|
+
let deep = ' '
|
|
227
|
+
// #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO
|
|
228
|
+
deep = '>>>'
|
|
229
|
+
// #endif
|
|
230
|
+
const selector = uni.createSelectorQuery()
|
|
231
|
+
// #ifndef MP-ALIPAY
|
|
232
|
+
.in(_in ? _in.page : vm)
|
|
165
233
|
// #endif
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
scrollTop
|
|
181
|
-
}
|
|
234
|
+
.select((_in ? _in.selector : '.dd-parse__root') + (id ? `${deep}#${id}` : '')).boundingClientRect()
|
|
235
|
+
if (_in) {
|
|
236
|
+
// @ts-ignore scrollOffset 的回调在 @dcloudio/types 中声明为必填,运行时可选
|
|
237
|
+
selector.select(_in.selector).scrollOffset()
|
|
238
|
+
.select(_in.selector).boundingClientRect()
|
|
239
|
+
} else {
|
|
240
|
+
// 获取 scroll-view 的位置和滚动距离
|
|
241
|
+
// @ts-ignore 同上
|
|
242
|
+
selector.selectViewport().scrollOffset() // 获取窗口的滚动距离
|
|
243
|
+
}
|
|
244
|
+
selector.exec((res: any) => {
|
|
245
|
+
if (!res[0]) {
|
|
246
|
+
reject(Error('Label not found'))
|
|
247
|
+
return
|
|
182
248
|
}
|
|
183
|
-
|
|
184
|
-
|
|
249
|
+
const scrollTop = res[1].scrollTop + res[0].top - (res[2] ? res[2].top : 0) + (offset as number)
|
|
250
|
+
if (_in) {
|
|
251
|
+
// scroll-view 跳转
|
|
252
|
+
_in.page[_in.scrollTop] = scrollTop
|
|
253
|
+
} else {
|
|
254
|
+
// 页面跳转
|
|
255
|
+
uni.pageScrollTo({
|
|
256
|
+
scrollTop,
|
|
257
|
+
duration: 300
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
resolve()
|
|
261
|
+
})
|
|
262
|
+
// #endif
|
|
263
|
+
})
|
|
264
|
+
}
|
|
185
265
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
resolve()
|
|
205
|
-
} else {
|
|
206
|
-
this._navigateTo = {
|
|
207
|
-
resolve,
|
|
208
|
-
reject,
|
|
209
|
-
offset
|
|
210
|
-
}
|
|
211
|
-
this.$refs.web.evalJs('uni.postMessage({data:{action:"getOffset",offset:(document.getElementById(' + id + ')||{}).offsetTop}})')
|
|
266
|
+
/**
|
|
267
|
+
* @description 获取文本内容
|
|
268
|
+
* @return {String}
|
|
269
|
+
*/
|
|
270
|
+
function getText(nodeList?: any[]) {
|
|
271
|
+
let text = '';
|
|
272
|
+
(function traversal(nodes: any[]) {
|
|
273
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
274
|
+
const node = nodes[i]
|
|
275
|
+
if (node.type === 'text') {
|
|
276
|
+
text += node.text.replace(/&/g, '&')
|
|
277
|
+
} else if (node.name === 'br') {
|
|
278
|
+
text += '\n'
|
|
279
|
+
} else {
|
|
280
|
+
// 块级标签前后加换行
|
|
281
|
+
const isBlock = node.name === 'p' || node.name === 'div' || node.name === 'tr' || node.name === 'li' || (node.name[0] === 'h' && node.name[1] > '0' && node.name[1] < '7')
|
|
282
|
+
if (isBlock && text && text[text.length - 1] !== '\n') {
|
|
283
|
+
text += '\n'
|
|
212
284
|
}
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
// #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO
|
|
217
|
-
deep = '>>>'
|
|
218
|
-
// #endif
|
|
219
|
-
const selector = uni.createSelectorQuery()
|
|
220
|
-
// #ifndef MP-ALIPAY
|
|
221
|
-
.in(this._in ? this._in.page : this)
|
|
222
|
-
// #endif
|
|
223
|
-
.select((this._in ? this._in.selector : '._root') + (id ? `${deep}#${id}` : '')).boundingClientRect()
|
|
224
|
-
if (this._in) {
|
|
225
|
-
selector.select(this._in.selector).scrollOffset()
|
|
226
|
-
.select(this._in.selector).boundingClientRect()
|
|
227
|
-
} else {
|
|
228
|
-
// 获取 scroll-view 的位置和滚动距离
|
|
229
|
-
selector.selectViewport().scrollOffset() // 获取窗口的滚动距离
|
|
285
|
+
// 递归获取子节点的文本
|
|
286
|
+
if (node.children) {
|
|
287
|
+
traversal(node.children)
|
|
230
288
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
const scrollTop = res[1].scrollTop + res[0].top - (res[2] ? res[2].top : 0) + offset
|
|
237
|
-
if (this._in) {
|
|
238
|
-
// scroll-view 跳转
|
|
239
|
-
this._in.page[this._in.scrollTop] = scrollTop
|
|
240
|
-
} else {
|
|
241
|
-
// 页面跳转
|
|
242
|
-
uni.pageScrollTo({
|
|
243
|
-
scrollTop,
|
|
244
|
-
duration: 300
|
|
245
|
-
})
|
|
246
|
-
}
|
|
247
|
-
resolve()
|
|
248
|
-
})
|
|
249
|
-
// #endif
|
|
250
|
-
})
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* @description 获取文本内容
|
|
255
|
-
* @return {String}
|
|
256
|
-
*/
|
|
257
|
-
getText(nodes) {
|
|
258
|
-
let text = '';
|
|
259
|
-
(function traversal(nodes) {
|
|
260
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
261
|
-
const node = nodes[i]
|
|
262
|
-
if (node.type === 'text') {
|
|
263
|
-
text += node.text.replace(/&/g, '&')
|
|
264
|
-
} else if (node.name === 'br') {
|
|
265
|
-
text += '\n'
|
|
266
|
-
} else {
|
|
267
|
-
// 块级标签前后加换行
|
|
268
|
-
const isBlock = node.name === 'p' || node.name === 'div' || node.name === 'tr' || node.name === 'li' || (node.name[0] === 'h' && node.name[1] > '0' && node.name[1] < '7')
|
|
269
|
-
if (isBlock && text && text[text.length - 1] !== '\n') {
|
|
270
|
-
text += '\n'
|
|
271
|
-
}
|
|
272
|
-
// 递归获取子节点的文本
|
|
273
|
-
if (node.children) {
|
|
274
|
-
traversal(node.children)
|
|
275
|
-
}
|
|
276
|
-
if (isBlock && text[text.length - 1] !== '\n') {
|
|
277
|
-
text += '\n'
|
|
278
|
-
} else if (node.name === 'td' || node.name === 'th') {
|
|
279
|
-
text += '\t'
|
|
280
|
-
}
|
|
281
|
-
}
|
|
289
|
+
if (isBlock && text[text.length - 1] !== '\n') {
|
|
290
|
+
text += '\n'
|
|
291
|
+
} else if (node.name === 'td' || node.name === 'th') {
|
|
292
|
+
text += '\t'
|
|
282
293
|
}
|
|
283
|
-
})(nodes || this.nodes)
|
|
284
|
-
return text
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* @description 获取内容大小和位置
|
|
289
|
-
* @return {Promise}
|
|
290
|
-
*/
|
|
291
|
-
getRect() {
|
|
292
|
-
return new Promise((resolve, reject) => {
|
|
293
|
-
uni.createSelectorQuery()
|
|
294
|
-
// #ifndef MP-ALIPAY
|
|
295
|
-
.in(this)
|
|
296
|
-
// #endif
|
|
297
|
-
.select('#_root').boundingClientRect().exec(res => res[0] ? resolve(res[0]) : reject(Error('Root label not found')))
|
|
298
|
-
})
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* @description 暂停播放媒体
|
|
303
|
-
*/
|
|
304
|
-
pauseMedia() {
|
|
305
|
-
for (let i = (this._videos || []).length; i--;) {
|
|
306
|
-
this._videos[i].pause()
|
|
307
294
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
while (!page.$scope) page = page.$parent
|
|
313
|
-
page.$scope.$getAppWebview().evalJS(command)
|
|
314
|
-
// #endif
|
|
315
|
-
// #ifdef APP-PLUS-NVUE
|
|
316
|
-
this.$refs.web.evalJs(command)
|
|
317
|
-
// #endif
|
|
318
|
-
// #endif
|
|
319
|
-
},
|
|
295
|
+
}
|
|
296
|
+
})(nodeList || nodes.value)
|
|
297
|
+
return text
|
|
298
|
+
}
|
|
320
299
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
// #ifdef APP-PLUS
|
|
331
|
-
const command = 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].playbackRate=' + rate
|
|
332
|
-
// #ifndef APP-PLUS-NVUE
|
|
333
|
-
let page = this.$parent
|
|
334
|
-
while (!page.$scope) page = page.$parent
|
|
335
|
-
page.$scope.$getAppWebview().evalJS(command)
|
|
336
|
-
// #endif
|
|
337
|
-
// #ifdef APP-PLUS-NVUE
|
|
338
|
-
this.$refs.web.evalJs(command)
|
|
339
|
-
// #endif
|
|
300
|
+
/**
|
|
301
|
+
* @description 获取内容大小和位置
|
|
302
|
+
* @return {Promise}
|
|
303
|
+
*/
|
|
304
|
+
function getRect() {
|
|
305
|
+
return new Promise<any>((resolve, reject) => {
|
|
306
|
+
uni.createSelectorQuery()
|
|
307
|
+
// #ifndef MP-ALIPAY
|
|
308
|
+
.in(vm)
|
|
340
309
|
// #endif
|
|
341
|
-
|
|
310
|
+
.select('#dd-parse-root').boundingClientRect().exec((res: any) => res[0] ? resolve(res[0]) : reject(Error('Root label not found')))
|
|
311
|
+
})
|
|
312
|
+
}
|
|
342
313
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
314
|
+
/**
|
|
315
|
+
* @description 暂停播放媒体
|
|
316
|
+
*/
|
|
317
|
+
function pauseMedia() {
|
|
318
|
+
for (let i = (_videos.value || []).length; i--;) {
|
|
319
|
+
_videos.value[i].pause()
|
|
320
|
+
}
|
|
321
|
+
// #ifdef APP-PLUS
|
|
322
|
+
const command = 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].pause()'
|
|
323
|
+
// #ifndef APP-PLUS-NVUE
|
|
324
|
+
let page: any = vm.$parent
|
|
325
|
+
while (!page.$scope) page = page.$parent
|
|
326
|
+
page.$scope.$getAppWebview().evalJS(command)
|
|
327
|
+
// #endif
|
|
328
|
+
// #ifdef APP-PLUS-NVUE
|
|
329
|
+
web.value.evalJs(command)
|
|
330
|
+
// #endif
|
|
331
|
+
// #endif
|
|
332
|
+
}
|
|
359
333
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
334
|
+
/**
|
|
335
|
+
* @description 设置媒体播放速率
|
|
336
|
+
* @param {Number} rate 播放速率
|
|
337
|
+
*/
|
|
338
|
+
function setPlaybackRate(rate: number) {
|
|
339
|
+
playbackRate.value = rate
|
|
340
|
+
for (let i = (_videos.value || []).length; i--;) {
|
|
341
|
+
_videos.value[i].playbackRate(rate)
|
|
342
|
+
}
|
|
343
|
+
// #ifdef APP-PLUS
|
|
344
|
+
const command = 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].playbackRate=' + rate
|
|
345
|
+
// #ifndef APP-PLUS-NVUE
|
|
346
|
+
let page: any = vm.$parent
|
|
347
|
+
while (!page.$scope) page = page.$parent
|
|
348
|
+
page.$scope.$getAppWebview().evalJS(command)
|
|
349
|
+
// #endif
|
|
350
|
+
// #ifdef APP-PLUS-NVUE
|
|
351
|
+
web.value.evalJs(command)
|
|
352
|
+
// #endif
|
|
353
|
+
// #endif
|
|
354
|
+
}
|
|
366
355
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
356
|
+
/**
|
|
357
|
+
* @description 设置内容
|
|
358
|
+
* @param {String} content html 内容
|
|
359
|
+
* @param {Boolean} append 是否在尾部追加
|
|
360
|
+
*/
|
|
361
|
+
function setContent(content: string, append?: boolean) {
|
|
362
|
+
if (!append || !imgList.value) {
|
|
363
|
+
imgList.value = []
|
|
364
|
+
}
|
|
365
|
+
const parsed = new Parser(parserCtx).parse(content)
|
|
366
|
+
// #ifdef APP-PLUS-NVUE
|
|
367
|
+
if (_ready) {
|
|
368
|
+
_set(parsed, append)
|
|
369
|
+
}
|
|
370
|
+
// #endif
|
|
371
|
+
nodes.value = append ? (nodes.value || []).concat(parsed) : parsed
|
|
372
|
+
|
|
373
|
+
// #ifndef APP-PLUS-NVUE
|
|
374
|
+
_videos.value = []
|
|
375
|
+
nextTick(() => {
|
|
376
|
+
_hook('onLoad')
|
|
377
|
+
emit('load')
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
if (props.lazyLoad || imgList.value._unloadimgs < imgList.value.length / 2) {
|
|
381
|
+
// 设置懒加载,每 350ms 获取高度,不变则认为加载完毕
|
|
382
|
+
let height = 0
|
|
383
|
+
const callback = (rect: any) => {
|
|
384
|
+
if (!rect || !rect.height) rect = {}
|
|
385
|
+
// 350ms 总高度无变化就触发 ready 事件
|
|
386
|
+
if (rect.height === height) {
|
|
387
|
+
emit('ready', rect)
|
|
383
388
|
} else {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}).catch(() => {
|
|
389
|
-
this.$emit('ready', {})
|
|
390
|
-
})
|
|
391
|
-
}
|
|
389
|
+
height = rect.height
|
|
390
|
+
setTimeout(() => {
|
|
391
|
+
getRect().then(callback).catch(callback)
|
|
392
|
+
}, 350)
|
|
392
393
|
}
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
}
|
|
395
|
+
getRect().then(callback).catch(callback)
|
|
396
|
+
} else {
|
|
397
|
+
// 未设置懒加载,等待所有图片加载完毕
|
|
398
|
+
if (!imgList.value._unloadimgs) {
|
|
399
|
+
getRect().then((rect) => {
|
|
400
|
+
emit('ready', rect)
|
|
401
|
+
}).catch(() => {
|
|
402
|
+
emit('ready', {})
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
// #endif
|
|
407
|
+
}
|
|
395
408
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
409
|
+
/**
|
|
410
|
+
* @description 调用插件钩子函数
|
|
411
|
+
*/
|
|
412
|
+
function _hook(name: string) {
|
|
413
|
+
for (let i = plugins.length; i--;) {
|
|
414
|
+
if (plugins[i][name]) {
|
|
415
|
+
plugins[i][name]()
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
406
419
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
420
|
+
// #ifdef APP-PLUS-NVUE
|
|
421
|
+
/**
|
|
422
|
+
* @description 设置内容
|
|
423
|
+
*/
|
|
424
|
+
function _set(nodesArg: any[], append?: boolean) {
|
|
425
|
+
web.value.evalJs('setContent(' + JSON.stringify(nodesArg).replace(/%22/g, '') + ',' + JSON.stringify([props.containerStyle.replace(/(?:margin|padding)[^;]+/g, ''), props.errorImg, props.loadingImg, props.pauseVideo, props.scrollTable, props.selectable]) + ',' + append + ')')
|
|
426
|
+
}
|
|
414
427
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
428
|
+
/**
|
|
429
|
+
* @description 接收到 web-view 消息
|
|
430
|
+
*/
|
|
431
|
+
function _onMessage(e: any) {
|
|
432
|
+
const message = e.detail.data[0]
|
|
433
|
+
switch (message.action) {
|
|
434
|
+
// web-view 初始化完毕
|
|
435
|
+
case 'onJSBridgeReady':
|
|
436
|
+
_ready = true
|
|
437
|
+
if (nodes.value) {
|
|
438
|
+
_set(nodes.value)
|
|
439
|
+
}
|
|
440
|
+
break
|
|
441
|
+
// 内容 dom 加载完毕
|
|
442
|
+
case 'onLoad':
|
|
443
|
+
height.value = message.height
|
|
444
|
+
_hook('onLoad')
|
|
445
|
+
emit('load')
|
|
446
|
+
break
|
|
447
|
+
// 所有图片加载完毕
|
|
448
|
+
case 'onReady':
|
|
449
|
+
getRect().then((res) => {
|
|
450
|
+
emit('ready', res)
|
|
451
|
+
}).catch(() => {
|
|
452
|
+
emit('ready', {})
|
|
453
|
+
})
|
|
454
|
+
break
|
|
455
|
+
// 总高度发生变化
|
|
456
|
+
case 'onHeightChange':
|
|
457
|
+
height.value = message.height
|
|
458
|
+
break
|
|
459
|
+
// 图片点击
|
|
460
|
+
case 'onImgTap':
|
|
461
|
+
emit('imgtap', message.attrs)
|
|
462
|
+
if (props.previewImg) {
|
|
463
|
+
uni.previewImage({
|
|
464
|
+
current: parseInt(message.attrs.i),
|
|
465
|
+
urls: imgList.value
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
break
|
|
469
|
+
// 链接点击
|
|
470
|
+
case 'onLinkTap': {
|
|
471
|
+
const href = normalizeHref(message.attrs.href)
|
|
472
|
+
emit('linktap', message.attrs)
|
|
473
|
+
if (href) {
|
|
474
|
+
// 锚点跳转
|
|
475
|
+
if (href[0] === '#') {
|
|
476
|
+
if (props.useAnchor) {
|
|
477
|
+
dom.scrollToElement(web.value, {
|
|
478
|
+
offset: message.offset
|
|
453
479
|
})
|
|
454
480
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
})
|
|
467
|
-
}
|
|
468
|
-
} else if (this.isExternalLink(href)) {
|
|
469
|
-
// 打开外链
|
|
470
|
-
if (this.copyLink) {
|
|
471
|
-
this.openExternalLink(href)
|
|
472
|
-
}
|
|
473
|
-
} else {
|
|
474
|
-
uni.navigateTo({
|
|
475
|
-
url: href,
|
|
476
|
-
fail() {
|
|
477
|
-
uni.switchTab({
|
|
478
|
-
url: href
|
|
479
|
-
})
|
|
480
|
-
}
|
|
481
|
+
} else if (isExternalLink(href)) {
|
|
482
|
+
// 打开外链
|
|
483
|
+
if (props.copyLink) {
|
|
484
|
+
openExternalLink(href)
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
uni.navigateTo({
|
|
488
|
+
url: href,
|
|
489
|
+
fail() {
|
|
490
|
+
uni.switchTab({
|
|
491
|
+
url: href
|
|
481
492
|
})
|
|
482
493
|
}
|
|
483
|
-
}
|
|
484
|
-
break
|
|
485
|
-
}
|
|
486
|
-
case 'onPlay':
|
|
487
|
-
this.$emit('play')
|
|
488
|
-
break
|
|
489
|
-
// 获取到锚点的偏移量
|
|
490
|
-
case 'getOffset':
|
|
491
|
-
if (typeof message.offset === 'number') {
|
|
492
|
-
dom.scrollToElement(this.$refs.web, {
|
|
493
|
-
offset: message.offset + this._navigateTo.offset
|
|
494
|
-
})
|
|
495
|
-
this._navigateTo.resolve()
|
|
496
|
-
} else {
|
|
497
|
-
this._navigateTo.reject(Error('Label not found'))
|
|
498
|
-
}
|
|
499
|
-
break
|
|
500
|
-
// 点击
|
|
501
|
-
case 'onClick':
|
|
502
|
-
this.$emit('tap')
|
|
503
|
-
this.$emit('click')
|
|
504
|
-
break
|
|
505
|
-
// 出错
|
|
506
|
-
case 'onError':
|
|
507
|
-
this.$emit('error', {
|
|
508
|
-
source: message.source,
|
|
509
|
-
attrs: message.attrs
|
|
510
494
|
})
|
|
495
|
+
}
|
|
511
496
|
}
|
|
497
|
+
break
|
|
512
498
|
}
|
|
513
|
-
|
|
499
|
+
case 'onPlay':
|
|
500
|
+
emit('play')
|
|
501
|
+
break
|
|
502
|
+
// 获取到锚点的偏移量
|
|
503
|
+
case 'getOffset':
|
|
504
|
+
if (typeof message.offset === 'number') {
|
|
505
|
+
dom.scrollToElement(web.value, {
|
|
506
|
+
offset: message.offset + _navigateTo.offset
|
|
507
|
+
})
|
|
508
|
+
_navigateTo.resolve()
|
|
509
|
+
} else {
|
|
510
|
+
_navigateTo.reject(Error('Label not found'))
|
|
511
|
+
}
|
|
512
|
+
break
|
|
513
|
+
// 点击
|
|
514
|
+
case 'onClick':
|
|
515
|
+
(emit as any)('tap')
|
|
516
|
+
(emit as any)('click')
|
|
517
|
+
break
|
|
518
|
+
// 出错
|
|
519
|
+
case 'onError':
|
|
520
|
+
emit('error', {
|
|
521
|
+
source: message.source,
|
|
522
|
+
attrs: message.attrs
|
|
523
|
+
})
|
|
514
524
|
}
|
|
515
525
|
}
|
|
526
|
+
// #endif
|
|
527
|
+
|
|
528
|
+
// node 子组件经 $parent(即本组件暴露对象)读写状态与 props,方法供外部 $refs 调用
|
|
529
|
+
defineExpose({
|
|
530
|
+
// props(node.vue 直接读取 pauseVideo/previewImg/showImgMenu/copyLink/lazyLoad 等)
|
|
531
|
+
...toRefs(props),
|
|
532
|
+
in: anchorIn,
|
|
533
|
+
navigateTo,
|
|
534
|
+
getText,
|
|
535
|
+
getRect,
|
|
536
|
+
pauseMedia,
|
|
537
|
+
setPlaybackRate,
|
|
538
|
+
setContent,
|
|
539
|
+
normalizeHref,
|
|
540
|
+
isExternalLink,
|
|
541
|
+
openExternalLink,
|
|
542
|
+
nodes,
|
|
543
|
+
imgList,
|
|
544
|
+
_videos,
|
|
545
|
+
playbackRate
|
|
546
|
+
})
|
|
516
547
|
</script>
|
|
517
548
|
|
|
518
549
|
<style>
|
|
519
550
|
/* #ifndef APP-PLUS-NVUE */
|
|
520
551
|
/* 根节点样式 */
|
|
521
|
-
.
|
|
552
|
+
.dd-parse__root {
|
|
522
553
|
padding: 1px 0;
|
|
523
554
|
overflow-x: auto;
|
|
524
555
|
overflow-y: hidden;
|
|
@@ -526,7 +557,7 @@ export default {
|
|
|
526
557
|
}
|
|
527
558
|
|
|
528
559
|
/* 长按复制 */
|
|
529
|
-
.
|
|
560
|
+
.dd-parse--select {
|
|
530
561
|
user-select: text;
|
|
531
562
|
}
|
|
532
563
|
|