app-ldm.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 keys from '@/keys.config'
  14. import { mapGetters } from 'vuex'
  15. export default {
  16. computed: {
  17. ...mapGetters(['userInfo', 'type', 'accessToken']),
  18. },
  19. data() {
  20. return {
  21. isMounted: false,
  22. }
  23. },
  24. mounted() {
  25. this.init()
  26. },
  27. beforeDestroy() {
  28. window.removeEventListener('resize', () => {})
  29. },
  30. methods: {
  31. init() {
  32. this.responseWidth()
  33. this.initPageData()
  34. },
  35. // 初始化数据页面公共数据
  36. initPageData() {
  37. const key = this.$route.path.split('/')[1]
  38. // 保存页面入口
  39. this.$store.commit('user/SET_TYPE', key)
  40. // 保存用户AppId
  41. this.$store.commit('user/SET_APPID', keys[key].appId)
  42. // 获取用户信息
  43. const userInfo = getCookies('userInfo')
  44. if (userInfo) {
  45. this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
  46. }
  47. // 初始化供应商信息
  48. this.fetchSupplierInfo()
  49. },
  50. // 获取供应商信息
  51. async fetchSupplierInfo() {
  52. const appId = this.$store.getters.appId
  53. try {
  54. const res = await this.$http.api.fetchSupplierInfo({ appId })
  55. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  56. } catch (error) {
  57. console.log(error)
  58. } finally {
  59. this.isMounted = true
  60. }
  61. },
  62. // 退出登录
  63. logout() {
  64. this.$store.dispatch('user/logout')
  65. },
  66. // 回到首页
  67. backHome() {
  68. const url = '/' + this.type
  69. if (this.$route.path === url) return
  70. this.$router.replace(url)
  71. },
  72. // 响应页面宽度变化
  73. responseWidth() {
  74. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  75. window.addEventListener('resize', (e) => {
  76. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  77. })
  78. },
  79. },
  80. }
  81. </script>
  82. <style scoped lang="scss"></style>