cashier/utils/common.ts

35 lines
838 B
TypeScript

// 检测微信小程序是否有新版本
export const VersionUpdate = () => {
if (!uni.canIUse('getUpdateManager')) {
uni.showModal({
title: '温馨提示',
content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
});
return;
}
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate((res) => {
if (!res.hasUpdate) return;
updateManager.onUpdateReady(() => {
uni.showModal({
title: '更新提示',
content: '小程序已发布新版本,是否重启?',
success: (modalRes) => {
if (modalRes.confirm) {
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(() => {
uni.showModal({
title: '提示',
content: '请删除当前小程序后重新打开。'
});
});
});
};