uni-app 157发布朋友圈-批量上传图片
作者:互联网
如下是我测试的截图
/components/free-ui/free-upload-image.vue
<template>
<view class="flex flex-wrap">
<view style="width: 230rpx;" v-for="(item,index) in imageList" :key='index' class="flex align-center justify-center pt-2 position-relative">
<image :src="item" class="bg-light rounded" style="width: 210rpx;height: 210rpx;" @click="preview(item)"></image>
<view class="flex align-center justify-center bg-danger rounded-circle " style="width: 60rpx;height: 60rpx;position: absolute;right: 0;top: 10rpx;background-color: rgba(0,0,0,0.5);" @click="deleteImage(item)">
<text class="iconfont text-white font-small">X</text>
</view>
</view>
<view v-if="imageList.length < 9" style="width: 230rpx;" class="flex align-center justify-center" @click="chooseImage">
<view class="flex align-center justify-center bg-light rounded" style="width: 210rpx;height: 210rpx;">
<text class="text-light-muted" style="font-size: 100rpx;">+</text>
</view>
</view>
</view>
</template>
<script>
import $H from '@/common/free-lib/request.js';
export default{
props:{
data:{
type:Array,
default:()=>{
return []
}
}
},
data(){
return {
imageList:[]
}
},
mounted() {
this.imageList = this.data;
},
methods:{
// 选择图片
chooseImage(){
uni.chooseImage({
count:9 - this.imageList.length,
sizeType:['compressed'],
success:(res)=>{
// 上传
res.tempFilePaths.forEach(path=>{
$H.upload('/upload',{
filePath:path
},(progress)=>{
console.log('上传进度',progress);
}).then(url=>{
this.imageList.push(url);
this.$emit('update',this.imageList);
})
})
// this.imageList = [...this.imageList,...res.tempFilePaths];
// this.$emit('update',this.imageList);
}
})
},
// 预览图片
preview(item){
uni.previewImage({
current:item,
urls:this.imageList
})
},
// 删除图片
deleteImage(item){
uni.showModal({
content:'是否要删除该图片?',
success:(res)=>{
if(res.confirm){
// 执行删除
let index = this.imageList.findIndex(url=>url === item);
if(index !== -1){
this.imageList.splice(index,1);
this.$emit('update',this.imageList);
}
}
}
})
}
}
}
</script>
<style>
</style>
/pages/find/moments/moments.vue
<template>
<view>
<free-transparent-bar :scrollTop="scrollTop" @clickRight="clickRight"></free-transparent-bar>
<view class="position-relative" style="height: 620rpx;">
<image src="https://douyinzcmcss.oss-cn-shenzhen.aliyuncs.com/shengchengqi/datapic/1.jpg" mode="aspectFill" style="height: 590rpx;" class="bg-secondary w-100"></image>
<image :src="user.avatar || '/static/images/demo/demo6.jpg'" style="width: 120rpx;height:120rpx;right: 30rpx;" mode="" class="bg-secondary rounded position-absolute bottom-0"></image>
<text class="text-white font-md position-absolute" style="bottom: 45rpx;right: 160rpx">{{user.nickname || user.username}}</text>
</view>
<!-- 朋友圈列表样式 -->
<free-moment-list v-for="(item,index) in list" :key='index' :item="item" :index="index" @action="doAction" @reply="replyEvent"></free-moment-list>
<!-- 评论框 -->
<free-popup ref="action" bottom transformOrigin="center bottom">
<view style="height: 105rpx;" class="bg-light border-top flex align-center">
<textarea fixed class="bg-white rounded p-2 font-md" style="height: 45rpx;width: 420rpx;" value="" placeholder="" v-model="content" :focus="true"/>
<free-icon-button @click="changeFaceModeal"><text class="iconfont font-lg"></text></free-icon-button>
<free-main-button name="发送" :disabled="content.length===0" @click="send"></free-main-button>
</view>
<!-- 表情包 -->
<scroll-view v-if="faceModal" scroll-y="true" style="height: 350rpx;" class="bg-light">
<view class="flex flex-wrap">
<view class="flex align-center justify-center" hover-class="bg-white" style="width:107rpx;height:107rpx;" v-for="(item,index) in faceList" :key="index" @click="addFace(item)">
<text>{{item}}</text>
</view>
</view>
</scroll-view>
</free-popup>
<!-- 上拉加载 -->
<view class="flex align-center justify-center py-5 bg-light" v-if="list.length >= 10">
<text class="text-muted font">{{loadmore}}</text>
</view>
</view>
</template>
<script>
import freeTransparentBar from '@/components/free-ui/free-transparent-bar.vue';
import freeMomentList from '@/components/free-ui/free-moment-list.vue';
import freePopup from '@/components/free-ui/free-popup.vue';
import freeIconButton from '@/components/free-ui/free-icon-button.vue';
import freeMainButton from '@/components/free-ui/free-main-button.vue';
import $H from '@/common/free-lib/request.js';
import { mapState } from 'vuex';
export default {
components:{
freeTransparentBar,
freeMomentList,
freePopup,
freeIconButton,
freeMainButton
},
data() {
return {
content:'',
scrollTop:0,
faceModal:false,
faceList:["标签:157,res,app,free,item,朋友圈,uni,imageList,user
来源: https://blog.csdn.net/ab15176142633/article/details/121747999