app-ldm.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 { getCookies } from '@/utils/auth'
  13. import { mapGetters } from 'vuex'
  14. export default {
  15. computed: {
  16. ...mapGetters(['userInfo', 'type', 'accessToken', 'authUserId']),
  17. },
  18. head() {
  19. return {
  20. title: '德国WELLCOMET LDM® 官方查询系统',
  21. link: [{ rel: 'icon', type: 'image/x-icon', href: '/ldm.ico' }],
  22. }
  23. },
  24. data() {
  25. return {
  26. isMounted: false,
  27. }
  28. },
  29. mounted() {
  30. this.init()
  31. },
  32. beforeDestroy() {
  33. window.removeEventListener('resize', () => {})
  34. },
  35. methods: {
  36. init() {
  37. this.responseWidth()
  38. this.initPageData()
  39. },
  40. // 初始化数据页面公共数据
  41. initPageData() {
  42. const id = this.$route.params.template
  43. // 保存页面入口
  44. this.$store.commit('user/SET_TYPE', `${id}/app`)
  45. // 保存用户AppId
  46. this.$store.commit('user/SET_AUTHUSERID', id)
  47. // 获取用户信息
  48. const userInfo = getCookies('userInfo')
  49. if (userInfo && userInfo.authUserId === id) {
  50. this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
  51. }
  52. // 初始化供应商信息
  53. this.fetchSupplierInfo()
  54. },
  55. // 获取供应商信息
  56. async fetchSupplierInfo() {
  57. try {
  58. const res = await this.$http.api.fetchSupplierInfo({
  59. authUserId: this.authUserId,
  60. })
  61. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  62. this.$store.commit('user/SET_APPID', res.data.appId)
  63. if (res.data.appId) {
  64. this.checkAccountType(res.data.appId)
  65. }
  66. } catch (error) {
  67. console.log(error)
  68. } finally {
  69. this.isMounted = true
  70. }
  71. },
  72. // 校验公众号类型
  73. async checkAccountType(appId) {
  74. try {
  75. // 1订阅号,2服务号
  76. const res = this.$http.api.checkAccountType({ appId })
  77. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  78. } catch (error) {
  79. console.log(error)
  80. }
  81. },
  82. // 退出登录
  83. logout() {
  84. this.$store.dispatch('user/logout')
  85. },
  86. // 回到首页
  87. backHome() {
  88. const url = '/' + this.type
  89. if (this.$route.path === url) return
  90. this.$router.replace(url)
  91. },
  92. // 响应页面宽度变化
  93. responseWidth() {
  94. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  95. window.addEventListener('resize', (e) => {
  96. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  97. })
  98. },
  99. },
  100. }
  101. </script>
  102. <style scoped lang="scss"></style>