45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
// 存储 TabBar 跳转参数
|
|
export const setGlobalData = (key: string, data: any) => {
|
|
if (!data) {
|
|
console.error("参数必须是一个对象");
|
|
return;
|
|
}
|
|
getApp().globalData[key] = data;
|
|
};
|
|
|
|
// 获取 TabBar 跳转参数(并自动清除)
|
|
export const getGlobalData = (key: string) => {
|
|
const params = getApp().globalData[key];
|
|
if (params) {
|
|
delete getApp().globalData[key]; // 获取后自动清理
|
|
return params;
|
|
}
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* 微信小程序支付
|
|
* @param paymentParams 支付参数
|
|
* @returns Promise
|
|
*/
|
|
export const requestPayment = (paymentParams: {
|
|
timeStamp: string;
|
|
nonceStr: string;
|
|
package: string;
|
|
signType?: "MD5" | "HMAC-SHA256";
|
|
paySign: string;
|
|
}): Promise<WechatMiniprogram.GeneralCallbackResult> => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.requestPayment({
|
|
...paymentParams,
|
|
signType: paymentParams.signType || "MD5",
|
|
success: (res) => {
|
|
resolve(res);
|
|
},
|
|
fail: (err) => {
|
|
reject(err);
|
|
},
|
|
});
|
|
});
|
|
};
|