From bd99a5211f3a5fcaa051e5da868d87bb870148f5 Mon Sep 17 00:00:00 2001 From: quanyawei <401863037@qq.com> Date: Fri, 01 Mar 2024 09:58:45 +0800 Subject: [PATCH] fix:手持设备 --- uni_modules/uview-ui/libs/util/route.js | 124 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/libs/util/route.js b/uni_modules/uview-ui/libs/util/route.js new file mode 100644 index 0000000..2afeea5 --- /dev/null +++ b/uni_modules/uview-ui/libs/util/route.js @@ -0,0 +1,124 @@ +/** + * ���������������������������������������������������uni.xxx������������������������������������ + * ������������������������������ + */ + +class Router { + constructor() { + // ������������������ + this.config = { + type: 'navigateTo', + url: '', + delta: 1, // navigateBack���������������,��������������� + params: {}, // ��������������� + animationType: 'pop-in', // ������������,������APP������ + animationDuration: 300, // ������������������������,������������,������APP������ + intercept: false // ������������������ + } + // ������route������������������������������������������������������������route���������������this������������route��������������� + // ������������������������������this������ + this.route = this.route.bind(this) + } + + // ������url���������������"/"��������������������������������������������� + addRootPath(url) { + return url[0] === '/' ? url : `/${url}` + } + + // ������������������ + mixinParam(url, params) { + url = url && this.addRootPath(url) + + // ���������������������������������������������������"/","?","="������������/page/index/index?name=mary" + // ���������url������get������������������������������"?" + let query = '' + if (/.*\/.*\?.*=.*/.test(url)) { + // object������������get��������������� + query = uni.$u.queryParams(params, false) + // ������������get������,���������������������������������������"&"������ + return url += `&${query}` + } + // ���������������������������������url������������������query���������������������"?/&"��������������� + query = uni.$u.queryParams(params) + return url += query + } + + // ��������������������� + async route(options = {}, params = {}) { + // ��������������������������������������������� + let mergeConfig = {} + + if (typeof options === 'string') { + // ������options���������������������route(url, params)��������� + mergeConfig.url = this.mixinParam(options, params) + mergeConfig.type = 'navigateTo' + } else { + mergeConfig = uni.$u.deepMerge(this.config, options) + // ������������������mergeConfig������url���params������������ + mergeConfig.url = this.mixinParam(options.url, options.params) + } + + // ��������������������������������������������������������������������������������������������������������������������������������������������������������� + if (mergeConfig.url === uni.$u.page()) return + + if (params.intercept) { + this.config.intercept = params.intercept + } + // params������������������������ + mergeConfig.params = params + // ��������������������� + mergeConfig = uni.$u.deepMerge(this.config, mergeConfig) + // ������������������������������������ + if (typeof uni.$u.routeIntercept === 'function') { + // ���������promise���������������������resolve(true)������resolve(false)��������������������������������� + const isNext = await new Promise((resolve, reject) => { + uni.$u.routeIntercept(mergeConfig, resolve) + }) + // ������isNext���true������������������������ + isNext && this.openPage(mergeConfig) + } else { + this.openPage(mergeConfig) + } + } + + // ������������������ + openPage(config) { + // ������������ + const { + url, + type, + delta, + animationType, + animationDuration + } = config + if (config.type == 'navigateTo' || config.type == 'to') { + uni.navigateTo({ + url, + animationType, + animationDuration + }) + } + if (config.type == 'redirectTo' || config.type == 'redirect') { + uni.redirectTo({ + url + }) + } + if (config.type == 'switchTab' || config.type == 'tab') { + uni.switchTab({ + url + }) + } + if (config.type == 'reLaunch' || config.type == 'launch') { + uni.reLaunch({ + url + }) + } + if (config.type == 'navigateBack' || config.type == 'back') { + uni.navigateBack({ + delta + }) + } + } +} + +export default (new Router()).route -- Gitblit v1.8.0