circle_chat_details.vue 9.9 KB

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