wangEnduit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template lang="html">
  2. <div class="editor cont">
  3. <div ref="toolbar" class="toolbar">
  4. </div>
  5. <div ref="editor" class="text">
  6. </div>
  7. <slot></slot>
  8. <div v-if="proVisible" class="mask">
  9. <div class="progressBox">
  10. <div class="lbox">
  11. <img src="../../../../assets/loading.gif" />上传中,请稍后
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import E from "wangeditor";
  19. import "../../../../common/aws-sdk-2.235.1.min";
  20. import { Loading } from 'element-ui';
  21. // import 'wangeditor/release/wangEditor.min.css'
  22. export default {
  23. name: "editoritem",
  24. data() {
  25. return {
  26. // uploadPath,
  27. editor: null,
  28. info_: null,
  29. proVisible:false,
  30. progress:0
  31. };
  32. },
  33. model: {
  34. prop: "value",
  35. event: "change",
  36. },
  37. props: {
  38. value: {
  39. type: String,
  40. default: "",
  41. },
  42. isClear: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. placeholder: {
  47. type: String,
  48. default: "请输入正文"
  49. },
  50. showGetTextLoading:{
  51. type:Boolean,
  52. default:false,
  53. }
  54. },
  55. watch: {
  56. isClear(val) {
  57. // 触发清除文本域内容
  58. if (val) {
  59. this.editor.txt.clear();
  60. this.info_ = null;
  61. }
  62. },
  63. value: function (value) {
  64. if (value !== this.editor.txt.html()) {
  65. this.editor.txt.html(this.value);
  66. }
  67. },
  68. //value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值
  69. },
  70. mounted() {
  71. this.seteditor();
  72. this.editor.txt.html(this.value);
  73. },
  74. methods: {
  75. seteditor() {
  76. this.editor = new E(this.$refs.toolbar, this.$refs.editor);
  77. // 关闭菜单栏fixed
  78. this.editor.config.menuFixed = false;
  79. // 普通的自定义菜单
  80. this.editor.config.menus = [
  81. "head", //标题
  82. "bold", //加粗
  83. "fontSize", //字体大小
  84. // "fontName", //字体
  85. // "italic", //斜体
  86. // "underline", //下划线
  87. // "strikeThrough", //删除线
  88. "indent", //缩进
  89. // "lineHeight", //行高
  90. // "foreColor",
  91. // "backColor",
  92. // "link",
  93. // "list",
  94. // "todo",
  95. "justify",
  96. // "quote",
  97. // "emoticon",
  98. "image",
  99. // "video",
  100. "table",
  101. // "code",
  102. // "splitLine",
  103. "undo",
  104. "redo",
  105. ];
  106. // 带格式粘贴
  107. this.editor.config.pasteFilterStyle = false;
  108. //忽略粘贴内容中的图片
  109. this.editor.config.pasteIgnoreImg = false;
  110. this.editor.config.showLinkImg = false;
  111. this.editor.config.placeholder = this.placeholder;
  112. var that = this;
  113. this.editor.config.customUploadImg = function (files, insert) {
  114. // const loading = Loading.service({
  115. // lock: true,
  116. // background: 'rgba(0, 0, 0, 0.7)'
  117. // });
  118. // 图片自定义上传方法
  119. var kk = 0
  120. for (var i = 0; i < files.length; i++) {
  121. var file = files[i];
  122. var credentials = {
  123. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  124. secretAccessKey: "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",
  125. }; //秘钥形式的登录上传
  126. window.AWS.config.update(credentials);
  127. window.AWS.config.region = "cn-northwest-1"; //设置区域
  128. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  129. that.proVisible = true
  130. if (file) {
  131. var params = {
  132. Key:
  133. file.name.split(".")[0] +
  134. new Date().getTime() +
  135. "." +
  136. file.name.split(".")[file.name.split(".").length - 1],
  137. ContentType: file.type,
  138. Body: file,
  139. "Access-Control-Allow-Credentials": "*",
  140. ACL: "public-read",
  141. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  142. var options = {
  143. partSize: 2048 * 1024 * 1024,
  144. queueSize: 2,
  145. leavePartsOnError: true,
  146. };
  147. bucket
  148. .upload(params, options)
  149. .on("httpUploadProgress", function (evt) {
  150. //这里可以写进度条
  151. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  152. })
  153. .send(function (err, data) {
  154. kk++
  155. if(kk == files.length - 1 || kk > files.length - 1){
  156. that.proVisible = false
  157. }
  158. // loading.close();
  159. if (err) {
  160. that.$message.error("上传失败");
  161. } else {
  162. //上传成功处理
  163. insert(data.Location);
  164. }
  165. });
  166. }
  167. }
  168. };
  169. //配置 自定义处理粘贴的文本内容
  170. this.editor.config.pasteTextHandle = function (content) {
  171. if (content == '' && !content) return ''
  172. var str = content
  173. // str = str.replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  174. str = str.replace(/<style>[\s\S]*?<\/style>/ig, '')
  175. str = str.replace(/style="[\s\S]*?"/ig, '')
  176. // str = str.replace(/<\/?[^>]*>/g, '')
  177. // str = str.replace(/[ | ]*\n/g, '\n')
  178. // str = str.replace(/&nbsp;/ig, '')
  179. // console.log('****', content)
  180. // console.log('****', str)
  181. return str
  182. };
  183. this.editor.config.onchange = (html) => {
  184. this.info_ = html; // 绑定当前逐渐地值
  185. this.$emit("change", this.info_); // 将内容同步到父组件中
  186. };
  187. // 创建富文本编辑器
  188. this.editor.create();
  189. },
  190. },
  191. };
  192. </script>
  193. <style lang="css" scoped>
  194. .editor {
  195. width: 100%;
  196. /* margin: 10px auto; */
  197. position: relative;
  198. z-index: 0;
  199. }
  200. .toolbar {
  201. border: 1px solid #ccc;
  202. }
  203. .text {
  204. border: 1px solid #ccc;
  205. height: 230px;
  206. overflow: auto;
  207. }
  208. /* table 样式 */
  209. .cont>>>table {
  210. border-top: 1px solid #ccc;
  211. border-left: 1px solid #ccc;
  212. }
  213. .cont>>>table td,
  214. .cont>>>table th {
  215. border-bottom: 1px solid #ccc;
  216. border-right: 1px solid #ccc;
  217. /* padding: 20px 5px; */
  218. padding: 5px 10px;
  219. max-width: 0px;
  220. height: 30px;
  221. vertical-align: baseline;
  222. }
  223. .cont>>>table th {
  224. border-bottom: 2px solid #ccc;
  225. text-align: center;
  226. }
  227. /* blockquote 样式 */
  228. .cont>>>blockquote {
  229. display: block;
  230. border-left: 8px solid #d0e5f2;
  231. padding: 5px 10px;
  232. margin: 10px 0;
  233. line-height: 1.4;
  234. font-size: 100%;
  235. background-color: #f1f1f1;
  236. }
  237. /* code 样式 */
  238. .cont>>>code {
  239. display: inline-block;
  240. *display: inline;
  241. *zoom: 1;
  242. background-color: #f1f1f1;
  243. border-radius: 3px;
  244. padding: 3px 5px;
  245. margin: 0 3px;
  246. }
  247. .cont>>>pre code {
  248. display: block;
  249. }
  250. /* ul ol 样式 */
  251. .cont>>>ul,
  252. ol {
  253. margin: 0 !important;
  254. }
  255. /* .cont>>>.w-e-droplist{
  256. width: 80px !important;
  257. } */
  258. .mask {
  259. background-color: rgb(0 0 0 / 30%);
  260. /* position: fixed; */
  261. position: absolute;
  262. top: 0;
  263. left: 0;
  264. width: 100%;
  265. height: 100%;
  266. z-index: 99999;
  267. display: flex;
  268. align-items: center;
  269. justify-content: center;
  270. }
  271. .mask2 {
  272. position: fixed !important;
  273. z-index: 999999;
  274. }
  275. .progressBox {
  276. width: 300px;
  277. height: 150px;
  278. background: #fff;
  279. border-radius: 10px;
  280. box-shadow: 0 0 6px 1px #bfbfbf;
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. flex-direction: column;
  285. }
  286. .progressBox .lbox {
  287. height: 100px;
  288. font-size: 16px;
  289. display: flex;
  290. align-items: center;
  291. }
  292. .progressBox .lbox img {
  293. width: 40px;
  294. margin-right: 20px;
  295. }
  296. .progressBox>>>.el-progress-bar__outer {
  297. background-color: #d1dfff !important;
  298. }
  299. .progressBox .lbox {
  300. height: 100px;
  301. font-size: 19px;
  302. display: flex;
  303. align-items: center;
  304. }
  305. .progressBox .lbox img {
  306. width: 40px;
  307. margin-right: 20px;
  308. }
  309. </style>