刘光辉
15 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { OfficeContentControl } from '../onlyoffice/types';
 
import { acceptHMRUpdate, defineStore } from 'pinia';
 
export type RuntimeStatus = 'error' | 'initializing' | 'ready' | 'working';
 
export type OperationState = { kind: 'error' | 'success' | 'working'; message: string } | { kind: 'idle'; message: '' };
 
export interface AnnotationState {
  controls: OfficeContentControl[];
  operation: OperationState;
  status: RuntimeStatus;
}
 
function initialState(): AnnotationState {
  return {
    status: 'initializing',
    controls: [],
    operation: { kind: 'idle', message: '' },
  };
}
 
export const useAnnotationStore = defineStore('annotation', {
  state: initialState,
  actions: {
    reset() {
      this.$state = initialState();
    },
    setControls(controls: OfficeContentControl[]) {
      this.controls = [...controls];
    },
    setOperation(operation: OperationState) {
      this.operation = operation;
    },
    setStatus(status: RuntimeStatus) {
      this.status = status;
    },
  },
});
 
const hot = import.meta.hot;
if (hot) {
  hot.accept(acceptHMRUpdate(useAnnotationStore, hot));
}