Commit 958a9aac authored by lg's avatar lg

chore: appId为wxab14ac8f684ad962的都为半屏拉起

parent f02b7703
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
} }
}, },
"requiredBackgroundModes" : [ "share" ], "requiredBackgroundModes" : [ "share" ],
"embeddedAppIdList": ["wx4205ec55b793245e"] "embeddedAppIdList": ["wx4205ec55b793245e", "wxab14ac8f684ad962"]
}, },
"mp-alipay" : { "mp-alipay" : {
"usingComponents" : true "usingComponents" : true
......
// 导入全局store // 导入全局store
import { useGlobalStore } from "../stores/global"; import {useGlobalStore} from "../stores/global";
// 跳转类型枚举 // 跳转类型枚举
export const JumpType = { export const JumpType = {
INNER: 1, // 内部小程序页面跳转 INNER: 1, // 内部小程序页面跳转
MINI: 2, // 其他小程序页面跳转 MINI: 2, // 其他小程序页面跳转
H5: 3, // https 网络连接跳转 H5: 3, // https 网络连接跳转
}; };
const OPEN_EMBEDDED_APPS = [
"wx4205ec55b793245e", // 星妈优选
"wxab14ac8f684ad962",
]
/** /**
* 通用跳转方法 * 通用跳转方法
* @param {Object} options * @param {Object} options
...@@ -15,94 +20,94 @@ export const JumpType = { ...@@ -15,94 +20,94 @@ export const JumpType = {
* @param {string} options.url 跳转地址(页面路径/小程序路径/https链接) * @param {string} options.url 跳转地址(页面路径/小程序路径/https链接)
* @param {Object} [options.extra] 额外参数(如 appId、extraData 等) * @param {Object} [options.extra] 额外参数(如 appId、extraData 等)
*/ */
export function jump({ type, url, extra = {} }) { export function jump({type, url, extra = {}}) {
switch (type) { switch (type) {
case JumpType.INNER: case JumpType.INNER:
try { try {
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route; const currentPath = currentPage.route;
if (url.indexOf('pages/index/index') >= 0 && currentPath.indexOf('pages/index/index') >= 0) { if (url.indexOf('pages/index/index') >= 0 && currentPath.indexOf('pages/index/index') >= 0) {
// 获取全局store // 获取全局store
const globalStore = useGlobalStore(); const globalStore = useGlobalStore();
if (url.indexOf('home') >= 0) { if (url.indexOf('home') >= 0) {
globalStore.setCurTabIndex(0); globalStore.setCurTabIndex(0);
} else if (url.indexOf('brand') >= 0) { } else if (url.indexOf('brand') >= 0) {
globalStore.setCurTabIndex(1); globalStore.setCurTabIndex(1);
} else if (url.indexOf('integral') >= 0) { } else if (url.indexOf('integral') >= 0) {
globalStore.setCurTabIndex(2); globalStore.setCurTabIndex(2);
} else if (url.indexOf('my') >= 0) { } else if (url.indexOf('my') >= 0) {
globalStore.setCurTabIndex(3); globalStore.setCurTabIndex(3);
} }
} else { } else {
// 内部小程序页面跳转 // 内部小程序页面跳转
uni.navigateTo({ uni.navigateTo({
url, url,
...extra, ...extra,
}); });
} }
} catch (error) { } catch (error) {
console.error('跳转处理错误:', error); console.error('跳转处理错误:', error);
// 出错时默认执行内部跳转 // 出错时默认执行内部跳转
uni.navigateTo({ uni.navigateTo({
url, url,
...extra, ...extra,
}); });
} }
break; break;
case JumpType.MINI: case JumpType.MINI:
// 跳转到其他小程序页面 // 跳转到其他小程序页面
console.log("extra:", url, extra); console.log("extra:", url, extra);
const jumpParams = { const jumpParams = {
appId: extra.appId || "", appId: extra.appId || "",
path: url, path: url,
extraData: extra.extraData || {}, extraData: extra.extraData || {},
envVersion: extra.envVersion || "release", envVersion: extra.envVersion || "release",
success: extra.success, success: extra.success,
fail: extra.fail, fail: extra.fail,
}; };
console.log("jumpParams:", jumpParams); console.log("jumpParams:", jumpParams);
if (extra.embedded || jumpParams.appId === 'wx4205ec55b793245e') { // 星妈优选的小程序都为半屏拉起 if (extra.embedded || OPEN_EMBEDDED_APPS.includes(jumpParams.appId)) {
console.log('半屏拉起', jumpParams) console.log('半屏拉起', jumpParams)
uni.openEmbeddedMiniProgram(jumpParams); uni.openEmbeddedMiniProgram(jumpParams);
} else { } else {
console.log('直接跳转', jumpParams) console.log('直接跳转', jumpParams)
uni.navigateToMiniProgram(jumpParams); uni.navigateToMiniProgram(jumpParams);
} }
break; break;
case JumpType.H5: case JumpType.H5:
// 跳转到 https 网络链接 // 跳转到 https 网络链接
if (/^https?:\/\//.test(url)) { if (/^https?:\/\//.test(url)) {
// uni-app 推荐用 webview 页面承载 H5 // uni-app 推荐用 webview 页面承载 H5
uni.navigateTo({ uni.navigateTo({
url: `/pages/webview/webview?url=${encodeURIComponent(url)}`, url: `/pages/webview/webview?url=${encodeURIComponent(url)}`,
}); });
} else { } else {
console.error("H5 跳转地址必须为 https 链接"); console.error("H5 跳转地址必须为 https 链接");
} }
break; break;
default: default:
console.error("不支持的跳转类型"); console.error("不支持的跳转类型");
} }
} }
export function formatDate(timestamp) { export function formatDate(timestamp) {
const date = new Date(timestamp); const date = new Date(timestamp);
if (isNaN(date.getTime())) { if (isNaN(date.getTime())) {
console.error('无效的时间戳:', timestamp); console.error('无效的时间戳:', timestamp);
return ''; return '';
} }
const year = date.getFullYear() const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0') const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}` return `${year}-${month}-${day}`
} }
/** /**
...@@ -112,54 +117,54 @@ export function formatDate(timestamp) { ...@@ -112,54 +117,54 @@ export function formatDate(timestamp) {
* @returns {Function} 包装后的防连点函数 * @returns {Function} 包装后的防连点函数
*/ */
export function throttleTap(fn, delay = 1000) { export function throttleTap(fn, delay = 1000) {
let timer = null; let timer = null;
let lastTime = 0; let lastTime = 0;
return function (...args) { return function (...args) {
const now = Date.now(); const now = Date.now();
if (now - lastTime < delay) { if (now - lastTime < delay) {
// 小于间隔时间,阻止执行 // 小于间隔时间,阻止执行
console.log("防连点"); console.log("防连点");
return; return;
} }
lastTime = now; lastTime = now;
clearTimeout(timer); clearTimeout(timer);
// 立即执行一次 // 立即执行一次
fn.apply(this, args); fn.apply(this, args);
timer = setTimeout(() => { timer = setTimeout(() => {
lastTime = 0; // 重置时间 lastTime = 0; // 重置时间
}, delay); }, delay);
}; };
} }
let loadingCount = 0; let loadingCount = 0;
let loadingTimer = null; let loadingTimer = null;
export function showLoading(title = "加载中") { export function showLoading(title = "加载中") {
if (loadingCount == 0) { if (loadingCount == 0) {
uni.showLoading({ uni.showLoading({
title, title,
mask: true, mask: true,
}); });
loadingTimer = setTimeout(() => { loadingTimer = setTimeout(() => {
uni.hideLoading(); uni.hideLoading();
}, 10000); }, 10000);
} }
loadingCount++; loadingCount++;
} }
export function hideLoading() { export function hideLoading() {
if (loadingCount <= 0) return; if (loadingCount <= 0) return;
loadingCount--; loadingCount--;
if (loadingCount == 0) { if (loadingCount == 0) {
loadingTimer && clearTimeout(loadingTimer); loadingTimer && clearTimeout(loadingTimer);
uni.hideLoading(); uni.hideLoading();
} }
} }
/** /**
...@@ -169,37 +174,37 @@ export function hideLoading() { ...@@ -169,37 +174,37 @@ export function hideLoading() {
* @returns {String} * @returns {String}
*/ */
const dateFormatter = (date, format = "yyyy/MM/dd") => { const dateFormatter = (date, format = "yyyy/MM/dd") => {
if (!date) return "-"; if (!date) return "-";
date = new Date( date = new Date(
typeof date === "string" && isNaN(date) typeof date === "string" && isNaN(date)
? date.replace(/-/g, "/") ? date.replace(/-/g, "/")
: Number(date) : Number(date)
); );
const o = { const o = {
"M+": date.getMonth() + 1, "M+": date.getMonth() + 1,
"d+": date.getDate(), "d+": date.getDate(),
"h+": date.getHours(), "h+": date.getHours(),
"m+": date.getMinutes(), "m+": date.getMinutes(),
"s+": date.getSeconds(), "s+": date.getSeconds(),
"q+": Math.floor((date.getMonth() + 3) / 3), "q+": Math.floor((date.getMonth() + 3) / 3),
S: date.getMilliseconds(), S: date.getMilliseconds(),
}; };
if (/(y+)/.test(format)) { if (/(y+)/.test(format)) {
format = format.replace( format = format.replace(
RegExp.$1, RegExp.$1,
(date.getFullYear() + "").substr(4 - RegExp.$1.length) (date.getFullYear() + "").substr(4 - RegExp.$1.length)
); );
} }
for (const k in o) { for (const k in o) {
if (new RegExp("(" + k + ")").test(format)) { if (new RegExp("(" + k + ")").test(format)) {
format = format.replace( format = format.replace(
RegExp.$1, RegExp.$1,
RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length) RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
); );
} }
} }
return format; return format;
}; };
export { export {
dateFormatter dateFormatter
} }
\ No newline at end of file
...@@ -528,8 +528,11 @@ const onProgressBarError = (e) => { ...@@ -528,8 +528,11 @@ const onProgressBarError = (e) => {
function testGoto195() { function testGoto195() {
return return
jump({ jump({
type: JumpType.INNER, type: JumpType.MINI,
url: '/pages/activity/1015/home' url: '/pages/my/my',
extra: {
appId: 'wxab14ac8f684ad962',
}
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment