common.js 2.0 KB

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