重构错误处理逻辑,更新组件导入路径,新增多个模态框组件以支持用户、部门、角色和权限管理功能,优化分页和排序逻辑,更新类型定义以提高代码可读性和维护性

This commit is contained in:
Chuck1sn
2025-06-16 18:00:15 +08:00
parent 772ad547bf
commit 87d288c58e
54 changed files with 308 additions and 221 deletions

View File

@@ -7,20 +7,22 @@ import {
RequestError,
UnAuthError,
ValidationError,
} from "@/types/error";
} from "@/types/ErrorTypes";
import { useRouter } from "vue-router";
import { z } from "zod";
/**
* Composable
* Composable -
* @returns
*/
export function useErrorHandler() {
export function useErrorHandling() {
const router = useRouter();
const { signOut } = useUserAuth();
const alertStore = useAlertStore();
/**
*
* @param err
*/
const handleError = (err: unknown) => {
console.error(err);
@@ -69,4 +71,4 @@ export function useErrorHandler() {
};
}
export default useErrorHandler;
export default useErrorHandling;

View File

@@ -12,6 +12,11 @@ export interface UsePaginationOptions {
initialTotal?: number;
}
/**
* Composable -
* @param options
* @returns
*/
export function usePagination(options: UsePaginationOptions = {}) {
const { initialPage = 1, initialPageSize = 10, initialTotal = 0 } = options;

View File

@@ -1,23 +1,39 @@
import { computed, ref } from "vue";
export const useSort = () => {
const sortFields = ref<
{
field: string;
order: "asc" | "desc" | undefined;
}[]
>([]);
export interface SortField {
field: string;
order: "asc" | "desc" | undefined;
}
/**
* Composable -
* @returns
*/
export function useSorting() {
const sortFields = ref<SortField[]>([]);
/**
*
* @param field
* @returns
*/
const getSortField = (field: string) => {
return sortFields.value.find((item) => item.field === field);
};
/**
* API请求
*/
const sortBy = computed(() => {
return sortFields.value.length
? sortFields.value.map((item) => `${item.field}:${item.order}`).join(",")
: undefined;
});
/**
*
* @param field
*/
const handleSort = async (field: string) => {
if (sortFields.value?.find((item) => item.field === field)) {
sortFields.value = sortFields.value?.map((item) =>
@@ -39,4 +55,4 @@ export const useSort = () => {
handleSort,
getSortField,
};
};
}

View File

@@ -1,7 +1,8 @@
/**
* hook
* Composable -
* @returns
*/
export function useMobileStyles() {
export function useStyleSystem() {
// 移动端卡片容器样式
const cardContainerClass =
"p-4 bg-white rounded-lg shadow border border-gray-100";

View File

@@ -1,5 +1,5 @@
import client from "../../api/client";
import type { DepartmentUpsertModel } from "../../types/department";
import type { DepartmentUpsertModel } from "../../types/DepartmentTypes";
export const useDepartmentUpsert = () => {
const upsertDepartment = async (department: DepartmentUpsertModel) => {

View File

@@ -1,5 +1,5 @@
import client from "../../api/client";
import type { PermissionUpsertModel } from "../../types/permission";
import type { PermissionUpsertModel } from "../../types/PermissionTypes";
const usePermissionUpsert = () => {
const upsertPermission = async (permission: PermissionUpsertModel) => {

View File

@@ -1,5 +1,5 @@
import client from "../../api/client";
import type { UserUpsertSubmitModel } from "../../types/user";
import type { UserUpsertSubmitModel } from "../../types/UserTypes";
export const useUserUpsert = () => {
const uploadUserAvatar = async (file: File) => {