adtec-core-package 3.1.6 → 3.1.7

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.
@@ -3,109 +3,75 @@
3
3
  <!--创建时间: 2024/12/3 上午10:06-->
4
4
  <!--修改时间: 2024/12/3 上午10:06-->
5
5
  <template>
6
- <!-- <el-dialog :title="title" v-model="model" @close="model = false" width="100%">-->
7
6
  <Teleport to="body" v-if="model">
8
7
  <div
9
8
  v-loading="loading"
10
- element-loading-text="下载中,请稍后。。。"
11
- style="
12
- position: absolute;
13
- z-index: 9999;
14
- width: 100%;
15
- height: 100%;
16
- top: 0;
17
- left: 0;
18
- background: rgb(0, 0, 0, 0.5);
19
- text-align: center;
20
- vertical-align: middle;
21
- display: flex;
22
- align-items: center;
23
- justify-content: center;
24
- "
9
+ element-loading-text="加载中,请稍后。。。"
10
+ class="file-view-overlay"
25
11
  >
26
- <el-icon @click="download" style="
27
- position: absolute;
28
- top: 10%;
29
- right: 10%;
30
- font-size: 30px;
31
- color: rgba(0,0,0,0.5);
32
- cursor: pointer;"><Download /></el-icon>
33
- <el-icon
34
- @click="model = false"
35
- style="
36
- position: absolute;
37
- top: 20px;
38
- right: 20px;
39
- font-size: 30px;
40
- color: #f5f5f5;
41
- opacity: 0.6;
42
- cursor: pointer;
43
- "
44
- ><CircleClose
45
- /></el-icon>
46
-
47
-
48
- <DocumentEditor
49
- id="docEditor"
50
- :documentServerUrl="documentServerUrl"
51
- :config="configcomp"
52
- :events_onDocumentReady="onDocumentReady"
53
- :onLoadComponentError="onLoadComponentError"
12
+ <office-preview-toolbar
13
+ v-if="!isHeaderPreview"
14
+ class="file-view-toolbar"
15
+ :zoom="previewScale"
16
+ :show-zoom="false"
17
+ :show-download="!!url"
18
+ :show-close="true"
19
+ :download-loading="loading"
20
+ @download="download"
21
+ @close="model = false"
54
22
  />
23
+
24
+ <div class="office-preview" :class="{ 'has-rich-header': isHeaderPreview }">
25
+ <office-preview
26
+ v-if="url"
27
+ v-model:scale="previewScale"
28
+ :url="url"
29
+ :file-id="fileId"
30
+ :file-name="title"
31
+ :show-header="isHeaderPreview"
32
+ :show-download="!!url"
33
+ :show-close="isHeaderPreview"
34
+ :download-loading="loading"
35
+ @loaded="loading = false"
36
+ @error="loading = false"
37
+ @download="download"
38
+ @close="model = false"
39
+ />
40
+ </div>
55
41
  </div>
56
42
  </Teleport>
57
- <!-- </el-dialog>-->
58
43
  </template>
59
44
  <script setup lang="ts">
60
- import { DocumentEditor } from '@onlyoffice/document-editor-vue'
61
- import { computed, onBeforeMount, onMounted, ref } from 'vue'
62
- import { userInfoStore } from '../../stores/userInfoStore'
45
+ import { computed, ref, watch } from 'vue'
63
46
  import { useVModel } from '@vueuse/core'
64
- import { CircleClose, Download } from '@element-plus/icons-vue'
65
47
  import framework from '../../api/framework'
66
48
  import frameworkUtils from '../../utils/FrameworkUtils'
67
49
  import { toSameOriginFileUrl } from '../../utils/toSameOriginFileUrl'
68
- import { ElIcon } from 'element-plus'
69
- const userinfo = userInfoStore()
70
- const model = defineModel()
71
- const loading=ref(false)
72
- const documentServerUrl = ref('')
73
- const documentServerCallbackUrl = ref('')
74
-
75
50
  import request from '../../utils/AxiosConfig'
51
+ import OfficePreview from './OfficePreview.vue'
52
+ import OfficePreviewToolbar from './OfficePreviewToolbar.vue'
53
+ import {
54
+ isHeaderPreviewFile,
55
+ resolveOfficeFileExt,
56
+ } from '../../utils/officePreviewUtil.ts'
76
57
 
58
+ const model = defineModel()
59
+ const loading = ref(false)
60
+ const previewScale = ref(1)
77
61
 
