askbot-dragon 1.8.29-beta → 1.8.31-beta

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": "askbot-dragon",
3
- "version": "1.8.29-beta",
3
+ "version": "1.8.31-beta",
4
4
  "scripts": {
5
5
  "serve": "vue-cli-service serve",
6
6
  "build": "vue-cli-service build",
@@ -19,6 +19,7 @@ export default {
19
19
  return{
20
20
  colors: ['#E3EBFF', '#FFF5DC', '#FFE8D8','#D6F3EA','#FFF1C3'],
21
21
  html:"",
22
+ loading:false
22
23
  }
23
24
  },
24
25
  props:{
@@ -55,20 +56,8 @@ export default {
55
56
  }).then(res => {
56
57
  if(res.data) {
57
58
  this.$http.get(res.data).then(res => {
58
- this.html = res.data;
59
- let drawer = document.getElementById('drawer_content_pre')
60
- if (drawer){
61
- drawer.style.backgroundImage = 'none';
62
- drawer.style.overflowX = 'hidden';
63
- }
64
- this.$nextTick(() => {
65
- this.setColor();
66
- setTimeout(() => {
67
- if (this.textWatermarkStr){
68
- newInitWaterMark('docHtml',this.textWatermarkStr)
69
- }
70
- },500)
71
- })})
59
+ this.processImageUrls(res.data);
60
+ })
72
61
  }
73
62
  })
74
63
 
@@ -110,6 +99,118 @@ export default {
110
99
  this.$parent.scrollToParagraph('first')
111
100
  },500)
112
101
  },
102
+ // 处理HTML内容中的图片地址,为OSS图片添加签名
103
+ processImageUrls(htmlContent) {
104
+ // 创建临时DOM元素来解析HTML
105
+ const tempDiv = document.createElement('div');
106
+ tempDiv.innerHTML = htmlContent;
107
+
108
+ // 查找所有图片标签
109
+ const imgTags = tempDiv.querySelectorAll('img');
110
+ let processedCount = 0;
111
+ let totalImages = imgTags.length;
112
+
113
+ if (totalImages === 0) {
114
+ // 没有图片,直接显示内容
115
+ this.html = htmlContent;
116
+ this.loading = false;
117
+ let drawer = document.getElementById('drawer_content_pre')
118
+ if (drawer){
119
+ drawer.style.backgroundImage = 'none';
120
+ drawer.style.overflowX = 'hidden';
121
+ }
122
+ this.$nextTick(() => {
123
+ this.setColor();
124
+ setTimeout(() => {
125
+ if (this.textWatermarkStr){
126
+ newInitWaterMark('docHtml',this.textWatermarkStr)
127
+ }
128
+ },500)
129
+ })
130
+ return;
131
+ }
132
+
133
+ // 处理每个图片地址
134
+ imgTags.forEach((img) => {
135
+ const imgSrc = img.getAttribute('src');
136
+ if (imgSrc && (imgSrc.includes('aliyuncs') || imgSrc.includes('oss-'))) {
137
+ // 为OSS图片获取签名URL
138
+ this.getSignedImageUrl(imgSrc, (signedUrl) => {
139
+ if (signedUrl) {
140
+ img.setAttribute('src', signedUrl);
141
+ }
142
+ processedCount++;
143
+
144
+ // 所有图片处理完成后,更新内容
145
+ if (processedCount === totalImages) {
146
+ this.html = tempDiv.innerHTML;
147
+ this.loading = false;
148
+ let drawer = document.getElementById('drawer_content_pre')
149
+ if (drawer){
150
+ drawer.style.backgroundImage = 'none';
151
+ drawer.style.overflowX = 'hidden';
152
+ }
153
+ this.$nextTick(() => {
154
+ this.setColor();
155
+ setTimeout(() => {
156
+ if (this.textWatermarkStr){
157
+ newInitWaterMark('docHtml',this.textWatermarkStr)
158
+ }
159
+ },500)
160
+ })
161
+ }
162
+ });
163
+ } else {
164
+ // 非OSS图片,直接跳过
165
+ processedCount++;
166
+ if (processedCount === totalImages) {
167
+ this.html = tempDiv.innerHTML;
168
+ this.loading = false;
169
+ let drawer = document.getElementById('drawer_content_pre')
170
+ if (drawer){
171
+ drawer.style.backgroundImage = 'none';
172
+ drawer.style.overflowX = 'hidden';
173
+ }
174
+ this.$nextTick(() => {
175
+ this.setColor();
176
+ setTimeout(() => {
177
+ if (this.textWatermarkStr){
178
+ newInitWaterMark('docHtml',this.textWatermarkStr)
179
+ }
180
+ },500)
181
+ })
182
+ }
183
+ }
184
+ });
185
+ },
186
+
187
+ // 获取图片的签名URL
188
+ getSignedImageUrl(imgSrc, callback) {
189
+ // 检查是否是相对路径,如果是则拼接完整URL
190
+ let fullImgUrl = imgSrc;
191
+ if (imgSrc.startsWith('/') || !imgSrc.startsWith('http')) {
192
+ // 从当前URL中提取域名
193
+ const urlObj = new URL(this.url);
194
+ fullImgUrl = urlObj.origin + (imgSrc.startsWith('/') ? imgSrc : '/' + imgSrc);
195
+ }
196
+
197
+ // 调用获取临时证书的API
198
+ this.$http.post('/knowledge-api/knowledge/getTemporaryCertificate', {
199
+ "fileInOssPath": fullImgUrl
200
+ }, {
201
+ params: { needEncrypt: false }
202
+ }).then(res => {
203
+ if (res.data.code === '0') {
204
+ callback(res.data.data);
205
+ } else {
206
+ console.error('获取图片签名失败:', res.data.message);
207
+ callback(null);
208
+ }
209
+ }).catch(err => {
210
+ console.error('获取图片签名失败:', err);
211
+ callback(null);
212
+ });
213
+ },
113
214
  },
114
215
  watch:{
115
216
  html_result:{
@@ -281,8 +281,11 @@ export default {
281
281
  // 没有图片,直接显示内容
282
282
  this.fileText = htmlContent;
283
283
  this.loading = false;
284
- document.getElementById('drawer_content_pre').style.backgroundImage = 'none';
285
284
  this.$nextTick(() => {
285
+ let dom = document.getElementById('drawer_content_pre');
286
+ if (dom){
287
+ dom.style.backgroundImage = 'none';
288
+ }
286
289
  this.setColor()
287
290
  })
288
291
  this.$emit('loadingSuccess');
@@ -304,8 +307,11 @@ export default {
304
307
  if (processedCount === totalImages) {
305
308
  this.fileText = tempDiv.innerHTML;
306
309
  this.loading = false;
307
- document.getElementById('drawer_content_pre').style.backgroundImage = 'none';
308
310
  this.$nextTick(() => {
311
+ let dom = document.getElementById('drawer_content_pre');
312
+ if (dom){
313
+ dom.style.backgroundImage = 'none';
314
+ }
309
315
  this.setColor()
310
316
  })
311
317
  this.$emit('loadingSuccess');
@@ -317,8 +323,11 @@ export default {
317
323
  if (processedCount === totalImages) {
318
324
  this.fileText = tempDiv.innerHTML;
319
325
  this.loading = false;
320
- document.getElementById('drawer_content_pre').style.backgroundImage = 'none';
321
326
  this.$nextTick(() => {
327
+ let dom = document.getElementById('drawer_content_pre');
328
+ if (dom){
329
+ dom.style.backgroundImage = 'none';
330
+ }
322
331
  this.setColor()
323
332
  })
324
333
  this.$emit('loadingSuccess');