App.vue 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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', 'putShare']),
  30. async init () {
  31. try {
  32. await this.getAppId()
  33. await this.getCode()
  34. await this.getUser({ code: this.code })
  35. this.showPage = true
  36. this.putShare()
  37. } catch (err) {
  38. console.log(err)
  39. }
  40. },
  41. getCode () {
  42. return new Promise((resolve, reject) => {
  43. if (location.search && this.toolClass.UrlSearch(location.search).code) {
  44. this.code = this.toolClass.UrlSearch(location.search).code
  45. let oldCode = localStorage.getItem('code')
  46. if (this.code === oldCode) {
  47. localStorage.setItem('code', this.code)
  48. this.toolClass.getCode(this.appid)
  49. } else {
  50. localStorage.setItem('code', this.code)
  51. resolve()
  52. }
  53. } else {
  54. this.toolClass.getCode(this.appid)
  55. }
  56. })
  57. }
  58. }
  59. }
  60. </script>
  61. <style>
  62. #app {
  63. width: 100%;
  64. height: 100%;
  65. position: relative;
  66. overflow: hidden;
  67. }
  68. </style>