Files
cmgd-mini-app/utils/helper.ts
2026-01-16 03:58:57 +08:00

112 lines
2.4 KiB
TypeScript

const tabbar_pages = [
'/pages/index/index',
'/pages/todo/todoList',
'/pages/mine/index',
]
export const navigateTo = (url : string) => {
let is_tabbar_pages = false
tabbar_pages.forEach(item => {
if (url.indexOf(item) === 0) {
is_tabbar_pages = true
}
})
if (is_tabbar_pages) {
switchTab(url)
} else {
uni.navigateTo({
url: url
})
}
}
export const switchTab = (url : string) => {
uni.switchTab({
url: url
})
}
export const goToLoginPage = (redirect_url ?: string) => {
navigateTo('/pages/login/index?redirect_url=' + redirect_url)
}
// export const showWechatImg = () => {
// uni.previewImage({
// urls: ['https://qn.19year.cn/20250329143234415bb1067.jpg']
// })
// }
// export const showWechatPayImg = () => {
// uni.previewImage({
// urls: ['https://qn.19year.cn/20250330193232a6aca4595.jpg']
// })
// }
// export const goToOtherMiniProgram = async () => {
// try {
// const res = await fetchConfig();
// console.log('config response:', res);
// const appid = res.go_to_app_id;
// const path = res.go_to_app_path;
// uni.navigateToMiniProgram({
// appId: appid, // 替换为目标小程序的appid
// path: path,
// success(res) {
// console.log('跳转成功', res);
// },
// fail(err) {
// console.error('跳转失败', err);
// }
// });
// } catch (error) {
// console.error('Failed to load shop config:', error);
// uni.showToast({
// title: '加载失败',
// icon: 'none'
// });
// }
// }
// export const showPayImgs = async () => {
// try {
// const res = await fetchConfig();
// console.log('config response:', res);
// // 注意这里可能要根据你的实际数据结构调整
// const store_qr_codes = res.pay_qr_code?.map(item => item.url) || [];
// if (store_qr_codes.length === 0) {
// uni.showToast({
// title: '暂无图片',
// icon: 'none'
// });
// return;
// }
// console.log('preview images:', store_qr_codes);
// uni.previewImage({
// urls: store_qr_codes
// });
// } catch (error) {
// console.error('Failed to load shop config:', error);
// uni.showToast({
// title: '加载失败',
// icon: 'none'
// });
// }
// }
export const clearReactiveData = (obj) => {
for (const key in obj) {
delete obj[key]
}
}
// export const switchCart = (type) => {
// uni.setStorageSync('SHOPPING_CART_TYPE', type)
// uni.switchTab({ url: '/pages/cart/index' })
// }