186 lines
4.8 KiB
Plaintext
186 lines
4.8 KiB
Plaintext
/**
|
||
* 文章管理服务层
|
||
* 提供文章列表、详情、保存、删除等接口
|
||
*/
|
||
|
||
// 文章列表项数据结构
|
||
export interface ArticleItem {
|
||
id: number
|
||
title: string
|
||
category_id: number
|
||
category_name: string
|
||
image: string
|
||
description: string
|
||
status: number // 0: 未发布, 1: 已发布
|
||
views: number
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
// 文章详情数据结构
|
||
export interface ArticleDetail {
|
||
id: number
|
||
title: string
|
||
category_id: number
|
||
image: string
|
||
description: string
|
||
content: string
|
||
status: number
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
// 文章创建/编辑参数
|
||
export interface ArticlePayload {
|
||
title: string
|
||
category_id: number
|
||
image: string
|
||
description: string
|
||
content: string
|
||
status: number
|
||
}
|
||
|
||
/**
|
||
* 获取文章列表
|
||
* @param params 查询参数 { page, limit, keyword, status, category_id }
|
||
* @returns Promise<{ items: ArticleItem[], total: number }>
|
||
*/
|
||
export function getArticleList(params: any = {}): Promise<any> {
|
||
// TODO: 替换为实际 API 调用
|
||
// return uni.$http.get('/article/list', { params })
|
||
|
||
return new Promise((resolve) => {
|
||
setTimeout(() => {
|
||
resolve({
|
||
items: [
|
||
{
|
||
id: 1,
|
||
title: '如何选择合适的商品分类',
|
||
category_id: 1,
|
||
category_name: '运营指南',
|
||
image: '/static/article-1.png',
|
||
description: '商品分类是电商平台的重要组成部分...',
|
||
status: 1,
|
||
views: 128,
|
||
created_at: '2026-01-28 10:30:00',
|
||
updated_at: '2026-01-28 10:30:00'
|
||
},
|
||
{
|
||
id: 2,
|
||
title: '商城营销活动最佳实践',
|
||
category_id: 2,
|
||
category_name: '营销技巧',
|
||
image: '/static/article-2.png',
|
||
description: '分享最新的营销活动策略和案例...',
|
||
status: 1,
|
||
views: 256,
|
||
created_at: '2026-01-27 15:20:00',
|
||
updated_at: '2026-01-27 15:20:00'
|
||
},
|
||
{
|
||
id: 3,
|
||
title: '用户评价管理指南',
|
||
category_id: 1,
|
||
category_name: '运营指南',
|
||
image: '/static/article-3.png',
|
||
description: '如何有效管理用户的评价和反馈...',
|
||
status: 0,
|
||
views: 64,
|
||
created_at: '2026-01-26 09:15:00',
|
||
updated_at: '2026-01-26 09:15:00'
|
||
}
|
||
],
|
||
total: 3
|
||
})
|
||
}, 300)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取文章详情
|
||
* @param id 文章ID
|
||
* @returns Promise<ArticleDetail>
|
||
*/
|
||
export function getArticleDetail(id: number): Promise<ArticleDetail> {
|
||
// TODO: 替换为实际 API 调用
|
||
// return uni.$http.get(`/article/${id}`)
|
||
|
||
return new Promise((resolve) => {
|
||
setTimeout(() => {
|
||
resolve({
|
||
id,
|
||
title: '如何选择合适的商品分类',
|
||
category_id: 1,
|
||
image: '/static/article-1.png',
|
||
description: '商品分类是电商平台的重要组成部分...',
|
||
content: '<h2>标题</h2><p>详细内容...</p>',
|
||
status: 1,
|
||
created_at: '2026-01-28 10:30:00',
|
||
updated_at: '2026-01-28 10:30:00'
|
||
})
|
||
}, 300)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 保存文章(新建或编辑)
|
||
* @param data 文章数据
|
||
* @param id 文章ID(编辑时传入)
|
||
* @returns Promise<{ success: boolean, message: string, id?: number }>
|
||
*/
|
||
export function saveArticle(data: ArticlePayload, id?: number): Promise<any> {
|
||
// TODO: 替换为实际 API 调用
|
||
// const method = id ? 'PUT' : 'POST'
|
||
// const url = id ? `/article/${id}` : '/article'
|
||
// return uni.$http[method === 'PUT' ? 'put' : 'post'](url, data)
|
||
|
||
return new Promise((resolve) => {
|
||
setTimeout(() => {
|
||
resolve({
|
||
success: true,
|
||
message: id ? '编辑成功' : '新建成功',
|
||
id: id || Math.floor(Math.random() * 10000)
|
||
})
|
||
}, 500)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 删除文章
|
||
* @param id 文章ID
|
||
* @returns Promise<{ success: boolean, message: string }>
|
||
*/
|
||
export function deleteArticle(id: number): Promise<any> {
|
||
// TODO: 替换为实际 API 调用
|
||
// return uni.$http.delete(`/article/${id}`)
|
||
|
||
return new Promise((resolve) => {
|
||
setTimeout(() => {
|
||
resolve({
|
||
success: true,
|
||
message: '删除成功'
|
||
})
|
||
}, 300)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 发布/取消发布文章
|
||
* @param id 文章ID
|
||
* @param status 状态 (0: 取消发布, 1: 发布)
|
||
* @returns Promise<{ success: boolean, message: string }>
|
||
*/
|
||
export function publishArticle(id: number, status: number): Promise<any> {
|
||
// TODO: 替换为实际 API 调用
|
||
// return uni.$http.put(`/article/${id}/publish`, { status })
|
||
|
||
return new Promise((resolve) => {
|
||
setTimeout(() => {
|
||
resolve({
|
||
success: true,
|
||
message: status === 1 ? '发布成功' : '取消发布成功'
|
||
})
|
||
}, 300)
|
||
})
|
||
}
|