123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import Request from '@/library/Request.js'
- const getStore =() => {
- try {
- const app = getApp()
- if (app.$store) {
- return Promise.resolve(app.$store)
- }
- } catch (err) {
- setTimeout(() => {
- getStore()
- }, 200)
- }
- }
- export default function initSys() {
- const appType = uni.getSystemInfoSync().platform;
- if (plus != null) {
- plus.runtime.getProperty(plus.runtime.appid, async (wgtinfo) => {
- try {
- let versionCode = wgtinfo.versionCode;
- let arr1 = wgtinfo.version.split('.');
- const sotre = await getStore();
-
- sotre.commit('chnangeSshowData', false);
- const res = await Request.post("sysInit", {
- code: versionCode
- })
- if (res.code == 200) {
- if (appType != "ios") {
- if (wgtinfo.versionCode < res.data.app_code) {
- sotre.commit('chnangeSshowData', false);
- const upDater = uni.requireNativePlugin("CL-UpDater");
- let options = {
- title: "升级",
- con: res.data.app_update,
- downUrl: encodeURI(res.data.android_url),
- hidCancelbtn: false,
- btnBgColor: "#ff3300",
- updateBtnText: "升级",
- topImgBg: "",
- downMsgTip: "资源下载中,请稍后...",
- };
- if (res.data.android_url.indexOf('.wgt') > -1) {
- plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fobject) {
-
- let rootPath = fobject.root.fullPath;
- upDater.wgtUpdate(options, rootPath, result => {
- if (result) {
- var pathNew = plus.io
- .convertAbsoluteFileSystem(result);
- plus.runtime.install(pathNew, {
- force: false
- }, function() {
-
- plus.runtime.restart();
- }, (e) => {
- uni.showToast({
- title: '安装升级包失败' +
- JSON
- .stringify(
- e),
- icon: 'none'
- })
- });
- }
- }, () => {
- console.log("弹框关闭了");
- });
- })
- } else {
- options.hidBackBtn = true
- options.verCode = res.data
- .app_version
- options.goBackBtnText = "进入后台"
-
- upDater.startUpdate(options, () => {});
- }
- } else if (wgtinfo.versionCode > res.data.app_code) {
- sotre.commit('chnangeSshowData', false);
- } else {
- sotre.commit('chnangeSshowData', true);
- }
- }
- }
- if (appType == "ios") {
- const getIosUpAppUrl = 'https://itunes.apple.com/cn/lookup?id=6474850968'
- const iosAppStroeUrl =
- 'https://apps.apple.com/cn/app/%E6%98%93%E8%B6%A3cbb/id6474850968';
- uni.request({
- url: getIosUpAppUrl,
- method: 'POST',
- data: {},
- success: res => {
- let arr = res.data.results[0].version.split('.');
- for (let i = 0; i < arr.length; i++) {
-
- const x = +arr[i];
-
- const y = +arr1[i];
-
- if (x < y) {
-
- sotre.commit('chnangeSshowData', false);
- return
- }
-
- else if (x > y) {
- sotre.commit('chnangeSshowData', false);
- uni.showModal({
- title: '提示',
- content: '请更新应用',
- showCancel: false,
- success(e) {
- plus.runtime.openURL(
- iosAppStroeUrl
- );
- }
- });
- return
- }
-
- else if (x == y && i == arr.length - 1) {
- sotre.commit('chnangeSshowData', true);
- return
- }
- }
- },
- fail: res => {
- console.log(res, 'shib');
- }
- });
- }
- } catch (e) {
- console.log(e)
- }
- });
- }
- }
|