import Vue from 'vue' // import http from '@/plugins/http' // mixin Vue.mixin({ async fetch({ $axios, store, req }) { let headers = req && req.headers let res = await $axios.$get('/api/user/getInfo', {headers}); if(res && res.data) { store.commit('updateUserinfo', { userinfo: res.data || {} }) } }, components: { }, data() { return { } }, mounted() {}, computed: { userinfo() { return this.$store.state.userinfo }, hasLogined() { return !!this.userinfo.uid }, }, methods: { async needLogin() { const userInfo = await this.getUserInfo(); if (!userInfo.nickname) { this.goLogin(); } }, async needVerify() { const userInfo = await this.getUserInfo(); // 1是待审核,2审核通过,3是拒绝 if (userInfo.realname_verify_status !== '2') { this.$message.error('根据互联网相关法规要求,请先完成实名认证') this.goVerify(); } }, async getUserInfo() { let res = this.$store.state.userinfo; if (!res) { const result = await this.$axios.$get( `/api/user/getInfo` ); res = result.data; } return res; }, goVerify() { location.href = 'https://www.proginn.com/setting/user'; }, goHome() { location.href = 'https://www.proginn.com/'; }, goLogin(e, noAlert) { if(noAlert) { location.href = `https://www.proginn.com/?loginbox=show` }else { this.$alert('未登录, 前往登录', '提示', { confirmButtonText: '确定', callback: action => { location.href = `https://www.proginn.com/?loginbox=show` } }) } }, noCompetence(title = "没有权限") { this.$alert(title, '提示', { confirmButtonText: '确定', callback: action => { location.go(-1) } }) }, } })