Commit 7cedc8e8 authored by spc's avatar spc

jump page/index/index

parent e53c27a5
// 导入全局store
import { useGlobalStore } from "../stores/global";
// 跳转类型枚举 // 跳转类型枚举
export const JumpType = { export const JumpType = {
INNER: 1, // 内部小程序页面跳转 INNER: 1, // 内部小程序页面跳转
...@@ -15,11 +18,40 @@ export const JumpType = { ...@@ -15,11 +18,40 @@ export const JumpType = {
export function jump({ type, url, extra = {} }) { export function jump({ type, url, extra = {} }) {
switch (type) { switch (type) {
case JumpType.INNER: case JumpType.INNER:
// 内部小程序页面跳转 try {
uni.navigateTo({
url, const pages = getCurrentPages();
...extra, const currentPage = pages[pages.length - 1];
}); const currentPath = currentPage.route;
if (url.indexOf('pages/index/index') >= 0 && currentPath.indexOf('pages/index/index') >= 0) {
// 获取全局store
const globalStore = useGlobalStore();
if (url.indexOf('home') >= 0) {
globalStore.setCurTabIndex(0);
} else if (url.indexOf('brand') >= 0) {
globalStore.setCurTabIndex(1);
} else if (url.indexOf('integral') >= 0) {
globalStore.setCurTabIndex(2);
} else if (url.indexOf('my') >= 0) {
globalStore.setCurTabIndex(3);
}
} else {
// 内部小程序页面跳转
uni.navigateTo({
url,
...extra,
});
}
} catch (error) {
console.error('跳转处理错误:', error);
// 出错时默认执行内部跳转
uni.navigateTo({
url,
...extra,
});
}
break; break;
case JumpType.MINI: case JumpType.MINI:
// 跳转到其他小程序页面 // 跳转到其他小程序页面
...@@ -36,11 +68,11 @@ export function jump({ type, url, extra = {} }) { ...@@ -36,11 +68,11 @@ export function jump({ type, url, extra = {} }) {
console.log("jumpParams:", jumpParams); console.log("jumpParams:", jumpParams);
if(extra.embedded || jumpParams.appId === 'wx4205ec55b793245e'){ // 星妈优选的小程序都为半屏拉起 if (extra.embedded || jumpParams.appId === 'wx4205ec55b793245e') { // 星妈优选的小程序都为半屏拉起
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;
...@@ -60,11 +92,11 @@ export function jump({ type, url, extra = {} }) { ...@@ -60,11 +92,11 @@ export function jump({ type, url, extra = {} }) {
} }
} }
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()
...@@ -136,7 +168,7 @@ export function hideLoading() { ...@@ -136,7 +168,7 @@ export function hideLoading() {
* @param format 字符串,需要的格式例如:'yyyy/MM/dd hh:mm:ss' * @param format 字符串,需要的格式例如:'yyyy/MM/dd hh:mm:ss'
* @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)
...@@ -169,5 +201,5 @@ export function hideLoading() { ...@@ -169,5 +201,5 @@ export function hideLoading() {
return format; return format;
}; };
export { export {
dateFormatter dateFormatter
} }
\ No newline at end of file
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