ad.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="24" class="first-row">
  5. <div class="tag">广告管理</div>
  6. </el-col>
  7. </el-row>
  8. <hr style="background-color: #CCCCCC;height: 1px;border: 0;">
  9. <el-row>
  10. <el-col :span="12" class="third-row">
  11. <el-link type="danger">{{send_url}}</el-link>
  12. <el-upload ref="upload_send" :limit="1" :auto-upload="false" list-type="picture" accept=".jpg"
  13. action="#" :multiple="false">
  14. <el-button slot="trigger" size="small" type="primary">选取图片文件</el-button>
  15. <el-button style="margin-left: 10px;" size="small" type="success" @click="send_ad">上传到服务器
  16. </el-button>
  17. <div slot="tip" class="el-upload__tip">提示:仅允许上传多1个".jpg"文件,且不超过500kb</div>
  18. </el-upload>
  19. </el-col>
  20. <el-col :span="12" class="third-row">
  21. <el-link type="danger">{{modify_url}}</el-link>
  22. <el-upload ref="upload_modi" :limit="1" :auto-upload="false" list-type="picture" accept=".jpg"
  23. action="#" :multiple="false">
  24. <el-button slot="trigger" size="small" type="primary">选取图片文件</el-button>
  25. <el-button style="margin-left: 10px;" size="small" type="success" @click="modify_ad">上传到服务器
  26. </el-button>
  27. <div slot="tip" class="el-upload__tip">只能上传jpg文件,且不超过500kb</div>
  28. </el-upload>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. send_url: '上传成功显示URL',
  38. modify_url: '修改成功显示URL'
  39. }
  40. },
  41. methods: {
  42. /**
  43. * 上传广告图片
  44. */
  45. send_ad() {
  46. var _this = this
  47. let file = this.$refs.upload_send.uploadFiles.pop().raw; //这里获取上传的文件对象
  48. let formData = new FormData();
  49. formData.append("myFile", file);
  50. formData.append("url_name", '水电广告');
  51. formData.append("remark", '备注');
  52. this.$axios.post('/shuidian/HotWaters/adverthimage.action', formData)
  53. .then(res => {
  54. // console.log(res.data);
  55. if (res.data.code == 200) {
  56. _this.$message.success(res.data.message);
  57. _this.send_url = res.data.url;
  58. } else {
  59. _this.$message.warning(res.data.messag);
  60. }
  61. })
  62. .catch(err => {
  63. // console.log(err);
  64. _this.$message.error('【上传图片】请求异常: ' + err);
  65. })
  66. },
  67. /**
  68. * 修改广告图片
  69. */
  70. modify_ad() {
  71. var _this = this
  72. let file = this.$refs.upload_modi.uploadFiles.pop().raw; //这里获取上传的文件对象
  73. let formData = new FormData();
  74. formData.append("myFile", file);
  75. formData.append("url_name", '修改水电广告');
  76. formData.append("remark", '备注修改图片');
  77. formData.append("id", 1);
  78. this.$axios.post('/shuidian/HotWaters/adverth_uimage.action', formData)
  79. .then(res => {
  80. // console.log(res.data);
  81. if (res.data.code == 200) {
  82. _this.$message.success(res.data.message);
  83. _this.modify_url = res.data.url;
  84. } else {
  85. _this.$message.warning(res.data.messag);
  86. }
  87. })
  88. .catch(err => {
  89. // console.log(err);
  90. _this.$message.error('【修改图片】请求异常: ' + err);
  91. })
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped>
  97. @import url("ad.css");
  98. </style>