天波用户运营管理后台系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.4KB

  1. <!--
  2. * @Date: 2022-08-08 10:09:45
  3. * @LastEditors: JinxChen
  4. * @LastEditTime: 2022-09-16 16:39:27
  5. * @FilePath: \TelpoUserManageAdmin\src\views\message-manage\main\add-articles\index.vue
  6. * @description: 添加文章
  7. -->
  8. <template>
  9. <div class="home-container">
  10. <!-- 顶部内容 -->
  11. <div class="top-container">
  12. <TopMenu :buttonList="buttonList"/>
  13. </div>
  14. <!-- 表单 -->
  15. <el-form ref="form" :model="form" label-width="80px" size="small">
  16. <el-form-item label="文章标题:">
  17. <el-input v-model="form.articleTitle" ></el-input>
  18. </el-form-item>
  19. <el-form-item label="文章类型:">
  20. <el-select v-model="form.articleType" placeholder="请选择文章类型">
  21. <el-option :label="item.label" :value="item.label" v-for="(item, index) in articleTypes" :key="index"/>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="分享标题:">
  25. <el-input v-model="form.shareTitle"></el-input>
  26. </el-form-item>
  27. <el-form-item label="分享简介:">
  28. <el-input v-model="form.shareAbout"></el-input>
  29. </el-form-item>
  30. <el-form-item label="分享图片:">
  31. <el-button v-show="fileList.length > 0" disabled type="warning">请删除图片后再上传</el-button>
  32. <el-upload
  33. class="upload-img"
  34. action="https://jsonplaceholder.typicode.com/posts/"
  35. :on-preview="onPreview"
  36. :on-remove="onRemove"
  37. :on-progress="onProgress"
  38. :before-remove="beforeRemove"
  39. :before-upload="beforeUpload"
  40. :on-error="onError"
  41. :on-success="onSuccess"
  42. :on-change="onUploadChange"
  43. :auto-upload="false"
  44. :limit="1"
  45. list-type="picture"
  46. :file-list="fileList">
  47. <el-button size="small" type="primary" v-show="fileList.length <= 0">点击上传</el-button>
  48. <div slot="tip" class="el-upload__tip">
  49. <p>最多上传一张,尺寸750X300</p>
  50. </div>
  51. </el-upload>
  52. </el-form-item>
  53. <!-- 富文本编辑器 -->
  54. <el-form-item label="文章内容:">
  55. <!-- <tinymce v-model="form.articleContent" :height="5" menubar="false" /> -->
  56. <!-- <p>文章内容:{{form.articleContent}}</p> -->
  57. <div style="border: 1px solid #ccc;">
  58. <Toolbar
  59. style="border-bottom: 1px solid #ccc"
  60. :editor="editor"
  61. :defaultConfig="toolbarConfig"
  62. :mode="mode"
  63. />
  64. <Editor
  65. style="height: 350px; overflow-y: hidden;"
  66. v-model="form.articleContent"
  67. :defaultConfig="editorConfig"
  68. :mode="mode"
  69. @onCreated="onCreated"
  70. @onChange="onChange"
  71. @onDestroyed="onDestroyed"
  72. @onMaxLength="onMaxLength"
  73. @onFocus="onFocus"
  74. @onBlur="onBlur"
  75. @customPaste="customPaste"
  76. />
  77. </div>
  78. </el-form-item>
  79. <!-- 保存 -->
  80. <el-form-item class="footer-btn">
  81. <el-button type="primary" @click="onSave">保存</el-button>
  82. <el-button>取消</el-button>
  83. </el-form-item>
  84. </el-form>
  85. </div>
  86. </template>
  87. <script>
  88. import TopMenu from "@/components/TopMenu/index";
  89. import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
  90. /* import Tinymce from '@/components/Tinymce' */
  91. export default {
  92. name: 'wechat-fans',
  93. components: { TopMenu, /* Tinymce */ Editor, Toolbar },
  94. data(){
  95. return {
  96. buttonList: [], // 头部按钮,例子: {name: '添加', type: 'primary', icon: 'el-icon-circle-plus', click: () => { this.AddDialog();}}
  97. // 表单数据
  98. form: {
  99. articleTitle: '', //文章标题
  100. articleType: '普通文章', //文章类型
  101. shareTitle: '', //分享标题
  102. shareAbout: '', //分享简介
  103. shareImage: '', //分享图片
  104. articleContent: '', //文章内容
  105. },
  106. // 文章类型
  107. articleTypes: [
  108. { label: '普通文章', value: '普通文章' },
  109. { label: '特别文章', value: '特别文章' },
  110. { label: '其它文章', value: '其它文章' },
  111. ],
  112. // 图片列表
  113. fileList: [],
  114. editor: null,
  115. toolbarConfig: { },
  116. mode: 'default', // or 'simple'
  117. // 菜单配置
  118. editorConfig: {
  119. MENU_CONF: {
  120. uploadImage: {
  121. server: '', //上传图片地址 todo 待后端提供
  122. }
  123. }
  124. }
  125. }
  126. },
  127. mounted() {},
  128. created() {
  129. this.clearFiles();
  130. console.log("本地的上传图片列表", this.fileList);
  131. },
  132. beforeDestroy() {
  133. const editor = this.editor
  134. if (editor == null) return
  135. editor.destroy() // 组件销毁时,及时销毁编辑器
  136. },
  137. methods: {
  138. onCreated(editor) {
  139. this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
  140. },
  141. onChange(editor) { console.log('onChange', editor.children) },
  142. onDestroyed(editor) { console.log('onDestroyed', editor) },
  143. onMaxLength(editor) { console.log('onMaxLength', editor) },
  144. onFocus(editor) { console.log('onFocus', editor) },
  145. onBlur(editor) { console.log('onBlur', editor) },
  146. customPaste(editor, event, callback) {
  147. console.log('ClipboardEvent 粘贴事件对象', event)
  148. // const html = event.clipboardData.getData('text/html') // 获取粘贴的 html
  149. // const text = event.clipboardData.getData('text/plain') // 获取粘贴的纯文本
  150. // const rtf = event.clipboardData.getData('text/rtf') // 获取 rtf 数据(如从 word wsp 复制粘贴)
  151. // 自定义插入内容
  152. editor.insertText('')
  153. // 返回 false ,阻止默认粘贴行为
  154. event.preventDefault()
  155. callback(false) // 返回值(注意,vue 事件的返回值,不能用 return)
  156. // 返回 true ,继续默认的粘贴行为
  157. // callback(true)
  158. },
  159. // 清空本地上传的图片列表
  160. clearFiles() {},
  161. // 删除上传的图片
  162. onRemove() {
  163. this.fileList = []
  164. },
  165. // 点击文件列表中已上传的文件时的钩子
  166. onPreview(file) {
  167. console.log("点击了上传图片", file);
  168. },
  169. // 删除上传图片
  170. beforeRemove(file) {
  171. return this.$confirm(`确定删除 ${ file.name }?`);
  172. },
  173. // 上传图片前
  174. beforeUpload(file) {
  175. console.log("上传图片前::", file);
  176. },
  177. // 上传失败
  178. onError(err) {
  179. return this.$confirm(`上传失败,请联系管理人`);
  180. },
  181. // 上传成功
  182. onSuccess(file) {
  183. console.log("上传成功", file);
  184. },
  185. // 文件上传时
  186. onProgress(fileList) {
  187. console.log("fileList", fileList);
  188. },
  189. // 上传文件发生变化时
  190. onUploadChange(file) {
  191. console.log('传文件发生变化时', file);
  192. if(this.fileList.length > 0) {
  193. this.fileList.length = 0
  194. } else {
  195. this.fileList.push(file);
  196. }
  197. },
  198. // 保存
  199. onSave() {
  200. console.log("保存的内容::", this.form);
  201. }
  202. }
  203. }
  204. </script>
  205. <style src="@wangeditor/editor/dist/css/style.css"></style>
  206. <style scoped lang="scss">
  207. .home-container {
  208. position: relative;
  209. height: 600px;
  210. overflow-y: scroll;
  211. overflow-x: hidden;
  212. padding: 0 20px;
  213. p {
  214. padding: 5px;
  215. }
  216. }
  217. .upload-img {
  218. width: 400px;
  219. .el-button {
  220. margin-left: 0;
  221. }
  222. }
  223. </style>