list.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="flex wrap">
  3. <view @click="uploadAct" v-if="value.length < maxNum" class="upload-list-photo camera flex center alcenter">
  4. <view class="upload" :style="{background:isMain ? tempColor : '#5E40FF'}">
  5. <text class="iconfont iconicon_photo cl-w"></text>
  6. </view>
  7. </view>
  8. <view v-for="(item,index) in value" :key="index" class="upload-list-photo">
  9. <image class="photo" :src="item"></image>
  10. <view :data-index="index" @click="delPic" class="del">
  11. <text class="iconfont iconbtn_close cl-w"></text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import qiniu from '../../static/js/qiniu.js';
  18. export default{
  19. props:{
  20. value:{
  21. type:Array,
  22. default:function(){
  23. return new Array;
  24. }
  25. },
  26. isMain:{
  27. type:Boolean,
  28. default:true,
  29. },
  30. maxNum:{ //最多上传的数量
  31. type:Number,
  32. default:9
  33. }
  34. },
  35. data(){
  36. return {
  37. }
  38. },
  39. computed:{
  40. getNum(){
  41. return this.maxNum - this.value.length;
  42. }
  43. },
  44. created(){
  45. },
  46. methods:{
  47. delPic(e){
  48. let index = parseInt(e.currentTarget.dataset.index);
  49. let oldImgs = JSON.parse(JSON.stringify(this.value));
  50. oldImgs.splice(index,1);
  51. this.$emit('input',oldImgs);
  52. },
  53. uploadAct(){
  54. uni.chooseImage({
  55. count:this.getNum,
  56. success:(chooseImageRes)=>{
  57. if(chooseImageRes.tempFilePaths.length > 0){
  58. // this.$http.api('child.upload/imageAuth').then(auth=>{
  59. // let domain = auth.url;
  60. // let token = auth.token;
  61. // let region = auth.region_mini;
  62. // for (var i = 0; i < chooseImageRes.tempFilePaths.length; i++) {
  63. // let file = chooseImageRes.tempFilePaths[i];
  64. // let index = file.lastIndexOf('/');
  65. // let len = file.length
  66. // let name = file.substring(index + 1, len);
  67. // qiniu.upload(file, (res) => {
  68. // let url = res.imageURL;
  69. // let oldImgs = JSON.parse(JSON.stringify(this.value));
  70. // oldImgs.push(url);
  71. // this.$emit('input',oldImgs);
  72. // }, (error) => {
  73. // console.log(error);
  74. // }, {
  75. // region: region,
  76. // key: name,
  77. // domain:domain,
  78. // uptoken: token,
  79. // });
  80. // }
  81. // }).catch(res=>{
  82. // console.log(res);
  83. // });
  84. }
  85. }
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style>
  92. .upload-list-photo{
  93. width:190rpx;
  94. height:190rpx;
  95. border-radius:16rpx;
  96. position: relative;
  97. margin-right: 30rpx;
  98. margin-bottom: 30rpx;
  99. }
  100. .upload-list-photo.camera{
  101. background:#FFFFFF;
  102. border:2rpx dashed #C5CADB;
  103. }
  104. .upload-list-photo.camera .upload{
  105. width: 64rpx;
  106. height: 64rpx;
  107. border-radius: 32rpx;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. }
  112. .upload-list-photo:nth-child(3n){
  113. margin-right: 0rpx;
  114. }
  115. .upload-list-photo .photo{
  116. width:190rpx;
  117. height:190rpx;
  118. border-radius:16rpx;
  119. background: #f2f2f2;
  120. }
  121. .upload-list-photo .del{
  122. width: 56rpx;
  123. height: 56rpx;
  124. position: absolute;
  125. border-radius: 28rpx;
  126. background: rgba(0,0,0,0.5);
  127. display: flex;
  128. justify-content: center;
  129. align-items: center;
  130. z-index: 2;
  131. right: 0;
  132. top: 0;
  133. }
  134. </style>