zydx-plus 1.30.175 → 1.31.176

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zydx-plus",
3
- "version": "1.30.175",
3
+ "version": "1.31.176",
4
4
  "description": "Vue.js",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -40,7 +40,8 @@
40
40
  "@tiptap/extension-link": "^2.0.3",
41
41
  "@vue-office/docx": "^1.1.3",
42
42
  "@vue-office/excel": "^1.1.3",
43
- "fabric": "^5.3.0"
43
+ "fabric": "^5.3.0",
44
+ "js-export-word": "^1.0.5"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "vue": "^3.2.13"
@@ -17,7 +17,7 @@
17
17
  <div :style="{'border': (borderShow)? '1px solid #ccc': '0'}" v-if="editorShow">
18
18
  <editor-content class="editor" :editor="editor" :style="heightStyleCont" />
19
19
  </div>
20
- <div class="editor-but" v-if="butText !== ''&& readOnly">
20
+ <div class="editor-but" v-if="butText !== '' && readOnly">
21
21
  <button class="but" @click="complete">{{ butText }}</button>
22
22
  </div>
23
23
  <div class="enclosure" v-if="uploadAttData.length > 0 && enclosureShow">
@@ -84,6 +84,7 @@ import Placeholder from '@tiptap/extension-placeholder'
84
84
  import Color from '@tiptap/extension-color'
85
85
  import textStyle from '@tiptap/extension-text-style'
86
86
  import { sid } from "./sign-id";
