1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <template>
- <div class="layout" v-if="isMounted">
- <div class="header"></div>
- <div class="content">
- <nuxt />
- </div>
- <div class="footer"></div>
- <ldm-login></ldm-login>
- </div>
- </template>
- <script>
- import { getCookies } from '@/utils/auth'
- import keys from '@/keys.config'
- import { mapGetters } from 'vuex'
- export default {
- computed: {
- ...mapGetters(['userInfo', 'type', 'accessToken']),
- },
- data() {
- return {
- isMounted: false,
- }
- },
- mounted() {
- this.init()
- },
- beforeDestroy() {
- window.removeEventListener('resize', () => {})
- },
- methods: {
- init() {
- this.responseWidth()
- this.initPageData()
- },
- // 初始化数据页面公共数据
- initPageData() {
- const key = this.$route.path.split('/')[1]
- // 保存页面入口
- this.$store.commit('user/SET_TYPE', key)
- // 保存用户AppId
- this.$store.commit('user/SET_APPID', keys[key].appId)
- // 获取用户信息
- const userInfo = getCookies('userInfo')
- if (userInfo) {
- this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
- }
- // 初始化供应商信息
- this.fetchSupplierInfo()
- },
- // 获取供应商信息
- async fetchSupplierInfo() {
- const appId = this.$store.getters.appId
- try {
- const res = await this.$http.api.fetchSupplierInfo({ appId })
- this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
- } catch (error) {
- console.log(error)
- } finally {
- this.isMounted = true
- }
- },
- // 退出登录
- logout() {
- this.$store.dispatch('user/logout')
- },
- // 回到首页
- backHome() {
- const url = '/' + this.type
- if (this.$route.path === url) return
- this.$router.replace(url)
- },
- // 响应页面宽度变化
- responseWidth() {
- this.$store.commit('app/SET_SCREEN', window.innerWidth)
- window.addEventListener('resize', (e) => {
- this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
- })
- },
- },
- }
- </script>
- <style scoped lang="scss"></style>
|