|
|
- <template>
- <view class="yingbing-content" v-html="contentSync"></view>
- </template>
-
- <script>
- export default {
- inject: ['getFontSize', 'getFontFamily', 'getLineHeight', 'getColor', 'getSelectable'],
- props: {
- item: {
- type: Object,
- default () {
- return new Object
- }
- }
- },
- computed: {
- color () {
- return this.getColor()
- },
- fontSize () {
- return this.getFontSize()
- },
- fontFamily () {
- return this.getFontFamily()
- },
- lineHeight () {
- return this.getLineHeight()
- },
- selectable () {
- return this.getSelectable()
- },
- contentSync () {
- let content = this.item.content || ''
- content = content.replace('<whole-render', '<div').replace('<\/whole-render>', '<\/div>')
- return `<div class="yingbing-reader-content-html ${this.selectable ? 'user-selectable' : 'user-selectclose'}" style="box-sizing: border-box;color:${this.color};font-family:${this.fontFamily};font-size:${this.fontSize}px;line-height:${this.lineHeight}px;">` + content + '</div>'
- }
- },
- data () {
- return {
- selectShow: false,
- selectTop: 0,
- selectLeft: 0,
- selectArrowLeft: 0
- }
- },
- mounted() {
- // #ifdef H5
- // document.addEventListener('selectionchange',() => {
- // const selection = window.getSelection();// 获取当前的选区对象
- // // 如果选区不为空
- // if (selection.toString()) {
- // // 获取选区中的第一个范围
- // const range = selection.getRangeAt(0);
- // // 将选区的边界用于定位操作框
- // const rect = range.getBoundingClientRect();
- // const box = document.querySelector('.yingbing-reader-select-box')
- // this.selectArrowLeft = rect.left
- // this.selectTop = rect.top + (box.offsetHeight / 2)
- // this.selectLeft = rect.left - (box.offsetWidth / 2)
- // const right = box.offsetWidth + this.selectLeft
- // const bottom = box.offsetHeight + this.selectTop
- // if ( right > document.body.offsetWidth ) this.selectLeft = this.selectLeft - (right - document.body.offsetWidth)
- // if ( bottom > document.body.offsetHeight ) this.selectTop = this.selectTop - (bottom - document.body.offsetHeight)
- // this.selectShow = true
- // } else {
- // this.selectShow = false
- // }
- // });
- // #endif
- }
- }
- </script>
-
- <style scoped>
- /deep/ .yingbing-img {
- max-width: 100%!important;
- box-sizing: border-box!important;
- }
- /deep/ .user-selectable {
- -webkit-user-select: text; /*webkit浏览器*/
- -khtml-user-select: text; /*早期浏览器*/
- -moz-user-select: text; /*火狐*/
- -ms-user-select: text; /*IE10*/
- user-select: text;
- }
- /deep/ .user-selectclose {
- -webkit-touch-callout: none; /*系统默认菜单被禁用*/
- -webkit-user-select: none; /*webkit浏览器*/
- -khtml-user-select: none; /*早期浏览器*/
- -moz-user-select: none; /*火狐*/
- -ms-user-select: none; /*IE10*/
- user-select: none;
- }
- .yingbing-content {
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- }
- .yingbing-reader-select-box {
- position: fixed;
- display: flex;
- flex-direction: row;
- background-color: #fff;
- box-shadow: 0 0 10px rgba(0,0,0,.1);
- border-radius: 5px;
- padding: 15px 10px;
- }
- .yingbing-reader-select-box .arrow {
- position: absolute;
- width: 0;
- height: 0;
- border-top: 6px solid transparent;
- border-left: 6px solid transparent;
- border-right: 6px solid transparent;
- border-bottom: 6px solid #fff;
- top: -12px;
- }
- .yingbing-reader-select-box .select-box-item {
- padding: 0 10px;
- font-size: 13px;
- flex-shrink: 0;
- }
- </style>
|