adtec-core-package 3.1.5 → 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,108 +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
- import { ElIcon } from 'element-plus'
68
- const userinfo = userInfoStore()
69
- const model = defineModel()
70
- const loading=ref(false)
71
- const documentServerUrl = ref('')
72
- const documentServerCallbackUrl = ref('')
73
-
49
+ import { toSameOriginFileUrl } from '../../utils/toSameOriginFileUrl'
74
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'
75
57
 
58
+ const model = defineModel()
59
+ const loading = ref(false)
60
+ const previewScale = ref(1)
76
61
 
77
- // 定义Props类型
78
62
  const props = defineProps({
79
- /**
80
- * @default ''
81
- * @description 文件标题
82
- */
83
63
  title: {
84
64
  type: String,
85
65
  default: '',
86
66
  },
87
- /**
88
- * @default ''
89
- * @description 文件Url地址
90
- */
91
67
  url: {
92
68
  type: String,
93
69
  default: '',
94
70
  },
95
- /**
96
- * @default ''
97
- * @description 文件id
98
- */
99
71
  fileId: {
100
72
  type: String,
101
73
  default: '',
102
74
  },
103
- /**
104
- * @type {"view" | "edit"}
105
- * @default ''
106
- * @description 文件id
107
- */
108
75
  edit: {
109
76
  type: String,
110
77
  default: 'view',
@@ -114,105 +81,82 @@ const emit = defineEmits(['update:title', 'update:url', 'update:fileId', 'update
114
81
  const title = useVModel(props, 'title', emit)
115
82
  const fileId = useVModel(props, 'fileId', emit)
116
83
  const url = useVModel(props, 'url', emit)
117
- const edit = useVModel(props, 'edit', emit)
118
84
 
119
- const resolveFileExt = (type?: string, name?: string, fileUrl?: string) => {
120
- const normalizedType = (type || '').toLowerCase().replace(/^\./, '')
121
- if (normalizedType) {
122
- return normalizedType === 'doc' ? 'docx' : normalizedType
123
- }
124
- const fromName = (name || '').match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase()
125
- if (fromName) {
126
- return fromName === 'doc' ? 'docx' : fromName
127
- }
128
- const urlStr = (fileUrl || '').toLowerCase()
129
- if (urlStr.includes('.docx') || urlStr.includes('.doc')) return 'docx'
130
- if (urlStr.includes('.pdf')) return 'pdf'
131
- if (urlStr.includes('.xlsx') || urlStr.includes('.xls')) return 'xlsx'
132
- if (urlStr.includes('.pptx') || urlStr.includes('.ppt')) return 'pptx'
133
- return ''
134
- }
85
+ const isHeaderPreview = computed(() =>
86
+ isHeaderPreviewFile(undefined, title.value, url.value),
87
+ )
135
88
 
136
- const getFileType = () => resolveFileExt(undefined, title.value, url.value)
137
- const getDocumentType = () => {
138
- const ext = getFileType()
139
- if (ext === 'docx' || ext === 'doc') return 'word'
140
- if (ext === 'pdf') return 'pdf'
141
- if (ext === 'xlsx' || ext === 'xls') return 'cell'
142
- if (ext === 'pptx' || ext === 'ppt') return 'slide'
143
- }
144
- const download= async ()=>{
145
- try{
146
- loading.value=true
147
- const data=await framework.getFileAccessAddress(fileId.value)
148
- const res=await request<any>({
149
- url: data.url,
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>({
110
+ url: toSameOriginFileUrl(data.url),
150
111
  method: 'get',
151
112
  responseType: 'blob',
152
113
  })
153
114
  const viewSrc = new Blob([res.data], {
154
- type: 'application/'+getFileType(),
115
+ type: 'application/' + getFileType(),
155
116
  })
156
- var link = document.createElement('a')
117
+ const link = document.createElement('a')
157
118
  link.href = window.URL.createObjectURL(viewSrc)
158
119
  link.download = title.value
159
120
  link.click()
160
- //释放内存
161
121
  window.URL.revokeObjectURL(link.href)
162
-
163
- }catch (err){
122
+ } catch (err) {
164
123
  frameworkUtils.messageError(err)
165
- }finally {
124
+ } finally {
166
125
  loading.value = false
167
126
  }
168
127
  }
169
- const configcomp = computed(() => {
170
- return {
171
- document: {
172
- fileType: getFileType(),
173
- title: title.value,
174
- url: url.value + '',
175
- permissions: {
176
- download: false,
177
- edit: false,
178
- print: false,
179
- },
180
- },
181
- type:"embedded",
182
- documentType: getDocumentType(),
183
- editorConfig: {
184
- callbackUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
185
- lang: 'zh-CN',
186
- customization: {
187
- autosave: false,
188
- zoom: 95,
189
- },
190
- embedded: {
191
- // embedUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
192
- // fullscreenUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
193
- saveUrl: url.value + '',
194
- // shareUrl: documentServerCallbackUrl.value + '?fileId=' + fileId.value,
195
- toolbarDocked: 'top',
196
- },
197
- // customization: {
198
- // autosave: false,
199
- // },
200
- user: {
201
- id: userinfo.getUserInfo.userCode,
202
- name: userinfo.getUserInfo.userName,
203
- },
204
- },
205
- height: '90%',
206
- width: '90%',
207
- }
208
- })
209
- const onDocumentReady = () => {}
210
- const onLoadComponentError = () => {}
211
- onBeforeMount(() => {
212
- const config = JSON.parse(localStorage.getItem('systemConfig') + '')
213
- documentServerUrl.value = config.documentServerUrl
214
- documentServerCallbackUrl.value = config.documentServerCallbackUrl
215
- })
216
- onMounted(() => {})
217
128
  </script>
218
- <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>
@@ -19,6 +19,7 @@ import { showImages } from 'vue-img-viewr'
19
19
  import documentApi from '../../api/DocumentApi.ts'
20
20
  import frameworkUtils from '../../utils/FrameworkUtils.ts'
21
21
  import framework from '../../api/framework.ts'
22
+ import { toSameOriginFileUrl } from '../../utils/toSameOriginFileUrl.ts'
22
23
  import FileView from './FileView.vue'
23
24
  import request from '../../utils/AxiosConfig.ts'
24
25
  import { getFileSuffix, isPreviewableSuffix } from '../../utils/uploadAccept.ts'
@@ -33,7 +34,7 @@ const IMAGE_SUFFIXES = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
33
34
 
34
35
  const downloadFile = async (data: ISysUploadFiles, url: string) => {
35
36
  const res = await request<any>({
36
- url,
37
+ url: toSameOriginFileUrl(url),
37
38
  method: 'get',
38
39
  responseType: 'blob',
39
40
  })