78
- // 定义Props类型
79
62
  const props = defineProps({
80
- /**
81
- * @default ''
82
- * @description 文件标题
83
- */
84
63
  title: {
85
64
  type: String,
86
65
  default: '',
87
66
  },
88
- /**
89
- * @default ''
90
- * @description 文件Url地址
91
- */
92
67
  url: {
93
68
  type: String,
94
69
  default: '',
95
70
  },
96
- /**
97
- * @default ''
98
- * @description 文件id
99
- */
100
71
  fileId: {
101
72
  type: String,
102
73
  default: '',
103
74
  },
104
- /**
105
- * @type {"view" | "edit"}
106
- * @default ''
107
- * @description 文件id
108
- */
109
75
  edit: {
110
76
  type: String,
111
77
  default: 'view',
@@ -115,105 +81,82 @@ const emit = defineEmits(['update:title', 'update:url', 'update:fileId', 'update
115
81
  const title = useVModel(props, 'title', emit)
116
82
  const fileId = useVModel(props, 'fileId', emit)
117
83
  const url = useVModel(props, 'url', emit)
118
- const edit = useVModel(props, 'edit', emit)
119
84
 
120
- const resolveFileExt = (type?: string, name?: string, fileUrl?: string) => {
121
- const normalizedType = (type || '').toLowerCase().replace(/^\./, '')
122
- if (normalizedType) {
123
- return normalizedType === 'doc' ? 'docx' : normalizedType
124
- }
125
- const fromName = (name || '').match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase()
126
- if (fromName) {
127
- return fromName === 'doc' ? 'docx' : fromName
128
- }
129
- const urlStr = (fileUrl || '').toLowerCase()
130
- if (urlStr.includes('.docx') || urlStr.includes('.doc')) return 'docx'
131
- if (urlStr.includes('.pdf')) return 'pdf'
132
- if (urlStr.includes('.xlsx') || urlStr.includes('.xls')) return 'xlsx'
133
- if (urlStr.includes('.pptx') || urlStr.includes('.ppt')) return 'pptx'
134
- return ''
135
- }
85
+ const isHeaderPreview = computed(() =>
86
+ isHeaderPreviewFile(undefined, title.value, url.value),
87
+ )
136
88
 
137
- const getFileType = () => resolveFileExt(undefined, title.value, url.value)
138
- const getDocumentType = () => {
139
- const ext = getFileType()
140
- if (ext === 'docx' || ext === 'doc') return 'word'
141
- if (ext === 'pdf') return 'pdf'
142
- if (ext === 'xlsx' || ext === 'xls') return 'cell'
143
- if (ext === 'pptx' || ext === 'ppt') return 'slide'
144
- }
145
- const download= async ()=>{
146
- try{
147
- loading.value=true
148
- const data=await framework.getFileAccessAddress(fileId.value)
149
- const res=await request<any>({
89
+ watch(
90
+ [model, url],
91
+ ([visible, fileUrl]) => {
92
+ if (visible && fileUrl) {
93
+ loading.value = true
94
+ previewScale.value = 1
95
+ } else if (!visible) {
96
+ loading.value = false
97
+ previewScale.value = 1
98
+ }
99
+ },
100
+ { immediate: true },
101
+ )
102
+
103
+ const getFileType = () => resolveOfficeFileExt(undefined, title.value, url.value)
104
+
105
+ const download = async () => {
106
+ try {
107
+ loading.value = true
108
+ const data = await framework.getFileAccessAddress(fileId.value)
109
+ const res = await request<any>({
150
110
  url: toSameOriginFileUrl(data.url),
151
111
  method: 'get',
152
112
  responseType: 'blob',
153
113
  })
154
114
  const viewSrc = new Blob([res.data], {
155
- type: 'application/'+getFileType(),
115
+ type: 'application/' + getFileType(),
156
116
  })
157
- var link = document.createElement('a')
117
+ const link = document.createElement('a')
158
118
  link.href = window.URL.createObjectURL(viewSrc)
159
119
  link.download = title.value
160
120
  link.click()
161
- //释放内存
162
121
  window.URL.revokeObjectURL(link.href)
163
-
164
- }catch (err){
122
+ } catch (err) {
165
123
  frameworkUtils.messageError(err)
166
- }finally {
124
+ } finally {
167
125
  loading.value = false
168
126
  }
169
127
  }
170
- const configcomp = computed(() => {
171
- return {
172
- document: {
173
- fileType: getFileType(),
174
- title: title.value,
175
- url: url.value + '',
176
- permissions: {
177
- download: false,
178
- edit: false,
179
- print: false,
180
- },
181
- },
182
- type:"embedded",
183
- documentType: getDocumentType(),
184
- editorConfig: {
185
- callbackUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
186
- lang: 'zh-CN',
187
- customization: {
188
- autosave: false,
189
- zoom: 95,
190
- },
191
- embedded: {
192
- // embedUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
193
- // fullscreenUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
194
- saveUrl: url.value + '',
195
- // shareUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
196
- toolbarDocked: 'top',
197
- },
198
- // customization: {
199
- // autosave: false,
200
- // },
201
- user: {
202
- id: userinfo.getUserInfo.userCode,
203
- name: userinfo.getUserInfo.userName,
204
- },
205
- },
206
- height: '90%',
207
- width: '90%',
208
- }
209
- })
210
- const onDocumentReady = () => {}
211
- const onLoadComponentError = () => {}
212
- onBeforeMount(() => {
213
- const config = JSON.parse(localStorage.getItem('systemConfig') + '')
214
- documentServerUrl.value = config.documentServerUrl
215
- documentServerCallbackUrl.value = config.documentServerCallbackUrl
216
- })
217
- onMounted(() => {})
218
128
  </script>
219
- <style scoped lang="scss"></style>
129
+ <style scoped lang="scss">
130
+ .file-view-overlay {
131
+ position: absolute;
132
+ z-index: 9999;
133
+ width: 100%;
134
+ height: 100%;
135
+ top: 0;
136
+ left: 0;
137
+ background: rgb(0, 0, 0, 0.5);
138
+ display: flex;
139
+ align-items: center;
140
+ justify-content: center;
141
+ }
142
+
143
+ .file-view-toolbar {
144
+ position: absolute;
145
+ top: 20px;
146
+ right: 20px;
147
+ z-index: 10001;
148
+ }
149
+
150
+ .office-preview {
151
+ height: 90%;
152
+ width: 90%;
153
+ overflow: hidden;
154
+ background: #f5f5f5;
155
+ border-radius: 8px;
156
+
157
+ &.has-rich-header {
158
+ display: flex;
159
+ flex-direction: column;
160
+ }
161
+ }
162
+ </style>