app-ldm.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="layout" v-if="isMounted">
  3. <div class="header"></div>
  4. <div class="content">
  5. <nuxt />
  6. </div>
  7. <div class="footer"></div>
  8. <ldm-login></ldm-login>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapGetters } from 'vuex'
  13. export default {
  14. computed: {
  15. ...mapGetters([
  16. 'userInfo',
  17. 'accessToken',
  18. 'authUserId',
  19. 'appId',
  20. 'accountType',
  21. 'routePrefix',
  22. ]),
  23. },
  24. head() {
  25. return {
  26. title: '德国WELLCOMET LDM® 官方查询系统',
  27. link: [{ rel: 'icon', type: 'image/x-icon', href: '/ldm.ico' }],
  28. }
  29. },
  30. data() {
  31. return {
  32. isMounted: false,
  33. }
  34. },
  35. mounted() {
  36. this.init()
  37. },
  38. beforeDestroy() {
  39. window.removeEventListener('resize', () => {})
  40. },
  41. methods: {
  42. init() {
  43. this.responseWidth()
  44. this.initPageData()
  45. },
  46. // 初始化数据页面公共数据
  47. initPageData() {
  48. // 获取供应商id
  49. const authUserId = parseInt(this.$route.params.template)
  50. const routePrefix = `/${authUserId}/ldm`
  51. // 保存页面路由前缀
  52. this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
  53. // 保存用户AppId
  54. this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
  55. // 获取用户信息
  56. let userInfo = this.$getStorage(routePrefix, 'userInfo')
  57. if (userInfo && userInfo.authUserId === authUserId) {
  58. this.$store.commit('user/SET_USER_INFO', userInfo)
  59. }
  60. // 初始化供应商信息
  61. this.fetchSupplierInfo()
  62. },
  63. // 获取供应商信息
  64. async fetchSupplierInfo() {
  65. try {
  66. const res = await this.$http.api.fetchSupplierInfo({
  67. authUserId: this.authUserId,
  68. })
  69. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  70. this.$store.commit('user/SET_APPID', res.data.appId)
  71. // 如果appId存在
  72. if (res.data.appId) {
  73. this.checkAccountType(res.data.appId)
  74. }
  75. } catch (error) {
  76. console.log(error)
  77. } finally {
  78. this.isMounted = true
  79. // 清除缓存
  80. this.refreshCacheData()
  81. }
  82. },
  83. // 校验公众号类型
  84. async checkAccountType(appId) {
  85. try {
  86. // 1订阅号,2服务号
  87. const res = await this.$http.api.checkAccountType({ appId })
  88. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  89. } catch (error) {
  90. console.log(error)
  91. }
  92. },
  93. // 退出登录
  94. logout() {
  95. this.$store.dispatch('user/logout')
  96. console.log(this.routePrefix)
  97. this.$removeStorage(this.routePrefix, 'userInfo')
  98. this.backHome()
  99. },
  100. // 回到首页
  101. backHome() {
  102. if (this.$route.path === this.routePrefix) return
  103. this.$router.replace(this.routePrefix)
  104. },
  105. // 响应页面宽度变化
  106. responseWidth() {
  107. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  108. window.addEventListener('resize', (e) => {
  109. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  110. })
  111. },
  112. // 数据初始化刷新浏览器
  113. refreshCacheData() {
  114. this.$removeStorage(this.routePrefix, 'club_list_data')
  115. },
  116. },
  117. }
  118. </script>
  119. <style scoped lang="scss"></style>