features navigator 对小程序namespace的容错
This commit is contained in:
parent
48a6fd03d4
commit
d1bb8f9d14
|
|
@ -1,8 +1,20 @@
|
|||
/// <reference types="wechat-miniprogram" />
|
||||
import { Feature } from '../types/Feature';
|
||||
import { OakNavigateToParameters } from '../types/Page';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { EntityDict } from 'oak-domain/lib/types';
|
||||
declare type Location = {
|
||||
pathname: string;
|
||||
state: unknown;
|
||||
key: string;
|
||||
};
|
||||
export declare class Navigator extends Feature {
|
||||
namespace: string;
|
||||
history: WechatMiniprogram.Wx;
|
||||
constructor();
|
||||
setNamespace(namespace: string): void;
|
||||
getLocation(): Location;
|
||||
getNamespace(): string;
|
||||
private constructUrl;
|
||||
navigateTo<ED extends EntityDict & BaseEntityDict, T2 extends keyof ED>(options: {
|
||||
url: string;
|
||||
|
|
@ -12,3 +24,4 @@ export declare class Navigator extends Feature {
|
|||
} & OakNavigateToParameters<ED, T2>, state?: Record<string, any>): Promise<unknown>;
|
||||
navigateBack(delta?: number): Promise<unknown>;
|
||||
}
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -8,8 +8,28 @@ var Feature_1 = require("../types/Feature");
|
|||
var Navigator = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(Navigator, _super);
|
||||
function Navigator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
var _this = _super.call(this) || this;
|
||||
_this.history = wx;
|
||||
_this.namespace = '';
|
||||
return _this;
|
||||
}
|
||||
Navigator.prototype.setNamespace = function (namespace) {
|
||||
this.namespace = namespace;
|
||||
};
|
||||
Navigator.prototype.getLocation = function () {
|
||||
var pages = getCurrentPages(); //获取加载的页面
|
||||
var currentPage = pages[pages.length - 1]; //获取当前页面的对象
|
||||
var url = currentPage.route; //当前页面url
|
||||
var options = currentPage.options; //如果要获取url中所带的参数可以查看options
|
||||
return {
|
||||
pathname: url,
|
||||
state: options,
|
||||
key: "".concat(pages.length - 1),
|
||||
};
|
||||
};
|
||||
Navigator.prototype.getNamespace = function () {
|
||||
return this.namespace;
|
||||
};
|
||||
Navigator.prototype.constructUrl = function (url, state) {
|
||||
var urlParse = url_1.default.parse(url, true);
|
||||
var _a = urlParse, pathname = _a.pathname, search = _a.search;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ function reRender(option, extra) {
|
|||
var rows = this.features.runningTree.getFreshValue(this.state.oakFullpath);
|
||||
var oakDirty = this.features.runningTree.isDirty(this.state.oakFullpath);
|
||||
var oakLoading = !this.pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
var oakPullDownRefreshLoading = this.pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
var oakPullDownRefreshLoading = !!this.pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
var oakLoadingMore = this.features.runningTree.isLoadingMore(this.state.oakFullpath);
|
||||
var oakExecuting = this.features.runningTree.isExecuting(this.state.oakFullpath);
|
||||
var oakExecutable = !oakExecuting && this.features.runningTree.tryExecute(this.state.oakFullpath);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,42 @@ import { OakNavigateToParameters } from '../types/Page';
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { EntityDict } from 'oak-domain/lib/types';
|
||||
|
||||
type Location = {
|
||||
pathname: string;
|
||||
state: unknown;
|
||||
key: string
|
||||
};
|
||||
|
||||
export class Navigator extends Feature {
|
||||
namespace: string;
|
||||
history: WechatMiniprogram.Wx;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.history = wx;
|
||||
this.namespace = '';
|
||||
}
|
||||
|
||||
setNamespace(namespace: string) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
getLocation(): Location {
|
||||
const pages = getCurrentPages(); //获取加载的页面
|
||||
const currentPage = pages[pages.length - 1]; //获取当前页面的对象
|
||||
const url = currentPage.route; //当前页面url
|
||||
const options = currentPage.options; //如果要获取url中所带的参数可以查看options
|
||||
return {
|
||||
pathname: url,
|
||||
state: options,
|
||||
key: `${pages.length - 1}`,
|
||||
};
|
||||
}
|
||||
|
||||
getNamespace() {
|
||||
return this.namespace;
|
||||
}
|
||||
|
||||
private constructUrl(url: string, state?: Record<string, any>) {
|
||||
const urlParse = URL.parse(url, true);
|
||||
const { pathname, search } = urlParse as {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ export function reRender<
|
|||
|
||||
const oakDirty = this.features.runningTree.isDirty(this.state.oakFullpath);
|
||||
const oakLoading = !(this as any).pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
const oakPullDownRefreshLoading = (this as any).pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
const oakPullDownRefreshLoading = !!(this as any).pullDownRefresh && this.features.runningTree.isLoading(this.state.oakFullpath);
|
||||
const oakLoadingMore = this.features.runningTree.isLoadingMore(this.state.oakFullpath);
|
||||
const oakExecuting = this.features.runningTree.isExecuting(this.state.oakFullpath);
|
||||
const oakExecutable = !oakExecuting && this.features.runningTree.tryExecute(this.state.oakFullpath);
|
||||
|
|
|
|||
Loading…
Reference in New Issue