table.vue 6.9 KB

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