详情小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.7 KiB

  1. <template>
  2. <view class="content">
  3. <view class="my-images">
  4. <view class="my-image-item" @click="uploadImage" v-if="image_list.length < image_count">
  5. <text class="lf-iconfont icon-jia my-image-item-after"></text>
  6. </view>
  7. <view class="my-image-item" v-for="(item, index) in image_list" :key="index" @click="showMenu(index)">
  8. <image :src="item" mode="aspectFill"></image>
  9. <!-- <view class="remove-image" @click.stop="removeInage(index)">
  10. <text class="lf-iconfont icon-shanchu"></text>
  11. </view> -->
  12. <view class="mask">审核中</view>
  13. </view>
  14. </view>
  15. <view class="tips-desc">小提示最多可上传9张个人形象照使用本人近期真实照片为佳</view>
  16. <u-action-sheet :list="menu_list" v-model="show_menu" @click="clickSheet"></u-action-sheet>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data(){
  22. return {
  23. image_list: [],
  24. image_count: 9,
  25. menu_list: [{
  26. text: '设为封面图',
  27. }, {
  28. text: '预览'
  29. }, {
  30. text: '删除',
  31. color: 'red'
  32. }],
  33. show_menu: false,
  34. click_index: null
  35. }
  36. },
  37. onLoad(){
  38. },
  39. methods: {
  40. // 显示操作菜单
  41. showMenu(index){
  42. this.click_index = index;
  43. this.show_menu = true;
  44. },
  45. // 点击了操作菜单的某一项
  46. clickSheet(current){
  47. switch(current){
  48. case 1: this.lookImage(this.click_index); break;
  49. case 2: this.removeInage(this.click_index); break;
  50. }
  51. },
  52. // 上传凭证图片
  53. uploadImage(){
  54. let current_count = this.image_count - this.image_list.length;
  55. if(current_count == 0) return;
  56. uni.chooseImage({
  57. count: current_count,
  58. complete: result => {
  59. if(result.errMsg == "chooseImage:fail cancel"){
  60. return; // 取消选择图片
  61. }
  62. let tempFiles = result.tempFiles;
  63. let image_list = [];
  64. let overstep = false;
  65. tempFiles.map(item => {
  66. // 上传的图片需小于10MB
  67. if(item.size < 10464788){
  68. image_list.push(item.path);
  69. }else{
  70. overstep = true;
  71. }
  72. })
  73. if(overstep){
  74. uni.showModal({
  75. title: '温馨提示',
  76. content: '您上传的图片含有超出10M大小的限制,请优化大小后再上传!',
  77. showCancel: false
  78. })
  79. }
  80. this.image_list.push(...image_list);
  81. }
  82. })
  83. },
  84. // 预览图片
  85. lookImage(current){
  86. if(this.image_list.length <= 0) return;
  87. this.$u.throttle(() => {
  88. uni.previewImage({
  89. urls: this.image_list,
  90. current: current
  91. });
  92. }, 500);
  93. },
  94. // 移除图片
  95. removeInage(current){
  96. this.image_list.splice(current, 1);
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped="scoped">
  102. .content{
  103. width: 750rpx;
  104. height: max-content;
  105. box-sizing: border-box;
  106. padding: 30rpx 32rpx;
  107. }
  108. .my-images{
  109. display: flex;
  110. flex-wrap: wrap;
  111. margin-bottom: 40rpx;
  112. .my-image-item{
  113. width: 220rpx;
  114. height: 220rpx;
  115. background: #DDDDDD;
  116. position: relative;
  117. margin-right: 12rpx;
  118. &:nth-child(3n){
  119. margin-right: 0rpx;
  120. }
  121. &:nth-child(n+4){
  122. margin-top: 12rpx;
  123. }
  124. image{
  125. width: 100%;
  126. height: 100%;
  127. }
  128. .remove-image{
  129. position: absolute;
  130. right: -4rpx;
  131. top: -18rpx;
  132. color: #e74c3c;
  133. font-size: 40rpx;
  134. padding: 8rpx;
  135. }
  136. .mask{
  137. position: absolute;
  138. bottom: 0;
  139. left: 0;
  140. width: 100%;
  141. height: 42rpx;
  142. background-color: rgba(0,0,0,0.5);
  143. color: #FFFFFF;
  144. font-size: 24rpx;
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. }
  149. }
  150. .my-image-item-after{
  151. position: absolute;
  152. width: 100%;
  153. height: 100%;
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. font-size: 60rpx;
  158. color: #999999;
  159. }
  160. }
  161. .tips-desc{
  162. font-size: 24rpx;
  163. color: #999999;
  164. }
  165. </style>