init
This commit is contained in:
15
utils/debounce.js
Normal file
15
utils/debounce.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 防抖函数
|
||||
* @param {Function} fn 需要防抖的函数
|
||||
* @param {number} delay 延迟时间,单位毫秒
|
||||
* @returns {Function} 返回防抖处理后的函数
|
||||
*/
|
||||
export function debounce(fn, delay = 300) {
|
||||
let timer = null;
|
||||
return function (...args) {
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(this, args);
|
||||
}, delay);
|
||||
};
|
||||
}
|
||||
112
utils/helper.ts
Normal file
112
utils/helper.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
|
||||
import {
|
||||
fetchConfig
|
||||
} from '../api/index';
|
||||
|
||||
|
||||
const tabbar_pages = [
|
||||
'/pages/index/index',
|
||||
'/pages/cart/index',
|
||||
'/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' })
|
||||
// }
|
||||
Reference in New Issue
Block a user