chatroom.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <chat id="chat" :username="username" ref="chat" chatType="singleChat" @onClickInviteMsg="onClickMsg"></chat>
  3. </template>
  4. <script>
  5. let disp = require("../../hxChatSDK/utils/broadcast");
  6. import chat from "../../chat/components/chat/chat.vue";
  7. export default {
  8. data() {
  9. return {
  10. username: {
  11. your: ""
  12. }
  13. };
  14. },
  15. components: {
  16. chat
  17. },
  18. props: {},
  19. // options = 系统传入的 url 参数
  20. onLoad(options) {
  21. console.log('options>>>', options)
  22. let username = JSON.parse(options.username);
  23. this.setData({
  24. username: username
  25. });
  26. // 生成的支付宝小程序在onLoad里获取不到,这里放到全局变量下
  27. uni.username = username;
  28. var userNameText = username.your;
  29. const imUserInfo = uni.getStorageSync("imUserInfo_" + username.your);
  30. if (imUserInfo && imUserInfo.nickName) {
  31. userNameText = imUserInfo.nickName;
  32. }
  33. uni.setNavigationBarTitle({
  34. title: userNameText
  35. });
  36. },
  37. onUnload(options) {
  38. disp.fire("em.chatroom.leave");
  39. },
  40. onPullDownRefresh: function() {
  41. uni.showNavigationBarLoading();
  42. this.$refs.chat.getMore();
  43. // 停止下拉动作
  44. uni.hideNavigationBarLoading();
  45. uni.stopPullDownRefresh();
  46. },
  47. methods: {
  48. onClickMsg(msg) {
  49. msg.action = 'join'
  50. uni.navigateTo({
  51. url: "../emedia/index?srcData=" + JSON.stringify(msg)
  52. });
  53. },
  54. onNavigationBarButtonTap(e) {
  55. uni.navigateTo({
  56. url: `/pages/moreMenu/moreMenu?username=${this.username.your}&type=singleChat`
  57. })
  58. },
  59. }
  60. };
  61. </script>
  62. <style>
  63. @import "./chatroom.css";
  64. </style>