123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <script>
- const _ = require("lodash");
- import jwt from "jsonwebtoken";
- import {
- mapState,
- mapMutations,
- createNamespacedHelpers
- } from "vuex";
- export default {
- globalData: {
- version: plus.runtime.version
- },
- onLaunch: function() {
- // this.checkVersion();
- if (process.env.VUE_APP_PLATFORM === "app-plus") {
- // plus.screen.lockOrientation('portrait-secondary');
- plus.screen.lockOrientation("portrait-primary");
- }
- },
- onShow: function() {
- this.checkUser();
- // console.log('App Show')
- },
- onHide: function() {
- // console.log('App Hide')
- },
- methods: {
- // 检查用户
- async checkUser() {
- if (this.user.id) return;
- const token = uni.getStorageSync("token");
- if (!token) {
- uni.redirectTo({
- url: "/pages/login/index",
- });
- } else {
- const tokenObject = jwt.decode(token);
- if (tokenObject) {
- this.setUser(tokenObject);
- uni.redirectTo({
- url: "/pages/home/index",
- });
- }
- }
- },
- //检查版本
- checkVersion() {
- uni.request({
- method: "get",
- url: "http://broadcast.waityou24.cn/files/sps/appVersion.json",
- success: (res) => {
- const {
- version,
- url
- } = res.data;
- if (getApp().globalData.version === version) return;
- uni.showModal({
- title: "更新",
- content: "有新版本,是否下载?",
- success: (res) => {
- if (res.confirm) {
- // 下载app
- this.toUpdateAPK(url);
- }
- },
- });
- },
- });
- },
- // 更新
- toUpdateAPK(url) {
- if (!url) return;
- uni.showLoading({
- title: "更新中……",
- });
- uni.downloadFile({
- url,
- success: (res) => {
- uni.hideLoading();
- if (res.statusCode == 200) {
- uni.showModal({
- title: "",
- content: "更新成功,确定现在重启吗?",
- confirmText: "重启",
- confirmColor: "#EE8F57",
- success: (modalRes) => {
- if (modalRes.confirm) {
- plus.runtime.install(
- res.tempFilePath, {
- force: true
- },
- function(res) {
- plus.runtime.restart();
- }
- );
- }
- },
- });
- }
- },
- });
- // const task = plus.downloader.createDownload(url, {}, function (d, status) {
- // console.log(d, status);
- // if (status === 200) {
- // // 安装
- // plus.runtime.install(
- // plus.io.convertLocalFileSystemURL(d.filename, {}, {}, function (error) {
- // uni.showToast({
- // title: '更新失败',
- // mask: false,
- // })
- // })
- // )
- // }
- // });
- // task.start();
- },
- },
- computed: {
- ...mapState(["user"]),
- },
- };
- </script>
- <style lang="scss">
- @import "uview-ui/index.scss";
- @import "@/static/icon/iconfont.css";
- /*每个页面公共css */
- </style>
|