export default (options, type = 1) => {
return new Promise((reslove, reject) => {
routes[type](Object.assign(getPath(options), {
success: reslove,
fail: reject,
}));
});
};
function getPath(options) {
switch (Reflect.toString.call(options)) {
case “[object Object]”:
return {
url: ${options.url}?data=${encodeURIComponent(JSON.stringify(options.data))}
,
};
case “[object Number]”:
return {
delta: options,
};
case “[object String]”:
return {
url: options,
};
}
}
const routes = {
1: wx.navigateTo,
2: wx.switchTab,
3: wx.navigateBack,
4: wx.reLaunch,
5: wx.redirectTo,
};