feat:整合

This commit is contained in:
fangyunong 2025-07-10 20:05:35 +08:00
parent 0fdce24a3c
commit ec6655c64a
9 changed files with 68 additions and 18 deletions

1
auto-imports.d.ts vendored
View File

@ -16,6 +16,7 @@ declare global {
const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope'] const getCurrentScope: typeof import('vue')['getCurrentScope']
const getUserInfo: typeof import('./src/api/userApi')['getUserInfo'] const getUserInfo: typeof import('./src/api/userApi')['getUserInfo']
const getUserList: typeof import('./src/api/roleApi')['getUserList']
const h: typeof import('vue')['h'] const h: typeof import('vue')['h']
const inject: typeof import('vue')['inject'] const inject: typeof import('vue')['inject']
const isNewUser: typeof import('./src/api/userApi')['isNewUser'] const isNewUser: typeof import('./src/api/userApi')['isNewUser']

View File

@ -2,6 +2,7 @@
<n-config-provider :date-locale="dateZhCN" :locale="zhCN" :theme-overrides="themeOverrides"> <n-config-provider :date-locale="dateZhCN" :locale="zhCN" :theme-overrides="themeOverrides">
<n-dialog-provider> <n-dialog-provider>
<n-message-provider> <n-message-provider>
<InitAxiosInterceptors /> <!-- 新增的子组件 -->
<router-view></router-view> <router-view></router-view>
</n-message-provider> </n-message-provider>
</n-dialog-provider> </n-dialog-provider>
@ -10,6 +11,7 @@
<script setup lang='ts'> <script setup lang='ts'>
import { type GlobalThemeOverrides, dateZhCN, zhCN } from "naive-ui"; import { type GlobalThemeOverrides, dateZhCN, zhCN } from "naive-ui";
import InitAxiosInterceptors from "@/components/InitAxiosInterceptors.vue";
const themeOverrides: GlobalThemeOverrides = { const themeOverrides: GlobalThemeOverrides = {
// //
@ -20,5 +22,6 @@ const themeOverrides: GlobalThemeOverrides = {
'primaryColorSuppl': '#5A95FF' // hover 'primaryColorSuppl': '#5A95FF' // hover
}, },
}; };
</script> </script>
<style scoped lang='scss'></style> <style scoped lang='scss'></style>

14
src/api/roleApi.ts Normal file
View File

@ -0,0 +1,14 @@
import http from "@/utils/request";
// 用户列表
interface UserListQuery{
roleName?:string
page:number
pageSize:number
}
export function getUserList(data:UserListQuery){
return http({
url:"/api/v1/AdminRoleControllers/SearchUserFromRole",
method:'POST',
data
})
}

View File

@ -1,17 +1,9 @@
import http from "@/utils/request"; import http from "@/utils/request";
//是否第一次注册
export const isNewUser = () => {
return http({
url: "/api/UserInfo/IsNewUser",
method: "GET",
});
};
// 获取用户信息 // 获取用户信息
export const getUserInfo = () => { export const getUserInfo = () => {
return http({ return http({
url:'/api/UserInfo/My', url:'/api/v1/UserControllers/My',
method:'GET' method:'GET'
}) })
}; };

View File

@ -0,0 +1,13 @@
<template>
</template>
<script setup lang='ts'>
import { useMessage } from "naive-ui";
import { setupResponseInterceptors } from "@/utils/request";
//
const message = useMessage();
const router = useRouter();
setupResponseInterceptors({ message, router });
</script>
<style scoped lang='scss'>
</style>

View File

@ -1,5 +1,17 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; import axios, { AxiosResponse } from "axios";
import { getToken, removeToken } from "./auth"; import { getToken, removeToken } from "./auth";
import type { MessageApiInjection } from "naive-ui/es/message/src/MessageProvider";
import type { Router } from "vue-router";
let message: MessageApiInjection = null;
let router: Router = null;
export function setupResponseInterceptors({ message: msg, router: rt }: {
message: MessageApiInjection;
router: Router;
}) {
message = msg;
router = rt;
}
// 定义后端返回的统一数据结构 // 定义后端返回的统一数据结构
interface ApiResponse<T = any> { interface ApiResponse<T = any> {
@ -39,11 +51,11 @@ instance.interceptors.response.use(
// 401 未授权,跳转首页 // 401 未授权,跳转首页
if (code === 401) { if (code === 401) {
// // 这里调用退出登录的逻辑 // // 这里调用退出登录的逻辑
// console.log("未授权,跳转首页"); message.error("未授权,跳转首页");
// // 清除用户信息 // // 清除用户信息
// removeToken(); removeToken();
// // 跳转首页 // // 跳转首页
// window.location.href = "/"; //后续用发布订阅模式修改 router.push('/');
return Promise.reject(new Error(msg || "未授权")); return Promise.reject(new Error(msg || "未授权"));
} }

View File

@ -7,7 +7,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { removeToken, setToken } from '@/utils/auth'; import { removeToken, setToken } from '@/utils/auth';
import { useMessage } from 'naive-ui'; import { useMessage } from 'naive-ui';
import { isNewUser, getUserInfo } from '@/api/userApi'; import { getUserInfo } from '@/api/userApi';
const router = useRouter(); const router = useRouter();
const message = useMessage(); const message = useMessage();
const init = async () => { const init = async () => {
@ -22,8 +22,8 @@ const init = async () => {
message.success('登录成功!'); message.success('登录成功!');
router.push('/layout'); router.push('/layout');
} catch (error) { } catch (error) {
// removeToken(); removeToken();
// router.push('/'); router.push('/');
message.error(error.message); message.error(error.message);
} }
} }

View File

@ -26,10 +26,11 @@
<script setup lang='ts'> <script setup lang='ts'>
import { SearchOutline } from '@vicons/ionicons5'; import { SearchOutline } from '@vicons/ionicons5';
import { getUserList } from '@/api/roleApi';
const tableMainRef = ref<HTMLElement | null>(null); const tableMainRef = ref<HTMLElement | null>(null);
const roleName = ref(''); const roleName = ref('');
const pagination = reactive({ const pagination = reactive<PageController>({
pageSize: 10, pageSize: 10,
page: 1, page: 1,
}); });
@ -55,10 +56,19 @@ const data = Array.from({ length: 46 }).map((_, index) => ({
age: 32, age: 32,
address: `London, Park Lane no. ${index}` address: `London, Park Lane no. ${index}`
})); }));
const init = async () => {
try {
const result = await getUserList(pagination);
console.log(result,'result');
} catch (error) {
}
}
onMounted(() => { onMounted(() => {
if (tableMainRef.value) { if (tableMainRef.value) {
height.value = tableMainRef.value.clientHeight - 64 - 50; // - height.value = tableMainRef.value.clientHeight - 64 - 50; // -
} };
init();
}); });
</script> </script>

5
src/vite-env.d.ts vendored
View File

@ -8,3 +8,8 @@ declare module "@/components/*";
declare module "@/store/*"; declare module "@/store/*";
declare module "@/utils/*"; declare module "@/utils/*";
declare module "@/router/*"; declare module "@/router/*";
interface PageController{
page:number
pageSize:number
}