vue-page-store 0.4.0 → 0.4.1
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.
- package/README.md +84 -17
- package/dist/index.cjs.js +15 -4
- package/dist/index.d.ts +10 -1
- package/dist/index.esm.js +15 -4
- package/dist/index.umd.js +15 -4
- package/dist/index.umd.min.js +8 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# vue-page-store
|
|
2
2
|
|
|
3
|
-
> Vue 2.6 页面级作用域运行时容器 —— source、state、getters、actions、watch、enter/leave,一个页面作用域全收。
|
|
3
|
+
> Vue 2.6 页面级作用域运行时容器 —— source、state、getters、actions、watch、init/enter/leave,一个页面作用域全收。
|
|
4
4
|
|
|
5
5
|
## 它是什么
|
|
6
6
|
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- **getters** — 派生计算
|
|
14
14
|
- **actions** — 业务逻辑
|
|
15
15
|
- **watch** — 声明式副作用
|
|
16
|
+
- **init** — 一次性初始化(拉字典、注册事件监听等)
|
|
16
17
|
- **enter / leave** — 页面可见性生命周期
|
|
17
18
|
- **$setInterval** — 页面级定时器托管
|
|
18
19
|
- **event bus** — 页面内作用域通信
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
## 它不是什么
|
|
23
24
|
|
|
24
25
|
- **不是 Vuex / Pinia 替代品** — 全局状态(用户信息、权限、路由)请继续用 Vuex / Pinia
|
|
25
|
-
- **不是全局状态管理方案** —
|
|
26
|
+
- **不是全局状态管理方案** — 它的作用域是"页面",不是"应用"
|
|
26
27
|
- **不是大而全的框架** — 它只解决复杂页面的页面层状态编排
|
|
27
28
|
|
|
28
29
|
| | Vuex / Pinia | vue-page-store |
|
|
@@ -109,6 +110,13 @@ export const useOrderStore = definePageStore('orderList', {
|
|
|
109
110
|
}
|
|
110
111
|
},
|
|
111
112
|
|
|
113
|
+
// 只执行一次:拉下拉框选项、注册事件监听等
|
|
114
|
+
init() {
|
|
115
|
+
this.loadDictOptions()
|
|
116
|
+
this.$on('child:refresh', () => this.search())
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// 每次页面可见时执行
|
|
112
120
|
enter() {
|
|
113
121
|
this.$source.query = this.$vm.$route.query
|
|
114
122
|
this.search()
|
|
@@ -129,7 +137,7 @@ import { useOrderStore } from './stores/order-list'
|
|
|
129
137
|
|
|
130
138
|
export default {
|
|
131
139
|
created() {
|
|
132
|
-
// 传入 this → 自动绑定 enter/leave + 自动 provide + 页面销毁时自动回收
|
|
140
|
+
// 传入 this → 自动绑定 init/enter/leave + 自动 provide + 页面销毁时自动回收
|
|
133
141
|
this.pageStore = useOrderStore(this)
|
|
134
142
|
}
|
|
135
143
|
}
|
|
@@ -165,6 +173,7 @@ export default {
|
|
|
165
173
|
| `getters` | `{ [key]: function }` | 派生计算,`this` 指向 store |
|
|
166
174
|
| `actions` | `{ [key]: function }` | 业务方法,`this` 指向 store |
|
|
167
175
|
| `watch` | `{ [path]: handler \| options }` | 声明式 watcher,支持 dot-path |
|
|
176
|
+
| `init` | `function` | store 创建后一次性调用,`$vm` 已可用。适合拉字典、注册事件监听 |
|
|
168
177
|
| `enter` | `function` | 页面进入可见 / 可交互状态时触发 |
|
|
169
178
|
| `leave` | `function` | 页面离开可见 / 可交互状态时触发 |
|
|
170
179
|
|
|
@@ -207,7 +216,7 @@ watch: {
|
|
|
207
216
|
|
|
208
217
|
## source 与 state
|
|
209
218
|
|
|
210
|
-
v0.4 引入了 `source
|
|
219
|
+
v0.4 引入了 `source`,用于把"页面输入 / 原始返回"和"业务状态"分开。
|
|
211
220
|
|
|
212
221
|
### 推荐分工
|
|
213
222
|
|
|
@@ -233,15 +242,53 @@ state: () => ({
|
|
|
233
242
|
- getters 可以同时基于 `this.$source` 和 `this.xxx` 计算
|
|
234
243
|
- `$reset()` 时 source / state 一起恢复,更清晰
|
|
235
244
|
|
|
236
|
-
## enter / leave
|
|
245
|
+
## init / enter / leave
|
|
237
246
|
|
|
238
247
|
v0.4 用 `enter / leave` 替换了 v0.3 的 `lifecycle.mount / unmount / activate / deactivate`。
|
|
239
248
|
|
|
249
|
+
v0.4.1 新增 `init`,用于 store 创建后的一次性初始化。
|
|
250
|
+
|
|
240
251
|
### 语义
|
|
241
252
|
|
|
253
|
+
- **init**:store 创建后一次性调用,`$vm` 已可用,DOM 未就绪
|
|
242
254
|
- **enter**:页面进入可见 / 可交互状态
|
|
243
255
|
- **leave**:页面离开可见 / 可交互状态
|
|
244
256
|
|
|
257
|
+
### 执行时序
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
created() 开始
|
|
261
|
+
└→ useStore(this)
|
|
262
|
+
└→ createStoreInstance() ← state/source/getters/actions 就绪
|
|
263
|
+
└→ bindTo(this) ← $vm 赋值
|
|
264
|
+
└→ ★ init() ← $vm 可用,只执行一次
|
|
265
|
+
└→ created() 剩余代码
|
|
266
|
+
mounted()
|
|
267
|
+
└→ ★ enter() ← DOM 就绪,每次可见都执行
|
|
268
|
+
|
|
269
|
+
--- keep-alive 切走 ---
|
|
270
|
+
deactivated()
|
|
271
|
+
└→ clearAllIntervals()
|
|
272
|
+
└→ ★ leave()
|
|
273
|
+
|
|
274
|
+
--- keep-alive 切回 ---
|
|
275
|
+
activated()
|
|
276
|
+
└→ ★ enter() ← 重新开轮询、刷数据
|
|
277
|
+
|
|
278
|
+
--- 页面销毁 ---
|
|
279
|
+
beforeDestroy()
|
|
280
|
+
└→ ★ leave()(如果还没 leave)
|
|
281
|
+
└→ $destroy()
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### 分工原则
|
|
285
|
+
|
|
286
|
+
| 钩子 | 执行次数 | $vm | DOM | 典型场景 |
|
|
287
|
+
|---|---|---|---|---|
|
|
288
|
+
| `init` | 一次 | ✅ | ❌ | 拉下拉框选项、注册事件监听、从 localStorage 恢复配置、初始化 WebSocket |
|
|
289
|
+
| `enter` | 每次可见 | ✅ | ✅ | 读路由参数、刷列表数据、开轮询 |
|
|
290
|
+
| `leave` | 每次离开 | ✅ | ✅ | 通常不需要写,interval 已自动清理 |
|
|
291
|
+
|
|
245
292
|
### keep-alive 行为
|
|
246
293
|
|
|
247
294
|
- 首次 `mounted` → `enter`
|
|
@@ -249,14 +296,26 @@ v0.4 用 `enter / leave` 替换了 v0.3 的 `lifecycle.mount / unmount / activat
|
|
|
249
296
|
- `deactivated` → `leave`
|
|
250
297
|
- `beforeDestroy` → 如果当前还没 leave,先 leave,再 `$destroy`
|
|
251
298
|
|
|
252
|
-
### 适合放在
|
|
299
|
+
### 适合放在 init 里的逻辑
|
|
253
300
|
|
|
254
|
-
-
|
|
255
|
-
-
|
|
301
|
+
- 拉下拉框 / 字典选项(只需要一次)
|
|
302
|
+
- 注册 `$on` 监听 store 内部事件
|
|
303
|
+
- 从 localStorage 恢复上次的筛选条件
|
|
304
|
+
- 初始化 WebSocket / EventSource 连接
|
|
305
|
+
- 根据用户权限裁剪 columns / 按钮配置
|
|
306
|
+
|
|
307
|
+
### 适合放在 enter 里的逻辑
|
|
308
|
+
|
|
309
|
+
- 根据 `$route` 初始化 source / state(keep-alive 切回时路由参数可能变了)
|
|
310
|
+
- 首屏加载 / 刷新列表数据
|
|
256
311
|
- 启动页面轮询
|
|
257
|
-
- 页面离开时做收尾逻辑
|
|
258
312
|
|
|
259
313
|
```js
|
|
314
|
+
init() {
|
|
315
|
+
this.loadDictOptions()
|
|
316
|
+
this.$on('child:refresh', () => this.search())
|
|
317
|
+
},
|
|
318
|
+
|
|
260
319
|
enter() {
|
|
261
320
|
this.$source.query = this.$vm.$route.query
|
|
262
321
|
this.search()
|
|
@@ -385,7 +444,7 @@ state: () => ({
|
|
|
385
444
|
- 仪表盘页面 —— 多模块共享筛选条件、加载状态
|
|
386
445
|
- 漏斗 / 留存等分析详情页 —— 复杂交互 + 异步数据 + 页面可见性管理
|
|
387
446
|
- 大型配置页 —— 多 tab / 多步骤表单的状态统一管理
|
|
388
|
-
- keep-alive 业务页 —— 需要 enter / leave 感知的页面
|
|
447
|
+
- keep-alive 业务页 —— 需要 init / enter / leave 感知的页面
|
|
389
448
|
- 微前端子应用 —— 页面作用域隔离,不污染宿主全局状态
|
|
390
449
|
|
|
391
450
|
## 不适用场景
|
|
@@ -427,7 +486,7 @@ storeRegistry.forEach((store, id) => {
|
|
|
427
486
|
|
|
428
487
|
### Breaking Changes
|
|
429
488
|
|
|
430
|
-
**1. `lifecycle` 被移除,改为 `enter / leave`**
|
|
489
|
+
**1. `lifecycle` 被移除,改为 `init` / `enter` / `leave`**
|
|
431
490
|
|
|
432
491
|
v0.3.x:
|
|
433
492
|
|
|
@@ -440,16 +499,23 @@ lifecycle: {
|
|
|
440
499
|
}
|
|
441
500
|
```
|
|
442
501
|
|
|
443
|
-
v0.4.
|
|
502
|
+
v0.4.x:
|
|
444
503
|
|
|
445
504
|
```js
|
|
446
|
-
|
|
447
|
-
|
|
505
|
+
init() {
|
|
506
|
+
// 只执行一次的初始化(拉字典、注册事件等)
|
|
507
|
+
},
|
|
508
|
+
enter() {
|
|
509
|
+
// 每次可见时执行(替代 mount + activate)
|
|
510
|
+
},
|
|
511
|
+
leave() {
|
|
512
|
+
// 每次离开时执行(替代 deactivate + unmount)
|
|
513
|
+
}
|
|
448
514
|
```
|
|
449
515
|
|
|
450
516
|
迁移关系:
|
|
451
517
|
|
|
452
|
-
- `lifecycle.mount` → `enter`
|
|
518
|
+
- `lifecycle.mount` → `enter`(如果包含一次性逻辑,拆到 `init`)
|
|
453
519
|
- `lifecycle.unmount` → `leave`
|
|
454
520
|
- `lifecycle.activate` → `enter`
|
|
455
521
|
- `lifecycle.deactivate` → `leave`
|
|
@@ -465,10 +531,11 @@ v0.4.0 中:
|
|
|
465
531
|
### New Features
|
|
466
532
|
|
|
467
533
|
- `source`:页面输入 / 原始返回与业务状态分离
|
|
534
|
+
- `init`:store 创建后一次性钩子,`$vm` 已可用(v0.4.1)
|
|
468
535
|
- `enter / leave`:更简单的页面可见性生命周期
|
|
469
536
|
- `$setInterval()`:页面级 interval 托管
|
|
470
537
|
- `$loading.xxx`:返回 Promise 的 action 自动追踪 loading
|
|
471
|
-
- `$vm`:只读逃生口,可在 enter 中访问 `$route / $router`
|
|
538
|
+
- `$vm`:只读逃生口,可在 init / enter 中访问 `$route / $router`
|
|
472
539
|
|
|
473
540
|
## Roadmap
|
|
474
541
|
|
|
@@ -478,4 +545,4 @@ v0.4.0 中:
|
|
|
478
545
|
|
|
479
546
|
## License
|
|
480
547
|
|
|
481
|
-
MIT © weijianjun
|
|
548
|
+
MIT © weijianjun
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-page-store v0.4.
|
|
2
|
+
* vue-page-store v0.4.1
|
|
3
3
|
* (c) 2026 weijianjun
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
9
|
|
|
10
10
|
/*!
|
|
11
|
-
* vue-page-store v0.4.
|
|
11
|
+
* vue-page-store v0.4.1
|
|
12
12
|
* (c) 2026 weijianjun
|
|
13
13
|
* @license MIT
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
|
-
* vue-page-store 0.4.
|
|
16
|
+
* vue-page-store 0.4.1 — Vue 2.6 Page Scope Runtime
|
|
17
17
|
*
|
|
18
18
|
* 页面级作用域运行时容器:
|
|
19
|
-
* source · state · getters · actions · watch · enter/leave · $setInterval · event bus
|
|
19
|
+
* source · state · getters · actions · watch · init/enter/leave · $setInterval · event bus
|
|
20
20
|
*
|
|
21
21
|
* v0.4 新增:
|
|
22
22
|
* source → 页面输入 / 原始返回,和业务 state 分开
|
|
@@ -24,6 +24,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
24
24
|
* $setInterval → 页面级 timer 托管,leave 时自动清理
|
|
25
25
|
* $loading → async action 自动追踪 loading 状态
|
|
26
26
|
*
|
|
27
|
+
* v0.4.1 新增:
|
|
28
|
+
* init → store 创建后一次性初始化钩子,$vm 已可用
|
|
29
|
+
*
|
|
27
30
|
* @author weijianjun
|
|
28
31
|
* @license MIT
|
|
29
32
|
*/
|
|
@@ -428,6 +431,8 @@ function createStoreInstance(Vue, id, options) {
|
|
|
428
431
|
* - options 新增 source、enter、leave
|
|
429
432
|
* - options 移除 lifecycle
|
|
430
433
|
* - actions 中的 async 函数自动追踪 $loading
|
|
434
|
+
* v0.4.1 变更:
|
|
435
|
+
* - options 新增 init(bindTo 之后一次性调用)
|
|
431
436
|
*/
|
|
432
437
|
function definePageStore(id, options) {
|
|
433
438
|
// 入参校验
|
|
@@ -461,6 +466,12 @@ function definePageStore(id, options) {
|
|
|
461
466
|
var store = createStoreInstance(_Vue, id, options);
|
|
462
467
|
storeRegistry.set(id, store);
|
|
463
468
|
if (componentVm) store.bindTo(componentVm);
|
|
469
|
+
|
|
470
|
+
// v0.4.1 新增:init 钩子 —— bindTo 之后调用,$vm 已可用
|
|
471
|
+
if (typeof options.init === 'function') {
|
|
472
|
+
options.init.call(store);
|
|
473
|
+
}
|
|
474
|
+
|
|
464
475
|
return store;
|
|
465
476
|
};
|
|
466
477
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vue-page-store v0.4.
|
|
2
|
+
* vue-page-store v0.4.1 - TypeScript 类型定义
|
|
3
3
|
*
|
|
4
4
|
* Page Scope Runtime for Vue 2.6
|
|
5
5
|
*/
|
|
@@ -49,6 +49,13 @@ export interface StoreOptions<
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* store 创建后一次性调用(v0.4.1 新增)
|
|
54
|
+
* bindTo 之后调用,$vm 已可用
|
|
55
|
+
* 适合拉字典、注册事件监听、从 localStorage 恢复配置、初始化 WebSocket
|
|
56
|
+
*/
|
|
57
|
+
init?: (this: PageStore<S, Src>) => void;
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* 页面进入可见/可交互状态(v0.4 新增,替换 v0.3 lifecycle)
|
|
54
61
|
* keep-alive 切回时也会触发
|
|
@@ -129,6 +136,8 @@ export type PageStore<
|
|
|
129
136
|
* - options 新增 source、enter、leave
|
|
130
137
|
* - options 移除 lifecycle(breaking change)
|
|
131
138
|
* - async action 自动追踪 $loading
|
|
139
|
+
* v0.4.1 变更:
|
|
140
|
+
* - options 新增 init(bindTo 之后一次性调用)
|
|
132
141
|
*/
|
|
133
142
|
export declare function definePageStore<
|
|
134
143
|
S extends Record<string, any>,
|
package/dist/index.esm.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-page-store v0.4.
|
|
2
|
+
* vue-page-store v0.4.1
|
|
3
3
|
* (c) 2026 weijianjun
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
/*!
|
|
7
|
-
* vue-page-store v0.4.
|
|
7
|
+
* vue-page-store v0.4.1
|
|
8
8
|
* (c) 2026 weijianjun
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
|
-
* vue-page-store 0.4.
|
|
12
|
+
* vue-page-store 0.4.1 — Vue 2.6 Page Scope Runtime
|
|
13
13
|
*
|
|
14
14
|
* 页面级作用域运行时容器:
|
|
15
|
-
* source · state · getters · actions · watch · enter/leave · $setInterval · event bus
|
|
15
|
+
* source · state · getters · actions · watch · init/enter/leave · $setInterval · event bus
|
|
16
16
|
*
|
|
17
17
|
* v0.4 新增:
|
|
18
18
|
* source → 页面输入 / 原始返回,和业务 state 分开
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* $setInterval → 页面级 timer 托管,leave 时自动清理
|
|
21
21
|
* $loading → async action 自动追踪 loading 状态
|
|
22
22
|
*
|
|
23
|
+
* v0.4.1 新增:
|
|
24
|
+
* init → store 创建后一次性初始化钩子,$vm 已可用
|
|
25
|
+
*
|
|
23
26
|
* @author weijianjun
|
|
24
27
|
* @license MIT
|
|
25
28
|
*/
|
|
@@ -424,6 +427,8 @@ function createStoreInstance(Vue, id, options) {
|
|
|
424
427
|
* - options 新增 source、enter、leave
|
|
425
428
|
* - options 移除 lifecycle
|
|
426
429
|
* - actions 中的 async 函数自动追踪 $loading
|
|
430
|
+
* v0.4.1 变更:
|
|
431
|
+
* - options 新增 init(bindTo 之后一次性调用)
|
|
427
432
|
*/
|
|
428
433
|
function definePageStore(id, options) {
|
|
429
434
|
// 入参校验
|
|
@@ -457,6 +462,12 @@ function definePageStore(id, options) {
|
|
|
457
462
|
var store = createStoreInstance(_Vue, id, options);
|
|
458
463
|
storeRegistry.set(id, store);
|
|
459
464
|
if (componentVm) store.bindTo(componentVm);
|
|
465
|
+
|
|
466
|
+
// v0.4.1 新增:init 钩子 —— bindTo 之后调用,$vm 已可用
|
|
467
|
+
if (typeof options.init === 'function') {
|
|
468
|
+
options.init.call(store);
|
|
469
|
+
}
|
|
470
|
+
|
|
460
471
|
return store;
|
|
461
472
|
};
|
|
462
473
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-page-store v0.4.
|
|
2
|
+
* vue-page-store v0.4.1
|
|
3
3
|
* (c) 2026 weijianjun
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
})(this, (function (exports) { 'use strict';
|
|
11
11
|
|
|
12
12
|
/*!
|
|
13
|
-
* vue-page-store v0.4.
|
|
13
|
+
* vue-page-store v0.4.1
|
|
14
14
|
* (c) 2026 weijianjun
|
|
15
15
|
* @license MIT
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
-
* vue-page-store 0.4.
|
|
18
|
+
* vue-page-store 0.4.1 — Vue 2.6 Page Scope Runtime
|
|
19
19
|
*
|
|
20
20
|
* 页面级作用域运行时容器:
|
|
21
|
-
* source · state · getters · actions · watch · enter/leave · $setInterval · event bus
|
|
21
|
+
* source · state · getters · actions · watch · init/enter/leave · $setInterval · event bus
|
|
22
22
|
*
|
|
23
23
|
* v0.4 新增:
|
|
24
24
|
* source → 页面输入 / 原始返回,和业务 state 分开
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
* $setInterval → 页面级 timer 托管,leave 时自动清理
|
|
27
27
|
* $loading → async action 自动追踪 loading 状态
|
|
28
28
|
*
|
|
29
|
+
* v0.4.1 新增:
|
|
30
|
+
* init → store 创建后一次性初始化钩子,$vm 已可用
|
|
31
|
+
*
|
|
29
32
|
* @author weijianjun
|
|
30
33
|
* @license MIT
|
|
31
34
|
*/
|
|
@@ -430,6 +433,8 @@
|
|
|
430
433
|
* - options 新增 source、enter、leave
|
|
431
434
|
* - options 移除 lifecycle
|
|
432
435
|
* - actions 中的 async 函数自动追踪 $loading
|
|
436
|
+
* v0.4.1 变更:
|
|
437
|
+
* - options 新增 init(bindTo 之后一次性调用)
|
|
433
438
|
*/
|
|
434
439
|
function definePageStore(id, options) {
|
|
435
440
|
// 入参校验
|
|
@@ -463,6 +468,12 @@
|
|
|
463
468
|
var store = createStoreInstance(_Vue, id, options);
|
|
464
469
|
storeRegistry.set(id, store);
|
|
465
470
|
if (componentVm) store.bindTo(componentVm);
|
|
471
|
+
|
|
472
|
+
// v0.4.1 新增:init 钩子 —— bindTo 之后调用,$vm 已可用
|
|
473
|
+
if (typeof options.init === 'function') {
|
|
474
|
+
options.init.call(store);
|
|
475
|
+
}
|
|
476
|
+
|
|
466
477
|
return store;
|
|
467
478
|
};
|
|
468
479
|
}
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-page-store v0.4.
|
|
2
|
+
* vue-page-store v0.4.1
|
|
3
3
|
* (c) 2026 weijianjun
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VuePageStore={})}(this,function(e){"use strict";
|
|
7
7
|
/*!
|
|
8
|
-
* vue-page-store v0.4.
|
|
8
|
+
* vue-page-store v0.4.1
|
|
9
9
|
* (c) 2026 weijianjun
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
|
-
* vue-page-store 0.4.
|
|
13
|
+
* vue-page-store 0.4.1 — Vue 2.6 Page Scope Runtime
|
|
14
14
|
*
|
|
15
15
|
* 页面级作用域运行时容器:
|
|
16
|
-
* source · state · getters · actions · watch · enter/leave · $setInterval · event bus
|
|
16
|
+
* source · state · getters · actions · watch · init/enter/leave · $setInterval · event bus
|
|
17
17
|
*
|
|
18
18
|
* v0.4 新增:
|
|
19
19
|
* source → 页面输入 / 原始返回,和业务 state 分开
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
* $setInterval → 页面级 timer 托管,leave 时自动清理
|
|
22
22
|
* $loading → async action 自动追踪 loading 状态
|
|
23
23
|
*
|
|
24
|
+
* v0.4.1 新增:
|
|
25
|
+
* init → store 创建后一次性初始化钩子,$vm 已可用
|
|
26
|
+
*
|
|
24
27
|
* @author weijianjun
|
|
25
28
|
* @license MIT
|
|
26
|
-
*/var t=new Map,n="undefined"!=typeof process&&process.env&&"production"!==process.env.NODE_ENV;function o(e){n&&console.warn("[vue-page-store] "+e)}function r(e,n,r){var i=r.state(),c="function"==typeof r.source?r.source():{},u=r.getters||{},f=r.actions||{},a="function"==typeof r.enter?r.enter:null,s="function"==typeof r.leave?r.leave:null,d={},l={$disposed:!1};Object.keys(u).forEach(function(e){d[e]=function(){return u[e].call(l)}});var p=new e({data:function(){return{$$state:i,$$source:c,$$loading:{},$$status:{mounted:!1,active:!1}}},computed:d}),v=p.$data.$$state,$=p.$data.$$source,h=p.$data.$$loading,y=p.$data.$$status;Object.keys(i).forEach(function(e){Object.defineProperty(l,e,{enumerable:!0,configurable:!0,get:function(){return v[e]},set:function(t){l.$disposed?o('store "'+n+'" 已销毁,忽略对 "'+e+'" 的写入'):v[e]=t}})}),l.$source=$,l.$loading=h,Object.keys(u).forEach(function(e){Object.defineProperty(l,e,{enumerable:!0,get:function(){return p[e]}})});var b={};function g(t){b[t]--,b[t]<=0&&(b[t]=0,e.set(h,t,!1))}Object.keys(f).forEach(function(t){var n=f[t].bind(l);l[t]=function(){var o=n.apply(null,arguments);o&&"function"==typeof o.then&&(b[t]||(b[t]=0),b[t]++,e.set(h,t,!0),Promise.resolve(o).then(function(){g(t)},function(){g(t)}));return o}});var m=r.watch||{};Object.entries(m).forEach(function(e){var t,r,i=e[0],c=e[1];if("function"==typeof c)t=c,r={};else if(t=c.handler,r={},c.deep&&(r.deep=!0),c.immediate&&(r.immediate=!0),!t)return void o('watch "'+i+'" in store "'+n+'" 缺少 handler,该 watcher 将被跳过');p.$watch(function(){return i.split(".").reduce(function(e,t){return e&&e[t]},l)},t.bind(l),r)}),l.$state=v,l.$status=y,l.$id=n;var O=null;Object.defineProperty(l,"$vm",{enumerable:!0,configurable:!1,get:function(){return O},set:function(){o("$vm 是只读属性,不允许业务侧重写")}}),l.$patch=function(t){if(l.$disposed)o('store "'+n+'" 已销毁,忽略 $patch 操作');else{var r="function"==typeof t?t(v):t;Object.keys(r).forEach(function(t){e.set(v,t,r[t])})}},l.$reset=function(){var t=r.state();Object.keys(t).forEach(function(n){e.set(v,n,t[n])}),Object.keys(v).forEach(function(n){n in t||e.delete(v,n)});var n="function"==typeof r.source?r.source():{};Object.keys(n).forEach(function(t){e.set($,t,n[t])}),Object.keys($).forEach(function(t){t in n||e.delete($,t)})};var E={};l.$emit=function(e,t){var n=E[e];n&&n.slice().forEach(function(e){e(t)})},l.$on=function(e,t){return E[e]||(E[e]=[]),E[e].push(t),function(){if(E[e]){var n=E[e].indexOf(t);n>-1&&E[e].splice(n,1)}}},l.$off=function(e,t){if(E[e])if(t){var n=E[e].indexOf(t);n>-1&&E[e].splice(n,1)}else delete E[e]};var j=[];function k(){j.forEach(function(e){e.stopped||(clearInterval(e.id),e.stopped=!0)}),j.length=0}l.$setInterval=function(e,t){var n={id:setInterval(e,t),stopped:!1};j.push(n);return function(){if(!n.stopped){clearInterval(n.id),n.stopped=!0;var e=j.indexOf(n);e>-1&&j.splice(e,1)}}};var w=!1;function P(){w||(w=!0,y.mounted=!0,y.active=!0,a&&a.call(l),l.$emit("page:enter"))}function S(){w&&(k(),w=!1,y.active=!1,s&&s.call(l),l.$emit("page:leave"))}var x="undefined"!=typeof WeakSet?new WeakSet:null,_=x?null:[];return l.bindTo=function(e){return l.$disposed||function(e){return x?x.has(e):_.indexOf(e)>-1}(e)||(function(e){x?x.add(e):_.push(e)}(e),O=e,(e._provided||(e._provided={})).pageStore=l,e.$on("hook:mounted",function(){P()}),e.$on("hook:activated",function(){P()}),e.$on("hook:deactivated",function(){S()}),e.$on("hook:beforeDestroy",function(){S(),l.$destroy()})),l},l.$destroy=function(){l.$disposed||(y.mounted=!1,y.active=!1,k(),l.$disposed=!0,Object.keys(E).forEach(function(e){delete E[e]}),p.$destroy(),t.delete(n))},l._vm=p,l}function i(e,n){if(!e||"string"!=typeof e)throw new Error("[vue-page-store] definePageStore 需要一个非空字符串作为 id");if(!n||"function"!=typeof n.state)throw new Error('[vue-page-store] definePageStore("'+e+'") 需要 state 为函数');var o=null;return function(i){if(t.has(e)){var c=t.get(e);return i&&c.bindTo(i),c}if(!o)try{(o=require("vue")).default&&(o=o.default)}catch(e){throw new Error("[vue-page-store] 无法自动获取 Vue,请确保 vue 已安装")}var u=r(o,e,n);return t.set(e,u),i&&u.bindTo(i),u}}var c={definePageStore:i,storeRegistry:t};e.default=c,e.definePageStore=i,e.storeRegistry=t,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
29
|
+
*/var t=new Map,n="undefined"!=typeof process&&process.env&&"production"!==process.env.NODE_ENV;function o(e){n&&console.warn("[vue-page-store] "+e)}function r(e,n,r){var i=r.state(),c="function"==typeof r.source?r.source():{},u=r.getters||{},f=r.actions||{},a="function"==typeof r.enter?r.enter:null,s="function"==typeof r.leave?r.leave:null,d={},l={$disposed:!1};Object.keys(u).forEach(function(e){d[e]=function(){return u[e].call(l)}});var p=new e({data:function(){return{$$state:i,$$source:c,$$loading:{},$$status:{mounted:!1,active:!1}}},computed:d}),v=p.$data.$$state,$=p.$data.$$source,h=p.$data.$$loading,y=p.$data.$$status;Object.keys(i).forEach(function(e){Object.defineProperty(l,e,{enumerable:!0,configurable:!0,get:function(){return v[e]},set:function(t){l.$disposed?o('store "'+n+'" 已销毁,忽略对 "'+e+'" 的写入'):v[e]=t}})}),l.$source=$,l.$loading=h,Object.keys(u).forEach(function(e){Object.defineProperty(l,e,{enumerable:!0,get:function(){return p[e]}})});var b={};function g(t){b[t]--,b[t]<=0&&(b[t]=0,e.set(h,t,!1))}Object.keys(f).forEach(function(t){var n=f[t].bind(l);l[t]=function(){var o=n.apply(null,arguments);o&&"function"==typeof o.then&&(b[t]||(b[t]=0),b[t]++,e.set(h,t,!0),Promise.resolve(o).then(function(){g(t)},function(){g(t)}));return o}});var m=r.watch||{};Object.entries(m).forEach(function(e){var t,r,i=e[0],c=e[1];if("function"==typeof c)t=c,r={};else if(t=c.handler,r={},c.deep&&(r.deep=!0),c.immediate&&(r.immediate=!0),!t)return void o('watch "'+i+'" in store "'+n+'" 缺少 handler,该 watcher 将被跳过');p.$watch(function(){return i.split(".").reduce(function(e,t){return e&&e[t]},l)},t.bind(l),r)}),l.$state=v,l.$status=y,l.$id=n;var O=null;Object.defineProperty(l,"$vm",{enumerable:!0,configurable:!1,get:function(){return O},set:function(){o("$vm 是只读属性,不允许业务侧重写")}}),l.$patch=function(t){if(l.$disposed)o('store "'+n+'" 已销毁,忽略 $patch 操作');else{var r="function"==typeof t?t(v):t;Object.keys(r).forEach(function(t){e.set(v,t,r[t])})}},l.$reset=function(){var t=r.state();Object.keys(t).forEach(function(n){e.set(v,n,t[n])}),Object.keys(v).forEach(function(n){n in t||e.delete(v,n)});var n="function"==typeof r.source?r.source():{};Object.keys(n).forEach(function(t){e.set($,t,n[t])}),Object.keys($).forEach(function(t){t in n||e.delete($,t)})};var E={};l.$emit=function(e,t){var n=E[e];n&&n.slice().forEach(function(e){e(t)})},l.$on=function(e,t){return E[e]||(E[e]=[]),E[e].push(t),function(){if(E[e]){var n=E[e].indexOf(t);n>-1&&E[e].splice(n,1)}}},l.$off=function(e,t){if(E[e])if(t){var n=E[e].indexOf(t);n>-1&&E[e].splice(n,1)}else delete E[e]};var j=[];function k(){j.forEach(function(e){e.stopped||(clearInterval(e.id),e.stopped=!0)}),j.length=0}l.$setInterval=function(e,t){var n={id:setInterval(e,t),stopped:!1};j.push(n);return function(){if(!n.stopped){clearInterval(n.id),n.stopped=!0;var e=j.indexOf(n);e>-1&&j.splice(e,1)}}};var w=!1;function P(){w||(w=!0,y.mounted=!0,y.active=!0,a&&a.call(l),l.$emit("page:enter"))}function S(){w&&(k(),w=!1,y.active=!1,s&&s.call(l),l.$emit("page:leave"))}var x="undefined"!=typeof WeakSet?new WeakSet:null,_=x?null:[];return l.bindTo=function(e){return l.$disposed||function(e){return x?x.has(e):_.indexOf(e)>-1}(e)||(function(e){x?x.add(e):_.push(e)}(e),O=e,(e._provided||(e._provided={})).pageStore=l,e.$on("hook:mounted",function(){P()}),e.$on("hook:activated",function(){P()}),e.$on("hook:deactivated",function(){S()}),e.$on("hook:beforeDestroy",function(){S(),l.$destroy()})),l},l.$destroy=function(){l.$disposed||(y.mounted=!1,y.active=!1,k(),l.$disposed=!0,Object.keys(E).forEach(function(e){delete E[e]}),p.$destroy(),t.delete(n))},l._vm=p,l}function i(e,n){if(!e||"string"!=typeof e)throw new Error("[vue-page-store] definePageStore 需要一个非空字符串作为 id");if(!n||"function"!=typeof n.state)throw new Error('[vue-page-store] definePageStore("'+e+'") 需要 state 为函数');var o=null;return function(i){if(t.has(e)){var c=t.get(e);return i&&c.bindTo(i),c}if(!o)try{(o=require("vue")).default&&(o=o.default)}catch(e){throw new Error("[vue-page-store] 无法自动获取 Vue,请确保 vue 已安装")}var u=r(o,e,n);return t.set(e,u),i&&u.bindTo(i),"function"==typeof n.init&&n.init.call(u),u}}var c={definePageStore:i,storeRegistry:t};e.default=c,e.definePageStore=i,e.storeRegistry=t,Object.defineProperty(e,"__esModule",{value:!0})});
|