123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * 检查app版本是否需要升级
- */
- const checkVersion = ({
- name, //最新版本名称
- code, //最新版本号
- content, //更新内容
- url, //下载链接
- forceUpdate //是否强制升级
- }) => {
- const str = uni.getSystemInfoSync().appWgtVersion; //当前App版本号
-
- //const selfVersionCode =Version.split('.');
- const parts = str.split('.').map(Number);
- //console.log(parts)
- let selfVersionCode = 0;
- for (let i = 0; i < parts.length; i++) {
- selfVersionCode += parts[i] * Math.pow(10, (parts.length - 1 - i) ); // 乘以10的幂并累加
- }
-
- //线上版本号高于当前,进行在线升级
- if (code > selfVersionCode) {
- let platform = uni.getSystemInfoSync().platform //手机平台
- //安卓手机弹窗升级
- //console.log(111)
- if (platform === 'android') {
- // console.log(222)
- // console.log(getCurrentPageRoute())
- //当前页面不是升级页面跳转防止多次打开
- if (getCurrentPageRoute() !== 'pages/lq-upgrade/upgrade') {
- //console.log(333)
- uni.navigateTo({
- url: '/pages/lq-upgrade/upgrade',
- success() {
- // console.log(444)
- uni.$emit('upgrade-app', {
- name,
- content,
- url,
- forceUpdate
- })
- }
- })
- }
- }
- //IOS无法在线升级提示到商店下载
- else {
- uni.showModal({
- title: '发现新版本 ' + newVersionName,
- content: '请到App store进行升级',
- showCancel: false
- })
- }
- }
- }
- //获取当前页面url
- const getCurrentPageRoute = () => {
- let currentRoute;
- let pages = getCurrentPages() // 获取栈实例
- if (pages&&pages.length) {
- currentRoute = pages[pages.length - 1].route;
- }
- return currentRoute
- }
- export default checkVersion
|