1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
| <template>
| <view>
| <view class="grid-box">
| <view class="image-box" v-for="(item,index) in imageList" :key="index">
| <image :src="item" mode="aspectFit"></image>
| <image src="/static/policy/close.png" mode="widthFix" @click="delImage(index)" class="close"></image>
| </view>
| <view class="cam-box" @click="upload" v-if="imageList.length < max">
| <image src="/static/policy/carmea.png" mode="widthFix"></image>
| </view>
| </view>
| </view>
| </template>
|
| <script>
| export default {
| props: {
| max: {
| type: Number,
| default: 9
| },
| maxSize: {
| type: Number,
| default: 2 * 1024 * 1024
| }
| },
| data() {
| return {
| imageList: []
| }
| },
| methods: {
| upload() {
| uni.chooseImage({
| count: 9 - this.imageList.length,
| success: val => {
| const value = val.tempFiles.every(item => item.size < this.maxSize)
| if(!value){
| uni.showToast({
| title: '照片尺寸过大',
| icon: 'none'
| })
| return
| }
| this.imageList.push(val.tempFilePaths[0])
| }
| })
| },
| delImage(index) {
| this.imageList.splice(index,1)
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .cam-box{
| background-color: #F4F4F4;
| border-radius: 10rpx;
| width: 200rpx;
| height: 200rpx;
| text-align: center;
| line-height: 200rpx;
| image{
| width: 28rpx;
| height: 28rpx;
| }
| }
| .grid-box{
| display: grid;
| grid-template-columns: 1fr 1fr 1fr;
| grid-gap: 20rpx;
| }
| .image-box{
| width: 200rpx;
| height: 200rpx;
| border-radius: 10rpx;
| position: relative;
| image{
| width: 100%;
| height: 100%;
| border: 2rpx solid #F4F4F4;
| border-radius: 10rpx;
| }
| .close{
| width: 44rpx;
| height: 44rpx;
| position: absolute;
| top: -20rpx;
| right: -20rpx;
| border: none;
| }
| }
| </style>
|
|