chat-model.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <!-- v-if="isConnect" -->
  3. <div class="chat-message">
  4. <!-- 会话列表界面 -->
  5. <div class="chat-header">
  6. <i class="el-icon-close" @click="$listeners.close()"></i>
  7. <div class="header-card">
  8. <el-tooltip
  9. effect="dark"
  10. content="会话"
  11. placement="bottom"
  12. :open-delay="500"
  13. >
  14. <i
  15. class="el-icon-chat-line-round"
  16. :class="active === 'conversation' && 'active'"
  17. @click="active = 'conversation'"
  18. ></i>
  19. </el-tooltip>
  20. <el-tooltip
  21. effect="dark"
  22. content="联系人"
  23. placement="bottom"
  24. :open-delay="500"
  25. >
  26. <i
  27. class="el-icon-user"
  28. :class="active === 'contacts' && 'active'"
  29. @click="active = 'contacts'"
  30. ></i>
  31. </el-tooltip>
  32. <el-tooltip
  33. effect="dark"
  34. content="班级"
  35. placement="bottom"
  36. :open-delay="500"
  37. >
  38. <!-- <i
  39. class="el-icon-menu"
  40. :class="active === 'class' && 'active'"
  41. @click="active = 'class'"
  42. ></i> -->
  43. <!-- <img src="../imkit/images/class.svg" style="width: 30px;" /> -->
  44. <svg
  45. t="1660637972073"
  46. class="icon icon-class"
  47. :class="active === 'class' && 'active'"
  48. @click="active = 'class'"
  49. viewBox="0 0 1024 1024"
  50. version="1.1"
  51. xmlns="http://www.w3.org/2000/svg"
  52. p-id="3853"
  53. width="30"
  54. height="30"
  55. >
  56. <path
  57. d="M710.6 592.64c-34.76-35.29-75.26-63.01-120.36-82.39-7.6-3.26-15.28-6.26-23.03-9C616.28 463.21 648 403.29 648 336c0-114.69-92.11-208-205.33-208s-205.33 93.31-205.33 208c0 67.29 31.72 127.21 80.8 165.26-7.75 2.74-15.43 5.74-23.03 9-45.11 19.37-85.6 47.09-120.36 82.39-34.73 35.26-61.99 76.32-81.03 122.04C73.99 762 64 812.23 64 864c0 17.67 14.33 32 32 32s32-14.33 32-32c0-176.45 141.16-320 314.67-320 173.51 0 314.67 143.55 314.67 320 0 17.67 14.33 32 32 32s32-14.33 32-32c0-51.77-9.99-102-29.7-149.32-19.05-45.72-46.32-86.77-81.04-122.04zM301.33 336c0-79.4 63.4-144 141.33-144S584 256.6 584 336s-63.4 144-141.33 144-141.34-64.6-141.34-144z"
  58. p-id="3854"
  59. fill="#000000"
  60. ></path>
  61. <path
  62. d="M885.37 599.86c-23.5-32.05-51.65-60.1-83.65-83.36a377.22 377.22 0 0 0-58.05-34.72 208.22 208.22 0 0 0 23.19-35.61c15.09-29.39 23.07-62.54 23.07-95.87 0-83.7-49.16-158.9-125.24-191.57-16.24-6.98-35.06 0.54-42.03 16.77-6.97 16.24 0.54 35.06 16.78 42.03 52.54 22.56 86.49 74.68 86.49 132.77 0 45.62-21.49 88.86-57.55 115.96a31.89 31.89 0 0 0-13.01 17.04c-5.4 16.83 3.87 34.85 20.7 40.24C807.61 565.72 896 688.39 896 828.8c0 17.67 14.33 32 32 32s32-14.33 32-32c0-83.2-25.81-162.36-74.63-228.94z"
  63. p-id="3855"
  64. fill="#000000"
  65. ></path>
  66. </svg>
  67. </el-tooltip>
  68. </div>
  69. </div>
  70. <el-container style="margin-top: 56px">
  71. <el-aside width="280px" style="border-right: 1px solid #f7f7f7;">
  72. <conversation-list
  73. ref="conversationList"
  74. v-show="active === 'conversation'"
  75. />
  76. <contacts-list
  77. ref="contactsList"
  78. v-show="active === 'contacts'"
  79. @select="onSelect"
  80. />
  81. <class-list
  82. ref="classList"
  83. v-show="active === 'class'"
  84. @select="onSelect"
  85. />
  86. </el-aside>
  87. <!-- 判断是否有会话 -->
  88. <el-container v-show="currentConversation.targetId">
  89. <el-main style="padding: 0" id="el-main">
  90. <message-list ref="messageList"></message-list>
  91. </el-main>
  92. <el-footer
  93. style="height: auto; border-top: 1px solid #f7f7f7; padding: 0 20px;"
  94. >
  95. <message-editor ref="messageEditor"></message-editor>
  96. </el-footer>
  97. </el-container>
  98. <el-empty
  99. v-if="!currentConversation.targetId"
  100. :image="emptyImg"
  101. style="width: 100%;height: 100%"
  102. description=" "
  103. ></el-empty>
  104. </el-container>
  105. </div>
  106. </template>
  107. <script>
  108. import ConversationList from "../components/conversation-list.vue";
  109. import MessageList from "../components/message-list.vue";
  110. import MessageEditor from "../components/message-editor.vue";
  111. import ContactsList from "../components/contacts-list.vue";
  112. import ClassList from "../components/class-list.vue";
  113. import { core, CoreEvent } from "../imkit";
  114. import * as RongIMLib from "@rongcloud/imlib-next";
  115. import { custom_service } from "./chat.js";
  116. import ItemVue from "../Sidebar/Item.vue";
  117. // 接入时需要将 '请更换您应用的 appkey' 替换为您的应用的 appkey
  118. let libOption = { appkey: "c9kqb3rdc451j" };
  119. // 初始化 SDK
  120. core.init({
  121. service: custom_service,
  122. libOption: libOption,
  123. conversationPullCount: 20
  124. });
  125. export default {
  126. components: {
  127. ConversationList,
  128. MessageList,
  129. MessageEditor,
  130. ContactsList,
  131. ClassList
  132. },
  133. data() {
  134. return {
  135. emptyImg: require("../imkit/images/no-conversation.svg"),
  136. active: "conversation", // 会话 conversation; 联系人 contacts; 班级 class
  137. isConnect: false, // 连接中
  138. currentConversation: {
  139. channelId: "",
  140. conversationType: 0,
  141. targetId: ""
  142. }
  143. };
  144. },
  145. mounted() {
  146. core.connect(this.$store.state.user.imToken).then(res => {
  147. if (res.code === RongIMLib.ErrorCode.SUCCESS) {
  148. console.log("链接成功, 链接用户 id 为: ", res.data.userId);
  149. this.isConnect = true;
  150. } else {
  151. console.warn("链接失败, code:", res.code);
  152. }
  153. });
  154. core.on(CoreEvent.SWITCH_CONVERSATION, this.switchConversation);
  155. // 注册消息监听器
  156. // core.on("tapConversation", function(e) {
  157. // console.log("tapConversation", e);
  158. // });
  159. },
  160. methods: {
  161. onSelect(item) {
  162. console.log(item, "item");
  163. core.selectConversation({
  164. conversationType: item.conversationType,
  165. targetId: item.targetId,
  166. channelId: item.channelId
  167. });
  168. this.active = "conversation";
  169. },
  170. switchConversation(conversation) {
  171. console.log(conversation, "switchConversation chat-model");
  172. this.currentConversation = conversation;
  173. }
  174. },
  175. destoryed() {
  176. core.off(CoreEvent.SWITCH_CONVERSATION, this.switchConversation);
  177. }
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .chat-message {
  182. height: 100%;
  183. display: flex;
  184. }
  185. .chat-header {
  186. position: absolute;
  187. left: 0;
  188. right: 0;
  189. background: #f7f7f7;
  190. width: 100%;
  191. height: 56px;
  192. .el-icon-close {
  193. position: absolute;
  194. top: 0;
  195. right: 12px;
  196. line-height: 56px;
  197. font-size: 18px;
  198. font-weight: 600;
  199. text-align: center;
  200. color: #333;
  201. cursor: pointer;
  202. }
  203. .header-card {
  204. cursor: pointer;
  205. line-height: 56px;
  206. text-align: center;
  207. font-size: 30px;
  208. color: #333;
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. height: 56px;
  213. i,
  214. .icon-class {
  215. margin: 0 8px;
  216. &:hover,
  217. &.active {
  218. path {
  219. fill: #00a79d;
  220. }
  221. color: #00a79d;
  222. }
  223. }
  224. }
  225. }
  226. .chat-conversation {
  227. float: left;
  228. width: 20vw;
  229. height: 100%;
  230. overflow: hidden;
  231. }
  232. .chat-container {
  233. width: calc(100% - 20vw);
  234. }
  235. .chat-massage-list {
  236. height: calc(100% - 150px);
  237. }
  238. .chat-massage-editor {
  239. height: 150px;
  240. }
  241. /deep/.no-data::before {
  242. background-size: cover;
  243. }
  244. </style>