common.js 973 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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() {
  29. this.$alert('未登录, 前往登录', '提示', {
  30. confirmButtonText: '确定',
  31. callback: action => {
  32. location.href = `/?loginbox=show`
  33. }
  34. })
  35. },
  36. noCompetence(title = "没有权限") {
  37. this.$alert(title, '提示', {
  38. confirmButtonText: '确定',
  39. callback: action => {
  40. location.go(-1)
  41. }
  42. })
  43. },
  44. }
  45. })