diff --git a/docs/basic/prop.md b/docs/basic/prop.md index 8638d1bd..c4a65cf6 100644 --- a/docs/basic/prop.md +++ b/docs/basic/prop.md @@ -73,10 +73,12 @@ ## selectable 功能:是否开启文本长按复制 -类型:*Boolean* +类型:*Boolean* / *String* 默认值:*false* -!> 微信 *ios* 端该属性可能失效 +!> 将本属性的值设置为 *true* 在微信 *iOS* 端可能失效,若必要使用,需将本属性设置为 "*force*",但会带来以下影响: +1、所有文本块会显示为 *inline-block*(通过 [text](https://developers.weixin.qq.com/miniprogram/dev/component/text.html) 标签的 *user-select* 属性实现),需要自行适配 +2、所有文本块都无法被 *rich-text* 包含,一定程度上增加标签数,减慢渲染速度 ## set-title 功能:是否将 *title* 标签的内容设置到页面标题 diff --git a/src/miniprogram/index.js b/src/miniprogram/index.js index c8d51818..54221e60 100644 --- a/src/miniprogram/index.js +++ b/src/miniprogram/index.js @@ -89,10 +89,10 @@ Component({ /** * @description 是否开启长按复制 - * @type {Boolean} + * @type {Boolean | String} * @default false */ - selectable: Boolean, + selectable: null, /** * @description 是否将 title 标签的内容设置到页面标题 diff --git a/src/miniprogram/parser.js b/src/miniprogram/parser.js index 1dfc270a..ec9c1879 100644 --- a/src/miniprogram/parser.js +++ b/src/miniprogram/parser.js @@ -52,7 +52,12 @@ const config = { u: 'text-decoration:underline' } } -const windowWidth = wx.getSystemInfoSync().windowWidth +const { + windowWidth, + // #ifdef MP-WEIXIN + system + // #endif +} = wx.getSystemInfoSync() const blankChar = makeMap(' ,\r,\n,\t,\f') let idIndex = 0 @@ -823,6 +828,12 @@ parser.prototype.onText = function (text) { node.type = 'text' node.text = decodeEntity(text) if (this.hook(node)) { + // #ifdef MP-WEIXIN + if (this.options.selectable == 'force' && system.includes('iOS')) { + this.expose() + node.us = 'T' + } + // #endif let siblings = this.stack.length ? this.stack[this.stack.length - 1].children : this.nodes siblings.push(node) } diff --git a/src/uni-app/components/mp-html/mp-html.vue b/src/uni-app/components/mp-html/mp-html.vue index b5336246..f54b3256 100644 --- a/src/uni-app/components/mp-html/mp-html.vue +++ b/src/uni-app/components/mp-html/mp-html.vue @@ -24,7 +24,7 @@ * @property {Boolean} pause-video 是否在播放一个视频时自动暂停其他视频 * @property {Boolean} preview-img 是否允许图片被点击时自动预览 * @property {Boolean} scroll-table 是否给每个表格添加一个滚动层使其能单独横向滚动 - * @property {Boolean} selectable 是否开启长按复制 + * @property {Boolean | String} selectable 是否开启长按复制 * @property {Boolean} set-title 是否将 title 标签的内容设置到页面标题 * @property {Boolean} show-img-menu 是否允许图片被长按时显示菜单 * @property {Object} tag-style 标签的默认样式 @@ -84,7 +84,7 @@ export default { default: true }, scrollTable: Boolean, - selectable: Boolean, + selectable: null, setTitle: { type: Boolean, default: true diff --git a/src/uni-app/components/mp-html/node/node.vue b/src/uni-app/components/mp-html/node/node.vue index 74ab996e..f9aac328 100644 --- a/src/uni-app/components/mp-html/node/node.vue +++ b/src/uni-app/components/mp-html/node/node.vue @@ -13,7 +13,7 @@ - {{n.text}} + {{n.text}} \n diff --git a/src/uni-app/components/mp-html/parser.js b/src/uni-app/components/mp-html/parser.js index db367432..8dee7e72 100644 --- a/src/uni-app/components/mp-html/parser.js +++ b/src/uni-app/components/mp-html/parser.js @@ -54,7 +54,12 @@ const config = { // #endif } } -const windowWidth = uni.getSystemInfoSync().windowWidth +const { + windowWidth, + // #ifdef MP-WEIXIN + system + // #endif +} = uni.getSystemInfoSync() const blankChar = makeMap(' ,\r,\n,\t,\f') let idIndex = 0 @@ -894,6 +899,12 @@ parser.prototype.onText = function (text) { node.type = 'text' node.text = decodeEntity(text) if (this.hook(node)) { + // #ifdef MP-WEIXIN + if (this.options.selectable == 'force' && system.includes('iOS')) { + this.expose() + node.us = 'T' + } + // #endif let siblings = this.stack.length ? this.stack[this.stack.length - 1].children : this.nodes siblings.push(node) }