| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867 |
- /**
- * 图片上传
- */
- Vue.component('spaceUploadImg', {
- data: function () {
- return {
- id: "spaceUploadImg" + space.utils.random(6),
- }
- },
- name: "spaceUploadImg",
- model: {
- prop: 'patharry',
- evnet: 'click'
- },
- /**
- * patharry: v-model 绑定的值,非空,字符串数组
- * type: 上传按钮的风格,可空,缺省值为 button ,可选值为button / img
- * width: 图片裁剪的宽度,可空
- * height: 图片裁剪的高度,可空
- * maxsize: 最大上传的图片数量,可空,缺省值为1
- * tip: 提示语,可空
- * color: 图片背景,可空,值的类型与css的color值类型一样
- * source: 是否可上传原图
- */
- props: {
- patharry: {
- type: Array,
- required: true
- },
- type: {
- type: String,
- default: "button"
- },
- width: [String, Number],
- height: [String, Number],
- maxsize: {
- type: [String, Number],
- default: 1
- },
- tip: [String, Number],
- color: [String, Number],
- source: {
- type: Boolean,
- default: false,
- }
- },
- created: function () {
- // 对初始化值进行处理,排除掉空数据
- if (!this.patharry) {
- this.patharry = [];
- }
- var newAry = [];
- if (typeof this.patharry == "string") {
- if (space.utils.notNull(this.patharry)) {
- newAry.push(this.patharry);
- }
- } else {
- for (let index = 0; index < this.patharry.length; index++) {
- const element = this.patharry[index];
- if (space.utils.notNull(element)) {
- newAry.push(element);
- }
- }
- }
- this.patharry = newAry;
- this.$emit("input", newAry);
- },
- mounted: function () {
- var that = this;
- space.plugins.cropper.init({
- el: $("#" + that.id),
- photoSize: { // 裁剪的图片大小,会自动计算裁剪比例
- width: that.width,
- height: that.height,
- source: that.source,
- },
- show: function (setting) { //打开裁剪框前的回调
- setting.photoSize = {
- width: that.width,
- height: that.height,
- source: that.source,
- }
- },
- success: function (path) { // 成功后的回调方法,path为裁剪后的img路径
- that.patharry.push(path);
- that.$emit("input", that.patharry);
- },
- });
- },
- methods: {
- uploadClick: function () {
- if (this.patharry.length >= this.maxsize) {
- space.message.warning("最多上传" + this.maxsize + "张图片");
- return false;
- }
- $("#" + this.id).click();
- },
- removeCropperImg: function (index) {
- this.patharry.splice(index, 1);
- space.message.success("图片已删除");
- this.$emit("input", this.patharry);
- },
- },
- template: `
- <div class="space-upload-img">
- <el-button size="small" icon="el-icon-upload" @click="uploadClick" :disabled="patharry.length >= maxsize" v-if="type == 'button' || space.utils.isNull(type)">上传</el-button>
- <span v-show="patharry.length >= maxsize" style="color: #C0C4CC;margin-left: 6px;">
- 最多上传{{maxsize}}张图片
- </span>
- <span v-show="tip" style="color: #888;margin-left: 6px;">
- {{tip}}
- </span>
- <input type="file" accept="image/*" :id="id" style="display: none;" />
- <div>
- <div v-show="patharry" class="cropper-img-content" v-for="(item, index) in patharry" :key="index"">
- <el-image class="cropper-img" fit="contain" :style="{'background-color': color}"
- :src="item" @click="space.plugins.elPreview.show(item, patharry)">
- </el-image>
- <i class="el-icon-close" @click="removeCropperImg(index)"></i>
- </div>
- <div class="uploadButton-img" v-if="type == 'img'" @click="uploadClick" v-show="patharry.length < maxsize">
- <i class="el-icon-plus"></i>
- </div>
- </div>
-
- </div>
- `
- })
- /**
- * 图片预览
- */
- Vue.component('spacePreviewImg', {
- data: function () {
- return {
- newAry: [],
- }
- },
- name: "spacePreviewImg",
- /**
- * paths: 绑定的值,非空,字符串/数组
- * color: 图片背景色,可空,值的类型与css的color值类型一样
- */
- props: {
- paths: {
- type: [Array, String],
- required: true
- },
- color: {
- type: String,
- }
- },
- created: function () {
- // 对初始化值进行处理,排除掉空数据
- if (!this.paths) {
- this.paths = [];
- }
- if (typeof this.paths == "string") {
- if (space.utils.notNull(this.paths)) {
- this.newAry.push(this.paths);
- }
- } else {
- for (let index = 0; index < this.paths.length; index++) {
- const element = this.paths[index];
- if (space.utils.notNull(element)) {
- this.newAry.push(element);
- }
- }
- }
- this.$emit("input", this.newAry);
- },
- mounted: function () {
- },
- methods: {
- },
- template: `
- <div class="space-preview-img">
- <div class="cropper-img-content" v-for="(item, index) in newAry" :key="index">
- <el-image class="cropper-img" fit="contain" :style="{'background-color': color}"
- :src="item" @click="space.plugins.elPreview.show(item, newAry)">
- </el-image>
- </div>
- </div>
- `
- })
- /**
- * 对象选择器
- */
- Vue.component('spaceSelect', {
- data: function () {
- return {
- id: "spaceSelect" + space.utils.random(6),
- randomNum: space.utils.random(6),
- options: [],
- isOpen: true, // 是否打开
- }
- },
- name: "spaceSelect",
- model: {
- prop: 'modelAry',
- evnet: 'click'
- },
- /**
- * modelAry: 绑定的值,非空,字符串/数组
- * predefine: 预定义对象,非空,可选值有person、department、post、role
- * datasize: 最多选择的数量,可空,默认值为1
- * method:自定义方法
- */
- props: ['modelAry', "predefine", "datasize", "method"],
- watch: {
- modelAry: function (newVal, oldVal) {
- // 没有打开时,则可以初始化选择数据集合
- if (!this.isOpen) {
- this.isOpen = true;
- this.initSelectedDataList();
- } else {
- this.isOpen = false;
- }
- }
- },
- created: function () {
- if (this.predefine && this.method) {
- space.message.error('predefine 与 method 不能同时存在');
- }
- if (!this.isPredefine()) {
- if (!this.method) {
- space.message.warning('预定义选择器不存在:' + this.predefine);
- }
- }
- },
- mounted: function () {
- var that = this;
- if (!this.method) {
- // 初始化选择窗
- space.choose[that.predefine].init({
- el: $("#choose" + that.predefine + that.randomNum), // 点击弹出选择窗的元素
- selectAry: function () {
- return that.modelAry;
- }, // 已选的数组
- selectCountNum: that.datasize || 1, // 最多选择的数量
- success: function (param) { // 成功后的回调
- that.options = param;
- that.modelAry = [];
- that.options.forEach(function (item) {
- that.modelAry.push(item["id"]);
- });
- that.$emit("input", that.modelAry);
- }
- })
- }
- /* 监听容器高度 */
- const erd = elementResizeDetectorMaker();
- var eles = $("#" + that.id).find("div.el-input--suffix")[0];
- erd.listenTo(eles, element => {
- const height = element.offsetHeight;
- $("#choose" + that.predefine + that.randomNum).css("height", height);
- });
- this.initSelectedDataList();
- },
- methods: {
- removeFun: function () {
- this.$emit("input", this.modelAry);
- },
- /**
- * 获取最大限制绑定的值
- */
- getMaxSelectedModelAry: function () {
- var tmpAry = [];
- var _this = this;
- this.options.forEach(function (item) {
- tmpAry.push(item["id"]);
- });
- if (this.datasize == undefined || this.datasize == 1) {
- return tmpAry.length > 0 ? [tmpAry[tmpAry.length - 1]] : [];
- } else if (this.datasize > 1) {
- var selectedAry = [];
- tmpAry.forEach(function (item, index) {
- if ((index + 1) > _this.datasize) {
- return;
- }
- selectedAry.push(item);
- });
- return selectedAry;
- } else if (this.datasize == '*') {
- return tmpAry;
- } else {
- return [];
- }
- },
- /**
- * 是否预定义选择器,false:不是预定义选择器,true:是预定义选择器
- */
- isPredefine: function () {
- if (this.predefine != "person" && this.predefine != "department" && this.predefine != "post" && this.predefine != "role") {
- return false; // 不是预定义选择器
- } else {
- return true; // 预定义选择器
- }
- },
- /**
- * 获取预定义的服务
- */
- getPredefineService: function () {
- var map = new Map();
- map.set("person", "/apps?ark=personnel.person_getChoolsePersonInfoApi");
- map.set("department", "/apps?ark=sys.department_getChoolseDepartmentInfoApi");
- map.set("post", "/apps?ark=sys.post_getChoolsePostInfoApi");
- map.set("role", "/apps?ark=sys.role_getChoolseRoleInfoApi");
- return map.get(this.predefine);
- },
- /**
- * 初始化选择数据集合
- */
- initSelectedDataList: function () {
- if (!this.isPredefine() || this.method) {
- return;
- }
- if (!this.modelAry || this.modelAry.length == 0) {
- this.isOpen = false; // 没有数据时,则关闭
- return;
- }
- var url = this.getPredefineService();
- var ids = typeof (this.modelAry) == 'string' || typeof (this.modelAry) == 'number' ? this.modelAry : this.modelAry.join(',');
- var _this = this;
- // 查询选中的列表
- space.utils.ajax({
- url: url,
- data: {
- "ids": ids
- },
- dataType: 'json',
- callback: function (data) {
- _this.options = data.data;
- var tmpAry = _this.getMaxSelectedModelAry();
- _this.$emit("input", tmpAry);
- }
- })
- },
- },
- template: `
- <div class="space-select" :id="id" >
- <el-select class="choose-obj" v-model="modelAry" multiple placeholder="请选择" :value-key="id" clearable
- :popper-append-to-body="false" style="width: calc(100% - 60px);" :disabled="!modelAry.length>0" @remove-tag="removeFun" @clear="removeFun">
- <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
- </el-option>
- </el-select>
- <el-button type="button" size="medium" class="choose-btn" :id="'choose' + predefine + randomNum" icon="el-icon-search"></el-button>
- </div>
- `
- })
- /**
- * Editor 编辑器
- */
- Vue.component('spaceEditor', {
- data: function () {
- return {
- id: "spaceEditor" + space.utils.random(6),
- editor: undefined,
- // 编辑器需要的 js 文件
- jsUrl: [
- '/apps/space/plug-in/ckeditor5/build/ckeditor.js',
- '/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js?v=20260628-pdf'
- ],
- // 标识,全部为 true 则代表全部加载完成
- jsUrlFlag: [],
- notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完
- imageQuality: 'standard',
- uploading: false,
- uploadStatus: '',
- previewVisible: false,
- previewMode: 'pc',
- previewUrl: '',
- previewLoading: false,
- videoPlaybackSyncTimer: undefined,
- }
- },
- name: "spaceEditor",
- model: {
- prop: 'htmlContent',
- evnet: 'click'
- },
- /**
- * htmlContent: v-model 绑定的值,非空,html 字符串
- * size: 编辑器的大小,small、medium、large
- * width: 编辑器的宽度,可空
- * height: 编辑器的高度,可空
- * placeholder:占位符
- * type:编辑器工具栏类型
- * isfullscreen:是否有全屏,
- */
- props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl'],
- computed: {
- previewFrameStyle: function () {
- var widthMap = {
- pc: '1200px',
- pad: '768px',
- mobile: '390px'
- };
- return {
- width: widthMap[this.previewMode] || widthMap.pc,
- height: '680px'
- };
- }
- },
- watch: {
- height: function (newVal, oldVal) {
- if (this.height && this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
- this.height += 'px';
- } else {
- this.setEditorHeight();
- }
- },
- editor: function (newVal, oldVal) {
- this.setEditorHeight();
- },
- jsUrlFlag: function (newVal, oldVal) {
- if (this.jsUrl.length > 0 && this.jsUrl.length == this.jsUrlFlag.length) {
- if (this.jsUrlFlag.indexOf('false') != -1) {
- return;
- }
- this.initEditor();
- this.notLoadEditor = false;
- this.setEditorHeight();
- }
- },
- notLoadEditor: function (newVal, oldVal) {
- this.setEditorHeight();
- },
- },
- created: function () {
- var _this = this;
- for (var i = 0; i < _this.jsUrl.length; i++) {
- _this.loadJS(_this.jsUrl[i], function () {
- _this.jsUrlFlag.push('true');
- });
- }
- },
- methods: {
- loadJS: function (url, callback) {
- for (var i = 0; i < document.getElementsByTagName('head')[0].getElementsByTagName('script').length; i++) {
- var src = document.getElementsByTagName('head')[0].getElementsByTagName('script')[i].getAttribute('src');
- if (url == src) {
- // 防止一个页面有多个编辑器时,编辑器加载失败
- if (space.vars.editorReady != true) {
- var winInterval = setInterval(function () {
- if (space.vars.editorReady != true) {
- return;
- }
- window.clearInterval(winInterval);
- if (callback) {
- callback();
- }
- }, 100)
- }
- return;
- }
- }
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.onload = function () {
- if (callback) {
- callback();
- }
- };
- script.src = url;
- document.getElementsByTagName('head')[0].appendChild(script);
- },
- isArticlePreview: function () {
- return this.articlepreview === true || this.articlepreview === 'true';
- },
- showEditorTools: function () {
- return this.type != 'flow' && this.isArticlePreview();
- },
- getUploadOptions: function () {
- return {
- imageQuality: this.imageQuality,
- imageMaxWidth: 1920,
- imageMaxSize: 20 * 1024 * 1024,
- videoMaxSize: 1024 * 1024 * 1024,
- pdfMaxSize: 100 * 1024 * 1024,
- fileMaxSize: 10 * 1024 * 1024
- };
- },
- myCustomUploadAdapterPlugin: function (editor) {
- this.installUploadAdapter(editor);
- },
- installUploadAdapter: function (editor) {
- var _this = this;
- editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
- // 第二个参数设置上传图片的地址
- return new MyUploadAdapter(loader, _this.getUploadOptions());
- };
- },
- installPdfViewerPlugin: function (editor) {
- editor.model.schema.register("spacePdfViewer", {
- isObject: true,
- allowWhere: "$block",
- allowAttributes: ["src", "title"]
- });
- var createPdfViewerView = function (modelItem, viewWriter) {
- var src = modelItem.getAttribute("src") || "";
- var title = modelItem.getAttribute("title") || "PDF文件";
- var figure = viewWriter.createContainerElement("figure", {
- "class": "space-editor-pdf-viewer media",
- "data-space-pdf": "true"
- });
- var iframe = viewWriter.createRawElement("iframe", {
- "class": "space-editor-pdf-frame",
- "src": src,
- "title": title,
- "loading": "lazy",
- "frameborder": "0"
- });
- var caption = viewWriter.createContainerElement("figcaption");
- var link = viewWriter.createContainerElement("a", {
- "href": src,
- "target": "_blank",
- "rel": "noopener"
- });
- var text = viewWriter.createText("打开 PDF:" + title);
- viewWriter.insert(viewWriter.createPositionAt(link, 0), text);
- viewWriter.insert(viewWriter.createPositionAt(caption, 0), link);
- viewWriter.insert(viewWriter.createPositionAt(figure, 0), iframe);
- viewWriter.insert(viewWriter.createPositionAt(figure, "end"), caption);
- return figure;
- };
- editor.conversion.for("editingDowncast").elementToElement({
- model: "spacePdfViewer",
- view: function (modelItem, conversionApi) {
- return createPdfViewerView(modelItem, conversionApi.writer);
- }
- });
- editor.conversion.for("dataDowncast").elementToElement({
- model: "spacePdfViewer",
- view: function (modelItem, conversionApi) {
- return createPdfViewerView(modelItem, conversionApi.writer);
- }
- });
- editor.conversion.for("upcast").elementToElement({
- view: {
- name: "iframe",
- classes: "space-editor-pdf-frame"
- },
- model: function (viewElement, conversionApi) {
- return conversionApi.writer.createElement("spacePdfViewer", {
- src: viewElement.getAttribute("src") || "",
- title: viewElement.getAttribute("title") || "PDF文件"
- });
- }
- });
- },
- uploadPlainFileByAdapter: function (file, options, onProgress) {
- if (typeof MyUploadAdapter == "undefined") {
- return Promise.reject("上传组件未加载完成,请刷新页面后重试");
- }
- if (typeof MyUploadAdapter.uploadPlainFile == "function") {
- return MyUploadAdapter.uploadPlainFile(file, options, onProgress);
- }
- var adapter = new MyUploadAdapter(null, options || {});
- if (typeof adapter.uploadPlainFile == "function") {
- return adapter.uploadPlainFile(file, onProgress);
- }
- return Promise.reject("上传组件未加载完成,请刷新页面后重试");
- },
- /**
- * 获取高度
- */
- getHeight: function () {
- if (!this.height) {
- if (this.size == undefined || this.size == "small") {
- return '200px';
- } else if (this.size == "medium") {
- return '400px';
- } else if (this.size == "large") {
- return '600px';
- }
- } else if (this.height) {
- if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
- return this.height + 'px';
- } else {
- return this.height;
- }
- }
- return "";
- },
- /**
- * 设置编辑器高度
- */
- setEditorHeight: function () {
- if (this.notLoadEditor) {
- return;
- }
- var height = this.getHeight();
- if (!this.editor || !height) {
- return;
- }
- var _this = this;
- // 设置编辑器高度
- _this.editor.editing.view.change(writer => {
- writer.setStyle(
- "height",
- height,
- _this.editor.editing.view.document.getRoot()
- );
- });
- },
- /**
- * 获取工具栏
- */
- getToolbar: function () {
- var items = [];
- // 是否有全屏工具
- if (this.isfullscreen == false) {
- // 没有全屏工具栏
- items = [
- 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
- 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo'
- ];
- } else {
- items = [
- 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'blockQuote', 'bold', 'italic', 'link', '|',
- 'alignment', 'horizontalLine', '|', 'indent', 'outdent', '|', 'imageUpload', 'wordUpload', 'insertTable', 'mediaEmbed', 'phrase', 'undo', 'redo', 'fullScreen'
- ];
- }
- var toolbar = {
- items: items
- };
- if (!this.type) {
- return toolbar;
- }
- var map = new Map();
- map.set("flow", ['phrase']);
- if (map.get(this.type)) {
- return {
- items: map.get(this.type)
- }
- }
- return toolbar;
- },
- alignFullScreenToolbarButton: function () {
- if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
- return;
- }
- var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
- if (!toolbarItems) {
- return;
- }
- var buttons = toolbarItems.querySelectorAll(".ck-button");
- for (var i = 0; i < buttons.length; i++) {
- var label = (buttons[i].getAttribute("aria-label") || buttons[i].getAttribute("title") || buttons[i].textContent || "").replace(/\s/g, "");
- if (label.indexOf("全屏") != -1) {
- buttons[i].style.marginLeft = "auto";
- toolbarItems.appendChild(buttons[i]);
- return;
- }
- }
- },
- mountVideoUploadToolbarButton: function (retryCount) {
- if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
- return;
- }
- var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
- if (!toolbarItems) {
- return;
- }
- if (toolbarItems.querySelector(".space-editor-video-upload-ck-button")) {
- return;
- }
- var dropdowns = toolbarItems.querySelectorAll(".ck-dropdown");
- var mediaDropdown = null;
- for (var i = 0; i < dropdowns.length; i++) {
- var button = dropdowns[i].querySelector(".ck-button");
- var label = button ? (button.getAttribute("aria-label") || button.getAttribute("title") || button.textContent || "") : "";
- label = label.replace(/\s/g, "").toLowerCase();
- if (label.indexOf("媒体") != -1 || label.indexOf("media") != -1) {
- mediaDropdown = dropdowns[i];
- break;
- }
- }
- if (!mediaDropdown) {
- if ((retryCount || 0) < 3) {
- var _this = this;
- setTimeout(function () {
- _this.mountVideoUploadToolbarButton((retryCount || 0) + 1);
- }, 200);
- }
- return;
- }
- var _this = this;
- var videoButton = document.createElement("button");
- videoButton.type = "button";
- videoButton.className = "ck ck-button ck-off space-editor-video-upload-ck-button";
- videoButton.setAttribute("aria-label", "上传视频");
- videoButton.setAttribute("title", "上传视频");
- 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>';
- videoButton.addEventListener("click", function (event) {
- event.preventDefault();
- event.stopPropagation();
- _this.openVideoPicker();
- });
- mediaDropdown.classList.add("space-editor-media-link-dropdown");
- mediaDropdown.parentNode.insertBefore(videoButton, mediaDropdown);
- },
- mountPdfUploadToolbarButton: function (retryCount) {
- if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
- return;
- }
- var toolbarItems = this.editor.ui.view.element.querySelector(".ck-toolbar__items");
- if (!toolbarItems) {
- return;
- }
- if (toolbarItems.querySelector(".space-editor-pdf-upload-ck-button")) {
- return;
- }
- var dropdowns = toolbarItems.querySelectorAll(".ck-dropdown");
- var mediaDropdown = null;
- for (var i = 0; i < dropdowns.length; i++) {
- var button = dropdowns[i].querySelector(".ck-button");
- var label = button ? (button.getAttribute("aria-label") || button.getAttribute("title") || button.textContent || "") : "";
- label = label.replace(/\s/g, "").toLowerCase();
- if (label.indexOf("媒体") != -1 || label.indexOf("media") != -1) {
- mediaDropdown = dropdowns[i];
- break;
- }
- }
- if (!mediaDropdown) {
- if ((retryCount || 0) < 3) {
- var _this = this;
- setTimeout(function () {
- _this.mountPdfUploadToolbarButton((retryCount || 0) + 1);
- }, 200);
- }
- return;
- }
- var _this = this;
- var pdfButton = document.createElement("button");
- pdfButton.type = "button";
- pdfButton.className = "ck ck-button ck-off space-editor-upload-ck-button space-editor-pdf-upload-ck-button";
- pdfButton.setAttribute("aria-label", "上传PDF");
- pdfButton.setAttribute("title", "上传PDF");
- pdfButton.innerHTML = '<svg class="ck ck-icon ck-button__icon space-editor-pdf-upload-icon" viewBox="0 0 20 20" aria-hidden="true"><path d="M4 1.8h7.2L16 6.6v11.6H4V1.8zm7.6 1.9v3.5h3.5L11.6 3.7zM6 9.4h8v1.4H6V9.4zm0 2.7h8v1.4H6v-1.4zm0 2.7h5.2v1.4H6v-1.4z"></path><path d="M7.1 6.9h1.3c.8 0 1.3-.4 1.3-1.1 0-.7-.5-1.1-1.3-1.1H6v3.9h1.1V6.9zm0-.8v-.6h1.1c.2 0 .4.1.4.3 0 .2-.1.3-.4.3H7.1z"></path></svg><span class="ck ck-button__label">上传PDF</span>';
- pdfButton.addEventListener("click", function (event) {
- event.preventDefault();
- event.stopPropagation();
- _this.openPdfPicker();
- });
- mediaDropdown.classList.add("space-editor-media-link-dropdown");
- mediaDropdown.parentNode.insertBefore(pdfButton, mediaDropdown);
- },
- formatContent: function () {
- if (!this.editor) {
- return;
- }
- var html = this.editor.getData();
- if (space.utils.isNull(html)) {
- space.message.warning("正文内容为空");
- return;
- }
- var wrapper = document.createElement("div");
- wrapper.innerHTML = html;
- var all = wrapper.querySelectorAll("*");
- for (var i = 0; i < all.length; i++) {
- var node = all[i];
- node.removeAttribute("lang");
- node.removeAttribute("width");
- node.removeAttribute("height");
- node.removeAttribute("onload");
- node.removeAttribute("border");
- node.removeAttribute("vspace");
- node.removeAttribute("hspace");
- var style = node.getAttribute("style") || "";
- if (/mso-|font-family|text-indent:\s*0|background:\s*transparent/i.test(style)) {
- node.removeAttribute("style");
- }
- }
- var inlineNodes = wrapper.querySelectorAll("span, font");
- for (var s = inlineNodes.length - 1; s >= 0; s--) {
- var inlineNode = inlineNodes[s];
- if (inlineNode.attributes.length == 0 && inlineNode.parentNode) {
- while (inlineNode.firstChild) {
- inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
- }
- inlineNode.parentNode.removeChild(inlineNode);
- }
- }
- var emptyBlocks = wrapper.querySelectorAll("p, div");
- for (var e = emptyBlocks.length - 1; e >= 0; e--) {
- var block = emptyBlocks[e];
- var hasMedia = block.querySelector("img, video, iframe, object, embed, table, .space-editor-pdf-viewer");
- var text = (block.textContent || "").replace(/\u00a0/g, "").trim();
- if (!hasMedia && text == "" && block.parentNode) {
- block.parentNode.removeChild(block);
- }
- }
- var headings = wrapper.querySelectorAll("h1, h2, h3, h4, h5, h6");
- for (var headingIndex = 0; headingIndex < headings.length; headingIndex++) {
- headings[headingIndex].style.textAlign = "center";
- headings[headingIndex].style.textIndent = "0";
- }
- var findFirstTextNode = function (node) {
- for (var child = node.firstChild; child; child = child.nextSibling) {
- if (child.nodeType == 3 && child.nodeValue.replace(/[\s\u00a0\u3000]/g, "") != "") {
- return child;
- }
- if (child.nodeType == 1 && !/^(img|video|iframe|object|embed|table)$/i.test(child.tagName)) {
- var textNode = findFirstTextNode(child);
- if (textNode) {
- return textNode;
- }
- }
- }
- return null;
- };
- var trimFirstTextIndent = function (node) {
- var textNode = findFirstTextNode(node);
- if (textNode) {
- textNode.nodeValue = textNode.nodeValue.replace(/^[\s\u00a0\u3000]+/, "");
- }
- };
- var textBlocks = wrapper.querySelectorAll("p, div");
- for (var blockIndex = 0; blockIndex < textBlocks.length; blockIndex++) {
- var textBlock = textBlocks[blockIndex];
- var blockHasMedia = textBlock.querySelector("img, video, iframe, object, embed, table, .space-editor-pdf-viewer");
- var blockText = (textBlock.textContent || "").replace(/\u00a0/g, "").trim();
- if (blockHasMedia) {
- textBlock.style.textAlign = "center";
- textBlock.style.textIndent = "0";
- } else if (blockText != "") {
- textBlock.style.textAlign = "justify";
- textBlock.style.textIndent = "2em";
- textBlock.style.lineHeight = "1.8";
- trimFirstTextIndent(textBlock);
- }
- }
- var images = wrapper.querySelectorAll("img");
- for (var imgIndex = 0; imgIndex < images.length; imgIndex++) {
- images[imgIndex].style.maxWidth = "100%";
- images[imgIndex].style.height = "auto";
- images[imgIndex].style.display = "block";
- images[imgIndex].style.margin = "12px auto";
- }
- var videos = wrapper.querySelectorAll("video, iframe, object, embed");
- for (var v = 0; v < videos.length; v++) {
- videos[v].style.maxWidth = "100%";
- if (videos[v].tagName.toLowerCase() == "video") {
- videos[v].setAttribute("controls", "controls");
- videos[v].setAttribute("playsinline", "playsinline");
- videos[v].style.display = "block";
- videos[v].style.margin = "12px auto";
- }
- }
- var tables = wrapper.querySelectorAll("table");
- for (var t = 0; t < tables.length; t++) {
- tables[t].style.width = "100%";
- tables[t].style.borderCollapse = "collapse";
- }
- this.editor.setData(wrapper.innerHTML);
- this.$emit("input", this.editor.getData());
- this.deferSyncEditorPlayableVideos();
- space.message.success("正文已完成排版整理");
- },
- insertHtml: function (html) {
- if (!this.editor || space.utils.isNull(html)) {
- return;
- }
- var viewFragment = this.editor.data.processor.toView(html);
- var modelFragment = this.editor.data.toModel(viewFragment);
- this.editor.model.insertContent(modelFragment);
- this.$emit("input", this.editor.getData());
- this.deferSyncEditorPlayableVideos();
- },
- escapeHtmlAttr: function (value) {
- return String(value || "").replace(/[&<>"']/g, function (text) {
- return {
- "&": "&",
- "<": "<",
- ">": ">",
- "\"": """,
- "'": "'"
- }[text];
- });
- },
- normalizeLocalUploadUrl: function (url) {
- var text = String(url || "").trim().replace(/\\/g, "/");
- var match = text.match(/^(?:https?:)?\/\/[^/]*(\/web\/upload\/.*)$/i);
- if (match) {
- text = match[1];
- }
- text = text.replace(/^(https?:)\/+(\/web\/upload\/.*)$/i, "$2");
- text = text.replace(/(\/web\/upload\/modules)\/+/i, "$1/");
- return text;
- },
- toAbsoluteEditorMediaUrl: function (url) {
- var text = String(url || "").trim();
- if (/^(https?:)?\/\//i.test(text) || /^(data|blob):/i.test(text)) {
- return text;
- }
- if (text.charAt(0) == "/") {
- return window.location.origin + text;
- }
- return text;
- },
- openVideoPicker: function () {
- if (this.$refs.videoInput) {
- this.$refs.videoInput.click();
- }
- },
- openPdfPicker: function () {
- if (this.$refs.pdfInput) {
- this.$refs.pdfInput.click();
- }
- },
- handleVideoSelect: function (event) {
- var files = Array.prototype.slice.call(event.target.files || []);
- event.target.value = "";
- if (files.length > 0) {
- this.uploadVideoFile(files[0]);
- }
- },
- handlePdfSelect: function (event) {
- var files = Array.prototype.slice.call(event.target.files || []);
- event.target.value = "";
- if (files.length > 0) {
- this.uploadPdfFile(files[0]);
- }
- },
- isPdfFile: function (file) {
- return !!file && ((file.type && file.type.toLowerCase() == "application/pdf") || /\.pdf$/i.test(file.name || ""));
- },
- uploadVideoFile: function (file) {
- if (!file || !file.type || file.type.indexOf("video/") !== 0) {
- space.message.warning("请选择视频文件");
- return;
- }
- var _this = this;
- _this.uploading = true;
- _this.uploadStatus = "正在上传视频";
- _this.uploadPlainFileByAdapter(file, {
- imageQuality: 'origin'
- }, function (loaded, total) {
- if (total > 0) {
- _this.uploadStatus = "正在上传视频 " + Math.round(loaded * 100 / total) + "%";
- }
- }).then(function (res) {
- var videoUrl = _this.normalizeLocalUploadUrl(res.default);
- _this.insertHtml('<p><video controls playsinline preload="metadata" src="' + _this.escapeHtmlAttr(videoUrl) + '" style="max-width:100%;"></video></p>');
- _this.$emit("input", _this.editor.getData());
- space.message.success("视频已插入正文");
- }).catch(function (msg) {
- space.message.error(msg || "视频上传失败");
- }).finally(function () {
- _this.uploading = false;
- _this.uploadStatus = "";
- });
- },
- uploadPdfFile: function (file) {
- if (!this.isPdfFile(file)) {
- space.message.warning("请选择PDF文件");
- return;
- }
- var _this = this;
- _this.uploading = true;
- _this.uploadStatus = "正在上传PDF";
- _this.uploadPlainFileByAdapter(file, {
- imageQuality: 'origin',
- pdfMaxSize: 100 * 1024 * 1024
- }, function (loaded, total) {
- if (total > 0) {
- _this.uploadStatus = "正在上传PDF " + Math.round(loaded * 100 / total) + "%";
- }
- }).then(function (res) {
- var pdfUrl = _this.normalizeLocalUploadUrl(res.default);
- _this.insertPdfViewer(pdfUrl, file.name);
- _this.$emit("input", _this.editor.getData());
- space.message.success("PDF已插入正文");
- }).catch(function (msg) {
- space.message.error(msg || "PDF上传失败");
- }).finally(function () {
- _this.uploading = false;
- _this.uploadStatus = "";
- });
- },
- buildPdfViewerHtml: function (url, fileName) {
- var safeUrl = this.escapeHtmlAttr(url);
- var safeName = this.escapeHtmlAttr(fileName || "PDF文件");
- return '<figure class="space-editor-pdf-viewer media" data-space-pdf="true">'
- + '<iframe class="space-editor-pdf-frame" src="' + safeUrl + '" title="' + safeName + '" loading="lazy"></iframe>'
- + '<figcaption><a href="' + safeUrl + '" target="_blank" rel="noopener">打开 PDF:' + safeName + '</a></figcaption>'
- + '</figure><p></p>';
- },
- insertPdfViewer: function (url, fileName) {
- if (!this.editor || space.utils.isNull(url)) {
- return;
- }
- var title = fileName || "PDF文件";
- try {
- this.editor.model.change(function (writer) {
- var pdfViewer = writer.createElement("spacePdfViewer", {
- src: url,
- title: title
- });
- this.editor.model.insertContent(pdfViewer);
- }.bind(this));
- this.$emit("input", this.editor.getData());
- this.deferSyncEditorPlayableVideos();
- return;
- } catch (e) {
- console.log(e);
- }
- if (this.editor.commands && this.editor.commands.get("mediaEmbed")) {
- this.editor.execute("mediaEmbed", this.toAbsoluteEditorMediaUrl(url));
- this.deferSyncEditorPlayableVideos();
- return;
- }
- this.insertHtml(this.buildPdfViewerHtml(url, title));
- },
- buildPdfLinkHtml: function (url, fileName) {
- var safeUrl = this.escapeHtmlAttr(url);
- var safeName = this.escapeHtmlAttr(fileName || "PDF文件");
- return '<p class="space-editor-pdf-link"><a href="' + safeUrl
- + '" target="_blank" rel="noopener">打开 PDF:' + safeName + '</a></p>';
- },
- upgradePdfLinksToViewers: function () {
- if (!this.editor) {
- return;
- }
- var data = this.editor.getData();
- if (data.indexOf(".pdf") == -1) {
- return;
- }
- var wrapper = document.createElement("div");
- wrapper.innerHTML = data;
- var links = wrapper.querySelectorAll(".space-editor-pdf-link a[href], a[href]");
- var changed = false;
- for (var i = 0; i < links.length; i++) {
- var link = links[i];
- var href = link.getAttribute("href") || "";
- var text = (link.textContent || "").replace(/\s+/g, " ").trim();
- var isPdf = /\.pdf(\?.*)?$/i.test(href);
- var isEditorPdfLink = link.closest(".space-editor-pdf-link") || /^打开\s*PDF[::]/i.test(text);
- if (!isPdf || !isEditorPdfLink) {
- continue;
- }
- var title = text.replace(/^打开\s*PDF[::]\s*/i, "") || href.split("/").pop() || "PDF文件";
- var holder = document.createElement("div");
- holder.innerHTML = this.buildPdfViewerHtml(href, title);
- var viewer = holder.firstElementChild;
- var replaceTarget = link.closest(".space-editor-pdf-link") || link.parentNode;
- if (viewer && replaceTarget && replaceTarget.parentNode) {
- replaceTarget.parentNode.replaceChild(viewer, replaceTarget);
- changed = true;
- }
- }
- if (changed) {
- this.editor.setData(wrapper.innerHTML);
- this.$emit("input", this.editor.getData());
- this.deferSyncEditorPlayableVideos();
- }
- },
- bindVideoPasteUpload: function () {
- if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
- return;
- }
- var editable = this.editor.ui.getEditableElement();
- if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
- return;
- }
- editable.setAttribute("data-space-video-upload", "true");
- var _this = this;
- var handler = function (event) {
- var dataTransfer = event.clipboardData || event.dataTransfer;
- if (!dataTransfer || !dataTransfer.files || dataTransfer.files.length == 0) {
- return;
- }
- var files = Array.prototype.slice.call(dataTransfer.files);
- var videoFile = files.find(function (file) {
- return file && file.type && file.type.indexOf("video/") === 0;
- });
- var pdfFile = files.find(function (file) {
- return _this.isPdfFile(file);
- });
- if (videoFile) {
- event.preventDefault();
- _this.uploadVideoFile(videoFile);
- } else if (pdfFile) {
- event.preventDefault();
- _this.uploadPdfFile(pdfFile);
- }
- };
- editable.addEventListener("paste", handler);
- editable.addEventListener("drop", handler);
- },
- findClosestEditorMedia: function (target) {
- if (!target) {
- return null;
- }
- if (target.nodeType == 3) {
- target = target.parentNode;
- }
- if (!target || target.nodeType != 1) {
- return null;
- }
- if (/^(video|iframe)$/i.test(target.tagName)) {
- return target;
- }
- if (target.closest) {
- return target.closest("video, iframe");
- }
- return null;
- },
- prepareEditorPlayableMedia: function (media) {
- if (!media || media.nodeType != 1) {
- return;
- }
- var tagName = (media.tagName || "").toLowerCase();
- if (tagName == "video") {
- media.setAttribute("controls", "controls");
- media.setAttribute("playsinline", "playsinline");
- media.setAttribute("webkit-playsinline", "webkit-playsinline");
- if (!media.getAttribute("preload")) {
- media.setAttribute("preload", "metadata");
- }
- }
- media.classList.add("space-editor-playable-media");
- var mediaWidget = media.closest ? media.closest("figure.media") : null;
- if (mediaWidget) {
- mediaWidget.classList.add("space-editor-playable-media-widget");
- }
- },
- bindPlayableMediaNativeEvents: function (media) {
- if (!media || media.getAttribute("data-space-playable-media-bound") == "true") {
- return;
- }
- this.prepareEditorPlayableMedia(media);
- media.setAttribute("data-space-playable-media-bound", "true");
- var _this = this;
- var stopWidgetSelection = function (event) {
- _this.prepareEditorPlayableMedia(media);
- event.stopPropagation();
- };
- var eventNames = ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"];
- for (var i = 0; i < eventNames.length; i++) {
- media.addEventListener(eventNames[i], stopWidgetSelection);
- }
- },
- syncEditorPlayableVideos: function () {
- if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
- return;
- }
- var editable = this.editor.ui.getEditableElement();
- if (!editable) {
- return;
- }
- var medias = editable.querySelectorAll("video, iframe");
- for (var i = 0; i < medias.length; i++) {
- this.bindPlayableMediaNativeEvents(medias[i]);
- }
- },
- deferSyncEditorPlayableVideos: function () {
- if (this.videoPlaybackSyncTimer) {
- window.clearTimeout(this.videoPlaybackSyncTimer);
- }
- var _this = this;
- this.videoPlaybackSyncTimer = window.setTimeout(function () {
- _this.syncEditorPlayableVideos();
- _this.videoPlaybackSyncTimer = undefined;
- }, 0);
- },
- bindEditorVideoPlayback: function () {
- if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
- return;
- }
- var editable = this.editor.ui.getEditableElement();
- if (!editable || editable.getAttribute("data-space-playable-media-root") == "true") {
- this.syncEditorPlayableVideos();
- return;
- }
- editable.setAttribute("data-space-playable-media-root", "true");
- var _this = this;
- var stopNativeWidgetSelection = function (event) {
- var media = _this.findClosestEditorMedia(event.target);
- if (!media) {
- return;
- }
- _this.prepareEditorPlayableMedia(media);
- event.stopPropagation();
- };
- ["pointerdown", "pointerup", "mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
- editable.addEventListener(eventName, stopNativeWidgetSelection);
- });
- if (this.editor.editing && this.editor.editing.view && this.editor.editing.view.document) {
- ["mousedown", "mouseup", "click", "dblclick", "touchstart", "touchend"].forEach(function (eventName) {
- _this.editor.editing.view.document.on(eventName, function (evt, data) {
- var domTarget = data ? (data.domTarget || (data.domEvent ? data.domEvent.target : null)) : null;
- var media = _this.findClosestEditorMedia(domTarget);
- if (!media) {
- return;
- }
- _this.prepareEditorPlayableMedia(media);
- evt.stop();
- }, { priority: "highest" });
- });
- }
- this.syncEditorPlayableVideos();
- },
- getPreviewPostData: function () {
- var data = this.previewdata || {};
- return {
- title: data.title || '',
- source: data.source || '',
- navigationid: data.navigationid || '',
- desc: data.desc || '',
- body: this.editor ? this.editor.getData() : (this.htmlContent || '')
- };
- },
- openArticlePreview: function () {
- if (!this.editor) {
- return;
- }
- var postData = this.getPreviewPostData();
- if (space.utils.isNull(postData.navigationid)) {
- space.message.warning("请先选择发布栏目");
- return;
- }
- if (space.utils.isNull(postData.body)) {
- space.message.warning("正文内容为空");
- return;
- }
- var _this = this;
- _this.previewLoading = true;
- $.ajax({
- url: _this.previewurl || "/apps?ark=website.article_preview",
- type: "POST",
- data: postData,
- dataType: "json",
- success: function (res) {
- if (res.code != "success") {
- space.message.error(res.msg || "生成预览失败");
- return;
- }
- var data = res.data || {};
- var baseUrl = data.url || data.previewUrl || "";
- if (space.utils.isNull(baseUrl)) {
- space.message.error("生成预览失败");
- return;
- }
- _this.previewUrl = baseUrl + (baseUrl.indexOf("?") == -1 ? "?" : "&") + "_t=" + new Date().getTime();
- _this.previewVisible = true;
- },
- error: function () {
- space.message.error("生成预览失败");
- },
- complete: function () {
- _this.previewLoading = false;
- }
- });
- },
- setPreviewMode: function (mode) {
- this.previewMode = mode || 'pc';
- },
- handlePreviewFrameLoad: function (event) {
- var frame = event ? event.target : null;
- var _this = this;
- this.scrollPreviewFrameToArticle(frame);
- window.setTimeout(function () {
- _this.scrollPreviewFrameToArticle(frame);
- }, 220);
- },
- scrollPreviewFrameToArticle: function (frame) {
- if (!frame || !frame.contentWindow || !frame.contentWindow.document) {
- return;
- }
- try {
- var doc = frame.contentWindow.document;
- var target = doc.querySelector('.article-header')
- || doc.querySelector('article[class*="article-panel"]')
- || doc.querySelector('.article-body')
- || doc.querySelector('main');
- if (!target) {
- return;
- }
- var top = target.getBoundingClientRect().top + frame.contentWindow.pageYOffset - 24;
- frame.contentWindow.scrollTo(0, top > 0 ? top : 0);
- } catch (e) {
- console.log(e);
- }
- },
- /**
- * 初始化编辑器
- */
- initEditor: function () {
- var toolbar = this.getToolbar();
- var _this = this;
- ClassicEditor.create(document.querySelector("#" + _this.id), {
- extraPlugins: [function (editor) {
- _this.installUploadAdapter(editor);
- _this.installPdfViewerPlugin(editor);
- }], // 添加上传适配器
- toolbar: toolbar || {},
- language: 'zh-cn',
- placeholder: _this.placeholder || '',
- mediaEmbed: {
- previewsInData: true,
- providers: [{
- name: 'spaceVideo',
- url: [
- /\.(mp4|webm|ogg)(\?.*)?$/i
- ],
- html: match => {
- const input = match['input'];
- return (
- `<video controls playsinline preload="metadata" src="${input}" style="max-width:100%;"></video>`
- );
- }
- }, {
- name: 'spacePdf',
- url: [
- /\.pdf(\?.*)?$/i
- ],
- html: match => {
- const input = match['input'];
- return (
- `<iframe class="space-editor-pdf-frame" src="${input}" title="PDF文件" loading="lazy" frameborder="0"></iframe>`
- );
- }
- }, {
- name: 'myprovider',
- url: [
- /^lizzy.*\.com.*\/media\/(\w+)/,
- /^www\.lizzy.*/,
- /^.*/
- ],
- html: match => {
- //获取媒体url
- const input = match['input'];
- return (
- `<iframe src="${input}" allowFullScreen="true" frameborder="0"></iframe>`
- );
- }
- }]
- }
- }).then(editor => {
- space.vars.editorReady = true;
- _this.editor = editor;
- _this.alignFullScreenToolbarButton();
- _this.mountVideoUploadToolbarButton();
- _this.mountPdfUploadToolbarButton();
- _this.bindVideoPasteUpload();
- _this.bindEditorVideoPlayback();
- if (_this.htmlContent != undefined) {
- _this.editor.setData(_this.htmlContent);
- _this.upgradePdfLinksToViewers();
- _this.deferSyncEditorPlayableVideos();
- }
- window.setTimeout(function () {
- _this.upgradePdfLinksToViewers();
- }, 300);
- /**
- * 禁止在编辑器内回车事件
- */
- editor.ui.view.element.onkeydown = function (event) {
- // 回车键
- if (event.keyCode == 13) {
- event.stopPropagation();
- return false;
- }
- // tab 转空格
- if (event.keyCode == 9) {
- const model = editor.model;
- model.change(writer => {
- const ele = writer.createElement('span');
- writer.insertText(" ", ele);
- // 一定要 Element
- model.insertContent(ele);
- });
- event.stopPropagation();
- return false;
- }
- _this.$emit("input", editor.getData());
- };
- // 设置编辑器宽度
- if (_this.width) {
- $(editor.ui.view.element).css({
- 'width': _this.width
- })
- }
- // 监听编辑器的内容变动事件
- editor.model.document.on('change:data', function () {
- _this.$emit("input", editor.getData());
- _this.deferSyncEditorPlayableVideos();
- });
- }).catch(error => {
- console.log(error);
- });
- }
- },
- template: `
- <div class="space-editor-wrap">
- <div class="space-editor-toolstrip" v-if="showEditorTools()">
- <el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
- <span class="space-editor-tool-divider"></span>
- <el-select class="space-editor-quality" v-model="imageQuality" size="small" placeholder="图片质量压缩" title="图片质量压缩">
- <el-option label="原图" value="origin"></el-option>
- <el-option label="高清 85%" value="high"></el-option>
- <el-option label="标准 70%" value="standard"></el-option>
- <el-option label="低流量 50%" value="low"></el-option>
- </el-select>
- <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>
- <span class="space-editor-upload-status" v-if="uploadStatus">{{uploadStatus}}</span>
- </div>
- <input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
- <input ref="pdfInput" type="file" accept="application/pdf,.pdf" style="display:none;" @change="handlePdfSelect">
- <div :id="id">
- <script type="text/plain"></script>
- </div>
- <el-dialog title="正文预览" :visible.sync="previewVisible" width="calc(100vw - 32px)" top="4vh" append-to-body custom-class="space-editor-preview-dialog">
- <div class="space-editor-preview-toolbar">
- <el-button-group class="space-editor-preview-modes">
- <el-button size="small" :type="previewMode == 'pc' ? 'primary' : 'default'" @click="setPreviewMode('pc')">PC端</el-button>
- <el-button size="small" :type="previewMode == 'pad' ? 'primary' : 'default'" @click="setPreviewMode('pad')">平板端</el-button>
- <el-button size="small" :type="previewMode == 'mobile' ? 'primary' : 'default'" @click="setPreviewMode('mobile')">手机端</el-button>
- </el-button-group>
- <el-button size="small" icon="el-icon-refresh" @click="openArticlePreview" :loading="previewLoading">刷新预览</el-button>
- </div>
- <div class="space-editor-preview-stage">
- <iframe v-if="previewUrl" :key="previewMode + previewUrl" :src="previewUrl" :style="previewFrameStyle" frameborder="0" @load="handlePreviewFrameLoad"></iframe>
- </div>
- </el-dialog>
- </div>
- `
- })
- /**
- * CMS
- */
- Vue.component('spaceCms', {
- data: function () {
- return {
- fileCount: 0, // 文件总数
- }
- },
- name: "spaceCms",
- model: {
- prop: 'cmsid',
- evnet: 'click'
- },
- props: {
- // v-model
- cmsid: {
- type: [String],
- required: true
- },
- // 文件类型
- accept: {
- type: String
- },
- // 最大上传数量,默认199
- maxsize: {
- type: [String, Number],
- default: 199
- },
- },
- created: function () {
- this.getCmsFileCount(this.cmsid);
- },
- watch: {
- cmsid: function (newVal, oldVal) {
- this.getCmsFileCount(newVal);
- }
- },
- methods: {
- open: function () {
- var that = this;
- space.plugins.cms.openCMS({
- cmsid: that.cmsid,
- accept: that.accept,
- maxsize: that.maxsize
- }, that.callback);
- },
- callback: function (data, callback2) {
- this.$emit("input", data.cmsid);
- this.cmsid = data.cmsid;
- this.fileCount = data.fileCount;
- callback2();
- },
- getCmsFileCount: function (cmsid) {
- if (space.utils.isNull(cmsid)) {
- return;
- }
- var that = this;
- space.utils.ajax({
- url: '/apps?ark=sys.cms_getCmsInfo',
- data: {
- "idcard": cmsid
- },
- dataType: 'json',
- loadLayer: false,
- autoTip: false,
- async: false, // 同步请求
- callback: function (data) {
- if (data.code == "success") {
- that.fileCount = data.data.filecount;
- }
- }
- });
- }
- },
- template: `<div class="cms-upload">
- <el-badge :value="fileCount" type="primary" v-show="fileCount > 0">
- <el-button icon="el-icon-upload2" @click="open" >上传文件</el-button>
- </el-badge>
- <el-button icon="el-icon-upload2" v-show="fileCount == 0" @click="open" >上传文件</el-button>
- </div>`
- })
- /**
- * CMS预览
- */
- Vue.component('spaceCmsView', {
- data: function () {
- return {
- thumbnail: "",
- filename: "",
- filecount: 0,
- isShowEl: true, //是否显示整个组件元素
- }
- },
- name: "spaceCmsView",
- /**
- * cmsid: 绑定的值,非空
- * thumbnail: 缩略图
- * filename: 文件名
- * filecount: 文件数
- */
- props: {
- cmsid: {
- type: [String, Number],
- required: true
- }
- },
- created: function () {
- var that = this;
- if (space.utils.isNull(that.cmsid)) {
- // 不显示整个组件元素
- that.isShowEl = false;
- return;
- }
- space.utils.ajax({
- url: '/apps?ark=sys.cms_getCmsInfo',
- data: {
- "idcard": that.cmsid
- },
- dataType: 'json',
- loadLayer: false,
- autoTip: false,
- async: false, // 同步请求
- callback: function (data) {
- if (data.code == "success") {
- that.thumbnail = data.data.thumbnail;
- that.filename = data.data.filename;
- that.filecount = data.data.filecount;
- } else if (data.code == "warning") {
- // 不显示整个组件元素
- that.isShowEl = false;
- }
- }
- });
- },
- methods: {
- open: function () {
- var that = this;
- space.plugins.cms.openCMSView({
- cmsid: that.cmsid
- });
- },
- },
- template: `
- <div class="space-cms-view" v-if="isShowEl">
- <div class="space-cms-view-wrap" @click="open">
- <div class="space-cms-view-main">
- <el-image :src="thumbnail">
- <div slot="error" class="image-slot">
- <i class="el-icon-picture-outline"></i>
- </div>
- </el-image>
- <span>{{filename}}</span>
- </div>
- <div v-show="filecount >=2 " class="more-file"></div>
- <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
- </div>
- </div>
- `
- })
- /**
- * 业务流转
- */
- Vue.component('spacePluginFlow', {
- data: function () {
- return {
- isOpenFlowDrawer: false, // 是否打开抽屉
- isLoadShow: true, // 是否显示加载动画
- frameID: space.utils.randomStringAndNumber(6) + 'Frm', // frame 窗口ID
- closeBtnID: space.utils.randomStringAndNumber(6) + 'Close', // 关闭按钮的ID
- url: '/app/flow/time/', // url
- title: '业务流转', // 标题
- closeTitle: '收起', // 关闭按钮文本内容
- }
- },
- name: "spacePluginFlow",
- /**
- * cmsid: 绑定的值,非空
- * size: 抽屉大小,可传px、%,默认30%
- */
- props: {
- audit: {
- type: String,
- required: true
- },
- apply: {
- type: String,
- required: true
- },
- open: {
- type: Boolean,
- },
- size: {
- type: String
- },
- },
- created: function () {
- this.url = this.url + "?auditid=" + this.audit + "&applyid=" + this.apply;
- this.size = space.utils.isNull(this.size) ? '360px' : this.size;
- this.isOpenFlowDrawer = space.utils.isNull(this.open) ? false : this.open;
- this.showLoad();
- },
- mounted: function () {
- var that = this;
- // 监听窗口变化,计算关闭按钮的位置
- window.onresize = function () {
- // 抽屉打开状态
- if (that.isOpenFlowDrawer) {
- that.initCloseBtnLocation();
- }
- }
- },
- methods: {
- /**
- * 计算关闭按钮的坐标
- */
- initCloseBtnLocation: function () {
- var offset = space.utils.getDomPosition(document.getElementById(this.frameID));
- $("#" + this.closeBtnID).css("left", (offset.left - $("#" + this.closeBtnID).width()) + "px");
- },
- /**
- * 显示抽屉
- */
- showDrawer: function () {
- var that = this;
- that.initCloseBtnLocation();
- $("#" + that.closeBtnID).fadeIn(200);
- // 为了更好的动画体验
- setTimeout(() => {
- $("#" + that.closeBtnID).css("z-index", "999999999999999");
- }, 200);
- },
- /**
- * 控制加载动画
- */
- showLoad: function () {
- var that = this;
- var loadInterval = setInterval(() => {
- var frameEle = document.getElementById(that.frameID);
- console.log("loadInterval");
- frameEle.onload = function () {
- window.clearInterval(loadInterval);
- that.isLoadShow = false;
- }
- }, 100);
- }
- },
- watch: {
- isOpenFlowDrawer: function (newVal, oldVal) {
- var that = this;
- // 打开
- if (newVal) {
- var getFrameInterval = setInterval(() => {
- var frameEle = document.getElementById(that.frameID);
- if (!frameEle) {
- return;
- }
- window.clearInterval(getFrameInterval);
- that.showDrawer();
- }, 200);
- }
- // 关闭
- else {
- $("#" + that.closeBtnID).hide();
- $("#" + that.closeBtnID).css("z-index", "");
- }
- },
- open: function (newVal, oldVal) {
- this.isOpenFlowDrawer = space.utils.isNull(newVal) ? false : newVal;
- }
- },
- template: `
- <div class="space-app-plugin">
- <div class="space-app-plugin-open disable-select animate__animated animate__slideInRight" v-show="!isOpenFlowDrawer" @click="isOpenFlowDrawer = true">{{title}}</div>
- <div :id="closeBtnID" class="space-app-plugin-close disable-select animate__animated animate__slideInRight" @click="isOpenFlowDrawer = false">{{closeTitle}}</div>
- <el-drawer :modal="false" :visible.sync="isOpenFlowDrawer" :size="size" :with-header="false" :wrapper-closable="false" >
- <iframe :id="frameID" :src="url"></iframe>
- <div class="space-app-plugin-load" v-show="isLoadShow" ><i class="el-icon-loading" ></i>加载中</div>
- </el-drawer>
- </div>
- `
- })
|