publicityEdit.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <div class="center">
  3. <div class="main_css">
  4. <div class="formData">
  5. <el-form ref="form" :model="form" label-width="80px">
  6. <el-form-item label="资讯标题">
  7. <el-input v-model="form.title" clearable placeholder="请输入标题"></el-input>
  8. </el-form-item>
  9. <el-form-item label="资讯日期">
  10. <el-date-picker v-model="form.issuingDate" type="date" value-format="yyyy-MM-dd" style='width: 100%;'
  11. placeholder="选择日期时间">
  12. </el-date-picker>
  13. </el-form-item>
  14. <el-form-item label="发布机构">
  15. <el-input v-model="form.issuingAgency" clearable placeholder=""></el-input>
  16. </el-form-item>
  17. <el-form-item label="封面图片">
  18. <el-upload class="avatar-uploader1" :action="uploadPath"
  19. :show-file-list="false" :on-success="handleAvatarSuccess">
  20. <img v-if="imageUrl" :src="imageUrl" class="avatar">
  21. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  22. </el-upload>
  23. </el-form-item>
  24. <div class="quill-editor">
  25. <!-- 图片上传组件辅助,组件内添加v-show=“false”属性,把该组件隐藏起来。-->
  26. <el-upload class="avatar-uploader" :action="uploadPath" :show-file-list="false" :on-success="uploadSuccess">
  27. </el-upload>
  28. <!--富文本编辑器组件-->
  29. <quill-editor v-model="form.releaseContent" :content="form.releaseContent" :options="editorOption"
  30. @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @ready="onEditorReady($event)"
  31. ref="QuillEditor">
  32. </quill-editor>
  33. <div v-html="form.releaseContent" />
  34. </div>
  35. <!-- <quill-editor v-model="form.releaseContent" res="myQuillEditor" :options="editorOption" id="editor">
  36. </quill-editor> -->
  37. </el-form>
  38. </div>
  39. <div class="btn">
  40. <el-button @click="submit">提交</el-button>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import {
  47. seeData,
  48. editFormData,
  49. uploadPath
  50. } from '@/api/officialWebsiteManagement'
  51. import quillEditor from 'vue-quill-editor';
  52. const toolbarOptions = [
  53. ['bold', 'italic', 'underline', 'strike'], // 加粗,斜体,下划线,删除线
  54. ['blockquote', 'code-block'], //引用,代码块
  55. [{
  56. 'header': 1
  57. }, {
  58. 'header': 2
  59. }], // 几级标题
  60. [{
  61. 'list': 'ordered'
  62. }, {
  63. 'list': 'bullet'
  64. }], // 有序列表,无序列表
  65. [{
  66. 'script': 'sub'
  67. }, {
  68. 'script': 'super'
  69. }], // 下角标,上角标
  70. [{
  71. 'indent': '-1'
  72. }, {
  73. 'indent': '+1'
  74. }], // 缩进
  75. [{
  76. 'direction': 'rtl'
  77. }], // 文字输入方向
  78. [{
  79. 'size': ['small', false, 'large', 'huge']
  80. }], // 字体大小
  81. [{
  82. 'header': [1, 2, 3, 4, 5, 6, false]
  83. }], // 标题
  84. [{
  85. 'color': []
  86. }, {
  87. 'background': []
  88. }], // 颜色选择
  89. [{
  90. 'font': ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial']
  91. }], // 字体
  92. [{
  93. 'align': []
  94. }], // 居中
  95. ['clean'], // 清除样式,
  96. ['link', 'image'], // 上传图片、上传视频
  97. ]
  98. export default {
  99. data() {
  100. return {
  101. imageUrl: '',
  102. uploadPath,
  103. editorOption: {
  104. modules: {
  105. toolbar: {
  106. container: toolbarOptions,
  107. handlers: {
  108. image: function(value) {
  109. if (value) {
  110. // 调用element的图片上传组件
  111. document.querySelector('.avatar-uploader input').click()
  112. } else {
  113. this.quill.format('image', false)
  114. }
  115. }
  116. }
  117. }
  118. }
  119. },
  120. form: {
  121. issuingAgency: ''
  122. },
  123. regulations: {},
  124. version: [],
  125. count: ''
  126. }
  127. },
  128. created() {
  129. this.form.makeUser = JSON.parse(localStorage.getItem('UserInfo')).deptName
  130. },
  131. mounted() {
  132. this.id = this.$route.query.id
  133. this.getList()
  134. },
  135. methods: {
  136. handleAvatarSuccess(res, file) {
  137. this.imageUrl = URL.createObjectURL(file.raw);
  138. this.form.cover = res.data.url
  139. },
  140. getList() {
  141. this.listLoading = true
  142. var _obj = {}
  143. _obj.id = this.id
  144. seeData(_obj).then(response => {
  145. this.form = response.data
  146. this.imageUrl = response.data.cover
  147. console.log(this.form)
  148. this.listLoading = false
  149. })
  150. .catch(() => {
  151. this.loading = false
  152. })
  153. },
  154. // 失去焦点
  155. onEditorBlur(editor) {},
  156. // 获得焦点
  157. onEditorFocus(editor) {},
  158. // 开始
  159. onEditorReady(editor) {},
  160. // 值发生变化
  161. onEditorChange(editor) {
  162. this.form.releaseContent = editor.html;
  163. console.log(editor);
  164. },
  165. beforeUpload(file) {
  166. const isIMAGE = ''
  167. file.type === 'image/jpeg' || 'image/gif' || 'image/png' || 'image/jpg'
  168. const isLt1M = file.size / 1024 / 1024 < 1
  169. if (!isIMAGE) {
  170. this.$message.error('上传文件只能是图片格式!')
  171. }
  172. if (!isLt1M) {
  173. this.$message.error('上传文件大小不能超过 1MB!')
  174. }
  175. return isIMAGE && isLt1M
  176. },
  177. uploadSuccess(res) {
  178. // 获取富文本组件实例
  179. let quill = this.$refs.QuillEditor.quill
  180. // 如果上传成功
  181. if (res.data.errno = 200 && res.data.url) {
  182. // 获取光标所在位置
  183. let length = quill.getSelection().index;
  184. // 插入图片,res为服务器返回的图片链接地址
  185. quill.insertEmbed(length, 'image', res.data.url)
  186. // 调整光标到最后
  187. quill.setSelection(length + 1)
  188. } else {
  189. // 提示信息,需引入Message
  190. this.$message.error('图片插入失败!')
  191. }
  192. },
  193. submit() {
  194. this.listLoading = true
  195. this.form.contentType = '资讯'
  196. this.form.id = this.id
  197. delete this.form.createDate
  198. delete this.form.createUserId
  199. delete this.form.updateDate
  200. delete this.form.deleteFlag
  201. delete this.form.number
  202. editFormData(this.form).then(response => {
  203. this.$notify({
  204. title: '成功',
  205. message: '添加成功!',
  206. type: 'success'
  207. });
  208. this.listLoading = false
  209. this.$router.go(-1)
  210. })
  211. .catch(() => {
  212. this.loading = false
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .center {
  220. background: #F5F6F7;
  221. min-height: calc(100vh - 50px);
  222. padding-top: 20px;
  223. }
  224. .main_css {
  225. width: 96%;
  226. height: 90vh;
  227. overflow-y: scroll;
  228. background: #FFFFFF;
  229. margin: 20px auto;
  230. padding-top: 20px;
  231. }
  232. .formData {
  233. width: 50%;
  234. margin: 20px 0 0 140px;
  235. }
  236. .btn {
  237. text-align: right;
  238. position: absolute;
  239. right: 200px;
  240. bottom: 100px;
  241. }
  242. .ql-editor {
  243. height: 400px !important;
  244. }
  245. .avatar-uploader1 .el-upload {
  246. border: 1px dashed #d9d9d9;
  247. border-radius: 6px;
  248. cursor: pointer;
  249. position: relative;
  250. overflow: hidden;
  251. }
  252. .avatar-uploader1 .el-upload:hover {
  253. border-color: #409EFF;
  254. }
  255. .avatar-uploader-icon {
  256. font-size: 28px;
  257. color: #8c939d;
  258. width: 178px;
  259. height: 178px;
  260. line-height: 178px;
  261. text-align: center;
  262. }
  263. .avatar {
  264. width: 178px;
  265. height: 178px;
  266. display: block;
  267. }
  268. </style>