app-ldm.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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', 'authUserId']),
  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 id = this.$route.params.template
  38. // 保存页面入口
  39. this.$store.commit('user/SET_TYPE', `${id}/app`)
  40. // 保存用户AppId
  41. this.$store.commit('user/SET_AUTHUSERID', id)
  42. // 获取用户信息
  43. const userInfo = getCookies('userInfo')
  44. if (userInfo && userInfo.authUserId === id) {
  45. this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
  46. }
  47. // 初始化供应商信息
  48. this.fetchSupplierInfo()
  49. },
  50. // 获取供应商信息
  51. async fetchSupplierInfo() {
  52. try {
  53. const res = await this.$http.api.fetchSupplierInfo({
  54. authUserId: this.authUserId,
  55. })
  56. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  57. this.$store.commit('user/SET_APPID', res.data.appId)
  58. } catch (error) {
  59. console.log(error)
  60. } finally {
  61. this.isMounted = true
  62. }
  63. },
  64. // 退出登录
  65. logout() {
  66. this.$store.dispatch('user/logout')
  67. },
  68. // 回到首页
  69. backHome() {
  70. const url = '/' + this.type
  71. if (this.$route.path === url) return
  72. this.$router.replace(url)
  73. },
  74. // 响应页面宽度变化
  75. responseWidth() {
  76. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  77. window.addEventListener('resize', (e) => {
  78. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  79. })
  80. },
  81. },
  82. }
  83. </script>
  84. <style scoped lang="scss"></style>