Tinydemo.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-Record" v-if="curQue">
  4. <!-- <img
  5. src="../../../assets/adult/maikefeng-red.png"
  6. class="Big-Book-Record-icon"
  7. /> -->
  8. <div class="adult-book-input-item">
  9. <span class="adult-book-lable">标题:</span>
  10. <el-input
  11. class="adult-book-input"
  12. type="textarea"
  13. autosize
  14. placeholder="请输入标题"
  15. v-model="curQue.title"
  16. @blur="curQue.title = curQue.title.trim()"
  17. maxlength="500"
  18. show-word-limit
  19. ></el-input>
  20. </div>
  21. <div class="adult-book-input-item">
  22. <span class="adult-book-lable">图片:</span>
  23. <Upload
  24. :changeFillId="changeImage"
  25. :uploadType="'image'"
  26. :filleNumber="999"
  27. />
  28. </div>
  29. <ul v-if="curQue.img_list.length > 0" class="uploadArt_list">
  30. <li
  31. v-for="(artItem, artIndex) in curQue.img_list"
  32. :key="'articleImgList' + artIndex"
  33. >
  34. <span class="art_name">{{ artItem.name }}</span>
  35. <span v-if="artItem.url" :id="'file' + number" class="art_url"
  36. >{{ artItem.url }}
  37. <i class="el-icon-document-copy" @click="copyHttp('file' + number)"
  38. /></span>
  39. </li>
  40. </ul>
  41. <div class="main">
  42. <Editor
  43. :id="'tinydemo' + number"
  44. v-model="curQue.con"
  45. :init="init"
  46. @input="articleChange"
  47. />
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import Upload from "../common/Upload.vue";
  53. import tinymce from "tinymce/tinymce";
  54. import Editor from "@tinymce/tinymce-vue";
  55. import "tinymce/icons/default/icons";
  56. import "tinymce/themes/silver";
  57. // 引入富文本编辑器主题的js和css
  58. import "tinymce/themes/silver/theme.min";
  59. import "tinymce/skins/ui/oxide/skin.min.css";
  60. // 扩展插件
  61. // import "tinymce/plugins/"
  62. import "tinymce/plugins/image";
  63. import "tinymce/plugins/link";
  64. import "tinymce/plugins/code";
  65. import "tinymce/plugins/table";
  66. import "tinymce/plugins/lists";
  67. import "tinymce/plugins/wordcount"; // 字数统计插件
  68. import "tinymce/plugins/media"; // 插入视频插件
  69. import "tinymce/plugins/template"; // 模板插件
  70. import "tinymce/plugins/fullscreen";
  71. import "tinymce/plugins/paste";
  72. import "tinymce/plugins/preview";
  73. import "tinymce/plugins/contextmenu";
  74. import "tinymce/plugins/textcolor";
  75. import "tinymce/plugins/colorpicker";
  76. import { CopyToClipboard } from "@/utils/auth";
  77. export default {
  78. components: { Editor, Upload },
  79. props: ["curQue", "fn_data", "changeCurQue", "number"],
  80. data() {
  81. return {
  82. init: {
  83. language_url: `/tinymce/langs/zh_CN.js`,
  84. language: "zh_CN",
  85. skin_url: "/tinymce/skins/ui/oxide",
  86. height: 500,
  87. plugins: "link lists image code table wordcount preview",
  88. toolbar:
  89. "preview bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote | undo redo | link unlink image code | removeformat",
  90. branding: false,
  91. ax_wordlimit_num: 50,
  92. ax_wordlimit_callback: function (editor, txt, num) {
  93. tipsJS("当前字数:" + txt.length + ",限制字数:" + num);
  94. },
  95. }, //富文本初始化
  96. data_structure: {
  97. type: "tinydemo",
  98. name: "富文本",
  99. title: "",
  100. con: "",
  101. img_list: [],
  102. },
  103. };
  104. },
  105. computed: {},
  106. watch: {},
  107. //方法集合
  108. methods: {
  109. copyHttp(id) {
  110. CopyToClipboard(id, this);
  111. },
  112. changeImage(fileList, items, index) {
  113. const articleImgList = JSON.parse(JSON.stringify(fileList));
  114. const articleImgRes = [];
  115. articleImgList.forEach((item) => {
  116. if (item.response) {
  117. const obj = {
  118. name: item.name,
  119. url: item.response.file_info_list[0].file_url,
  120. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  121. };
  122. articleImgRes.push(obj);
  123. }
  124. });
  125. this.curQue.img_list = JSON.parse(JSON.stringify(articleImgRes));
  126. },
  127. articleChange(e) {
  128. let _this = this;
  129. let str = e.replace(/<[^>]+>/g, "");
  130. let arr = str.split(/[\n]/);
  131. let newstr = "";
  132. arr.forEach((item) => {
  133. newstr += item;
  134. });
  135. if (newstr.length == 5000) {
  136. this.newarticle = e;
  137. }
  138. if (newstr.length > 5000) {
  139. if (document.getElementsByClassName("el-message").length == 0) {
  140. this.$message.warning("已超出字数限制");
  141. }
  142. return;
  143. }
  144. },
  145. },
  146. //生命周期 - 创建完成(可以访问当前this实例)
  147. created() {
  148. if (!this.curQue) {
  149. this.changeCurQue(this.data_structure);
  150. }
  151. },
  152. //生命周期 - 挂载完成(可以访问DOM元素)
  153. mounted() {
  154. tinymce.init({
  155. selector: `#tinydemo${this.number}`,
  156. });
  157. },
  158. beforeCreate() {}, //生命周期 - 创建之前
  159. beforeMount() {}, //生命周期 - 挂载之前
  160. beforeUpdate() {}, //生命周期 - 更新之前
  161. updated() {}, //生命周期 - 更新之后
  162. beforeDestroy() {}, //生命周期 - 销毁之前
  163. destroyed() {}, //生命周期 - 销毁完成
  164. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  165. };
  166. </script>
  167. <style lang='scss' scoped>
  168. //@import url(); 引入公共css类
  169. .Big-Book-Record {
  170. &-icon {
  171. width: 48px;
  172. height: 48px;
  173. }
  174. .Big-Book-hanzi-option {
  175. margin-top: 20px;
  176. }
  177. .main {
  178. margin-top: 10px;
  179. }
  180. .addoption {
  181. width: 148px;
  182. height: 40px;
  183. background: #f3f3f3;
  184. border: 1px dashed rgba(0, 0, 0, 0.15);
  185. box-sizing: border-box;
  186. border-radius: 4px;
  187. text-align: center;
  188. line-height: 40px;
  189. cursor: pointer;
  190. font-size: 14px;
  191. color: #000000;
  192. }
  193. .Big-Book-con {
  194. margin-bottom: 10px;
  195. display: flex;
  196. align-items: center;
  197. }
  198. .uploadArt_list {
  199. > li {
  200. min-height: 28px;
  201. .art_name {
  202. margin-right: 10px;
  203. }
  204. }
  205. }
  206. }
  207. </style>