🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
import {Order} from "../../model/order.js"; ``` import {Http} from "../utils/http"; import {Paging} from "../utils/paging"; import {config} from "../config/config"; class Order{ static async getContent(group=''){ if(group==''){ var paging= new Paging({url:'v1/order/getContentData'}); }else{ var paging= new Paging({url:`v1/order/getContentData?group_id=${group}`}); } console.log(group) return paging; } static makeImages(data){ data.forEach((item)=>{ //是否开启图片压缩 if(config.compress){ if(item.avatar)item.avatar+=config.headerCompressRule; if(item.images){ var imgArray=item.images.split(','); var okimg=[]; imgArray.forEach((i)=>{ okimg.push(i+=config.comunityCompressRule); }) item.images=okimg; } }else{ if(item.images) item.images=item.images.split(','); } }) return data; } //发送动态 static async sendContent(data){ return await Http.tSend({ url:`v1/order/sendContent`, data:data, method:"POST" }) } //上传文件 static async uploadFile(file){ return await Http.upload({ url:`v1/file/uploadFile`, file:file }) } //获取动态详细信息 static async getCommunityInfo(id){ var res = await Http.send({ url:`v1/order/getCommunityInfo?Id=${id}` }) var info =Community.makeImages([res.data]); res.data=info[0]; return res; } //删除动态 static async removeCommunity(id){ return await Http.tSend({ url:`v1/order/removeCommunity?Id=${id}` }) } //获取用户的动态 static async getUserCommunity(Id=''){ if(Id==''){ uni.showToast({ title:"用户参数错误", icon:'none' }) return ; } var paging= new Paging({url:`v1/order/getUserCommunity?Id=${Id}`}); return paging; } // static async getUserCommunityIndex(Id=''){ if(Id==''){ uni.showToast({ title:"用户参数错误", icon:'none' }) return ; } return await Http.request({ url:`v1/order/getUserCommunityIndex?Id=${Id}` }) } static async searchAll(e){ var paging= new Paging({url:'v1/order/searchAll?searchValue='+e}); return paging; } } export { Order } ``` send/order.vue ``` <template> <view> <header-title title="发布你的内容吧" :isPoint="true" pointColor="#5466ff" :isBtn="true" :btnStyle="customStyle" @clickBtn="clickBtn" ></header-title> <view class="content Limit"> <view style="margin: 15rpx;"> <u-input v-model="form.content" :auto-height="false" type="textarea" maxlength="1000" height="300" placeholder="想说你就多说点" :border="false" /></u-form-item> <view style="color: #C0C4CC;"> <text>{{form.content.length}}/1000</text> </view> </view> <u-upload :action="action" :header="header" :upload-text="type=='video'?'选择视频':'选择图片'" :max-count="type=='video'?1:9" :limitType="limitType" @on-success="uploadSuccess" :before-upload="beforeUpload" v-if="type=='image'" @on-error="onImageError" :show-tips="false" ></u-upload> <upload v-if="type=='video'" @uploadData="uploadData"></upload> <u-cell-group> <u-cell-item title="添加地点" @click="addAddress" :arrow="false"> <text class="iconfont icondingwei" slot="icon" style="margin-right: 10rpx;"></text> <text slot="right-icon">{{address}}</text> </u-cell-item> <u-cell-item title="发布类别" @click="changeGroup" :arrow="false"> <text class="iconfont" slot="icon" style="margin-right: 10rpx;"> &#xe8cb; </text> <text slot="right-icon">{{group.length>0?group[okGroup].name:''}}</text> <u-picker v-model="show" mode="selector" :range="group" range-key="name" @confirm="confirm"></u-picker> </u-cell-item> <!-- <u-cell-item title="置顶" :arrow="false"> <text class="iconfont" slot="icon" style="margin-right: 10rpx;"> &#xe729; </text> <view slot="right-icon"> <u-switch v-model="form.checked"></u-switch> </view> </u-cell-item> --> </u-cell-group> </view> </view> </template> <script> import {config} from "../../config/config"; import {Order} from "../../model/order"; import headerTitle from "../../components/header-title/header-title.vue" import upload from "../../components/upload/upload.vue" export default { data() { return { customStyle: { backgroundColor: '#5466ff', marginRight: '30rpx' }, type:'image', header:{ token:uni.getStorageSync('token') }, uploadVideo:'', form: { content: '', checked: false }, show: false, address:"", location:"", okGroup:0, limitType:['png', 'jpg', 'jpeg', 'webp', 'gif'], action:config.apiBaseUrl+'v1/file/uploadFile', fileList: [ ], group:[] }; }, components:{ headerTitle }, async onLoad(e) { this.type=e.type; if(this.type=='video'){ this.limitType=['mp4','avi','mov','flv']; } var res = await Order.getCommunityGroup(); if(res.code==200){ this.group=res.data; } }, methods:{ onImageError(e){ uni.showToast({ title:e.msg, icon:"none" }) }, beforeUpload(){ uni.showLoading({ title:"上传中", icon:"none", mask:true }) }, //视频上传成功 uploadData(e){ this.uploadVideo=e; console.log(e); }, confirm(e){ this.okGroup=e; }, changeGroup(){ this.show=!this.show; }, addAddress(e){ var that = this; uni.chooseLocation({ success: function (res) { that.address=res.name; that.location=res.longitude+','+res.latitude; } }); }, uploadSuccess(e){ this.fileList.push(e.data.src); uni.hideLoading(); }, cunstomback(){ uni.reLaunch({ url:"../home/order" }) }, async clickBtn(e){ if(this.form.content.length<1){ uni.showToast({ title:"说点什么在发吧", icon:'none' }) return; } if(this.type=='image'){ const images=this.fileList.join(','); var data= { communityContent:this.form.content, images:images, video:null, group_id:this.group[this.okGroup].Id, address:this.address, location:this.location } var res = await Order.sendContent(data); if(res.code==200){ uni.showToast({ title:res.msg }) setTimeout(()=>{ uni.reLaunch({ url:'../home/order' }) },1000) } }else{ var data= { communityContent:this.form.content, images:null, video:this.uploadVideo!=''?this.uploadVideo.video:null, group_id:this.group[this.okGroup].Id, address:this.address, location:this.location } var res = await Order.sendContent(data); if(res.code==200){ uni.showToast({ title:res.msg }) setTimeout(()=>{ uni.reLaunch({ url:'../home/order' }) },1000) } } } } }; </script> <style lang="scss"> </style> ``` home/order.vue ``` <template> <view> <view class="u-page" style="height: 93vh;"> <view style="width: 95%;margin: 0 auto;"> <u-search placeholder="点我搜索" :disabled="true" :show-action="false" @click="tapSearch"></u-search> </view> <u-tabs :list="list" active-color="#5466ff" :is-scroll="true" :current="swiperCurrent" @change="change"></u-tabs> <block v-for="(i,j) in communityList" :key="j"> <community-card @tapComment="tapComment" :info="i" :isIndex="j" @clickGood="clickGood" @clickCollection="clickCollection" @clickFollow="clickFollow" @clickH5comment="clickH5comment" @changeMoreSelect="changeMoreSelect" ></community-card> </block> <community-comment :show="showComment" :info="commentList" @close="closeComment" @sendComment="sendComment" @tapGood="tapGood" @tapGoodTwo="tapGoodTwo" ></community-comment> <view style="width: 100%;height: 10vh;margin-top: 20rpx;"> <u-loadmore :status="status"/> </view> <view style="width: 100%;height: 10vh"> </view> </view> <!-- <u-tabbar active-color="#5466ff" v-model="current" :list="tabbar" :mid-button="true" height="7vh"></u-tabbar> --> <tabbar :current='current' :show="show" @changeShow="changeShow"></tabbar> </view> </template> <script> import communityCard from '../../components/community-card/index.vue'; import communityComment from '../../components/community-comment/index.vue'; import tabbar from "../../components/tabbar/tabbar" //import tabbar from "../../common/tabbar.js" import {Order} from "../../model/order"; import {getTime} from "../../utils/public.js"; export default { data() { return { current:0, tabsCurrent:1, swiperCurrent:0, // tabbar:tabbar, communityList:[], commentList:[], status:"loading", list: [ { name: '关注', }, { name: '最新' }, { name: '最热' } ], show:false, showComment: false, commentCode:{ }, communityObject:"" }; }, components: { communityCard, communityComment, tabbar }, mounted() { }, async onLoad(){ await this.initGroup(); this.initList(); }, async onReachBottom(){ if(this.communityObject=="")return ; var paging =await this.communityObject; console.log(paging.moreData==true) if(paging.moreData){ var data = await paging.getMoreData(); const resData=Order.makeImages(data.items); this.communityList=this.communityList.concat(resData); if(!data.moreData){ this.status="nomore"; } }else{ this.status="nomore"; } console.log(this.status) }, async onPullDownRefresh(){ await this.initList(); uni.showToast({ title:"刷新完成", icon:'none' }) uni.stopPullDownRefresh(); }, methods: { tapSearch(e){ console.log(123) uni.navigateTo({ url:"../search/search" }) }, changeShow(e){ console.log(e) this.show=true; }, //选择了更多 async changeMoreSelect(e){ //举报 if(e.value==1){ var ress = await Order.sendReport(e.Id); //删除 }else if(e.value==2){ var that = this; await new Promise((res,rs)=>{ uni.showModal({ title: '提示', content: '确定要删除吗', success: async function (res) { if (res.confirm) { var ress = await Order.removeOrder(e.Id); that.communityList.splice(e.index, 1); } else if (res.cancel) { console.log('用户点击取消'); } } }); }) } if(ress.code==200){ uni.showToast({ title:ress.msg }) }else{ uni.showToast({ title:ress.msg, icon:'none' }) } }, //H5点击回复 clickH5comment(e){ uni.navigateTo({ url:"../community/index?Id="+e }) }, //初始化数据 async initList(group='',index=1){ this.swiperCurrent=index; //初始化最新首页数据 if(group==''){ var paging = await Order.getContent(); }else{ var paging = await Order.getContent(group); } var data = await paging.getMoreData(); if(!data.moreData){ this.status="nomore"; }; const resData=Order.makeImages(data.items); this.communityList=resData; this.communityObject=paging; }, //初始化圈子类别 async initGroup(){ var quanzi = await Order.getCommunityGroup(); quanzi.data.shift(); this.list=this.list.concat(quanzi.data) }, //二级评论点赞 async tapGoodTwo(e){ var res = await Order.sendCommentTwoGood(e.Id); if(res){ this.commentList[e.index].twoComment[e.indexTwo].isGood=!e.isGood; this.commentList[e.index].twoComment[e.indexTwo].isGood==1?this.commentList[e.index].twoComment[e.indexTwo].good+=1:this.commentList[e.index].twoComment[e.indexTwo].good-=1; } }, //评论点赞 async tapGood(e){ var res = await Order.sendCommentGood(e.Id); if(res){ this.commentList[e.index].isGood=!e.isGood; this.commentList[e.index].isGood==1?this.commentList[e.index].good+=1:this.commentList[e.index].good-=1; } }, //评论 async sendComment(e){ const res = await Order.senComment({'community_id':this.commentCode.Id,'comment_user_id':e.Id,'content':e.content}); if(res){ uni.showToast({ title:"评论成功" }) uni.$emit('commentOk',{ code:true }); const userInfo=uni.getStorageSync('userInfo'); let comment={ Id: res.data.Id, avatar: userInfo.avatar, content: e.content, create_time:getTime(), good: 0, isGood: 0, nickname: userInfo.nickname, sign: userInfo.sign, twoComment: [], user_id: userInfo.Id, username: userInfo.username } if(e.Id){ this.commentList[e.index]['twoComment'].unshift(comment); }else{ this.commentList.unshift(comment); } } }, //关注 async clickFollow(e){ uni.showLoading({ title:"请求中" }) const res= await Order.sendFollow(e.Id); uni.hideLoading(); var that = this; this.communityList.forEach((item,index)=>{ if(item.user_id==e.Id){ that.communityList[index].isFollow=!e.isFollow; } }) }, //点赞 async clickGood(e){ this.communityList[e.isIndex].isGood=!e.isGood; e.isGood==0?this.communityList[e.isIndex].good+=1:this.communityList[e.isIndex].good-=1; const res= await Order.sendGood(e.Id); if(res){ //#ifdef MP-WEIXIN uni.vibrateShort({ success: function () { console.log('抖动'); } }); //#endif }else{ this.communityList[e.isIndex].isGood=!this.communityList[e.isIndex].isGood; e.isGood==0?this.communityList[e.isIndex].good-=1:this.communityList[e.isIndex].good+=1; } }, //收藏 async clickCollection(e){ this.communityList[e.isIndex].isCollection=!e.isCollection; e.isCollection==0?this.communityList[e.isIndex].collection+=1:this.communityList[e.isIndex].collection-=1; const res= await Order.sendCollection(e.Id); if(res){ //#ifdef APP-PLUS||MP-WEIXIN uni.vibrateShort({ success: function () { console.log('抖动'); } }); //#endif }else{ e.isCollection==0?this.communityList[e.isIndex].collection-=1:this.communityList[e.isIndex].collection+=1; } }, async tapComment(e) { this.commentCode=e; this.showComment = true; const res= await Order.getComment(e.Id); this.commentList=res.accoumulator; }, closeComment(e) { this.showComment = false; }, //获取我的关注 async getMyFollow(){ if(uni.getStorageSync('userInfo')==undefined || uni.getStorageSync('userInfo')==''){ uni.showToast({ title:"请先登录", icon:"none" }) return ; } this.swiperCurrent = 0; var paging = await Order.getMyFollow(); const moreData = await paging.getMoreData(); const data=Order.makeImages(moreData.items); if(!data.moreData){ this.status="nomore"; }; this.communityList=data; this.communityObject=paging; }, //获取最热 async getOrderFire(){ this.swiperCurrent = 2; var paging = await Order.getOrderFire(); const moreData = await paging.getMoreData(); const data=Order.makeImages(moreData.items); this.communityList=data; this.communityObject=paging; console.log(data); }, // tab栏切换 change(index) { if(index==0){ this.getMyFollow(); }else if(index==1){ this.initList() }else if(index==2){ this.getOrderFire(); }else{ this.initList(this.list[index].Id,index); this.swiperCurrent=index; } }, changeTab(index){ this.current=index; uni.reLaunch({ url:this.tabbar[index].path }) }, } }; </script> <style lang="scss"> // .swiper-box { // flex: 1; // height: calc(100vh - 50rpx - 80rpx - 100rpx - var(--window-top)); // } .swiper-item { height: 100%; } </style> ``` route.php ``` Route::get('order/getContentData','api/:version.order/getContentData'); Route::get('order/getCommunityInfo','api/:version.order/getCommunityInfo'); Route::get('order/getCommunityFire','api/:version.order/getCommunityFire'); Route::get('order/getComment','api/:version.order/getComment'); Route::get('order/getCommentTwo','api/:version.order/getCommentTwo'); Route::get('order/getCommunityType','api/:version.order/getCommunityType'); Route::get('order/getUserCommunity','api/:version.order/getUserCommunity'); Route::get('order/getUserCommunityIndex','api/:version.order/getUserCommunityIndex'); Route::get('order/addVisitorNumber','api/:version.order/addVisitorNumber'); Route::get('order/getCommunityTop','api/:version.order/getCommunityTop'); Route::get('order/searchAll','api/:version.order/searchAll'); Route::get('order/getHotSearch','api/:version.order/getHotSearch'); ```