addChampionSay.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <style lang="scss">
  2. .content {
  3. .avatar-uploader .el-upload {
  4. border: 1px dashed #d9d9d9;
  5. border-radius: 6px;
  6. cursor: pointer;
  7. position: relative;
  8. overflow: hidden;
  9. }
  10. .avatar-uploader .el-upload:hover {
  11. border-color: #409eff;
  12. }
  13. .avatar-uploader-icon {
  14. font-size: 28px;
  15. color: #8c939d;
  16. width: 178px;
  17. height: 178px;
  18. line-height: 178px;
  19. text-align: center;
  20. }
  21. .avatar {
  22. width: 178px;
  23. height: 178px;
  24. display: block;
  25. }
  26. height: 110vh!important;
  27. }
  28. </style>
  29. <template>
  30. <section class="content">
  31. <h4>新增文章</h4>
  32. <el-divider></el-divider>
  33. <el-form label-width="80px">
  34. <el-form-item label="分类">
  35. <el-select v-model="form.category" placeholder="">
  36. <el-option
  37. v-for="item in categoryList"
  38. :key="item.value"
  39. :label="item.label"
  40. :value="item.value">
  41. </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="置顶">
  45. <el-select v-model="form.isbanner" placeholder="">
  46. <el-option
  47. v-for="item in bannerList"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value">
  51. </el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="标题">
  55. <el-input placeholder="标题" v-model="form.name"></el-input>
  56. </el-form-item>
  57. <el-form-item label="封面图">
  58. <el-upload
  59. class="avatar-uploader"
  60. action="/api/admin/uploadfile"
  61. :show-file-list="false"
  62. :on-success="handleAvatarSuccess"
  63. :before-upload="beforeAvatarUpload"
  64. >
  65. <img v-if="form.img" :src="form.img" class="avatar" />
  66. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  67. </el-upload>
  68. </el-form-item>
  69. <el-form-item label="详情">
  70. <!-- <fuEditor
  71. v-model="form.content"
  72. :isClear="isClear"
  73. @change="change"
  74. ></fuEditor> -->
  75. <vue-ueditor-wrap ref="editor" v-model="form.content" :config="myConfig"></vue-ueditor-wrap>
  76. </el-form-item>
  77. <el-form-item label="状态" prop="status">
  78. <el-select v-model="form.status" placeholder="请选择状态">
  79. <el-option key="1" label="编辑中" :value="1"></el-option>
  80. <el-option key="2" label="上线" :value="2"></el-option>
  81. <el-option key="-1" label="下线" :value="-1"></el-option>
  82. </el-select>
  83. </el-form-item>
  84. <el-form-item label="">
  85. <el-button type="primary" @click="save">保存</el-button>
  86. </el-form-item>
  87. </el-form>
  88. </section>
  89. </template>
  90. <script>
  91. import fuEditor from "@/components/fuEditor/index.vue";
  92. export default {
  93. components: {
  94. fuEditor,
  95. },
  96. data() {
  97. return {
  98. imageUrl: "",
  99. test: "",
  100. list: [],
  101. form: {
  102. title: "",
  103. category_id: "",
  104. content: "",
  105. imgs: [],
  106. address: "",
  107. point: "",
  108. status: 1,
  109. img: "",
  110. },
  111. isClear: false,
  112. keyword: "",
  113. point: {
  114. lng: "",
  115. lat: "",
  116. },
  117. BMap: null,
  118. myConfig: {
  119. // 编辑器自动被内容撑高
  120. autoHeightEnabled: true,
  121. // 初始容器高度
  122. initialFrameHeight: 500,
  123. // 初始容器宽度
  124. initialFrameWidth: '100%',
  125. // 上传文件接口,实现上传图片功能必须的配置,这个地址会在后端配置的时候产生,此处先放上结果
  126. serverUrl: '/api/admin/ueditor/upload',
  127. },
  128. categoryList:[
  129. {label:"游资专场",value:"游资专场"},
  130. {label:"冠军交割",value:"冠军交割"},
  131. {label:"牛人专场",value:"牛人专场"},
  132. {label:"妖股列传",value:"妖股列传"}
  133. ],
  134. bannerList:[
  135. {label:"否",value:0},
  136. {label:"是",value:1}
  137. ]
  138. };
  139. },
  140. methods: {
  141. getData() {
  142. this.$api.getArticleById({ id: this.form.id }).then((res) => {
  143. this.form = res.data.data;
  144. });
  145. },
  146. getContent() {
  147. this.$api.getContentList({ page: this.page }).then((res) => {
  148. this.loading = false;
  149. if (res.status == 200) {
  150. this.list = res.data.data.list;
  151. } else {
  152. this.$message({
  153. message: res.message,
  154. type: "error",
  155. });
  156. }
  157. });
  158. },
  159. change(val) {
  160. this.form.content = val;
  161. },
  162. upload(type) {
  163. var file = document.getElementById(type).files;
  164. var data = new FormData();
  165. data.append("file", file[0]);
  166. this.$api.uploadFile(data).then((res) => {
  167. if (res.data.code == 0) {
  168. let imgs = this.form.imgs || [];
  169. imgs.push(res.data.data.url);
  170. this.form.imgs = imgs;
  171. // this.$set(form,type,res.data.data.url)
  172. this.$message({ message: "上传成功!", type: "success" });
  173. } else {
  174. this.$message.error(res.data.message);
  175. }
  176. });
  177. },
  178. save() {
  179. var parm = this.form;
  180. // parm.point=this.point.lng+','+this.point.lat
  181. parm.type = "champion";
  182. if (parm.id) {
  183. // debugger;
  184. this.$api.editArticle(parm).then((res) => {
  185. if (res.data.code == 0) {
  186. this.$message({ message: "修改成功!", type: "success" });
  187. this.$router.push({ path: "/championsay" });
  188. } else {
  189. this.$message.error(res.data.message);
  190. }
  191. });
  192. } else {
  193. this.$api.addArticle(parm).then((res) => {
  194. if (res.data.code == 0) {
  195. this.$message({ message: "添加成功!", type: "success" });
  196. this.$router.push({ path: "/championsay" });
  197. } else {
  198. this.$message.error(res.data.message);
  199. }
  200. });
  201. }
  202. },
  203. handleAvatarSuccess(res, file) {
  204. this.form.img = res.data.url;
  205. },
  206. beforeAvatarUpload(file) {
  207. return;
  208. const isJPG = file.type === "image/jpeg";
  209. const isLt2M = file.size / 1024 / 1024 < 2;
  210. if (!isJPG) {
  211. this.$message.error("上传头像图片只能是 JPG 格式!");
  212. }
  213. if (!isLt2M) {
  214. this.$message.error("上传头像图片大小不能超过 2MB!");
  215. }
  216. return isJPG && isLt2M;
  217. },
  218. onBaiduMapReady(e) {
  219. // const that = this
  220. this.BMap = e.BMap;
  221. },
  222. getClickInfo(e) {
  223. // 调整地图中心位置
  224. this.point = e.point;
  225. // 此时已经可以获取到BMap类
  226. if (this.BMap) {
  227. const that = this;
  228. // Geocoder() 类进行地址解析
  229. // 创建地址解析器的实例
  230. const geoCoder = new this.BMap.Geocoder();
  231. // getLocation() 类--利用坐标获取地址的详细信息
  232. // getPoint() 类--获取位置对应的坐标
  233. geoCoder.getLocation(e.point, function (res) {
  234. const addrComponent = res.addressComponents;
  235. const surroundingPois = res.surroundingPois;
  236. const province = addrComponent.province;
  237. const city = addrComponent.city;
  238. const district = addrComponent.district;
  239. let addr = addrComponent.street;
  240. if (surroundingPois.length > 0 && surroundingPois[0].title) {
  241. if (addr) {
  242. addr += `-${surroundingPois[0].title}`;
  243. } else {
  244. addr += `${surroundingPois[0].title}`;
  245. }
  246. } else {
  247. addr += addrComponent.streetNumber;
  248. }
  249. that.form.address = province + city + district + addr;
  250. });
  251. }
  252. },
  253. },
  254. created() {
  255. // this.getContent()
  256. if (this.$route.query.id) {
  257. this.form.id = this.$route.query.id;
  258. this.id = this.$route.query.id;
  259. this.getData();
  260. }
  261. },
  262. };
  263. </script>