dever 4 rokov pred
rodič
commit
a29d938f14
1 zmenil súbory, kde vykonal 46 pridanie a 116 odobranie
  1. 46 116
      pages/dream/view/moment.vue

+ 46 - 116
pages/dream/view/moment.vue

@@ -11,27 +11,27 @@
 		</view>
 
 		<view style="padding-bottom: 140rpx;">
-			<view class="moments__post" v-for="(post,index) in posts" :key="index" :id="'post-'+index">
+			<view class="moments__post" v-for="(v,k) in fetch.info" :key="k" :id="'post-'+k">
 				<view class="post-left">
-					<image class="post_header" :src="post.header_image"></image>
+					<image class="post_header" :src="v.user.avatar"></image>
 				</view>
 
 				<view class="post_right">
-					<text class="post-username">{{post.username}}</text>
-					<view id="paragraph" class="paragraph">{{post.content.text}}</view>
+					<text class="post-username">{{v.user.username}}</text>
+					<view class="paragraph">{{v.content}}</view>
 					<!-- 相册 -->
-					<view class="thumbnails">
-						<view :class="post.content.images.length === 1?'my-gallery':'thumbnail'" v-for="(image, index_images) in post.content.images" :key="index_images">
-							<image class="gallery_img" lazy-load mode="aspectFill" :src="image" :data-src="image" @tap="previewImage(post.content.images,index_images)"></image>
+					<view class="thumbnails" v-if="v.pic.length > 0 && v.pic[0]">
+						<view :class="v.pic.length === 1?'my-gallery':'thumbnail'" v-for="(v1, k1) in v.pic" :key="k1">
+							<image class="gallery_img" lazy-load mode="aspectFill" :src="v1" :data-src="v1" @tap="Dever.viewPic(v.pic, v1)"></image>
 						</view>
 					</view>
 					<!-- 资料条 -->
 					<view class="toolbar">
-						<view class="timestamp">{{post.timestamp}}</view>
-						<view class="like" @tap="like(index)">
+						<view class="timestamp">{{v.cdate_string}}</view>
+						<view class="like" @tap="like(k)">
 							<image src="@/static/moment/islike.png" style="width: 30px;"></image>
 						</view>
-						<view class="comment" @tap="comment(index)">
+						<view class="comment" @tap="updateComment(v.id)">
 							<image src="@/static/moment/comment.png" style="width: 30px;"></image>
 						</view>
 					</view>
@@ -39,10 +39,10 @@
 					<view class="post-footer">
 						<view class="footer_content">
 							<image class="liked" src="@/static/moment/liked.png"></image>
-							<text class="nickname" v-for="(user,index_like) in post.like" :key="index_like">{{user.username}}</text>
+							<!--<text class="nickname" v-for="(user,index_like) in post.like" :key="index_like">{{user.username}}</text>-->
 						</view>
-						<view class="footer_content" v-for="(comment,comment_index) in post.comments.comment" :key="comment_index" @tap="reply(index,comment_index)">
-							<text class="comment-nickname">{{comment.username}}: <text class="comment-content">{{comment.content}}</text></text>
+						<view v-if="v.child.length" class="footer_content" v-for="(v2, k2) in v.child" :key="k2" @tap="reply(k,k2)">
+							<text class="comment-nickname">{{v2.user.username}}: <text class="comment-content">{{v2.content}}</text></text>
 						</view>
 					</view>
 				</view>
@@ -56,12 +56,12 @@
 		
 		<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
 		
-		<y-Fab :bottom="20" :right="140" @click="showModal" bgColor="#0fa5e5" text="发布"></y-Fab>
+		<y-Fab :bottom="20" :right="140" @click="publish" bgColor="#0fa5e5" text="发布"></y-Fab>
 		<block v-if="index == -1">
 			<y-Fab :bottom="20" :right="20" @click="back" text="返回"></y-Fab>
 		</block>
 		<view v-if="showComment">
-			<dever-publish :title="title" :is_upload="is_upload" @hideModal="hideModal" @getRefresh="getRefresh" :type="key" :type_id="item.id" :api="api"></dever-publish>
+			<dever-publish :title="title" :is_upload="is_upload" @hideModal="hideModal" @getRefresh="getRefresh" :type="publish_type" :type_id="publish_type_id" :api="api"  :to_id="to_id" :to_uid="to_uid"></dever-publish>
 		</view>
 	</view>
 
