wevu 6.7.2 → 6.7.4
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/dist/api.d.mts +1 -0
- package/dist/api.mjs +2 -0
- package/dist/compiler.mjs +2 -3
- package/dist/defineProperty-JH0tR899.mjs +39 -0
- package/dist/fetch.d.mts +26 -0
- package/dist/fetch.mjs +345 -0
- package/dist/index-Ciz2Ye1L.d.mts +246 -0
- package/dist/index.d.mts +238 -410
- package/dist/index.mjs +1609 -2560
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/ref-BeA_Is-2.mjs +804 -0
- package/dist/router-5qgy8oOS.mjs +329 -0
- package/dist/router-BxV0btOX.d.mts +46 -0
- package/dist/router.d.mts +192 -0
- package/dist/router.mjs +1412 -0
- package/dist/store-DFP_p2kt.mjs +504 -0
- package/dist/store.d.mts +2 -0
- package/dist/store.mjs +2 -0
- package/package.json +31 -2
- /package/dist/{weappIntrinsicElements-CihhL3Md.d.mts → weappIntrinsicElements-BKiRK0cC.d.mts} +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { n as isRef, r as markAsRef, v as isObject } from "./ref-BeA_Is-2.mjs";
|
|
2
|
+
//#region src/reactivity/readonly.ts
|
|
3
|
+
function readonly(target) {
|
|
4
|
+
if (isRef(target)) {
|
|
5
|
+
const source = target;
|
|
6
|
+
return markAsRef({
|
|
7
|
+
get value() {
|
|
8
|
+
return source.value;
|
|
9
|
+
},
|
|
10
|
+
set value(_v) {
|
|
11
|
+
throw new Error("无法给只读 ref 赋值");
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (!isObject(target)) return target;
|
|
16
|
+
return new Proxy(target, {
|
|
17
|
+
set() {
|
|
18
|
+
throw new Error("无法在只读对象上设置属性");
|
|
19
|
+
},
|
|
20
|
+
deleteProperty() {
|
|
21
|
+
throw new Error("无法在只读对象上删除属性");
|
|
22
|
+
},
|
|
23
|
+
defineProperty() {
|
|
24
|
+
throw new Error("无法在只读对象上定义属性");
|
|
25
|
+
},
|
|
26
|
+
get(target, key, receiver) {
|
|
27
|
+
return Reflect.get(target, key, receiver);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/runtime/platform.ts
|
|
33
|
+
function getGlobalRuntime() {
|
|
34
|
+
if (typeof globalThis === "undefined") return;
|
|
35
|
+
return globalThis;
|
|
36
|
+
}
|
|
37
|
+
function getMiniProgramGlobalObject() {
|
|
38
|
+
var _env;
|
|
39
|
+
const globalRuntime = getGlobalRuntime();
|
|
40
|
+
const compiledPlatform = (_env = import.meta.env) === null || _env === void 0 ? void 0 : _env.PLATFORM;
|
|
41
|
+
if (compiledPlatform === "tt") return globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.tt;
|
|
42
|
+
if (compiledPlatform === "alipay" || compiledPlatform === "my") return globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.my;
|
|
43
|
+
if (compiledPlatform === "weapp" || compiledPlatform === "wx") return globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.wx;
|
|
44
|
+
if (globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.wx) return globalRuntime.wx;
|
|
45
|
+
if (globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.my) return globalRuntime.my;
|
|
46
|
+
if (globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.tt) return globalRuntime.tt;
|
|
47
|
+
}
|
|
48
|
+
function getScopedSlotHostGlobalObject() {
|
|
49
|
+
var _getMiniProgramGlobal;
|
|
50
|
+
return (_getMiniProgramGlobal = getMiniProgramGlobalObject()) !== null && _getMiniProgramGlobal !== void 0 ? _getMiniProgramGlobal : getGlobalRuntime();
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/runtime/hooks/base.ts
|
|
54
|
+
let __currentInstance;
|
|
55
|
+
let __currentSetupContext;
|
|
56
|
+
function getCurrentInstance() {
|
|
57
|
+
return __currentInstance;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 设置当前运行时实例(框架内部使用)。
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
function setCurrentInstance(inst) {
|
|
64
|
+
__currentInstance = inst;
|
|
65
|
+
}
|
|
66
|
+
function getCurrentSetupContext() {
|
|
67
|
+
return __currentSetupContext;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 设置当前 setup 上下文(框架内部使用)。
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
function setCurrentSetupContext(ctx) {
|
|
74
|
+
__currentSetupContext = ctx;
|
|
75
|
+
}
|
|
76
|
+
function assertInSetup(name) {
|
|
77
|
+
if (!__currentInstance) throw new Error(`${name}() 必须在 setup() 的同步阶段调用`);
|
|
78
|
+
return __currentInstance;
|
|
79
|
+
}
|
|
80
|
+
function ensureHookBucket(target) {
|
|
81
|
+
if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
|
|
82
|
+
return target.__wevuHooks;
|
|
83
|
+
}
|
|
84
|
+
function pushHook(target, name, handler, { single = false } = {}) {
|
|
85
|
+
const bucket = ensureHookBucket(target);
|
|
86
|
+
if (single) bucket[name] = handler;
|
|
87
|
+
else {
|
|
88
|
+
var _bucket$name;
|
|
89
|
+
((_bucket$name = bucket[name]) !== null && _bucket$name !== void 0 ? _bucket$name : bucket[name] = []).push(handler);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function ensureSinglePageHookOnInstance(target, name) {
|
|
93
|
+
var _ref, _ref$__wevuShareHookB;
|
|
94
|
+
const bridges = (_ref$__wevuShareHookB = (_ref = target).__wevuShareHookBridges) !== null && _ref$__wevuShareHookB !== void 0 ? _ref$__wevuShareHookB : _ref.__wevuShareHookBridges = Object.create(null);
|
|
95
|
+
if (typeof bridges[name] === "function") return;
|
|
96
|
+
const original = target[name];
|
|
97
|
+
const bridge = function onWevuShareHookBridge(...args) {
|
|
98
|
+
var _runtime$proxy;
|
|
99
|
+
const hooks = this.__wevuHooks;
|
|
100
|
+
const entry = hooks === null || hooks === void 0 ? void 0 : hooks[name];
|
|
101
|
+
const runtime = this.__wevu;
|
|
102
|
+
const ctx = (_runtime$proxy = runtime === null || runtime === void 0 ? void 0 : runtime.proxy) !== null && _runtime$proxy !== void 0 ? _runtime$proxy : this;
|
|
103
|
+
let ret;
|
|
104
|
+
if (typeof entry === "function") try {
|
|
105
|
+
ret = entry.apply(ctx, args);
|
|
106
|
+
} catch (_unused) {
|
|
107
|
+
ret = void 0;
|
|
108
|
+
}
|
|
109
|
+
else if (Array.isArray(entry)) for (const fn of entry) try {
|
|
110
|
+
ret = fn.apply(ctx, args);
|
|
111
|
+
} catch (_unused2) {}
|
|
112
|
+
if (ret !== void 0) return ret;
|
|
113
|
+
if (typeof original === "function") return original.apply(this, args);
|
|
114
|
+
};
|
|
115
|
+
bridges[name] = bridge;
|
|
116
|
+
target[name] = bridge;
|
|
117
|
+
}
|
|
118
|
+
function ensurePageShareMenusOnSetup(target) {
|
|
119
|
+
var _target$__wevuHooks;
|
|
120
|
+
const wxGlobal = getMiniProgramGlobalObject();
|
|
121
|
+
if (!wxGlobal || typeof wxGlobal.showShareMenu !== "function") return;
|
|
122
|
+
const hooks = (_target$__wevuHooks = target.__wevuHooks) !== null && _target$__wevuHooks !== void 0 ? _target$__wevuHooks : {};
|
|
123
|
+
const hasShareAppMessage = typeof hooks.onShareAppMessage === "function";
|
|
124
|
+
const hasShareTimeline = typeof hooks.onShareTimeline === "function";
|
|
125
|
+
if (!hasShareAppMessage && !hasShareTimeline) return;
|
|
126
|
+
const menus = ["shareAppMessage"];
|
|
127
|
+
if (hasShareTimeline) menus.push("shareTimeline");
|
|
128
|
+
try {
|
|
129
|
+
wxGlobal.showShareMenu({
|
|
130
|
+
withShareTicket: true,
|
|
131
|
+
menus
|
|
132
|
+
});
|
|
133
|
+
} catch (_unused3) {}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 调用批量 hook(框架内部调度入口)。
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
function callHookList(target, name, args = []) {
|
|
140
|
+
var _runtime$proxy2;
|
|
141
|
+
const hooks = target.__wevuHooks;
|
|
142
|
+
if (!hooks) return;
|
|
143
|
+
const list = hooks[name];
|
|
144
|
+
if (!list) return;
|
|
145
|
+
const runtime = target.__wevu;
|
|
146
|
+
const ctx = (_runtime$proxy2 = runtime === null || runtime === void 0 ? void 0 : runtime.proxy) !== null && _runtime$proxy2 !== void 0 ? _runtime$proxy2 : target;
|
|
147
|
+
if (Array.isArray(list)) for (const fn of list) try {
|
|
148
|
+
fn.apply(ctx, args);
|
|
149
|
+
} catch (_unused4) {}
|
|
150
|
+
else if (typeof list === "function") try {
|
|
151
|
+
list.apply(ctx, args);
|
|
152
|
+
} catch (_unused5) {}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 调用返回值型 hook(框架内部调度入口)。
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
function callHookReturn(target, name, args = []) {
|
|
159
|
+
var _runtime$proxy3;
|
|
160
|
+
const hooks = target.__wevuHooks;
|
|
161
|
+
if (!hooks) return;
|
|
162
|
+
const entry = hooks[name];
|
|
163
|
+
if (!entry) return;
|
|
164
|
+
const runtime = target.__wevu;
|
|
165
|
+
const ctx = (_runtime$proxy3 = runtime === null || runtime === void 0 ? void 0 : runtime.proxy) !== null && _runtime$proxy3 !== void 0 ? _runtime$proxy3 : target;
|
|
166
|
+
if (typeof entry === "function") try {
|
|
167
|
+
return entry.apply(ctx, args);
|
|
168
|
+
} catch (_unused6) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (Array.isArray(entry)) {
|
|
172
|
+
let out;
|
|
173
|
+
for (const fn of entry) try {
|
|
174
|
+
out = fn.apply(ctx, args);
|
|
175
|
+
} catch (_unused7) {}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/runtime/hooks/register.ts
|
|
181
|
+
function registerHook(name, handler, options) {
|
|
182
|
+
pushHook(assertInSetup(name), name, handler, options);
|
|
183
|
+
}
|
|
184
|
+
function onLaunch(handler) {
|
|
185
|
+
registerHook("onLaunch", handler);
|
|
186
|
+
}
|
|
187
|
+
function onPageNotFound(handler) {
|
|
188
|
+
registerHook("onPageNotFound", handler);
|
|
189
|
+
}
|
|
190
|
+
function onUnhandledRejection(handler) {
|
|
191
|
+
registerHook("onUnhandledRejection", handler);
|
|
192
|
+
}
|
|
193
|
+
function onThemeChange(handler) {
|
|
194
|
+
registerHook("onThemeChange", handler);
|
|
195
|
+
}
|
|
196
|
+
function onMemoryWarning(handler) {
|
|
197
|
+
registerHook("onMemoryWarning", handler);
|
|
198
|
+
}
|
|
199
|
+
function onShow(handler) {
|
|
200
|
+
registerHook("onShow", handler);
|
|
201
|
+
}
|
|
202
|
+
function onLoad(handler) {
|
|
203
|
+
registerHook("onLoad", handler);
|
|
204
|
+
}
|
|
205
|
+
function onHide(handler) {
|
|
206
|
+
registerHook("onHide", handler);
|
|
207
|
+
}
|
|
208
|
+
function onUnload(handler) {
|
|
209
|
+
registerHook("onUnload", handler);
|
|
210
|
+
}
|
|
211
|
+
function onReady(handler) {
|
|
212
|
+
registerHook("onReady", handler);
|
|
213
|
+
}
|
|
214
|
+
function onPullDownRefresh(handler) {
|
|
215
|
+
registerHook("onPullDownRefresh", handler);
|
|
216
|
+
}
|
|
217
|
+
function onReachBottom(handler) {
|
|
218
|
+
registerHook("onReachBottom", handler);
|
|
219
|
+
}
|
|
220
|
+
function onPageScroll(handler) {
|
|
221
|
+
registerHook("onPageScroll", handler);
|
|
222
|
+
}
|
|
223
|
+
function onRouteDone(handler) {
|
|
224
|
+
registerHook("onRouteDone", handler);
|
|
225
|
+
}
|
|
226
|
+
function onTabItemTap(handler) {
|
|
227
|
+
registerHook("onTabItemTap", handler);
|
|
228
|
+
}
|
|
229
|
+
function onResize(handler) {
|
|
230
|
+
registerHook("onResize", handler);
|
|
231
|
+
}
|
|
232
|
+
function onMoved(handler) {
|
|
233
|
+
registerHook("onMoved", handler);
|
|
234
|
+
}
|
|
235
|
+
function onAttached(handler) {
|
|
236
|
+
registerHook("onAttached", handler);
|
|
237
|
+
}
|
|
238
|
+
function onDetached(handler) {
|
|
239
|
+
registerHook("onDetached", handler);
|
|
240
|
+
}
|
|
241
|
+
function onError(handler) {
|
|
242
|
+
registerHook("onError", handler);
|
|
243
|
+
}
|
|
244
|
+
function onSaveExitState(handler) {
|
|
245
|
+
registerHook("onSaveExitState", handler, { single: true });
|
|
246
|
+
}
|
|
247
|
+
function onShareAppMessage(handler) {
|
|
248
|
+
const instance = assertInSetup("onShareAppMessage");
|
|
249
|
+
pushHook(instance, "onShareAppMessage", handler, { single: true });
|
|
250
|
+
ensureSinglePageHookOnInstance(instance, "onShareAppMessage");
|
|
251
|
+
ensurePageShareMenusOnSetup(instance);
|
|
252
|
+
}
|
|
253
|
+
function onShareTimeline(handler) {
|
|
254
|
+
const instance = assertInSetup("onShareTimeline");
|
|
255
|
+
pushHook(instance, "onShareTimeline", handler, { single: true });
|
|
256
|
+
ensureSinglePageHookOnInstance(instance, "onShareTimeline");
|
|
257
|
+
ensurePageShareMenusOnSetup(instance);
|
|
258
|
+
}
|
|
259
|
+
function onAddToFavorites(handler) {
|
|
260
|
+
const instance = assertInSetup("onAddToFavorites");
|
|
261
|
+
pushHook(instance, "onAddToFavorites", handler, { single: true });
|
|
262
|
+
ensureSinglePageHookOnInstance(instance, "onAddToFavorites");
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/runtime/vueCompat/router.ts
|
|
266
|
+
const RUNTIME_ROUTER_METHODS = [
|
|
267
|
+
"switchTab",
|
|
268
|
+
"reLaunch",
|
|
269
|
+
"redirectTo",
|
|
270
|
+
"navigateTo",
|
|
271
|
+
"navigateBack"
|
|
272
|
+
];
|
|
273
|
+
function isRuntimeRouter(candidate) {
|
|
274
|
+
if (!candidate || typeof candidate !== "object") return false;
|
|
275
|
+
return RUNTIME_ROUTER_METHODS.every((methodName) => {
|
|
276
|
+
return typeof candidate[methodName] === "function";
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function createGlobalRouterFallback() {
|
|
280
|
+
const miniProgramGlobal = getMiniProgramGlobalObject();
|
|
281
|
+
if (!miniProgramGlobal) return;
|
|
282
|
+
const fallbackRouter = Object.create(null);
|
|
283
|
+
for (const methodName of RUNTIME_ROUTER_METHODS) {
|
|
284
|
+
const handler = miniProgramGlobal[methodName];
|
|
285
|
+
if (typeof handler !== "function") return;
|
|
286
|
+
fallbackRouter[methodName] = (...args) => handler.apply(miniProgramGlobal, args);
|
|
287
|
+
}
|
|
288
|
+
return fallbackRouter;
|
|
289
|
+
}
|
|
290
|
+
function useRuntimeRouterByAccessor(primaryAccessor, fallbackAccessor, helperName) {
|
|
291
|
+
const ctx = getCurrentSetupContext();
|
|
292
|
+
if (!(ctx === null || ctx === void 0 ? void 0 : ctx.instance)) throw new Error(`${helperName}() 必须在 setup() 的同步阶段调用`);
|
|
293
|
+
const nativeInstance = ctx.instance;
|
|
294
|
+
const primaryRouter = nativeInstance[primaryAccessor];
|
|
295
|
+
if (isRuntimeRouter(primaryRouter)) return primaryRouter;
|
|
296
|
+
const fallbackRouter = nativeInstance[fallbackAccessor];
|
|
297
|
+
if (isRuntimeRouter(fallbackRouter)) return fallbackRouter;
|
|
298
|
+
const globalFallbackRouter = createGlobalRouterFallback();
|
|
299
|
+
if (globalFallbackRouter) return globalFallbackRouter;
|
|
300
|
+
throw new Error("当前运行环境不支持 Router,请升级微信基础库到 2.16.1+ 或检查平台路由能力");
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* 在 setup 中获取与当前组件路径语义一致的原生 Router 对象。
|
|
304
|
+
*
|
|
305
|
+
* - 优先使用实例上的 `this.router`(组件路径语义)。
|
|
306
|
+
* - 不可用时回退到 `this.pageRouter`。
|
|
307
|
+
* - 低版本基础库再回退到全局 `wx.*` 路由方法。
|
|
308
|
+
*
|
|
309
|
+
* 如需更贴近 Vue Router 的高阶能力(导航守卫、失败类型、统一解析),
|
|
310
|
+
* 推荐改用 `wevu/router` 子入口的 `useRouter()`。
|
|
311
|
+
*/
|
|
312
|
+
function useNativeRouter() {
|
|
313
|
+
return useRuntimeRouterByAccessor("router", "pageRouter", "useNativeRouter");
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* 在 setup 中获取与当前页面路径语义一致的原生 Router 对象。
|
|
317
|
+
*
|
|
318
|
+
* - 优先使用实例上的 `this.pageRouter`(页面路径语义)。
|
|
319
|
+
* - 不可用时回退到 `this.router`。
|
|
320
|
+
* - 低版本基础库再回退到全局 `wx.*` 路由方法。
|
|
321
|
+
*
|
|
322
|
+
* 如需更贴近 Vue Router 的高阶能力(导航守卫、失败类型、统一解析),
|
|
323
|
+
* 推荐改用 `wevu/router` 子入口的 `useRouter()`。
|
|
324
|
+
*/
|
|
325
|
+
function useNativePageRouter() {
|
|
326
|
+
return useRuntimeRouterByAccessor("pageRouter", "router", "useNativePageRouter");
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
export { getCurrentInstance as A, onTabItemTap as C, assertInSetup as D, onUnload as E, getMiniProgramGlobalObject as F, getScopedSlotHostGlobalObject as I, readonly as L, pushHook as M, setCurrentInstance as N, callHookList as O, setCurrentSetupContext as P, onShow as S, onUnhandledRejection as T, onResize as _, onDetached as a, onShareAppMessage as b, onLaunch as c, onMoved as d, onPageNotFound as f, onReady as g, onReachBottom as h, onAttached as i, getCurrentSetupContext as j, callHookReturn as k, onLoad as l, onPullDownRefresh as m, useNativeRouter as n, onError as o, onPageScroll as p, onAddToFavorites as r, onHide as s, useNativePageRouter as t, onMemoryWarning as u, onRouteDone as v, onThemeChange as w, onShareTimeline as x, onSaveExitState as y };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/runtime/types/props/router.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Router 路由类型映射(供声明合并扩展)。
|
|
4
|
+
*
|
|
5
|
+
* 典型用法:在业务项目的类型声明中补充 `entries` 联合类型,
|
|
6
|
+
* 让 `useNativeRouter()/useNativePageRouter()` 的 `url` 参数获得字面量约束。
|
|
7
|
+
*/
|
|
8
|
+
interface WevuTypedRouterRouteMap {}
|
|
9
|
+
type ResolveTypedRouterEntries = WevuTypedRouterRouteMap extends {
|
|
10
|
+
entries: infer Entries;
|
|
11
|
+
} ? Extract<Entries, string> : string;
|
|
12
|
+
type ResolveTypedRouterTabBarEntries = WevuTypedRouterRouteMap extends {
|
|
13
|
+
tabBarEntries: infer Entries;
|
|
14
|
+
} ? Extract<Entries, string> : ResolveTypedRouterEntries;
|
|
15
|
+
type RelativeRouterUrl = `./${string}` | `../${string}`;
|
|
16
|
+
type AbsoluteRouterPath<Path extends string> = Path | `/${Path}`;
|
|
17
|
+
type AbsoluteRouterUrl<Path extends string> = AbsoluteRouterPath<Path> | `${Path}?${string}` | `/${Path}?${string}`;
|
|
18
|
+
type RouterUrl<Path extends string> = string extends Path ? string : AbsoluteRouterUrl<Path> | RelativeRouterUrl;
|
|
19
|
+
type RouterPathUrl<Path extends string> = string extends Path ? string : AbsoluteRouterPath<Path>;
|
|
20
|
+
type TypedRouterUrl = RouterUrl<ResolveTypedRouterEntries>;
|
|
21
|
+
type TypedRouterTabBarUrl = RouterPathUrl<ResolveTypedRouterTabBarEntries>;
|
|
22
|
+
type RouterSwitchTabOption = Omit<WechatMiniprogram.SwitchTabOption, 'url'> & {
|
|
23
|
+
url: TypedRouterTabBarUrl;
|
|
24
|
+
};
|
|
25
|
+
type RouterReLaunchOption = Omit<WechatMiniprogram.ReLaunchOption, 'url'> & {
|
|
26
|
+
url: TypedRouterUrl;
|
|
27
|
+
};
|
|
28
|
+
type RouterRedirectToOption = Omit<WechatMiniprogram.RedirectToOption, 'url'> & {
|
|
29
|
+
url: TypedRouterUrl;
|
|
30
|
+
};
|
|
31
|
+
type RouterNavigateToOption = Omit<WechatMiniprogram.NavigateToOption, 'url'> & {
|
|
32
|
+
url: TypedRouterUrl;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* setup 场景下推荐使用的 Router 类型。
|
|
36
|
+
* 默认行为与原生 Router 一致;声明合并后可获得更精确的 `url` 类型提示。
|
|
37
|
+
*/
|
|
38
|
+
interface SetupContextRouter {
|
|
39
|
+
switchTab: (option: RouterSwitchTabOption) => ReturnType<WechatMiniprogram.Component.Router['switchTab']>;
|
|
40
|
+
reLaunch: (option: RouterReLaunchOption) => ReturnType<WechatMiniprogram.Component.Router['reLaunch']>;
|
|
41
|
+
redirectTo: (option: RouterRedirectToOption) => ReturnType<WechatMiniprogram.Component.Router['redirectTo']>;
|
|
42
|
+
navigateTo: (option: RouterNavigateToOption) => ReturnType<WechatMiniprogram.Component.Router['navigateTo']>;
|
|
43
|
+
navigateBack: WechatMiniprogram.Component.Router['navigateBack'];
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { SetupContextRouter as a, WevuTypedRouterRouteMap as c, RouterSwitchTabOption as i, RouterReLaunchOption as n, TypedRouterTabBarUrl as o, RouterRedirectToOption as r, TypedRouterUrl as s, RouterNavigateToOption as t };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { a as SetupContextRouter, c as WevuTypedRouterRouteMap, i as RouterSwitchTabOption, n as RouterReLaunchOption, o as TypedRouterTabBarUrl, r as RouterRedirectToOption, s as TypedRouterUrl, t as RouterNavigateToOption } from "./router-BxV0btOX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/routerInternal/types.d.ts
|
|
4
|
+
interface RouteResolveCodec {
|
|
5
|
+
parseQuery: RouteQueryParser;
|
|
6
|
+
stringifyQuery: RouteQueryStringifier;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/routerInternal/query.d.ts
|
|
10
|
+
declare function parseQuery(search: string): LocationQuery;
|
|
11
|
+
declare function stringifyQuery(query?: LocationQueryRaw | LocationQuery): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/router/types.d.ts
|
|
14
|
+
type LocationQueryValue = string | null;
|
|
15
|
+
type LocationQueryValueRaw = LocationQueryValue | number | boolean | undefined;
|
|
16
|
+
type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>;
|
|
17
|
+
type LocationQueryRaw = Record<string, LocationQueryValueRaw | LocationQueryValueRaw[]>;
|
|
18
|
+
type RouteParamValue = string;
|
|
19
|
+
type RouteParamValueRaw = RouteParamValue | number | boolean | null | undefined;
|
|
20
|
+
type RouteParams = Record<string, RouteParamValue | RouteParamValue[]>;
|
|
21
|
+
type RouteParamsRaw = Record<string, RouteParamValueRaw | RouteParamValueRaw[]>;
|
|
22
|
+
type RouteParamsMode = 'loose' | 'strict';
|
|
23
|
+
type RouteQueryParser = (search: string) => LocationQueryRaw | LocationQuery;
|
|
24
|
+
type RouteQueryStringifier = (query: LocationQueryRaw | LocationQuery) => string;
|
|
25
|
+
type RouteMeta = Record<string, unknown>;
|
|
26
|
+
interface NamedRouteRecord {
|
|
27
|
+
name: string;
|
|
28
|
+
path: string;
|
|
29
|
+
}
|
|
30
|
+
type NamedRoutes = Readonly<Record<string, string>> | readonly RouteRecordRaw[];
|
|
31
|
+
type RouteLocationRaw = string | {
|
|
32
|
+
path?: string;
|
|
33
|
+
fullPath?: string;
|
|
34
|
+
query?: LocationQueryRaw;
|
|
35
|
+
hash?: string;
|
|
36
|
+
name?: string;
|
|
37
|
+
params?: RouteParamsRaw;
|
|
38
|
+
};
|
|
39
|
+
interface RouteLocationNormalizedLoaded {
|
|
40
|
+
path: string;
|
|
41
|
+
fullPath: string;
|
|
42
|
+
query: LocationQuery;
|
|
43
|
+
hash: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
meta?: RouteMeta;
|
|
46
|
+
href?: string;
|
|
47
|
+
matched?: readonly RouteRecordMatched[];
|
|
48
|
+
redirectedFrom?: RouteLocationRedirectedFrom;
|
|
49
|
+
params: RouteParams;
|
|
50
|
+
}
|
|
51
|
+
declare const NavigationFailureType: {
|
|
52
|
+
readonly unknown: 1;
|
|
53
|
+
readonly aborted: 4;
|
|
54
|
+
readonly cancelled: 8;
|
|
55
|
+
readonly duplicated: 16;
|
|
56
|
+
};
|
|
57
|
+
type NavigationFailureTypeValue = (typeof NavigationFailureType)[keyof typeof NavigationFailureType];
|
|
58
|
+
interface NavigationFailure extends Error {
|
|
59
|
+
readonly __wevuNavigationFailure: true;
|
|
60
|
+
readonly type: NavigationFailureTypeValue;
|
|
61
|
+
readonly to?: RouteLocationNormalizedLoaded;
|
|
62
|
+
readonly from?: RouteLocationNormalizedLoaded;
|
|
63
|
+
readonly cause?: unknown;
|
|
64
|
+
}
|
|
65
|
+
type NavigationMode = 'push' | 'replace' | 'back';
|
|
66
|
+
interface NavigationRedirect {
|
|
67
|
+
to: RouteLocationRaw;
|
|
68
|
+
replace?: boolean;
|
|
69
|
+
}
|
|
70
|
+
type RouteRecordRedirect = RouteLocationRaw | NavigationRedirect | ((to: RouteLocationNormalizedLoaded, from: RouteLocationNormalizedLoaded) => RouteLocationRaw | NavigationRedirect | Promise<RouteLocationRaw | NavigationRedirect>);
|
|
71
|
+
interface RouteRecordRaw extends NamedRouteRecord {
|
|
72
|
+
meta?: RouteMeta;
|
|
73
|
+
alias?: string | readonly string[];
|
|
74
|
+
children?: readonly RouteRecordRaw[];
|
|
75
|
+
beforeEnter?: NavigationGuard | readonly NavigationGuard[];
|
|
76
|
+
redirect?: RouteRecordRedirect;
|
|
77
|
+
}
|
|
78
|
+
interface RouteRecordMatched {
|
|
79
|
+
name: string;
|
|
80
|
+
path: string;
|
|
81
|
+
aliasPath?: string;
|
|
82
|
+
meta?: RouteMeta;
|
|
83
|
+
}
|
|
84
|
+
interface RouteLocationRedirectedFrom {
|
|
85
|
+
path: string;
|
|
86
|
+
fullPath: string;
|
|
87
|
+
query: LocationQuery;
|
|
88
|
+
hash: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
meta?: RouteMeta;
|
|
91
|
+
href?: string;
|
|
92
|
+
matched?: readonly RouteRecordMatched[];
|
|
93
|
+
params: RouteParams;
|
|
94
|
+
}
|
|
95
|
+
type NavigationGuardResult = void | boolean | NavigationFailure | RouteLocationRaw | NavigationRedirect;
|
|
96
|
+
type NavigationGuard = (to: RouteLocationNormalizedLoaded | undefined, from: RouteLocationNormalizedLoaded, context?: NavigationGuardContext) => NavigationGuardResult | Promise<NavigationGuardResult>;
|
|
97
|
+
type NavigationAfterEach = (to: RouteLocationNormalizedLoaded | undefined, from: RouteLocationNormalizedLoaded, failure?: NavigationFailure, context?: NavigationAfterEachContext) => void | Promise<void>;
|
|
98
|
+
interface NavigationGuardContext {
|
|
99
|
+
readonly mode: NavigationMode;
|
|
100
|
+
readonly to?: RouteLocationNormalizedLoaded;
|
|
101
|
+
readonly from: RouteLocationNormalizedLoaded;
|
|
102
|
+
readonly nativeRouter: SetupContextRouter;
|
|
103
|
+
}
|
|
104
|
+
interface NavigationAfterEachContext {
|
|
105
|
+
readonly mode: NavigationMode;
|
|
106
|
+
readonly to?: RouteLocationNormalizedLoaded;
|
|
107
|
+
readonly from: RouteLocationNormalizedLoaded;
|
|
108
|
+
readonly nativeRouter: SetupContextRouter;
|
|
109
|
+
readonly failure?: NavigationFailure;
|
|
110
|
+
}
|
|
111
|
+
interface NavigationErrorContext {
|
|
112
|
+
readonly mode: NavigationMode;
|
|
113
|
+
readonly to?: RouteLocationNormalizedLoaded;
|
|
114
|
+
readonly from: RouteLocationNormalizedLoaded;
|
|
115
|
+
readonly nativeRouter: SetupContextRouter;
|
|
116
|
+
readonly failure: NavigationFailure;
|
|
117
|
+
}
|
|
118
|
+
type NavigationErrorHandler = (error: unknown, context: NavigationErrorContext) => void | Promise<void>;
|
|
119
|
+
interface UseRouterOptions {
|
|
120
|
+
tabBarEntries?: readonly (TypedRouterTabBarUrl | string)[];
|
|
121
|
+
/**
|
|
122
|
+
* Vue Router 对齐入口:推荐使用 `routes`
|
|
123
|
+
*/
|
|
124
|
+
routes?: readonly RouteRecordRaw[];
|
|
125
|
+
/**
|
|
126
|
+
* 兼容入口:支持对象 map 或路由记录数组
|
|
127
|
+
*/
|
|
128
|
+
namedRoutes?: NamedRoutes;
|
|
129
|
+
paramsMode?: RouteParamsMode;
|
|
130
|
+
maxRedirects?: number;
|
|
131
|
+
parseQuery?: RouteQueryParser;
|
|
132
|
+
stringifyQuery?: RouteQueryStringifier;
|
|
133
|
+
/**
|
|
134
|
+
* 异常型导航失败时是否以 Promise reject 抛出失败对象。
|
|
135
|
+
*
|
|
136
|
+
* - `true`:更贴近 Vue Router 心智(默认)
|
|
137
|
+
* - `false`:始终以返回值形式携带失败对象
|
|
138
|
+
*/
|
|
139
|
+
rejectOnError?: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface RouterNavigation {
|
|
142
|
+
readonly nativeRouter: SetupContextRouter;
|
|
143
|
+
readonly options: Readonly<UseRouterOptions>;
|
|
144
|
+
readonly currentRoute: Readonly<RouteLocationNormalizedLoaded>;
|
|
145
|
+
install: (app?: unknown) => void;
|
|
146
|
+
resolve: (to: RouteLocationRaw) => RouteLocationNormalizedLoaded;
|
|
147
|
+
isReady: () => Promise<void>;
|
|
148
|
+
push: (to: RouteLocationRaw) => Promise<void | NavigationFailure>;
|
|
149
|
+
replace: (to: RouteLocationRaw) => Promise<void | NavigationFailure>;
|
|
150
|
+
back: (delta?: number) => Promise<void | NavigationFailure>;
|
|
151
|
+
go: (delta: number) => Promise<void | NavigationFailure>;
|
|
152
|
+
forward: () => Promise<void | NavigationFailure>;
|
|
153
|
+
hasRoute: (name: string) => boolean;
|
|
154
|
+
getRoutes: () => readonly RouteRecordRaw[];
|
|
155
|
+
addRoute: AddRoute;
|
|
156
|
+
removeRoute: (name: string) => void;
|
|
157
|
+
clearRoutes: () => void;
|
|
158
|
+
beforeEach: (guard: NavigationGuard) => () => void;
|
|
159
|
+
beforeResolve: (guard: NavigationGuard) => () => void;
|
|
160
|
+
afterEach: (hook: NavigationAfterEach) => () => void;
|
|
161
|
+
onError: (handler: NavigationErrorHandler) => () => void;
|
|
162
|
+
}
|
|
163
|
+
interface AddRoute {
|
|
164
|
+
(route: RouteRecordRaw): () => void;
|
|
165
|
+
(parentName: string, route: RouteRecordRaw): () => void;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/router/navigationCore.d.ts
|
|
169
|
+
declare function createNavigationFailure(type: NavigationFailureTypeValue, to?: RouteLocationNormalizedLoaded, from?: RouteLocationNormalizedLoaded, cause?: unknown): NavigationFailure;
|
|
170
|
+
declare function isNavigationFailure(error: unknown, type?: NavigationFailureTypeValue): error is NavigationFailure;
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/router/resolve.d.ts
|
|
173
|
+
declare function resolveRouteLocation(to: RouteLocationRaw, currentPath?: string, codec?: RouteResolveCodec): RouteLocationNormalizedLoaded;
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/router/useRoute.d.ts
|
|
176
|
+
declare function useRoute(): Readonly<RouteLocationNormalizedLoaded>;
|
|
177
|
+
/**
|
|
178
|
+
* @description 获取当前组件路径语义的原生 Router
|
|
179
|
+
*/
|
|
180
|
+
declare function useNativeRouter(): SetupContextRouter;
|
|
181
|
+
/**
|
|
182
|
+
* @description 获取当前页面路径语义的原生 Page Router
|
|
183
|
+
*/
|
|
184
|
+
declare function useNativePageRouter(): SetupContextRouter;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/router/useRouter.d.ts
|
|
187
|
+
/**
|
|
188
|
+
* @description 获取高阶路由导航器(对齐 Vue Router 心智)
|
|
189
|
+
*/
|
|
190
|
+
declare function useRouter(options?: UseRouterOptions): RouterNavigation;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { type AddRoute, type LocationQuery, type LocationQueryRaw, type LocationQueryValue, type LocationQueryValueRaw, type NamedRouteRecord, type NamedRoutes, type NavigationAfterEach, type NavigationAfterEachContext, type NavigationErrorContext, type NavigationErrorHandler, type NavigationFailure, NavigationFailureType, type NavigationFailureTypeValue, type NavigationGuard, type NavigationGuardContext, type NavigationGuardResult, type NavigationMode, type NavigationRedirect, type RouteLocationNormalizedLoaded, type RouteLocationRaw, type RouteLocationRedirectedFrom, type RouteMeta, type RouteParamValue, type RouteParamValueRaw, type RouteParams, type RouteParamsMode, type RouteParamsRaw, type RouteQueryParser, type RouteQueryStringifier, type RouteRecordMatched, type RouteRecordRaw, type RouteRecordRedirect, type RouterNavigateToOption, type RouterNavigation, type RouterReLaunchOption, type RouterRedirectToOption, type RouterSwitchTabOption, type SetupContextRouter, type TypedRouterTabBarUrl, type TypedRouterUrl, type UseRouterOptions, type WevuTypedRouterRouteMap, createNavigationFailure, isNavigationFailure, parseQuery, resolveRouteLocation, stringifyQuery, useNativePageRouter, useNativeRouter, useRoute, useRouter };
|