zydx-plus 1.11.45 → 1.12.45
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/package.json +1 -1
- package/src/components/word/index.js +6 -0
- package/src/components/word/src/word.vue +160 -0
- package/src/index.js +6 -3
package/package.json
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="page">
|
|
3
|
+
<div class="page-content" v-for="(item,index) in pages" :key="index" v-html="item"></div>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
name: "zydx-word",
|
|
10
|
+
data() {
|
|
11
|
+
return {
|
|
12
|
+
perPage: 38,
|
|
13
|
+
pages: [],
|
|
14
|
+
imgList: [], // 图片列表
|
|
15
|
+
strNum: 76, // 每行字符数
|
|
16
|
+
pagesText: '', // 每页内容
|
|
17
|
+
start: 0,
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
props: {
|
|
21
|
+
content: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: ''
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
mounted() {
|
|
27
|
+
this.splitHtml(this.content, this.perPage)
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
getImgHeight(imgs) {
|
|
31
|
+
// 获取img标签里的图片地址
|
|
32
|
+
imgs = imgs.join('')
|
|
33
|
+
imgs = imgs.match(/<img.*?>/g)
|
|
34
|
+
if (imgs === null) return
|
|
35
|
+
for (let i = 0; i < imgs.length; i++) {
|
|
36
|
+
// 获取图片地址
|
|
37
|
+
imgs[i] = imgs[i].match(/src=".*?"/g)[0].replace(/src="|"/g, '')
|
|
38
|
+
const img = new Image()
|
|
39
|
+
img.src = imgs[i]
|
|
40
|
+
img.onload = () => {
|
|
41
|
+
let height = img.height
|
|
42
|
+
let width = img.width
|
|
43
|
+
// 计算图片比例
|
|
44
|
+
const scale = height / width
|
|
45
|
+
// 计算图片高度整数
|
|
46
|
+
height = Math.floor(693 * scale)
|
|
47
|
+
this.imgList.push({
|
|
48
|
+
src: imgs[i],
|
|
49
|
+
height: height,
|
|
50
|
+
width: width,
|
|
51
|
+
index: i
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
resetData() {
|
|
57
|
+
this.start = 0
|
|
58
|
+
this.pages.push(this.pagesText)
|
|
59
|
+
this.pagesText = ''
|
|
60
|
+
},
|
|
61
|
+
splitHtml(html, perPage) {
|
|
62
|
+
const arr = html.split('</p>')
|
|
63
|
+
this.getImgHeight(arr)
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
// 重新排序
|
|
66
|
+
this.imgList.sort((a, b) => {
|
|
67
|
+
return a.index - b.index
|
|
68
|
+
})
|
|
69
|
+
let imgIndex = 0
|
|
70
|
+
// 筛选出标签里的内容
|
|
71
|
+
for (let i = 0; i < arr.length; i++) {
|
|
72
|
+
// 判断是否是最后一个
|
|
73
|
+
if (arr.length - 1 === i) {
|
|
74
|
+
this.pagesText += `${arr[i]}`
|
|
75
|
+
this.resetData()
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
if (this.start >= perPage) this.resetData()
|
|
79
|
+
// 判断是否是img标签
|
|
80
|
+
if (arr[i].indexOf('<img') > -1) {
|
|
81
|
+
const h = this.imgList[imgIndex].height
|
|
82
|
+
const w = this.imgList[imgIndex].width
|
|
83
|
+
const src = this.imgList[imgIndex].src
|
|
84
|
+
const hNum = Math.ceil(h / 27)
|
|
85
|
+
if ((perPage - this.start) < hNum) this.resetData()
|
|
86
|
+
this.start += hNum
|
|
87
|
+
this.pagesText += `<p style="text-align: center;"><img style="width: ${(w < 693) ? w : 693}px;height: ${(h > 1020) ? 1020 : h}px;vertical-align: middle;padding: 14px 0" src="${src}" alt="" /></p>`
|
|
88
|
+
imgIndex += 1
|
|
89
|
+
} else {
|
|
90
|
+
// 判断标签是否是h1-h6
|
|
91
|
+
if (arr[i].indexOf('<h') > -1) {
|
|
92
|
+
arr[i] = arr[i].replace(/<h[1-6]>/g, '<p style="font-size: 18px;font-weight: bold;">')
|
|
93
|
+
arr[i] = arr[i].replace(/<\/h[1-6]>/g, '</p>')
|
|
94
|
+
}
|
|
95
|
+
const text = arr[i].replace(/<[^>]+>/g, '')
|
|
96
|
+
const lenNum = Math.ceil(this.thatLenText(text,0).len / this.strNum)
|
|
97
|
+
if ((perPage - this.start) < lenNum) {
|
|
98
|
+
const { st, end, surplus } = this.thatLenText(text,(perPage - this.start),lenNum)
|
|
99
|
+
this.pagesText += `<p>${st}</p>`
|
|
100
|
+
this.resetData()
|
|
101
|
+
this.start = surplus
|
|
102
|
+
this.pagesText = `<p>${end}</p>`
|
|
103
|
+
}else {
|
|
104
|
+
this.start += (lenNum <= 0) ? 1 : lenNum
|
|
105
|
+
this.pagesText += `${arr[i]}`
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, 200)
|
|
110
|
+
},
|
|
111
|
+
// 计算每行字符数
|
|
112
|
+
thatLenText(data,num,lenNum) {
|
|
113
|
+
let len = 0
|
|
114
|
+
let st = ''
|
|
115
|
+
let end = ''
|
|
116
|
+
for(let i= 0; i < data.length; i++) {
|
|
117
|
+
if(data[i].replace(/[^\u4e00-\u9fa5]/g, '')) {
|
|
118
|
+
len += 2
|
|
119
|
+
}else if(data[i].match(/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u2014|\u2026|\u2013]/g)) {
|
|
120
|
+
len += 2
|
|
121
|
+
}else if(data[i].match(/[a-zA-Z]/g)) {
|
|
122
|
+
len += 1
|
|
123
|
+
}else {
|
|
124
|
+
len += 1
|
|
125
|
+
}
|
|
126
|
+
if(len <= num*this.strNum) {
|
|
127
|
+
st += data[i]
|
|
128
|
+
}else {
|
|
129
|
+
end += data[i]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {st, end, len, row: num-1, surplus: lenNum - num}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<style scoped>
|
|
139
|
+
.page {
|
|
140
|
+
text-align: center;
|
|
141
|
+
width: 100%;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.page-content {
|
|
145
|
+
width: 793px;
|
|
146
|
+
height: 1122px;
|
|
147
|
+
background-color: #fff;
|
|
148
|
+
padding: 50px;
|
|
149
|
+
display: inline-block;
|
|
150
|
+
box-sizing: border-box;
|
|
151
|
+
white-space: pre-wrap;
|
|
152
|
+
text-align: left;
|
|
153
|
+
box-shadow: 0 0 5px rgba(0, 0, 0, .5);
|
|
154
|
+
margin-bottom: 30px;
|
|
155
|
+
font-size: 18px;
|
|
156
|
+
line-height: 1.5;
|
|
157
|
+
page-break-after: always;
|
|
158
|
+
position: relative;
|
|
159
|
+
}
|
|
160
|
+
</style>
|
package/src/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import treeList from './components/treeList/index';
|
|
|
14
14
|
import flip from './components/flip/index';
|
|
15
15
|
import editor from './components/editor/index';
|
|
16
16
|
import tab from './components/tab/index';
|
|
17
|
+
import word from './components/word/index';
|
|
17
18
|
|
|
18
19
|
const components = [
|
|
19
20
|
Calendar,
|
|
@@ -29,7 +30,8 @@ const components = [
|
|
|
29
30
|
treeList,
|
|
30
31
|
flip,
|
|
31
32
|
editor,
|
|
32
|
-
tab
|
|
33
|
+
tab,
|
|
34
|
+
word
|
|
33
35
|
];
|
|
34
36
|
|
|
35
37
|
function install(app) {
|
|
@@ -41,7 +43,7 @@ function install(app) {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
export default {
|
|
44
|
-
version: '1.
|
|
46
|
+
version: '1.12.45',
|
|
45
47
|
install,
|
|
46
48
|
Calendar,
|
|
47
49
|
Message,
|
|
@@ -58,6 +60,7 @@ export default {
|
|
|
58
60
|
treeList,
|
|
59
61
|
flip,
|
|
60
62
|
editor,
|
|
61
|
-
tab
|
|
63
|
+
tab,
|
|
64
|
+
word
|
|
62
65
|
};
|
|
63
66
|
|