87
+ import { FontSize } from "./font-size";
87
88
  export default {
88
89
  name: 'zydx-xiao-editor',
89
90
  components: {
@@ -191,7 +192,7 @@ export default {
191
192
  // 强制监听data变化
192
193
  data: {
193
194
  handler: function (e, oldVal) {
194
- this.editor.commands.setContent(json2html({node: "root",child: (e.html === undefined || null)? [] : e.html}))
195
+ this.editor?.commands.setContent(json2html({node: "root",child: (e.html === undefined || null)? [] : e.html}))
195
196
  this.uploadAttData = (e.enclosure === undefined)? [] : this.enclosureAction(e.enclosure)
196
197
  },
197
198
  deep: true
@@ -218,6 +219,7 @@ export default {
218
219
  sid,
219
220
  StarterKit,
220
221
  textStyle,
222
+ FontSize,
221
223
  Color.configure({
222
224
  types: ['textStyle'],
223
225
  }),
@@ -357,6 +359,9 @@ export default {
357
359
  this.editor.chain().focus().insertContentAt(this.selection(),html).run()
358
360
  }
359
361
  },
362
+ enclosureContent(v) {
363
+ this.uploadAttData = [...this.uploadAttData, ...this.enclosureAction(v)]
364
+ },
360
365
  download(index) {
361
366
  this.$emit('download', this.uploadAttData[index])
362
367
  },
@@ -392,10 +397,10 @@ export default {
392
397
  return json.child
393
398
  },
394
399
  toolTap(v) {
395
- if(v === 'h1') this.editor.chain().focus().toggleHeading({level:1}).run()
396
- if(v === 'h2') this.editor.chain().focus().toggleHeading({level:2}).run()
397
- if(v === 'h3') this.editor.chain().focus().toggleHeading({level:3}).run()
398
- if(v === 'p') this.editor.chain().focus().setParagraph().run()
400
+ if(v === 'h1') this.editor.chain().focus().setFontSize('18px').setBold().run()
401
+ if(v === 'h2') this.editor.chain().focus().setFontSize('16px').setBold().run()
402
+ if(v === 'h3') this.editor.chain().focus().setFontSize('14px').setBold().run()
403
+ if(v === 'p') this.editor.chain().focus().setParagraph().setFontSize('14px').unsetBold().run()
399
404
  if(v === 'bold') this.editor.chain().focus().toggleBold().run()
400
405
  if(v === 'center' || v === 'left' || v === 'right') this.editor.chain().focus().setTextAlign(v).run()
401
406
  if(v === 'add') {
@@ -403,9 +408,9 @@ export default {
403
408
  html += '<p style="text-align: right;"><span style="color: #999;">请填来源</span></p>'
404
409
  this.editor.commands.setContent(html)
405
410
  }
406
- if(v === 'centerH2') this.editor.chain().focus().toggleHeading({level:2}).setTextAlign('center').run()
407
- if(v === 'leftH2') this.editor.chain().focus().toggleHeading({level:2}).setTextAlign('left').run()
408
- if(v === 'rightH2') this.editor.chain().focus().toggleHeading({level:2}).setTextAlign('right').run()
411
+ if(v === 'centerH2') this.editor.chain().focus().setFontSize('16px').setBold().setTextAlign('center').run()
412
+ if(v === 'leftH2') this.editor.chain().focus().setFontSize('16px').setBold().setTextAlign('left').run()
413
+ if(v === 'rightH2') this.editor.chain().focus().setFontSize('16px').setBold().setTextAlign('right').run()
409
414
  }
410
415
  }
411
416
  }
@@ -413,6 +418,22 @@ export default {
413
418
  </script>
414
419
 
415
420
  <style scoped>
421
+ .editor :deep(h1) {
422
+ line-height: 25px;
423
+ font-size: 18px;
424
+ }
425
+ .editor :deep(h2) {
426
+ line-height: 25px;
427
+ font-size: 16px;
428
+ }
429
+ .editor :deep(h3) {
430
+ line-height: 25px;
431
+ font-size: 14px;
432
+ }
433
+ .editor :deep(p) {
434
+ font-size: 14px;
435
+ line-height: 25px;
436
+ }
416
437
  :deep(.ProseMirror) p.is-editor-empty:first-child::before {
417
438
  content: attr(data-placeholder);
418
439
  float: left;
@@ -0,0 +1,49 @@
1
+ import { Extension } from '@tiptap/core'
2
+
3
+ export const FontSize = Extension.create({
4
+ name: 'fontSize',
5
+
6
+ addOptions() {
7
+ return {
8
+ types: ['textStyle'],
9
+ }
10
+ },
11
+
12
+ addGlobalAttributes() {
13
+ return [
14
+ {
15
+ types: this.options.types,
16
+ attributes: {
17
+ fontSize: {
18
+ default: null,
19
+ parseHTML: element => element.style.fontSize.replace(/['"]+/g, ''),
20
+ renderHTML: attributes => {
21
+ if (!attributes.fontSize) {
22
+ return {}
23
+ }
24
+ return {
25
+ style: `font-size: ${attributes.fontSize}`,
26
+ }
27
+ },
28
+ },
29
+ },
30
+ },
31
+ ]
32
+ },
33
+
34
+ addCommands() {
35
+ return {
36
+ setFontSize: fontSize => ({ chain }) => {
37
+ return chain()
38
+ .setMark('textStyle', { fontSize })
39
+ .run()
40
+ },
41
+ unsetFontSize: () => ({ chain }) => {
42
+ return chain()
43
+ .setMark('textStyle', { fontSize: null })
44
+ .removeEmptyTextStyle()
45
+ .run()
46
+ },
47
+ }
48
+ },
49
+ })
@@ -0,0 +1,6 @@
1
+ import main from './src/word';
2
+
3
+ main.install = function(Vue) {
4
+ Vue.component(main.name, main);
5
+ };
6
+ export default main;
@@ -0,0 +1,24 @@
1
+ .page-cont{
2
+ width: 794px;
3
+ margin: 0 auto;
4
+ position: relative;
5
+ }
6
+ .page-cont-html{
7
+ width: 100%;
8
+ height: 1123px;
9
+ padding: 100px;
10
+ background-color: #fff;
11
+ box-sizing: border-box;
12
+ position: relative;
13
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
14
+ margin: 20px 0;
15
+ }
16
+ .page-cont-num{
17
+ position: absolute;
18
+ bottom: 25px;
19
+ left: 50%;
20
+ z-index: 1;
21
+ font-size: 14px;
22
+ transform: translateX(-50%);
23
+ color: #999;
24
+ }
@@ -0,0 +1,91 @@
1
+ <template>
2
+ <div class="word-cont">
3
+ <div class="word-slot" :style="page?style:{}" id="test">
4
+ <slot></slot>
5
+ </div>
6
+ <div class="word-page" v-if="page">
7
+ <div class="page-cont" v-for="(item,index) in htmlArr">
8
+ <div class="page-cont-html" v-html="item"></div>
9
+ <div class="page-cont-num">{{ index + 1 }}/{{ htmlArr.length }}</div>
10
+ </div>
11
+ </div>
12
+ </div>
13
+ </template>
14
+
15
+ <script>
16
+ import exportWord from 'js-export-word'
17
+
18
+ export default {
19
+ name: "zydx-paper",
20
+ data() {
21
+ return {
22
+ htmlArr: []
23
+ }
24
+ },
25
+ props: {
26
+ page: {
27
+ type: Boolean,
28
+ default: false
29
+ },
30
+ fileName: {
31
+ type: String,
32
+ default: '试卷'
33
+ }
34
+ },
35
+ computed: {
36
+ style() {
37
+ return {
38
+ position: 'fixed',
39
+ top: '-9999px',
40
+ left: 0,
41
+ zIndex: -1,
42
+ opacity: 0
43
+ }
44
+ }
45
+ },
46
+ mounted() {
47
+ this.$nextTick(() => {
48
+ this.init()
49
+ })
50
+ },
51
+ methods: {
52
+ init() {
53
+ const slot = this.$slots.default()[0]
54
+ let max = 1123
55
+ let pHeight = 0
56
+ let html = ''
57
+ for (let i = 0; i < slot.children.length; i++) {
58
+ const data = document.getElementsByClassName(slot.children[i].props.class)
59
+ let text = data[0].offsetHeight
60
+ if((pHeight + text) > max) {
61
+ this.htmlArr.push(html)
62
+ pHeight = 0
63
+ html = ''
64
+ }
65
+ pHeight += text
66
+ html += data[0].outerHTML
67
+ if(i === slot.children.length - 1) {
68
+ this.htmlArr.push(html)
69
+ pHeight = 0
70
+ html = ''
71
+ break
72
+ }
73
+ }
74
+ },
75
+ exportToWord() {
76
+ const wrap = document.getElementById('test')
77
+ const config = {
78
+ addStyle: true, // 是否导出样式,默认为true,此操作会将所有样式转换成行内样式导出
79
+ fileName: this.fileName, // 导出文件名
80
+ // toImg:['.need-to-img','.bg-danger'], // 页面哪些部分需要转化成图片,例如echart图表之类
81
+ success() {
82
+ console.log('导出成功')
83
+ } // 完成之后回调,一般页面篇幅比较大,时间比较长
84
+ }
85
+ exportWord(wrap, config)
86
+ }
87
+ }
88
+ }
89
+ </script>
90
+
91
+ <style scoped src="./word.css"></style>
package/src/index.js CHANGED
@@ -30,6 +30,7 @@ import word from './components/word/index';
30
30
  import sketchpad from './components/sketchpad/index';
31
31
  import pictureViewer from './components/pictureViewer/index';
32
32
  import lessonTemplate from './components/lesson_template/index';
33
+ import paper from './components/word2/index';
33
34
 
34
35
  const components = [
35
36
  Calendar,
@@ -61,7 +62,8 @@ const components = [
61
62
  word,
62
63
  sketchpad,
63
64
  pictureViewer,
64
- lessonTemplate
65
+ lessonTemplate,
66
+ paper
65
67
  ];
66
68
 
67
69
  function install(app) {
@@ -73,7 +75,7 @@ function install(app) {
73
75
  }
74
76
 
75
77
  export default {
76
- version: '1.30.175',
78
+ version: '1.31.176',
77
79
  install,
78
80
  Calendar,
79
81
  Message,
@@ -106,6 +108,7 @@ export default {
106
108
  word,
107
109
  sketchpad,
108
110
  pictureViewer,
109
- lessonTemplate
111
+ lessonTemplate,
112
+ paper
110
113
  };
111
114