NurseStationPersonApp/pages/startup/startup.vue

153 lines
3.3 KiB
Vue
Raw Normal View History

2022-11-03 18:16:30 +08:00
<template>
<view class="app">
2022-11-15 15:47:42 +08:00
<image src="../../static/logo.png" mode=""></image>
2022-11-03 18:16:30 +08:00
<view class="title">
2023-04-13 16:02:47 +08:00
泉医助手
2022-11-03 18:16:30 +08:00
</view>
2022-12-01 17:05:15 +08:00
<u-toast ref="uToast" />
2022-11-03 18:16:30 +08:00
</view>
</template>
<script>
2022-12-01 17:05:15 +08:00
import {
2023-04-13 16:02:47 +08:00
createMobileToken
2022-12-01 17:05:15 +08:00
} from '@/api/login/index.js'
import {
appFileInfoByOneId
2023-04-13 16:02:47 +08:00
} from '@/api/startup/index.js'
2022-11-03 18:16:30 +08:00
export default {
data() {
return {
2022-12-01 17:05:15 +08:00
apknumber: null,
2022-11-03 18:16:30 +08:00
};
},
2022-11-10 10:51:44 +08:00
onShow() {
2023-04-13 16:02:47 +08:00
createMobileToken().then(res => {
uni.setStorageSync("token", res.data.token)
})
2022-12-01 17:05:15 +08:00
//自动更新
2023-02-23 09:54:22 +08:00
var that = this;
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
2023-04-13 16:02:47 +08:00
that.apknumber = wgtinfo.version
2023-02-23 09:54:22 +08:00
appFileInfoByOneId().then(res => {
2023-04-13 16:02:47 +08:00
if (res.fileVersion > that.apknumber) {
2023-02-23 09:54:22 +08:00
uni.showToast({
title: '有新的版本发布,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
mask: false,
duration: 5000,
icon: "none"
});
var dtask = plus.downloader.createDownload(
res.fileUrl, {},
function(d, status) {
//下载完成
if (status == 200) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(d
.filename), {}, {}, function(error) {
uni.showToast({
title: '安装失败',
mask: false,
duration: 1500
});
})
} else {
uni.showToast({
title: '更新失败',
mask: false,
duration: 1500
});
}
});
try {
dtask.start(); // 开启下载的任务
var prg = 0;
var showLoading = plus.nativeUI.showWaiting(
"正在下载"); //创建一个showWaiting对象
dtask.addEventListener('statechanged', function(
task,
status
) {
// 给下载任务设置一个监听 并根据状态 做操作
switch (task.state) {
case 1:
showLoading.setTitle("正在下载");
break;
case 2:
showLoading.setTitle("已连接到服务器");
break;
case 3:
prg = parseInt(
(parseFloat(task.downloadedSize) /
parseFloat(task.totalSize)) *
100
);
showLoading.setTitle(" 正在下载" + prg + "% ");
break;
case 4:
plus.nativeUI.closeWaiting();
//下载完成
break;
}
});
} catch (err) {
plus.nativeUI.closeWaiting();
uni.showToast({
title: '更新失败',
mask: false,
duration: 1500
});
that.info();
}
} else {
that.info();
}
})
})
2022-12-01 17:05:15 +08:00
},
methods: {
info() {
var that = this
2023-04-13 16:02:47 +08:00
const nursePersonId = uni.getStorageSync("nursePersonId")
if (!nursePersonId) {
uni.reLaunch({
url: "/pages/login/login"
})
} else {
uni.switchTab({
url: "/pages/homepage/homepage"
})
2022-11-10 10:51:44 +08:00
}
}
2022-11-03 18:16:30 +08:00
},
}
</script>
<style lang="scss">
2023-04-13 16:02:47 +08:00
.app {
height: 100vh;
background-color: #fff;
}
2022-11-03 18:16:30 +08:00
image {
2023-04-13 16:02:47 +08:00
width: 390rpx;
height: 380rpx;
2022-11-03 18:16:30 +08:00
position: absolute;
top: 28%;
2023-04-13 16:02:47 +08:00
margin-left: 50%;
transform: translateX(-50%);
2022-11-03 18:16:30 +08:00
}
.title {
width: 80%;
height: 48rpx;
font-size: 49rpx;
text-align: center;
font-family: DengXian;
font-weight: bold;
color: #000000;
position: absolute;
2023-04-13 16:02:47 +08:00
top: 55%;
2022-11-03 18:16:30 +08:00
left: 10%;
}
</style>