|
|
@@ -4,26 +4,14 @@
|
|
|
<ul>
|
|
|
<li class="list_img" v-for="(item,index) in showImgList" :key="index"
|
|
|
:style="{ width: size + 'rpx', height: size + 'rpx' }">
|
|
|
- <view class="iconfont icondelete" @click="delImg(index)" v-if='!disableds'></view>
|
|
|
- <image :src="http+item.url" @click="viewImg(item.url)"
|
|
|
- :style="{ width: size + 'rpx', height: size + 'rpx' }"></image>
|
|
|
+ <view class="iconfont icondelete" @click="delImg(index)"></view>
|
|
|
+ <image :src="item" @click="viewImg(item)"
|
|
|
+ :style="{ width: size + 'rpx', height: size + 'rpx' }" :mode="imgMode" ></image>
|
|
|
</li>
|
|
|
- <div v-if='!disableds'>
|
|
|
- <li v-if="showImgList.length < num" class="uploadImg" @click="chooseImage"
|
|
|
- :style="{ width: size + 'rpx', height: size + 'rpx' }">
|
|
|
- <view class="iconfont"></view>
|
|
|
- </li>
|
|
|
- </div>
|
|
|
- <div v-if='disableds'>
|
|
|
- <li v-if="showImgList.length < num" class="uploadImg"
|
|
|
- :style="{ width: size + 'rpx', height: size + 'rpx' }">
|
|
|
- <view class="iconfont"></view>
|
|
|
- </li>
|
|
|
- </div>
|
|
|
- <!-- <li v-if="(showImgList.length < num)&&(disabled==false)" class="uploadImg" @click="chooseImage"
|
|
|
+ <li v-if="showImgList.length < num" class="uploadImg" @click="chooseImage"
|
|
|
:style="{ width: size + 'rpx', height: size + 'rpx' }">
|
|
|
- <view class="iconfont"></view>
|
|
|
- </li> -->
|
|
|
+ <view class="iconfont icontupiantianjia"></view>
|
|
|
+ </li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
</view>
|
|
|
@@ -31,7 +19,7 @@
|
|
|
<script>
|
|
|
import { uploadPic } from '@/api/common'
|
|
|
export default {
|
|
|
- name: 'App_uploader',
|
|
|
+ name: 'app-uploader',
|
|
|
props: {
|
|
|
// 传入的图片数组
|
|
|
imgList: {
|
|
|
@@ -79,20 +67,23 @@ export default {
|
|
|
},
|
|
|
multiple: { // 是否多图上传
|
|
|
type: Boolean,
|
|
|
- default: false
|
|
|
+ default: true
|
|
|
},
|
|
|
disabled: { // 是否只读
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
+ },
|
|
|
+ // 图片展示模式
|
|
|
+ imgMode: {
|
|
|
+ type: String,
|
|
|
+ default: 'scaleToFill'
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
showImgList: [],
|
|
|
base64ImgList: [],
|
|
|
- xssarr: ['data:', 'text', 'txt', 'html', 'js', 'css', 'json', 'exe', 'sql', 'xml', 'doc', 'docx'],
|
|
|
- disableds: true,
|
|
|
- http: this.$constant.formal
|
|
|
+ xssarr: ['data:', 'text', 'txt', 'html', 'js', 'css', 'json', 'exe', 'sql', 'xml', 'doc', 'docx']
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
@@ -109,8 +100,6 @@ export default {
|
|
|
uni.removeStorageSync(this.saveStr)
|
|
|
}
|
|
|
this.showImgList = [...this.imgList]
|
|
|
- // this.showImgList = this.imgList
|
|
|
- // console.log('组件',this.imgList)
|
|
|
},
|
|
|
methods: {
|
|
|
chooseImage: async function() {
|
|
|
@@ -134,8 +123,7 @@ export default {
|
|
|
let base64ImgList = that.base64ImgList
|
|
|
let params = {}
|
|
|
if (base64ImgList.length === 1) {
|
|
|
- // params['file[content]'] = base64ImgList[0]
|
|
|
- params.coding = base64ImgList[0]
|
|
|
+ params['file[content]'] = base64ImgList[0]
|
|
|
} else {
|
|
|
base64ImgList.forEach((item, index) => {
|
|
|
params[`file[${index}][content]`] = item
|
|
|
@@ -147,40 +135,21 @@ export default {
|
|
|
relative_path: 1
|
|
|
}).then(res => {
|
|
|
if (res.status === 'success') {
|
|
|
- uni.hideLoading()
|
|
|
- let imgs = {}
|
|
|
- imgs.url = res.data.upload_file_dir
|
|
|
- imgs.urls = res.data.url
|
|
|
that.showImgList = [
|
|
|
- ...that.showImgList
|
|
|
+ ...that.showImgList,
|
|
|
+ ...res.data.image_url.reverse()
|
|
|
]
|
|
|
- that.showImgList.unshift(imgs)
|
|
|
- let showing = that.showImgList
|
|
|
- let imgbox = []
|
|
|
- showing.map((item, index) => {
|
|
|
- let imgs = {}
|
|
|
- if (item.url) {
|
|
|
- imgs.url = item.url
|
|
|
- // imgs.urls = that.$constant.formal + item.url
|
|
|
- } else {
|
|
|
- imgs.url = item
|
|
|
- // imgs.urls = that.$constant.formal +item
|
|
|
- }
|
|
|
- imgbox.push(imgs)
|
|
|
- })
|
|
|
- that.showImgList = imgbox
|
|
|
- this.$emit('currentUpload', imgs)
|
|
|
+ this.$emit('currentUpload', res.data.image_url.reverse())
|
|
|
this.$emit('getResult', that.showImgList)
|
|
|
resolve(that.showImgList)
|
|
|
} else {
|
|
|
- uni.hideLoading()
|
|
|
reject(res)
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
// 转64
|
|
|
- async blobToBase64(tempFilePaths) {
|
|
|
+ async blobToBase64(tempFilePaths) {
|
|
|
let that = this
|
|
|
that.base64ImgList = []
|
|
|
let newImgList = [...tempFilePaths]
|
|
|
@@ -284,14 +253,15 @@ export default {
|
|
|
for (let i = 0; i < tempFiles.length; i++) {
|
|
|
// 大于1.5m就不让上传
|
|
|
let fileSize = tempFiles[i].size
|
|
|
- if (fileSize > 1024 * 1024 * 20) {
|
|
|
- // uni.showToast({
|
|
|
- // title: '上传图片不能大于10M',
|
|
|
- // duration: 2000,
|
|
|
- // icon: 'none'
|
|
|
- // })
|
|
|
+ if (fileSize > 1024 * 1024 * 1.5) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '过滤不能大于1.5m的文件',
|
|
|
+ duration: 2000,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
continue
|
|
|
}
|
|
|
+
|
|
|
// 文件类型设置
|
|
|
let spl = tempFiles[i].path.split('.')
|
|
|
let fileType = spl[spl.length - 1]
|
|
|
@@ -303,15 +273,12 @@ export default {
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
+
|
|
|
newtempFiles.push(tempFiles[i])
|
|
|
newtempFilePaths.push(tempFilePaths[i])
|
|
|
}
|
|
|
res.tempFiles = newtempFiles
|
|
|
res.tempFilePaths = newtempFilePaths
|
|
|
- uni.showLoading({
|
|
|
- title: '图片上传中...',
|
|
|
- mask: true
|
|
|
- })
|
|
|
// console.log('过滤完了')
|
|
|
},
|
|
|
// 删除
|
|
|
@@ -331,11 +298,9 @@ export default {
|
|
|
},
|
|
|
// 预览
|
|
|
viewImg(path) {
|
|
|
- let arr = []
|
|
|
- arr[0] = this.$constant.formal + path
|
|
|
uni.previewImage({
|
|
|
- urls: arr,
|
|
|
- current: this.$constant.formal + path
|
|
|
+ urls: this.showImgList,
|
|
|
+ current: path
|
|
|
})
|
|
|
},
|
|
|
// 获取图片信息
|
|
|
@@ -377,6 +342,9 @@ export default {
|
|
|
|
|
|
.upload-box {
|
|
|
padding: 0 30px;
|
|
|
+ &:first-child {
|
|
|
+ padding-left: 0;
|
|
|
+ }
|
|
|
|
|
|
& > ul {
|
|
|
display: inline-block;
|