@@ -88,7 +88,6 @@
 		},
 		data() {
 			return {
-				posts: postData,//模拟数据
 				user_id: 4,
 				username: 'Liuxy',
 
@@ -107,17 +106,26 @@
 				loadMoreText: "加载中...",
 				showLoadMore: false,
 				
-				style : '',
 				
+				fetch : {
+					'info' : [],
+				},
+				style : '',
 				title : '发布新动态',
 				api : 'app/community/?l=api.addMoment',
-				key : '30',
+				type : 3,
+				type_id : 0,
+				publish_type : 3,
+				publish_type_id : 0,
+				type_id : 0,
+				to_id : 0,
+				to_uid : 0,
 				is_upload : true,
 				showComment : false,
 			}
 		},
 		mounted() {
-			console.info(this.item);
+			this.type_id = this.item.id;
 			this.style = 'background:url("'+this.item.pic+'");background-size: contain;';
 			uni.getSystemInfo({ //获取设备信息
 				success: (res) => {
@@ -125,13 +133,6 @@
 					this.platform = res.platform;
 				}
 			});
-			uni.getStorage({
-				key: 'posts',
-				success: function (res) {
-					console.log(res.data);
-					this.posts = res.data;
-				}
-			});
 			
 			uni.onWindowResize((res) => { //监听窗口尺寸变化,窗口尺寸不包括底部导航栏
 				if(this.platform === 'ios'){
@@ -187,7 +188,7 @@
 		},
 		methods: {
 			getData : function(page) {
-				this.Dever.page([page, 'info'], this, 'app/community/?l=api.moment', {type:this.key,type_id:this.item.id});
+				this.Dever.page([page, 'info'], this, 'app/community/?l=api.moment', {type:this.type,type_id:this.type_id});
 			},
 			showModal : function() {
 				this.showComment = true;
@@ -199,101 +200,30 @@
 				this.getData(1);
 				this.hideModal();
 			},
-			navigateTo(url) {
-				uni.navigateTo({
-					url: url
-				});
+			publish : function() {
+				this.publish_type = 3;
+				this.publish_type_id = this.item.id;
+				this.to_id = 0;
+				this.to_uid = 0;
+				this.is_upload = true;
+				this.showModal();
 			},
-			like(index) {
-				if (this.posts[index].islike === 0) {
-					this.posts[index].islike = 1;
-					this.posts[index].like.push({
-						"uid": this.user_id,
-						"username": "," + this.username
-					});
+			updateComment : function (type_id, to_id, to_uid) {
+				this.publish_type = 30;
+				this.publish_type_id = type_id;
+				if (to_id) {
+					this.to_id = to_id;
 				} else {
-					this.posts[index].islike = 0;
-					this.posts[index].like.splice(this.posts[index].like.indexOf({
-						"uid": this.user_id,
-						"username": "," + this.username
-					}), 1);
+					this.to_id = 0;
 				}
-			},
-			comment(index) {
-				this.showInput = true; //调起input框
-				this.focus = true;
-				this.data_index = index;
-			},
-			adjust() { //当弹出软键盘发生评论动作时,调整页面位置pageScrollTo
-				return;
-				uni.createSelectorQuery().selectViewport().scrollOffset(res => {
-					var scrollTop = res.scrollTop;
-					let view = uni.createSelectorQuery().select("#post-" + this.data_index);
-					view.boundingClientRect(data => {
-						console.log("data:" + JSON.stringify(data));
-						console.log("手机屏幕高度:" + this.screenHeight);
-						console.log("竖直滚动位置" + scrollTop);
-						console.log("节点离页面顶部的距离为" + data.top);
-						console.log("节点高度为" + data.height);
-						console.log("窗口高度为" + this.windowHeight);
-
-						uni.pageScrollTo({
-							scrollTop: scrollTop - (this.windowHeight - (data.height + data.top + 45)), //一顿乱算
-							// scrollTop: 50, 
-							duration: 300
-						});
-					}).exec();
-				}).exec();
-			},
-			reply(index, comment_index) {
-				this.is_reply = true; //回复中
-				this.showInput = true; //调起input框
-				let replyTo = this.posts[index].comments.comment[comment_index].username;
-				this.input_placeholder = '回复' + replyTo;
-				this.data_index = index; //post索引
-				this.comment_index = comment_index; //评论索引
-				this.focus = true;
-			},
-			blur: function() {
-				this.init_input();
-			},
-			send_comment: function(message) {
-
-				if (this.is_reply) {
-					var reply_username = this.posts[this.data_index].comments.comment[this.comment_index].username;
-					var comment_content = '回复' + reply_username + ':' + message.content;
+				if (to_uid) {
+					this.to_uid = to_uid;
 				} else {
-					var comment_content = message.content;
+					this.to_uid = 0;
 				}
-				this.posts[this.data_index].comments.total += 1;
-				this.posts[this.data_index].comments.comment.push({
-					"uid": this.user_id,
-					"username": this.username,
-					"content": comment_content //直接获取input中的值
-				});
-				this.init_input();
+				this.is_upload = false;
+				this.showModal();
 			},
-			init_input() {
-				this.showInput = false;
-				this.focus = false;
-				this.input_placeholder = '评论';
-				this.is_reply = false;
-			},
-			previewImage(imageList, image_index) {
-				var current = imageList[image_index];
-				uni.previewImage({
-					current: current,
-					urls: imageList
-				});
-			},
-			goPublish() {
-				uni.navigateTo({
-					url: './publish/publish',
-					success: res => {},
-					fail: () => {},
-					complete: () => {}
-				});
-			}
 		}
 	}
 </script>