index.ts 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { defineStore } from 'pinia';
  2. import { Oss } from '@/api/models';
  3. import { toRaw } from 'vue';
  4. export interface DocState {
  5. file: Oss | any;
  6. messages:
  7. | {
  8. id: string;
  9. list: any[];
  10. }[]
  11. | any[];
  12. curMessage: any[];
  13. }
  14. export const useDocStore = defineStore({
  15. id: 'doc-store',
  16. state: (): DocState => ({
  17. file: {},
  18. messages: [],
  19. curMessage: [],
  20. }),
  21. actions: {
  22. onSelect(item: Oss) {
  23. this.file = item;
  24. const list = this.messages.filter((i) => i.id == this.file.id);
  25. if (list.length > 0) {
  26. this.curMessage = list[0].list;
  27. } else {
  28. this.curMessage = [];
  29. }
  30. console.log(this.curMessage);
  31. },
  32. addMessage(item: any) {
  33. const list = this.messages.filter((i) => i.id == this.file.id);
  34. if (list.length > 0) {
  35. list[0].list.push(toRaw(item));
  36. } else {
  37. this.messages.push({
  38. id: this.file.id,
  39. list: [toRaw(item)],
  40. });
  41. }
  42. },
  43. },
  44. });