Skip to content

Commit

Permalink
selectable 属性设置为 force 时能够在微信 iOS 端生效(文本块会变成 inline-block)#267
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-yufeng committed Mar 2, 2021
1 parent f40fca8 commit d9955d2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions docs/basic/prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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* 标签的内容设置到页面标题
Expand Down
4 changes: 2 additions & 2 deletions src/miniprogram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ Component({

/**
* @description 是否开启长按复制
* @type {Boolean}
* @type {Boolean | String}
* @default false
*/
selectable: Boolean,
selectable: null,

/**
* @description 是否将 title 标签的内容设置到页面标题
Expand Down
13 changes: 12 additions & 1 deletion src/miniprogram/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/uni-app/components/mp-html/mp-html.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 标签的默认样式
Expand Down Expand Up @@ -84,7 +84,7 @@ export default {
default: true
},
scrollTable: Boolean,
selectable: Boolean,
selectable: null,
setTitle: {
type: Boolean,
default: true
Expand Down
2 changes: 1 addition & 1 deletion src/uni-app/components/mp-html/node/node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- #endif -->
<!-- 文本 -->
<!-- #ifndef MP-BAIDU -->
<text v-else-if="n.type=='text'" decode>{{n.text}}</text>
<text v-else-if="n.type=='text'" :user-select="n.us" decode>{{n.text}}</text>
<!-- #endif -->
<text v-else-if="n.name=='br'">\n</text>
<!-- 链接 -->
Expand Down
13 changes: 12 additions & 1 deletion src/uni-app/components/mp-html/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d9955d2

Please sign in to comment.