addArticle.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <style lang="scss">
  2. .add {
  3. .el-input,
  4. button {
  5. width: 300px;
  6. }
  7. .bm-view {
  8. width: 100%;
  9. }
  10. .avatar-uploader .el-upload {
  11. border: 1px dashed #d9d9d9;
  12. border-radius: 6px;
  13. cursor: pointer;
  14. position: relative;
  15. overflow: hidden;
  16. }
  17. .avatar-uploader .el-upload:hover {
  18. border-color: #409eff;
  19. }
  20. .avatar-uploader-icon {
  21. font-size: 28px;
  22. color: #8c939d;
  23. width: 178px;
  24. height: 178px;
  25. line-height: 178px;
  26. text-align: center;
  27. }
  28. .avatar {
  29. width: 178px;
  30. height: 178px;
  31. display: block;
  32. }
  33. .imgs{
  34. li{
  35. display: inline-block;
  36. width: 150px;
  37. height: 150px;
  38. overflow: hidden;
  39. margin: 0 10px;
  40. }
  41. .up_img{
  42. border: 1px dashed #999;
  43. border-radius: 4px;
  44. font-size: 50px;
  45. text-align: center;
  46. line-height: 150px;
  47. color:#999;
  48. position: relative;
  49. input{
  50. position: absolute;
  51. width: 100%;
  52. height: 100%;
  53. left:0;
  54. top: 0;
  55. opacity: 0;
  56. }
  57. }
  58. }
  59. }
  60. </style>
  61. <template>
  62. <section class="content">
  63. <h4>新增公告</h4>
  64. <el-divider></el-divider>
  65. <el-form label-width="80px">
  66. <el-form-item label="标题">
  67. <el-input placeholder="标题" v-model="form.name"></el-input>
  68. </el-form-item>
  69. <el-form-item label="详情">
  70. <fuEditor v-model="form.content" :isClear="isClear" @change="change"></fuEditor>
  71. </el-form-item>
  72. <el-form-item label="状态" prop="status">
  73. <el-select v-model="form.status" placeholder="请选择状态">
  74. <el-option key='1' label="编辑中" :value="1"></el-option>
  75. <el-option key='2' label="上线" :value="2"></el-option>
  76. <el-option key='-1' label="下线" :value="-1"></el-option>
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item label=" ">
  80. <el-button type="primary" @click="save">保存</el-button>
  81. </el-form-item>
  82. </el-form>
  83. </section>
  84. </template>
  85. <script>
  86. import fuEditor from "@/components/fuEditor/index.vue";
  87. export default {
  88. components: {
  89. fuEditor
  90. },
  91. data() {
  92. return {
  93. test: "",
  94. list:[],
  95. form: {
  96. title: "",
  97. category_id: '',
  98. content: "",
  99. imgs: [],
  100. address: "",
  101. point: ""
  102. },
  103. isClear: false,
  104. keyword:'',
  105. point:{
  106. lng:'',
  107. lat:''
  108. },
  109. BMap:null
  110. };
  111. },
  112. methods: {
  113. getData() {
  114. this.$api.getArticleById({ id: this.form.id }).then(res => {
  115. this.form = res.data.data;
  116. });
  117. },
  118. getContent(){
  119. this.$api.getContentList({page:this.page}).then(res => {
  120. this.loading=false
  121. if (res.status == 200) {
  122. this.list = res.data.data.list;
  123. } else {
  124. this.$message({
  125. message: res.message,
  126. type: "error"
  127. });
  128. }
  129. });
  130. },
  131. change(val) {
  132. this.form.content = val;
  133. },
  134. upload(type){
  135. var file=document.getElementById(type).files;
  136. var data=new FormData();
  137. data.append("file",file[0])
  138. this.$api.uploadFile(data).then(res=>{
  139. if(res.data.code==0){
  140. let imgs=this.form.imgs||[];
  141. imgs.push(res.data.data.url)
  142. this.form.imgs=imgs
  143. // this.$set(form,type,res.data.data.url)
  144. this.$message({message: '上传成功!',type: 'success'});
  145. }else{
  146. this.$message.error(res.data.message);
  147. }
  148. })
  149. },
  150. save() {
  151. var parm = this.form;
  152. parm.point=this.point.lng+','+this.point.lat
  153. parm.type = "notice"
  154. if (parm.id) {
  155. // debugger;
  156. this.$api.editArticle(parm).then(res => {
  157. if (res.data.code == 0) {
  158. this.$message({ message: "修改成功!", type: "success" });
  159. this.$router.push({ path: "/notice" });
  160. } else {
  161. this.$message.error(res.data.message);
  162. }
  163. });
  164. } else {
  165. this.$api.addArticle(parm).then(res => {
  166. if (res.data.code == 0) {
  167. this.$message({ message: "添加成功!", type: "success" });
  168. this.$router.push({ path: "/notice" });
  169. } else {
  170. this.$message.error(res.data.message);
  171. }
  172. });
  173. }
  174. },
  175. onBaiduMapReady(e) {
  176. // const that = this
  177. this.BMap = e.BMap
  178. },
  179. getClickInfo(e) {
  180. // 调整地图中心位置
  181. this.point=e.point
  182. // 此时已经可以获取到BMap类
  183. if (this.BMap) {
  184. const that = this
  185. // Geocoder() 类进行地址解析
  186. // 创建地址解析器的实例
  187. const geoCoder = new this.BMap.Geocoder()
  188. // getLocation() 类--利用坐标获取地址的详细信息
  189. // getPoint() 类--获取位置对应的坐标
  190. geoCoder.getLocation(e.point, function(res) {
  191. const addrComponent = res.addressComponents
  192. const surroundingPois = res.surroundingPois
  193. const province = addrComponent.province
  194. const city = addrComponent.city
  195. const district = addrComponent.district
  196. let addr = addrComponent.street
  197. if (surroundingPois.length > 0 && surroundingPois[0].title) {
  198. if (addr) {
  199. addr += `-${surroundingPois[0].title}`
  200. } else {
  201. addr += `${surroundingPois[0].title}`
  202. }
  203. } else {
  204. addr += addrComponent.streetNumber
  205. }
  206. that.form.address=province+city+district+addr
  207. })
  208. }
  209. },
  210. },
  211. created() {
  212. // this.getContent()
  213. if (this.$route.query.id) {
  214. this.form.id = this.$route.query.id;
  215. this.id = this.$route.query.id;
  216. this.getData();
  217. }
  218. }
  219. };
  220. </script>