space.vue.subassembly.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /**
  2. * 图片上传
  3. */
  4. Vue.component('spaceUploadImg', {
  5. data: function () {
  6. return {
  7. id: "spaceUploadImg" + space.utils.random(6),
  8. }
  9. },
  10. name: "spaceUploadImg",
  11. model: {
  12. prop: 'patharry',
  13. evnet: 'click'
  14. },
  15. /**
  16. * patharry: v-model 绑定的值,非空,字符串数组
  17. * type: 上传按钮的风格,可空,缺省值为 button ,可选值为button / img
  18. * width: 图片裁剪的宽度,可空
  19. * height: 图片裁剪的高度,可空
  20. * maxsize: 最大上传的图片数量,可空,缺省值为1
  21. * tip: 提示语,可空
  22. * color: 图片背景,可空,值的类型与css的color值类型一样
  23. * source: 是否可上传原图
  24. */
  25. props: {
  26. patharry: {
  27. type: Array,
  28. required: true
  29. },
  30. type: {
  31. type: String,
  32. default: "button"
  33. },
  34. width: [String, Number],
  35. height: [String, Number],
  36. maxsize: {
  37. type: [String, Number],
  38. default: 1
  39. },
  40. tip: [String, Number],
  41. color: [String, Number],
  42. source: {
  43. type: Boolean,
  44. default: false,
  45. }
  46. },
  47. created: function () {
  48. // 对初始化值进行处理,排除掉空数据
  49. if (!this.patharry) {
  50. this.patharry = [];
  51. }
  52. var newAry = [];
  53. if (typeof this.patharry == "string") {
  54. if (space.utils.notNull(this.patharry)) {
  55. newAry.push(this.patharry);
  56. }
  57. } else {
  58. for (let index = 0; index < this.patharry.length; index++) {
  59. const element = this.patharry[index];
  60. if (space.utils.notNull(element)) {
  61. newAry.push(element);
  62. }
  63. }
  64. }
  65. this.patharry = newAry;
  66. this.$emit("input", newAry);
  67. },
  68. mounted: function () {
  69. var that = this;
  70. space.plugins.cropper.init({
  71. el: $("#" + that.id),
  72. photoSize: { // 裁剪的图片大小,会自动计算裁剪比例
  73. width: that.width,
  74. height: that.height,
  75. source: that.source,
  76. },
  77. show: function (setting) { //打开裁剪框前的回调
  78. setting.photoSize = {
  79. width: that.width,
  80. height: that.height,
  81. source: that.source,
  82. }
  83. },
  84. success: function (path) { // 成功后的回调方法,path为裁剪后的img路径
  85. that.patharry.push(path);
  86. that.$emit("input", that.patharry);
  87. },
  88. });
  89. },
  90. methods: {
  91. uploadClick: function () {
  92. if (this.patharry.length >= this.maxsize) {
  93. space.message.warning("最多上传" + this.maxsize + "张图片");
  94. return false;
  95. }
  96. $("#" + this.id).click();
  97. },
  98. removeCropperImg: function (index) {
  99. this.patharry.splice(index, 1);
  100. space.message.success("图片已删除");
  101. this.$emit("input", this.patharry);
  102. },
  103. },
  104. template: `
  105. <div class="space-upload-img">
  106. <el-button size="small" icon="el-icon-upload" @click="uploadClick" :disabled="patharry.length >= maxsize" v-if="type == 'button' || space.utils.isNull(type)">上传</el-button>
  107. <span v-show="patharry.length >= maxsize" style="color: #C0C4CC;margin-left: 6px;">
  108. 最多上传{{maxsize}}张图片
  109. </span>
  110. <span v-show="tip" style="color: #888;margin-left: 6px;">
  111. {{tip}}
  112. </span>
  113. <input type="file" accept="image/*" :id="id" style="display: none;" />
  114. <div>
  115. <div v-show="patharry" class="cropper-img-content" v-for="(item, index) in patharry" :key="index"">
  116. <el-image class="cropper-img" fit="contain" :style="{'background-color': color}"
  117. :src="item" @click="space.plugins.elPreview.show(item, patharry)">
  118. </el-image>
  119. <i class="el-icon-close" @click="removeCropperImg(index)"></i>
  120. </div>
  121. <div class="uploadButton-img" v-if="type == 'img'" @click="uploadClick" v-show="patharry.length < maxsize">
  122. <i class="el-icon-plus"></i>
  123. </div>
  124. </div>
  125. </div>
  126. `
  127. })
  128. /**
  129. * 图片预览
  130. */
  131. Vue.component('spacePreviewImg', {
  132. data: function () {
  133. return {
  134. newAry: [],
  135. }
  136. },
  137. name: "spacePreviewImg",
  138. /**
  139. * paths: 绑定的值,非空,字符串/数组
  140. * color: 图片背景色,可空,值的类型与css的color值类型一样
  141. */
  142. props: {
  143. paths: {
  144. type: [Array, String],
  145. required: true
  146. },
  147. color: {
  148. type: String,
  149. }
  150. },
  151. created: function () {
  152. // 对初始化值进行处理,排除掉空数据
  153. if (!this.paths) {
  154. this.paths = [];
  155. }
  156. if (typeof this.paths == "string") {
  157. if (space.utils.notNull(this.paths)) {
  158. this.newAry.push(this.paths);
  159. }
  160. } else {
  161. for (let index = 0; index < this.paths.length; index++) {
  162. const element = this.paths[index];
  163. if (space.utils.notNull(element)) {
  164. this.newAry.push(element);
  165. }
  166. }
  167. }
  168. this.$emit("input", this.newAry);
  169. },
  170. mounted: function () {
  171. },
  172. methods: {
  173. },
  174. template: `
  175. <div class="space-preview-img">
  176. <div class="cropper-img-content" v-for="(item, index) in newAry" :key="index">
  177. <el-image class="cropper-img" fit="contain" :style="{'background-color': color}"
  178. :src="item" @click="space.plugins.elPreview.show(item, newAry)">
  179. </el-image>
  180. </div>
  181. </div>
  182. `
  183. })
  184. /**
  185. * 对象选择器
  186. */
  187. Vue.component('spaceSelect', {
  188. data: function () {
  189. return {
  190. id: "spaceSelect" + space.utils.random(6),
  191. randomNum: space.utils.random(6),
  192. options: [],
  193. isOpen: true, // 是否打开
  194. }
  195. },
  196. name: "spaceSelect",
  197. model: {
  198. prop: 'modelAry',
  199. evnet: 'click'
  200. },
  201. /**
  202. * modelAry: 绑定的值,非空,字符串/数组
  203. * predefine: 预定义对象,非空,可选值有person、department、post、role
  204. * datasize: 最多选择的数量,可空,默认值为1
  205. * method:自定义方法
  206. */
  207. props: ['modelAry', "predefine", "datasize", "method"],
  208. watch: {
  209. modelAry: function (newVal, oldVal) {
  210. // 没有打开时,则可以初始化选择数据集合
  211. if (!this.isOpen) {
  212. this.isOpen = true;
  213. this.initSelectedDataList();
  214. } else {
  215. this.isOpen = false;
  216. }
  217. }
  218. },
  219. created: function () {
  220. if (this.predefine && this.method) {
  221. space.message.error('predefine 与 method 不能同时存在');
  222. }
  223. if (!this.isPredefine()) {
  224. if (!this.method) {
  225. space.message.warning('预定义选择器不存在:' + this.predefine);
  226. }
  227. }
  228. },
  229. mounted: function () {
  230. var that = this;
  231. if (!this.method) {
  232. // 初始化选择窗
  233. space.choose[that.predefine].init({
  234. el: $("#choose" + that.predefine + that.randomNum), // 点击弹出选择窗的元素
  235. selectAry: function () {
  236. return that.modelAry;
  237. }, // 已选的数组
  238. selectCountNum: that.datasize || 1, // 最多选择的数量
  239. success: function (param) { // 成功后的回调
  240. that.options = param;
  241. that.modelAry = [];
  242. that.options.forEach(function (item) {
  243. that.modelAry.push(item["id"]);
  244. });
  245. that.$emit("input", that.modelAry);
  246. }
  247. })
  248. }
  249. /* 监听容器高度 */
  250. const erd = elementResizeDetectorMaker();
  251. var eles = $("#" + that.id).find("div.el-input--suffix")[0];
  252. erd.listenTo(eles, element => {
  253. const height = element.offsetHeight;
  254. $("#choose" + that.predefine + that.randomNum).css("height", height);
  255. });
  256. this.initSelectedDataList();
  257. },
  258. methods: {
  259. removeFun: function () {
  260. this.$emit("input", this.modelAry);
  261. },
  262. /**
  263. * 获取最大限制绑定的值
  264. */
  265. getMaxSelectedModelAry: function () {
  266. var tmpAry = [];
  267. var _this = this;
  268. this.options.forEach(function (item) {
  269. tmpAry.push(item["id"]);
  270. });
  271. if (this.datasize == undefined || this.datasize == 1) {
  272. return tmpAry.length > 0 ? [tmpAry[tmpAry.length - 1]] : [];
  273. } else if (this.datasize > 1) {
  274. var selectedAry = [];
  275. tmpAry.forEach(function (item, index) {
  276. if ((index + 1) > _this.datasize) {
  277. return;
  278. }
  279. selectedAry.push(item);
  280. });
  281. return selectedAry;
  282. } else if (this.datasize == '*') {
  283. return tmpAry;
  284. } else {
  285. return [];
  286. }
  287. },
  288. /**
  289. * 是否预定义选择器,false:不是预定义选择器,true:是预定义选择器
  290. */
  291. isPredefine: function () {
  292. if (this.predefine != "person" && this.predefine != "department" && this.predefine != "post" && this.predefine != "role") {
  293. return false; // 不是预定义选择器
  294. } else {
  295. return true; // 预定义选择器
  296. }
  297. },
  298. /**
  299. * 获取预定义的服务
  300. */
  301. getPredefineService: function () {
  302. var map = new Map();
  303. map.set("person", "/apps?ark=personnel.person_getChoolsePersonInfoApi");
  304. map.set("department", "/apps?ark=sys.department_getChoolseDepartmentInfoApi");
  305. map.set("post", "/apps?ark=sys.post_getChoolsePostInfoApi");
  306. map.set("role", "/apps?ark=sys.role_getChoolseRoleInfoApi");
  307. return map.get(this.predefine);
  308. },
  309. /**
  310. * 初始化选择数据集合
  311. */
  312. initSelectedDataList: function () {
  313. if (!this.isPredefine() || this.method) {
  314. return;
  315. }
  316. if (!this.modelAry || this.modelAry.length == 0) {
  317. this.isOpen = false; // 没有数据时,则关闭
  318. return;
  319. }
  320. var url = this.getPredefineService();
  321. var ids = typeof (this.modelAry) == 'string' || typeof (this.modelAry) == 'number' ? this.modelAry : this.modelAry.join(',');
  322. var _this = this;
  323. // 查询选中的列表
  324. space.utils.ajax({
  325. url: url,
  326. data: {
  327. "ids": ids
  328. },
  329. dataType: 'json',
  330. callback: function (data) {
  331. _this.options = data.data;
  332. var tmpAry = _this.getMaxSelectedModelAry();
  333. _this.$emit("input", tmpAry);
  334. }
  335. })
  336. },
  337. },
  338. template: `
  339. <div class="space-select" :id="id" >
  340. <el-select class="choose-obj" v-model="modelAry" multiple placeholder="请选择" :value-key="id" clearable
  341. :popper-append-to-body="false" style="width: calc(100% - 60px);" :disabled="!modelAry.length>0" @remove-tag="removeFun" @clear="removeFun">
  342. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
  343. </el-option>
  344. </el-select>
  345. <el-button type="button" size="medium" class="choose-btn" :id="'choose' + predefine + randomNum" icon="el-icon-search"></el-button>
  346. </div>
  347. `
  348. })
  349. /**
  350. * Editor 编辑器
  351. */
  352. Vue.component('spaceEditor', {
  353. data: function () {
  354. return {
  355. id: "spaceEditor" + space.utils.random(6),
  356. editor: undefined,
  357. // 编辑器需要的 js 文件
  358. jsUrl: [
  359. '/apps/space/plug-in/ckeditor5/build/ckeditor.js',
  360. '/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js?v=2026062712'
  361. ],
  362. // 标识,全部为 true 则代表全部加载完成
  363. jsUrlFlag: [],
  364. notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完
  365. imageQuality: 'standard',
  366. uploading: false,
  367. uploadStatus: '',
  368. previewVisible: false,
  369. previewMode: 'pc',
  370. previewUrl: '',
  371. previewLoading: false,
  372. }
  373. },
  374. name: "spaceEditor",
  375. model: {
  376. prop: 'htmlContent',
  377. evnet: 'click'
  378. },
  379. /**
  380. * htmlContent: v-model 绑定的值,非空,html 字符串
  381. * size: 编辑器的大小,small、medium、large
  382. * width: 编辑器的宽度,可空
  383. * height: 编辑器的高度,可空
  384. * placeholder:占位符
  385. * type:编辑器工具栏类型
  386. * isfullscreen:是否有全屏,
  387. */
  388. props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl'],
  389. computed: {
  390. previewFrameStyle: function () {
  391. var widthMap = {
  392. pc: '1200px',
  393. pad: '768px',
  394. mobile: '390px'
  395. };
  396. return {
  397. width: widthMap[this.previewMode] || widthMap.pc,
  398. height: '680px'
  399. };
  400. }
  401. },
  402. watch: {
  403. height: function (newVal, oldVal) {
  404. if (this.height && this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  405. this.height += 'px';
  406. } else {
  407. this.setEditorHeight();
  408. }
  409. },
  410. editor: function (newVal, oldVal) {
  411. this.setEditorHeight();
  412. },
  413. jsUrlFlag: function (newVal, oldVal) {
  414. if (this.jsUrl.length > 0 && this.jsUrl.length == this.jsUrlFlag.length) {
  415. if (this.jsUrlFlag.indexOf('false') != -1) {
  416. return;
  417. }
  418. this.initEditor();
  419. this.notLoadEditor = false;
  420. this.setEditorHeight();
  421. }
  422. },
  423. notLoadEditor: function (newVal, oldVal) {
  424. this.setEditorHeight();
  425. },
  426. },
  427. created: function () {
  428. var _this = this;
  429. for (var i = 0; i < _this.jsUrl.length; i++) {
  430. _this.loadJS(_this.jsUrl[i], function () {
  431. _this.jsUrlFlag.push('true');
  432. });
  433. }
  434. },
  435. methods: {
  436. loadJS: function (url, callback) {
  437. for (var i = 0; i < document.getElementsByTagName('head')[0].getElementsByTagName('script').length; i++) {
  438. var src = document.getElementsByTagName('head')[0].getElementsByTagName('script')[i].getAttribute('src');
  439. if (url == src) {
  440. // 防止一个页面有多个编辑器时,编辑器加载失败
  441. if (space.vars.editorReady != true) {
  442. var winInterval = setInterval(function () {
  443. if (space.vars.editorReady != true) {
  444. return;
  445. }
  446. window.clearInterval(winInterval);
  447. if (callback) {
  448. callback();
  449. }
  450. }, 100)
  451. }
  452. return;
  453. }
  454. }
  455. var script = document.createElement('script');
  456. script.type = 'text/javascript';
  457. script.onload = function () {
  458. if (callback) {
  459. callback();
  460. }
  461. };
  462. script.src = url;
  463. document.getElementsByTagName('head')[0].appendChild(script);
  464. },
  465. isArticlePreview: function () {
  466. return this.articlepreview === true || this.articlepreview === 'true';
  467. },
  468. showEditorTools: function () {
  469. return this.type != 'flow' && this.isArticlePreview();
  470. },
  471. getUploadOptions: function () {
  472. return {
  473. imageQuality: this.imageQuality,
  474. imageMaxWidth: 1920,
  475. imageMaxSize: 20 * 1024 * 1024,
  476. videoMaxSize: 1024 * 1024 * 1024,
  477. fileMaxSize: 10 * 1024 * 1024
  478. };
  479. },
  480. myCustomUploadAdapterPlugin: function (editor) {
  481. this.installUploadAdapter(editor);
  482. },
  483. installUploadAdapter: function (editor) {
  484. var _this = this;
  485. editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
  486. // 第二个参数设置上传图片的地址
  487. return new MyUploadAdapter(loader, _this.getUploadOptions());
  488. };
  489. },
  490. uploadPlainFileByAdapter: function (file, options, onProgress) {
  491. if (typeof MyUploadAdapter == "undefined") {
  492. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  493. }
  494. if (typeof MyUploadAdapter.uploadPlainFile == "function") {
  495. return MyUploadAdapter.uploadPlainFile(file, options, onProgress);
  496. }
  497. var adapter = new MyUploadAdapter(null, options || {});
  498. if (typeof adapter.uploadPlainFile == "function") {
  499. return adapter.uploadPlainFile(file, onProgress);
  500. }
  501. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  502. },
  503. /**
  504. * 获取高度
  505. */
  506. getHeight: function () {
  507. if (!this.height) {
  508. if (this.size == undefined || this.size == "small") {
  509. return '200px';
  510. } else if (this.size == "medium") {
  511. return '400px';
  512. } else if (this.size == "large") {
  513. return '600px';
  514. }
  515. } else if (this.height) {
  516. if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  517. return this.height + 'px';
  518. } else {
  519. return this.height;
  520. }
  521. }
  522. return "";
  523. },
  524. /**
  525. * 设置编辑器高度
  526. */
  527. setEditorHeight: function () {
  528. if (this.notLoadEditor) {
  529. return;
  530. }
  531. var height = this.getHeight();
  532. if (!this.editor || !height) {
  533. return;
  534. }
  535. var _this = this;
  536. // 设置编辑器高度
  537. _this.editor.editing.view.change(writer => {
  538. writer.setStyle(
  539. "height",
  540. height,
  541. _this.editor.editing.view.document.getRoot()
  542. );
  543. });
  544. },
  545. /**
  546. * 获取工具栏
  547. */
  548. getToolbar: function () {
  549. var items = [];
  550. // 是否有全屏工具
  551. if (this.isfullscreen == false) {
  552. // 没有全屏工具栏
  553. items = [
  554. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  555. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo'
  556. ];
  557. } else {
  558. items = [
  559. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  560. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo', 'fullScreen'
  561. ];
  562. }
  563. var toolbar = {
  564. items: items
  565. };
  566. if (!this.type) {
  567. return toolbar;
  568. }
  569. var map = new Map();
  570. map.set("flow", ['phrase']);
  571. if (map.get(this.type)) {
  572. return {
  573. items: map.get(this.type)
  574. }
  575. }
  576. return toolbar;
  577. },
  578. alignFullScreenToolbarButton: function () {
  579. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  580. return;
  581. }
  582. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  583. if (!toolbarItems) {
  584. return;
  585. }
  586. var buttons = toolbarItems.querySelectorAll(".ck-button");
  587. for (var i = 0; i < buttons.length; i++) {
  588. var label = (buttons[i].getAttribute("aria-label") || buttons[i].getAttribute("title") || buttons[i].textContent || "").replace(/\s/g, "");
  589. if (label.indexOf("全屏") != -1) {
  590. buttons[i].style.marginLeft = "auto";
  591. toolbarItems.appendChild(buttons[i]);
  592. return;
  593. }
  594. }
  595. },
  596. mountVideoUploadToolbarButton: function (retryCount) {
  597. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  598. return;
  599. }
  600. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  601. if (!toolbarItems) {
  602. return;
  603. }
  604. if (toolbarItems.querySelector(".space-editor-video-upload-ck-button")) {
  605. return;
  606. }
  607. var dropdowns = toolbarItems.querySelectorAll(".ck-dropdown");
  608. var mediaDropdown = null;
  609. for (var i = 0; i < dropdowns.length; i++) {
  610. var button = dropdowns[i].querySelector(".ck-button");
  611. var label = button ? (button.getAttribute("aria-label") || button.getAttribute("title") || button.textContent || "") : "";
  612. label = label.replace(/\s/g, "").toLowerCase();
  613. if (label.indexOf("媒体") != -1 || label.indexOf("media") != -1) {
  614. mediaDropdown = dropdowns[i];
  615. break;
  616. }
  617. }
  618. if (!mediaDropdown) {
  619. if ((retryCount || 0) < 3) {
  620. var _this = this;
  621. setTimeout(function () {
  622. _this.mountVideoUploadToolbarButton((retryCount || 0) + 1);
  623. }, 200);
  624. }
  625. return;
  626. }
  627. var _this = this;
  628. var videoButton = document.createElement("button");
  629. videoButton.type = "button";
  630. videoButton.className = "ck ck-button ck-off space-editor-video-upload-ck-button";
  631. videoButton.setAttribute("aria-label", "上传视频");
  632. videoButton.setAttribute("title", "上传视频");
  633. videoButton.innerHTML = '<svg class="ck ck-icon ck-button__icon space-editor-video-upload-icon" viewBox="0 0 20 20" aria-hidden="true"><path d="M3.2 5.4c-.9 0-1.6.7-1.6 1.6v6.2c0 .9.7 1.6 1.6 1.6h8.2c.9 0 1.6-.7 1.6-1.6V7c0-.9-.7-1.6-1.6-1.6H3.2zm.2 1.8h7.8V13H3.4V7.2z"></path><path d="M13.9 8.2l2.9-2c.7-.5 1.6 0 1.6.9v6c0 .8-.9 1.3-1.6.9l-2.9-2V8.2z"></path><path d="M7.6 12.2h1.8V9.3l1.1 1.1 1.2-1.2-3.2-3-3.2 3 1.2 1.2 1.1-1.1v2.9z"></path></svg><span class="ck ck-button__label">上传视频</span>';
  634. videoButton.addEventListener("click", function (event) {
  635. event.preventDefault();
  636. event.stopPropagation();
  637. _this.openVideoPicker();
  638. });
  639. mediaDropdown.classList.add("space-editor-media-link-dropdown");
  640. mediaDropdown.parentNode.insertBefore(videoButton, mediaDropdown);
  641. },
  642. formatContent: function () {
  643. if (!this.editor) {
  644. return;
  645. }
  646. var html = this.editor.getData();
  647. if (space.utils.isNull(html)) {
  648. space.message.warning("正文内容为空");
  649. return;
  650. }
  651. var wrapper = document.createElement("div");
  652. wrapper.innerHTML = html;
  653. var all = wrapper.querySelectorAll("*");
  654. for (var i = 0; i < all.length; i++) {
  655. var node = all[i];
  656. node.removeAttribute("lang");
  657. node.removeAttribute("width");
  658. node.removeAttribute("height");
  659. node.removeAttribute("onload");
  660. node.removeAttribute("border");
  661. node.removeAttribute("vspace");
  662. node.removeAttribute("hspace");
  663. var style = node.getAttribute("style") || "";
  664. if (/mso-|font-family|text-indent:\s*0|background:\s*transparent/i.test(style)) {
  665. node.removeAttribute("style");
  666. }
  667. }
  668. var inlineNodes = wrapper.querySelectorAll("span, font");
  669. for (var s = inlineNodes.length - 1; s >= 0; s--) {
  670. var inlineNode = inlineNodes[s];
  671. if (inlineNode.attributes.length == 0 && inlineNode.parentNode) {
  672. while (inlineNode.firstChild) {
  673. inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
  674. }
  675. inlineNode.parentNode.removeChild(inlineNode);
  676. }
  677. }
  678. var emptyBlocks = wrapper.querySelectorAll("p, div");
  679. for (var e = emptyBlocks.length - 1; e >= 0; e--) {
  680. var block = emptyBlocks[e];
  681. var hasMedia = block.querySelector("img, video, iframe, table");
  682. var text = (block.textContent || "").replace(/\u00a0/g, "").trim();
  683. if (!hasMedia && text == "" && block.parentNode) {
  684. block.parentNode.removeChild(block);
  685. }
  686. }
  687. var headings = wrapper.querySelectorAll("h1, h2, h3, h4, h5, h6");
  688. for (var headingIndex = 0; headingIndex < headings.length; headingIndex++) {
  689. headings[headingIndex].style.textAlign = "center";
  690. headings[headingIndex].style.textIndent = "0";
  691. }
  692. var findFirstTextNode = function (node) {
  693. for (var child = node.firstChild; child; child = child.nextSibling) {
  694. if (child.nodeType == 3 && child.nodeValue.replace(/[\s\u00a0\u3000]/g, "") != "") {
  695. return child;
  696. }
  697. if (child.nodeType == 1 && !/^(img|video|iframe|table)$/i.test(child.tagName)) {
  698. var textNode = findFirstTextNode(child);
  699. if (textNode) {
  700. return textNode;
  701. }
  702. }
  703. }
  704. return null;
  705. };
  706. var addFirstLineIndent = function (node) {
  707. var textNode = findFirstTextNode(node);
  708. if (textNode) {
  709. textNode.nodeValue = "\u3000\u3000" + textNode.nodeValue.replace(/^[\s\u00a0\u3000]+/, "");
  710. } else {
  711. node.insertBefore(document.createTextNode("\u3000\u3000"), node.firstChild);
  712. }
  713. };
  714. var textBlocks = wrapper.querySelectorAll("p, div");
  715. for (var blockIndex = 0; blockIndex < textBlocks.length; blockIndex++) {
  716. var textBlock = textBlocks[blockIndex];
  717. var blockHasMedia = textBlock.querySelector("img, video, iframe, table");
  718. var blockText = (textBlock.textContent || "").replace(/\u00a0/g, "").trim();
  719. if (blockHasMedia) {
  720. textBlock.style.textAlign = "center";
  721. textBlock.style.textIndent = "0";
  722. } else if (blockText != "") {
  723. textBlock.style.textAlign = "justify";
  724. textBlock.style.textIndent = "2em";
  725. textBlock.style.lineHeight = "1.8";
  726. addFirstLineIndent(textBlock);
  727. }
  728. }
  729. var images = wrapper.querySelectorAll("img");
  730. for (var imgIndex = 0; imgIndex < images.length; imgIndex++) {
  731. images[imgIndex].style.maxWidth = "100%";
  732. images[imgIndex].style.height = "auto";
  733. images[imgIndex].style.display = "block";
  734. images[imgIndex].style.margin = "12px auto";
  735. }
  736. var videos = wrapper.querySelectorAll("video, iframe");
  737. for (var v = 0; v < videos.length; v++) {
  738. videos[v].style.maxWidth = "100%";
  739. if (videos[v].tagName.toLowerCase() == "video") {
  740. videos[v].setAttribute("controls", "controls");
  741. videos[v].setAttribute("playsinline", "playsinline");
  742. videos[v].style.display = "block";
  743. videos[v].style.margin = "12px auto";
  744. }
  745. }
  746. var tables = wrapper.querySelectorAll("table");
  747. for (var t = 0; t < tables.length; t++) {
  748. tables[t].style.width = "100%";
  749. tables[t].style.borderCollapse = "collapse";
  750. }
  751. this.editor.setData(wrapper.innerHTML);
  752. this.$emit("input", this.editor.getData());
  753. space.message.success("正文已完成排版整理");
  754. },
  755. insertHtml: function (html) {
  756. if (!this.editor || space.utils.isNull(html)) {
  757. return;
  758. }
  759. var viewFragment = this.editor.data.processor.toView(html);
  760. var modelFragment = this.editor.data.toModel(viewFragment);
  761. this.editor.model.insertContent(modelFragment);
  762. this.$emit("input", this.editor.getData());
  763. },
  764. escapeHtmlAttr: function (value) {
  765. return String(value || "").replace(/[&<>"']/g, function (text) {
  766. return {
  767. "&": "&amp;",
  768. "<": "&lt;",
  769. ">": "&gt;",
  770. "\"": "&quot;",
  771. "'": "&#39;"
  772. }[text];
  773. });
  774. },
  775. normalizeLocalUploadUrl: function (url) {
  776. var text = String(url || "").trim().replace(/\\/g, "/");
  777. var match = text.match(/^(?:https?:)?\/\/[^/]*(\/web\/upload\/.*)$/i);
  778. if (match) {
  779. text = match[1];
  780. }
  781. text = text.replace(/^(https?:)\/+(\/web\/upload\/.*)$/i, "$2");
  782. text = text.replace(/(\/web\/upload\/modules)\/+/i, "$1/");
  783. return text;
  784. },
  785. openVideoPicker: function () {
  786. if (this.$refs.videoInput) {
  787. this.$refs.videoInput.click();
  788. }
  789. },
  790. handleVideoSelect: function (event) {
  791. var files = Array.prototype.slice.call(event.target.files || []);
  792. event.target.value = "";
  793. if (files.length > 0) {
  794. this.uploadVideoFile(files[0]);
  795. }
  796. },
  797. uploadVideoFile: function (file) {
  798. if (!file || !file.type || file.type.indexOf("video/") !== 0) {
  799. space.message.warning("请选择视频文件");
  800. return;
  801. }
  802. var _this = this;
  803. _this.uploading = true;
  804. _this.uploadStatus = "正在上传视频";
  805. _this.uploadPlainFileByAdapter(file, {
  806. imageQuality: 'origin'
  807. }, function (loaded, total) {
  808. if (total > 0) {
  809. _this.uploadStatus = "正在上传视频 " + Math.round(loaded * 100 / total) + "%";
  810. }
  811. }).then(function (res) {
  812. var videoUrl = _this.normalizeLocalUploadUrl(res.default);
  813. _this.insertHtml('<p><video controls playsinline preload="metadata" src="' + _this.escapeHtmlAttr(videoUrl) + '" style="max-width:100%;"></video></p>');
  814. _this.$emit("input", _this.editor.getData());
  815. space.message.success("视频已插入正文");
  816. }).catch(function (msg) {
  817. space.message.error(msg || "视频上传失败");
  818. }).finally(function () {
  819. _this.uploading = false;
  820. _this.uploadStatus = "";
  821. });
  822. },
  823. bindVideoPasteUpload: function () {
  824. if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
  825. return;
  826. }
  827. var editable = this.editor.ui.getEditableElement();
  828. if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
  829. return;
  830. }
  831. editable.setAttribute("data-space-video-upload", "true");
  832. var _this = this;
  833. var handler = function (event) {
  834. var dataTransfer = event.clipboardData || event.dataTransfer;
  835. if (!dataTransfer || !dataTransfer.files || dataTransfer.files.length == 0) {
  836. return;
  837. }
  838. var files = Array.prototype.slice.call(dataTransfer.files);
  839. var videoFile = files.find(function (file) {
  840. return file && file.type && file.type.indexOf("video/") === 0;
  841. });
  842. if (videoFile) {
  843. event.preventDefault();
  844. _this.uploadVideoFile(videoFile);
  845. }
  846. };
  847. editable.addEventListener("paste", handler);
  848. editable.addEventListener("drop", handler);
  849. },
  850. getPreviewPostData: function () {
  851. var data = this.previewdata || {};
  852. return {
  853. title: data.title || '',
  854. source: data.source || '',
  855. navigationid: data.navigationid || '',
  856. desc: data.desc || '',
  857. body: this.editor ? this.editor.getData() : (this.htmlContent || '')
  858. };
  859. },
  860. openArticlePreview: function () {
  861. if (!this.editor) {
  862. return;
  863. }
  864. var postData = this.getPreviewPostData();
  865. if (space.utils.isNull(postData.navigationid)) {
  866. space.message.warning("请先选择发布栏目");
  867. return;
  868. }
  869. if (space.utils.isNull(postData.body)) {
  870. space.message.warning("正文内容为空");
  871. return;
  872. }
  873. var _this = this;
  874. _this.previewLoading = true;
  875. $.ajax({
  876. url: _this.previewurl || "/apps?ark=website.article_preview",
  877. type: "POST",
  878. data: postData,
  879. dataType: "json",
  880. success: function (res) {
  881. if (res.code != "success") {
  882. space.message.error(res.msg || "生成预览失败");
  883. return;
  884. }
  885. var data = res.data || {};
  886. var baseUrl = data.url || data.previewUrl || "";
  887. if (space.utils.isNull(baseUrl)) {
  888. space.message.error("生成预览失败");
  889. return;
  890. }
  891. _this.previewUrl = baseUrl + (baseUrl.indexOf("?") == -1 ? "?" : "&") + "_t=" + new Date().getTime();
  892. _this.previewVisible = true;
  893. },
  894. error: function () {
  895. space.message.error("生成预览失败");
  896. },
  897. complete: function () {
  898. _this.previewLoading = false;
  899. }
  900. });
  901. },
  902. /**
  903. * 初始化编辑器
  904. */
  905. initEditor: function () {
  906. var toolbar = this.getToolbar();
  907. var _this = this;
  908. ClassicEditor.create(document.querySelector("#" + _this.id), {
  909. extraPlugins: [function (editor) {
  910. _this.installUploadAdapter(editor);
  911. }], // 添加上传适配器
  912. toolbar: toolbar || {},
  913. language: 'zh-cn',
  914. placeholder: _this.placeholder || '',
  915. mediaEmbed: {
  916. previewsInData: true,
  917. providers: [{
  918. name: 'spaceVideo',
  919. url: [
  920. /\.(mp4|webm|ogg)(\?.*)?$/i
  921. ],
  922. html: match => {
  923. const input = match['input'];
  924. return (
  925. `<video controls playsinline preload="metadata" src="${input}" style="max-width:100%;"></video>`
  926. );
  927. }
  928. }, {
  929. name: 'myprovider',
  930. url: [
  931. /^lizzy.*\.com.*\/media\/(\w+)/,
  932. /^www\.lizzy.*/,
  933. /^.*/
  934. ],
  935. html: match => {
  936. //获取媒体url
  937. const input = match['input'];
  938. return (
  939. `<iframe src="${input}" allowFullScreen="true" frameborder="0"></iframe>`
  940. );
  941. }
  942. }]
  943. }
  944. }).then(editor => {
  945. space.vars.editorReady = true;
  946. _this.editor = editor;
  947. _this.alignFullScreenToolbarButton();
  948. _this.mountVideoUploadToolbarButton();
  949. _this.bindVideoPasteUpload();
  950. if (_this.htmlContent != undefined) {
  951. _this.editor.setData(_this.htmlContent);
  952. }
  953. /**
  954. * 禁止在编辑器内回车事件
  955. */
  956. editor.ui.view.element.onkeydown = function (event) {
  957. // 回车键
  958. if (event.keyCode == 13) {
  959. event.stopPropagation();
  960. return false;
  961. }
  962. // tab 转空格
  963. if (event.keyCode == 9) {
  964. const model = editor.model;
  965. model.change(writer => {
  966. const ele = writer.createElement('span');
  967. writer.insertText(" ", ele);
  968. // 一定要 Element
  969. model.insertContent(ele);
  970. });
  971. event.stopPropagation();
  972. return false;
  973. }
  974. _this.$emit("input", editor.getData());
  975. };
  976. // 设置编辑器宽度
  977. if (_this.width) {
  978. $(editor.ui.view.element).css({
  979. 'width': _this.width
  980. })
  981. }
  982. // 监听编辑器的内容变动事件
  983. editor.model.document.on('change:data', function () {
  984. _this.$emit("input", editor.getData());
  985. });
  986. }).catch(error => {
  987. console.log(error);
  988. });
  989. }
  990. },
  991. template: `
  992. <div class="space-editor-wrap">
  993. <div class="space-editor-toolstrip" v-if="showEditorTools()">
  994. <el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
  995. <span class="space-editor-tool-divider"></span>
  996. <el-select class="space-editor-quality" v-model="imageQuality" size="small" placeholder="图片质量压缩" title="图片质量压缩">
  997. <el-option label="原图" value="origin"></el-option>
  998. <el-option label="高清 85%" value="high"></el-option>
  999. <el-option label="标准 70%" value="standard"></el-option>
  1000. <el-option label="低流量 50%" value="low"></el-option>
  1001. </el-select>
  1002. <el-button class="space-editor-tool-btn space-editor-preview-btn" size="small" type="primary" plain icon="el-icon-view" @click="openArticlePreview" :loading="previewLoading">三端预览</el-button>
  1003. <span class="space-editor-upload-status" v-if="uploadStatus">{{uploadStatus}}</span>
  1004. </div>
  1005. <input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
  1006. <div :id="id">
  1007. <script type="text/plain"></script>
  1008. </div>
  1009. <el-dialog title="正文预览" :visible.sync="previewVisible" width="90%" top="4vh" append-to-body custom-class="space-editor-preview-dialog">
  1010. <div class="space-editor-preview-toolbar">
  1011. <el-radio-group v-model="previewMode" size="small">
  1012. <el-radio-button label="pc">PC端</el-radio-button>
  1013. <el-radio-button label="pad">平板端</el-radio-button>
  1014. <el-radio-button label="mobile">手机端</el-radio-button>
  1015. </el-radio-group>
  1016. <el-button size="small" icon="el-icon-refresh" @click="openArticlePreview" :loading="previewLoading">刷新预览</el-button>
  1017. </div>
  1018. <div class="space-editor-preview-stage">
  1019. <iframe v-if="previewUrl" :key="previewMode + previewUrl" :src="previewUrl" :style="previewFrameStyle" frameborder="0"></iframe>
  1020. </div>
  1021. </el-dialog>
  1022. </div>
  1023. `
  1024. })
  1025. /**
  1026. * CMS
  1027. */
  1028. Vue.component('spaceCms', {
  1029. data: function () {
  1030. return {
  1031. fileCount: 0, // 文件总数
  1032. }
  1033. },
  1034. name: "spaceCms",
  1035. model: {
  1036. prop: 'cmsid',
  1037. evnet: 'click'
  1038. },
  1039. props: {
  1040. // v-model
  1041. cmsid: {
  1042. type: [String],
  1043. required: true
  1044. },
  1045. // 文件类型
  1046. accept: {
  1047. type: String
  1048. },
  1049. // 最大上传数量,默认199
  1050. maxsize: {
  1051. type: [String, Number],
  1052. default: 199
  1053. },
  1054. },
  1055. created: function () {
  1056. this.getCmsFileCount(this.cmsid);
  1057. },
  1058. watch: {
  1059. cmsid: function (newVal, oldVal) {
  1060. this.getCmsFileCount(newVal);
  1061. }
  1062. },
  1063. methods: {
  1064. open: function () {
  1065. var that = this;
  1066. space.plugins.cms.openCMS({
  1067. cmsid: that.cmsid,
  1068. accept: that.accept,
  1069. maxsize: that.maxsize
  1070. }, that.callback);
  1071. },
  1072. callback: function (data, callback2) {
  1073. this.$emit("input", data.cmsid);
  1074. this.cmsid = data.cmsid;
  1075. this.fileCount = data.fileCount;
  1076. callback2();
  1077. },
  1078. getCmsFileCount: function (cmsid) {
  1079. if (space.utils.isNull(cmsid)) {
  1080. return;
  1081. }
  1082. var that = this;
  1083. space.utils.ajax({
  1084. url: '/apps?ark=sys.cms_getCmsInfo',
  1085. data: {
  1086. "idcard": cmsid
  1087. },
  1088. dataType: 'json',
  1089. loadLayer: false,
  1090. autoTip: false,
  1091. async: false, // 同步请求
  1092. callback: function (data) {
  1093. if (data.code == "success") {
  1094. that.fileCount = data.data.filecount;
  1095. }
  1096. }
  1097. });
  1098. }
  1099. },
  1100. template: `<div class="cms-upload">
  1101. <el-badge :value="fileCount" type="primary" v-show="fileCount > 0">
  1102. <el-button icon="el-icon-upload2" @click="open" >上传文件</el-button>
  1103. </el-badge>
  1104. <el-button icon="el-icon-upload2" v-show="fileCount == 0" @click="open" >上传文件</el-button>
  1105. </div>`
  1106. })
  1107. /**
  1108. * CMS预览
  1109. */
  1110. Vue.component('spaceCmsView', {
  1111. data: function () {
  1112. return {
  1113. thumbnail: "",
  1114. filename: "",
  1115. filecount: 0,
  1116. isShowEl: true, //是否显示整个组件元素
  1117. }
  1118. },
  1119. name: "spaceCmsView",
  1120. /**
  1121. * cmsid: 绑定的值,非空
  1122. * thumbnail: 缩略图
  1123. * filename: 文件名
  1124. * filecount: 文件数
  1125. */
  1126. props: {
  1127. cmsid: {
  1128. type: [String, Number],
  1129. required: true
  1130. }
  1131. },
  1132. created: function () {
  1133. var that = this;
  1134. if (space.utils.isNull(that.cmsid)) {
  1135. // 不显示整个组件元素
  1136. that.isShowEl = false;
  1137. return;
  1138. }
  1139. space.utils.ajax({
  1140. url: '/apps?ark=sys.cms_getCmsInfo',
  1141. data: {
  1142. "idcard": that.cmsid
  1143. },
  1144. dataType: 'json',
  1145. loadLayer: false,
  1146. autoTip: false,
  1147. async: false, // 同步请求
  1148. callback: function (data) {
  1149. if (data.code == "success") {
  1150. that.thumbnail = data.data.thumbnail;
  1151. that.filename = data.data.filename;
  1152. that.filecount = data.data.filecount;
  1153. } else if (data.code == "warning") {
  1154. // 不显示整个组件元素
  1155. that.isShowEl = false;
  1156. }
  1157. }
  1158. });
  1159. },
  1160. methods: {
  1161. open: function () {
  1162. var that = this;
  1163. space.plugins.cms.openCMSView({
  1164. cmsid: that.cmsid
  1165. });
  1166. },
  1167. },
  1168. template: `
  1169. <div class="space-cms-view" v-if="isShowEl">
  1170. <div class="space-cms-view-wrap" @click="open">
  1171. <div class="space-cms-view-main">
  1172. <el-image :src="thumbnail">
  1173. <div slot="error" class="image-slot">
  1174. <i class="el-icon-picture-outline"></i>
  1175. </div>
  1176. </el-image>
  1177. <span>{{filename}}</span>
  1178. </div>
  1179. <div v-show="filecount >=2 " class="more-file"></div>
  1180. <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
  1181. </div>
  1182. </div>
  1183. `
  1184. })
  1185. /**
  1186. * 业务流转
  1187. */
  1188. Vue.component('spacePluginFlow', {
  1189. data: function () {
  1190. return {
  1191. isOpenFlowDrawer: false, // 是否打开抽屉
  1192. isLoadShow: true, // 是否显示加载动画
  1193. frameID: space.utils.randomStringAndNumber(6) + 'Frm', // frame 窗口ID
  1194. closeBtnID: space.utils.randomStringAndNumber(6) + 'Close', // 关闭按钮的ID
  1195. url: '/app/flow/time/', // url
  1196. title: '业务流转', // 标题
  1197. closeTitle: '收起', // 关闭按钮文本内容
  1198. }
  1199. },
  1200. name: "spacePluginFlow",
  1201. /**
  1202. * cmsid: 绑定的值,非空
  1203. * size: 抽屉大小,可传px、%,默认30%
  1204. */
  1205. props: {
  1206. audit: {
  1207. type: String,
  1208. required: true
  1209. },
  1210. apply: {
  1211. type: String,
  1212. required: true
  1213. },
  1214. open: {
  1215. type: Boolean,
  1216. },
  1217. size: {
  1218. type: String
  1219. },
  1220. },
  1221. created: function () {
  1222. this.url = this.url + "?auditid=" + this.audit + "&applyid=" + this.apply;
  1223. this.size = space.utils.isNull(this.size) ? '360px' : this.size;
  1224. this.isOpenFlowDrawer = space.utils.isNull(this.open) ? false : this.open;
  1225. this.showLoad();
  1226. },
  1227. mounted: function () {
  1228. var that = this;
  1229. // 监听窗口变化,计算关闭按钮的位置
  1230. window.onresize = function () {
  1231. // 抽屉打开状态
  1232. if (that.isOpenFlowDrawer) {
  1233. that.initCloseBtnLocation();
  1234. }
  1235. }
  1236. },
  1237. methods: {
  1238. /**
  1239. * 计算关闭按钮的坐标
  1240. */
  1241. initCloseBtnLocation: function () {
  1242. var offset = space.utils.getDomPosition(document.getElementById(this.frameID));
  1243. $("#" + this.closeBtnID).css("left", (offset.left - $("#" + this.closeBtnID).width()) + "px");
  1244. },
  1245. /**
  1246. * 显示抽屉
  1247. */
  1248. showDrawer: function () {
  1249. var that = this;
  1250. that.initCloseBtnLocation();
  1251. $("#" + that.closeBtnID).fadeIn(200);
  1252. // 为了更好的动画体验
  1253. setTimeout(() => {
  1254. $("#" + that.closeBtnID).css("z-index", "999999999999999");
  1255. }, 200);
  1256. },
  1257. /**
  1258. * 控制加载动画
  1259. */
  1260. showLoad: function () {
  1261. var that = this;
  1262. var loadInterval = setInterval(() => {
  1263. var frameEle = document.getElementById(that.frameID);
  1264. console.log("loadInterval");
  1265. frameEle.onload = function () {
  1266. window.clearInterval(loadInterval);
  1267. that.isLoadShow = false;
  1268. }
  1269. }, 100);
  1270. }
  1271. },
  1272. watch: {
  1273. isOpenFlowDrawer: function (newVal, oldVal) {
  1274. var that = this;
  1275. // 打开
  1276. if (newVal) {
  1277. var getFrameInterval = setInterval(() => {
  1278. var frameEle = document.getElementById(that.frameID);
  1279. if (!frameEle) {
  1280. return;
  1281. }
  1282. window.clearInterval(getFrameInterval);
  1283. that.showDrawer();
  1284. }, 200);
  1285. }
  1286. // 关闭
  1287. else {
  1288. $("#" + that.closeBtnID).hide();
  1289. $("#" + that.closeBtnID).css("z-index", "");
  1290. }
  1291. },
  1292. open: function (newVal, oldVal) {
  1293. this.isOpenFlowDrawer = space.utils.isNull(newVal) ? false : newVal;
  1294. }
  1295. },
  1296. template: `
  1297. <div class="space-app-plugin">
  1298. <div class="space-app-plugin-open disable-select animate__animated animate__slideInRight" v-show="!isOpenFlowDrawer" @click="isOpenFlowDrawer = true">{{title}}</div>
  1299. <div :id="closeBtnID" class="space-app-plugin-close disable-select animate__animated animate__slideInRight" @click="isOpenFlowDrawer = false">{{closeTitle}}</div>
  1300. <el-drawer :modal="false" :visible.sync="isOpenFlowDrawer" :size="size" :with-header="false" :wrapper-closable="false" >
  1301. <iframe :id="frameID" :src="url"></iframe>
  1302. <div class="space-app-plugin-load" v-show="isLoadShow" ><i class="el-icon-loading" ></i>加载中</div>
  1303. </el-drawer>
  1304. </div>
  1305. `
  1306. })