askbot-dragon 1.6.18-beta → 1.6.20-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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="pdf_view" ref="pdfView" @scroll="pdfScroll" :style="{
2
+ <div class="pdf_view" id="pdf_view" :style="{
3
3
  marginTop: isPC ? '50px' : '',
4
4
  marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
5
  height: setHeight
@@ -17,6 +17,7 @@
17
17
  </el-option>
18
18
  </el-select>
19
19
  </div>
20
+ <div class="pdf_container_view" id="pdf_container_view" @scroll="pdfScroll" ref="pdfView"></div>
20
21
  <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
21
22
  <div class="prev" @click="prev">上一段</div>
22
23
  <div class="next" @click="next">下一段</div>
@@ -44,10 +45,11 @@ if (pdfjsLib) {
44
45
  // 'pdfjs-dist/build/pdf.worker';
45
46
  }
46
47
  const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
48
+ const CSS_UNITS = 96.0 / 72.0
47
49
  // import { zoomElement } from '../assets/js/hammer'
48
50
  export default {
49
51
  name: 'pdfView',
50
- props: ['tagIds', 'isMessageRecord'],
52
+ props: ['tagIds', 'isMessageRecord','fileName', "knowledgeItem"],
51
53
  data () {
52
54
  return {
53
55
  url: '',
@@ -94,6 +96,7 @@ export default {
94
96
  },
95
97
  isTouchMoved: false,
96
98
  transformSalce: null,
99
+ defaultTransform:0.8,
97
100
  isPC: false,
98
101
  handScale: 'auto',
99
102
  scaleList: [
@@ -258,6 +261,9 @@ export default {
258
261
  this.contentView.style.paddingBottom = '60px'
259
262
  // contentView.style.overflowY = 'auto'
260
263
  this.$refs.pdfView.appendChild(this.contentView);
264
+ if (this.knowledgeItem && (this.knowledgeItem.source === 'CORP_LOCAL_FILE' || this.knowledgeItem.source === 'YUQUE' || this.knowledgeItem.source === 'FEISHU') && (this.knowledgeItem.visitorWatermarkValue || this.knowledgeItem.textWatermarkValue)){
265
+ this.watermark()
266
+ }
261
267
  }
262
268
  this.renderPages(pageIndex)
263
269
  },
@@ -281,12 +287,12 @@ export default {
281
287
  const { pdfPage, pageNo, dom } = page;
282
288
  // dom 元素已存在,无须重新渲染,直接返回
283
289
  if ((dom && dom.children.length != 0) || page.loading) {
284
- return;
290
+ return;
285
291
  }
286
292
  page.loading = true
287
293
  const viewport = pdfPage.getViewport({
288
- scale: this.scale,
289
- rotation: this.rotation,
294
+ scale: this.scale,
295
+ rotation: this.rotation,
290
296
  });
291
297
  // 创建新的canvas
292
298
  const canvas = document.createElement('canvas');
@@ -377,6 +383,10 @@ export default {
377
383
  page.dom = await pageDom;
378
384
  page.loading = false
379
385
  this.contentView.appendChild(pageDom);
386
+ let pdf_view = document.getElementsByClassName('pdf_view');
387
+ if (pdf_view && pdf_view[0]){
388
+ pdf_view[0].style.backgroundImage = 'none'
389
+ }
380
390
  if (this.transformSalce !== null) {
381
391
  this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
382
392
  }
@@ -443,8 +453,8 @@ export default {
443
453
  startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
444
454
  endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
445
455
  }
446
- for (let pageIndex = startNum; pageIndex < endNum; pageIndex++) {
447
- if (pageIndex > 0 && pageIndex < that.pages.length) {
456
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
457
+ if (pageIndex > 0 && pageIndex <= that.pages.length) {
448
458
  that.loadPdfData(pageIndex)
449
459
  }
450
460
  }
@@ -836,6 +846,164 @@ export default {
836
846
  this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
837
847
  // this.getpdfResloutePage(this.cachePdf[0])
838
848
  },
849
+ //添加水印
850
+ watermark() {
851
+ //默认设置
852
+ var defaultSettings = {
853
+ watermark_txt:"",
854
+ watermark_x: 0,//水印起始位置x轴坐标
855
+ watermark_y: 0,//水印起始位置Y轴坐标
856
+ watermark_rows: 0,//水印行数
857
+ watermark_cols: 0,//水印列数
858
+ watermark_x_space: 40,//水印x轴间隔
859
+ watermark_y_space: 60,//水印y轴间隔
860
+ watermark_color: 'black',//水印字体颜色
861
+ watermark_alpha: .3,//水印透明度
862
+ watermark_fontsize: 12,//水印字体大小
863
+ watermark_font: '微软雅黑',//水印字体
864
+ watermark_width: 100,//水印宽度
865
+ watermark_height: 80,//水印长度
866
+ watermark_angle: 20,//水印倾斜度数***
867
+ visitorWatermark_txt:""
868
+ };
869
+ if(this.knowledgeItem.textWatermarkValue){
870
+ defaultSettings.watermark_txt = this.knowledgeItem.textWatermarkValue;
871
+ }
872
+ if (this.knowledgeItem.visitorWatermarkValue){
873
+ defaultSettings.visitorWatermark_txt = this.knowledgeItem.visitorWatermarkValue
874
+ }
875
+ //采用配置项替换默认值,作用类似jquery.extend
876
+ if (arguments.length === 1 && typeof arguments[0] === "object") {
877
+ console.log("arguments = " + JSON.stringify(arguments[0]));
878
+ // 获取参数配置
879
+ var src = arguments[0];
880
+ for (let key in src) {
881
+ if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key])
882
+ continue;
883
+ else if (src[key])
884
+ defaultSettings[key] = src[key];
885
+ }
886
+ }
887
+ var oTemp = document.createDocumentFragment();
888
+ //获取页面最大宽度
889
+ console.debug('pdf_view',document.getElementById('pdf_view'))
890
+ let scrollWidth = document.getElementById('pdf_view').scrollWidth;
891
+ let clientWidth = document.getElementById('pdf_view').clientWidth;
892
+ var page_width = Math.max(scrollWidth, clientWidth);
893
+
894
+ var cutWidth = page_width * 0.0150;
895
+
896
+ page_width = page_width - cutWidth;
897
+
898
+ //获取页面最大高度
899
+ let height = parseInt(this.totalPageCount * this.pageSize.height)
900
+ var page_height = Math.max(document.getElementById('pdf_container_view').scrollHeight,height);
901
+
902
+ console.debug('page_height',page_height,this.totalPageCount * this.pageSize.height);
903
+
904
+ // var page_height = document.body.scrollHeight+document.body.scrollTop;
905
+
906
+ //如果将水印列数设置为0,或水印列数设置过大,超过页面最大宽度,则重新计算水印列数和水印x轴间隔
907
+
908
+ if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings
909
+ .watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space *
910
+ (defaultSettings.watermark_cols - 1)) > page_width)) {
911
+ defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings
912
+ .watermark_x_space) / (defaultSettings.watermark_width + defaultSettings
913
+ .watermark_x_space));
914
+ defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x -
915
+ defaultSettings
916
+ .watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
917
+ }
918
+
919
+ //如果将水印行数设置为0,或水印行数设置过大,超过页面最大长度,则重新计算水印行数和水印y轴间隔
920
+
921
+ if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings
922
+
923
+ .watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (
924
+
925
+ defaultSettings.watermark_rows - 1)) > page_height)) {
926
+
927
+ defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height -
928
+
929
+ defaultSettings
930
+
931
+ .watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
932
+
933
+ defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) -
934
+
935
+ defaultSettings
936
+
937
+ .watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
938
+
939
+ }
940
+
941
+ var x;
942
+
943
+ var y;
944
+
945
+ for (var i = 0; i < defaultSettings.watermark_rows; i++) {
946
+ y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
947
+ for (var j = 0; j < defaultSettings.watermark_cols; j++) {
948
+ x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;
949
+
950
+ var mask_div = document.createElement('div');
951
+ mask_div.id = 'mask_div' + i + j;
952
+ mask_div.className = 'mask_div';
953
+
954
+ //注意看这里加了图片水印
955
+ mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
956
+ mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
957
+ mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
958
+ mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
959
+ mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
960
+ mask_div.style.visibility = "";
961
+ mask_div.style.position = "absolute";
962
+ //奇偶行错开,这样水印就不对齐,显的不呆板
963
+ console.debug('x',x)
964
+ if (i % 2 != 0) {
965
+ mask_div.style.left = x + 'px';
966
+ if (j % 2 != 0 && this.knowledgeItem.visitorWatermarkValue){
967
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
968
+ } else {
969
+ if (!this.knowledgeItem.textWatermarkValue){
970
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
971
+ } else {
972
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
973
+ }
974
+ }
975
+ } else {
976
+ mask_div.style.left = x + 'px';
977
+ if (j % 2 != 0 && this.knowledgeItem.textWatermarkValue){
978
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
979
+ } else {
980
+ if (!this.knowledgeItem.visitorWatermarkValue){
981
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
982
+ } else {
983
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
984
+ }
985
+ }
986
+ }
987
+
988
+ mask_div.style.top = y + 'px';
989
+ mask_div.style.overflow = "hidden";
990
+ mask_div.style.zIndex = "9999";
991
+ mask_div.style.pointerEvents = 'none'; //让水印不遮挡页面的点击事件
992
+ mask_div.style.opacity = defaultSettings.watermark_alpha;
993
+ mask_div.style.fontSize = defaultSettings.watermark_fontsize;
994
+ mask_div.style.fontFamily = defaultSettings.watermark_font;
995
+ mask_div.style.color = defaultSettings.watermark_color;
996
+ mask_div.style.textAlign = "center";
997
+ mask_div.style.width = defaultSettings.watermark_width + 'px';
998
+ mask_div.style.height = defaultSettings.watermark_height + 'px';
999
+ mask_div.style.display = "block";
1000
+ oTemp.appendChild(mask_div);
1001
+ }
1002
+ }
1003
+ let pageDom = document.getElementById('pdf_container_view')
1004
+ pageDom.appendChild(oTemp);
1005
+
1006
+ },
839
1007
  },
