存客宝 React

This commit is contained in:
柳清爽
2025-03-29 16:50:39 +08:00
parent caea0b4b99
commit 7e7c199996
388 changed files with 53282 additions and 2076 deletions

View File

@@ -1,84 +0,0 @@
import request from '@/utils/request'
/**
* 获取设备列表
* @param {Object} params 查询参数
* @param {string} params.keyword 关键词搜索同时搜索IMEI和备注
* @param {number} params.alive 设备在线状态可选1:在线 0:离线)
* @param {number} params.page 页码
* @param {number} params.limit 每页数量
* @returns {Promise} 设备列表
*
* 注意: params 参数会被自动添加到URL查询字符串中如 /v1/devices?keyword=xxx&alive=1&page=1&limit=20
*/
export function getDeviceList(params) {
return request({
url: '/v1/devices',
method: 'GET',
params
})
}
/**
* 获取设备总数
* @param {Object} params 查询参数
* @param {number} params.alive 设备在线状态可选1:在线 0:离线)
* @returns {Promise} 设备总数
*/
export function getDeviceCount(params) {
return request({
url: '/v1/devices/count',
method: 'GET',
params
})
}
/**
* 获取设备详情
* @param {number} id 设备ID
* @returns {Promise} 设备详情
*/
export function getDeviceDetail(id) {
return request({
url: `/v1/devices/${id}`,
method: 'GET'
})
}
/**
* 删除设备
* @param {number} id 设备ID
* @returns {Promise} 删除结果
*/
export function deleteDevice(id) {
return request({
url: `/v1/devices/${id}`,
method: 'DELETE'
})
}
/**
* 刷新设备状态
* @returns {Promise} 刷新结果
*/
export function refreshDevices() {
return request({
url: '/v1/devices/refresh',
method: 'PUT'
})
}
/**
* 添加设备
* @param {Object} data 设备数据
* @param {string} data.imei 设备IMEI
* @param {string} data.memo 设备备注
* @returns {Promise} 添加结果
*/
export function addDevice(data) {
return request({
url: '/v1/devices',
method: 'POST',
data
})
}

131
Cunkebao/api/devices.ts Normal file
View File

@@ -0,0 +1,131 @@
import type {
ApiResponse,
Device,
DeviceStats,
DeviceTaskRecord,
PaginatedResponse,
QueryDeviceParams,
CreateDeviceParams,
UpdateDeviceParams,
DeviceStatus, // Added DeviceStatus import
} from "@/types/device"
const API_BASE = "/api/devices"
// 设备管理API
export const deviceApi = {
// 创建设备
async create(params: CreateDeviceParams): Promise<ApiResponse<Device>> {
const response = await fetch(`${API_BASE}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
})
return response.json()
},
// 更新设备
async update(params: UpdateDeviceParams): Promise<ApiResponse<Device>> {
const response = await fetch(`${API_BASE}/${params.id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
})
return response.json()
},
// 获取设备详情
async getById(id: string): Promise<ApiResponse<Device>> {
const response = await fetch(`${API_BASE}/${id}`)
return response.json()
},
// 查询设备列表
async query(params: QueryDeviceParams): Promise<ApiResponse<PaginatedResponse<Device>>> {
const queryString = new URLSearchParams({
...params,
tags: params.tags ? JSON.stringify(params.tags) : "",
dateRange: params.dateRange ? JSON.stringify(params.dateRange) : "",
}).toString()
const response = await fetch(`${API_BASE}?${queryString}`)
return response.json()
},
// 删除设备
async delete(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}`, {
method: "DELETE",
})
return response.json()
},
// 重启设备
async restart(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}/restart`, {
method: "POST",
})
return response.json()
},
// 解绑设备
async unbind(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}/unbind`, {
method: "POST",
})
return response.json()
},
// 获取设备统计数据
async getStats(id: string): Promise<ApiResponse<DeviceStats>> {
const response = await fetch(`${API_BASE}/${id}/stats`)
return response.json()
},
// 获取设备任务记录
async getTaskRecords(id: string, page = 1, pageSize = 20): Promise<ApiResponse<PaginatedResponse<DeviceTaskRecord>>> {
const response = await fetch(`${API_BASE}/${id}/tasks?page=${page}&pageSize=${pageSize}`)
return response.json()
},
// 批量更新设备标签
async updateTags(ids: string[], tags: string[]): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/tags`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ deviceIds: ids, tags }),
})
return response.json()
},
// 批量导出设备数据
async exportDevices(ids: string[]): Promise<Blob> {
const response = await fetch(`${API_BASE}/export`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ deviceIds: ids }),
})
return response.blob()
},
// 检查设备在线状态
async checkStatus(ids: string[]): Promise<ApiResponse<Record<string, DeviceStatus>>> {
const response = await fetch(`${API_BASE}/status`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ deviceIds: ids }),
})
return response.json()
},
}

74
Cunkebao/api/route.ts Normal file
View File

