index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view class="response_box" :style="'height:' + phoneHeight + 'px'">
  3. <view class="response_ul" v-if="list.length > 0">
  4. <view class="response_list" v-for="item in list" @click="defail(item)">
  5. <view class="response_left">
  6. <u-badge numberType="overflow" shape="circle" :type="type" max="99" :value="item.unread">
  7. </u-badge>
  8. <!-- <image :src="item.img" mode=""></image> -->
  9. <image src="https://cdn.uviewui.com/uview/album/1.jpg" mode=""></image>
  10. </view>
  11. <view class="response_right">
  12. <view class="response_right_title">
  13. <view class="response_right_titleName">
  14. {{ item.real_name | name }}
  15. </view>
  16. <view class="response_right_titleTime">
  17. {{ item.msg_list[0].create_time }}
  18. </view>
  19. </view>
  20. <view class="response_right_text">
  21. {{ item.msg_list[0].msg_info | msgData}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="" style="padding: 20% 0 0 0;" v-else>
  27. <image style="margin: 0 0 0 65rpx;" src="../../static/image/13.png" mode=""></image>
  28. <view style="text-align: center; color: #83ccfd; font-size: 20px; line-height: 20rpx;">暂无数据</view>
  29. </view>
  30. <!-- 加载 -->
  31. <u-loading-page :loading="loading"></u-loading-page>
  32. <!-- 列表加载更多 -->
  33. <!-- 返回顶部 -->
  34. <u-back-top :scroll-top="scrollTop"></u-back-top>
  35. <!-- 顶部弹出框 - 视频通话提示框 -->
  36. <u-popup :safeAreaInsetTop="true" :closeOnClickOverlay="false" :customStyle="styleObj" :show="show" mode="top"
  37. :round="10" @close="close" @open="open">
  38. <view style="display: flex; justify-content: space-evenly; margin: 25rpx 0 0 0;">
  39. <view style="display: flex;">
  40. <view class="topUpImg">
  41. <image src="https://cdn.uviewui.com/uview/album/1.jpg" mode=""></image>
  42. </view>
  43. <view class="topUpTxt">
  44. <text>嚣张</text>
  45. <text>邀请你进行视频通话..</text>
  46. </view>
  47. </view>
  48. <view class="topUpBtn">
  49. <u-button @click="close()" type="error" style="border-radius: 50px; width: 50px; height: 50px;"
  50. size="mini" text="取消"></u-button>
  51. <u-button @click="open()" type="success"
  52. style="border-radius: 50px; width: 50px; height: 50px; margin: 0 0 0 15rpx;" size="mini"
  53. text="确定"></u-button>
  54. </view>
  55. </view>
  56. </u-popup>
  57. <!-- 测试 -->
  58. <image id="remoteVideo"></image>
  59. <!-- 测试 -->
  60. </view>
  61. </template>
  62. <script>
  63. import store from '@/store/index.js'; //需要引入store
  64. let App = getApp();
  65. var API = App.globalData.socketTask;
  66. export default {
  67. components: {},
  68. // 过滤
  69. filters: {
  70. name: function(val) {
  71. if (!val) return "";
  72. if (val.length > 7) {
  73. return val.slice(0, 7) + '...'
  74. }
  75. return val
  76. },
  77. msgData: function(val) {
  78. if (!val) return ""
  79. if (val.length > 21) {
  80. return val.slice(0, 21) + '...'
  81. }
  82. return val
  83. },
  84. },
  85. data() {
  86. return {
  87. loading: false, // 加载
  88. scrollTop: 0, // 返回顶部
  89. list: [],
  90. page: 0,
  91. // 消息通知
  92. type: "error",
  93. value: 99999,
  94. // 即构
  95. engine: undefined,
  96. videoObj: null,
  97. userid: "Uni" + Math.floor(Math.random() * 1000000).toString(),
  98. // 弹出框
  99. show: false,
  100. styleObj: {
  101. display: 'flex',
  102. backgroundColor: "#fff",
  103. height: '500px'
  104. },
  105. isPublishingStream: false,
  106. phoneHeight: '', // 获取当前的屏幕高度
  107. }
  108. },
  109. watch: {
  110. videoData(news, old) {
  111. console.log('触发了')
  112. console.log(news)
  113. if (news) {
  114. this.videoObj = news
  115. this.show = true
  116. }
  117. },
  118. list(val) {
  119. console.log(val)
  120. console.log(App.globalData.socketTask)
  121. if (val.length == 0 && App.globalData.socketTask == null) {
  122. App.msgInit(); // 请求重启初始化Websocket
  123. // var obj = {}
  124. // obj = {
  125. // 'action': 'list', // 动作标识,必填
  126. // 'recv_user_id': '', // 接收人用户id, 非必填
  127. // 'data': {}
  128. // }
  129. // API.send(JSON.stringify(obj))
  130. // App.msgInit(); // 重新初始化websocket
  131. }
  132. },
  133. msgList(news, old) {
  134. this.list = news
  135. console.log(news, '新数据')
  136. console.log(old, '旧数据')
  137. }
  138. },
  139. computed: {
  140. // 视频消息
  141. videoData() {
  142. return store.state.video
  143. },
  144. // 用户列表消息
  145. msgList() {
  146. return store.state.list
  147. }
  148. },
  149. methods: {
  150. loadmoreAxios() {
  151. console.log(this.list)
  152. },
  153. // 进入详情
  154. defail(data) {
  155. var that = this
  156. if (App.globalData.is_open_socket) {
  157. // websocket的服务器的原理是:发送一次消息,同时返回一组数据【否则服务器会进去死循环崩溃】
  158. // 进入详情前先发送已经阅读过消息
  159. var obj = {
  160. 'action': 'read', // 动作标识,必填
  161. 'send_user_id': data.user_id, // 接收人用户id, 非必填
  162. 'data': {}
  163. }
  164. API.send({
  165. data: JSON.stringify(obj),
  166. async success(res) {
  167. console.log("消息发送成功");
  168. },
  169. });
  170. uni.navigateTo({
  171. url: '/pages/response/details?data=' + JSON.stringify(data)
  172. })
  173. } else {
  174. console.log('没有进入')
  175. }
  176. },
  177. // 弹出框
  178. open() {
  179. console.log('open');
  180. uni.navigateTo({
  181. url: '/pages/response/video?videoObj=' + JSON.stringify(this.videoObj)
  182. })
  183. this.show = false
  184. },
  185. close() {
  186. this.show = false
  187. console.log('close');
  188. },
  189. },
  190. async onLoad() {
  191. var that = this
  192. // uni.startPullDownRefresh(); // 开始刷新
  193. uni.getSystemInfo({ //异步获取。
  194. success(res) {
  195. that.phoneHeight = res.windowHeight - 0; //窗口高度
  196. // console.log(that.phoneHeight)
  197. }
  198. });
  199. },
  200. onShow() {
  201. var that = this
  202. var a = App.globalData.list
  203. for (var i = 0; i < a.length; i++) {
  204. if (a[i].msg_list[0].im_id == 1) {
  205. a[i].msg_list.reverse()
  206. }
  207. }
  208. this.list = App.globalData.list; // 倒叙
  209. },
  210. // 下拉刷新
  211. onPullDownRefresh() {
  212. // console.log('刷新了')
  213. var that = this
  214. if (App.globalData.is_open_socket) {
  215. // websocket的服务器的原理是:发送一次消息,同时返回一组数据【否则服务器会进去死循环崩溃】
  216. var obj = {
  217. 'action': 'list', // 动作标识,必填
  218. 'send_user_id': '', // 接收人用户id, 非必填
  219. 'data': {}
  220. }
  221. API.send({
  222. data: JSON.stringify(obj),
  223. async success(res) {
  224. console.log("消息发送成功");
  225. },
  226. });
  227. } else {
  228. console.log('没有进入')
  229. }
  230. setTimeout(() => {
  231. uni.stopPullDownRefresh()
  232. }, 1000)
  233. },
  234. // 上拉加载
  235. onReachBottom() {
  236. console.log('加载了')
  237. },
  238. onPageScroll(e) {
  239. this.scrollTop = e.scrollTop;
  240. },
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. page {
  245. background: #f7f7f7;
  246. padding: 25rpx 0 25rpx 0;
  247. }
  248. .response_box {
  249. background: #f7f7f7;
  250. .response_ul {
  251. background: #f7f7f7;
  252. overflow: hidden;
  253. .response_list {
  254. position: relative;
  255. background: #FFF;
  256. border: 1px solid #e5e2e2;
  257. margin: 0 0 35rpx 0;
  258. padding: 20rpx 20rpx 20rpx 20rpx;
  259. display: flex;
  260. // 左
  261. .response_left {
  262. image {
  263. width: 110rpx;
  264. height: 110rpx;
  265. border-radius: 20rpx;
  266. }
  267. }
  268. // 右
  269. .response_right {
  270. margin: 8rpx 0 0 30rpx;
  271. width: 100%;
  272. .response_right_title {
  273. line-height: 50rpx;
  274. display: flex;
  275. justify-content: space-between;
  276. .response_right_titleName {}
  277. .response_right_titleTime {
  278. color: #999999;
  279. font-size: 25rpx;
  280. }
  281. }
  282. .response_right_text {
  283. color: #999999;
  284. font-size: 25rpx;
  285. line-height: 58rpx;
  286. }
  287. }
  288. }
  289. }
  290. .topUpImg {
  291. image {
  292. width: 110rpx;
  293. height: 110rpx;
  294. border-radius: 15rpx;
  295. }
  296. margin: 15rpx 0 0 15rpx;
  297. }
  298. .topUpTxt {
  299. margin: 45rpx 0 0 15rpx;
  300. text {
  301. color: #979994;
  302. font-size: 28rpx;
  303. display: block;
  304. }
  305. }
  306. .topUpBtn {
  307. display: flex;
  308. margin: 25rpx 0 0 0;
  309. }
  310. // 视频通话
  311. .video_you {
  312. position: relative;
  313. // border: 1px solid #000;
  314. width: 100%;
  315. height: 100%;
  316. overflow: hidden;
  317. }
  318. .video_me {
  319. // border: 1px solid #000;
  320. width: 200rpx;
  321. height: 300rpx;
  322. position: absolute;
  323. right: 0;
  324. top: 0;
  325. }
  326. .video_btn {
  327. // border: 1px solid;
  328. position: absolute;
  329. bottom: 0;
  330. left: 0;
  331. width: 100%;
  332. .video_imgList {
  333. display: flex;
  334. justify-content: space-evenly;
  335. .video_imgList1 {
  336. // border: 1px solid;
  337. // background: rgba(0, 0, 0, .5);
  338. .video_view {
  339. background: rgba(0, 0, 0, .5);
  340. border: 1px solid;
  341. border-radius: 50px;
  342. width: 50px;
  343. height: 50px;
  344. margin: 0 auto;
  345. image {
  346. width: 50rpx;
  347. height: 50rpx;
  348. margin: 24rpx 0 0 25rpx;
  349. }
  350. }
  351. view {
  352. color: #fff;
  353. font-size: 20rpx;
  354. }
  355. }
  356. .video_imgList2 {
  357. // border: 1px solid;
  358. // background: rgba(0, 0, 0, .5);
  359. .video_view {
  360. border: 1px solid;
  361. background: rgba(0, 0, 0, .5);
  362. margin: 0 auto;
  363. border-radius: 50px;
  364. width: 50px;
  365. height: 50px;
  366. image {
  367. width: 50rpx;
  368. height: 50rpx;
  369. margin: 24rpx 0 0 25rpx;
  370. }
  371. }
  372. view {
  373. color: #fff;
  374. font-size: 20rpx;
  375. }
  376. }
  377. }
  378. }
  379. }
  380. // uview 样式修改
  381. /deep/.u-badge--error {
  382. position: absolute;
  383. left: 105rpx;
  384. top: 15rpx;
  385. z-index: 10;
  386. }
  387. /deep/.u-slide-down-enter-active {
  388. height: 200rpx;
  389. }
  390. </style>