space.vue.subassembly.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  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. videoPlaybackSyncTimer: undefined,
  373. }
  374. },
  375. name: "spaceEditor",
  376. model: {
  377. prop: 'htmlContent',
  378. evnet: 'click'
  379. },
  380. /**
  381. * htmlContent: v-model 绑定的值,非空,html 字符串
  382. * size: 编辑器的大小,small、medium、large
  383. * width: 编辑器的宽度,可空
  384. * height: 编辑器的高度,可空
  385. * placeholder:占位符
  386. * type:编辑器工具栏类型
  387. * isfullscreen:是否有全屏,
  388. */
  389. props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl'],
  390. computed: {
  391. previewFrameStyle: function () {
  392. var widthMap = {
  393. pc: '1200px',
  394. pad: '768px',
  395. mobile: '390px'
  396. };
  397. return {
  398. width: widthMap[this.previewMode] || widthMap.pc,
  399. height: '680px'
  400. };
  401. }
  402. },
  403. watch: {
  404. height: function (newVal, oldVal) {
  405. if (this.height && this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  406. this.height += 'px';
  407. } else {
  408. this.setEditorHeight();
  409. }
  410. },
  411. editor: function (newVal, oldVal) {
  412. this.setEditorHeight();
  413. },
  414. jsUrlFlag: function (newVal, oldVal) {
  415. if (this.jsUrl.length > 0 && this.jsUrl.length == this.jsUrlFlag.length) {
  416. if (this.jsUrlFlag.indexOf('false') != -1) {
  417. return;
  418. }
  419. this.initEditor();
  420. this.notLoadEditor = false;
  421. this.setEditorHeight();
  422. }
  423. },
  424. notLoadEditor: function (newVal, oldVal) {
  425. this.setEditorHeight();
  426. },
  427. },
  428. created: function () {
  429. var _this = this;
  430. for (var i = 0; i < _this.jsUrl.length; i++) {
  431. _this.loadJS(_this.jsUrl[i], function () {
  432. _this.jsUrlFlag.push('true');
  433. });
  434. }
  435. },
  436. methods: {
  437. loadJS: function (url, callback) {
  438. for (var i = 0; i < document.getElementsByTagName('head')[0].getElementsByTagName('script').length; i++) {
  439. var src = document.getElementsByTagName('head')[0].getElementsByTagName('script')[i].getAttribute('src');
  440. if (url == src) {
  441. // 防止一个页面有多个编辑器时,编辑器加载失败
  442. if (space.vars.editorReady != true) {
  443. var winInterval = setInterval(function () {
  444. if (space.vars.editorReady != true) {
  445. return;
  446. }
  447. window.clearInterval(winInterval);
  448. if (callback) {
  449. callback();
  450. }
  451. }, 100)
  452. }
  453. return;
  454. }
  455. }
  456. var script = document.createElement('script');
  457. script.type = 'text/javascript';
  458. script.onload = function () {
  459. if (callback) {
  460. callback();
  461. }
  462. };
  463. script.src = url;
  464. document.getElementsByTagName('head')[0].appendChild(script);
  465. },
  466. isArticlePreview: function () {
  467. return this.articlepreview === true || this.articlepreview === 'true';
  468. },
  469. showEditorTools: function () {
  470. return this.type != 'flow' && this.isArticlePreview();
  471. },
  472. getUploadOptions: function () {
  473. return {
  474. imageQuality: this.imageQuality,
  475. imageMaxWidth: 1920,
  476. imageMaxSize: 20 * 1024 * 1024,
  477. videoMaxSize: 1024 * 1024 * 1024,
  478. fileMaxSize: 10 * 1024 * 1024
  479. };
  480. },
  481. myCustomUploadAdapterPlugin: function (editor) {
  482. this.installUploadAdapter(editor);
  483. },
  484. installUploadAdapter: function (editor) {
  485. var _this = this;
  486. editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
  487. // 第二个参数设置上传图片的地址
  488. return new MyUploadAdapter(loader, _this.getUploadOptions());
  489. };
  490. },
  491. uploadPlainFileByAdapter: function (file, options, onProgress) {
  492. if (typeof MyUploadAdapter == "undefined") {
  493. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  494. }
  495. if (typeof MyUploadAdapter.uploadPlainFile == "function") {
  496. return MyUploadAdapter.uploadPlainFile(file, options, onProgress);
  497. }
  498. var adapter = new MyUploadAdapter(null, options || {});
  499. if (typeof adapter.uploadPlainFile == "function") {
  500. return adapter.uploadPlainFile(file, onProgress);
  501. }
  502. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  503. },
  504. /**
  505. * 获取高度
  506. */
  507. getHeight: function () {
  508. if (!this.height) {
  509. if (this.size == undefined || this.size == "small") {
  510. return '200px';
  511. } else if (this.size == "medium") {
  512. return '400px';
  513. } else if (this.size == "large") {
  514. return '600px';
  515. }
  516. } else if (this.height) {
  517. if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  518. return this.height + 'px';
  519. } else {
  520. return this.height;
  521. }
  522. }
  523. return "";
  524. },
  525. /**
  526. * 设置编辑器高度
  527. */
  528. setEditorHeight: function () {
  529. if (this.notLoadEditor) {
  530. return;
  531. }
  532. var height = this.getHeight();
  533. if (!this.editor || !height) {
  534. return;
  535. }
  536. var _this = this;
  537. // 设置编辑器高度
  538. _this.editor.editing.view.change(writer => {
  539. writer.setStyle(
  540. "height",
  541. height,
  542. _this.editor.editing.view.document.getRoot()
  543. );
  544. });
  545. },
  546. /**
  547. * 获取工具栏
  548. */
  549. getToolbar: function () {
  550. var items = [];
  551. // 是否有全屏工具
  552. if (this.isfullscreen == false) {
  553. // 没有全屏工具栏
  554. items = [
  555. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  556. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo'
  557. ];
  558. } else {
  559. items = [
  560. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  561. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo', 'fullScreen'
  562. ];
  563. }
  564. var toolbar = {
  565. items: items
  566. };
  567. if (!this.type) {
  568. return toolbar;
  569. }
  570. var map = new Map();
  571. map.set("flow", ['phrase']);
  572. if (map.get(this.type)) {
  573. return {
  574. items: map.get(this.type)
  575. }
  576. }
  577. return toolbar;
  578. },
  579. alignFullScreenToolbarButton: function () {
  580. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  581. return;
  582. }
  583. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  584. if (!toolbarItems) {
  585. return;
  586. }
  587. var buttons = toolbarItems.querySelectorAll(".ck-button");
  588. for (var i = 0; i < buttons.length; i++) {
  589. var label = (buttons[i].getAttribute("aria-label") || buttons[i].getAttribute("title") || buttons[i].textContent || "").replace(/\s/g, "");
  590. if (label.indexOf("全屏") != -1) {
  591. buttons[i].style.marginLeft = "auto";
  592. toolbarItems.appendChild(buttons[i]);
  593. return;
  594. }
  595. }
  596. },
  597. mountVideoUploadToolbarButton: function (retryCount) {
  598. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  599. return;
  600. }
  601. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  602. if (!toolbarItems) {
  603. return;
  604. }
  605. if (toolbarItems.querySelector(".space-editor-video-upload-ck-button")) {
  606. return;
  607. }
  608. var dropdowns = toolbarItems.querySelectorAll(".ck-dropdown");
  609. var mediaDropdown = null;
  610. for (var i = 0; i < dropdowns.length; i++) {
  611. var button = dropdowns[i].querySelector(".ck-button");
  612. var label = button ? (button.getAttribute("aria-label") || button.getAttribute("title") || button.textContent || "") : "";
  613. label = label.replace(/\s/g, "").toLowerCase();
  614. if (label.indexOf("媒体") != -1 || label.indexOf("media") != -1) {
  615. mediaDropdown = dropdowns[i];
  616. break;
  617. }
  618. }
  619. if (!mediaDropdown) {
  620. if ((retryCount || 0) < 3) {
  621. var _this = this;
  622. setTimeout(function () {
  623. _this.mountVideoUploadToolbarButton((retryCount || 0) + 1);
  624. }, 200);
  625. }
  626. return;
  627. }
  628. var _this = this;
  629. var videoButton = document.createElement("button");
  630. videoButton.type = "button";
  631. videoButton.className = "ck ck-button ck-off space-editor-video-upload-ck-button";
  632. videoButton.setAttribute("aria-label", "上传视频");
  633. videoButton.setAttribute("title", "上传视频");
  634. 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>';
  635. videoButton.addEventListener("click", function (event) {
  636. event.preventDefault();
  637. event.stopPropagation();
  638. _this.openVideoPicker();
  639. });
  640. mediaDropdown.classList.add("space-editor-media-link-dropdown");
  641. mediaDropdown.parentNode.insertBefore(videoButton, mediaDropdown);
  642. },
  643. formatContent: function () {
  644. if (!this.editor) {
  645. return;
  646. }
  647. var html = this.editor.getData();
  648. if (space.utils.isNull(html)) {
  649. space.message.warning("正文内容为空");
  650. return;
  651. }
  652. var wrapper = document.createElement("div");
  653. wrapper.innerHTML = html;
  654. var all = wrapper.querySelectorAll("*");
  655. for (var i = 0; i < all.length; i++) {
  656. var node = all[i];
  657. node.removeAttribute("lang");
  658. node.removeAttribute("width");
  659. node.removeAttribute("height");
  660. node.removeAttribute("onload");
  661. node.removeAttribute("border");
  662. node.removeAttribute("vspace");
  663. node.removeAttribute("hspace");
  664. var style = node.getAttribute("style") || "";
  665. if (/mso-|font-family|text-indent:\s*0|background:\s*transparent/i.test(style)) {
  666. node.removeAttribute("style");
  667. }
  668. }
  669. var inlineNodes = wrapper.querySelectorAll("span, font");
  670. for (var s = inlineNodes.length - 1; s >= 0; s--) {
  671. var inlineNode = inlineNodes[s];
  672. if (inlineNode.attributes.length == 0 && inlineNode.parentNode) {
  673. while (inlineNode.firstChild) {
  674. inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
  675. }
  676. inlineNode.parentNode.removeChild(inlineNode);
  677. }
  678. }
  679. var emptyBlocks = wrapper.querySelectorAll("p, div");
  680. for (var e = emptyBlocks.length - 1; e >= 0; e--) {
  681. var block = emptyBlocks[e];
  682. var hasMedia = block.querySelector("img, video, iframe, table");
  683. var text = (block.textContent || "").replace(/\u00a0/g, "").trim();
  684. if (!hasMedia && text == "" && block.parentNode) {
  685. block.parentNode.removeChild(block);
  686. }
  687. }
  688. var headings = wrapper.querySelectorAll("h1, h2, h3, h4, h5, h6");
  689. for (var headingIndex = 0; headingIndex < headings.length; headingIndex++) {
  690. headings[headingIndex].style.textAlign = "center";
  691. headings[headingIndex].style.textIndent = "0";
  692. }
  693. var findFirstTextNode = function (node) {
  694. for (var child = node.firstChild; child; child = child.nextSibling) {
  695. if (child.nodeType == 3 && child.nodeValue.replace(/[\s\u00a0\u3000]/g, "") != "") {
  696. return child;
  697. }
  698. if (child.nodeType == 1 && !/^(img|video|iframe|table)$/i.test(child.tagName)) {
  699. var textNode = findFirstTextNode(child);
  700. if (textNode) {
  701. return textNode;
  702. }
  703. }
  704. }
  705. return null;
  706. };
  707. var trimFirstTextIndent = function (node) {
  708. var textNode = findFirstTextNode(node);
  709. if (textNode) {
  710. textNode.nodeValue = textNode.nodeValue.replace(/^[\s\u00a0\u3000]+/, "");
  711. }
  712. };
  713. var textBlocks = wrapper.querySelectorAll("p, div");
  714. for (var blockIndex = 0; blockIndex < textBlocks.length; blockIndex++) {
  715. var textBlock = textBlocks[blockIndex];
  716. var blockHasMedia = textBlock.querySelector("img, video, iframe, table");
  717. var blockText = (textBlock.textContent || "").replace(/\u00a0/g, "").trim();
  718. if (blockHasMedia) {
  719. textBlock.style.textAlign = "center";
  720. textBlock.style.textIndent = "0";
  721. } else if (blockText != "") {
  722. textBlock.style.textAlign = "justify";
  723. textBlock.style.textIndent = "2em";
  724. textBlock.style.lineHeight = "1.8";
  725. trimFirstTextIndent(textBlock);
  726. }
  727. }
  728. var images = wrapper.querySelectorAll("img");
  729. for (var imgIndex = 0; imgIndex < images.length; imgIndex++) {
  730. images[imgIndex].style.maxWidth = "100%";
  731. images[imgIndex].style.height = "auto";
  732. images[imgIndex].style.display = "block";
  733. images[imgIndex].style.margin = "12px auto";
  734. }
  735. var videos = wrapper.querySelectorAll("video, iframe");
  736. for (var v = 0; v < videos.length; v++) {
  737. videos[v].style.maxWidth = "100%";
  738. if (videos[v].tagName.toLowerCase() == "video") {
  739. videos[v].setAttribute("controls", "controls");
  740. videos[v].setAttribute("playsinline", "playsinline");
  741. videos[v].style.display = "block";
  742. videos[v].style.margin = "12px auto";
  743. }
  744. }
  745. var tables = wrapper.querySelectorAll("table");
  746. for (var t = 0; t < tables.length; t++) {
  747. tables[t].style.width = "100%";
  748. tables[t].style.borderCollapse = "collapse";
  749. }
  750. this.editor.setData(wrapper.innerHTML);
  751. this.$emit("input", this.editor.getData());
  752. this.deferSyncEditorPlayableVideos();
  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. this.deferSyncEditorPlayableVideos();
  764. },
  765. escapeHtmlAttr: function (value) {
  766. return String(value || "").replace(/[&<>"']/g, function (text) {
  767. return {
  768. "&": "&amp;",
  769. "<": "&lt;",
  770. ">": "&gt;",
  771. "\"": "&quot;",
  772. "'": "&#39;"
  773. }[text];
  774. });
  775. },
  776. normalizeLocalUploadUrl: function (url) {
  777. var text = String(url || "").trim().replace(/\\/g, "/");
  778. var match = text.match(/^(?:https?:)?\/\/[^/]*(\/web\/upload\/.*)$/i);
  779. if (match) {
  780. text = match[1];
  781. }
  782. text = text.replace(/^(https?:)\/+(\/web\/upload\/.*)$/i, "$2");
  783. text = text.replace(/(\/web\/upload\/modules)\/+/i, "$1/");
  784. return text;
  785. },
  786. openVideoPicker: function () {
  787. if (this.$refs.videoInput) {
  788. this.$refs.videoInput.click();
  789. }
  790. },
  791. handleVideoSelect: function (event) {
  792. var files = Array.prototype.slice.call(event.target.files || []);
  793. event.target.value = "";
  794. if (files.length > 0) {
  795. this.uploadVideoFile(files[0]);
  796. }
  797. },
  798. uploadVideoFile: function (file) {
  799. if (!file || !file.type || file.type.indexOf("video/") !== 0) {
  800. space.message.warning("请选择视频文件");
  801. return;
  802. }
  803. var _this = this;
  804. _this.uploading = true;
  805. _this.uploadStatus = "正在上传视频";
  806. _this.uploadPlainFileByAdapter(file, {
  807. imageQuality: 'origin'
  808. }, function (loaded, total) {
  809. if (total > 0) {
  810. _this.uploadStatus = "正在上传视频 " + Math.round(loaded * 100 / total) + "%";
  811. }
  812. }).then(function (res) {
  813. var videoUrl = _this.normalizeLocalUploadUrl(res.default);
  814. _this.insertHtml('<p><video controls playsinline preload="metadata" src="' + _this.escapeHtmlAttr(videoUrl) + '" style="max-width:100%;"></video></p>');
  815. _this.$emit("input", _this.editor.getData());
  816. space.message.success("视频已插入正文");
  817. }).catch(function (msg) {
  818. space.message.error(msg || "视频上传失败");
  819. }).finally(function () {
  820. _this.uploading = false;
  821. _this.uploadStatus = "";
  822. });
  823. },
  824. bindVideoPasteUpload: function () {
  825. if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
  826. return;
  827. }
  828. var editable = this.editor.ui.getEditableElement();
  829. if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
  830. return;
  831. }
  832. editable.setAttribute("data-space-video-upload", "true");
  833. var _this = this;
  834. var handler = function (event) {
  835. var dataTransfer = event.clipboardData || event.dataTransfer;
  836. if (!dataTransfer || !dataTransfer.files || dataTransfer.files.length == 0) {
  837. return;
  838. }
  839. var files = Array.prototype.slice.call(dataTransfer.files);
  840. var videoFile = files.find(function (file) {
  841. return file && file.type && file.type.indexOf("video/") === 0;
  842. });
  843. if (videoFile) {
  844. event.preventDefault();
  845. _this.uploadVideoFile(videoFile);
  846. }
  847. };
  848. editable.addEventListener("paste", handler);
  849. editable.addEventListener("drop", handler);
  850. },
  851. findClosestEditorMedia: function (target) {
  852. if (!target) {
  853. return null;
  854. }
  855. if (target.nodeType == 3) {
  856. target = target.parentNode;
  857. }
  858. if (!target || target.nodeType != 1) {
  859. return null;
  860. }
  861. if (/^(video|iframe)$/i.test(target.tagName)) {
  862. return target;
  863. }
  864. if (target.closest) {
  865. return target.closest("video, iframe");
  866. }
  867. return null;
  868. },
  869. prepareEditorPlayableMedia: function (media) {
  870. if (!media || media.nodeType != 1) {
  871. return;
  872. }
  873. var tagName = (media.tagName || "").toLowerCase();
  874. if (tagName == "video") {
  875. media.setAttribute("controls", "controls");
  876. media.setAttribute("playsinline", "playsinline");
  877. media.setAttribute("webkit-playsinline", "webkit-playsinline");
  878. if (!media.getAttribute("preload")) {
  879. media.setAttribute("preload", "metadata");
  880. }
  881. }
  882. media.classList.add("space-editor-playable-media");
  883. var mediaWidget = media.closest ? media.closest("figure.media") : null;
  884. if (mediaWidget) {
  885. mediaWidget.classList.add("space-editor-playable-media-widget");
  886. }
  887. },
  888. bindPlayableMediaNativeEvents: function (media) {
  889. if (!media || media.getAttribute("data-space-playable-media-bound") == "true") {
  890. return;
  891. }
  892. this.prepareEditorPlayableMedia(media);
  893. media.setAttribute("data-space-playable-media-bound", "true");
  894. var _this = this;
  895. var stopWidgetSelection = function (event) {
  896. _this.prepareEditorPlayableMedia(media);
  897. event.stopPropagation();
  898. };
  899. var eventNames = ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"];
  900. for (var i = 0; i < eventNames.length; i++) {
  901. media.addEventListener(eventNames[i], stopWidgetSelection);
  902. }
  903. },
  904. syncEditorPlayableVideos: function () {
  905. if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
  906. return;
  907. }
  908. var editable = this.editor.ui.getEditableElement();
  909. if (!editable) {
  910. return;
  911. }
  912. var medias = editable.querySelectorAll("video, iframe");
  913. for (var i = 0; i < medias.length; i++) {
  914. this.bindPlayableMediaNativeEvents(medias[i]);
  915. }
  916. },
  917. deferSyncEditorPlayableVideos: function () {
  918. if (this.videoPlaybackSyncTimer) {
  919. window.clearTimeout(this.videoPlaybackSyncTimer);
  920. }
  921. var _this = this;
  922. this.videoPlaybackSyncTimer = window.setTimeout(function () {
  923. _this.syncEditorPlayableVideos();
  924. _this.videoPlaybackSyncTimer = undefined;
  925. }, 0);
  926. },
  927. bindEditorVideoPlayback: function () {
  928. if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
  929. return;
  930. }
  931. var editable = this.editor.ui.getEditableElement();
  932. if (!editable || editable.getAttribute("data-space-playable-media-root") == "true") {
  933. this.syncEditorPlayableVideos();
  934. return;
  935. }
  936. editable.setAttribute("data-space-playable-media-root", "true");
  937. var _this = this;
  938. var stopNativeWidgetSelection = function (event) {
  939. var media = _this.findClosestEditorMedia(event.target);
  940. if (!media) {
  941. return;
  942. }
  943. _this.prepareEditorPlayableMedia(media);
  944. event.stopPropagation();
  945. };
  946. ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
  947. editable.addEventListener(eventName, stopNativeWidgetSelection);
  948. });
  949. if (this.editor.editing && this.editor.editing.view && this.editor.editing.view.document) {
  950. ["mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
  951. _this.editor.editing.view.document.on(eventName, function (evt, data) {
  952. var domTarget = data ? (data.domTarget || (data.domEvent ? data.domEvent.target : null)) : null;
  953. var media = _this.findClosestEditorMedia(domTarget);
  954. if (!media) {
  955. return;
  956. }
  957. _this.prepareEditorPlayableMedia(media);
  958. evt.stop();
  959. }, { priority: "highest" });
  960. });
  961. }
  962. this.syncEditorPlayableVideos();
  963. },
  964. getPreviewPostData: function () {
  965. var data = this.previewdata || {};
  966. return {
  967. title: data.title || '',
  968. source: data.source || '',
  969. navigationid: data.navigationid || '',
  970. desc: data.desc || '',
  971. body: this.editor ? this.editor.getData() : (this.htmlContent || '')
  972. };
  973. },
  974. openArticlePreview: function () {
  975. if (!this.editor) {
  976. return;
  977. }
  978. var postData = this.getPreviewPostData();
  979. if (space.utils.isNull(postData.navigationid)) {
  980. space.message.warning("请先选择发布栏目");
  981. return;
  982. }
  983. if (space.utils.isNull(postData.body)) {
  984. space.message.warning("正文内容为空");
  985. return;
  986. }
  987. var _this = this;
  988. _this.previewLoading = true;
  989. $.ajax({
  990. url: _this.previewurl || "/apps?ark=website.article_preview",
  991. type: "POST",
  992. data: postData,
  993. dataType: "json",
  994. success: function (res) {
  995. if (res.code != "success") {
  996. space.message.error(res.msg || "生成预览失败");
  997. return;
  998. }
  999. var data = res.data || {};
  1000. var baseUrl = data.url || data.previewUrl || "";
  1001. if (space.utils.isNull(baseUrl)) {
  1002. space.message.error("生成预览失败");
  1003. return;
  1004. }
  1005. _this.previewUrl = baseUrl + (baseUrl.indexOf("?") == -1 ? "?" : "&") + "_t=" + new Date().getTime();
  1006. _this.previewVisible = true;
  1007. },
  1008. error: function () {
  1009. space.message.error("生成预览失败");
  1010. },
  1011. complete: function () {
  1012. _this.previewLoading = false;
  1013. }
  1014. });
  1015. },
  1016. setPreviewMode: function (mode) {
  1017. this.previewMode = mode || 'pc';
  1018. },
  1019. /**
  1020. * 初始化编辑器
  1021. */
  1022. initEditor: function () {
  1023. var toolbar = this.getToolbar();
  1024. var _this = this;
  1025. ClassicEditor.create(document.querySelector("#" + _this.id), {
  1026. extraPlugins: [function (editor) {
  1027. _this.installUploadAdapter(editor);
  1028. }], // 添加上传适配器
  1029. toolbar: toolbar || {},
  1030. language: 'zh-cn',
  1031. placeholder: _this.placeholder || '',
  1032. mediaEmbed: {
  1033. previewsInData: true,
  1034. providers: [{
  1035. name: 'spaceVideo',
  1036. url: [
  1037. /\.(mp4|webm|ogg)(\?.*)?$/i
  1038. ],
  1039. html: match => {
  1040. const input = match['input'];
  1041. return (
  1042. `<video controls playsinline preload="metadata" src="${input}" style="max-width:100%;"></video>`
  1043. );
  1044. }
  1045. }, {
  1046. name: 'myprovider',
  1047. url: [
  1048. /^lizzy.*\.com.*\/media\/(\w+)/,
  1049. /^www\.lizzy.*/,
  1050. /^.*/
  1051. ],
  1052. html: match => {
  1053. //获取媒体url
  1054. const input = match['input'];
  1055. return (
  1056. `<iframe src="${input}" allowFullScreen="true" frameborder="0"></iframe>`
  1057. );
  1058. }
  1059. }]
  1060. }
  1061. }).then(editor => {
  1062. space.vars.editorReady = true;
  1063. _this.editor = editor;
  1064. _this.alignFullScreenToolbarButton();
  1065. _this.mountVideoUploadToolbarButton();
  1066. _this.bindVideoPasteUpload();
  1067. _this.bindEditorVideoPlayback();
  1068. if (_this.htmlContent != undefined) {
  1069. _this.editor.setData(_this.htmlContent);
  1070. _this.deferSyncEditorPlayableVideos();
  1071. }
  1072. /**
  1073. * 禁止在编辑器内回车事件
  1074. */
  1075. editor.ui.view.element.onkeydown = function (event) {
  1076. // 回车键
  1077. if (event.keyCode == 13) {
  1078. event.stopPropagation();
  1079. return false;
  1080. }
  1081. // tab 转空格
  1082. if (event.keyCode == 9) {
  1083. const model = editor.model;
  1084. model.change(writer => {
  1085. const ele = writer.createElement('span');
  1086. writer.insertText(" ", ele);
  1087. // 一定要 Element
  1088. model.insertContent(ele);
  1089. });
  1090. event.stopPropagation();
  1091. return false;
  1092. }
  1093. _this.$emit("input", editor.getData());
  1094. };
  1095. // 设置编辑器宽度
  1096. if (_this.width) {
  1097. $(editor.ui.view.element).css({
  1098. 'width': _this.width
  1099. })
  1100. }
  1101. // 监听编辑器的内容变动事件
  1102. editor.model.document.on('change:data', function () {
  1103. _this.$emit("input", editor.getData());
  1104. _this.deferSyncEditorPlayableVideos();
  1105. });
  1106. }).catch(error => {
  1107. console.log(error);
  1108. });
  1109. }
  1110. },
  1111. template: `
  1112. <div class="space-editor-wrap">
  1113. <div class="space-editor-toolstrip" v-if="showEditorTools()">
  1114. <el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
  1115. <span class="space-editor-tool-divider"></span>
  1116. <el-select class="space-editor-quality" v-model="imageQuality" size="small" placeholder="图片质量压缩" title="图片质量压缩">
  1117. <el-option label="原图" value="origin"></el-option>
  1118. <el-option label="高清 85%" value="high"></el-option>
  1119. <el-option label="标准 70%" value="standard"></el-option>
  1120. <el-option label="低流量 50%" value="low"></el-option>
  1121. </el-select>
  1122. <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>
  1123. <span class="space-editor-upload-status" v-if="uploadStatus">{{uploadStatus}}</span>
  1124. </div>
  1125. <input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
  1126. <div :id="id">
  1127. <script type="text/plain"></script>
  1128. </div>
  1129. <el-dialog title="正文预览" :visible.sync="previewVisible" width="calc(100vw - 32px)" top="4vh" append-to-body custom-class="space-editor-preview-dialog">
  1130. <div class="space-editor-preview-toolbar">
  1131. <el-button-group class="space-editor-preview-modes">
  1132. <el-button size="small" :type="previewMode == 'pc' ? 'primary' : 'default'" @click="setPreviewMode('pc')">PC端</el-button>
  1133. <el-button size="small" :type="previewMode == 'pad' ? 'primary' : 'default'" @click="setPreviewMode('pad')">平板端</el-button>
  1134. <el-button size="small" :type="previewMode == 'mobile' ? 'primary' : 'default'" @click="setPreviewMode('mobile')">手机端</el-button>
  1135. </el-button-group>
  1136. <el-button size="small" icon="el-icon-refresh" @click="openArticlePreview" :loading="previewLoading">刷新预览</el-button>
  1137. </div>
  1138. <div class="space-editor-preview-stage">
  1139. <iframe v-if="previewUrl" :key="previewMode + previewUrl" :src="previewUrl" :style="previewFrameStyle" frameborder="0"></iframe>
  1140. </div>
  1141. </el-dialog>
  1142. </div>
  1143. `
  1144. })
  1145. /**
  1146. * CMS
  1147. */
  1148. Vue.component('spaceCms', {
  1149. data: function () {
  1150. return {
  1151. fileCount: 0, // 文件总数
  1152. }
  1153. },
  1154. name: "spaceCms",
  1155. model: {
  1156. prop: 'cmsid',
  1157. evnet: 'click'
  1158. },
  1159. props: {
  1160. // v-model
  1161. cmsid: {
  1162. type: [String],
  1163. required: true
  1164. },
  1165. // 文件类型
  1166. accept: {
  1167. type: String
  1168. },
  1169. // 最大上传数量,默认199
  1170. maxsize: {
  1171. type: [String, Number],
  1172. default: 199
  1173. },
  1174. },
  1175. created: function () {
  1176. this.getCmsFileCount(this.cmsid);
  1177. },
  1178. watch: {
  1179. cmsid: function (newVal, oldVal) {
  1180. this.getCmsFileCount(newVal);
  1181. }
  1182. },
  1183. methods: {
  1184. open: function () {
  1185. var that = this;
  1186. space.plugins.cms.openCMS({
  1187. cmsid: that.cmsid,
  1188. accept: that.accept,
  1189. maxsize: that.maxsize
  1190. }, that.callback);
  1191. },
  1192. callback: function (data, callback2) {
  1193. this.$emit("input", data.cmsid);
  1194. this.cmsid = data.cmsid;
  1195. this.fileCount = data.fileCount;
  1196. callback2();
  1197. },
  1198. getCmsFileCount: function (cmsid) {
  1199. if (space.utils.isNull(cmsid)) {
  1200. return;
  1201. }
  1202. var that = this;
  1203. space.utils.ajax({
  1204. url: '/apps?ark=sys.cms_getCmsInfo',
  1205. data: {
  1206. "idcard": cmsid
  1207. },
  1208. dataType: 'json',
  1209. loadLayer: false,
  1210. autoTip: false,
  1211. async: false, // 同步请求
  1212. callback: function (data) {
  1213. if (data.code == "success") {
  1214. that.fileCount = data.data.filecount;
  1215. }
  1216. }
  1217. });
  1218. }
  1219. },
  1220. template: `<div class="cms-upload">
  1221. <el-badge :value="fileCount" type="primary" v-show="fileCount > 0">
  1222. <el-button icon="el-icon-upload2" @click="open" >上传文件</el-button>
  1223. </el-badge>
  1224. <el-button icon="el-icon-upload2" v-show="fileCount == 0" @click="open" >上传文件</el-button>
  1225. </div>`
  1226. })
  1227. /**
  1228. * CMS预览
  1229. */
  1230. Vue.component('spaceCmsView', {
  1231. data: function () {
  1232. return {
  1233. thumbnail: "",
  1234. filename: "",
  1235. filecount: 0,
  1236. isShowEl: true, //是否显示整个组件元素
  1237. }
  1238. },
  1239. name: "spaceCmsView",
  1240. /**
  1241. * cmsid: 绑定的值,非空
  1242. * thumbnail: 缩略图
  1243. * filename: 文件名
  1244. * filecount: 文件数
  1245. */
  1246. props: {
  1247. cmsid: {
  1248. type: [String, Number],
  1249. required: true
  1250. }
  1251. },
  1252. created: function () {
  1253. var that = this;
  1254. if (space.utils.isNull(that.cmsid)) {
  1255. // 不显示整个组件元素
  1256. that.isShowEl = false;
  1257. return;
  1258. }
  1259. space.utils.ajax({
  1260. url: '/apps?ark=sys.cms_getCmsInfo',
  1261. data: {
  1262. "idcard": that.cmsid
  1263. },
  1264. dataType: 'json',
  1265. loadLayer: false,
  1266. autoTip: false,
  1267. async: false, // 同步请求
  1268. callback: function (data) {
  1269. if (data.code == "success") {
  1270. that.thumbnail = data.data.thumbnail;
  1271. that.filename = data.data.filename;
  1272. that.filecount = data.data.filecount;
  1273. } else if (data.code == "warning") {
  1274. // 不显示整个组件元素
  1275. that.isShowEl = false;
  1276. }
  1277. }
  1278. });
  1279. },
  1280. methods: {
  1281. open: function () {
  1282. var that = this;
  1283. space.plugins.cms.openCMSView({
  1284. cmsid: that.cmsid
  1285. });
  1286. },
  1287. },
  1288. template: `
  1289. <div class="space-cms-view" v-if="isShowEl">
  1290. <div class="space-cms-view-wrap" @click="open">
  1291. <div class="space-cms-view-main">
  1292. <el-image :src="thumbnail">
  1293. <div slot="error" class="image-slot">
  1294. <i class="el-icon-picture-outline"></i>
  1295. </div>
  1296. </el-image>
  1297. <span>{{filename}}</span>
  1298. </div>
  1299. <div v-show="filecount >=2 " class="more-file"></div>
  1300. <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
  1301. </div>
  1302. </div>
  1303. `
  1304. })
  1305. /**
  1306. * 业务流转
  1307. */
  1308. Vue.component('spacePluginFlow', {
  1309. data: function () {
  1310. return {
  1311. isOpenFlowDrawer: false, // 是否打开抽屉
  1312. isLoadShow: true, // 是否显示加载动画
  1313. frameID: space.utils.randomStringAndNumber(6) + 'Frm', // frame 窗口ID
  1314. closeBtnID: space.utils.randomStringAndNumber(6) + 'Close', // 关闭按钮的ID
  1315. url: '/app/flow/time/', // url
  1316. title: '业务流转', // 标题
  1317. closeTitle: '收起', // 关闭按钮文本内容
  1318. }
  1319. },
  1320. name: "spacePluginFlow",
  1321. /**
  1322. * cmsid: 绑定的值,非空
  1323. * size: 抽屉大小,可传px、%,默认30%
  1324. */
  1325. props: {
  1326. audit: {
  1327. type: String,
  1328. required: true
  1329. },
  1330. apply: {
  1331. type: String,
  1332. required: true
  1333. },
  1334. open: {
  1335. type: Boolean,
  1336. },
  1337. size: {
  1338. type: String
  1339. },
  1340. },
  1341. created: function () {
  1342. this.url = this.url + "?auditid=" + this.audit + "&applyid=" + this.apply;
  1343. this.size = space.utils.isNull(this.size) ? '360px' : this.size;
  1344. this.isOpenFlowDrawer = space.utils.isNull(this.open) ? false : this.open;
  1345. this.showLoad();
  1346. },
  1347. mounted: function () {
  1348. var that = this;
  1349. // 监听窗口变化,计算关闭按钮的位置
  1350. window.onresize = function () {
  1351. // 抽屉打开状态
  1352. if (that.isOpenFlowDrawer) {
  1353. that.initCloseBtnLocation();
  1354. }
  1355. }
  1356. },
  1357. methods: {
  1358. /**
  1359. * 计算关闭按钮的坐标
  1360. */
  1361. initCloseBtnLocation: function () {
  1362. var offset = space.utils.getDomPosition(document.getElementById(this.frameID));
  1363. $("#" + this.closeBtnID).css("left", (offset.left - $("#" + this.closeBtnID).width()) + "px");
  1364. },
  1365. /**
  1366. * 显示抽屉
  1367. */
  1368. showDrawer: function () {
  1369. var that = this;
  1370. that.initCloseBtnLocation();
  1371. $("#" + that.closeBtnID).fadeIn(200);
  1372. // 为了更好的动画体验
  1373. setTimeout(() => {
  1374. $("#" + that.closeBtnID).css("z-index", "999999999999999");
  1375. }, 200);
  1376. },
  1377. /**
  1378. * 控制加载动画
  1379. */
  1380. showLoad: function () {
  1381. var that = this;
  1382. var loadInterval = setInterval(() => {
  1383. var frameEle = document.getElementById(that.frameID);
  1384. console.log("loadInterval");
  1385. frameEle.onload = function () {
  1386. window.clearInterval(loadInterval);
  1387. that.isLoadShow = false;
  1388. }
  1389. }, 100);
  1390. }
  1391. },
  1392. watch: {
  1393. isOpenFlowDrawer: function (newVal, oldVal) {
  1394. var that = this;
  1395. // 打开
  1396. if (newVal) {
  1397. var getFrameInterval = setInterval(() => {
  1398. var frameEle = document.getElementById(that.frameID);
  1399. if (!frameEle) {
  1400. return;
  1401. }
  1402. window.clearInterval(getFrameInterval);
  1403. that.showDrawer();
  1404. }, 200);
  1405. }
  1406. // 关闭
  1407. else {
  1408. $("#" + that.closeBtnID).hide();
  1409. $("#" + that.closeBtnID).css("z-index", "");
  1410. }
  1411. },
  1412. open: function (newVal, oldVal) {
  1413. this.isOpenFlowDrawer = space.utils.isNull(newVal) ? false : newVal;
  1414. }
  1415. },
  1416. template: `
  1417. <div class="space-app-plugin">
  1418. <div class="space-app-plugin-open disable-select animate__animated animate__slideInRight" v-show="!isOpenFlowDrawer" @click="isOpenFlowDrawer = true">{{title}}</div>
  1419. <div :id="closeBtnID" class="space-app-plugin-close disable-select animate__animated animate__slideInRight" @click="isOpenFlowDrawer = false">{{closeTitle}}</div>
  1420. <el-drawer :modal="false" :visible.sync="isOpenFlowDrawer" :size="size" :with-header="false" :wrapper-closable="false" >
  1421. <iframe :id="frameID" :src="url"></iframe>
  1422. <div class="space-app-plugin-load" v-show="isLoadShow" ><i class="el-icon-loading" ></i>加载中</div>
  1423. </el-drawer>
  1424. </div>
  1425. `
  1426. })