| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <script>
- import { mapState, mapMutations } from 'vuex';
- import BaseTool from '@/utils/tool';
- // 需要登录才能访问的 tabBar 页面路径(首页允许未登录浏览)
- const TAB_NEED_LOGIN = ['/pages/operate/operate', '/pages/middle/middle', '/pages/tidings/tidings', '/pages/my/my'];
- // 免登录可查看的普通页面白名单(扫码查看设备详情等场景)
- const PUBLIC_PAGES = ['/pages/equipment-detail/equipment-detail'];
- export default {
- mixins: [{
- onShow() {
- // 全局页面鉴权:未登录时记录来源页面并跳转登录
- const pages = getCurrentPages();
- if (!pages || pages.length === 0) return;
- const page = pages[pages.length - 1];
- const route = '/' + page.route;
- // 登录页、微信授权回调页不做鉴权,不记录回跳
- if (route === '/pages/login/login') return;
- if (route === '/pages/setting/wechat-oauth') return;
- // 首页、白名单页面允许未登录浏览,其他页面需要登录
- if (route === '/pages/home/home') return;
- if (PUBLIC_PAGES.indexOf(route) !== -1) return;
- if (!BaseTool.UserUtil.isLogin()) {
- // 记录当前页面路径(含参数),登录成功后回跳
- try {
- const opts = page.options || (page.$page && page.$page.options) || {};
- const query = Object.keys(opts)
- .map(k => k + '=' + encodeURIComponent(opts[k]))
- .join('&');
- const isTab = TAB_NEED_LOGIN.indexOf(route) !== -1;
- uni.setStorageSync('login_back_url', route + (query ? '?' + query : ''));
- uni.setStorageSync('login_back_is_tab', isTab);
- } catch (e) {}
- uni.navigateTo({ url: '/pages/login/login' });
- }
- }
- }],
- methods: {
- ...mapMutations(['_login', '_userInfo'])
- },
- onLaunch: function () {
- const token = uni.getStorageSync('token');
- if (token) {
- this._login(token);
- }
- const userInfo = uni.getStorageSync('userInfo');
- if (userInfo) {
- this._userInfo(userInfo);
- }
- // #ifdef MP-WEIXIN
- const updateManager = uni.getUpdateManager();
- updateManager.onCheckForUpdate(function (res) {
- // 请求完新版本信息的回调
- console.log(res.hasUpdate);
- });
- updateManager.onUpdateReady(function (res) {
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate();
- }
- }
- });
-
- });
- updateManager.onUpdateFailed(function (res) {
- // 新的版本下载失败
- });
- // #endif
- // uni.navigateTo({
- // url:'pages/login/login'
- // })
- },
- onShow: function () {},
- onHide: function () {}
- };
- </script>
- <style lang="scss">
- @import 'uview-ui/index.scss';
- /*每个页面公共css */
- @import '/static/common/css/main.css';
- @import '/static/common/css/icon.css';
- @import '/static/common/css/state.css';
- </style>
|