chore(test): 测试代码

This commit is contained in:
2025-12-29 15:54:00 +08:00
parent 6b5a268955
commit 30403871e7
15 changed files with 394 additions and 99 deletions

View File

@@ -14,7 +14,55 @@ export default {
*/
redirectTo(to, param, mode) {
let url = to;
let tabbarList = ['/pages/index/index', '/pages/goods/category', '/pages/vr/index', '/pages/contact/contact', '/pages/member/index'];
// 当前最新的tabBar.list (参见pages.json 中的tabBar.list 配置)
const systemTabBarList = [
'/pages/index/index',
'/pages_goods/category',
'/pages_tool/contact/contact',
'/pages_tool/member/index',
'/pages_tool/vr/index'
];
/**
* 特别注意:
* 由于老版本或者后台系统服务未同步更新可以作为tabBarList的最新分包路径。历史遗留问题需要与当前最新分包机制版本保持一致。
* 系统当前的支持tarbarList包含动态tabBar,注意这是实际分包后的路径
* 根据匹配映射关系修改url为实际分包后的路径
*/
// 定义前缀映射表
const urlPrefixMap = {
'/pages/goods/': '/pages_goods/',
'/pages/contact/': '/pages_tool/contact/',
'/pages/member/': '/pages_tool/member/',
'/pages/vr': '/pages_tool/vr/'
};
// 构建正则表达式
const regex = new RegExp(
Object.keys(urlPrefixMap).map(key =>
key.replace(/\//g, '\\/').replace(/\*/g, '.*')
).join('|'),
'g'
);
// 替换函数
function replacePrefix(str) {
return str.replace(regex, match => {
for (const [oldPrefix, newPrefix] of Object.entries(urlPrefixMap)) {
if (match.startsWith(oldPrefix)) {
return match.replace(oldPrefix, newPrefix);
}
}
return match; // 默认返回原匹配
});
}
console.log('redirectTo', to, param, mode);
// 替换url中的前缀
url = replacePrefix(url);
console.log('replacePrefix', url);
if (param != undefined) {
Object.keys(param).forEach(function (key) {
if (url.indexOf('?') != -1) {
@@ -24,14 +72,19 @@ export default {
}
});
}
for (let i = 0; i < tabbarList.length; i++) {
if (url.indexOf(tabbarList[i]) == 0) {
// 针对tabBar.list中的路径直接切换tabBar
for (let i = 0; i < systemTabBarList.length; i++) {
const tabBarUrl = systemTabBarList[i];
if (url.indexOf(tabBarUrl) == 0) {
uni.switchTab({
url
});
return;
}
}
// 如果url不包含tabBarList中的路径根据mode判断跳转方式
switch (mode) {
case 'tabbar':
// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面。
@@ -57,6 +110,8 @@ export default {
url
});
}
console.log('无任何处理', url);
},
/**
* 图片路径转换
@@ -64,8 +119,8 @@ export default {
* @param {Object} params 参数针对商品、相册里面的图片区分大中小size: big、mid、small
*/
img(img_path, params) {
var path = "";
if (img_path != undefined && img_path != "") {
if (img_path.split(',').length > 1) {
@@ -81,7 +136,7 @@ export default {
// if(img_path.indexOf('attachment') == -1){
// img_path = arr.join(".");
// }
}
if (img_path.indexOf("http://") == -1 && img_path.indexOf("https://") == -1) {
path = Config.imgDomain + "/" + img_path;
@@ -90,7 +145,7 @@ export default {
path = img_path;
}
}
// path += '?t=' + parseInt(new Date().getTime() / 1000);
return path;
},
@@ -385,14 +440,14 @@ export default {
*/
isWeChatMiniProgram() {
const userAgent = navigator.userAgent.toLowerCase();
// 微信小程序的web-view User-Agent会包含以下特征之一
const miniProgramIndicators = [
'miniprogram', // 普通微信小程序
'wxwork', // 企业微信小程序
'micromessenger/[0-9]+\.[0-9]+\.[0-9]+ nettype/wifi wxwebviewtype/1'
];
return miniProgramIndicators.some(indicator => {
if (typeof indicator === 'string' && indicator.includes('/')) {
// 正则表达式匹配
@@ -466,11 +521,11 @@ export default {
* @param {Object} link
*/
diyRedirectTo(link) {
//if (link == null || Object.keys(link).length == 1) return;
// 外部链接
if (link.wap_url && link.wap_url.indexOf('http') != -1 || link.wap_url && link.wap_url.indexOf('http') != -1) {
if (link.wap_url && link.wap_url.indexOf('http') != -1) {
// #ifdef H5
window.location.href = link.wap_url;
// #endif
@@ -786,7 +841,7 @@ export default {
if (!path) {
let route = this.getCurrentRoute();
path = route.path;
if (path == '/pages/member/index') {
if (path == '/pages_tool/member/index') {
return new Promise((resolve, reject) => {
resolve({})
});
@@ -951,11 +1006,11 @@ export default {
var points_E = [];
const DIST_AB = Math.sqrt(Math.pow(points[1]['x'] - points[0]['x'], 2) + Math.pow(points[1]['y'] - points[0][
'y'
], 2));
], 2));
// 邻控制BC点间距
const DIST_BC = Math.sqrt(Math.pow(points[2]['x'] - points[1]['x'], 2) + Math.pow(points[2]['y'] - points[1][
'y'
], 2));
], 2));
// D每次在AB方向上移动的距离
if (points[0]['x'] > points[2]['x']) {
var EACH_MOVE_AD = -(DIST_AB / times);