| 1 |
- (window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-4c57cedb"],{"0b77":function(t,e,i){},4715:function(t,e,i){"use strict";i("0b77")},6571:function(t,e,i){"use strict";i.r(e);var n=function(){var t=this,e=t._self._c;return e("div",{staticClass:"rich-media-editor"},[e("div",{staticClass:"content-area"},[t._l(t.contentList,(function(i,n){return e("div",{key:"block-"+n,staticClass:"content-item",class:{selected:t.selectedIndex===n},on:{click:function(e){t.selectedIndex=n}}},[1===i.type?e("div",{staticClass:"block-card"},[e("div",{staticClass:"item-header"},[e("span",{staticClass:"item-title"},[t._v("大图")]),e("div",{staticClass:"header-controls"},[e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveUp(n)}}},[t._v("上移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveDown(n)}}},[t._v("下移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveToTop(n)}}},[t._v("置顶")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.openInsertMenu(n)}}},[t._v("添加")]),e("el-button",{staticClass:"danger",attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.deleteItem(n)}}},[t._v("删除")])],1)]),e("div",{staticClass:"big-image-wrap"},[i.content?e("img",{attrs:{src:t.toShowUrl(i.content),alt:"大图"}}):e("div",{staticClass:"empty-img"},[t._v("暂无图片")])])]):2===i.type?e("div",{staticClass:"block-card"},[e("div",{staticClass:"item-header"},[e("span",{staticClass:"item-title"},[t._v("小图")]),e("div",{staticClass:"header-controls"},[e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveUp(n)}}},[t._v("上移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveDown(n)}}},[t._v("下移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveToTop(n)}}},[t._v("置顶")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.openInsertMenu(n)}}},[t._v("添加")]),e("el-button",{staticClass:"danger",attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.deleteItem(n)}}},[t._v("删除")])],1)]),e("div",{staticClass:"small-grid"},[t._l(i.content,(function(i,s){return e("div",{key:"s-"+n+"-"+s,staticClass:"small-item"},[e("img",{attrs:{src:t.toShowUrl(i),alt:""}}),e("i",{staticClass:"el-icon-close del-icon",on:{click:function(e){return e.stopPropagation(),t.removeSmallImage(n,s)}}})])})),(i.content||[]).length<15?e("div",{staticClass:"small-add",on:{click:function(e){return e.stopPropagation(),t.pickSmallImages(n)}}},[e("i",{staticClass:"el-icon-plus"}),e("span",[t._v("添加图片")])]):t._e()],2)]):e("div",{staticClass:"block-card"},[e("div",{staticClass:"item-header"},[e("span",{staticClass:"item-title"},[t._v("文字")]),e("div",{staticClass:"header-controls"},[e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveUp(n)}}},[t._v("上移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveDown(n)}}},[t._v("下移")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.moveToTop(n)}}},[t._v("置顶")]),e("el-button",{attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.openInsertMenu(n)}}},[t._v("添加")]),e("el-button",{staticClass:"danger",attrs:{type:"text",size:"mini"},on:{click:function(e){return e.stopPropagation(),t.deleteItem(n)}}},[t._v("删除")])],1)]),e("el-input",{attrs:{type:"textarea",rows:4,placeholder:"请输入文本内容..."},on:{input:t.emitChange},model:{value:i.content,callback:function(e){t.$set(i,"content",e)},expression:"item.content"}})],1)])})),t.contentList.length?t._e():e("div",{staticClass:"empty-placeholder"},[t._v("点击下方按钮开始创建内容")])],2),e("div",{staticClass:"bottom-toolbar"},[e("div",{staticClass:"toolbar-btn",on:{click:t.addBigImage}},[e("i",{staticClass:"el-icon-picture-outline"}),e("span",[t._v("大图")])]),e("div",{staticClass:"toolbar-btn",on:{click:t.addSmallImages}},[e("i",{staticClass:"el-icon-menu"}),e("span",[t._v("小图")])]),e("div",{staticClass:"toolbar-btn",on:{click:t.addText}},[e("i",{staticClass:"el-icon-edit-outline"}),e("span",[t._v("文字")])])]),e("el-dialog",{attrs:{title:"选择要添加的内容",visible:t.insertVisible,width:"360px","append-to-body":""},on:{"update:visible":function(e){t.insertVisible=e}}},[e("div",{staticClass:"insert-options"},[e("el-button",{staticClass:"opt",on:{click:t.insertBigImage}},[t._v("向下添加大图")]),e("el-button",{staticClass:"opt",on:{click:t.insertSmallImages}},[t._v("向下添加小图")]),e("el-button",{staticClass:"opt",on:{click:t.insertText}},[t._v("向下添加文字")])],1)]),e("input",{ref:"fileInput",staticStyle:{display:"none"},attrs:{type:"file",accept:"image/*",multiple:t.fileMultiple},on:{change:t.onFileChange}})],1)},s=[],a=i("f2ed"),o=i("dadb"),c=i("c91c"),l=i("9ae9"),r=(i("b15b"),i("8e72"),i("0da6"),i("b138"),i("71e2"),i("2153"),i("7212"),i("8f26"),i("666b"),i("963e"),i("209c"),i("f803"),i("4786"),i("6d35"),i("0401"),i("d27c"),i("5889"),i("b3c4"),i("adb4"),i("86d6"),i("2e12"),i("fddf"),i("51be")),p={name:"rich-media-editor",props:{value:{type:Array,default:function(){return[]}},deferDelete:{type:Boolean,default:!1}},data:function(){return{contentList:[],selectedIndex:-1,insertVisible:!1,insertAfterIndex:-1,pickMode:"",appendSmallIndex:-1,fileMultiple:!1,uploading:!1}},watch:{value:{deep:!0,immediate:!0,handler:function(t){JSON.stringify(t||[])!==JSON.stringify(this.contentList)&&(this.contentList=this.normalizeList(t||[]))}}},methods:{normalizeList:function(t){return(t||[]).map((function(t){var e=Number(t.type)||3,i=t.content;if(2===e){if("string"===typeof i)try{i=JSON.parse(i)}catch(n){i=i?[i]:[]}Array.isArray(i)||(i=[])}else i=null==i?"":i;return{type:e,content:i}}))},updateContent:function(t){this.contentList=this.normalizeList(t||[]),this.emitChange()},emitChange:function(){var t=JSON.parse(JSON.stringify(this.contentList));this.$emit("input",t),this.$emit("change",t)},toShowUrl:function(t){return t?/^https?:\/\//.test(t)?t:"".concat(r["imgHostUrl"]).concat(String(t).replace(/^\//,"")):""},normalizeShort:function(t){if(!t||"string"!==typeof t)return"";var e=t.indexOf("?"),i=e>=0?t.substring(0,e):t,n=i.match(/:\/\/[\w.-]+(:\d+)?(\/[^?#]+)$/),s="";return s=n&&n[2]?n[2]:(i.startsWith("/"),i),s.replace(/^\//,"")},moveUp:function(t){if(!(t<=0)){var e=this.contentList.splice(t,1)[0];this.contentList.splice(t-1,0,e),this.selectedIndex=t-1,this.emitChange()}},moveDown:function(t){if(!(t>=this.contentList.length-1)){var e=this.contentList.splice(t,1)[0];this.contentList.splice(t+1,0,e),this.selectedIndex=t+1,this.emitChange()}},moveToTop:function(t){if(!(t<=0)){var e=this.contentList.splice(t,1)[0];this.contentList.unshift(e),this.selectedIndex=0,this.emitChange()}},openInsertMenu:function(t){this.insertAfterIndex=t,this.insertVisible=!0},deleteItem:function(t){var e=this;this.$confirm("确定要删除这个内容项吗?","提示",{type:"warning"}).then((function(){var i=e.contentList.splice(t,1)[0];e.collectDeletePaths(i),e.selectedIndex===t&&(e.selectedIndex=-1),e.emitChange()})).catch((function(){}))},collectDeletePaths:function(t){var e=this;if(t){var i=[];1===t.type&&t.content&&i.push(t.content),2===t.type&&Array.isArray(t.content)&&t.content.forEach((function(t){return t&&i.push(t)})),i.length&&(this.deferDelete?this.$emit("collect-delete",{filePaths:i}):i.forEach((function(t){e.$service.common.deleteFile({filePath:t}).catch((function(){}))})))}},addText:function(){this.contentList.push({type:3,content:""}),this.selectedIndex=this.contentList.length-1,this.emitChange()},insertText:function(){var t=this.insertAfterIndex+1;this.contentList.splice(t,0,{type:3,content:""}),this.selectedIndex=t,this.insertVisible=!1,this.insertAfterIndex=-1,this.emitChange()},addBigImage:function(){this.pickMode="big",this.insertAfterIndex=-1,this.fileMultiple=!1,this.$refs.fileInput&&this.$refs.fileInput.click()},insertBigImage:function(){this.insertVisible=!1,this.pickMode="big",this.fileMultiple=!1,this.$refs.fileInput&&this.$refs.fileInput.click()},addSmallImages:function(){this.pickMode="small-new",this.insertAfterIndex=-1,this.appendSmallIndex=-1,this.fileMultiple=!0,this.$refs.fileInput&&this.$refs.fileInput.click()},insertSmallImages:function(){this.insertVisible=!1,this.pickMode="small-new",this.appendSmallIndex=-1,this.fileMultiple=!0,this.$refs.fileInput&&this.$refs.fileInput.click()},pickSmallImages:function(t){this.pickMode="small-append",this.appendSmallIndex=t,this.insertAfterIndex=-1,this.fileMultiple=!0,this.$refs.fileInput&&this.$refs.fileInput.click()},removeSmallImage:function(t,e){var i=this;this.$confirm("确定要删除这张图片吗?","提示",{type:"warning"}).then((function(){var n=i.contentList[t];if(n&&Array.isArray(n.content)){var s=n.content.splice(e,1),a=Object(l["a"])(s,1),o=a[0];o&&(i.deferDelete?i.$emit("collect-delete",{filePaths:[o]}):i.$service.common.deleteFile({filePath:o}).catch((function(){}))),i.emitChange()}})).catch((function(){}))},onFileChange:function(t){var e=Array.from(t.target&&t.target.files||[]);t.target.value="",e.length&&this.uploadFiles(e)},uploadFiles:function(t){var e=this;return Object(c["a"])(Object(a["a"])().m((function i(){var n,s,c,l,r,p,u,d,h;return Object(a["a"])().w((function(i){while(1)switch(i.p=i.n){case 0:if(!e.uploading){i.n=1;break}return i.a(2);case 1:e.uploading=!0,n=e.$loading({text:"上传中..."}),i.p=2,s=[],c=Object(o["a"])(t),i.p=3,c.s();case 4:if((l=c.n()).done){i.n=9;break}if(r=l.value,!(r.size/1024/1024>2)){i.n=5;break}return e.$message.warning("".concat(r.name," 超过 2M,已跳过")),i.a(3,8);case 5:return i.n=6,e.fileToBase64(r);case 6:return p=i.v,i.n=7,e.$service.common.uploadImg({content:p});case 7:u=i.v,d=e.normalizeShort(u&&(u.shortUrl||u.smallShortUrl||u.url)||"")||"",d&&s.push(d);case 8:i.n=4;break;case 9:i.n=11;break;case 10:i.p=10,h=i.v,c.e(h);case 11:return i.p=11,c.f(),i.f(11);case 12:if(s.length){i.n=13;break}return e.$message.warning("上传失败"),i.a(2);case 13:e.applyUploaded(s),i.n=15;break;case 14:i.p=14,i.v,e.$message.error("图片上传失败");case 15:return i.p=15,n.close(),e.uploading=!1,e.pickMode="",e.appendSmallIndex=-1,i.f(15);case 16:return i.a(2)}}),i,null,[[3,10,11,12],[2,14,15,16]])})))()},applyUploaded:function(t){if("big"===this.pickMode){var e={type:1,content:t[0]};this.insertAfterIndex>=0?(this.contentList.splice(this.insertAfterIndex+1,0,e),this.selectedIndex=this.insertAfterIndex+1):(this.contentList.push(e),this.selectedIndex=this.contentList.length-1)}else if("small-append"===this.pickMode&&this.appendSmallIndex>=0){var i=this.contentList[this.appendSmallIndex];i&&2===i.type&&(i.content=(i.content||[]).concat(t).slice(0,15))}else{var n={type:2,content:t.slice(0,15)};this.insertAfterIndex>=0?(this.contentList.splice(this.insertAfterIndex+1,0,n),this.selectedIndex=this.insertAfterIndex+1):(this.contentList.push(n),this.selectedIndex=this.contentList.length-1)}this.insertAfterIndex=-1,this.emitChange()},fileToBase64:function(t){return new Promise((function(e,i){var n=new FileReader;n.onload=function(){return e(n.result)},n.onerror=i,n.readAsDataURL(t)}))}}},u=p,d=(i("4715"),i("1805")),h=Object(d["a"])(u,n,s,!1,null,"4b3c422e",null);e["default"]=h.exports}}]);
|