contextxx.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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"></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. methods: {
  31. ...mapActions(['query', 'fetch']),
  32. async search() {
  33. let res = await this.query({ seller_id: this.user.uid });
  34. if (this.$checkRes(res)) this.$set(this, `list`, res.data);
  35. },
  36. async toChat(data) {
  37. let res = await this.fetch(data.id);
  38. if (this.$checkRes(res)) {
  39. this.$set(this, `room`, res.data);
  40. this.view = 'chat';
  41. }
  42. },
  43. },
  44. computed: {
  45. ...mapState(['user']),
  46. pageTitle() {
  47. return `${this.$route.meta.title}`;
  48. },
  49. },
  50. metaInfo() {
  51. return { title: this.$route.meta.title };
  52. },
  53. };
  54. </script>
  55. <style lang="less" scoped></style>