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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| /**
| * 插件内全局状态管理
| * @author sonve
| * @version 1.0.0
| * @date 2024-12-04
| */
|
| // #ifdef VUE3
| import { reactive } from 'vue';
| // #endif
|
| // #ifdef VUE2
| import Vue from 'vue';
| // #endif
|
| // 定义state状态
| let state = null
|
| // #ifdef VUE3
| // 定义响应式状态
| state = reactive({
| curEID: '',
| formats: {},
| isReadOnly: false,
| firstInstanceFlag: '' // 首次实例化标志,禁止手动更改
| })
| // #endif
|
| // #ifdef VUE2
| // 定义响应式状态
| state = Vue.observable({
| curEID: '',
| formats: {},
| isReadOnly: false,
| firstInstanceFlag: '' // 首次实例化标志,禁止手动更改
| })
| // #endif
|
| // 定义方法
| function getEditor(eid) {
| return state[`${eid}-ctx`];
| };
|
| function setEditor(eid, ctx) {
| state[`${eid}-ctx`] = ctx
| // #ifdef MP-WEIXIN
| state[`${eid}-ctx`].id = eid
| // #endif
| }
|
| function getEID() {
| return state.curEID
| };
|
| function setEID(eid) {
| state.curEID = eid
| }
|
| function getFormats() {
| return state.formats
| }
|
| function setFormats(formats) {
| state.formats = formats
| }
|
| function getReadOnly() {
| return state.isReadOnly
| }
|
| function setReadOnly(readOnly) {
| state.isReadOnly = readOnly
| }
|
| function destroy() {
| // 重置所有状态
| state = {}
| state.curEID = ''
| state.formats = {}
| state.isReadOnly = false
| state.firstInstanceFlag = '' // 首次实例化标志,禁止手动更改
| }
|
| // 定义options对象
| const options = {
| state,
| actions: {
| getEditor,
| setEditor,
| getEID,
| setEID,
| getFormats,
| setFormats,
| getReadOnly,
| setReadOnly,
| destroy
| }
| }
|
| // 导出
| export default options
|
|