sh-view 1.6.0 → 1.6.5

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": "sh-view",
3
- "version": "1.6.0",
3
+ "version": "1.6.5",
4
4
  "description": "基于vxe-table、view-ui-plus二次封装",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
@@ -17,11 +17,13 @@
17
17
  "@codemirror/lang-sql": "^6.5.2",
18
18
  "@codemirror/theme-one-dark": "^6.1.2",
19
19
  "@tinymce/tinymce-vue": "^5.0.0",
20
+ "@vue-office/docx": "^1.2.3",
21
+ "@vue-office/excel": "^1.2.7",
22
+ "@vue-office/pdf": "^1.2.6",
20
23
  "babel-polyfill": "^6.26.0",
21
24
  "codemirror": "^6.0.1",
22
25
  "core-js": "^3.32.0",
23
26
  "cron-parser": "^4.8.1",
24
- "docx-preview": "^0.1.18",
25
27
  "exceljs": "^4.3.0",
26
28
  "file-saver": "^2.0.5",
27
29
  "jspdf": "^2.5.1",
@@ -30,6 +32,7 @@
30
32
  "tinymce": "^5.10.5",
31
33
  "view-ui-plus": "^1.3.14",
32
34
  "vue": "^3.3.4",
35
+ "vue-demi": "^0.13.11",
33
36
  "vue-masonry": "^0.16.0",
34
37
  "vue-ripple-directive": "^2.0.1",
35
38
  "vue-router": "^4.2.2",
@@ -1,15 +1,22 @@
1
1
  <template>
2
2
  <div class="sh-preview">
3
- <template v-if="previewObj.component">
4
- <component :is="previewObj.component" :url="url" :width="width" :height="height" disabled />
5
- </template>
6
- <iframe v-else :src="(previewObj.base || '') + url + '#scrollbars=0&toolbar=0&statusbar=0'" :width="width" :height="height" frameborder="0"></iframe>
3
+ <component :is="componentName" v-bind="componentProps" :style="componentStyles" @rendered="onRendered" @error="onError" />
7
4
  </div>
8
5
  </template>
9
6
 
10
7
  <script>
