mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-25 12:53:43 +08:00
重构错误处理逻辑,更新组件导入路径,新增多个模态框组件以支持用户、部门、角色和权限管理功能,优化分页和排序逻辑,更新类型定义以提高代码可读性和维护性
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -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";
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user