web-上传组件、富文本组件
This commit is contained in:
9
schoolNewsWeb/src/apis/resource/index.ts
Normal file
9
schoolNewsWeb/src/apis/resource/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @description 资源相关API接口导出
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
export * from './resourceCategory';
|
||||
export * from './resourceTag';
|
||||
export * from './resource';
|
||||
206
schoolNewsWeb/src/apis/resource/resource.ts
Normal file
206
schoolNewsWeb/src/apis/resource/resource.ts
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* @description 资源API接口
|
||||
* @filename resource.ts
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis';
|
||||
import type { ResultDomain, Resource, ResourceSearchParams } from '@/types';
|
||||
|
||||
/**
|
||||
* 资源API服务
|
||||
*/
|
||||
export const resourceApi = {
|
||||
// ==================== 资源基础操作 ====================
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param filter 筛选条件
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getResourceList(filter?: ResourceSearchParams): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/news/resources/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取资源详情
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getResourceById(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>(`/news/resources/resource/${resourceID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建资源
|
||||
* @param resource 资源信息
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async createResource(resource: Resource): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>('/news/resources/resource', resource);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新资源
|
||||
* @param resource 资源信息
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async updateResource(resource: Resource): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.put<Resource>('/news/resources/resource', resource);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除资源
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteResource(resourceID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/news/resources/resource/${resourceID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// ==================== 资源状态操作 ====================
|
||||
|
||||
/**
|
||||
* 更新资源状态
|
||||
* @param resourceID 资源ID
|
||||
* @param status 状态值(0草稿 1已发布 2下架)
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async updateResourceStatus(resourceID: string, status: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.put<Resource>(`/news/resources/resource/${resourceID}/status`, null, {
|
||||
params: { status }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 发布资源
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async publishResource(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>(`/news/resources/resource/${resourceID}/publish`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 下架资源
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async unpublishResource(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>(`/news/resources/resource/${resourceID}/unpublish`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// ==================== 资源统计操作 ====================
|
||||
|
||||
/**
|
||||
* 增加浏览次数
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async incrementViewCount(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>(`/news/resources/resource/${resourceID}/view`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加点赞次数
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async incrementLikeCount(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>(`/news/resources/resource/${resourceID}/like`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加收藏次数
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async incrementCollectCount(resourceID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.post<Resource>(`/news/resources/resource/${resourceID}/collect`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// ==================== 资源推荐和轮播操作 ====================
|
||||
|
||||
/**
|
||||
* 设置资源推荐
|
||||
* @param resourceID 资源ID
|
||||
* @param isRecommend 是否推荐
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async setResourceRecommend(resourceID: string, isRecommend: boolean): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.put<Resource>(`/news/resources/resource/${resourceID}/recommend`, null, {
|
||||
params: { isRecommend }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置资源轮播
|
||||
* @param resourceID 资源ID
|
||||
* @param isBanner 是否轮播
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async setResourceBanner(resourceID: string, isBanner: boolean): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.put<Resource>(`/news/resources/resource/${resourceID}/banner`, null, {
|
||||
params: { isBanner }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// ==================== 资源查询操作 ====================
|
||||
|
||||
/**
|
||||
* 获取推荐资源列表
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getRecommendResources(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/news/resources/recommend', { limit });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取轮播资源列表
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getBannerResources(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/news/resources/banner', { limit });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索资源
|
||||
* @param keyword 搜索关键词
|
||||
* @param categoryID 分类ID(可选)
|
||||
* @param status 状态(可选)
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async searchResources(
|
||||
keyword: string,
|
||||
categoryID?: string,
|
||||
status?: number
|
||||
): Promise<ResultDomain<Resource>> {
|
||||
const params: any = { keyword };
|
||||
if (categoryID) params.categoryID = categoryID;
|
||||
if (status !== undefined) params.status = status;
|
||||
|
||||
const response = await api.get<Resource>('/news/resources/search', params);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
export default resourceApi;
|
||||
98
schoolNewsWeb/src/apis/resource/resourceCategory.ts
Normal file
98
schoolNewsWeb/src/apis/resource/resourceCategory.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* @description 资源分类API接口
|
||||
* @filename resourceCategory.ts
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis';
|
||||
import type { ResultDomain, ResourceCategory } from '@/types';
|
||||
|
||||
/**
|
||||
* 资源分类API服务
|
||||
*/
|
||||
export const resourceCategoryApi = {
|
||||
/**
|
||||
* 获取分类列表
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async getCategoryList(): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.get<ResourceCategory>('/news/categorys/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取分类详情
|
||||
* @param categoryID 分类ID
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async getCategoryById(categoryID: string): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.get<ResourceCategory>(`/news/categorys/category/${categoryID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建分类
|
||||
* @param category 分类信息
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async createCategory(category: ResourceCategory): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.post<ResourceCategory>('/news/categorys/category', category);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新分类
|
||||
* @param category 分类信息
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async updateCategory(category: ResourceCategory): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.put<ResourceCategory>('/news/categorys/category', category);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param categoryID 分类ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteCategory(categoryID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/news/categorys/category/${categoryID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新分类状态
|
||||
* @param categoryID 分类ID
|
||||
* @param status 状态值
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async updateCategoryStatus(categoryID: string, status: number): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.put<ResourceCategory>(`/news/categorys/category/${categoryID}/status`, null, {
|
||||
params: { status }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取分类树
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async getCategoryTree(): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.get<ResourceCategory>('/news/categorys/tree');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取子分类
|
||||
* @param parentID 父分类ID
|
||||
* @returns Promise<ResultDomain<ResourceCategory>>
|
||||
*/
|
||||
async getChildCategories(parentID: string): Promise<ResultDomain<ResourceCategory>> {
|
||||
const response = await api.get<ResourceCategory>(`/news/categorys/category/${parentID}/children`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
export default resourceCategoryApi;
|
||||
143
schoolNewsWeb/src/apis/resource/resourceTag.ts
Normal file
143
schoolNewsWeb/src/apis/resource/resourceTag.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* @description 标签API接口
|
||||
* @filename resourceTag.ts
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis';
|
||||
import type { ResultDomain, Tag, ResourceTag } from '@/types';
|
||||
|
||||
/**
|
||||
* 标签API服务
|
||||
*/
|
||||
export const resourceTagApi = {
|
||||
// ==================== 标签基础操作 ====================
|
||||
|
||||
/**
|
||||
* 获取标签列表
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async getTagList(): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.get<Tag>('/news/tags/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取标签详情
|
||||
* @param tagID 标签ID
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async getTagById(tagID: string): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.get<Tag>(`/news/tags/tag/${tagID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建标签
|
||||
* @param tag 标签信息
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async createTag(tag: Tag): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.post<Tag>('/news/tags/tag', tag);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新标签
|
||||
* @param tag 标签信息
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async updateTag(tag: Tag): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.put<Tag>('/news/tags/tag', tag);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
* @param tagID 标签ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteTag(tagID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/news/tags/tag/${tagID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索标签
|
||||
* @param keyword 搜索关键词
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async searchTags(keyword: string): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.get<Tag>('/news/tags/search', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// ==================== 资源标签关联操作 ====================
|
||||
|
||||
/**
|
||||
* 获取资源的标签列表
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<Tag>>
|
||||
*/
|
||||
async getResourceTags(resourceID: string): Promise<ResultDomain<Tag>> {
|
||||
const response = await api.get<Tag>(`/news/tags/resource/${resourceID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 为资源添加单个标签
|
||||
* @param resourceID 资源ID
|
||||
* @param tagID 标签ID
|
||||
* @returns Promise<ResultDomain<ResourceTag>>
|
||||
*/
|
||||
async addResourceTag(resourceID: string, tagID: string): Promise<ResultDomain<ResourceTag>> {
|
||||
const response = await api.post<ResourceTag>(`/news/tags/resource/${resourceID}/tag/${tagID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量为资源添加标签
|
||||
* @param resourceID 资源ID
|
||||
* @param tagIDs 标签ID列表
|
||||
* @returns Promise<ResultDomain<ResourceTag>>
|
||||
*/
|
||||
async batchAddResourceTags(resourceID: string, tagIDs: string): Promise<ResultDomain<ResourceTag>> {
|
||||
const response = await api.post<ResourceTag>(`/news/tags/resource/${resourceID}/tags`, tagIDs);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 移除资源的标签
|
||||
* @param resourceID 资源ID
|
||||
* @param tagID 标签ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async removeResourceTag(resourceID: string, tagID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/news/tags/resource/${resourceID}/tag/${tagID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空资源的所有标签
|
||||
* @param resourceID 资源ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async clearResourceTags(resourceID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/news/tags/resource/${resourceID}/tags`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据标签获取资源列表
|
||||
* @param tagID 标签ID
|
||||
* @returns Promise<ResultDomain<string>>
|
||||
*/
|
||||
async getResourcesByTag(tagID: string): Promise<ResultDomain<string>> {
|
||||
const response = await api.get<string>(`/news/tags/tag/${tagID}/resources`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
export default resourceTagApi;
|
||||
Reference in New Issue
Block a user