index.vue 3.29 KB
<template>
  <div class="layout">
    <template v-if="flag">
      <template v-if="list.length">
        <template v-for="item in list">
          <template v-if="item.children && item.children.length">
            <div :key="item.id">
              <template v-if="item.label != '工作台'">
                <div class="title">{{item.label}}</div>
              </template>
              <div class="box">
                <template v-for="i in item.children">
                  <div
                    :key="i.id"
                    class="item"
                    @click="jump(i)"
                  >
                    <div class="icon">
                      <img
                        :src="i.icon"
                        :alt="i.label"
                      >
                    </div>
                    {{i.label}}
                  </div>
                </template>
              </div>
            </div>
          </template>
        </template>
      </template>
      <template v-else>
        <van-empty description="暂无内容" />
      </template>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
const { subsystemInfo } = window.$fetchConfig
import { ssoApi } from '@/api'
export default {
  name: '',
  data () {
    return {
      list: [],
      flag: false
    }
  },
  activated () {
    ssoApi.getPermission().then(data => {
      if (data && data.length) {
        let [merchantProTreeResponses] = data[0].products[0].merchantProTreeResponses
        if (merchantProTreeResponses) {
          let list = merchantProTreeResponses.children
          if (list && list.length) {
            list.map(e => {
              if (e.children) {
                e.children.map(i => {
                  let [url, item] = i.menuUrl.split('@')
                  let [target, icon] = item.split('|')
                  let [link, query] = url.split('?')
                  i.icon = icon
                  i.link = link
                  i.target = target
                  i.query = query
                })
              }
            })
            console.log(list)
            this.list = list
          }
        }
      }

      this.flag = true
    })
  },
  mounted () { },
  methods: {
    jump (e) {
      let sessionId = this.getSessionId()
      let { corpId } = this.getLocalStorage('dj_scrm_corpId')
      let { link, query, target } = e
      let { path } = subsystemInfo[target]
      let url = `${path}${link}?sessionId=${sessionId}&corpId=${corpId}`
      if (query) url = `${url}&${query}`
      window.location.href = url
    }
  }
}
</script>

<style scoped lang='scss'>
.layout {
  padding: 16px 16px 66px;
  .title {
    font-weight: 500;
    font-size: 16px;
    color: #4a4a4a;
    padding: 16px 0 10px;
  }
  .box {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: center;
    min-height: 84px;
    background: #ffffff;
    box-shadow: 0px 2px 4px 0px rgba(206, 209, 222, 0.12), 0px 2px 8px 0px rgba(206, 209, 222, 0.4);
    border-radius: 4px;
    box-sizing: border-box;
    color: #333;
    font-size: 12px;
    .item {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      height: 84px;
      .icon {
        width: 40px;
        height: 40px;
        margin-bottom: 7px;
      }
    }
  }
}
</style>