space.vue.subassembly.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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=2026062706'
  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. };
  476. },
  477. myCustomUploadAdapterPlugin: function (editor) {
  478. this.installUploadAdapter(editor);
  479. },
  480. installUploadAdapter: function (editor) {
  481. var _this = this;
  482. editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
  483. // 第二个参数设置上传图片的地址
  484. return new MyUploadAdapter(loader, _this.getUploadOptions());
  485. };
  486. },
  487. uploadPlainFileByAdapter: function (file, options, onProgress) {
  488. if (typeof MyUploadAdapter == "undefined") {
  489. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  490. }
  491. if (typeof MyUploadAdapter.uploadPlainFile == "function") {
  492. return MyUploadAdapter.uploadPlainFile(file, options, onProgress);
  493. }
  494. var adapter = new MyUploadAdapter(null, options || {});
  495. if (typeof adapter.uploadPlainFile == "function") {
  496. return adapter.uploadPlainFile(file, onProgress);
  497. }
  498. return Promise.reject("上传组件未加载完成,请刷新页面后重试");
  499. },
  500. /**
  501. * 获取高度
  502. */
  503. getHeight: function () {
  504. if (!this.height) {
  505. if (this.size == undefined || this.size == "small") {
  506. return '200px';
  507. } else if (this.size == "medium") {
  508. return '400px';
  509. } else if (this.size == "large") {
  510. return '600px';
  511. }
  512. } else if (this.height) {
  513. if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  514. return this.height + 'px';
  515. } else {
  516. return this.height;
  517. }
  518. }
  519. return "";
  520. },
  521. /**
  522. * 设置编辑器高度
  523. */
  524. setEditorHeight: function () {
  525. if (this.notLoadEditor) {
  526. return;
  527. }
  528. var height = this.getHeight();
  529. if (!this.editor || !height) {
  530. return;
  531. }
  532. var _this = this;
  533. // 设置编辑器高度
  534. _this.editor.editing.view.change(writer => {
  535. writer.setStyle(
  536. "height",
  537. height,
  538. _this.editor.editing.view.document.getRoot()
  539. );
  540. });
  541. },
  542. /**
  543. * 获取工具栏
  544. */
  545. getToolbar: function () {
  546. var items = [];
  547. // 是否有全屏工具
  548. if (this.isfullscreen == false) {
  549. // 没有全屏工具栏
  550. items = [
  551. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  552. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo'
  553. ];
  554. } else {
  555. items = [
  556. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  557. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo', 'fullScreen'
  558. ];
  559. }
  560. var toolbar = {
  561. items: items
  562. };
  563. if (!this.type) {
  564. return toolbar;
  565. }
  566. var map = new Map();
  567. map.set("flow", ['phrase']);
  568. if (map.get(this.type)) {
  569. return {
  570. items: map.get(this.type)
  571. }
  572. }
  573. return toolbar;
  574. },
  575. alignFullScreenToolbarButton: function () {
  576. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  577. return;
  578. }
  579. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  580. if (!toolbarItems) {
  581. return;
  582. }
  583. var buttons = toolbarItems.querySelectorAll(".ck-button");
  584. for (var i = 0; i < buttons.length; i++) {
  585. var label = (buttons[i].getAttribute("aria-label") || buttons[i].getAttribute("title") || buttons[i].textContent || "").replace(/\s/g, "");
  586. if (label.indexOf("全屏") != -1) {
  587. buttons[i].style.marginLeft = "auto";
  588. toolbarItems.appendChild(buttons[i]);
  589. return;
  590. }
  591. }
  592. },
  593. mountVideoUploadToolbarButton: function (retryCount) {
  594. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  595. return;
  596. }
  597. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  598. if (!toolbarItems) {
  599. return;
  600. }
  601. if (toolbarItems.querySelector(".space-editor-video-upload-ck-button")) {
  602. return;
  603. }
  604. var dropdowns = toolbarItems.querySelectorAll(".ck-dropdown");
  605. var mediaDropdown = null;
  606. for (var i = 0; i < dropdowns.length; i++) {
  607. var button = dropdowns[i].querySelector(".ck-button");
  608. var label = button ? (button.getAttribute("aria-label") || button.getAttribute("title") || button.textContent || "") : "";
  609. label = label.replace(/\s/g, "").toLowerCase();
  610. if (label.indexOf("媒体") != -1 || label.indexOf("media") != -1) {
  611. mediaDropdown = dropdowns[i];
  612. break;
  613. }
  614. }
  615. if (!mediaDropdown) {
  616. if ((retryCount || 0) < 3) {
  617. var _this = this;
  618. setTimeout(function () {
  619. _this.mountVideoUploadToolbarButton((retryCount || 0) + 1);
  620. }, 200);
  621. }
  622. return;
  623. }
  624. var _this = this;
  625. var videoButton = document.createElement("button");
  626. videoButton.type = "button";
  627. videoButton.className = "ck ck-button ck-off space-editor-video-upload-ck-button";
  628. videoButton.setAttribute("aria-label", "上传视频");
  629. videoButton.setAttribute("title", "上传视频");
  630. 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>';
  631. videoButton.addEventListener("click", function (event) {
  632. event.preventDefault();
  633. event.stopPropagation();
  634. _this.openVideoPicker();
  635. });
  636. mediaDropdown.classList.add("space-editor-media-link-dropdown");
  637. mediaDropdown.parentNode.insertBefore(videoButton, mediaDropdown);
  638. },
  639. formatContent: function () {
  640. if (!this.editor) {
  641. return;
  642. }
  643. var html = this.editor.getData();
  644. if (space.utils.isNull(html)) {
  645. space.message.warning("正文内容为空");
  646. return;
  647. }
  648. var wrapper = document.createElement("div");
  649. wrapper.innerHTML = html;
  650. var all = wrapper.querySelectorAll("*");
  651. for (var i = 0; i < all.length; i++) {
  652. var node = all[i];
  653. node.removeAttribute("lang");
  654. node.removeAttribute("width");
  655. node.removeAttribute("height");
  656. node.removeAttribute("onload");
  657. node.removeAttribute("border");
  658. node.removeAttribute("vspace");
  659. node.removeAttribute("hspace");
  660. var style = node.getAttribute("style") || "";
  661. if (/mso-|font-family|text-indent:\s*0|background:\s*transparent/i.test(style)) {
  662. node.removeAttribute("style");
  663. }
  664. }
  665. var inlineNodes = wrapper.querySelectorAll("span, font");
  666. for (var s = inlineNodes.length - 1; s >= 0; s--) {
  667. var inlineNode = inlineNodes[s];
  668. if (inlineNode.attributes.length == 0 && inlineNode.parentNode) {
  669. while (inlineNode.firstChild) {
  670. inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
  671. }
  672. inlineNode.parentNode.removeChild(inlineNode);
  673. }
  674. }
  675. var emptyBlocks = wrapper.querySelectorAll("p, div");
  676. for (var e = emptyBlocks.length - 1; e >= 0; e--) {
  677. var block = emptyBlocks[e];
  678. var hasMedia = block.querySelector("img, video, iframe, table");
  679. var text = (block.textContent || "").replace(/\u00a0/g, "").trim();
  680. if (!hasMedia && text == "" && block.parentNode) {
  681. block.parentNode.removeChild(block);
  682. }
  683. }
  684. var images = wrapper.querySelectorAll("img");
  685. for (var imgIndex = 0; imgIndex < images.length; imgIndex++) {
  686. images[imgIndex].style.maxWidth = "100%";
  687. images[imgIndex].style.height = "auto";
  688. images[imgIndex].style.display = "block";
  689. images[imgIndex].style.margin = "12px auto";
  690. }
  691. var videos = wrapper.querySelectorAll("video, iframe");
  692. for (var v = 0; v < videos.length; v++) {
  693. videos[v].style.maxWidth = "100%";
  694. if (videos[v].tagName.toLowerCase() == "video") {
  695. videos[v].setAttribute("controls", "controls");
  696. videos[v].setAttribute("playsinline", "playsinline");
  697. videos[v].style.display = "block";
  698. videos[v].style.margin = "12px auto";
  699. }
  700. }
  701. var tables = wrapper.querySelectorAll("table");
  702. for (var t = 0; t < tables.length; t++) {
  703. tables[t].style.width = "100%";
  704. tables[t].style.borderCollapse = "collapse";
  705. }
  706. this.editor.setData(wrapper.innerHTML);
  707. this.$emit("input", this.editor.getData());
  708. space.message.success("正文已完成排版整理");
  709. },
  710. insertHtml: function (html) {
  711. if (!this.editor || space.utils.isNull(html)) {
  712. return;
  713. }
  714. var viewFragment = this.editor.data.processor.toView(html);
  715. var modelFragment = this.editor.data.toModel(viewFragment);
  716. this.editor.model.insertContent(modelFragment);
  717. this.$emit("input", this.editor.getData());
  718. },
  719. openVideoPicker: function () {
  720. if (this.$refs.videoInput) {
  721. this.$refs.videoInput.click();
  722. }
  723. },
  724. handleVideoSelect: function (event) {
  725. var files = Array.prototype.slice.call(event.target.files || []);
  726. event.target.value = "";
  727. if (files.length > 0) {
  728. this.uploadVideoFile(files[0]);
  729. }
  730. },
  731. uploadVideoFile: function (file) {
  732. if (!file || !file.type || file.type.indexOf("video/") !== 0) {
  733. space.message.warning("请选择视频文件");
  734. return;
  735. }
  736. var _this = this;
  737. _this.uploading = true;
  738. _this.uploadStatus = "正在上传视频";
  739. _this.uploadPlainFileByAdapter(file, {
  740. imageQuality: 'origin'
  741. }, function (loaded, total) {
  742. if (total > 0) {
  743. _this.uploadStatus = "正在上传视频 " + Math.round(loaded * 100 / total) + "%";
  744. }
  745. }).then(function (res) {
  746. if (_this.editor && _this.editor.commands.get('mediaEmbed')) {
  747. _this.editor.execute('mediaEmbed', res.default);
  748. } else {
  749. _this.insertHtml('<p><video controls playsinline preload="metadata" src="' + res.default + '"></video></p>');
  750. }
  751. _this.$emit("input", _this.editor.getData());
  752. space.message.success("视频已插入正文");
  753. }).catch(function (msg) {
  754. space.message.error(msg || "视频上传失败");
  755. }).finally(function () {
  756. _this.uploading = false;
  757. _this.uploadStatus = "";
  758. });
  759. },
  760. bindVideoPasteUpload: function () {
  761. if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
  762. return;
  763. }
  764. var editable = this.editor.ui.getEditableElement();
  765. if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
  766. return;
  767. }
  768. editable.setAttribute("data-space-video-upload", "true");
  769. var _this = this;
  770. var handler = function (event) {
  771. var dataTransfer = event.clipboardData || event.dataTransfer;
  772. if (!dataTransfer || !dataTransfer.files || dataTransfer.files.length == 0) {
  773. return;
  774. }
  775. var files = Array.prototype.slice.call(dataTransfer.files);
  776. var videoFile = files.find(function (file) {
  777. return file && file.type && file.type.indexOf("video/") === 0;
  778. });
  779. if (videoFile) {
  780. event.preventDefault();
  781. _this.uploadVideoFile(videoFile);
  782. }
  783. };
  784. editable.addEventListener("paste", handler);
  785. editable.addEventListener("drop", handler);
  786. },
  787. getPreviewPostData: function () {
  788. var data = this.previewdata || {};
  789. return {
  790. title: data.title || '',
  791. source: data.source || '',
  792. navigationid: data.navigationid || '',
  793. desc: data.desc || '',
  794. body: this.editor ? this.editor.getData() : (this.htmlContent || '')
  795. };
  796. },
  797. openArticlePreview: function () {
  798. if (!this.editor) {
  799. return;
  800. }
  801. var postData = this.getPreviewPostData();
  802. if (space.utils.isNull(postData.navigationid)) {
  803. space.message.warning("请先选择发布栏目");
  804. return;
  805. }
  806. if (space.utils.isNull(postData.body)) {
  807. space.message.warning("正文内容为空");
  808. return;
  809. }
  810. var _this = this;
  811. _this.previewLoading = true;
  812. $.ajax({
  813. url: _this.previewurl || "/apps?ark=website.article_preview",
  814. type: "POST",
  815. data: postData,
  816. dataType: "json",
  817. success: function (res) {
  818. if (res.code != "success") {
  819. space.message.error(res.msg || "生成预览失败");
  820. return;
  821. }
  822. var data = res.data || {};
  823. var baseUrl = data.url || data.previewUrl || "";
  824. if (space.utils.isNull(baseUrl)) {
  825. space.message.error("生成预览失败");
  826. return;
  827. }
  828. _this.previewUrl = baseUrl + (baseUrl.indexOf("?") == -1 ? "?" : "&") + "_t=" + new Date().getTime();
  829. _this.previewVisible = true;
  830. },
  831. error: function () {
  832. space.message.error("生成预览失败");
  833. },
  834. complete: function () {
  835. _this.previewLoading = false;
  836. }
  837. });
  838. },
  839. /**
  840. * 初始化编辑器
  841. */
  842. initEditor: function () {
  843. var toolbar = this.getToolbar();
  844. var _this = this;
  845. ClassicEditor.create(document.querySelector("#" + _this.id), {
  846. extraPlugins: [function (editor) {
  847. _this.installUploadAdapter(editor);
  848. }], // 添加上传适配器
  849. toolbar: toolbar || {},
  850. language: 'zh-cn',
  851. placeholder: _this.placeholder || '',
  852. mediaEmbed: {
  853. previewsInData: true,
  854. providers: [{
  855. name: 'spaceVideo',
  856. url: [
  857. /\.(mp4|webm|ogg)(\?.*)?$/i
  858. ],
  859. html: match => {
  860. const input = match['input'];
  861. return (
  862. `<video controls playsinline preload="metadata" src="${input}" style="max-width:100%;"></video>`
  863. );
  864. }
  865. }, {
  866. name: 'myprovider',
  867. url: [
  868. /^lizzy.*\.com.*\/media\/(\w+)/,
  869. /^www\.lizzy.*/,
  870. /^.*/
  871. ],
  872. html: match => {
  873. //获取媒体url
  874. const input = match['input'];
  875. return (
  876. `<iframe src="${input}" allowFullScreen="true" frameborder="0"></iframe>`
  877. );
  878. }
  879. }]
  880. }
  881. }).then(editor => {
  882. space.vars.editorReady = true;
  883. _this.editor = editor;
  884. _this.alignFullScreenToolbarButton();
  885. _this.mountVideoUploadToolbarButton();
  886. _this.bindVideoPasteUpload();
  887. if (_this.htmlContent != undefined) {
  888. _this.editor.setData(_this.htmlContent);
  889. }
  890. /**
  891. * 禁止在编辑器内回车事件
  892. */
  893. editor.ui.view.element.onkeydown = function (event) {
  894. // 回车键
  895. if (event.keyCode == 13) {
  896. event.stopPropagation();
  897. return false;
  898. }
  899. // tab 转空格
  900. if (event.keyCode == 9) {
  901. const model = editor.model;
  902. model.change(writer => {
  903. const ele = writer.createElement('span');
  904. writer.insertText(" ", ele);
  905. // 一定要 Element
  906. model.insertContent(ele);
  907. });
  908. event.stopPropagation();
  909. return false;
  910. }
  911. _this.$emit("input", editor.getData());
  912. };
  913. // 设置编辑器宽度
  914. if (_this.width) {
  915. $(editor.ui.view.element).css({
  916. 'width': _this.width
  917. })
  918. }
  919. // 监听编辑器的内容变动事件
  920. editor.model.document.on('change:data', function () {
  921. _this.$emit("input", editor.getData());
  922. });
  923. }).catch(error => {
  924. console.log(error);
  925. });
  926. }
  927. },
  928. template: `
  929. <div class="space-editor-wrap">
  930. <div class="space-editor-toolstrip" v-if="showEditorTools()">
  931. <el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
  932. <span class="space-editor-tool-divider"></span>
  933. <el-select class="space-editor-quality" v-model="imageQuality" size="small" placeholder="图片质量压缩" title="图片质量压缩">
  934. <el-option label="原图" value="origin"></el-option>
  935. <el-option label="高清 85%" value="high"></el-option>
  936. <el-option label="标准 70%" value="standard"></el-option>
  937. <el-option label="低流量 50%" value="low"></el-option>
  938. </el-select>
  939. <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>
  940. <span class="space-editor-upload-status" v-if="uploadStatus">{{uploadStatus}}</span>
  941. </div>
  942. <input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
  943. <div :id="id">
  944. <script type="text/plain"></script>
  945. </div>
  946. <el-dialog title="正文预览" :visible.sync="previewVisible" width="90%" top="4vh" append-to-body custom-class="space-editor-preview-dialog">
  947. <div class="space-editor-preview-toolbar">
  948. <el-radio-group v-model="previewMode" size="small">
  949. <el-radio-button label="pc">PC端</el-radio-button>
  950. <el-radio-button label="pad">平板端</el-radio-button>
  951. <el-radio-button label="mobile">手机端</el-radio-button>
  952. </el-radio-group>
  953. <el-button size="small" icon="el-icon-refresh" @click="openArticlePreview" :loading="previewLoading">刷新预览</el-button>
  954. </div>
  955. <div class="space-editor-preview-stage">
  956. <iframe v-if="previewUrl" :key="previewMode + previewUrl" :src="previewUrl" :style="previewFrameStyle" frameborder="0"></iframe>
  957. </div>
  958. </el-dialog>
  959. </div>
  960. `
  961. })
  962. /**
  963. * CMS
  964. */
  965. Vue.component('spaceCms', {
  966. data: function () {
  967. return {
  968. fileCount: 0, // 文件总数
  969. }
  970. },
  971. name: "spaceCms",
  972. model: {
  973. prop: 'cmsid',
  974. evnet: 'click'
  975. },
  976. props: {
  977. // v-model
  978. cmsid: {
  979. type: [String],
  980. required: true
  981. },
  982. // 文件类型
  983. accept: {
  984. type: String
  985. },
  986. // 最大上传数量,默认199
  987. maxsize: {
  988. type: [String, Number],
  989. default: 199
  990. },
  991. },
  992. created: function () {
  993. this.getCmsFileCount(this.cmsid);
  994. },
  995. watch: {
  996. cmsid: function (newVal, oldVal) {
  997. this.getCmsFileCount(newVal);
  998. }
  999. },
  1000. methods: {
  1001. open: function () {
  1002. var that = this;
  1003. space.plugins.cms.openCMS({
  1004. cmsid: that.cmsid,
  1005. accept: that.accept,
  1006. maxsize: that.maxsize
  1007. }, that.callback);
  1008. },
  1009. callback: function (data, callback2) {
  1010. this.$emit("input", data.cmsid);
  1011. this.cmsid = data.cmsid;
  1012. this.fileCount = data.fileCount;
  1013. callback2();
  1014. },
  1015. getCmsFileCount: function (cmsid) {
  1016. if (space.utils.isNull(cmsid)) {
  1017. return;
  1018. }
  1019. var that = this;
  1020. space.utils.ajax({
  1021. url: '/apps?ark=sys.cms_getCmsInfo',
  1022. data: {
  1023. "idcard": cmsid
  1024. },
  1025. dataType: 'json',
  1026. loadLayer: false,
  1027. autoTip: false,
  1028. async: false, // 同步请求
  1029. callback: function (data) {
  1030. if (data.code == "success") {
  1031. that.fileCount = data.data.filecount;
  1032. }
  1033. }
  1034. });
  1035. }
  1036. },
  1037. template: `<div class="cms-upload">
  1038. <el-badge :value="fileCount" type="primary" v-show="fileCount > 0">
  1039. <el-button icon="el-icon-upload2" @click="open" >上传文件</el-button>
  1040. </el-badge>
  1041. <el-button icon="el-icon-upload2" v-show="fileCount == 0" @click="open" >上传文件</el-button>
  1042. </div>`
  1043. })
  1044. /**
  1045. * CMS预览
  1046. */
  1047. Vue.component('spaceCmsView', {
  1048. data: function () {
  1049. return {
  1050. thumbnail: "",
  1051. filename: "",
  1052. filecount: 0,
  1053. isShowEl: true, //是否显示整个组件元素
  1054. }
  1055. },
  1056. name: "spaceCmsView",
  1057. /**
  1058. * cmsid: 绑定的值,非空
  1059. * thumbnail: 缩略图
  1060. * filename: 文件名
  1061. * filecount: 文件数
  1062. */
  1063. props: {
  1064. cmsid: {
  1065. type: [String, Number],
  1066. required: true
  1067. }
  1068. },
  1069. created: function () {
  1070. var that = this;
  1071. if (space.utils.isNull(that.cmsid)) {
  1072. // 不显示整个组件元素
  1073. that.isShowEl = false;
  1074. return;
  1075. }
  1076. space.utils.ajax({
  1077. url: '/apps?ark=sys.cms_getCmsInfo',
  1078. data: {
  1079. "idcard": that.cmsid
  1080. },
  1081. dataType: 'json',
  1082. loadLayer: false,
  1083. autoTip: false,
  1084. async: false, // 同步请求
  1085. callback: function (data) {
  1086. if (data.code == "success") {
  1087. that.thumbnail = data.data.thumbnail;
  1088. that.filename = data.data.filename;
  1089. that.filecount = data.data.filecount;
  1090. } else if (data.code == "warning") {
  1091. // 不显示整个组件元素
  1092. that.isShowEl = false;
  1093. }
  1094. }
  1095. });
  1096. },
  1097. methods: {
  1098. open: function () {
  1099. var that = this;
  1100. space.plugins.cms.openCMSView({
  1101. cmsid: that.cmsid
  1102. });
  1103. },
  1104. },
  1105. template: `
  1106. <div class="space-cms-view" v-if="isShowEl">
  1107. <div class="space-cms-view-wrap" @click="open">
  1108. <div class="space-cms-view-main">
  1109. <el-image :src="thumbnail">
  1110. <div slot="error" class="image-slot">
  1111. <i class="el-icon-picture-outline"></i>
  1112. </div>
  1113. </el-image>
  1114. <span>{{filename}}</span>
  1115. </div>
  1116. <div v-show="filecount >=2 " class="more-file"></div>
  1117. <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
  1118. </div>
  1119. </div>
  1120. `
  1121. })
  1122. /**
  1123. * 业务流转
  1124. */
  1125. Vue.component('spacePluginFlow', {
  1126. data: function () {
  1127. return {
  1128. isOpenFlowDrawer: false, // 是否打开抽屉
  1129. isLoadShow: true, // 是否显示加载动画
  1130. frameID: space.utils.randomStringAndNumber(6) + 'Frm', // frame 窗口ID
  1131. closeBtnID: space.utils.randomStringAndNumber(6) + 'Close', // 关闭按钮的ID
  1132. url: '/app/flow/time/', // url
  1133. title: '业务流转', // 标题
  1134. closeTitle: '收起', // 关闭按钮文本内容
  1135. }
  1136. },
  1137. name: "spacePluginFlow",
  1138. /**
  1139. * cmsid: 绑定的值,非空
  1140. * size: 抽屉大小,可传px、%,默认30%
  1141. */
  1142. props: {
  1143. audit: {
  1144. type: String,
  1145. required: true
  1146. },
  1147. apply: {
  1148. type: String,
  1149. required: true
  1150. },
  1151. open: {
  1152. type: Boolean,
  1153. },
  1154. size: {
  1155. type: String
  1156. },
  1157. },
  1158. created: function () {
  1159. this.url = this.url + "?auditid=" + this.audit + "&applyid=" + this.apply;
  1160. this.size = space.utils.isNull(this.size) ? '360px' : this.size;
  1161. this.isOpenFlowDrawer = space.utils.isNull(this.open) ? false : this.open;
  1162. this.showLoad();
  1163. },
  1164. mounted: function () {
  1165. var that = this;
  1166. // 监听窗口变化,计算关闭按钮的位置
  1167. window.onresize = function () {
  1168. // 抽屉打开状态
  1169. if (that.isOpenFlowDrawer) {
  1170. that.initCloseBtnLocation();
  1171. }
  1172. }
  1173. },
  1174. methods: {
  1175. /**
  1176. * 计算关闭按钮的坐标
  1177. */
  1178. initCloseBtnLocation: function () {
  1179. var offset = space.utils.getDomPosition(document.getElementById(this.frameID));
  1180. $("#" + this.closeBtnID).css("left", (offset.left - $("#" + this.closeBtnID).width()) + "px");
  1181. },
  1182. /**
  1183. * 显示抽屉
  1184. */
  1185. showDrawer: function () {
  1186. var that = this;
  1187. that.initCloseBtnLocation();
  1188. $("#" + that.closeBtnID).fadeIn(200);
  1189. // 为了更好的动画体验
  1190. setTimeout(() => {
  1191. $("#" + that.closeBtnID).css("z-index", "999999999999999");
  1192. }, 200);
  1193. },
  1194. /**
  1195. * 控制加载动画
  1196. */
  1197. showLoad: function () {
  1198. var that = this;
  1199. var loadInterval = setInterval(() => {
  1200. var frameEle = document.getElementById(that.frameID);
  1201. console.log("loadInterval");
  1202. frameEle.onload = function () {
  1203. window.clearInterval(loadInterval);
  1204. that.isLoadShow = false;
  1205. }
  1206. }, 100);
  1207. }
  1208. },
  1209. watch: {
  1210. isOpenFlowDrawer: function (newVal, oldVal) {
  1211. var that = this;
  1212. // 打开
  1213. if (newVal) {
  1214. var getFrameInterval = setInterval(() => {
  1215. var frameEle = document.getElementById(that.frameID);
  1216. if (!frameEle) {
  1217. return;
  1218. }
  1219. window.clearInterval(getFrameInterval);
  1220. that.showDrawer();
  1221. }, 200);
  1222. }
  1223. // 关闭
  1224. else {
  1225. $("#" + that.closeBtnID).hide();
  1226. $("#" + that.closeBtnID).css("z-index", "");
  1227. }
  1228. },
  1229. open: function (newVal, oldVal) {
  1230. this.isOpenFlowDrawer = space.utils.isNull(newVal) ? false : newVal;
  1231. }
  1232. },
  1233. template: `
  1234. <div class="space-app-plugin">
  1235. <div class="space-app-plugin-open disable-select animate__animated animate__slideInRight" v-show="!isOpenFlowDrawer" @click="isOpenFlowDrawer = true">{{title}}</div>
  1236. <div :id="closeBtnID" class="space-app-plugin-close disable-select animate__animated animate__slideInRight" @click="isOpenFlowDrawer = false">{{closeTitle}}</div>
  1237. <el-drawer :modal="false" :visible.sync="isOpenFlowDrawer" :size="size" :with-header="false" :wrapper-closable="false" >
  1238. <iframe :id="frameID" :src="url"></iframe>
  1239. <div class="space-app-plugin-load" v-show="isLoadShow" ><i class="el-icon-loading" ></i>加载中</div>
  1240. </el-drawer>
  1241. </div>
  1242. `
  1243. })