| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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 || !userInfo.nickname) {
- this.goLogin();
- }
- },
- async checkLogin(goLogin = false) {
- const userInfo = await this.getUserInfo();
- if (!userInfo || !userInfo.nickname) {
- this.$message.error('请先登录!')
- if (goLogin) {
- const { app } = this.$deviceType
-
- if (app) {
- location.href = 'proginn://login'
- } else if (location.origin.indexOf('local') !== 1 || location.origin.indexOf('dev') !== 1 ) {
- location.href = 'https://dev.test.proginn.com/?loginbox=show'
- } else {
- location.href = 'https://www.proginn.com/?loginbox=show'
- }
- }
- return false
- }
- return true
- },
- 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.$message.closeAll()
- this.$alert('未登录, 前往登录', '提示', {
- confirmButtonText: '确定',
- callback: action => {
- location.href = `/?loginbox=show`
- }
- })
- }
- },
- noCompetence(title = "没有权限") {
- this.$alert(title, '提示', {
- confirmButtonText: '确定',
- callback: action => {
- location.go(-1)
- }
- })
- },
- async updateUserInfo() {
- let res = await this.$axios.$get('/api/user/getInfo');
- console.log('res', res.data)
- if (res && res.data) {
- this.$store.commit('updateUserinfo', { userinfo: res.data || {} })
- }
- },
- }
- })
|