mycircle.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <view id="moments" class="page">
  3. <view class="back" @tap="back()">
  4. <image src="../../static/img/back.png"></image>
  5. </view>
  6. <view class="home-pic">
  7. <image :src="my_data.circle_img" @tap="upload" style="width: 100vw;height:65vw;"></image>
  8. <view class="home-pic-base">
  9. <view class="top-pic">
  10. <image class="header" :src="image_cache(myPhoto)" @tap.stop="goDetails(my_data.id)"
  11. :lazy-load="true" />
  12. </view>
  13. <view class="top-name">{{ my_data.nickname }}</view>
  14. </view>
  15. </view>
  16. <view class="sign" v-if="my_data.signature">{{my_data.signature}}</view>
  17. <view class="moments__post1" v-for="(post,index) in posts" :key="index" :id="'post-'+index">
  18. <view class="moments__post">
  19. <view class="post-left">
  20. <image class="post_header" :src="image_cache(post.header_image)" @tap="goDetails(post.userid)"
  21. :lazy-load="true" />
  22. </view>
  23. <view class="post_right">
  24. <text class="post-username" @tap="goDetails(post.uid)">{{post.username}}</text>
  25. <view id="paragraph" class="paragraph" @tap="init_input()">{{post.content.text}}</view>
  26. <!-- 相册 -->
  27. <view class="thumbnails" v-if="post.type == 0" @tap="init_input()">
  28. <view :class="post.content.value.length === 1 ? 'my-gallery' : 'thumbnail' "
  29. v-for="(image, index_images) in post.content.value" :key="index_images">
  30. <image class="gallery_img" :lazy-load="true" mode="aspectFill"
  31. :src="image_cache(staticPath + image)" :data-src="image_cache(image)"
  32. @tap="previewImage(index,index_images)" />
  33. </view>
  34. </view>
  35. <!-- 资料条 -->
  36. <view class="toolbar">
  37. <view class="timestamp">{{ timestamp(post.time) }}
  38. <view class="delete" v-if="post.userid==meid" @tap="circle_delete(index)">删除</view>
  39. </view>
  40. <view class="like" @tap="like(index)">
  41. <image
  42. :src="post.islike === 0 ? '../../static/push/circle/islike.png' : '../../static/push/circle/like.png'"
  43. :lazy-load="true" />
  44. </view>
  45. <view class="comment" @tap="comment(index)">
  46. <image src="../../static/push/circle/comment.png" :lazy-load="true"></image>
  47. </view>
  48. </view>
  49. <!-- 赞/评论区 -->
  50. <view class="post-footer">
  51. <view class="footer_content" v-if="post.like.length">
  52. <image class="liked" src="../../static/push/circle/liked.png" :lazy-load="true"></image>
  53. <text class="nickname" v-for="(user,index_like) in post.like" :key="index_like"
  54. @tap="goDetails(user.uid)">
  55. {{(index_like ? ',' : '' ) + user.username}}
  56. </text>
  57. </view>
  58. <view class="footer_content" v-for="(comment,comment_index) in post.comment"
  59. :key="comment_index" @tap="reply(index,comment_index)">
  60. <view class="comment-nickname" style="word-break:break-all;line-height: 40upx;">
  61. {{comment.username + comment.reply + ': '}}
  62. <text class="comment-content">
  63. {{comment.content}}
  64. </text>
  65. <view class="delete" style="float: right;" v-if="comment.uid==meid"
  66. @tap="comment_delete(index,comment_index)">删除</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 结束 post -->
  73. </view>
  74. <view class="foot" style="z-index: 999999;" v-show="showInput">
  75. <chat-input @send-message="send_comment" @blur="blur" :focus="focus"
  76. :placeholder="input_placeholder"></chat-input>
  77. <!-- <chat-input @send-message="send_comment" @blur="blur" :placeholder="input_placeholder"></chat-input> -->
  78. </view>
  79. <view class="loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
  80. </view>
  81. </template>
  82. <script>
  83. import chatInput from './circle/chat_input.vue'; //输入消息框
  84. import _data from "../../library/_data.js"
  85. import api from "../../library/index.js"
  86. import action from "../../library/action.js"
  87. import config from "../../config.js"
  88. import helper from "../../library/helper.js"
  89. export default {
  90. components: {
  91. chatInput
  92. },
  93. data() {
  94. return {
  95. my_data: {},
  96. user_id: 0,
  97. posts: [],
  98. index: '',
  99. comment_index: '',
  100. input_placeholder: '评论', //占位内容
  101. focus: false, //是否自动聚焦输入框
  102. is_reply: false, //回复还是评论
  103. showInput: false, //评论输入框
  104. screenHeight: '', //屏幕高度(系统)
  105. platform: '',
  106. windowHeight: '', //可用窗口高度(不计入软键盘)
  107. loadMoreText: "加载中...",
  108. showLoadMore: false,
  109. is_more: false,
  110. no_reader_msg: uni.getStorageSync('data_circle_tips') ? uni.getStorageSync('data_circle_tips') : 0,
  111. loaddata: [],
  112. myid: '',
  113. page: 1,
  114. meid: uni.getStorageSync('access_token'),
  115. }
  116. },
  117. created() {
  118. this.my_data = {
  119. id: uni.getStorageSync('access_token'),
  120. nickname: this.$store.state.userinfo.nickname,
  121. photo: '../../static/logo.png',
  122. circle_img: '../../static/img/default_circle_img.jpg',
  123. signature: '',
  124. }
  125. },
  126. computed: {
  127. myPhoto() {
  128. return this.my_data.photo + '?_=' + this.imgRan;
  129. },
  130. circleImg() {
  131. return this.my_data.circle_img;
  132. },
  133. staticPath() {
  134. return config.imgUri;
  135. },
  136. staticPhoto() {
  137. return _data.staticPhoto();
  138. },
  139. imgRan() {
  140. return Math.random();
  141. },
  142. },
  143. onLoad(option) {
  144. let _this = this;
  145. this.myid = option.id;
  146. uni.getSystemInfo({ //获取设备信息
  147. success: (res) => {
  148. _this.screenHeight = res.screenHeight;
  149. _this.platform = res.platform;
  150. }
  151. });
  152. // this.onGetData();
  153. },
  154. onShow() {
  155. let _this = this;
  156. _this.pullDownRefresh();
  157. // 监听窗口尺寸变化,窗口尺寸不包括底部导航栏
  158. },
  159. onUnload() {
  160. this.max = 0,
  161. this.data = [],
  162. this.loadMoreText = "加载更多",
  163. this.showLoadMore = false;
  164. },
  165. onReachBottom() { //监听上拉触底事件
  166. let _this = this;
  167. _this.showLoadMore = true;
  168. if (_this.is_more) {
  169. return;
  170. }
  171. // this.page++;
  172. this.onGetData();
  173. },
  174. onPullDownRefresh() { //监听下拉刷新动作
  175. this.pullDownRefresh();
  176. },
  177. onNavigationBarButtonTap(e) { //监听标题栏点击事件
  178. if (e.index == 0) {
  179. this.navigateTo('./circle/send');
  180. }
  181. },
  182. methods: {
  183. back() {
  184. uni.navigateBack();
  185. },
  186. photo(path) {
  187. if (path.indexOf('http') <= -1) path = config.imgUri + path;
  188. return path;
  189. },
  190. timestamp(time) {
  191. return action.timestampFormat(time);
  192. },
  193. upload(e) {
  194. if (this.myid != uni.getStorageSync('access_token')) return false;
  195. uni.chooseImage({
  196. success: (chooseImageRes) => {
  197. uni.showLoading();
  198. const tempFilePaths = chooseImageRes.tempFilePaths;
  199. helper.uploadFiles(tempFilePaths, 'image', {
  200. type: 'avatar'
  201. }).then(res => {
  202. this.my_data.circle_img = res;
  203. // console.log(res);
  204. var avatar = res.replace(config.imgUri, '');
  205. api.changeProfile({
  206. circle_img: avatar,
  207. id: this.my_data.id
  208. }).then(res => {
  209. uni.hideLoading()
  210. this.$toast('更新成功').then(() => {
  211. });
  212. });
  213. })
  214. }
  215. });
  216. },
  217. onGetData() {
  218. let that = this;
  219. api.getMyCircle({
  220. page: this.page,
  221. userid: this.myid
  222. }).then(res => {
  223. this.posts.push(...res.data);
  224. if (res.data.length < 20) {
  225. this.loadMoreText = '没有更多数据了';
  226. this.is_more = true;
  227. } else {
  228. this.page++;
  229. }
  230. })
  231. },
  232. setCircleData(data) {
  233. var list11 = [];
  234. for (var i = 0; i < data.length; i++) {
  235. var item = data[i];
  236. if (item.like == false) item.like = [];
  237. if (item.comment == false) item.comment = [];
  238. item.timestamp = action.timestampFormat(item.time);
  239. item.islike = this.setisLike(uni.getStorageSync('access_token'), item.like);
  240. list11.push(item);
  241. }
  242. this.posts = list11;
  243. },
  244. setisLike(id, data) {
  245. if (data.length == 0 || data == []) return 0;
  246. for (var i = 0; i < data.length; i++) {
  247. if (data[i].uid == id) return 1;
  248. }
  249. return 0;
  250. },
  251. goCircleChat() {
  252. _data.data('no_reader_circle_chat_num', 0);
  253. this.navigateTo('./circle_chat_details');
  254. },
  255. getUserInfo() {
  256. let _this = this;
  257. api.getUserInfo({
  258. friend_uid: this.myid
  259. }).then(res => {
  260. _this.my_data.id = res.data.id;
  261. _this.my_data.nickname = res.data.nickname;
  262. _this.my_data.photo = res.data.avatar;
  263. if (res.data.circle_img != null) {
  264. this.my_data.circle_img = this.image_cache(res.data.circle_img);
  265. }
  266. this.my_data.signature = res.data.sign;
  267. })
  268. },
  269. pullDownRefresh() {
  270. let _this = this;
  271. //初始化数据
  272. this.getUserInfo();
  273. this.onGetData();
  274. uni.stopPullDownRefresh();
  275. },
  276. goDetails(user_id) {
  277. this.navigateTo('../friend/detail?id=' + user_id);
  278. },
  279. navigateTo(url) {
  280. uni.navigateTo({
  281. url: url
  282. });
  283. },
  284. socket_push(id, action, userid, issend) {
  285. let data = {
  286. type: 'circle_push',
  287. id: id,
  288. action: action,
  289. fromid: uni.getStorageSync('access_token'),
  290. userid: userid,
  291. issend: issend
  292. }
  293. this.$socket.send(data);
  294. },
  295. circle_delete(index) {
  296. let _this = this
  297. uni.showModal({
  298. title: '提示',
  299. content: '确定要删除吗?',
  300. showCancel: true,
  301. cancelText: '取消',
  302. confirmText: '删除',
  303. success: res => {
  304. if (res.confirm) {
  305. var id = _this.posts[index].id;
  306. api.CircleDelete({
  307. id: id
  308. }).then(res => {
  309. if (res.data == 1) {
  310. _this.socket_push(_this.posts[index].id, 'delete', _this.posts[
  311. index].userid, 0);
  312. _this.posts.splice(index, 1);
  313. } else {
  314. uni.showModal({
  315. title: '网络连接失败'
  316. })
  317. }
  318. })
  319. }
  320. }
  321. });
  322. },
  323. comment_delete(index, index1) {
  324. let _this = this
  325. var id = _this.posts[index].id;
  326. console.log(index1);
  327. uni.showModal({
  328. title: '提示',
  329. content: '确定要删除吗?',
  330. showCancel: true,
  331. cancelText: '取消',
  332. confirmText: '删除',
  333. success: res => {
  334. if (res.confirm) {
  335. api.CommentDelete({
  336. id: id,
  337. index: index1
  338. }).then(res => {
  339. if (res.data == 1) {
  340. _this.posts[index].comment.splice(index1, 1);
  341. _this.socket_push(_this.posts[index].id, 'delete', _this.posts[
  342. index].userid, 0);
  343. } else {
  344. uni.showModal({
  345. title: '网络连接失败'
  346. })
  347. }
  348. })
  349. }
  350. }
  351. });
  352. },
  353. like(index) {
  354. let _this = this,
  355. is_like = (_this.posts[index].islike ? 0 : 1);
  356. // console.log( _this.posts[index]);
  357. var data = {
  358. id: _this.posts[index].id,
  359. userid: uni.getStorageSync('access_token')
  360. };
  361. api.setCircleLike(data).then(res => {
  362. var data = res.data;
  363. _this.posts[index].islike = data.action;
  364. if (data.action) {
  365. _this.posts[index].like.push({
  366. "uid": _this.my_data.id,
  367. "username": _this.my_data.nickname,
  368. });
  369. } else {
  370. let likes = [];
  371. for (let i = 0, j = _this.posts[index].like.length; i < j; i++) {
  372. if (parseInt(_this.posts[index].like[i].uid) == parseInt(uni.getStorageSync(
  373. 'access_token'))) {
  374. _this.posts[index].like.splice(i, 1);
  375. break;
  376. }
  377. }
  378. }
  379. this.socket_push(_this.posts[index].id, 'like', _this.posts[index].userid, data.action);
  380. })
  381. },
  382. comment(index) {
  383. if (this.showInput) {
  384. this.showInput = false;
  385. this.focus = false;
  386. this.index = '';
  387. } else {
  388. this.showInput = true; //调起input框
  389. this.focus = true;
  390. this.index = index;
  391. }
  392. },
  393. reply(index, comment_index) {
  394. this.is_reply = true; //回复中
  395. this.showInput = true; //调起input框
  396. let replyTo = this.posts[index].comment[comment_index].username;
  397. this.input_placeholder = '回复' + replyTo;
  398. this.index = index; //post索引
  399. this.comment_index = comment_index; //评论索引
  400. this.focus = true;
  401. },
  402. blur: function() {
  403. //this.init_input();
  404. },
  405. send_comment: function(message) {
  406. let _this = this,
  407. is_posts_obj = this.posts[this.index],
  408. chat_user_id = is_posts_obj.userid,
  409. reply = '';
  410. if (chat_user_id == undefined) chat_user_id = 0
  411. if (this.is_reply) {
  412. let is_reply_obj = is_posts_obj.comment[this.comment_index];
  413. chat_user_id = is_reply_obj.uid;
  414. if (is_posts_obj.userid != chat_user_id) {
  415. reply = '回复' + is_reply_obj.username;
  416. }
  417. }
  418. var data = {
  419. message,
  420. id: is_posts_obj.id,
  421. chat_user_id,
  422. reply: reply,
  423. uid: uni.getStorageSync('access_token')
  424. }
  425. api.setCircleComment(data).then(res => {
  426. is_posts_obj.comment.push({
  427. "uid": _this.my_data.id,
  428. 'reply': reply,
  429. "username": _this.my_data.nickname,
  430. "content": message
  431. });
  432. _this.init_input();
  433. this.socket_push(_this.posts[this.index].id, 'comment', _this.posts[this.index].userid,
  434. 1);
  435. })
  436. },
  437. init_input() {
  438. this.showInput = false;
  439. this.focus = false;
  440. this.input_placeholder = '评论';
  441. this.is_reply = false;
  442. },
  443. previewImage(index, image_index) {
  444. let data = this.posts[index],
  445. images_all = [];
  446. for (let i = 0, j = data.content.value.length; i < j; i++) {
  447. images_all.push(this.image_cache(data.content.value[i]));
  448. }
  449. var current = images_all[image_index];
  450. uni.previewImage({
  451. current: current,
  452. urls: images_all
  453. });
  454. },
  455. goPublish() {
  456. uni.navigateTo({
  457. url: './circle/send',
  458. success: res => {},
  459. fail: () => {},
  460. complete: () => {}
  461. });
  462. }
  463. },
  464. watch: {
  465. },
  466. }
  467. </script>
  468. <style scoped>
  469. @import url("../../static/css/circle.css");
  470. .new_msg {
  471. text-align: center;
  472. color: #333333;
  473. font-size: 32upx;
  474. }
  475. .inputbox {
  476. clear: both;
  477. width: 100%;
  478. display: flex;
  479. }
  480. .delete {
  481. display: inline-block;
  482. padding: 0px 20upx;
  483. color: #2319dc;
  484. font-size: 24upx;
  485. }
  486. .sign {
  487. display: block;
  488. padding-right: 190upx;
  489. margin-top: -65upx;
  490. min-height: 50upx;
  491. line-height: 50upx;
  492. font-size: 24upx;
  493. color: #666;
  494. text-align: right;
  495. }
  496. .back {
  497. position: fixed;
  498. top: 50upx;
  499. left: 10upx;
  500. z-index: 10000;
  501. height: 150upx;
  502. width: 150upx;
  503. }
  504. .back image {
  505. height: 40upx;
  506. width: 20upx;
  507. margin-left: 20upx;
  508. }
  509. </style>