233 lines
7.5 KiB
JavaScript
233 lines
7.5 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const _sfc_main = {
|
||
name: "ZyUpgrade",
|
||
props: {
|
||
theme: {
|
||
//主题,目前支持green,pink,blue,yellow,red
|
||
type: String,
|
||
default: "green"
|
||
},
|
||
updateurl: {
|
||
//升级检测url,全路径
|
||
type: String,
|
||
default: ""
|
||
},
|
||
h5preview: {
|
||
//H5界面下是否预览升级
|
||
type: Boolean,
|
||
default: false
|
||
},
|
||
oldversion: {
|
||
//如果是H5,为了方便测试,可以传入一个旧版本号进来。
|
||
type: String,
|
||
default: ""
|
||
},
|
||
oldcode: {
|
||
//如果是H5,为了方便测试,可以传一个旧版本的code进来。
|
||
type: Number,
|
||
default: 0
|
||
},
|
||
appstoreflag: {
|
||
//是否启用appstore升级,如果启用,由服务端返回appstore的地址
|
||
type: Boolean,
|
||
default: false
|
||
},
|
||
noticeflag: {
|
||
//是否通知主界面无需更新
|
||
type: Boolean,
|
||
default: false
|
||
},
|
||
autocheckupdate: {
|
||
//是否页面截入时就判断升级
|
||
type: Boolean,
|
||
default: true
|
||
}
|
||
},
|
||
data() {
|
||
return {
|
||
update_flag: false,
|
||
//点击升级按钮后,显示进度条
|
||
dshow: false,
|
||
update_process: 0,
|
||
downloadTask: [],
|
||
updated2version: "",
|
||
version_url: "",
|
||
update_tips: "",
|
||
forceupgrade: false,
|
||
currentversion: this.oldversion,
|
||
versionname: "",
|
||
vesioncode: this.oldcode,
|
||
wgt_flag: 0,
|
||
wgt_url: "",
|
||
size: 0,
|
||
//开启gzip等情形下,获取不到安装包大小,可以服务端返回安装包大小
|
||
header: { Authorization: common_vendor.index.getStorageSync("token") || "token" }
|
||
};
|
||
},
|
||
mounted() {
|
||
let app_flag = false;
|
||
if ((this.h5preview || app_flag) && this.autocheckupdate) {
|
||
this.check_update();
|
||
}
|
||
},
|
||
computed: {
|
||
version() {
|
||
let retversion = "";
|
||
retversion = this.currentversion + (this.currentversion != "" && this.updated2version != "" ? "->" : "") + this.updated2version;
|
||
return retversion;
|
||
}
|
||
},
|
||
methods: {
|
||
//检测升级
|
||
check_update() {
|
||
},
|
||
updatebusiness: function(that) {
|
||
common_vendor.index.request({
|
||
url: `http://121.36.88.64/nursing-unit/api/pad/versionUpdate?platform=1&version=${that.currentversion}`,
|
||
method: "GET",
|
||
dataType: "json",
|
||
success: (res) => {
|
||
if (res.data.code == 100) {
|
||
if (res.data.data.update_url) {
|
||
that.dshow = true;
|
||
that.update_tips = res.data.data.update_tips;
|
||
that.forceupgrade = res.data.data.forceupdate == 1;
|
||
that.version_url = res.data.data.update_url;
|
||
that.updated2version = res.data.data.version;
|
||
that.wgt_flag = res.data.data.wgt_flag;
|
||
that.wgt_url = res.data.data.wgt_url;
|
||
that.size = res.data.data.size;
|
||
that.getnewbanben();
|
||
}
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: "请求升级出错:" + data.msg,
|
||
icon: "none"
|
||
});
|
||
}
|
||
},
|
||
fail() {
|
||
this.loading = false;
|
||
}
|
||
});
|
||
},
|
||
getnewbanben: function() {
|
||
this.$emit("chuandinew", this.updated2version);
|
||
},
|
||
//点击开始升级按钮,开始升级
|
||
upgrade_checked: function() {
|
||
common_vendor.index.removeStorageSync("token");
|
||
this.update_flag = true;
|
||
this.updateversion();
|
||
},
|
||
//点击取消升级按钮,取消升级
|
||
upgrade_cancel: function() {
|
||
this.dshow = false;
|
||
},
|
||
//升级过程中,点击中断升级按钮,中断升级
|
||
upgrade_break: function() {
|
||
this.downloadTask.abort();
|
||
this.update_flag = false;
|
||
},
|
||
//升级下载apk安装包的具体处理业务逻辑
|
||
updateversion: function() {
|
||
let platform = common_vendor.index.getSystemInfoSync().platform;
|
||
let that = this;
|
||
if (platform == "ios" && this.appstoreflag && that.wgt_flag != 1) {
|
||
that.dshow = false;
|
||
plus.runtime.launchApplication({
|
||
action: that.version_url
|
||
}, function(e) {
|
||
common_vendor.index.showToast({
|
||
title: "打开appstore失败",
|
||
icon: "none"
|
||
});
|
||
});
|
||
} else {
|
||
let that2 = this;
|
||
let downloadurl = that2.wgt_flag == 1 ? that2.wgt_url : that2.version_url;
|
||
let targetUrl = "http://121.36.88.64/nursing-unit/sys/common/static/" + downloadurl;
|
||
this.update_confirm = true;
|
||
this.downloadTask = common_vendor.index.downloadFile({
|
||
url: targetUrl,
|
||
header: this.header,
|
||
success: function(res) {
|
||
if (res.statusCode == 200) {
|
||
plus.runtime.install(res.tempFilePath, {
|
||
force: false
|
||
}, function() {
|
||
plus.runtime.restart();
|
||
}, function(e) {
|
||
common_vendor.index.__f__("error", "at component/zy-upgrade/zy-upgrade.vue:221", "install fail...", JSON.stringify(e));
|
||
common_vendor.index.showToast({
|
||
title: "升级失败",
|
||
icon: "none"
|
||
});
|
||
});
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: "下载失败,网络错误",
|
||
icon: "none"
|
||
});
|
||
}
|
||
},
|
||
fail: function(e) {
|
||
common_vendor.index.showToast({
|
||
title: "下载失败:" + e.errMsg,
|
||
icon: "none"
|
||
});
|
||
this.update_flag = false;
|
||
},
|
||
complete: function() {
|
||
}
|
||
});
|
||
this.downloadTask.onProgressUpdate(function(res) {
|
||
that2.update_process = res.progress;
|
||
if (res.progress == Infinity) {
|
||
let progress = res.totalBytesWritten / that2.size * 100;
|
||
if (progress > 100) {
|
||
progress = 100;
|
||
}
|
||
that2.update_process = progress;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
};
|
||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
return common_vendor.e({
|
||
a: common_vendor.t($options.version),
|
||
b: common_vendor.n("zy-upgrade-topbg-" + $props.theme),
|
||
c: !$data.update_flag
|
||
}, !$data.update_flag ? {
|
||
d: common_vendor.t($data.update_tips)
|
||
} : {}, {
|
||
e: $data.update_flag
|
||
}, $data.update_flag ? {
|
||
f: common_vendor.t($data.update_process),
|
||
g: common_vendor.n("bg-" + $props.theme),
|
||
h: common_vendor.s("width: " + $data.update_process + "%;")
|
||
} : {}, {
|
||
i: !$data.update_flag
|
||
}, !$data.update_flag ? common_vendor.e({
|
||
j: common_vendor.n("bg-" + $props.theme),
|
||
k: common_vendor.o((...args) => $options.upgrade_checked && $options.upgrade_checked(...args)),
|
||
l: !$data.forceupgrade
|
||
}, !$data.forceupgrade ? {
|
||
m: common_vendor.n("line-" + $props.theme),
|
||
n: common_vendor.o((...args) => $options.upgrade_cancel && $options.upgrade_cancel(...args))
|
||
} : {}) : {}, {
|
||
o: $data.update_flag && !$data.forceupgrade
|
||
}, $data.update_flag && !$data.forceupgrade ? {
|
||
p: common_vendor.n("bg-" + $props.theme),
|
||
q: common_vendor.o((...args) => $options.upgrade_break && $options.upgrade_break(...args))
|
||
} : {}, {
|
||
r: common_vendor.n($data.dshow ? "show" : "")
|
||
});
|
||
}
|
||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-bf1d6c35"]]);
|
||
wx.createComponent(Component);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/component/zy-upgrade/zy-upgrade.js.map
|