123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <template>
- <view class="wrap" v-if="popup_show">
- <view class="popup-bg" :style="getHeight">
- <view class="popup-content" :class="{ 'popup-content-show': popup_show }">
- <view class="update-wrap">
- <image src="./images/img.png" class="top-img"></image>
- <view class="content">
- <text class="title">{{$t(`发现新版本`)}}{{ update_info.version }}</text>
-
- <view class="title-sub" v-html="update_info.info"></view>
-
- <button class="btn" v-if="downstatus < 1" @click="nowUpdate()">
- {{$t(`立即升级`)}}
- </button>
-
- <view class="sche-wrap" v-else>
-
- <view class="sche-bg">
- <view class="sche-bg-jindu" :style="lengthWidth"></view>
- </view>
- <text class="down-text">{{$t(`下载进度`)}}:{{ (downSize / 1024 / 1024).toFixed(2) }}M/{{
- (fileSize / 1024 / 1024).toFixed(2)
- }}M</text>
- </view>
- </view>
- </view>
- <image src="./images/close.png" class="close-ioc" @click="closeUpdate()"></image>
- </view>
- </view>
- </view>
- </template>
- <script>
- let vm;
- import {
- getUpdateInfo
- } from '@/api/public.js'
- export default {
- name: "appUpdate",
-
- props: {
- tabbar: {
- type: Boolean,
- default: false,
- },
- getVer: {
- type: Boolean,
- default: false,
- },
- },
- data() {
- return {
- popup_show: false,
- platform: "",
- version: "1.0.0",
- need_update: false,
- downing: false,
- downstatus: 0,
- update_info: {
- os: "",
- version: "",
- info: "",
- },
- fileSize: 0,
- downSize: 0,
- viewObj: null,
- };
- },
- created() {
- vm = this;
- if (!this.getVer) this.update()
- },
- computed: {
-
- lengthWidth: function() {
- let w = (this.downSize / this.fileSize) * 100;
- if (!w) {
- w = 0;
- } else {
- w = w.toFixed(2);
- }
- return {
- width: w + "%",
- };
- },
- getHeight() {
- let bottom = 0;
- if (this.tabbar) {
- bottom = 50;
- }
- return {
- bottom: bottom + "px",
- height: "auto",
- };
- },
- },
- methods: {
-
- update() {
-
-
- uni.getSystemInfo({
- success: function(res) {
- vm.platform = res.platform;
- console.log("手机系统信息", vm.platform);
- },
- });
-
- plus.runtime.getProperty(plus.runtime.appid, function(inf) {
- vm.version = inf.version;
- });
- console.log("当前版本", vm.version);
- this.getUpdateInfo();
-
- },
-
- getUpdateInfo() {
-
- getUpdateInfo(this.platform === "ios" ? 2 : 1)
- .then((res) => {
- console.log(res)
- if(Array.isArray(res.data)){
- return this.$emit('isNew')
- }
- const tagDate = uni.getStorageSync('app_update_time') || '',
- nowDate = new Date().toLocaleDateString();
- if (tagDate !== nowDate && !this.getVer) {
- uni.setStorageSync('app_update_time', new Date().toLocaleDateString());
- } else if ((tagDate !== nowDate) && this.getVer) {
- if (!res.data.is_force) return
- } else if (tagDate == nowDate && !this.getVer && !res.data.is_force) {
- return
- }
-
- let data = res.data;
-
- vm.update_info = data;
- if (!vm.update_info.platform) {
-
- } else {
- console.log('111111111111111')
- vm.checkUpdate();
- }
- })
- .catch((err) => {
- vm.popup_show = false
- console.log(err);
- });
- },
-
- checkUpdate() {
- vm.need_update = vm.compareVersion(vm.version, vm.update_info.version);
- if (vm.need_update) {
- vm.popup_show = true;
- if (vm.tabbar) {
-
-
- vm.viewObj = new plus.nativeObj.View("viewObj", {
- bottom: "0px",
- left: "0px",
- height: "50px",
- width: "100%",
- backgroundColor: "rgba(0,0,0,.6)",
- });
- vm.viewObj.show();
- }
- } else {
- this.$emit('isNew')
- }
- },
-
- closeUpdate() {
- if (vm.update_info.is_force) {
-
- this.platform == "android" ?
- plus.runtime.quit() :
- plus.ios
- .import("UIApplication")
- .sharedApplication()
- .performSelector("exit");
- } else {
- vm.popup_show = false;
- if (vm.viewObj) vm.viewObj.hide();
- }
- },
-
- nowUpdate() {
- if (vm.downing) return false;
- vm.downing = true;
- if (/\.apk$/.test(vm.update_info.url)) {
-
- vm.download_wgt();
- } else if (/\.wgt$/.test(vm.update_info.url)) {
-
- vm.download_wgt();
- } else {
- plus.runtime.openURL(vm.update_info.url, function() {
-
- plus.nativeUI.toast("打开错误");
- });
- }
- },
-
- download_wgt() {
- plus.nativeUI.showWaiting("下载更新文件...");
- let options = {
- method: "get",
- };
- let dtask = plus.downloader.createDownload(
- vm.update_info.url,
- options,
- function(d, status) {}
- );
- dtask.addEventListener("statechanged", function(task, status) {
- if (status === null) {} else if (status == 200) {
-
- vm.downstatus = task.state;
- switch (task.state) {
- case 3:
- vm.downSize = task.downloadedSize;
- if (task.totalSize) {
- vm.fileSize = task.totalSize;
- }
- break;
- case 4:
- vm.installWgt(task.filename);
- break;
- }
- } else {
- plus.nativeUI.closeWaiting();
- plus.nativeUI.toast("下载出错");
- vm.downing = false;
- vm.downstatus = 0;
- }
- });
- dtask.start();
- },
-
- installWgt(path) {
- plus.nativeUI.showWaiting("安装更新文件...");
- plus.runtime.install(
- path, {},
- function() {
- plus.nativeUI.closeWaiting();
-
- plus.nativeUI.alert("应用资源下载完成!", function() {
- plus.runtime.restart();
- });
- },
- function(e) {
- plus.nativeUI.closeWaiting();
-
- plus.nativeUI.alert("安装更新文件失败[" + e.code + "]:" + e.message);
- }
- );
- },
-
- compareVersion(ov, nv) {
- if (!ov || !nv || ov == "" || nv == "") {
- return false;
- }
- let b = false,
- ova = ov.split(".", 4),
- nva = nv.split(".", 4);
- for (let i = 0; i < ova.length && i < nva.length; i++) {
- let so = ova[i],
- no = parseInt(so),
- sn = nva[i],
- nn = parseInt(sn);
- if (nn > no || sn.length > so.length) {
- return true;
- } else if (nn < no) {
- return false;
- }
- }
- if (nva.length > ova.length && 0 == nv.indexOf(ov)) {
- return true;
- } else {
- return false;
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .popup-bg {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- position: fixed;
- top: 0;
- left: 0rpx;
- right: 0;
- bottom: 0;
- width: 750rpx;
- background-color: rgba(0, 0, 0, 0.6);
- z-index: 10000;
- }
- .popup-content {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .popup-content-show {
- animation: mymove 500ms;
- transform: scale(1);
- }
- @keyframes mymove {
- 0% {
- transform: scale(0);
- /*开始为原始大小*/
- }
- 100% {
- transform: scale(1);
- }
- }
- .update-wrap {
- width: 580rpx;
- border-radius: 18rpx;
- position: relative;
- display: flex;
- flex-direction: column;
- background-color: #ffffff;
- padding: 170rpx 30rpx 0;
- .top-img {
- position: absolute;
- left: 0;
- width: 100%;
- height: 256rpx;
- top: -128rpx;
- }
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-bottom: 40rpx;
- .title {
- font-size: 32rpx;
- font-weight: bold;
- color: #6526f3;
- }
- .title-sub {
- text-align: center;
- font-size: 24rpx;
- color: #666666;
- padding: 30rpx 0;
- }
- .btn {
- width: 460rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
- font-size: 30rpx;
- height: 80rpx;
- line-height: 80rpx;
- border-radius: 100px;
- background-color: #6526f3;
- margin-top: 20rpx;
- }
- }
- }
- .close-ioc {
- width: 70rpx;
- height: 70rpx;
- margin-top: 30rpx;
- }
- .sche-wrap {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: flex-end;
- padding: 10rpx 50rpx 0;
- .sche-wrap-text {
- font-size: 24rpx;
- color: #666;
- margin-bottom: 20rpx;
- }
- .sche-bg {
- position: relative;
- background-color: #cccccc;
- height: 30rpx;
- border-radius: 100px;
- width: 480rpx;
- display: flex;
- align-items: center;
- .sche-bg-jindu {
- position: absolute;
- left: 0;
- top: 0;
- height: 30rpx;
- min-width: 40rpx;
- border-radius: 100px;
- background: url(images/round.png) #5775e7 center right 4rpx no-repeat;
- background-size: 26rpx 26rpx;
- }
- }
- .down-text {
- font-size: 24rpx;
- color: #5674e5;
- margin-top: 16rpx;
- }
- }
- </style>
|