udxcms 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +53 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -105,46 +105,69 @@ export function init({ Vue, router, store, Parent, onComponentsRegistered, onRou
105
105
  console.log(`模块结构 - state:`, !!actualModule.state, 'mutations:', !!actualModule.mutations, 'actions:', !!actualModule.actions);
106
106
  if (actualModule.state || actualModule.mutations || actualModule.actions) {
107
107
  console.log(`注册模块 ${v} 成功`);
108
- // 特殊处理 CmsStore - 将其内容合并到根 store
108
+ // 特殊处理 CmsStore - 直接合并到根 store
109
109
  if (v === 'CmsStore') {
110
- console.log('将 CmsStore 合并到根 store');
111
- // 1. 首先注册 state 到根级别
110
+ console.log('将 CmsStore 直接合并到根 store');
111
+ // 1. 直接修改根 state 来添加 cms 命名空间
112
112
  if (actualModule.state) {
113
- store.registerModule(['cmsState'], {
114
- state: actualModule.state,
115
- namespaced: false
113
+ if (!store.state.cms) {
114
+ store.state.cms = {};
115
+ }
116
+ Object.keys(actualModule.state).forEach(key => {
117
+ store.state.cms[key] = actualModule.state[key];
116
118
  });
117
119
  }
118
- // 2. 注册 mutations 到根级别
120
+ // 2. 直接修改 store._mutations 来添加根级别 mutations
119
121
  if (actualModule.mutations) {
120
- const rootMutations = {};
121
- Object.keys(actualModule.mutations).forEach(key => {
122
- rootMutations[key] = function (rootState, payload) {
123
- // 确保调用时传入正确的模块状态
124
- const moduleState = rootState.cmsState || actualModule.state;
125
- return actualModule.mutations[key](moduleState, payload);
126
- };
127
- });
128
- // 临时注册来获取 mutations
129
- store.registerModule(['__temp__'], {
130
- mutations: rootMutations
122
+ console.log('添加根级别 mutations:', Object.keys(actualModule.mutations));
123
+ console.log('当前 store._mutations:', Object.keys(store._mutations));
124
+ Object.keys(actualModule.mutations).forEach(mutationName => {
125
+ if (!store._mutations[mutationName]) {
126
+ store._mutations[mutationName] = [];
127
+ }
128
+ // 添加 mutation 处理器
129
+ store._mutations[mutationName].push(function (payload) {
130
+ // 获取当前模块状态
131
+ const moduleState = store.state.cms || actualModule.state;
132
+ // 调用原始 mutation
133
+ return actualModule.mutations[mutationName](moduleState, payload);
134
+ });
135
+ console.log(`已注册 mutation: ${mutationName}`);
131
136
  });
132
- store.unregisterModule(['__temp__']);
137
+ console.log('注册后的 store._mutations:', Object.keys(store._mutations));
133
138
  }
134
- // 3. 注册 actions 到根级别
139
+ // 3. 直接修改 store._actions 来添加根级别 actions
135
140
  if (actualModule.actions) {
136
- const rootActions = {};
137
- Object.keys(actualModule.actions).forEach(key => {
138
- rootActions[key] = function (context, payload) {
139
- // 创建一个新的 context,指向模块状态
140
- const moduleContext = Object.assign(Object.assign({}, context), { state: context.state.cmsState || actualModule.state, commit: context.commit, dispatch: context.dispatch, getters: context.getters, rootState: context.rootState, rootGetters: context.rootGetters });
141
- return actualModule.actions[key](moduleContext, payload);
142
- };
141
+ console.log('添加根级别 actions:', Object.keys(actualModule.actions));
142
+ Object.keys(actualModule.actions).forEach(actionName => {
143
+ if (!store._actions[actionName]) {
144
+ store._actions[actionName] = [];
145
+ }
146
+ // 添加 action 处理器
147
+ store._actions[actionName].push(function (payload) {
148
+ // 创建正确的 context
149
+ const context = {
150
+ state: store.state.cms || actualModule.state,
151
+ rootState: store.state,
152
+ commit: store.commit,
153
+ dispatch: store.dispatch,
154
+ getters: store.getters,
155
+ rootGetters: store.getters
156
+ };
157
+ // 调用原始 action
158
+ return actualModule.actions[actionName](context, payload);
159
+ });
143
160
  });
144
- store.registerModule(['__temp__'], {
145
- actions: rootActions
161
+ }
162
+ // 4. 直接修改 store._wrappedGetters 来添加根级别 getters
163
+ if (actualModule.getters) {
164
+ console.log('添加根级别 getters:', Object.keys(actualModule.getters));
165
+ Object.keys(actualModule.getters).forEach(getterName => {
166
+ store._wrappedGetters[getterName] = function () {
167
+ const moduleState = store.state.cms || actualModule.state;
168
+ return actualModule.getters[getterName](moduleState, store.getters, store.state, store.getters);
169
+ };
146
170
  });
147
- store.unregisterModule(['__temp__']);
148
171
  }
149
172
  }
150
173
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "udxcms",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "cms submodule",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",