feat(user): 添加用户信息获取新接口并更新相关功能

- 在 user.ts 中新增 getUserInfoByID 函数,用于通过用户 ID 获取信息
- 在 user.store.ts 中添加 getUserInfoByID 方法,用于更新用户信息
- 修改 .env.development 文件,更新 API 基础 URL
- 在 header 组件中添加 menuLi 组件,调整布局结构
This commit is contained in:
mkm 2025-02-26 16:39:38 +08:00
parent 7d0642f970
commit 6b60ac2cf9
6 changed files with 79 additions and 6 deletions

View File

@ -6,6 +6,6 @@ VITE_NOW_TYPE = 'dist'
# VITE_APP_BASE_URL='http://192.168.1.10:8546'
# VITE_APP_BASE_URL='https://test-multi-store.lihaink.cn'
# VITE_APP_BASE_URL='https://multi-store.lihaink.cn'
VITE_APP_BASE_URL='http://192.168.1.22:8545'
VITE_APP_BASE_URL='http://192.168.1.22:8544'
# VITE_APP_BASE_URL='https://ceshi-multi-store.lihaink.cn'

View File

@ -66,3 +66,6 @@ export function apiUserSingList(params: any) {
export function apiUserGiftList(params: any) {
return request.get({ url: '/user/user/userGiftList', params })
}
export function getUserInfoByID(params: any) {
return request.get({ url: '/auth/menu/model_menu_lists', params })
}

View File

@ -13,9 +13,9 @@
</div>
</div>
<div class="flex">
<div class="navbar-item" v-if="!isMobile">
<cache />
<menuLi></menuLi>
</div>
<div class="flex">
<div class="navbar-item" v-if="!isMobile">
<full-screen />
</div>
@ -41,6 +41,7 @@ import UserDropDown from './user-drop-down.vue'
import Setting from '../setting/index.vue'
import MultipleTabs from './multiple-tabs.vue'
import Cache from './cache.vue'
import menuLi from './menuLi.vue'
import useSettingStore from '@/stores/modules/setting'
const appStore = useAppStore()
@ -52,6 +53,7 @@ const settingStore = useSettingStore()
.navbar {
height: var(--navbar-height);
@apply flex px-2 bg-body;
.navbar-item {
@apply h-full flex justify-center items-center hover:bg-page;
}

View File

@ -0,0 +1,53 @@
<template>
<div class="flex mt-3">
<div
class="mr-2 cursor-pointer flex items-center flex-col transition-all duration-300 mt-1 hover:bg-primary-light-9 hover:text-primary"
@click="menuClick(item)"
v-for="(item, index) in menuList"
v-show="item.paths != 'workbench'"
:style="menuName == item.name ? { transform: 'scale(1.1)' } : ''"
>
<!-- <div
class="w-[40px] h-[40px] duration-300 mt-[5px] mb-[2px] !bg-[length:100%_100%]"
></div> -->
<span> {{ item.name }}</span>
</div>
</div>
</template>
<script setup lang="ts">
import { getUserInfo } from '@/api/user'
import useUserStore from '@/stores/modules/user'
import { useWatchRoute } from '@/hooks/useWatchRoute'
import { useRouter } from 'vue-router'
const userStore = useUserStore()
const menuList = reactive([])
const menuName = ref('')
const router = useRouter()
const menuClick = async (item) => {
userStore.getUserInfoByID(item.id)
localStorage.setItem('menuId', item.id)
await nextTick()
menuName.value = item.name
item.id == 173
? router.push('/sys/consumer/lists')
: router.push('/' + item.paths + '/' + item.children[0].paths)
}
getUserInfo().then((res) => {
res.menu.forEach((item) => {
menuList.push(item)
})
userStore.getUserInfoByID(localStorage?.getItem('menuId') || menuList[1].id)
})
useWatchRoute((route) => {
menuName.value = route.matched[0]?.meta?.title || ''
if (menuList.length) {
const index = menuList.findIndex((item) => item.name == menuName.value)
userStore.getUserInfoByID(menuList[index]?.id || 173)
}
})
</script>

View File

@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import cache from '@/utils/cache'
import type { RouteRecordRaw } from 'vue-router'
import { getUserInfo, login, logout } from '@/api/user'
import { getUserInfo, login, logout, getUserInfoByID } from '@/api/user'
import router, { filterAsyncRoutes } from '@/router'
import { TOKEN_KEY } from '@/enums/cacheEnums'
import { PageEnum } from '@/enums/pageEnum'
@ -75,6 +75,21 @@ const useUserStore = defineStore({
reject(error)
})
})
},
getUserInfoByID(id: number) {
return new Promise((resolve, reject) => {
getUserInfoByID({ id })
.then((data) => {
data.forEach((item) => {
item.paths = item.model_name + '/' + item.paths
})
this.routes = filterAsyncRoutes(data)
resolve(data)
})
.catch((error) => {
reject(error)
})
})
}
}
})

View File