common.js 1.1 KB

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