@@ -0,0 +1,74 @@
import { NextResponse } from "next/server"
import type { CreateScenarioParams, QueryScenarioParams, ScenarioBase, ApiResponse } from "@/types/scenario"
// 获客场景路由处理
export async function POST(request: Request) {
try {
const body: CreateScenarioParams = await request.json()
// TODO: 实现创建场景的具体逻辑
const scenario: ScenarioBase = {
id: "generated-id",
...body,
status: "draft",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: "current-user-id",
}
const response: ApiResponse<ScenarioBase> = {
code: 0,
message: "创建成功",
data: scenario,
}
return NextResponse.json(response)
} catch (error) {
return NextResponse.json(
{
code: 500,
message: "创建失败",
data: null,
},
{ status: 500 },
)
}
}
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const params: QueryScenarioParams = {
type: searchParams.get("type") as any,
status: searchParams.get("status") as any,
keyword: searchParams.get("keyword") || undefined,
dateRange: searchParams.get("dateRange") ? JSON.parse(searchParams.get("dateRange")!) : undefined,
page: Number(searchParams.get("page")) || 1,
pageSize: Number(searchParams.get("pageSize")) || 20,
}
// TODO: 实现查询场景列表的具体逻辑
return NextResponse.json({
code: 0,
message: "查询成功",
data: {
items: [],
total: 0,
page: params.page,
pageSize: params.pageSize,
totalPages: 0,
},
})
} catch (error) {
return NextResponse.json(
{
code: 500,
message: "查询失败",
data: null,
},
{ status: 500 },
)
}
}

112
Cunkebao/api/scenarios.ts Normal file
View File

@@ -0,0 +1,112 @@
import type {
ApiResponse,
CreateScenarioParams,
UpdateScenarioParams,
QueryScenarioParams,
ScenarioBase,
ScenarioStats,
AcquisitionRecord,
PaginatedResponse,
} from "@/types/scenario"
const API_BASE = "/api/scenarios"
// 获客场景API
export const scenarioApi = {
// 创建场景
async create(params: CreateScenarioParams): Promise<ApiResponse<ScenarioBase>> {
const response = await fetch(`${API_BASE}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
})
return response.json()
},
// 更新场景
async update(params: UpdateScenarioParams): Promise<ApiResponse<ScenarioBase>> {
const response = await fetch(`${API_BASE}/${params.id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
})
return response.json()
},
// 获取场景详情
async getById(id: string): Promise<ApiResponse<ScenarioBase>> {
const response = await fetch(`${API_BASE}/${id}`)
return response.json()
},
// 查询场景列表
async query(params: QueryScenarioParams): Promise<ApiResponse<PaginatedResponse<ScenarioBase>>> {
const queryString = new URLSearchParams({
...params,
dateRange: params.dateRange ? JSON.stringify(params.dateRange) : "",
}).toString()
const response = await fetch(`${API_BASE}?${queryString}`)
return response.json()
},
// 删除场景
async delete(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}`, {
method: "DELETE",
})
return response.json()
},
// 启动场景
async start(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}/start`, {
method: "POST",
})
return response.json()
},
// 暂停场景
async pause(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}/pause`, {
method: "POST",
})
return response.json()
},
// 获取场景统计数据
async getStats(id: string): Promise<ApiResponse<ScenarioStats>> {
const response = await fetch(`${API_BASE}/${id}/stats`)
return response.json()
},
// 获取获客记录
async getRecords(id: string, page = 1, pageSize = 20): Promise<ApiResponse<PaginatedResponse<AcquisitionRecord>>> {
const response = await fetch(`${API_BASE}/${id}/records?page=${page}&pageSize=${pageSize}`)
return response.json()
},
// 导出获客记录
async exportRecords(id: string, dateRange?: { start: string; end: string }): Promise<Blob> {
const queryString = dateRange ? `?start=${dateRange.start}&end=${dateRange.end}` : ""
const response = await fetch(`${API_BASE}/${id}/records/export${queryString}`)
return response.blob()
},
// 批量更新标签
async updateTags(id: string, customerIds: string[], tags: string[]): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/${id}/tags`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ customerIds, tags }),
})
return response.json()
},
}

View File

@@ -1,108 +0,0 @@
import request from '@/utils/request'
/**
* 用户登录
* @param {Object} data 登录数据
* @param {string} data.account 账号(手机号)
* @param {string} data.password 密码
* @param {number} data.typeId 用户类型
* @returns {Promise} 登录结果
*/
export function login(data) {
return request({
url: '/v1/auth/login',
method: 'POST',
data
})
}
/**
* 手机号验证码登录
* @param {Object} data 登录数据
* @param {string} data.account 手机号
* @param {string} data.code 验证码
* @param {number} data.typeId 用户类型
* @returns {Promise} 登录结果
*/
export function mobileLogin(data) {
return request({
url: '/v1/auth/mobile-login',
method: 'POST',
data
})
}
/**
* 发送验证码
* @param {Object} data 数据
* @param {string} data.account 手机号
* @param {string} data.type 验证码类型(login:登录,register:注册)
* @returns {Promise} 发送结果
*/
export function sendCode(data) {
return request({
url: '/v1/auth/code',
method: 'POST',
data
})
}
/**
* 获取用户信息
* @returns {Promise} 用户信息
*/
export function getUserInfo() {
return request({
url: '/v1/auth/info',
method: 'GET'
})
}
/**
* 刷新token
* @returns {Promise} 刷新结果
*/
export function refreshToken() {
return request({
url: '/v1/auth/refresh',
method: 'POST'
})
}
/**
* 退出登录
* @returns {Promise} 退出结果
*/
export function logout() {
return new Promise(resolve => {
resolve({ code: 200, msg: '退出成功' })
})
}
/**
* 微信登录
* @param {Object} data 登录数据
* @param {string} data.code 微信授权码
* @returns {Promise} 登录结果
*/
export function wechatLogin(data) {
return request({
url: '/v1/auth/wechat-login',
method: 'POST',
data
})
}
/**
* Apple登录
* @param {Object} data 登录数据
* @param {string} data.identityToken Apple身份令牌
* @returns {Promise} 登录结果
*/
export function appleLogin(data) {
return request({
url: '/v1/auth/apple-login',
method: 'POST',
data
})
}