index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="response_box">
  3. <view class="response_ul">
  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"></u-badge>
  7. <!-- <image :src="item.img" mode=""></image> -->
  8. <image src="https://cdn.uviewui.com/uview/album/1.jpg" mode=""></image>
  9. </view>
  10. <view class="response_right">
  11. <view class="response_right_title">
  12. <view class="response_right_titleName">
  13. {{ item.real_name | name }}
  14. </view>
  15. <view class="response_right_titleTime">
  16. {{ item.msg_list[0].create_time }}
  17. </view>
  18. </view>
  19. <view class="response_right_text">
  20. {{ item.msg_list[0].msg_info | msgData}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 加载 -->
  26. <u-loading-page :loading="loading"></u-loading-page>
  27. <!-- 列表加载更多 -->
  28. <!-- 返回顶部 -->
  29. <u-back-top :scroll-top="scrollTop"></u-back-top>
  30. <!-- 顶部弹出框 - 视频通话提示框 -->
  31. <u-popup :safeAreaInsetTop="true" :closeOnClickOverlay="false" :customStyle="styleObj" :show="show" mode="top"
  32. :round="10" @close="close" @open="open">
  33. <view style="display: flex; justify-content: space-evenly; margin: 25rpx 0 0 0;">
  34. <view style="display: flex;">
  35. <view class="topUpImg">
  36. <image src="https://cdn.uviewui.com/uview/album/1.jpg" mode=""></image>
  37. </view>
  38. <view class="topUpTxt">
  39. <text>嚣张</text>
  40. <text>邀请你进行视频通话..</text>
  41. </view>
  42. </view>
  43. <view class="topUpBtn">
  44. <u-button @click="close()" type="error" style="border-radius: 50px; width: 50px; height: 50px;"
  45. size="mini" text="取消"></u-button>
  46. <u-button @click="open()" type="success"
  47. style="border-radius: 50px; width: 50px; height: 50px; margin: 0 0 0 15rpx;" size="mini"
  48. text="确定"></u-button>
  49. </view>
  50. </view>
  51. </u-popup>
  52. <!-- 视频通话框 -->
  53. <!-- <u-popup :show="videoShow" :closeOnClickOverlay="false" :customStyle="styleObj1" mode="center"
  54. @close="videClose" @open="videOpen">
  55. 本地预览视图
  56. <view class="video_me">
  57. <zego-local-view :viewMode="publisherViewModeIndex"
  58. style="height: 403.84rpx;flex: 1; border: 1px solid #0000;">
  59. </zego-local-view>
  60. </view>
  61. 服务器传来的预览图
  62. <view class="video_you">
  63. <zego-remote-view :viewMode="publisherViewModeIndex"
  64. style="height: 403.84rpx;flex: 1; border: 1px solid #0000;">
  65. </zego-remote-view>
  66. </view>
  67. <view class="video_btn">
  68. <view class="video_imgList">
  69. <view class="video_imgList1">
  70. <view class="video_view">
  71. <image src="../../static/image/9.png" mode=""></image>
  72. </view>
  73. <view class="">翻转镜头</view>
  74. </view>
  75. <view class="video_imgList2">
  76. <view class="video_view">
  77. <image src="../../static/image/8.png" mode=""></image>
  78. </view>
  79. <view class="">切换语音通话</view>
  80. </view>
  81. </view>
  82. <u-button type="error" style="border-radius: 50px; width: 50px; height: 50px;" size="mini" text="关闭">
  83. </u-button>
  84. </view>
  85. </u-popup> -->
  86. </view>
  87. </template>
  88. <script>
  89. import store from '@/store/index.js'; //需要引入store
  90. let App = getApp();
  91. var API = App.globalData.socketTask;
  92. import permision from "@/zego-express-video-uniapp/permission.js";
  93. // import ZegoExpressEngine from '@/zego-express-video-uniapp/lib/ZegoExpressEngine';
  94. import {
  95. ZegoScenario,
  96. ZegoRoomState,
  97. ZegoUpdateType,
  98. // ZegoViewMode
  99. } from '@/zego-express-video-uniapp/lib/ZegoExpressDefines'
  100. import {
  101. AppID,
  102. AppSign
  103. } from '@/zego-express-video-uniapp/KeyCenter.js'
  104. import ZegoLocalView from '@/zego-express-video-uniapp/zego-view/ZegoLocalView';
  105. import ZegoRemoteView from '@/zego-express-video-uniapp/zego-view/ZegoRemoteView';
  106. export default {
  107. components: {
  108. // ZegoLocalView: ZegoLocalView,
  109. // ZegoRemoteView: ZegoRemoteView
  110. },
  111. // 过滤
  112. filters: {
  113. name: function(val) {
  114. if (!val) return "";
  115. if (val.length > 7) {
  116. return val.slice(0, 7) + '...'
  117. }
  118. return val
  119. },
  120. msgData: function(val) {
  121. if (!val) return ""
  122. if (val.length > 21) {
  123. return val.slice(0, 21) + '...'
  124. }
  125. return val
  126. },
  127. },
  128. data() {
  129. return {
  130. loading: false, // 加载
  131. scrollTop: 0, // 返回顶部
  132. list: [],
  133. page: 0,
  134. // 消息通知
  135. type: "error",
  136. value: 99999,
  137. // 即构
  138. engine: undefined,
  139. videoObj: null,
  140. userid: "Uni" + Math.floor(Math.random() * 1000000).toString(),
  141. // 弹出框
  142. show: false,
  143. styleObj: {
  144. display: 'flex',
  145. backgroundColor: "#fff",
  146. height: '500px'
  147. },
  148. // videoShow: false, // 视频通话框
  149. // styleObj1: {
  150. // backgroundColor: "#fff",
  151. // height: '100%',
  152. // width: '100%'
  153. // },
  154. // publisherViewModeIndex: 0, // 本地预览图
  155. isPublishingStream: false,
  156. }
  157. },
  158. watch: {
  159. videoData(news, old) {
  160. console.log('触发了')
  161. console.log(news)
  162. if (news) {
  163. this.videoObj = news
  164. this.show = true
  165. }
  166. },
  167. },
  168. computed: {
  169. videoData() {
  170. return store.state.video
  171. },
  172. },
  173. methods: {
  174. loadmoreAxios() {
  175. console.log(this.list)
  176. },
  177. // 即构 - 视频通话 初始化
  178. async setup() {
  179. var that = this
  180. // 创建引擎
  181. let profile = {
  182. appID: AppID,
  183. appSign: AppSign,
  184. scenario: ZegoScenario.General
  185. }
  186. this.engine = await ZegoExpressEngine.createEngineWithProfile(profile);
  187. // console.log(this.engine)
  188. this.addListeners();
  189. // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + that.videoObj.room_id)
  190. this.engine.loginRoom(that.videoObj.room_id, {
  191. userID: that.videoObj.room_id,
  192. userName: that.videoObj.room_id
  193. }, {
  194. isUserStatusNotify: true
  195. });
  196. },
  197. // 即构 - 视频通话 监听房间
  198. addListeners() {
  199. // 房间状态变化通知
  200. this.engine.on("roomStateUpdate", (roomID, state, errorCode, extendedData) => {
  201. console.log('房间状态变化')
  202. });
  203. // 房间用户变化通知
  204. this.engine.on("roomUserUpdate", (roomID, updateType, userList) => {
  205. console.log('房间用户变化通知')
  206. });
  207. // 房间内其他用户推的流变化通知
  208. this.engine.on("roomStreamUpdate", (roomID, updateType, streamList) => {
  209. console.log('房间内其他用户推的流变化通知')
  210. });
  211. // 房间内在线用户数量回调
  212. this.engine.on("roomOnlineUserCountUpdate", (roomID, count) => {
  213. console.log(roomID)
  214. console.log(count)
  215. console.log('>?>>>>>>>>>>>>>>>>>>>>>>>在线用户有变化')
  216. });
  217. // 拉流质量回调
  218. this.engine.on("playerQualityUpdate", (streamID, quality) => {
  219. console.log('拉流质量回调')
  220. });
  221. // 推流质量回调
  222. this.engine.on("publisherQualityUpdate", (streamID, quality) => {
  223. console.log('推流质量回调')
  224. });
  225. // 采集视频大小变更回调
  226. this.engine.on("publisherVideoSizeChanged", (width, height, channel) => {
  227. console.log('采集视频大小变更回调')
  228. });
  229. // 拉流分辨率变更通知
  230. this.engine.on("playerVideoSizeChanged", (streamID, width, height) => {
  231. console.log('拉流分辨率变更通知')
  232. });
  233. },
  234. // 进入详情
  235. defail(data) {
  236. var that = this
  237. if (App.globalData.is_open_socket) {
  238. // websocket的服务器的原理是:发送一次消息,同时返回一组数据【否则服务器会进去死循环崩溃】
  239. // 进入详情前先发送已经阅读过消息
  240. var obj = {
  241. 'action': 'read', // 动作标识,必填
  242. 'send_user_id': data.user_id, // 接收人用户id, 非必填
  243. 'data': {}
  244. }
  245. API.send({
  246. data: JSON.stringify(obj),
  247. async success(res) {
  248. console.log("消息发送成功");
  249. },
  250. });
  251. uni.navigateTo({
  252. url: '/pages/response/details?data=' + JSON.stringify(data)
  253. })
  254. } else {
  255. console.log('没有进入')
  256. }
  257. },
  258. // 弹出框
  259. open() {
  260. console.log('open');
  261. uni.navigateTo({
  262. url: '/pages/response/video?videoObj=' + JSON.stringify(this.videoObj)
  263. })
  264. this.show = false
  265. },
  266. close() {
  267. this.show = false
  268. console.log('close');
  269. },
  270. // 视频通话弹框
  271. // videOpen() {
  272. // console.log('open');
  273. // },
  274. // videClose() {
  275. // console.log('close');
  276. // },
  277. // 推流 - 展示视图
  278. onPublish() {
  279. // 设置视频配置
  280. ZegoExpressEngine.instance().setVideoConfig(this.videoObj.room_id);
  281. if (this.isPublishingStream) {
  282. this.engine.stopPreview();
  283. this.engine.stopPublishingStream();
  284. this.publishBtnName = "Start Publishing";
  285. } else {
  286. this.engine.startPreview();
  287. this.engine.startPublishingStream(this.videoObj.room_id);
  288. this.publishBtnName = "Stop Publishing";
  289. }
  290. this.isPublishingStream = !this.isPublishingStream;
  291. },
  292. },
  293. async onLoad() {
  294. // uni.startPullDownRefresh(); // 开始刷新
  295. // 即构 - 视频通话
  296. // 获取系统信息同步接口
  297. // if (uni.getSystemInfoSync().platform === 'android') {
  298. // await permision.requestAndroidPermission('android.permission.RECORD_AUDIO');
  299. // await permision.requestAndroidPermission('android.permission.CAMERA');
  300. // }
  301. // await this.setup()
  302. },
  303. onShow() {
  304. var that = this
  305. var a = App.globalData.list
  306. for (var i = 0; i < a.length; i++) {
  307. if (a[i].msg_list[0].im_id == 1) {
  308. a[i].msg_list.reverse()
  309. }
  310. }
  311. this.list = App.globalData.list; // 倒叙
  312. },
  313. // 下拉刷新
  314. onPullDownRefresh() {
  315. console.log('刷新了')
  316. },
  317. // 上拉加载
  318. onReachBottom() {
  319. console.log('加载了')
  320. },
  321. onPageScroll(e) {
  322. this.scrollTop = e.scrollTop;
  323. },
  324. }
  325. </script>
  326. <style lang="scss" scoped>
  327. page {
  328. background: #f7f7f7;
  329. padding: 25rpx 0 25rpx 0;
  330. overflow: hidden;
  331. }
  332. .response_box {
  333. background: #f7f7f7;
  334. .response_ul {
  335. // border: 1px solid #000;
  336. overflow-y: auto;
  337. // height: 1550rpx;
  338. height: 1450rpx;
  339. .response_list {
  340. position: relative;
  341. background: #FFF;
  342. border: 1px solid #e5e2e2;
  343. margin: 0 0 35rpx 0;
  344. padding: 20rpx 20rpx 20rpx 20rpx;
  345. display: flex;
  346. // 左
  347. .response_left {
  348. image {
  349. width: 110rpx;
  350. height: 110rpx;
  351. border-radius: 20rpx;
  352. }
  353. }
  354. // 右
  355. .response_right {
  356. margin: 8rpx 0 0 30rpx;
  357. width: 100%;
  358. .response_right_title {
  359. line-height: 50rpx;
  360. display: flex;
  361. justify-content: space-between;
  362. .response_right_titleName {}
  363. .response_right_titleTime {
  364. color: #999999;
  365. font-size: 25rpx;
  366. }
  367. }
  368. .response_right_text {
  369. color: #999999;
  370. font-size: 25rpx;
  371. line-height: 58rpx;
  372. }
  373. }
  374. }
  375. }
  376. .topUpImg {
  377. image {
  378. width: 110rpx;
  379. height: 110rpx;
  380. border-radius: 15rpx;
  381. }
  382. margin: 15rpx 0 0 15rpx;
  383. }
  384. .topUpTxt {
  385. margin: 45rpx 0 0 15rpx;
  386. text {
  387. color: #979994;
  388. font-size: 28rpx;
  389. display: block;
  390. }
  391. }
  392. .topUpBtn {
  393. display: flex;
  394. margin: 25rpx 0 0 0;
  395. }
  396. // 视频通话
  397. .video_you {
  398. position: relative;
  399. // border: 1px solid #000;
  400. width: 100%;
  401. height: 100%;
  402. overflow: hidden;
  403. }
  404. .video_me {
  405. // border: 1px solid #000;
  406. width: 200rpx;
  407. height: 300rpx;
  408. position: absolute;
  409. right: 0;
  410. top: 0;
  411. }
  412. .video_btn {
  413. // border: 1px solid;
  414. position: absolute;
  415. bottom: 0;
  416. left: 0;
  417. width: 100%;
  418. .video_imgList {
  419. display: flex;
  420. justify-content: space-evenly;
  421. .video_imgList1 {
  422. // border: 1px solid;
  423. // background: rgba(0, 0, 0, .5);
  424. .video_view {
  425. background: rgba(0, 0, 0, .5);
  426. border: 1px solid;
  427. border-radius: 50px;
  428. width: 50px;
  429. height: 50px;
  430. margin: 0 auto;
  431. image {
  432. width: 50rpx;
  433. height: 50rpx;
  434. margin: 24rpx 0 0 25rpx;
  435. }
  436. }
  437. view {
  438. color: #fff;
  439. font-size: 20rpx;
  440. }
  441. }
  442. .video_imgList2 {
  443. // border: 1px solid;
  444. // background: rgba(0, 0, 0, .5);
  445. .video_view {
  446. border: 1px solid;
  447. background: rgba(0, 0, 0, .5);
  448. margin: 0 auto;
  449. border-radius: 50px;
  450. width: 50px;
  451. height: 50px;
  452. image {
  453. width: 50rpx;
  454. height: 50rpx;
  455. margin: 24rpx 0 0 25rpx;
  456. }
  457. }
  458. view {
  459. color: #fff;
  460. font-size: 20rpx;
  461. }
  462. }
  463. }
  464. }
  465. }
  466. // uview 样式修改
  467. /deep/.u-badge--error {
  468. position: absolute;
  469. left: 105rpx;
  470. top: 15rpx;
  471. z-index: 10;
  472. }
  473. /deep/.u-slide-down-enter-active {
  474. height: 200rpx;
  475. }
  476. </style>