840
1008
  computed: {
841
1009
  perviewUrl () {
@@ -863,8 +1031,11 @@ export default {
863
1031
  if (value && value.length) {
864
1032
  // 在 pdf_view 下创建 所有canvs的容器
865
1033
  this.contentView = document.createElement('div')
1034
+ this.contentView.setAttribute('id','contentView')
866
1035
  this.contentView.style.transformOrigin = '0px 0px 0px'
867
- this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
1036
+ this.contentView.setAttribute('id','contentView');
1037
+
1038
+ this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
868
1039
  // res.data = {"data":[{"id":"64591b7d8bb8ab1b91c65f24","knowledgeId":"64591a9c8da27649473f3b4b","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":3,"total":18,"pageHeight":540.0,"pageWidth":960.00946,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/11/55/18/64591b638bb8ab1b91c65eed/3.pdf","extractInfo":{"location":[280.488,161.32,398.71573,61.99298],"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距北京市区65公里,是以奇而著称,融山川、碧水、古长城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","lines":[{"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距","location":[280.488,161.32,398.71573,15.9869995]},{"content":"北京市区65公里,是以奇而著称,融山川、碧水、古长","location":[283.691,184.30899,392.3055,15.9869995]},{"content":"城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","location":[282.699,207.32599,394.3033,15.9869995]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
869
1040
  // res.data = {"data":[{"id":"64590ce1eb1320043401cc90","knowledgeId":"64590cd5017b461d67e282e1","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":2,"total":5,"pageHeight":841.8898,"pageWidth":595.30396,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/10/53/20/64590ce0eb1320043401cc7b/2.pdf","extractInfo":{"location":[89.32981,638.1907,415.15512,98.63251],"content":":北京地铁 13\r号线 :藤黄\r色 :西直门站—\r东直门站 :17 :41.\r5 :6\r准\rB :2002年\r09月\r28日 ","lines":[{"content":":北京地铁 13\r号线 ","location":[89.32981,638.1907,99.44599,98.63251]},{"content":":藤黄\r色 ","location":[188.7758,638.1907,46.79959,98.63251]},{"content":":西直门站—\r东直门站 ","location":[235.5754,638.1907,86.09996,98.63251]},{"content":":17 ","location":[321.67535,638.1907,36.200012,98.63251]},{"content":":41.\r5 ","location":[357.87537,638.1907,39.400696,98.63251]},{"content":":6\r准\rB ","location":[397.27606,638.1907,41.099,98.63251]},{"content":":2002年\r09月\r28日 ","location":[438.37506,638.1907,66.10986,98.63251]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
870
1041
  // res.data = {"data":[{"id":"64591b7d8bb8ab1b91c65f24","knowledgeId":"64591a9c8da27649473f3b4b","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":3,"total":18,"pageHeight":540.0,"pageWidth":960.00946,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/11/55/18/64591b638bb8ab1b91c65eed/3.pdf","extractInfo":{"location":[280.488,161.32,398.71573,61.99298],"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距北京市区65公里,是以奇而著称,融山川、碧水、古长城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","lines":[{"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距","location":[280.488,161.32,398.71573,15.9869995]},{"content":"北京市区65公里,是以奇而著称,融山川、碧水、古长","location":[283.691,184.30899,392.3055,15.9869995]},{"content":"城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","location":[282.699,207.32599,394.3033,15.9869995]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
@@ -1030,9 +1201,9 @@ export default {
1030
1201
  // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
1031
1202
  // 缓存拿到的所有数据
1032
1203
  this.cachePdf = res.data.data
1033
- let publicPageFileUrl = res.data.data[0].publicPageFileUrl
1204
+ let publicPageFileUrl = res.data.data && res.data.data[0] ? res.data.data[0].publicPageFileUrl : ''
1034
1205
  this.currentPage = 0
1035
- if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
1206
+ if (publicPageFileUrl && publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
1036
1207
  this.preViewType = 'pdf'
1037
1208
  this.setPageAllLine(this.cachePdf)
1038
1209
  this.getpdfResloutePage(res.data.data[0])
@@ -1053,11 +1224,16 @@ export default {
1053
1224
  xhr.onload = ({ currentTarget }) => {
1054
1225
  // 请求完成
1055
1226
  if (currentTarget.status === 200) { // 返回200
1227
+ let pdf_view = document.getElementsByClassName('pdf_view');
1228
+ if (pdf_view && pdf_view[0]){
1229
+ pdf_view[0].style.backgroundImage = 'none'
1230
+ }
1056
1231
  this.contentView.innerHTML = currentTarget.response
1057
1232
  this.contentView.style.padding = '10px'
1058
1233
  // this.contentView.style.position = 'relative'
1059
1234
  this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
1060
1235
  this.$refs.pdfView.appendChild(this.contentView)
1236
+
1061
1237
  let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
1062
1238
  this.allTr = []
1063
1239
  for (let index = 0; index < allTr.length; index++) {
@@ -1100,10 +1276,14 @@ export default {
1100
1276
  width: 100%;
1101
1277
  height: calc(100% - 110px);
1102
1278
  overflow: auto;
1279
+ //overflow-y: scroll;
1103
1280
  background-color: #f5f7fb;
1104
1281
  // margin-bottom: 60px;
1105
1282
  box-sizing: border-box;
1106
-
1283
+ background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
1284
+ background-position: center;
1285
+ background-size: 50px;
1286
+ background-repeat: no-repeat;
1107
1287
  // position: relative;
1108
1288
  // > div {
1109
1289
  // width: 100%;
@@ -1292,6 +1472,12 @@ export default {
1292
1472
  background: rgba(221, 222, 223, 1);
1293
1473
  }
1294
1474
  }
1475
+ .pdf_container_view{
1476
+ height: 100%;
1477
+ width: 100%;
1478
+ position: relative;
1479
+ overflow: auto;
1480
+ }
1295
1481
  }
1296
1482
  </style>
1297
1483
  <style lang="less">
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
  <div id="drawer_content_pre">
56
56
  <template v-if="tagIds && tagIds.length != 0 && drawer">
57
- <pdfPosition :tagIds="tagIds" :isMessageRecord="isMessageRecord"></pdfPosition>
57
+ <pdfPosition :tagIds="tagIds" :isMessageRecord="isMessageRecord" :fileName="fileName" :knowledgeItem="watermark" ref="pdfPosition"></pdfPosition>
58
58
  </template>
59
59
  <template v-else>
60
60
  <div v-if="fileType == 'VIDEO'" style="width: 100%;">
@@ -97,6 +97,7 @@ export default {
97
97
  tagIds: [],
98
98
  // '6454aa1a70573a6ead6f0f7d', '6454aa1a70573a6ead6f0f81',
99
99
  loading:true,
100
+ fileName:''
100
101
  }
101
102
  },
102
103
  mounted() {
@@ -117,6 +118,9 @@ export default {
117
118
  sourceFileType:{
118
119
  type: String,
119
120
  default: '',
121
+ },
122
+ watermark:{
123
+ type: Object
120
124
  }
121
125
  },
122
126
  components:{
@@ -126,9 +130,20 @@ export default {
126
130
  drawer(value) {
127
131
  if(value) {
128
132
  this.$nextTick(() =>{
129
- zoomElement(document.getElementById('drawer_content_pre'))
133
+ if (this.tagIds && this.tagIds.length != 0){
134
+ zoomElement(document.getElementById('pdf_container_view'))
135
+ }
130
136
  })
131
137
  }
138
+ setTimeout(() => {
139
+ let previewIframe = document.getElementsByClassName('preview_iframe')
140
+ Array.from(previewIframe).forEach(item =>{
141
+ item.onload = () =>{
142
+ console.debug('previewIframe 106',previewIframe,this.drawer)
143
+ item.style.backgroundImage = 'none'
144
+ }
145
+ })
146
+ })
132
147
  }
133
148
  },
134
149
  computed:{
@@ -143,8 +158,10 @@ export default {
143
158
  // }
144
159
  // }
145
160
  url = url + this.url
146
- if(this.sourceFileType == '.ppt' || this.sourceFileType == '.pptx') {
147
- url += '&officePreviewType=pdf'
161
+ url += '&officePreviewType=pdf'
162
+ if(this.watermark) {
163
+ url = this.watermark.textWatermarkValue ? (url += '&textWatermarkValue=' + this.watermark.textWatermarkValue) : url
164
+ url = this.watermark.visitorWatermarkValue ? (url += '&visitorWatermarkValue=' + this.watermark.visitorWatermarkValue) : url
148
165
  }
149
166
  return url
150
167
  },
@@ -282,10 +299,6 @@ export default {
282
299
  overflow: auto;
283
300
  height: calc(100% - 50px);
284
301
  background: #FFF;
285
- background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
286
- background-position: center;
287
- background-size: 50px;
288
- background-repeat: no-repeat;
289
302
  }
290
303
  }
291
304
  @media screen and (min-width: 768px) {
@@ -0,0 +1,110 @@
1
+ import Command from "@ckeditor/ckeditor5-core/src/command";
2
+ import { multipartUpload, ossFileUrl } from "../AliyunIssUtil";
3
+ const ossConfig = {
4
+ region: "oss-cn-zhangjiakou",
5
+ //云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用STS方式来进行API访问
6
+ accessKeyId: "LTAI4G3QtdEdwkEbihBngAsK",
7
+ accessKeySecret: "OwgdVfc5PeCkIgqIdug660xmiSPchn",
8
+ // stsToken: '<Your securityToken(STS)>',
9
+ bucket: "guoranopen-zjk",
10
+ }
11
+ export default class ImageCommand extends Command {
12
+ refresh() {
13
+ this.isEnabled = true;
14
+ }
15
+ execute(file) {
16
+ if (file){
17
+ this.forEachFiles(file.file)
18
+ return
19
+ }
20
+ var inputObj = document.createElement('input')
21
+ inputObj.setAttribute('id', '_ef');
22
+ inputObj.setAttribute('type', 'file');
23
+ inputObj.setAttribute('accept','image/jpeg,image/png,image/gif,image/bmp,image/webp,image/tiff')
24
+ inputObj.setAttribute("style", 'visibility:hidden');
25
+ document.body.appendChild(inputObj);
26
+ inputObj.click();
27
+ inputObj.onchange = () => {
28
+ // 循环上传文件
29
+ let files = inputObj.files;
30
+ for (let index = 0; index < files.length; index++) {
31
+ const filed = files[index];
32
+ let command = this.editor.commands.get("insertAskComponent");
33
+ command.execute({
34
+ tag: "span-editable",
35
+ options: {
36
+ name: filed.name + '正在上传...',
37
+ data: index,
38
+ editable:false,
39
+ type:'upload'
40
+ },
41
+ })
42
+ this.upload(filed).then(res =>{
43
+ // let command = this.editor.commands.get("insertAskComponent");
44
+ command.execute({
45
+ tag: "img",
46
+ options: {
47
+ width:'100%',
48
+ alt: filed.name + index,
49
+ src: res.default
50
+ },
51
+ });
52
+ })
53
+ }
54
+ }
55
+ }
56
+ forEachFiles(files){
57
+ for (let index = 0; index < files.length; index++) {
58
+ const filed = files[index];
59
+ let command = this.editor.commands.get("insertAskComponent");
60
+ command.execute({
61
+ tag: "span-editable",
62
+ options: {
63
+ name: filed.name + '正在上传...',
64
+ data: index,
65
+ editable: false,
66
+ type: 'upload'
67
+ },
68
+ })
69
+ this.upload(filed).then(res => {
70
+ // let command = this.editor.commands.get("insertAskComponent");
71
+ command.execute({
72
+ tag: "img",
73
+ options: {
74
+ width: '100%',
75
+ alt: filed.name + index,
76
+ src: res.default
77
+ },
78
+ });
79
+ })
80
+ }
81
+ }
82
+ upload(file) {
83
+ return new Promise((resolve) => {
84
+ /* this._initRequest();
85
+ this._initListeners( resolve, reject, file );
86
+ this._sendRequest( file );*/
87
+ this.uploadFile(file, resolve)
88
+ })
89
+ }
90
+ uploadFile(file, resolve) {
91
+ let imgInfo = {
92
+ url: '',
93
+ }
94
+ let res = multipartUpload(
95
+ ossConfig,
96
+ file,
97
+ null,
98
+ imgInfo
99
+ );
100
+ console.log(res,'resprespresp');
101
+ res.then(resp => {
102
+ imgInfo.url = ossFileUrl(ossConfig, resp.name)
103
+ console.log(resp,'resprespresp');
104
+ console.log(imgInfo)
105
+ resolve({
106
+ default: imgInfo.url
107
+ })
108
+ })
109
+ }
110
+ }
@@ -0,0 +1,12 @@
1
+ import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
2
+ import ImageCommand from "./command";
3
+ export default class MyimageUpload extends Plugin {
4
+ static get pluginName() {
5
+ return "imageUpload";
6
+ }
7
+ init() {
8
+ const editor = this.editor;
9
+ // 注册一个 BoldCommand 命令
10
+ editor.commands.add('imageUpload', new ImageCommand(editor));
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
2
+ import ToolbarUI from './toolbar-ui'
3
+ import ImageUpload from './editing'
4
+
5
+ export default class MyimageUpload extends Plugin {
6
+ static get requires() {
7
+ return [ImageUpload, ToolbarUI];
8
+ }
9
+ static get pluginName() {
10
+ return 'MyimageUpload';
11
+ }
12
+ }
@@ -0,0 +1,41 @@
1
+ /* eslint-disable */
2
+ import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
3
+ import ButtonView from "@ckeditor/ckeditor5-ui/src/button/buttonview";
4
+ // import aoteman from "@ckeditor/ckeditor5-basic-styles/theme/icons/bold.svg";
5
+
6
+ // console.log(aoteman.replace('/',''));
7
+ export default class BoldToolbarUI extends Plugin {
8
+ init() {
9
+ this._createToolbarButton();
10
+ }
11
+
12
+ _createToolbarButton() {
13
+ const editor = this.editor;
14
+ const command = editor.commands.get('imageUpload');
15
+ editor.ui.componentFactory.add('MyimageUpload', (locale) => {
16
+ const view = new ButtonView(locale);
17
+ view.set({
18
+ label: '上传图片',
19
+ tooltip: true,
20
+ withText: true, // 在按钮上展示 label
21
+ // icon:`<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
22
+ // viewBox="0 0 200 200" style="enable-background:new 0 0 200 200;" xml:space="preserve">
23
+ // <path d="M182,4.2H18c-9.9,0-18,8-18,18l0,0v156c0.2,9.7,8.3,17.5,18,17.5h164c9.7,0,17.8-7.8,18-17.5v-156C200,12.3,192,4.2,182,4.2
24
+ // z M152.5,101.2c-3.1-2.3-7.5-2.3-10.6,0l-31.1,26.1L67.9,58.5c-3.4-3.7-8.9-3.9-12.6-0.6c-0.2,0.2-0.3,0.3-0.6,0.6L18,99.3V22.2h164
25
+ // v91.3L152.5,101.2z" fill="#333333"/>
26
+ // <path d="M145.8,38.3c-14,0-25.3,11.3-25.3,25.3s11.3,25.3,25.3,25.3s25.3-11.3,25.3-25.3l0,0C171.1,49.6,159.7,38.3,145.8,38.3z
27
+ // M145.8,70.3c-4,0-7.3-3.2-7.3-7.3s3.2-7.3,7.3-7.3s7.3,3.2,7.3,7.3c0.2,4-2.8,7.4-6.8,7.6c-0.1,0-0.3,0-0.4,0V70.3z" fill="#333333"/>
28
+ // </svg>`,
29
+ class:'icon'
30
+ });
31
+
32
+ // console.log(Template);
33
+ // 将按钮的状态关联到命令对应值上
34
+ view.bind("isOn", "isEnabled").to(command, "value", "isEnabled");
35
+ // 点击按钮时触发相应命令
36
+ this.listenTo(view, "execute", () => editor.execute('imageUpload'));
37
+ return view;
38
+
39
+ })
40
+ }
41
+ }