request.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <view class='page'>
  3. <headerline navstyle="left:25%;width:50%;" :reditem='unreadnum' :isback="true" :shownav="true" :navitem="navitem" :navselect="navselect" @tapnav="tapnav" :statusbarheight='statusBarHeight' :islogo="false" ></headerline>
  4. <block v-if="isloading==false">
  5. <block v-if="navselect==0">
  6. <block v-if="friend_lists.length>0">
  7. <block v-for="(m,index) in friend_lists" :key='index'>
  8. <view class="lines" style="margin-top: 10px;">
  9. <view>
  10. <image @tap='openuser(m.user)' :src="image_cache(m.user.avatar)" class="avatar"></image>
  11. </view>
  12. <view>
  13. <view >
  14. <span class='nickname' @tap='openuser(m.user)'>{{m.user.nickname}}</span>申请添加您为好友
  15. <view style='float: right;display: inline-block;color: #999;padding-right: 10px;'>{{timestampFormat(m.addtime)}}</view>
  16. </view>
  17. <scroll-view scroll-y="true" :scroll-top="m.mark.length*20" v-if="m.mark.length>0" style="max-height:32px;">
  18. <view v-for="(m1,index1) in m.mark" :key='index1' class="mark">
  19. {{m1}}
  20. </view>
  21. </scroll-view>
  22. <view v-if="m.status==0">
  23. <button class="btns ok" @tap="deal_userapply(m.id,1,index)">
  24. <uni-icons type='checkmarkempty' style="color:#FFF"></uni-icons>
  25. 同意</button>
  26. <button class="btns clear" @tap="deal_userapply(m.id,2,index)">
  27. <uni-icons type='closeempty'></uni-icons>拒绝</button>
  28. </view>
  29. <view v-else style="color:#666;font-size: 14px;">
  30. <block v-if="m.status==1">已同意</block>
  31. <block v-else>已拒绝</block>
  32. </view>
  33. </view>
  34. </view>
  35. </block>
  36. </block>
  37. <view class="nodata" v-else >
  38. 暂无好友验证消息
  39. </view>
  40. </block>
  41. <block v-else>
  42. <block v-if="group_lists.length>0">
  43. <block v-for="(m,index) in group_lists" :key='index'>
  44. <view class="times">{{timestampFormat(m.addtime)}}</view>
  45. <view class="lines">
  46. <view>
  47. <image @tap='openuser(m.user)' :src="image_cache(m.user.avatar)" class="avatar"></image>
  48. </view>
  49. <view>
  50. <view >
  51. <span class='nickname' @tap='openuser(m.user)'>{{m.user.nickname}}</span>申请加入<span class='nickname' @tap='opengroup(m.group)'>{{m.group.nickname}}</span>
  52. </view>
  53. <scroll-view scroll-y="true" :scroll-top="m.content1.length*20" v-if="m.content1.length>0" style="max-height:32px;">
  54. <view v-for="(m1,index1) in m.content1" :key='index1' class="mark">
  55. {{m1}}
  56. </view>
  57. </scroll-view>
  58. <view v-if="m.status==0">
  59. <button class="btns ok" @tap="deal_apply(m.id,1,index)">
  60. <uni-icons type='checkmarkempty' style="color:#FFF"></uni-icons>
  61. 同意</button>
  62. <button class="btns clear" @tap="deal_apply(m.id,2,index)">
  63. <uni-icons type='closeempty'></uni-icons>拒绝</button>
  64. </view>
  65. <view v-else style="color:#666;font-size: 14px;">
  66. <block v-if="m.apply_uid!=userid">其他人</block>
  67. <block v-if="m.status==1">已同意</block>
  68. <block v-else>已拒绝</block>
  69. </view>
  70. </view>
  71. </view>
  72. </block>
  73. </block>
  74. <view class="nodata" v-else >
  75. 暂无群组验证消息
  76. </view>
  77. </block>
  78. </block>
  79. <view class="loading" v-else style="padding-top: 70px;" >
  80. <view class="spinner">
  81. <view class="rect1"></view>
  82. <view class="rect2"></view>
  83. <view class="rect3"></view>
  84. <view class="rect4"></view>
  85. <view class="rect5"></view>
  86. </view>
  87. </view>
  88. <layer v-if="showlayer" title="确定要拒绝申请?" placeholder="请输入拒绝理由" isradio=true radiotext="同时设置为黑名单" btn_ok="确认" @close="showlayer=false;" @sub="layer_sub" ></layer>
  89. </view>
  90. </template>
  91. <script>
  92. import api from "../../library/index.js"
  93. import http from "../../library/http.js"
  94. import config from "../../config.js"
  95. import uniIcons from '../../components/uni-icons/uni-icons.vue'
  96. import headerline from '../../components/header.vue'
  97. import layer from '../../components/layer.vue'
  98. var windowHeight= uni.getSystemInfoSync().windowHeight;
  99. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight ;
  100. var contenttop=statusBarHeight+45;
  101. var conentheight=windowHeight-contenttop;
  102. var lottHeight= conentheight-30;
  103. var lottTop= contenttop + 30;
  104. export default {
  105. components: {
  106. uniIcons,
  107. headerline,
  108. layer
  109. },
  110. data() {
  111. return {
  112. statusBarHeight: statusBarHeight+ 'px',
  113. contenttop:contenttop+'px',
  114. contentheight:conentheight+'px',
  115. lottHeight:lottHeight+'px',
  116. lottTop:lottTop+'px',
  117. shownav:true,
  118. navitem:['好友','群组'],
  119. navselect:0,
  120. system:uni.getStorageSync('system'),
  121. userid:uni.getStorageSync('access_token'),
  122. user:uni.getStorageSync('userInfo'),
  123. group_lists:uni.getStorageSync('group_applylist'),
  124. friend_lists:uni.getStorageSync('friend_applylist'),
  125. isloading:true,
  126. page:1,
  127. showlayer:false,
  128. senddata:{},
  129. index:0,
  130. applytype:'friend',
  131. unreadnum:[0,0],
  132. num1:0,
  133. num2:0,
  134. }
  135. },
  136. methods: {
  137. timestampFormat( timestamp ) {
  138. let curTimestamp = parseInt(new Date().getTime() / 1000), //当前时间戳
  139. timestampDiff = curTimestamp - timestamp, // 参数时间戳与当前时间戳相差秒数
  140. curDate = new Date( curTimestamp * 1000 ), // 当前时间日期对象
  141. tmDate = new Date( timestamp * 1000 ), // 参数时间戳转换成的日期对象
  142. Y = tmDate.getFullYear(),
  143. m = tmDate.getMonth() + 1, d = tmDate.getDate(),
  144. H = tmDate.getHours(), i = tmDate.getMinutes(),
  145. s = tmDate.getSeconds();
  146. if ( timestampDiff < 60 ) { // 一分钟以内
  147. return "刚刚";
  148. } else if( timestampDiff < 3600 ) { // 一小时前之内
  149. return Math.floor( timestampDiff / 60 ) + "分钟前";
  150. } else if ( curDate.getFullYear() == Y && curDate.getMonth()+1 == m && curDate.getDate() == d ) {
  151. return '今天 ' + ((String(H).length == 1 ? '0' : '') + H) + ':' + ((String(i).length == 1 ? '0' : '') + i);
  152. } else {
  153. var newDate = new Date( (curTimestamp - 86400) * 1000 ); // 参数中的时间戳加一天转换成的日期对象
  154. if ( newDate.getFullYear() == Y && newDate.getMonth()+1 == m && newDate.getDate() == d ) {
  155. return '昨天 ' + ((String(H).length == 1 ? '0' : '') + H) + ':' + ((String(i).length == 1 ? '0' : '') + i);
  156. } else if ( curDate.getFullYear() == Y ) {
  157. return ((String(m).length == 1 ? '0' : '') + m) + '月' + ((String(d).length == 1 ? '0' : '') + d) + '日 ' + ((String(H).length == 1 ? '0' : '') + H) + ':' + ((String(i).length == 1 ? '0' : '') + i);
  158. } else {
  159. return Y + '年' + ((String(m).length == 1 ? '0' : '') + m) + '月' + ((String(d).length == 1 ? '0' : '') + d) + '日 ' + ((String(H).length == 1 ? '0' : '') + H) + ':' + ((String(i).length == 1 ? '0' : '') + i);
  160. }
  161. }
  162. },
  163. openuser(m){
  164. this.$jump('friend.detail',m);
  165. },
  166. opengroup(m){
  167. this.$jump('group.detail',m);
  168. },
  169. layer_sub(e){
  170. var data=this.senddata;
  171. if(this.applytype=='group'){
  172. data['apply']=e;
  173. this.$socket.send(data);
  174. this.group_lists[this.index].status=this.senddata.status;
  175. this.group_lists[this.index].apply_uid=this.user.id;
  176. this.showlayer=false;
  177. }
  178. else
  179. {
  180. this.friend_lists[this.index].status=this.senddata.status;
  181. data['apply']=JSON.stringify(e);
  182. http.setWait(false).post('user.php?act=handleFriendApply',data).then(res=>{
  183. if(res.code==200){
  184. this.getFriendData();
  185. this.showlayer=false;
  186. }else{
  187. uni.showToast({
  188. title:'网络错误,请稍后再试',
  189. icon:'none'
  190. })
  191. }
  192. })
  193. }
  194. },
  195. deal_apply(applyid,status,index) {
  196. if(status==1){
  197. this.senddata={type:'deal_group_apply',userid:this.user.id,applyid:applyid,status:status}
  198. this.index=index;
  199. this.$socket.send(this.senddata);
  200. this.group_lists[this.index].status=this.senddata.status;
  201. this.group_lists[this.index].apply_uid=this.user.id;
  202. }else{
  203. this.showlayer=true;
  204. this.senddata={type:'deal_group_apply',userid:this.user.id,applyid:applyid,status:status}
  205. this.index=index;
  206. this.applytype='group';
  207. }
  208. },
  209. deal_userapply(applyid,status,index) {
  210. if(status==1){
  211. this.friend_lists[index].status=status;
  212. http.setWait(false).post('user.php?act=handleFriendApply',{userid:this.user.id,id:applyid,status:status}).then(res=>{
  213. if(res.code==200){
  214. this.getFriendData();
  215. }else{
  216. uni.showToast({
  217. title:'网络错误,请稍后再试',
  218. icon:'none'
  219. })
  220. }
  221. })
  222. }
  223. else{
  224. this.showlayer=true;
  225. this.senddata={userid:this.user.id,id:applyid,status:status};
  226. this.index=index;
  227. this.applytype='friend';
  228. }
  229. },
  230. tapnav(e){
  231. this.navselect=e;
  232. this.page=1;
  233. if(e==1) this.getGroupData();
  234. else this.getFriendData();
  235. },
  236. getFriendData(){
  237. try{
  238. if(this.friend_lists.length>0)
  239. this.isloading=false;
  240. else
  241. this.isloading=true;
  242. }catch(e){
  243. //TODO handle the exception
  244. this.isloading=true;
  245. }
  246. http.setWait(false).get('user.php?act=getFriendApply',{userid:this.user.id,page:this.page}).then(res=>{
  247. if(res.code==200){
  248. this.isloading=false;
  249. if(this.page==1){
  250. this.friend_lists=res.data;
  251. uni.setStorageSync('friend_applylist',res.data);
  252. var num=0;
  253. for(var i=0;i<res.data.length;i++){
  254. var item=res.data[i];
  255. if(item.status==0){
  256. num=1;
  257. break;
  258. }
  259. }
  260. this.setunread(0,num);
  261. }
  262. else {
  263. this.friend_lists.push(...res.data)
  264. this.page++;
  265. }
  266. }else{
  267. uni.showToast({
  268. title:'网络错误,请稍后再试',
  269. icon:'none'
  270. })
  271. }
  272. })
  273. },
  274. setunread(index,num){
  275. if(index==0) this.num1=num;
  276. else this.num2=num;
  277. this.unreadnum.splice(0,2);
  278. this.unreadnum.push(this.num1);
  279. this.unreadnum.push(this.num2);
  280. this.$forceUpdate();
  281. },
  282. getGroupData(){
  283. try{
  284. if(this.group_lists.length>0)
  285. this.isloading=false;
  286. else
  287. this.isloading=true;
  288. }catch(e){
  289. //TODO handle the exception
  290. this.isloading=true;
  291. }
  292. http.setWait(false).get('group.php?act=applylist',{userid:this.user.id,page:this.page}).then(res=>{
  293. if(res.code==200){
  294. this.isloading=false;
  295. if(this.page==1){
  296. this.group_lists=res.data;
  297. uni.setStorageSync('group_applylist',res.data);
  298. var num=0;
  299. for(var i=0;i<res.data.length;i++){
  300. var item=res.data[i];
  301. if(item.status==0){
  302. num=1;
  303. break;
  304. }
  305. }
  306. this.setunread(1,num);
  307. }
  308. else {
  309. this.group_lists.push(...res.data);
  310. this.page++;
  311. }
  312. }else{
  313. uni.showToast({
  314. title:'网络错误,请稍后再试',
  315. icon:'none'
  316. })
  317. }
  318. })
  319. }
  320. },
  321. onReachBottom() {
  322. if(this.page==1)this.page++;
  323. if(this.navselect==1)this.getGroupData();
  324. else this.getFriendData();
  325. },
  326. onPullDownRefresh() {
  327. this.page=1;
  328. if(this.navselect==1)this.getGroupData();
  329. else this.getFriendData();
  330. },
  331. onLoad(opts) {
  332. if(opts.type=='group') this.navselect=1;
  333. else this.navselect=0;
  334. this.getGroupData();
  335. this.getFriendData();
  336. this.$socket.on('deal_response', (res) => {
  337. uni.showToast({
  338. title:res.data.message,
  339. icon:'none'
  340. })
  341. this.page=1;
  342. if(this.navselect==1) this.getGroupData();
  343. else this.getFriendData();
  344. })
  345. },
  346. onUnload() {
  347. this.$socket.off('deal_response')
  348. }
  349. }
  350. </script>
  351. <style lang="scss">
  352. @import "@/static/css/group.css";
  353. .page{
  354. background-color: #FAFAFA;
  355. }
  356. .nodata{
  357. height: 30px;
  358. line-height: 30px;
  359. text-align: center;
  360. color: #666;
  361. }
  362. .lines{
  363. margin: 0px auto;
  364. background-color: #FFF;
  365. padding: 5px 0px;
  366. width: 100%;
  367. display: table;
  368. table-layout: fixed;
  369. }
  370. .lines > view{
  371. display: table-cell;
  372. }
  373. .lines > view:first-child{
  374. width: 60px;
  375. text-align: right;
  376. }
  377. .lines > view:nth-child(2){
  378. text-align: left;
  379. padding-left: 10px;;
  380. line-height: 20px;
  381. vertical-align: top;
  382. }
  383. .lines .avatar{
  384. height: 50px;
  385. width: 50px;
  386. border-radius: 5px;
  387. vertical-align: middle;
  388. }
  389. .lines .nickname{
  390. color: #2319DC;
  391. display: inline-block;
  392. }
  393. .lines .btns{
  394. padding: 0px 10px;
  395. height: 25px;
  396. line-height: 25px;
  397. text-align: center;
  398. border-radius: 5px;
  399. font-size: 14px;
  400. display: inline-block;
  401. vertical-align: middle;
  402. cursor: pointer;
  403. margin-right: 20px;
  404. }
  405. .lines .btns.clear{
  406. border: 1px solid #666;
  407. color: #666;
  408. background-color: #fff;
  409. }
  410. .lines .btns.ok{
  411. // background: -webkit-linear-gradient(left top, #3388ff , #2319dc);
  412. // background: -o-linear-gradient(bottom right, #3388ff, #2319dc);
  413. // background: -moz-linear-gradient(bottom right, #3388ff, #2319dc);
  414. // background: linear-gradient(to bottom right, #3388ff , #2319dc);
  415. background: $base-color;
  416. color: #fff;
  417. }
  418. .lines .mark{
  419. color: #666;
  420. font-size: 12px;;
  421. height: 16px;
  422. line-height: 16px;;
  423. }
  424. .times{
  425. height: 25px;
  426. line-height: 25px;
  427. text-align: center;
  428. color: #999;
  429. font-size: 12px;
  430. }
  431. .loading {
  432. //loading动画
  433. display: flex;
  434. justify-content: center;
  435. @keyframes stretchdelay {
  436. 0%,
  437. 40%,
  438. 100% {
  439. transform: scaleY(0.6);
  440. }
  441. 20% {
  442. transform: scaleY(1.0);
  443. }
  444. }
  445. .spinner {
  446. margin: 20upx 0;
  447. width: 60upx;
  448. height: 25px;
  449. display: flex;
  450. align-items: center;
  451. justify-content: space-between;
  452. view {
  453. background-color: #ff9800;
  454. height: 25px;
  455. width: 3px;
  456. border-radius: 3px;
  457. animation: stretchdelay 1.2s infinite ease-in-out;
  458. }
  459. .rect2 {
  460. animation-delay: -1.1s;
  461. }
  462. .rect3 {
  463. animation-delay: -1.0s;
  464. }
  465. .rect4 {
  466. animation-delay: -0.9s;
  467. }
  468. .rect5 {
  469. animation-delay: -0.8s;
  470. }
  471. }
  472. }
  473. </style>