edit.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <el-row>
  3. <el-row style="padding-top: 50px;width: 1500px;padding-left: 30px">
  4. <el-form ref="form" :model="form" :rules="formRules" label-width="120px">
  5. <el-row>
  6. <el-col :span="12">
  7. <el-row>
  8. <el-form-item label="标题" prop="newsTitle">
  9. <el-input v-model="form.newsTitle" placeholder="在这里输入标题" show-word-limit maxlength="40"></el-input>
  10. </el-form-item>
  11. </el-row>
  12. <el-row>
  13. <el-form-item label="简介" prop="intro" style="margin-top: 5px">
  14. <el-input v-model="form.intro" type="textarea" :rows="7" placeholder="在这里输入简介" show-word-limit maxlength="300"></el-input>
  15. </el-form-item>
  16. </el-row>
  17. <el-row style="margin-top: 20px">
  18. <el-form-item label="网址">
  19. <el-col :span="20"><el-input v-model="form.newUrl" placeholder="在这里粘贴文章地址"></el-input></el-col>
  20. <el-col :span="4"><el-button type="primary" @click="crawler">获取内容</el-button></el-col>
  21. </el-form-item>
  22. </el-row>
  23. </el-col>
  24. <el-col :span="12">
  25. <el-row>
  26. <el-row style="height: 131px">
  27. <el-col :span="12">
  28. <el-form-item label="缩略图" prop="imageUrl">
  29. <div @click="onClick">
  30. <material-dialog v-model="form.imageUrl" sourceType="新闻资讯"></material-dialog>
  31. </div>
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="12">
  35. <div style="height: 131px"><img :src="OSS_URL + form.imageUrl" style="height: 131px;width: 248px;border-radius: 4px"></div>
  36. </el-col>
  37. </el-row>
  38. </el-row>
  39. <el-row style="padding-top: 15px;height: 130px;">
  40. <el-col :span="24"><img @click="changeBorder('1')" class="img1" src="../../assets/news2.png" style="margin-left: 56px;border-radius: 4px;box-sizing: border-box;width: 122px;height: 82px">
  41. <img @click="changeBorder('2')" class="img2" src="../../assets/hangye2.png" style="margin-left: 18px;border-radius: 4px;box-sizing: border-box;width: 122px;height: 82px">
  42. <img @click="changeBorder('3')" class="img3" src="../../assets/hangye.png" style="margin-left: 19px;border-radius: 4px;box-sizing: border-box;width: 122px;height: 82px">
  43. <img @click="changeBorder('4')" class="img4" src="../../assets/hangye.png" style="margin-left: 19px;border-radius: 4px;box-sizing: border-box;width: 122px;height: 82px">
  44. </el-col>
  45. </el-row>
  46. </el-col>
  47. </el-row>
  48. <el-row style="margin-top: 0px">
  49. <el-form-item label="内容">
  50. <quill-editor ref="myTextEditor" v-model="form.content" :options="editorOption" style="height: 300px;"></quill-editor>
  51. </el-form-item>
  52. </el-row>
  53. </el-form>
  54. </el-row>
  55. <el-row style="padding: 50px 150px;text-align: left;">
  56. <el-button type="primary" @click="handleSave">保存</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  57. <el-button type="primary" @click="toPortalDetail">预览</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  58. <el-button type="primary" @click="checkboxrelease">发布</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  59. <el-button type="primary" @click="toBack">取消</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  60. </el-row>
  61. </el-row>
  62. </template>
  63. <script>
  64. import materialDialog from '@/views/material/dialog'
  65. import newsApi from '@/api/newsApi'
  66. import crawlerApi from '@/api/crawlerApi'
  67. export default {
  68. name: 'courseIntroduce',
  69. components: {
  70. 'material-dialog': materialDialog
  71. },
  72. data () {
  73. return {
  74. saveMark: 0,
  75. form: {
  76. id: '',
  77. newsTitle: '',
  78. content: '',
  79. newUrl: '',
  80. intro: '',
  81. imageUrl: '',
  82. classtype: 1,
  83. releaseStatue: 0,
  84. pushIndex: 0,
  85. secondTop: 0
  86. },
  87. formRules: {
  88. newsTitle: { required: true, message: '请输入标题', trigger: 'blur' },
  89. intro: { required: true, message: '请输入简介', trigger: 'blur' },
  90. imageUrl: { required: true, message: '请选择缩略图', trigger: 'blur' }
  91. },
  92. editorOption: {
  93. placeholder: '请输入内容'
  94. }
  95. }
  96. },
  97. mounted () {
  98. this.form['id'] = this.$route.params.msgKey
  99. this.findById()
  100. },
  101. methods: {
  102. toBack () {
  103. this.$confirm('是否取消创建/修改文章?,并退出编辑页面?', {
  104. confirmButtonText: '继续退出',
  105. cancelButtonText: '留下',
  106. type: 'primary'
  107. }).then(() => {
  108. this.$router.push({name: 'News'})
  109. }).catch(() => {
  110. this.$message({
  111. type: 'info',
  112. message: '已退出编辑页面'
  113. })
  114. })
  115. },
  116. onClick () {
  117. var d = document.getElementsByClassName('el-dialog')
  118. d[0].style.marginTop = '10vh'
  119. d[1].style.marginTop = '10vh'
  120. },
  121. crawler () {
  122. if (this.form.newUrl === '') {
  123. this.$message({
  124. type: 'info',
  125. message: '网址不能为空'
  126. })
  127. }
  128. crawlerApi.crawler(this.form.newUrl).then(data => {
  129. this.form.newsTitle = data.newsTitle
  130. this.form.content = data.content
  131. this.form.intro = data.intro
  132. })
  133. },
  134. handleSave () {
  135. this.$refs['form'].validate((valid) => {
  136. if (!valid) {
  137. return false
  138. }
  139. this.$confirm('是否马上保存文章?', {
  140. confirmButtonText: '是',
  141. cancelButtonText: '否',
  142. type: 'primary'
  143. }).then(() => {
  144. newsApi.save(this.form).then(data => {
  145. this.saveMark = 1
  146. })
  147. }).catch(() => {
  148. this.$message({
  149. type: 'info',
  150. message: '已取消发布'
  151. })
  152. })
  153. })
  154. },
  155. changeBorder (temp) {
  156. let img1 = document.getElementsByClassName('img1')
  157. img1[0].style.marginLeft = '60px'
  158. for (var i = 1; i < 5; i++) {
  159. let img2 = document.getElementsByClassName('img' + i)
  160. img2[0].style.border = ''
  161. }
  162. let img3 = document.getElementsByClassName('img' + temp)
  163. img3[0].style.border = 'solid 4px #00afff'
  164. if (temp === '1') {
  165. this.form['imageUrl'] = '/vr_resource/images/news/static/news2.png'
  166. }
  167. if (temp === '2') {
  168. this.form['imageUrl'] = '/vr_resource/images/news/static/hangye2.png'
  169. }
  170. if (temp === '3') {
  171. this.form['imageUrl'] = '/vr_resource/images/news/static/news.png'
  172. }
  173. if (temp === '4') {
  174. this.form['imageUrl'] = '/vr_resource/images/news/static/hangye.png'
  175. }
  176. },
  177. toPortalDetail () {
  178. if (this.form['id'] !== undefined) {
  179. window.open(`${this.PORTAL_URL}/#/main/new/${this.form['id']}`, '_blank')
  180. } else {
  181. this.$message.error('请保存后再进行预览')
  182. }
  183. },
  184. findById () {
  185. if (this.form['id']) {
  186. newsApi.findById(this.form['id']).then(data => {
  187. this.form['id'] = data.id
  188. this.form['newsTitle'] = data.newsTitle
  189. this.form['content'] = data.content
  190. this.form['newUrl'] = data.newUrl
  191. this.form['intro'] = data.intro
  192. this.form['imageUrl'] = data.imageUrl
  193. this.form['classtype'] = data.classtype
  194. this.form['releaseStatue'] = data.releaseStatue
  195. this.form['pushIndex'] = data.pushIndex
  196. this.form['secondTop'] = data.secondTop
  197. })
  198. }
  199. },
  200. checkboxrelease () {
  201. this.$confirm('是否马上发布文章?', {
  202. confirmButtonText: '是',
  203. cancelButtonText: '否',
  204. type: 'primary'
  205. }).then(() => {
  206. if (this.form['id'] !== undefined | this.saveMark === 1) {
  207. newsApi.checkboxrelease(this.form['id']).then(data => {
  208. this.list()
  209. })
  210. } else {
  211. this.$message.error('请保存后再进行发布')
  212. }
  213. }).catch(() => {
  214. this.$message({
  215. type: 'info',
  216. message: '已取消发布'
  217. })
  218. })
  219. }
  220. }
  221. }
  222. </script>
  223. <style scoped>
  224. .el-icon-circle-plus {
  225. font-size: 50px;
  226. }
  227. /deep/ .el-dialog {
  228. margin-top: 10vh
  229. }
  230. /deep/ .el-button--primary {
  231. background-color: #2493e5;
  232. border-color: #2493e5;
  233. }
  234. /deep/ .el-button--mini, .el-button--mini.is-round{
  235. padding: 9px 19px;
  236. }
  237. /deep/ .el-input--mini .el-input__inner{
  238. height: 32px;
  239. }
  240. </style>