common.js 1.9 KB

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