equipment-img.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="mt-3 px3">
  3. <view class="f-size-30 f-weight-bold py2 border-bottom my3">设备图片</view>
  4. <u-upload
  5. width="180"
  6. height="180"
  7. :action="action"
  8. :file-list="fileList"
  9. max-count="3"
  10. :max-size="5 * 100 * 1024"
  11. @on-success="uploadSuccess"
  12. @on-remove="uploadRemove"
  13. :before-upload="beforeUpload"
  14. :header="header">
  15. </u-upload>
  16. <view class="d-flex j-around a-center footer">
  17. <view
  18. class="main-color-bg text-color-white common"
  19. @tap="handleSubmit"
  20. >提交</view
  21. >
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. infoData: {},
  30. detailId: '',
  31. fileList: [],
  32. action: this.$BaseTool.UserUtil.getUploadUrl(),
  33. header: {
  34. Authorization: 'Bearer ' + uni.getStorageSync('accessToken')
  35. },
  36. imagesList: []
  37. };
  38. },
  39. onLoad(options) {
  40. this.detailId = options.detailId;
  41. this.initData();
  42. },
  43. methods: {
  44. initData() {
  45. this.$Http
  46. .fetchSbInfoIgnores({
  47. id: this.detailId
  48. })
  49. .then((res) => {
  50. this.fileList = res.data.sbFileList
  51. this.imagesList = JSON.parse(JSON.stringify(res.data.sbFileList))
  52. this.fileList.forEach((d) => {
  53. d.url = this.$BaseTool.UserUtil.getFileUrl(d.url);
  54. });
  55. });
  56. },
  57. // 删除成功
  58. uploadRemove(index, lists, name) {
  59. this.fileList = lists;
  60. this.imagesList.splice(index, 1)
  61. console.log(this.imagesList);
  62. },
  63. // 上传成功
  64. uploadSuccess(data, index, lists, name) {
  65. this.fileList = lists;
  66. this.imagesList.push(data.data)
  67. console.log(this.imagesList);
  68. },
  69. // 上传前登录校验:u-upload 直传不走统一请求拦截,未登录不会触发 401 登录弹框,需在此拦住
  70. beforeUpload() {
  71. return this.$Http.requireLogin(null, '上传设备图片需要先登录,是否登录?');
  72. },
  73. handleSubmit() {
  74. if (!this.$Http.requireLogin(null, '保存设备图片需要先登录,是否登录?')) {
  75. return
  76. }
  77. const params = {
  78. sbFileList: this.imagesList,
  79. id: this.detailId
  80. };
  81. this.imagesList.map((item) => {
  82. return item.url;
  83. });
  84. this.$Http.updateSbInfoImagesIgnores(params).then((res) => {
  85. uni.showToast({ title: '添加成功' });
  86. });
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="less" scoped>
  92. .main {
  93. .img {
  94. width: 76rpx;
  95. height: 76rpx;
  96. border-radius: 10rpx;
  97. image {
  98. width: 76rpx;
  99. height: 76rpx;
  100. border-radius: 10rpx;
  101. }
  102. }
  103. .content {
  104. .text-color-3 {
  105. width: 500rpx;
  106. }
  107. }
  108. }
  109. .footer {
  110. bottom: 150rpx;
  111. left: 0;
  112. right: 0;
  113. z-index: 10000;
  114. border-top: 1rpx solid #f4f4f4;
  115. height: 100rpx;
  116. .common {
  117. padding: 15rpx 200rpx;
  118. border-radius: 30rpx;
  119. background-color: #0082ff;
  120. color: #fff;
  121. }
  122. }
  123. </style>