chooseImage.vue
2.5 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<view class="submitGamePicture">
<template v-for="(item,index) in tempFileList">
<view class="submitGamePicture-item" :key="item.path">
<image :src="item.path" class="submitGamePicture-icon"></image>
<uni-icons type="closeempty" class="submitGamePicture-delete" color="#ffffff" @click="deleteImgHandle(index)"></uni-icons>
</view>
</template>
<view v-if="tempFileList.length<limit" class="submitGamePicture-btn" @click="chooseImageHandle">
<uni-icons type="plusempty" size="30"></uni-icons>
<text style="padding-top: 2px;">添加图片</text>
</view>
</view>
</template>
<script>
export default {
name: "chooseImage",
props: {
limit: {
type: String,
default: '9'
},
FileList: {
type: Array,
default: () => {
return []
}
}
},
data() {
return {
tempFileList: [], //选择图片临时存储
};
},
mounted() {
this.tempFileList = this.FileList;
},
methods: {
//上传图片
chooseImageHandle() {
let that = this;
let limit = parseInt(this.limit);
uni.chooseImage({
count: limit, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
that.tempFileList.push(res.tempFiles[0])
}
})
},
//删除图片
deleteImgHandle(currentIndex) {
const temp = this.tempFileList.splice(currentIndex, 1);
},
}
}
</script>
<style scoped>
.submitGamePicture {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-top: 2px;
}
.submitGamePicture-item {
width:70px;
height: 70px;
margin-right: 9.5px;
margin-top: 9.5px;
display: flex;
background-color: #FFFFFF;
position: relative;
}
.submitGamePicture-icon {
border: 1px solid #70737F;
border-radius: 8px;
width: 100%;
height: 100%;
display: block;
}
.submitGamePicture-delete {
position: absolute;
top: -5px;
right: -5px;
background-color: #ff0000;
border-radius: 10px;
}
.submitGamePicture-btn {
border: 1px dashed #70737F;
border-radius: 8px;
width: 70px;
height: 70px;
margin-right: 9.5px;
margin-top: 9.5px;
display: flex;
flex-direction: column;
font-size: 13px;
font-family: Source Han Sans CN;
font-weight: 400;
color: #999999;
justify-content: center;
align-items: center;
}
</style>