common.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if(res && res.data) {
  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. async needLogin() {
  29. Vue.hasMessage = true
  30. const userInfo = await this.getUserInfo();
  31. if (!userInfo.nickname) {
  32. this.goLogin();
  33. }
  34. },
  35. async needVerify() {
  36. const userInfo = await this.getUserInfo();
  37. // 1是待审核,2审核通过,3是拒绝
  38. if (userInfo.realname_verify_status !== '2') {
  39. this.$message.error('根据互联网相关法规要求,请先完成实名认证')
  40. this.goVerify();
  41. }
  42. },
  43. async getUserInfo() {
  44. let res = this.$store.state.userinfo;
  45. if (!res) {
  46. const result = await this.$axios.$get(
  47. `/api/user/getInfo`
  48. );
  49. res = result.data;
  50. }
  51. return res;
  52. },
  53. goVerify() {
  54. location.href = 'https://www.proginn.com/setting/user';
  55. },
  56. goHome() {
  57. location.href = 'https://www.proginn.com/';
  58. },
  59. goLogin(e, noAlert) {
  60. if(noAlert) {
  61. location.href = `https://www.proginn.com/?loginbox=show`
  62. }else {
  63. this.$alert('未登录, 前往登录', '提示', {
  64. confirmButtonText: '确定',
  65. callback: action => {
  66. location.href = `https://www.proginn.com/?loginbox=show`
  67. }
  68. })
  69. }
  70. },
  71. noCompetence(title = "没有权限") {
  72. this.$alert(title, '提示', {
  73. confirmButtonText: '确定',
  74. callback: action => {
  75. location.go(-1)
  76. }
  77. })
  78. },
  79. }
  80. })