circle_chat_details.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view id="moments">
  3. <view class="moments__post1" v-for="(post,index) in posts" :key="index" :id="'post-'+index">
  4. <view class="moments__post">
  5. <view class="post-left">
  6. <image class="post_header" :src="photo(post.user.avatar)" @tap="goDetails(post.uid)" :lazy-load="true"/>
  7. </view>
  8. <view class="post_right">
  9. <text class="post-username" @tap="goDetails(post.from_uid)">{{post.user.nickname}}</text>
  10. <view id="paragraph" class="paragraph" >
  11. <view v-if="post.type=='like'">
  12. <image src="../../static/push/circle/liked.png" :lazy-load="true" style="height:40upx;width: 40upx;"/>
  13. </view>
  14. <view v-else> {{post.content}}</view>
  15. </view>
  16. <!-- 资料条 -->
  17. <view class="toolbar">
  18. <view class="timestamp">{{ timestamp(post.time) }}</view>
  19. </view>
  20. </view>
  21. <view class="post-info">
  22. <view v-if="post.info.type=='delete'" class="text">该说说已删除</view>
  23. <view v-else-if="post.info.type=='text'" class="text">{{post.info.content}}</view>
  24. <view v-else>
  25. <image :src="photo(post.info.content)" style="width: 140upx;height: 140upx;vertical-align: middle;"></image>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 结束 post -->
  30. </view>
  31. <view class="foot" v-show="showInput">
  32. <chat-input @blur="blur" :focus="focus" :placeholder="input_placeholder"></chat-input>
  33. </view>
  34. <view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
  35. </view>
  36. </template>
  37. <script>
  38. import chatInput from './circle/chat_input.vue'; //输入消息框
  39. import _data from "../../library/_data.js"
  40. import api from "../../library/index.js"
  41. import action from "../../library/action.js"
  42. import config from "../../config.js"
  43. import helper from "../../library/helper.js"
  44. export default {
  45. components: {
  46. chatInput
  47. },
  48. data() {
  49. return {
  50. user_id: 0,
  51. posts: [],//模拟数据
  52. index: '',
  53. comment_index: '',
  54. input_placeholder: '评论', //占位内容
  55. focus: false, //是否自动聚焦输入框
  56. is_reply: false, //回复还是评论
  57. showInput: false, //评论输入框
  58. screenHeight: '', //屏幕高度(系统)
  59. platform: '',
  60. windowHeight: '' ,//可用窗口高度(不计入软键盘)
  61. loadMoreText: "加载中...",
  62. showLoadMore: true,
  63. is_more: false,
  64. my_data: {},
  65. page:1
  66. }
  67. },
  68. computed:{
  69. staticPath(){
  70. return _data.staticCircle();
  71. },
  72. staticPhoto(){
  73. return _data.staticPhoto();
  74. },
  75. },
  76. onLoad(option) {
  77. let _this = this;
  78. _this.my_data = _data.data('user_info');
  79. uni.getSystemInfo({ //获取设备信息
  80. success: (res) => {
  81. _this.screenHeight = res.screenHeight;
  82. _this.platform = res.platform;
  83. }
  84. });
  85. },
  86. onShow() {
  87. let _this = this;
  88. uni.onWindowResize((res) => { //监听窗口尺寸变化,窗口尺寸不包括底部导航栏
  89. if(this.platform === 'ios'){
  90. this.windowHeight = res.size.windowHeight;
  91. this.adjust();
  92. }else{
  93. if (this.screenHeight - res.size.windowHeight > 60 && this.windowHeight <= res.size.windowHeight) {
  94. this.windowHeight = res.size.windowHeight;
  95. this.adjust();
  96. }
  97. }
  98. });
  99. this.pullDownRefresh();
  100. /** 监听新的个人数据 */
  101. uni.$on('data_user_info',function(data){
  102. _this.my_data = data;
  103. });
  104. uni.setStorageSync('data_circle_tips',0);
  105. action.setStatusTips();
  106. },
  107. onUnload() {
  108. uni.$off('data_user_info');
  109. uni.offWindowResize(); //取消监听窗口尺寸变化
  110. this.max = 0,
  111. this.data = [],
  112. this.loadMoreText = "加载更多",
  113. this.showLoadMore = false;
  114. },
  115. onReachBottom() { //监听上拉触底事件
  116. this.showLoadMore = true;
  117. if(this.is_more){
  118. return;
  119. }
  120. let time = 0,
  121. is_length = this.posts.length;
  122. if(is_length){
  123. time = this.posts[is_length - 1].time;
  124. }
  125. this.getCircleList({
  126. time,
  127. type: 1,
  128. user_id: this.user_id,
  129. chat: 1,
  130. });
  131. },
  132. onPullDownRefresh() { //监听下拉刷新动作
  133. this.pullDownRefresh();
  134. },
  135. onNavigationBarButtonTap(e) {//监听标题栏点击事件
  136. if (e.index == 0) {
  137. this.navigateTo('./circle/send')
  138. }
  139. },
  140. methods: {
  141. photo(path){
  142. if(path.indexOf('http')<=-1) path=config.imgUri+path;
  143. return path;
  144. },
  145. timestamp(time){
  146. return action.timestampFormat(time);
  147. },
  148. pullDownRefresh() {
  149. //初始化数据
  150. let time = 0;
  151. if(this.posts.length){
  152. time = this.posts[0].time;
  153. }
  154. this.getCircleList({
  155. time,
  156. type: 0,
  157. user_id: this.user_id,
  158. chat: 1,
  159. });
  160. uni.stopPullDownRefresh(); // 停止下拉刷新
  161. },
  162. getCircleList(send_data){
  163. let _this = this;
  164. var data={userid:uni.getStorageSync('access_token'),page:this.page};
  165. // console.log(this.page);
  166. api.getCircleMsg(data).then(res=>{
  167. if(res.data.length){
  168. _this.posts.push(...res.data);
  169. this.page++
  170. }else{
  171. if(this.page==1)
  172. _this.loadMoreText = '暂无通知';
  173. else
  174. _this.loadMoreText = '没有数据了';
  175. _this.is_more = true;
  176. }
  177. })
  178. },
  179. goDetails(user_id){
  180. this.navigateTo('../friend/detail?id=' + user_id);
  181. },
  182. navigateTo(url) {
  183. uni.navigateTo({
  184. url: url
  185. });
  186. },
  187. adjust() { //当弹出软键盘发生评论动作时,调整页面位置pageScrollTo
  188. return;
  189. uni.createSelectorQuery().selectViewport().scrollOffset(res => {
  190. var scrollTop = res.scrollTop;
  191. let view = uni.createSelectorQuery().select("#post-" + this.index);
  192. view.boundingClientRect(data => {
  193. // console.log("data:" + JSON.stringify(data));
  194. // console.log("手机屏幕高度:" + this.screenHeight);
  195. // console.log("竖直滚动位置" + scrollTop);
  196. // console.log("节点离页面顶部的距离为" + data.top);
  197. // console.log("节点高度为" + data.height);
  198. // console.log("窗口高度为" + this.windowHeight);
  199. uni.pageScrollTo({
  200. scrollTop: scrollTop - (this.windowHeight - (data.height + data.top + 45)), //一顿乱算
  201. // scrollTop: 50,
  202. duration: 300
  203. });
  204. }).exec();
  205. }).exec();
  206. },
  207. blur: function() {
  208. //this.init_input();
  209. },
  210. init_input() {
  211. this.showInput = false;
  212. this.focus = false;
  213. this.input_placeholder = '评论';
  214. this.is_reply = false;
  215. },
  216. previewImage(index, image_index) {
  217. let data = this.posts[index],
  218. images_all = [];
  219. for(let i = 0,j = data.content.value.length;i<j;i++){
  220. images_all.push(this.staticPath + data.post_id + '/' + data.content.value[i].replace('_thumb',''));
  221. }
  222. var current = images_all[image_index];
  223. uni.previewImage({
  224. current: current,
  225. urls: images_all
  226. });
  227. },
  228. goPublish() {
  229. uni.navigateTo({
  230. url: './circle/send',
  231. success: res => {},
  232. fail: () => {},
  233. complete: () => {}
  234. });
  235. }
  236. },
  237. watch: {
  238. },
  239. }
  240. </script>
  241. <style scoped>
  242. @import url("../../static/css/circle.css");
  243. .new_msg {
  244. text-align: center;
  245. color: #36648B;
  246. font-weight: bold;
  247. }
  248. </style>