common.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import Vue from 'vue'
  2. // import http from '@/plugins/http'
  3. // mixin
  4. Vue.mixin({
  5. async fetch({ $axios, store, req }) {
  6. let headers = req && req.headers
  7. let res = await $axios.$get('/api/user/getInfo', {headers});
  8. console.log(res.data)
  9. if(res && res.data) {
  10. store.commit('updateUserinfo', { userinfo: res.data || {} })
  11. }
  12. },
  13. components: {
  14. },
  15. data() {
  16. return {
  17. }
  18. },
  19. mounted() {},
  20. computed: {
  21. userinfo() {
  22. return this.$store.state.userinfo
  23. },
  24. hasLogined() {
  25. return !!this.userinfo.uid
  26. },
  27. },
  28. methods: {
  29. needLogin() {
  30. this.$axios.$get(
  31. `/api/user/getInfo`
  32. ).then(res => {
  33. }).catch(err => {
  34. this.goLogin();
  35. })
  36. },
  37. goLogin(e, noAlert) {
  38. if(noAlert) {
  39. location.href = `https://www.proginn.com/?loginbox=show`
  40. }else {
  41. this.$alert('未登录, 前往登录', '提示', {
  42. confirmButtonText: '确定',
  43. callback: action => {
  44. location.href = `https://www.proginn.com/?loginbox=show`
  45. }
  46. })
  47. }
  48. },
  49. noCompetence(title = "没有权限") {
  50. this.$alert(title, '提示', {
  51. confirmButtonText: '确定',
  52. callback: action => {
  53. location.go(-1)
  54. }
  55. })
  56. },
  57. }
  58. })