8
+ import ShWord from '@vue-office/docx'
9
+ import '@vue-office/docx/lib/index.css'
10
+ import * as ShExcel from '@vue-office/excel'
11
+ import '@vue-office/excel/lib/index.css'
12
+ import * as ShPdf from '@vue-office/pdf'
11
13
  export default {
12
14
  name: 'ShPreview',
15
+ components: {
16
+ ShWord,
17
+ ShExcel,
18
+ ShPdf
19
+ },
13
20
  props: {
14
21
  type: {
15
22
  type: String
@@ -29,26 +36,42 @@ export default {
29
36
  default: '600px'
30
37
  }
31
38
  },
32
- data() {
33
- return {
34
- compTypeObj: [
35
- {
36
- types: ['word', 'doc', 'docx'],
37
- component: 'ShWord'
38
- },
39
- {
40
- types: ['excel', 'xlsx'],
41
- component: 'ShSheet'
42
- }
43
- ]
44
- }
45
- },
39
+ emits: ['ready', 'error'],
46
40
  computed: {
47
41
  previewType() {
48
42
  return (this.type && this.type.toLowerCase()) || (this.url && this.url.substr(this.url.lastIndexOf('.') + 1).toLowerCase())
49
43
  },
50
- previewObj() {
51
- return this.compTypeObj.find(item => item.types.includes(this.previewType)) || {}
44
+ componentName() {
45
+ if (['word', 'doc', 'docx'].includes(this.previewType)) {
46
+ return 'sh-word'
47
+ } else if (['excel', 'xlsx'].includes(this.previewType)) {
48
+ return 'sh-excel'
49
+ } else if (['pdf'].includes(this.previewType)) {
50
+ return 'sh-pdf'
51
+ }
52
+ return 'iframe'
53
+ },
54
+ componentProps() {
55
+ let srcPrefix = this.base || ''
56
+ let srcSuffix = this.componentName === 'iframe' ? '#scrollbars=0&toolbar=0&statusbar=0' : ''
57
+ return {
58
+ src: srcPrefix + this.url + srcSuffix,
59
+ frameborder: 0
60
+ }
61
+ },
62
+ componentStyles() {
63
+ return {
64
+ width: this.width,
65
+ height: this.height
66
+ }
67
+ }
68
+ },
69
+ methods: {
70
+ onRendered(data) {
71
+ this.$emit('ready', data)
72
+ },
73
+ onError(data) {
74
+ this.$emit('error', data)
52
75
  }
53
76
  }
54
77
  }
@@ -13,7 +13,6 @@ import ShNoticeBar from './global-components/sh-noticebar/index.vue'
13
13
  import ShPreview from './global-components/sh-preview/index.vue'
14
14
  import ShPullRefresh from './global-components/sh-pull-refresh/index.vue'
15
15
  import ShResult from './global-components/sh-result/index.vue'
16
- import ShSheet from './global-components/sh-sheet/index.vue'
17
16
  import ShUpload from './global-components/sh-upload/index.vue'
18
17
  import ShForm from './global-components/sh-vxe-form/index.vue'
19
18
  import ShList from './global-components/sh-vxe-list/index.vue'
@@ -23,7 +22,6 @@ import ShTable from './global-components/sh-vxe-table/index.vue'
23
22
  import ShToolbar from './global-components/sh-vxe-toolbar/index.vue'
24
23
  import ShTree from './global-components/sh-vxe-tree/index.vue'
25
24
  import ShWaterFall from './global-components/sh-water-fall/index.vue'
26
- import ShWord from './global-components/sh-word/index.vue'
27
25
 
28
26
  const components = {
29
27
  ShCard,
@@ -40,7 +38,6 @@ const components = {
40
38
  ShPreview,
41
39
  ShPullRefresh,
42
40
  ShResult,
43
- ShSheet,
44
41
  ShUpload,
45
42
  ShForm,
46
43
  ShList,
@@ -49,8 +46,7 @@ const components = {
49
46
  ShTable,
50
47
  ShToolbar,
51
48
  ShTree,
52
- ShWaterFall,
53
- ShWord
49
+ ShWaterFall
54
50
  }
55
51
 
56
52
  const index = {
@@ -1,173 +0,0 @@
1
- <template>
2
- <div :id="sheetId" ref="shSheet" class="sh-sheet" :style="sheetStyles"></div>
3
- </template>
4
-
5
- <script>
6
- export default {
7
- name: 'ShSheet',
8
- props: {
9
- option: {
10
- type: Object,
11
- default() {
12
- return {}
13
- }
14
- },
15
- title: {
16
- type: String,
17
- default: ''
18
- },
19
- width: {
20
- type: String,
21
- default: '100%'
22
- },
23
- height: {
24
- type: String,
25
- default: '600'
26
- },
27
- disabled: {
28
- type: Boolean
29
- },
30
- readonly: {
31
- type: Boolean
32
- },
33
- url: {
34
- type: String,
35
- default: ''
36
- }
37
- },
38
- data() {
39
- return {}
40
- },
41
- computed: {
42
- sheetId() {
43
- return 'ShSheet' + this._.uid
44
- },
45
- sheetStyles() {
46
- return {
47
- width: this.width,
48
- height: this.height
49
- }
50
- },
51
- sheetOption() {
52
- let { disabled, readonly, sheetId } = this
53
- let isedit = !disabled && !readonly
54
- let defaultOption = {
55
- title: this.title,
56
- lang: 'zh',
57
- // plugins: ['chart'],
58
- allowCopy: true, // 允许复制
59
- showinfobar: isedit,
60
- showtoolbar: isedit, // 工具栏
61
- showtoolbarConfig: {}, // 自定义工具栏
62
- showstatisticBar: true, // 底部计数栏
63
- showstatisticBarConfig: {
64
- count: true, // 计数栏
65
- view: true, // 打印视图
66
- zoom: true // 缩放
67
- }, // 自定义计数栏
68
- showsheetbar: true, // 底部sheet页
69
- showsheetbarConfig: {
70
- add: isedit, // 新增sheet
71
- menu: true, // sheet管理菜单
72
- sheet: true // sheet页显示
73
- }, // 自定义底部sheet页
74
- enableAddRow: isedit, // 允许添加行
75
- enableAddBackTop: true, // 允许回到顶部
76
- cellRightClickConfig: {
77
- copy: false, // 复制
78
- copyAs: false, // 复制为
79
- paste: false, // 粘贴
80
- insertRow: false, // 插入行
81
- insertColumn: false, // 插入列
82
- deleteRow: false, // 删除选中行
83
- deleteColumn: false, // 删除选中列
84
- deleteCell: false, // 删除单元格
85
- hideRow: false, // 隐藏选中行和显示选中行
86
- hideColumn: false, // 隐藏选中列和显示选中列
87
- rowHeight: false, // 行高
88
- columnWidth: false, // 列宽
89
- clear: false, // 清除内容
90
- matrix: false, // 矩阵操作选区
91
- sort: false, // 排序选区
92
- filter: false, // 筛选选区
93
- chart: false, // 图表生成
94
- image: false, // 插入图片
95
- link: false, // 插入链接
96
- data: false, // 数据验证
97
- cellFormat: false // 设置单元格格式
98
- }, // 自定义单元格右键菜单
99
- sheetRightClickConfig: {
100
- delete: false, // 删除
101
- copy: false, // 复制
102
- rename: false, // 重命名
103
- color: false, // 更改颜色
104
- hide: false, // 隐藏,取消隐藏
105
- move: false // 向左移,向右移
106
- }, // 自定义sheet页右击菜单
107
- sheetFormulaBar: isedit, // 是否显示公式栏
108
- defaultFontSize: 14, // 初始化默认字体大小
109
- functionButton: false, // 功能按钮
110
- data: [],
111
- userInfo: ''
112
- }
113
- return Object.assign(defaultOption, this.option, { container: sheetId })
114
- }
115
- },
116
- watch: {
117
- sheetOption: {
118
- handler() {
119
- this.sheetRender()
120
- },
121
- deep: true
122
- },
123
- url: {
124
- handler() {
125
- this.sheetRender()
126
- }
127
- }
128
- },
129
- mounted() {
130
- this.sheetRender()
131
- },
132
- methods: {
133
- async sheetRender() {
134
- const that = this
135
- try {
136
- window.luckysheet.destroy() // 先销毁当前容器
137
- let sheetOption = that.sheetOption
138
- if (that.url) {
139
- let contentJson = await that.getFileContent()
140
- sheetOption.data = contentJson.sheets
141
- sheetOption.title = contentJson.info.name
142
- sheetOption.userInfo = contentJson.info.creator
143
- }
144
- window.luckysheet.create(sheetOption)
145
- } catch (e) {
146
- that.msgerror(`初始化失败:${e.message}`)
147
- }
148
- },
149
- // 获取文件流
150
- async getFileContent() {
151
- return new Promise(async (resolve, reject) => {
152
- let fileRes = await this.$http.request({
153
- methods: 'get',
154
- url: this.url,
155
- responseType: 'blob'
156
- })
157
- window.LuckyExcel.transformExcelToLucky(fileRes, (exportJson, luckysheetfile) => {
158
- if (exportJson.sheets == null || exportJson.sheets.length === 0) {
159
- reject(new Error('读取excel文件内容失败!'))
160
- }
161
- resolve(exportJson)
162
- })
163
- })
164
- }
165
- }
166
- }
167
- </script>
168
-
169
- <style lang="scss" scoped>
170
- .sh-sheet {
171
- position: relative;
172
- }
173
- </style>
@@ -1,106 +0,0 @@
1
- <template>
2
- <div :ref="wordRef" class="sh-word"></div>
3
- </template>
4
-
5
- <script>
6
- import * as docx from 'docx-preview'
7
- export default {
8
- name: 'ShWord',
9
- props: {
10
- option: {
11
- type: Object,
12
- default() {
13
- return {}
14
- }
15
- },
16
- title: {
17
- type: String,
18
- default: ''
19
- },
20
- width: {
21
- type: String,
22
- default: '100%'
23
- },
24
- height: {
25
- type: String,
26
- default: '600'
27
- },
28
- disabled: {
29
- type: Boolean
30
- },
31
- readonly: {
32
- type: Boolean
33
- },
34
- url: {
35
- type: String,
36
- default: ''
37
- }
38
- },
39
- data() {
40
- return {}
41
- },
42
- computed: {
43
- wordRef() {
44
- return 'shWord' + this._.uid
45
- },
46
- wordOption() {
47
- let defaultOption = {
48
- width: this.width,
49
- height: this.height,
50
- className: 'sh-word-wrap', //默认和文档样式类的类名/前缀
51
- inWrapper: true, //启用围绕文档内容呈现包装器
52
- ignoreWidth: true, //禁用页面的渲染宽度
53
- ignoreHeight: false, //禁用页面的渲染高度
54
- ignoreFonts: false, //禁用字体渲染
55
- breakPages: true, //在分页符上启用分页
56
- ignoreLastRenderedPageBreak: true, //在lastRenderedPageBreak元素上禁用分页
57
- experimental: false, //启用实验功能(制表符停止计算)
58
- trimXmlDeclaration: true, //如果为true,则在解析之前将从xml文档中删除xml声明
59
- useBase64URL: false, //如果为true,图像、字体等将转换为base 64 URL,否则使用URL.createObjectURL
60
- useMathMLPolyfill: false, //包括用于铬、边等的MathML多填充。
61
- showChanges: false, //启用文档更改的实验渲染(插入/删除)
62
- debug: false //启用额外的日志记录
63
- }
64
- return Object.assign(defaultOption, this.option)
65
- }
66
- },
67
- watch: {
68
- wordOption: {
69
- handler() {
70
- this.sheetRender()
71
- },
72
- deep: true
73
- },
74
- url: {
75
- handler() {
76
- this.sheetRender()
77
- }
78
- }
79
- },
80
- mounted() {
81
- this.wordRender()
82
- },
83
- methods: {
84
- async wordRender() {
85
- if(!this.url) return
86
- try {
87
- let content = await this.getFileContent()
88
- let res = await docx.renderAsync(content, this.$refs[this.wordRef], null, this.wordOption)
89
- console.log(res)
90
- } catch (e) {
91
- this.msgerror(`初始化失败:${e.message}`)
92
- }
93
- },
94
- // 获取文件流
95
- async getFileContent() {
96
- return this.$http.request({
97
- methods: 'get',
98
- url: this.url,
99
- responseType: 'blob'
100
- })
101
- }
102
- }
103
- }
104
- </script>
105
-
106
- <style lang="scss" scoped></style>