space.vue.subassembly.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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'
  361. ],
  362. // 标识,全部为 true 则代表全部加载完成
  363. jsUrlFlag: [],
  364. notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完
  365. }
  366. },
  367. name: "spaceEditor",
  368. model: {
  369. prop: 'htmlContent',
  370. evnet: 'click'
  371. },
  372. /**
  373. * htmlContent: v-model 绑定的值,非空,html 字符串
  374. * size: 编辑器的大小,small、medium、large
  375. * width: 编辑器的宽度,可空
  376. * height: 编辑器的高度,可空
  377. * placeholder:占位符
  378. * type:编辑器工具栏类型
  379. * isfullscreen:是否有全屏,
  380. */
  381. props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen'],
  382. watch: {
  383. height: function (newVal, oldVal) {
  384. if (this.height && this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  385. this.height += 'px';
  386. } else {
  387. this.setEditorHeight();
  388. }
  389. },
  390. editor: function (newVal, oldVal) {
  391. this.setEditorHeight();
  392. },
  393. jsUrlFlag: function (newVal, oldVal) {
  394. if (this.jsUrl.length > 0 && this.jsUrl.length == this.jsUrlFlag.length) {
  395. if (this.jsUrlFlag.indexOf('false') != -1) {
  396. return;
  397. }
  398. this.initEditor();
  399. this.notLoadEditor = false;
  400. this.setEditorHeight();
  401. }
  402. },
  403. notLoadEditor: function (newVal, oldVal) {
  404. this.setEditorHeight();
  405. },
  406. },
  407. created: function () {
  408. var _this = this;
  409. for (var i = 0; i < _this.jsUrl.length; i++) {
  410. _this.loadJS(_this.jsUrl[i], function () {
  411. _this.jsUrlFlag.push('true');
  412. });
  413. }
  414. },
  415. methods: {
  416. loadJS: function (url, callback) {
  417. for (var i = 0; i < document.getElementsByTagName('head')[0].getElementsByTagName('script').length; i++) {
  418. var src = document.getElementsByTagName('head')[0].getElementsByTagName('script')[i].getAttribute('src');
  419. if (url == src) {
  420. // 防止一个页面有多个编辑器时,编辑器加载失败
  421. if (space.vars.editorReady != true) {
  422. var winInterval = setInterval(function () {
  423. if (space.vars.editorReady != true) {
  424. return;
  425. }
  426. window.clearInterval(winInterval);
  427. if (callback) {
  428. callback();
  429. }
  430. }, 100)
  431. }
  432. return;
  433. }
  434. }
  435. var script = document.createElement('script');
  436. script.type = 'text/javascript';
  437. script.onload = function () {
  438. if (callback) {
  439. callback();
  440. }
  441. };
  442. script.src = url;
  443. document.getElementsByTagName('head')[0].appendChild(script);
  444. },
  445. myCustomUploadAdapterPlugin: function (editor) {
  446. editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
  447. // 第二个参数设置上传图片的地址
  448. return new MyUploadAdapter(loader);
  449. };
  450. },
  451. /**
  452. * 获取高度
  453. */
  454. getHeight: function () {
  455. if (!this.height) {
  456. if (this.size == undefined || this.size == "small") {
  457. return '200px';
  458. } else if (this.size == "medium") {
  459. return '400px';
  460. } else if (this.size == "large") {
  461. return '600px';
  462. }
  463. } else if (this.height) {
  464. if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
  465. return this.height + 'px';
  466. } else {
  467. return this.height;
  468. }
  469. }
  470. return "";
  471. },
  472. /**
  473. * 设置编辑器高度
  474. */
  475. setEditorHeight: function () {
  476. if (this.notLoadEditor) {
  477. return;
  478. }
  479. var height = this.getHeight();
  480. if (!this.editor || !height) {
  481. return;
  482. }
  483. var _this = this;
  484. // 设置编辑器高度
  485. _this.editor.editing.view.change(writer => {
  486. writer.setStyle(
  487. "height",
  488. height,
  489. _this.editor.editing.view.document.getRoot()
  490. );
  491. });
  492. },
  493. /**
  494. * 获取工具栏
  495. */
  496. getToolbar: function () {
  497. var items = [];
  498. // 是否有全屏工具
  499. if (this.isfullscreen == false) {
  500. // 没有全屏工具栏
  501. items = [
  502. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  503. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo'
  504. ];
  505. } else {
  506. items = [
  507. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
  508. 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo', 'fullScreen'
  509. ];
  510. }
  511. var toolbar = {
  512. items: items
  513. };
  514. if (!this.type) {
  515. return toolbar;
  516. }
  517. var map = new Map();
  518. map.set("flow", ['phrase']);
  519. if (map.get(this.type)) {
  520. return {
  521. items: map.get(this.type)
  522. }
  523. }
  524. return toolbar;
  525. },
  526. alignFullScreenToolbarButton: function () {
  527. if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
  528. return;
  529. }
  530. var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
  531. if (!toolbarItems) {
  532. return;
  533. }
  534. var buttons = toolbarItems.querySelectorAll(".ck-button");
  535. for (var i = 0; i < buttons.length; i++) {
  536. var label = (buttons[i].getAttribute("aria-label") || buttons[i].getAttribute("title") || buttons[i].textContent || "").replace(/\s/g, "");
  537. if (label.indexOf("全屏") != -1) {
  538. buttons[i].style.marginLeft = "auto";
  539. toolbarItems.appendChild(buttons[i]);
  540. return;
  541. }
  542. }
  543. },
  544. /**
  545. * 初始化编辑器
  546. */
  547. initEditor: function () {
  548. var toolbar = this.getToolbar();
  549. var _this = this;
  550. ClassicEditor.create(document.querySelector("#" + _this.id), {
  551. extraPlugins: [_this.myCustomUploadAdapterPlugin], // 添加上传适配器
  552. toolbar: toolbar || {},
  553. language: 'zh-cn',
  554. placeholder: _this.placeholder || '',
  555. mediaEmbed: {
  556. providers: [{
  557. name: 'myprovider',
  558. url: [
  559. /^lizzy.*\.com.*\/media\/(\w+)/,
  560. /^www\.lizzy.*/,
  561. /^.*/
  562. ],
  563. html: match => {
  564. //获取媒体url
  565. const input = match['input'];
  566. return (
  567. `<iframe src="${input}" allowFullScreen="true" frameborder="0"></iframe>`
  568. );
  569. }
  570. }]
  571. }
  572. }).then(editor => {
  573. space.vars.editorReady = true;
  574. _this.editor = editor;
  575. _this.alignFullScreenToolbarButton();
  576. if (_this.htmlContent != undefined) {
  577. _this.editor.setData(_this.htmlContent);
  578. }
  579. /**
  580. * 禁止在编辑器内回车事件
  581. */
  582. editor.ui.view.element.onkeydown = function (event) {
  583. // 回车键
  584. if (event.keyCode == 13) {
  585. event.stopPropagation();
  586. return false;
  587. }
  588. // tab 转空格
  589. if (event.keyCode == 9) {
  590. const model = editor.model;
  591. model.change(writer => {
  592. const ele = writer.createElement('span');
  593. writer.insertText(" ", ele);
  594. // 一定要 Element
  595. model.insertContent(ele);
  596. });
  597. event.stopPropagation();
  598. return false;
  599. }
  600. _this.$emit("input", editor.getData());
  601. };
  602. // 设置编辑器宽度
  603. if (_this.width) {
  604. $(editor.ui.view.element).css({
  605. 'width': _this.width
  606. })
  607. }
  608. // 监听编辑器的内容变动事件
  609. editor.model.document.on('change:data', function () {
  610. _this.$emit("input", editor.getData());
  611. });
  612. }).catch(error => {
  613. console.log(error);
  614. });
  615. }
  616. },
  617. template: `
  618. <div :id="id">
  619. <script type="text/plain"></script>
  620. </div>
  621. `
  622. })
  623. /**
  624. * CMS
  625. */
  626. Vue.component('spaceCms', {
  627. data: function () {
  628. return {
  629. fileCount: 0, // 文件总数
  630. }
  631. },
  632. name: "spaceCms",
  633. model: {
  634. prop: 'cmsid',
  635. evnet: 'click'
  636. },
  637. props: {
  638. // v-model
  639. cmsid: {
  640. type: [String],
  641. required: true
  642. },
  643. // 文件类型
  644. accept: {
  645. type: String
  646. },
  647. // 最大上传数量,默认199
  648. maxsize: {
  649. type: [String, Number],
  650. default: 199
  651. },
  652. },
  653. created: function () {
  654. this.getCmsFileCount(this.cmsid);
  655. },
  656. watch: {
  657. cmsid: function (newVal, oldVal) {
  658. this.getCmsFileCount(newVal);
  659. }
  660. },
  661. methods: {
  662. open: function () {
  663. var that = this;
  664. space.plugins.cms.openCMS({
  665. cmsid: that.cmsid,
  666. accept: that.accept,
  667. maxsize: that.maxsize
  668. }, that.callback);
  669. },
  670. callback: function (data, callback2) {
  671. this.$emit("input", data.cmsid);
  672. this.cmsid = data.cmsid;
  673. this.fileCount = data.fileCount;
  674. callback2();
  675. },
  676. getCmsFileCount: function (cmsid) {
  677. if (space.utils.isNull(cmsid)) {
  678. return;
  679. }
  680. var that = this;
  681. space.utils.ajax({
  682. url: '/apps?ark=sys.cms_getCmsInfo',
  683. data: {
  684. "idcard": cmsid
  685. },
  686. dataType: 'json',
  687. loadLayer: false,
  688. autoTip: false,
  689. async: false, // 同步请求
  690. callback: function (data) {
  691. if (data.code == "success") {
  692. that.fileCount = data.data.filecount;
  693. }
  694. }
  695. });
  696. }
  697. },
  698. template: `<div class="cms-upload">
  699. <el-badge :value="fileCount" type="primary" v-show="fileCount > 0">
  700. <el-button icon="el-icon-upload2" @click="open" >上传文件</el-button>
  701. </el-badge>
  702. <el-button icon="el-icon-upload2" v-show="fileCount == 0" @click="open" >上传文件</el-button>
  703. </div>`
  704. })
  705. /**
  706. * CMS预览
  707. */
  708. Vue.component('spaceCmsView', {
  709. data: function () {
  710. return {
  711. thumbnail: "",
  712. filename: "",
  713. filecount: 0,
  714. isShowEl: true, //是否显示整个组件元素
  715. }
  716. },
  717. name: "spaceCmsView",
  718. /**
  719. * cmsid: 绑定的值,非空
  720. * thumbnail: 缩略图
  721. * filename: 文件名
  722. * filecount: 文件数
  723. */
  724. props: {
  725. cmsid: {
  726. type: [String, Number],
  727. required: true
  728. }
  729. },
  730. created: function () {
  731. var that = this;
  732. if (space.utils.isNull(that.cmsid)) {
  733. // 不显示整个组件元素
  734. that.isShowEl = false;
  735. return;
  736. }
  737. space.utils.ajax({
  738. url: '/apps?ark=sys.cms_getCmsInfo',
  739. data: {
  740. "idcard": that.cmsid
  741. },
  742. dataType: 'json',
  743. loadLayer: false,
  744. autoTip: false,
  745. async: false, // 同步请求
  746. callback: function (data) {
  747. if (data.code == "success") {
  748. that.thumbnail = data.data.thumbnail;
  749. that.filename = data.data.filename;
  750. that.filecount = data.data.filecount;
  751. } else if (data.code == "warning") {
  752. // 不显示整个组件元素
  753. that.isShowEl = false;
  754. }
  755. }
  756. });
  757. },
  758. methods: {
  759. open: function () {
  760. var that = this;
  761. space.plugins.cms.openCMSView({
  762. cmsid: that.cmsid
  763. });
  764. },
  765. },
  766. template: `
  767. <div class="space-cms-view" v-if="isShowEl">
  768. <div class="space-cms-view-wrap" @click="open">
  769. <div class="space-cms-view-main">
  770. <el-image :src="thumbnail">
  771. <div slot="error" class="image-slot">
  772. <i class="el-icon-picture-outline"></i>
  773. </div>
  774. </el-image>
  775. <span>{{filename}}</span>
  776. </div>
  777. <div v-show="filecount >=2 " class="more-file"></div>
  778. <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
  779. </div>
  780. </div>
  781. `
  782. })
  783. /**
  784. * 业务流转
  785. */
  786. Vue.component('spacePluginFlow', {
  787. data: function () {
  788. return {
  789. isOpenFlowDrawer: false, // 是否打开抽屉
  790. isLoadShow: true, // 是否显示加载动画
  791. frameID: space.utils.randomStringAndNumber(6) + 'Frm', // frame 窗口ID
  792. closeBtnID: space.utils.randomStringAndNumber(6) + 'Close', // 关闭按钮的ID
  793. url: '/app/flow/time/', // url
  794. title: '业务流转', // 标题
  795. closeTitle: '收起', // 关闭按钮文本内容
  796. }
  797. },
  798. name: "spacePluginFlow",
  799. /**
  800. * cmsid: 绑定的值,非空
  801. * size: 抽屉大小,可传px、%,默认30%
  802. */
  803. props: {
  804. audit: {
  805. type: String,
  806. required: true
  807. },
  808. apply: {
  809. type: String,
  810. required: true
  811. },
  812. open: {
  813. type: Boolean,
  814. },
  815. size: {
  816. type: String
  817. },
  818. },
  819. created: function () {
  820. this.url = this.url + "?auditid=" + this.audit + "&applyid=" + this.apply;
  821. this.size = space.utils.isNull(this.size) ? '360px' : this.size;
  822. this.isOpenFlowDrawer = space.utils.isNull(this.open) ? false : this.open;
  823. this.showLoad();
  824. },
  825. mounted: function () {
  826. var that = this;
  827. // 监听窗口变化,计算关闭按钮的位置
  828. window.onresize = function () {
  829. // 抽屉打开状态
  830. if (that.isOpenFlowDrawer) {
  831. that.initCloseBtnLocation();
  832. }
  833. }
  834. },
  835. methods: {
  836. /**
  837. * 计算关闭按钮的坐标
  838. */
  839. initCloseBtnLocation: function () {
  840. var offset = space.utils.getDomPosition(document.getElementById(this.frameID));
  841. $("#" + this.closeBtnID).css("left", (offset.left - $("#" + this.closeBtnID).width()) + "px");
  842. },
  843. /**
  844. * 显示抽屉
  845. */
  846. showDrawer: function () {
  847. var that = this;
  848. that.initCloseBtnLocation();
  849. $("#" + that.closeBtnID).fadeIn(200);
  850. // 为了更好的动画体验
  851. setTimeout(() => {
  852. $("#" + that.closeBtnID).css("z-index", "999999999999999");
  853. }, 200);
  854. },
  855. /**
  856. * 控制加载动画
  857. */
  858. showLoad: function () {
  859. var that = this;
  860. var loadInterval = setInterval(() => {
  861. var frameEle = document.getElementById(that.frameID);
  862. console.log("loadInterval");
  863. frameEle.onload = function () {
  864. window.clearInterval(loadInterval);
  865. that.isLoadShow = false;
  866. }
  867. }, 100);
  868. }
  869. },
  870. watch: {
  871. isOpenFlowDrawer: function (newVal, oldVal) {
  872. var that = this;
  873. // 打开
  874. if (newVal) {
  875. var getFrameInterval = setInterval(() => {
  876. var frameEle = document.getElementById(that.frameID);
  877. if (!frameEle) {
  878. return;
  879. }
  880. window.clearInterval(getFrameInterval);
  881. that.showDrawer();
  882. }, 200);
  883. }
  884. // 关闭
  885. else {
  886. $("#" + that.closeBtnID).hide();
  887. $("#" + that.closeBtnID).css("z-index", "");
  888. }
  889. },
  890. open: function (newVal, oldVal) {
  891. this.isOpenFlowDrawer = space.utils.isNull(newVal) ? false : newVal;
  892. }
  893. },
  894. template: `
  895. <div class="space-app-plugin">
  896. <div class="space-app-plugin-open disable-select animate__animated animate__slideInRight" v-show="!isOpenFlowDrawer" @click="isOpenFlowDrawer = true">{{title}}</div>
  897. <div :id="closeBtnID" class="space-app-plugin-close disable-select animate__animated animate__slideInRight" @click="isOpenFlowDrawer = false">{{closeTitle}}</div>
  898. <el-drawer :modal="false" :visible.sync="isOpenFlowDrawer" :size="size" :with-header="false" :wrapper-closable="false" >
  899. <iframe :id="frameID" :src="url"></iframe>
  900. <div class="space-app-plugin-load" v-show="isLoadShow" ><i class="el-icon-loading" ></i>加载中</div>
  901. </el-drawer>
  902. </div>
  903. `
  904. })