hyingbo
2 天以前 5636ee8eb5d1108668d0abf1e425268bde14922d
src/views/dashboard/Analysis.vue
@@ -1,17 +1,25 @@
<template>
  <Component :is="currentSignage" :userType="userType" :productionCode="productionCode"
  <Component :is="currentSignage"
             :userType="userType"
             :productionCode="productionCode"
             :workshopSectionProductionCode="workshopSectionProductionCode"
             v-if="[1,2,3,4].includes(userType)"
             >
  </Component>
  <div v-else>  <!-- 与组件渲染互斥 -->
    <img src="@/assets/index.png" style="width: 100%;height: 785px">
  </div>
</template>
<script>
  import signageApi from '@/api/signage'
  import MdcManagerSignage from './mdcIndex/MdcManagerSignage.vue'
  import DncManagerSignage from './dncIndex/DncManagerSignage.vue'
  export default {
    name: "Analysis",
    components: {
      MdcManagerSignage,
      DncManagerSignage
    },
    data() {
@@ -20,7 +28,7 @@
        productionCode: '',
        branchFactoryProductionCode: '',
        workshopSectionProductionCode: '',
        userType: ''
        userType: '',
      }
    },
    created() {
@@ -28,20 +36,27 @@
    },
    methods: {
      showModuleByUserInfo() {
        const id = JSON.parse(localStorage.getItem('pro__Login_Userinfo')).value.id
        // 安全处理:先判断localStorage中是否存在用户信息,避免JSON.parse报错
        const userInfoStr = localStorage.getItem('pro__Login_Userinfo')
        if (!userInfoStr) {
          this.currentSignage = '' // 无用户信息时不渲染组件
          return
        }
        const id = JSON.parse(userInfoStr).value.id
        signageApi.getUserByIdApi(id)
          .then(res => {
            console.log("res", res.userType)
            this.userType = res.userType
            this.userType = res.userType // 赋值后自动触发条件渲染判断
            // 根据userType匹配对应组件(恢复case1和case4的逻辑)
            switch (this.userType) {
              // case 1:
              //   //刀具管理
              //   this.currentSignage = 'EquipmentSignage'
              //   break
              // case 2:
              //   //mdc
              //   this.currentSignage = 'WorkshopSectionSignage'
              //   break
              case 2:
                // mdc
                this.currentSignage = 'MdcManagerSignage'
                break
              case 3:
                //dnc
                this.currentSignage = 'DncManagerSignage'
@@ -55,6 +70,12 @@
                break
            }
          })
          .catch(err => {
            // 接口请求失败时,默认显示图片
            console.error('获取用户类型失败:', err)
            this.userType = ''
            this.currentSignage = ''
          })
      }
    }
  }