Pārlūkot izejas kodu

Merge branch 'dev4.0' into debug

shanbinzhang 4 dienas atpakaļ
vecāks
revīzija
7e8167c7d5

+ 4 - 0
src/api/system/common.js

@@ -24,5 +24,9 @@ export default{
     //获取用户信息
     userInfo:()=>{
         return get('/user/base_info',{})
+    },
+
+    menuAuth: () => {
+        return get('/user/auth_list')
     }
 }

+ 52 - 0
src/hooks/usePermissionMenu.js

@@ -0,0 +1,52 @@
+import commonApi from '@/api/system/common'
+import {$confirmDialog} from '@/plugin/dialog'
+
+export function usePermissionMenu(){
+
+    async function getMenu(){
+      return await commonApi.menuAuth()
+    }
+
+
+    const menu = [
+      {  
+        title: '研报',
+        path: '/etaReport/index',
+      },
+      {  
+        title: '图库',
+        path: '/etaChart/index',
+      },
+    ]
+
+    async function getPermissionMenu() {
+      const res = await getMenu()
+      if(res.Ret !== 200) return 
+
+      if(res.Data.ReportPermissions||res.Data.ChartPermissions) {
+        let haveReport = res.Data.ReportPermissions ? true : false,
+            haveChart = res.Data.ChartPermissions ? true : false;
+        
+        let arr = menu.map( _ => ({
+          ..._,
+          show: _.path==='/etaReport/index' ? haveReport : haveChart
+        }))
+
+        return arr.filter(_ =>_.show);
+      }else {
+        $confirmDialog({
+          header:'提示',
+          body: '您无菜单权限,请联系管理员!',
+          confirmBtn:'知道了',
+          cancelBtn:null,
+          closeBtn:false
+        }).then(()=>{
+        });
+      }  
+    }
+
+    return {
+        getMenu,
+        getPermissionMenu
+    }
+}

+ 17 - 2
src/layout/Index.vue

@@ -4,11 +4,26 @@ import { computed } from 'vue';
 import AudioBox from '@/components/Audio.vue'
 import { useRoute, useRouter } from 'vue-router';
 import Aslide from './components/Aslide.vue'
+import { usePermissionMenu } from '@/hooks/usePermissionMenu'
 
 const {getUserInfo,userInfo}=useUserInfo()
 const router=useRouter()
 const route= useRoute()
 
+const { getPermissionMenu } = usePermissionMenu()
+
+const menu = ref([])
+async function init() {
+	const res = await getPermissionMenu()
+	menu.value = res;
+	if(!res.length) {
+		router.replace('/404')
+	}else {
+		router.replace(menu.value[0].path)
+	}
+}
+init()
+
 getUserInfo()
 
 const isShowAslide = computed(() => {
@@ -39,9 +54,9 @@ async function handleLoginOut(){
     <div class="flex header">
 			<div class="flex">
       	<img class="logo" src="@/assets/imgs/logo.png" alt="" />
-				<Aslide v-if="isShowAslide"/>
+				<Aslide v-if="isShowAslide" :menu="menu"/>
 			</div>
-			<div class="fav-btn" @click="$router.push('/etaChart/favorite')">我的收藏</div>
+			<div class="fav-btn" @click="$router.push('/etaChart/favorite')">{{menu.length ? '我的收藏':''}}</div>
       <t-popup placement="bottom-left" overlayInnerClassName="header-userInfo-pop-wrap">
 				<template #content>
 					<div class="content">

+ 21 - 12
src/layout/components/Aslide.vue

@@ -1,23 +1,32 @@
 <script setup>
-import { ref } from 'vue'
+import { ref, watch } from 'vue'
 import { useRouter } from 'vue-router'
 import { useRoute } from 'vue-router'
 
 const route = useRoute()
 const router = useRouter()
 
-const menu = [
-  {  
-    title: '研报',
-    path: '/etaReport/index'
-  },
-  {  
-    title: '图库',
-    path: '/etaChart/index'
-  },
-]
+const props = defineProps({
+  menu: Array
+})
+
+// const menu = [
+//   {  
+//     title: '研报',
+//     path: '/etaReport/index'
+//   },
+//   {  
+//     title: '图库',
+//     path: '/etaChart/index'
+//   },
+// ]
 const activeMenu = ref(route.path)
 
+watch(() => route.path,
+  (newpath) => {
+    activeMenu.value = newpath
+  }
+)
 function handleClickItem(value) {
   console.log(value)
   if(value !== route.path) {
@@ -27,7 +36,7 @@ function handleClickItem(value) {
 </script>
 <template>
   <t-head-menu v-model="activeMenu" theme="light" @change="handleClickItem">
-    <t-menu-item :value="item.path" v-for="item in menu" :key="item.path">{{item.title}}</t-menu-item>
+    <t-menu-item :value="item.path" v-for="item in props.menu" :key="item.path">{{item.title}}</t-menu-item>
   </t-head-menu>
 </template>
 <style scoped lang="scss">

+ 2 - 1
src/router/index.js

@@ -13,7 +13,8 @@ const routes = [
   ...appAllRoutes,
   {
     path:'/',
-    redirect: '/etaReport/index'
+    // redirect: '/etaReport/index'
+    component:()=>import('@/layout/Index.vue'),
   },
   {
     path:'/login',

+ 21 - 1
src/views/Login.vue

@@ -3,10 +3,13 @@ import { useTemplateRef } from "vue"
 import {apiSystemCommon} from '@/api/system'
 import { useRouter } from "vue-router"
 import {useToken} from '@/hooks/useToken'
+import { usePermissionMenu } from '@/hooks/usePermissionMenu'
 
 const {setToken}=useToken()
 const router=useRouter()
 
+const { getMenu } = usePermissionMenu()
+
 //图形验证码
 const imgCodeUrl=ref('')
 let imgCodeId=''
@@ -65,9 +68,26 @@ async function onSubmit(){
     return
   }
   setToken(res.Data.Authorization)
-  router.replace('/etaReport/index')
+  handleMenuJump()
 }
 
+async function handleMenuJump(){
+  const res = await getMenu()
+  if(res.Ret !== 200) return 
+  if(res.Data.ReportPermissions||res.Data.ChartPermissions) {
+    let path = res.Data.ReportPermissions ? '/etaReport/index' : '/etaChart/index'
+    router.replace(path)
+  }else {
+    $confirmDialog({
+      header:'提示',
+      body: '您无菜单权限,请联系管理员!',
+      confirmBtn:'知道了',
+      cancelBtn:null,
+      closeBtn:false
+    }).then(()=>{
+    });
+  }
+}
 
 // 获取手机号验证码
 let countDownTimer=null