App.vue 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div id="app" v-if="showPage">
  3. <router-view/>
  4. </div>
  5. </template>
  6. <script>
  7. import './assets/css/reset.css'
  8. import { createNamespacedHelpers } from 'vuex'
  9. const { mapActions: mapIndexActions } = createNamespacedHelpers('user')
  10. const { mapState: mapUserState } = createNamespacedHelpers('user')
  11. export default {
  12. name: 'App',
  13. data () {
  14. return {
  15. showPage: false, // 不控制显示时机
  16. code: ''
  17. }
  18. },
  19. created () {
  20. this.init()
  21. },
  22. computed: {
  23. ...mapUserState({
  24. userInfo: item => item.userInfo,
  25. appid: item => item.appid
  26. })
  27. },
  28. methods: {
  29. ...mapIndexActions(['getAppId', 'getUser', 'getShare']),
  30. async init () {
  31. // this.showPage = true
  32. try {
  33. await this.getAppId()
  34. await this.getCode()
  35. await this.getUser({ code: this.code })
  36. this.showPage = true
  37. // this.getShare()
  38. } catch (err) {
  39. console.log(err)
  40. }
  41. },
  42. getCode () {
  43. return new Promise((resolve, reject) => {
  44. if (location.search && this.toolClass.UrlSearch(location.search).code) {
  45. this.code = this.toolClass.UrlSearch(location.search).code
  46. let oldCode = localStorage.getItem('code')
  47. if (this.code === oldCode) {
  48. localStorage.setItem('code', this.code)
  49. this.toolClass.getCode(this.appid)
  50. } else {
  51. localStorage.setItem('code', this.code)
  52. resolve()
  53. }
  54. } else {
  55. this.toolClass.getCode(this.appid)
  56. }
  57. })
  58. }
  59. }
  60. }
  61. </script>
  62. <style>
  63. #app {
  64. width: 100%;
  65. height: 100%;
  66. position: relative;
  67. overflow: hidden;
  68. }
  69. </style>