index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view>
  3. <view class="img_box">
  4. <u-upload @on-list-change="change" upload-text="上传图片" width="139" height="139"
  5. :max-size="10 * 1024 * 1024" max-count="6" ref="uUpload" :action="action" :auto-upload="false">
  6. </u-upload>
  7. </view>
  8. <u-toast ref="uToast" />
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. uploadlist:[],//上传图片数组
  16. value: '', //提交图片数组
  17. action: 'https://www.jxydyw.cn/patrol-app/v1/file/upload' //没用到的
  18. }
  19. },
  20. created() {},
  21. methods: {
  22. change() {
  23. this.uploadlist = []
  24. this.value = ''
  25. this.$nextTick(() => {
  26. let lists = this.$refs.uUpload.lists;
  27. lists.forEach(val => {
  28. this.upload(val.url)
  29. })
  30. })
  31. },
  32. //上传图片
  33. upload(item){
  34. uni.uploadFile({
  35. url: 'https://www.jxydyw.cn/patrol-app/v1/file/upload', //仅为示例,非真实的接口地址
  36. filePath: item,
  37. name: 'file',
  38. success: (uploadFileRes) => {
  39. let data= JSON.parse(uploadFileRes.data)
  40. let showUrl=data.data
  41. this.uploadlist.push(showUrl)
  42. this.$nextTick(() => {
  43. let value = '';
  44. let len = this.uploadlist.length
  45. if( len > 0 ) {
  46. if (len > 1) {
  47. value = this.uploadlist[0];
  48. for (let i = 1; i < len; i++) {
  49. value = value + "," + this.uploadlist[i];
  50. }
  51. } else {
  52. value = this.uploadlist[0];
  53. }
  54. this.value = value
  55. this.$nextTick(() => {
  56. this.$emit('changeImg',this.value)
  57. })
  58. }
  59. })
  60. },
  61. fail(data) {
  62. this.$refs.uToast.show({
  63. title: data.message,
  64. type: 'warning',
  65. })
  66. }
  67. });
  68. },
  69. //提交
  70. submit() {
  71. let newarr = JSON.parse(JSON.stringify(this.value))
  72. let item = {
  73. id: this.scan_id,
  74. value: JSON.stringify(newarr)
  75. } //提交数据
  76. this.$store.state.user.items.push(item)
  77. },
  78. reset() {
  79. this.$nextTick(() => {
  80. let len = this.$refs.uUpload.lists.length
  81. this.$refs.uUpload.lists.splice(0,len)
  82. })
  83. }
  84. }
  85. }
  86. </script>
  87. <style>
  88. </style>