contextxx.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div id="contextxx">
  3. <template v-if="view == 'room'">
  4. <rooms :list="list" @toChat="toChat"></rooms>
  5. </template>
  6. <template v-else>
  7. <chat :room="room" @toRoom="view = 'room'"></chat>
  8. </template>
  9. </div>
  10. </template>
  11. <script>
  12. import rooms from './parts/room.vue';
  13. import chat from './parts/chat.vue';
  14. import { mapState, createNamespacedHelpers } from 'vuex';
  15. const { mapActions } = createNamespacedHelpers('personalroom');
  16. export default {
  17. name: 'contextxx',
  18. props: {},
  19. components: { rooms, chat },
  20. data: () => {
  21. return {
  22. view: 'room',
  23. list: [],
  24. room: {},
  25. };
  26. },
  27. created() {
  28. this.search();
  29. },
  30. mounted() {
  31. this.channel();
  32. },
  33. methods: {
  34. ...mapActions(['query', 'fetch']),
  35. async search() {
  36. let res = await this.query({ seller_id: this.user.uid });
  37. if (this.$checkRes(res)) this.$set(this, `list`, res.data);
  38. },
  39. async toChat(data) {
  40. let res = await this.fetch(data.id);
  41. if (this.$checkRes(res)) {
  42. this.$set(this, `room`, res.data);
  43. this.view = 'chat';
  44. }
  45. },
  46. channel() {
  47. this.$stomp({
  48. [`/exchange/chat_message/${this.user.uid}`]: this.onMessage,
  49. });
  50. },
  51. onMessage(message) {
  52. console.log(message);
  53. },
  54. },
  55. computed: {
  56. ...mapState(['user']),
  57. pageTitle() {
  58. return `${this.$route.meta.title}`;
  59. },
  60. },
  61. metaInfo() {
  62. return { title: this.$route.meta.title };
  63. },
  64. };
  65. </script>
  66. <style lang="less" scoped></style>