circle_details.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view id="moments">
  3. <view class="home-pic">
  4. <image
  5. :src="circleImg"
  6. style="width: 750upx; height: 500upx; border-radius: 0upx;"
  7. />
  8. </image>
  9. <view class="home-pic-base">
  10. <view class="top-pic">
  11. <image class="header" :src="myPhoto" @tap.stop="goDetails(my_data.id)" :lazy-load="true"></image>
  12. </view>
  13. <view class="top-name">{{ my_data.nickname }}</view>
  14. </view>
  15. </view>
  16. <view class="moments__post" v-for="(post,index) in posts" :key="index" :id="'post-'+index">
  17. <view class="post-left">
  18. <image class="post_header" :src="staticPhoto + post.header_image" @tap="goDetails(post.uid)" :lazy-load="true"/>
  19. </view>
  20. <view class="post_right">
  21. <text class="post-username" @tap="goDetails(post.uid)">{{post.username}}</text>
  22. <view id="paragraph" class="paragraph" @tap="init_input()">{{post.content.text}}</view>
  23. <!-- 相册 -->
  24. <view class="thumbnails" v-if="post.type == 0" @tap="init_input()">
  25. <view :class="post.content.value.length === 1?'my-gallery':'thumbnail'" v-for="(image, index_images) in post.content.value" :key="index_images">
  26. <image class="gallery_img"
  27. :lazy-load="true"
  28. mode="aspectFill"
  29. :src="staticPath + post.post_id +'/' + image"
  30. :data-src="image"
  31. @tap="previewImage(index,index_images)"
  32. />
  33. </view>
  34. </view>
  35. <!-- 资料条 -->
  36. <view class="toolbar">
  37. <view class="timestamp">{{ post.timestamp }}</view>
  38. <view class="like" @tap="like(index)">
  39. <image :src="post.islike === 0 ? '../../static/push/circle/islike.png' : '../../static/push/circle/like.png'" :lazy-load="true"/>
  40. </view>
  41. <view class="comment" @tap="comment(index)">
  42. <image src="../../static/push/circle/comment.png" :lazy-load="true"></image>
  43. </view>
  44. </view>
  45. <!-- 赞/评论区 -->
  46. <view class="post-footer">
  47. <view class="footer_content" v-if="post.like.length">
  48. <image class="liked" src="../../static/push/circle/liked.png" :lazy-load="true"></image>
  49. <text class="nickname"
  50. v-for="(user,index_like) in post.like"
  51. :key="index_like"
  52. @tap="goDetails(user.uid)"
  53. >
  54. {{(index_like ? ',' : '' ) + user.username}}
  55. </text>
  56. </view>
  57. <view class="footer_content" v-for="(comment,comment_index) in post.comments" :key="comment_index" @tap="reply(index,comment_index)">
  58. <text class="comment-nickname" style="word-break:break-all;">{{comment.username + comment.reply}}: <text class="comment-content">{{comment.content}}</text></text>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 结束 post -->
  63. </view>
  64. <view class="foot" v-show="showInput">
  65. <chat-input @send-message="send_comment" @blur="blur" :focus="focus" :placeholder="input_placeholder"></chat-input>
  66. <!-- <chat-input @send-message="send_comment" @blur="blur" :placeholder="input_placeholder"></chat-input> -->
  67. </view>
  68. <view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
  69. </view>
  70. </template>
  71. <script>
  72. import chatInput from './circle/chat_input.vue'; //输入消息框
  73. export default {
  74. components: {
  75. chatInput,
  76. },
  77. data() {
  78. return {
  79. my_data: {},
  80. user_id: 0,
  81. posts: [],//模拟数据
  82. index: '',
  83. comment_index: '',
  84. input_placeholder: '评论', //占位内容
  85. focus: false, //是否自动聚焦输入框
  86. is_reply: false, //回复还是评论
  87. showInput: false, //评论输入框
  88. screenHeight: '', //屏幕高度(系统)
  89. platform: '',
  90. windowHeight: '' ,//可用窗口高度(不计入软键盘)
  91. loadMoreText: "加载中...",
  92. showLoadMore: false,
  93. is_more: false,
  94. }
  95. },
  96. computed:{
  97. myPhoto(){
  98. return _data.staticPhoto() + this.my_data.photo + '?_=' + Math.random();
  99. },
  100. circleImg(){
  101. return _data.staticPhoto() + this.my_data.circle_img + '?_=' + Math.random();
  102. },
  103. isNickname(){
  104. return this.my_data.nickname;
  105. },
  106. staticPath(){
  107. return _data.staticCircle();
  108. },
  109. staticPhoto(){
  110. return _data.staticPhoto();
  111. },
  112. },
  113. onLoad(option) {
  114. let _this = this;
  115. _this.user_id = option.user_id;
  116. _this.my_data = _data.data('user_info');
  117. uni.getSystemInfo({ //获取设备信息
  118. success: (res) => {
  119. _this.screenHeight = res.screenHeight;
  120. _this.platform = res.platform;
  121. }
  122. });
  123. },
  124. onShow() {
  125. _hook.routeSonHook();
  126. let _this = this;
  127. uni.onWindowResize((res) => { //监听窗口尺寸变化,窗口尺寸不包括底部导航栏
  128. if(this.platform === 'ios'){
  129. this.windowHeight = res.size.windowHeight;
  130. this.adjust();
  131. }else{
  132. if (this.screenHeight - res.size.windowHeight > 60 && this.windowHeight <= res.size.windowHeight) {
  133. this.windowHeight = res.size.windowHeight;
  134. this.adjust();
  135. }
  136. }
  137. });
  138. this.pullDownRefresh();
  139. /** 监听新的个人数据 */
  140. uni.$on('data_user_info',function(data){
  141. _this.my_data = data;
  142. });
  143. },
  144. onUnload() {
  145. uni.offWindowResize(); //取消监听窗口尺寸变化
  146. uni.$off('data_user_info');
  147. this.max = 0,
  148. this.data = [],
  149. this.loadMoreText = "加载更多",
  150. this.showLoadMore = false;
  151. },
  152. onReachBottom() { //监听上拉触底事件
  153. this.showLoadMore = true;
  154. if(this.is_more) {
  155. return;
  156. }
  157. let time = 0,
  158. is_length = this.posts.length;
  159. if(is_length){
  160. time = this.posts[is_length - 1].time;
  161. }
  162. this.getCircleList({
  163. time,
  164. type: 1,
  165. user_id: this.user_id,
  166. },(data) => {
  167. _this.my_data = data.user_info;
  168. });
  169. },
  170. onPullDownRefresh() { //监听下拉刷新动作
  171. this.pullDownRefresh();
  172. },
  173. onNavigationBarButtonTap(e) {//监听标题栏点击事件
  174. if (e.index == 0) {
  175. this.navigateTo('./circle/send')
  176. }
  177. },
  178. methods: {
  179. pullDownRefresh() {
  180. //初始化数据
  181. let time = 0;
  182. if(this.posts.length){
  183. time = this.posts[0].time;
  184. }
  185. this.getCircleList({
  186. time,
  187. type: 0,
  188. user_id: this.user_id,
  189. },(data) => {
  190. _this.my_data = data.user_info;
  191. });
  192. uni.stopPullDownRefresh(); //停止下拉刷新
  193. },
  194. getCircleList(send_data){
  195. let _this = this;
  196. this.$httpSend({
  197. path: '/im/get/circleData',
  198. data: send_data,
  199. success(data) {
  200. if(data.data.length){
  201. let circle_data = [];
  202. if(send_data.type){
  203. _this.posts.push(...data.data);
  204. }else{
  205. _this.posts.unshift(...data.data);
  206. }
  207. } else {
  208. _this.loadMoreText = '没有更多数据了';
  209. _this.is_more = true;
  210. }
  211. _this.my_data = data.user_info;
  212. }
  213. });
  214. },
  215. goDetails(user_id){
  216. this.navigateTo('../details/index?user_id=' + user_id);
  217. },
  218. navigateTo(url) {
  219. uni.navigateTo({
  220. url: url
  221. });
  222. },
  223. like(index) {
  224. let _this = this,
  225. is_like = (_this.posts[index].islike ? 0 : 1);
  226. _this.$httpSend({
  227. path: '/im/circle/likeAction',
  228. data: {
  229. is_like: is_like,
  230. id: _this.posts[index].post_id,
  231. },
  232. success(data) {
  233. _this.posts[index].islike = data.action;
  234. if (data.action) {
  235. _this.posts[index].like.push({
  236. "uid": _this.my_data.id,
  237. "username": _this.my_data.nickname,
  238. });
  239. } else {
  240. let likes = [];
  241. for(let i = 0,j = _this.posts[index].like.length;i < j; i ++){
  242. if(_this.posts[index].like[i].uid == _this.my_data.id){
  243. _this.posts[index].like.splice(i, 1);
  244. break;
  245. }
  246. }
  247. }
  248. }
  249. });
  250. },
  251. comment(index) {
  252. if(this.showInput){
  253. this.showInput = false;
  254. this.focus = false;
  255. this.index = '';
  256. }else{
  257. this.showInput = true; //调起input框
  258. this.focus = true;
  259. this.index = index;
  260. }
  261. },
  262. adjust() { //当弹出软键盘发生评论动作时,调整页面位置pageScrollTo
  263. return;
  264. uni.createSelectorQuery().selectViewport().scrollOffset(res => {
  265. var scrollTop = res.scrollTop;
  266. let view = uni.createSelectorQuery().select("#post-" + this.index);
  267. view.boundingClientRect(data => {
  268. uni.pageScrollTo({
  269. scrollTop: scrollTop - (this.windowHeight - (data.height + data.top + 45)), //一顿乱算
  270. // scrollTop: 50,
  271. duration: 300
  272. });
  273. }).exec();
  274. }).exec();
  275. },
  276. reply(index, comment_index) {
  277. this.is_reply = true; //回复中
  278. this.showInput = true; //调起input框
  279. let replyTo = this.posts[index].comments[comment_index].username;
  280. this.input_placeholder = '回复' + replyTo;
  281. this.index = index; //post索引
  282. this.comment_index = comment_index; //评论索引
  283. this.focus = true;
  284. },
  285. blur: function() {
  286. //this.init_input();
  287. },
  288. send_comment: function(message) {
  289. let _this = this,
  290. is_posts_obj = this.posts[this.index],
  291. chat_user_id = is_posts_obj.uid,
  292. reply = '';
  293. if (this.is_reply) {
  294. let is_reply_obj = is_posts_obj.comments[this.comment_index];
  295. chat_user_id = is_reply_obj.uid;
  296. if(is_posts_obj.uid != chat_user_id){
  297. reply = '回复' + is_reply_obj.username;
  298. }
  299. }
  300. _this.$httpSend({
  301. path: '/im/circle/comment',
  302. data: {
  303. message,
  304. id: is_posts_obj.post_id,
  305. chat_user_id,
  306. },
  307. success(data) {
  308. is_posts_obj.comments.push({
  309. "uid": _this.my_data.id,
  310. 'reply': reply,
  311. "username": _this.my_data.nickname,
  312. "content": message
  313. });
  314. _this.init_input();
  315. }
  316. });
  317. },
  318. init_input() {
  319. this.showInput = false;
  320. this.focus = false;
  321. this.input_placeholder = '评论';
  322. this.is_reply = false;
  323. },
  324. previewImage(index, image_index) {
  325. let data = this.posts[index],
  326. images_all = [];
  327. for(let i = 0,j = data.content.value.length;i<j;i++){
  328. images_all.push(this.staticPath + data.post_id + '/' + data.content.value[i].replace('_thumb',''));
  329. }
  330. var current = images_all[image_index];
  331. uni.previewImage({
  332. current: current,
  333. urls: images_all
  334. });
  335. },
  336. },
  337. watch: {
  338. isNickname(new_val,old_val){
  339. uni.setNavigationBarTitle({
  340. title: new_val,
  341. });
  342. }
  343. },
  344. }
  345. </script>
  346. <style scoped>
  347. @import url("../../static/css/circle.css");
  348. .new_msg {
  349. text-align: center;
  350. color: #36648B;
  351. font-weight: bold;
  352. }
  353. </style>