diff --git a/.mock/finance.json b/.mock/finance.json index 0da1e13..e542151 100644 --- a/.mock/finance.json +++ b/.mock/finance.json @@ -14,7 +14,6 @@ { "id": "1002", "billNo": "2026083222P345", "projectId": "1", "projectNo": "20260813ZK2Q5f45", "projectName": "社区康养智能服务系统", "userId": "1", "amount": "20100.00", "contractId": null, "billType": "PROGRESS", "periodName": "第二期", "periodRatio": "33.00", "status": "PENDING", "payChannel": null, "transactionNo": null, "tradeName": null, "payTime": null, "dueDate": null }, { "id": "1003", "billNo": "2026083222P345", "projectId": "1", "projectNo": "20260813ZK2Q5f45", "projectName": "社区康养智能服务系统", "userId": "1", "amount": "20100.00", "contractId": null, "billType": "FINAL", "periodName": "第三期", "periodRatio": "33.00", "status": "UNSTARTED", "payChannel": null, "transactionNo": null, "tradeName": null, "payTime": null, "dueDate": null } ], - "billPlans": [], "invoices": [ { "id": "1", "billId": "1001", "invoiceTitle": "测试", "taxNo": null, "invoiceType": "电子普通发票", "amount": "20100.00", "status": "ISSUED", "invoiceNo": null, "invoiceFile": "https://example.com/inv.pdf", "applyTime": "2026-8-17 17:00", "invoiceDate": null, "createTime": "2026-8-17 17:00" }, { "id": "2", "billId": "1001", "invoiceTitle": "测试", "taxNo": null, "invoiceType": "电子普通发票", "amount": "20100.00", "status": "ISSUED", "invoiceNo": null, "invoiceFile": "https://example.com/inv2.pdf", "applyTime": "2026-8-17 17:00", "invoiceDate": null, "createTime": "2026-8-17 17:00" } diff --git a/package-lock.json b/package-lock.json index 89839f5..8990089 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "axios": "^1.20.0", "element-plus": "^2.14.5", "pinia": "^4.0.3", + "qrcode-generator": "^2.0.4", "vue": "^3.5.42", "vue-router": "^4.6.4" }, @@ -1836,6 +1837,12 @@ "license": "MIT", "optional": true }, + "node_modules/qrcode-generator": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-2.0.4.tgz", + "integrity": "sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g==", + "license": "MIT" + }, "node_modules/rolldown": { "version": "1.2.10", "resolved": "https://registry.npmmirror.com/rolldown/-/rolldown-1.2.10.tgz", diff --git a/src/api/cases.ts b/src/api/cases.ts index e47bfe0..f133e86 100644 --- a/src/api/cases.ts +++ b/src/api/cases.ts @@ -3,6 +3,7 @@ import { request, serializeQuery } from '@/utils/request' import type { CaseSelectionModel, ProjectCaseAndCaseCountVo, + ProjectCaseCountResultVo, ProjectCaseUserBo, ProjectCaseVo, } from '@/types/business/cases' @@ -42,6 +43,14 @@ export function getCaseCategories(): Promise { }) } +/** 案例总数与按业务类型统计(已按案例数倒序,无案例分类补 0)。 */ +export function getProjectCaseCount(): Promise { + return request({ + url: '/web/projectCase/count', + method: 'get', + }) +} + export function getFeaturedCases(type?: string): Promise { return request({ url: '/web/projectCase/mostViewed', diff --git a/src/api/contract.ts b/src/api/contract.ts index ac25892..29dda8e 100644 --- a/src/api/contract.ts +++ b/src/api/contract.ts @@ -1,102 +1,94 @@ -import type { FileInfo, PageResult } from '@/types/api' -import type { Contract, ContractQuery } from '@/types/business/contract' +import type { + ContractPageResult, + ContractPreviewVo, + ContractQrTokenVo, + ContractQuery, + ContractSignProgressVo, + ContractVo, +} from '@/types/business/contract' +import { request } from '@/utils/request' -// TODO(api): 待接口文档到位后,将以下 mock 替换为 request 调用 +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/contract/page → 合同中心列表(表格分页) +// pageNum/pageSize 分页;keyword 模糊匹配合同编号 / 标题 / 项目名 +// 返回 { total, rows: ContractVo[] } +// ───────────────────────────────────────────────────────────────────────────── -function mockFile(name: string, size: number, uploadTime: string): FileInfo { - return { name, size, uploadTime, url: '' } -} - -const DETAIL_ID = 'contract-001' - -const MOCK_CONTRACTS: Contract[] = [ - { - id: 'contract-001', - contractNo: 'C8K2M202408001', - contractName: '智慧城市建设项目技术服务合同', - contractType: '互联网软件通用/app开发', - contractAmount: 201000, - relatedProjectName: '智慧城市大数据平台建设项目', - projectNo: 'P8K2M202408001', - signStatus: '履行中', - signDate: '2026-8-17 14:00', - effectiveDate: '2026-8-17 14:00', - expiryDate: '2026-8-17 14:00', - files: [mockFile('项目需求规格说明书.pdf', 2516582, '2026-8-17 14:00')], - }, - { - id: 'contract-002', - contractNo: 'C8K2M202408002', - contractName: '智慧城市建设项目硬件电路设计合同', - contractType: '硬件电路通用/电路版设计', - contractAmount: 180000, - relatedProjectName: '三甲医院指挥医疗信息化系统', - projectNo: 'P8K2M202408001', - signStatus: '已过期', - signDate: '2026-8-17 14:00', - effectiveDate: '2026-8-17 14:00', - expiryDate: '2026-8-17 14:00', - files: [mockFile('硬件电路设计合同.pdf', 1468006, '2026-8-17 14:00')], - }, - { - id: 'contract-003', - contractNo: 'C8K2M202408003', - contractName: '智慧城市建设项目物联网全案合同', - contractType: '物联网全案通用/一套门禁卡', - contractAmount: 96000, - relatedProjectName: '社区康养智能服务系统', - projectNo: 'P8K2M202408001', - signStatus: '待签署', - effectiveDate: '2026-8-17 14:00', - expiryDate: '2026-8-17 14:00', - files: [mockFile('物联网全案合同.pdf', 1258291, '2026-8-17 14:00')], - }, -] - -const CONTRACT_DETAIL: Contract = { - id: DETAIL_ID, - contractNo: 'C8K2M202408001', - contractName: '社区康养智能服务系统开发合同', - contractType: '互联网软件开发', - contractAmount: 201000, - relatedProjectName: '社区康养智能服务系统', - projectNo: '20260813ZZ251245', - signStatus: '履行中', - signDate: '2024-10-15', - effectiveDate: '2024-10-15', - expiryDate: '2024-10-15', - files: [mockFile('项目需求规格说明书.pdf', 2516582, '2024-10-15')], -} - -export function getContractList(query: ContractQuery): Promise> { - const filtered = MOCK_CONTRACTS.filter((item) => { - if ( - query.keyword - && !item.contractName.includes(query.keyword) - && !item.contractNo.includes(query.keyword) - ) { - return false - } - return true - }) - const pageSize = query.pageSize > 0 ? query.pageSize : 8 - const start = (query.page - 1) * pageSize - return Promise.resolve({ - list: filtered.slice(start, start + pageSize), - total: filtered.length, +export function getContractList(query: ContractQuery): Promise { + return request({ + url: '/web/contract/page', + method: 'get', + params: { + keyword: query.keyword || undefined, + pageNum: query.pageNum, + pageSize: query.pageSize, + }, }) } -export function getContractDetail(id: string): Promise { - if (id === DETAIL_ID) return Promise.resolve({ ...CONTRACT_DETAIL, files: [...CONTRACT_DETAIL.files] }) - const found = MOCK_CONTRACTS.find((item) => item.id === id) ?? null - return Promise.resolve(found ? { ...found, files: [...found.files] } : null) +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/contract/{id} → 合同详情 ContractVo +// GET /web/contract/preview/{id} → ContractPreviewVo(合同 PDF 地址) +// GET /web/contract/download/{id} → String(仅「已签署」合同可下载) +// ───────────────────────────────────────────────────────────────────────────── + +export function getContractDetail(id: string): Promise { + return request({ + url: `/web/contract/${id}`, + method: 'get', + }) } -export function getSignQr(_id: string): Promise<{ expiresInSeconds: number }> { - return Promise.resolve({ expiresInSeconds: 272 }) +export function getContractPreview(id: string): Promise { + return request({ + url: `/web/contract/preview/${id}`, + method: 'get', + }) } -export function refreshSignQr(_id: string): Promise<{ expiresInSeconds: number }> { - return Promise.resolve({ expiresInSeconds: 272 }) +export function getContractDownloadUrl(id: string): Promise { + return request({ + url: `/web/contract/download/${id}`, + method: 'get', + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/contract/sign/progress/{id} → 签署进度 ContractSignProgressVo +// ───────────────────────────────────────────────────────────────────────────── + +export function getContractSignProgress(id: string): Promise { + return request({ + url: `/web/contract/sign/progress/${id}`, + method: 'get', + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// POST /web/contract/sign/qr-init/{contractId} → String(完整落地页 URL,Redis TTL 5 分钟) +// GET /web/contract/sign/qr-status/{contractId} → Boolean(sign_status === SIGNED) +// GET /web/contract/sign/qr-token/{token} → ContractQrTokenVo(扫码落地页数据) +// ───────────────────────────────────────────────────────────────────────────── + +export function initContractSignQr(contractId: string): Promise { + return request({ + url: `/web/contract/sign/qr-init/${contractId}`, + method: 'post', + }) +} + +export function getContractSignQrStatus(contractId: string): Promise { + return request({ + url: `/web/contract/sign/qr-status/${contractId}`, + method: 'get', + // 轮询接口:失败由调用方静默降级,避免每 3 秒弹一次错误提示 + silent: true, + }) +} + +export function getContractSignQrToken(token: string): Promise { + return request({ + url: `/web/contract/sign/qr-token/${encodeURIComponent(token)}`, + method: 'get', + }) } diff --git a/src/api/finance.ts b/src/api/finance.ts index dbd15bf..67f86c6 100644 --- a/src/api/finance.ts +++ b/src/api/finance.ts @@ -1,377 +1,328 @@ -import type { PageResult } from '@/types/api' import type { - Bill, BillQuery, - BillVo, - FinanceStats, - Invoice, - InvoiceQuery, - InvoiceTitle, - InvoiceTitlePayload, - PayMethod, - PayOrderResponse, - Payment, - PaymentResult, + DictOptionVo, + FinanceBillStatisticsVo, + FinanceBillVo, + FinanceInvoiceApplyBo, + FinanceInvoiceAvailableVo, + FinanceInvoicePreviewVo, + FinanceInvoiceQuery, + FinanceInvoiceSendEmailBo, + FinanceInvoiceTitleBo, + FinanceInvoiceTitleVo, + FinanceInvoiceVo, + FinancePageResult, + FinancePayQueryVo, + FinancePayResultVo, + FinanceRefundBo, + FinanceRefundQuery, + FinanceRefundVo, + FinanceSummaryQuery, + FinanceSummaryVo, + PayChannelCode, + PayChannelVo, } from '@/types/business/finance' -import { toBills, toPlanBills, type PlanLike } from '@/utils/billVo' -import { toPayMethod } from '@/utils/payMeta' -import { request } from '@/utils/request' +import { toBillStatusCode } from '@/utils/billVo' +import service, { request } from '@/utils/request' -const MOCK_BILLS: Bill[] = [ - { - id: 'bill-001', - planName: '第一期·预付款 比例33%', - billNo: '20260813ZZ251245', - tradeNo: 'T20260819153035678K2M001', - projectName: '某大型银行数字化转型方案', - amount: 20000, - status: '已支付', - createTime: '2026-8-17 14:00', - }, - { - id: 'bill-002', - planName: '第二期·进度款 比例30%', - billNo: '20260813ZZ251246', - projectName: '智慧城市大数据平台建设项目', - amount: 20100, - status: '待支付', - createTime: '2026-8-17 14:00', - }, - { - id: 'bill-003', - planName: '第三期·验收款 比例27%', - billNo: '20260813ZZ251247', - projectName: '三甲医院指挥医疗信息化系统', - amount: 20000, - status: '未到期', - createTime: '2026-8-17 14:00', - }, - { - id: 'bill-004', - planName: '第四期·尾款 比例10%', - billNo: '20260813ZZ251248', - projectName: '智慧城市大数据平台建设项目', - amount: 20100, - status: '未到期', - createTime: '2026-8-17 14:00', - }, - { - id: 'bill-005', - planName: '第二期·进度款 比例30%', - billNo: '20260813ZZ251249', - projectName: '三甲医院指挥医疗信息化系统', - amount: 20100, - status: '待支付', - createTime: '2026-8-16 10:30', - }, - { - id: 'bill-006', - planName: '第一期·预付款 比例33%', - billNo: '20260813ZZ251250', - tradeNo: 'T20260819153035678K2M002', - projectName: '某大型银行数字化转型方案', - amount: 20000, - status: '已支付', - createTime: '2026-8-15 09:12', - }, -] +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/finance/summary → 财务中心首页统计(累计消费总额 + 业务类型分布) +// year / dimension(YEAR|MONTH|QUARTER) / month(1-12) / quarter(1-4) +// ───────────────────────────────────────────────────────────────────────────── -const MOCK_INVOICES: Invoice[] = [ - { - id: 'invoice-001', - planName: '第一期·预付款 比例33%', - billNo: '20260813ZZ251245', - tradeNo: 'T20260819153035678K2M001', - projectName: '某大型银行数字化转型方案', - amount: 20000, - status: '已开票', - applyTime: '2026-8-17 14:00', - }, - { - id: 'invoice-002', - planName: '第一期·预付款 比例33%', - billNo: '20260813ZZ251250', - tradeNo: 'T20260819153035678K2M002', - projectName: '某大型银行数字化转型方案', - amount: 20000, - status: '开票中', - applyTime: '2026-8-17 14:00', - }, - { - id: 'invoice-003', - planName: '第二期·进度款 比例30%', - billNo: '20260813ZZ251249', - projectName: '三甲医院指挥医疗信息化系统', - amount: 20100, - status: '未开票', - applyTime: '2026-8-17 14:00', - }, -] - -const MOCK_TITLES: InvoiceTitle[] = [ - { - id: 'title-001', - type: '企业单位', - title: '山东日照有限有限公司', - taxNo: '344683434513543543545535', - isDefault: true, - }, - { - id: 'title-002', - type: '企业单位', - title: '山东省一周练七次有限公司', - taxNo: '6856754615216565476846', - isDefault: false, - }, -] - -const MOCK_PAYMENTS = new Map() - -const MOCK_RESULTS = new Map() -MOCK_RESULTS.set('bill-001', { - method: 'wechat', - amount: 20000, - payTime: '2026-01-21 15:00:00', - tradeNo: 'T20260819153035678K2M001', - bills: [{ ...MOCK_BILLS[0] }], -}) -MOCK_RESULTS.set('bill-006', { - method: 'wechat', - amount: 20000, - payTime: '2026-01-21 15:00:00', - tradeNo: 'T20260819153035678K2M002', - bills: [{ ...MOCK_BILLS[5] }], -}) - -const DEFAULT_STATS: FinanceStats = { - totalExpense: 1726823900, - month: '2026年1', - pendingCount: 3, - distribution: [ - { name: '生产智造', value: 25, color: '#3370ff' }, - { name: '物联网全案', value: 25, color: '#34c724' }, - { name: '硬件电路', value: 25, color: '#ff8f1f' }, - { name: '互联网软件', value: 25, color: '#f54a45' }, - ], -} - -export function getFinanceStats(period?: string): Promise { - void period - return Promise.resolve(structuredClone(DEFAULT_STATS)) -} - -function isRealBillId(id: string): boolean { - return /^\d+$/.test(id) -} - -async function fetchOwnBills(): Promise { - const rows = await request({ url: '/web/bill/list', method: 'get' }) - return toBills(rows) -} - -function matchBillKeyword(item: Bill, keyword: string): boolean { - if (!keyword) return true - return ( - item.planName.includes(keyword) || - item.billNo.includes(keyword) || - item.projectName.includes(keyword) || - (item.tradeNo?.includes(keyword) ?? false) - ) -} - -export async function getBillList(query: BillQuery): Promise> { - const all = await fetchOwnBills() - const filtered = all.filter((item) => { - if (query.status !== 'all' && item.status !== query.status) return false - return matchBillKeyword(item, query.keyword) - }) - const start = (query.page - 1) * query.pageSize - return { list: filtered.slice(start, start + query.pageSize), total: filtered.length } -} - -export async function getBillDetail(id: string): Promise { - const rows = await request({ url: '/web/bill/list', method: 'get', params: { ids: id } }) - return toBills(rows)[0] ?? null -} - -// ═══════════════════════════════════════════════════════════════════════ -// --------------------------------------------------------------------- -// ═══════════════════════════════════════════════════════════════════════ - -export function createPayment(billId: string, method: PayMethod): Promise { - const bill = MOCK_BILLS.find((item) => item.id === billId) - if (!bill) return Promise.reject(new Error('账单不存在')) - const payment: Payment = { - billId, - method, - amount: bill.amount, - qrExpiresInSeconds: 300, - } - MOCK_PAYMENTS.set(billId, payment) - return Promise.resolve({ ...payment }) -} - -export function switchPaymentMethod(billId: string, method: PayMethod): Promise { - return createPayment(billId, method) -} - -export async function getPayResult(billId: string): Promise { - if (isRealBillId(billId)) { - const bill = await getBillDetail(billId) - if (!bill || bill.status !== '已支付') return null - return { - method: toPayMethod(bill.payChannel), - amount: bill.amount, - payTime: bill.payTime ?? '—', - tradeNo: bill.tradeNo ?? '—', - bills: [bill], - } - } - return getLegacyPayResult(billId) -} - -function getLegacyPayResult(billId: string): Promise { - const existing = MOCK_RESULTS.get(billId) - if (existing) return Promise.resolve(structuredClone(existing)) - - const payment = MOCK_PAYMENTS.get(billId) - const bill = MOCK_BILLS.find((item) => item.id === billId) - if (!payment || !bill) return Promise.resolve(null) - - const tradeNo = bill.tradeNo ?? 'T20260819153035678K2M001' - if (bill.status !== '已支付') { - bill.status = '已支付' - bill.tradeNo = tradeNo - } - const result: PaymentResult = { - method: payment.method, - amount: payment.amount, - payTime: '2026-01-21 15:00:00', - tradeNo, - bills: [{ ...bill }], - } - MOCK_RESULTS.set(billId, result) - return Promise.resolve(structuredClone(result)) -} - -function matchInvoiceKeyword(item: Invoice, keyword: string): boolean { - if (!keyword) return true - return ( - item.planName.includes(keyword) || - item.billNo.includes(keyword) || - item.projectName.includes(keyword) || - (item.tradeNo?.includes(keyword) ?? false) - ) -} - -export function getInvoiceList(query: InvoiceQuery): Promise> { - const filtered = MOCK_INVOICES.filter((item) => { - if (query.status !== 'all' && item.status !== query.status) return false - return matchInvoiceKeyword(item, query.keyword) - }) - const start = (query.page - 1) * query.pageSize - return Promise.resolve({ - list: filtered.slice(start, start + query.pageSize).map((item) => ({ ...item })), - total: filtered.length, +export function getFinanceSummary(query: FinanceSummaryQuery = {}): Promise { + const dimension = query.dimension ?? 'YEAR' + return request({ + url: '/web/finance/summary', + method: 'get', + params: { + year: query.year, + dimension, + month: dimension === 'MONTH' ? query.month : undefined, + quarter: dimension === 'QUARTER' ? query.quarter : undefined, + }, }) } -export function applyInvoice(id: string): Promise { - const found = MOCK_INVOICES.find((item) => item.id === id) - if (!found) return Promise.reject(new Error('发票记录不存在')) - found.status = '开票中' - return Promise.resolve({ ...found }) -} +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/bill/page → 账单分页列表 { total, rows } +// GET /web/bill/statistics → 账单顶部统计(金额合计 / 总笔数 / 待支付笔数) +// GET /web/bill/{id} → 账单详情 +// 查询参数:keyword / status(UNSTARTED/PENDING/PAID/CANCELLED) / bizType / +// pageNum / pageSize / orderByColumn / isAsc +// ───────────────────────────────────────────────────────────────────────────── -export function getInvoiceTitles(): Promise { - return Promise.resolve(MOCK_TITLES.map((item) => ({ ...item }))) -} - -export function createInvoiceTitle(payload: InvoiceTitlePayload): Promise { - const created: InvoiceTitle = { - id: `title-${Date.now()}`, - ...payload, - isDefault: false, +function toBillFilter(query: BillQuery): Record { + return { + keyword: query.keyword || undefined, + status: toBillStatusCode(query.status), } - MOCK_TITLES.push(created) - return Promise.resolve({ ...created }) } -export function updateInvoiceTitle(id: string, payload: InvoiceTitlePayload): Promise { - const found = MOCK_TITLES.find((item) => item.id === id) - if (!found) return Promise.reject(new Error('抬头不存在')) - found.type = payload.type - found.title = payload.title - found.taxNo = payload.taxNo - return Promise.resolve({ ...found }) +export function getBillList(query: BillQuery): Promise> { + return request>({ + url: '/web/bill/page', + method: 'get', + params: { + ...toBillFilter(query), + pageNum: query.page, + pageSize: query.pageSize, + }, + }) +} + +export function getBillStatistics(query: BillQuery): Promise { + return request({ + url: '/web/bill/statistics', + method: 'get', + params: toBillFilter(query), + }) +} + +export function getBillDetail(id: string): Promise { + return request({ + url: `/web/bill/${id}`, + method: 'get', + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/bill/export?format=excel|pdf → 导出账单明细(二进制文件流) +// 该接口不返回统一 JSON 包装,直接用 axios 实例取 Blob。 +// ───────────────────────────────────────────────────────────────────────────── + +export type ExportFormat = 'excel' | 'pdf' + +export async function exportBillReport( + query: BillQuery, + format: ExportFormat = 'excel', +): Promise { + const resp = await service.get('/web/bill/export', { + params: { + ...toBillFilter(query), + format, + }, + responseType: 'blob', + }) + return resp.data +} + +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/pay/channels → 可用支付通道 +// POST /web/pay/bill → 单笔支付 { id, payChannel } → { outTradeNo, qrCode } +// POST /web/pay/bill/batch → 多账单合并支付 { ids, payChannel } → { outTradeNo, qrCode } +// GET /web/pay/query/{outTradeNo} → 支付结果(status/transactionNo/payTime) +// ───────────────────────────────────────────────────────────────────────────── + +export function getPayChannels(): Promise { + return request({ + url: '/web/pay/channels', + method: 'get', + }) +} + +export function payBill(id: string, payChannel: PayChannelCode): Promise { + return request({ + url: '/web/pay/bill', + method: 'post', + data: { id, payChannel }, + }) +} + +export function payBills(ids: string[], payChannel: PayChannelCode): Promise { + return request({ + url: '/web/pay/bill/batch', + method: 'post', + data: { ids, payChannel }, + }) +} + +/** silent:轮询时静默失败,避免瞬时网络异常反复弹提示。 */ +export function queryPayResult(outTradeNo: string, silent = false): Promise { + return request({ + url: `/web/pay/query/${encodeURIComponent(outTradeNo)}`, + method: 'get', + silent, + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// POST /web/pay/refund → 申请退款,返回退款单 ID +// GET /web/pay/refund/page → 我的退款分页列表 +// ───────────────────────────────────────────────────────────────────────────── + +export function applyRefund(payload: FinanceRefundBo): Promise { + return request({ + url: '/web/pay/refund', + method: 'post', + data: payload, + }) +} + +export function getRefundPage(query: FinanceRefundQuery): Promise> { + return request>({ + url: '/web/pay/refund/page', + method: 'get', + params: { + billId: query.billId, + amount: query.amount, + reason: query.reason || undefined, + status: query.status || undefined, + orderByColumn: query.orderByColumn, + isAsc: query.isAsc, + pageNum: query.page, + pageSize: query.pageSize, + }, + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// 发票抬头 +// GET /web/finance/invoice/title/list +// POST /web/finance/invoice/title +// PUT /web/finance/invoice/title +// DELETE /web/finance/invoice/title/{id} +// PUT /web/finance/invoice/title/default/{id} +// ───────────────────────────────────────────────────────────────────────────── + +export function getInvoiceTitleList(): Promise { + return request({ + url: '/web/finance/invoice/title/list', + method: 'get', + }) +} + +export function createInvoiceTitle(payload: FinanceInvoiceTitleBo): Promise { + return request({ + url: '/web/finance/invoice/title', + method: 'post', + data: payload, + }) +} + +export function updateInvoiceTitle(payload: FinanceInvoiceTitleBo): Promise { + return request({ + url: '/web/finance/invoice/title', + method: 'put', + data: payload, + }) } export function deleteInvoiceTitle(id: string): Promise { - const index = MOCK_TITLES.findIndex((item) => item.id === id) - if (index < 0) return Promise.reject(new Error('抬头不存在')) - MOCK_TITLES.splice(index, 1) - return Promise.resolve() + return request({ + url: `/web/finance/invoice/title/${encodeURIComponent(id)}`, + method: 'delete', + }) } -export function setDefaultTitle(id: string): Promise { - for (const item of MOCK_TITLES) { - item.isDefault = item.id === id - } - return Promise.resolve(MOCK_TITLES.map((item) => ({ ...item }))) +export function setDefaultInvoiceTitle(id: string): Promise { + return request({ + url: `/web/finance/invoice/title/default/${encodeURIComponent(id)}`, + method: 'put', + }) } -export function exportReport(): Promise { - return Promise.resolve() -} +// ───────────────────────────────────────────────────────────────────────────── +// 开票申请 / 发票记录 +// GET /web/finance/invoice/available → 可开票账单(已支付且尚无有效发票) +// POST /web/finance/invoice/apply → 申请开票 { billId, titleId, invoiceType } +// GET /web/finance/invoice/page → 发票记录分页 +// GET /web/finance/invoice/{id} → 发票记录详情 +// GET /web/finance/invoice/preview/{id} → 预览电子发票(仅已开票) +// GET /web/finance/invoice/download/{id} → 下载电子发票(仅已开票) +// POST /web/finance/invoice/send-email → 发送电子发票到邮箱(仅已开票) +// ───────────────────────────────────────────────────────────────────────────── -// ═══════════════════════════════════════════════════════════════════════ -// ═══════════════════════════════════════════════════════════════════════ +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/system/dict/data/type/invoice_status → 发票状态字典 +// 字典项:0 未开票 / 1 开票中 / 2 已开票(颜色取 listClass) +// ───────────────────────────────────────────────────────────────────────────── -export async function getCheckoutBills(requirementId: string, ids: string[] = []): Promise { - if (!/^\d+$/.test(requirementId)) return [] - const vo = await request<{ billPlans?: PlanLike[] }>({ - url: `/web/requirementPool/get/finance/${requirementId}`, +export const INVOICE_STATUS_DICT = 'invoice_status' + +export function getInvoiceStatusDict(): Promise { + return request({ + url: `/web/system/dict/data/type/${INVOICE_STATUS_DICT}`, method: 'get', }) - const all = toPlanBills(vo?.billPlans) - return ids.length > 0 - ? all.filter((bill) => ids.includes(bill.id)) - : all.filter((bill) => bill.status === '待支付') } -export async function getPlanPayResult(requirementId: string, planId: string): Promise { - const bills = await getCheckoutBills(requirementId, [planId]) - const bill = bills[0] - if (!bill || bill.status !== '已支付') return null - return { - method: toPayMethod(bill.payChannel), - amount: bill.amount, - payTime: bill.payTime ?? '—', - tradeNo: bill.tradeNo ?? '—', - bills: [bill], +export function getAvailableInvoiceBills(): Promise { + return request({ + url: '/web/finance/invoice/available', + method: 'get', + }) +} + +export function applyInvoice(payload: FinanceInvoiceApplyBo): Promise { + return request({ + url: '/web/finance/invoice/apply', + method: 'post', + data: payload, + }) +} + +export function getInvoicePage(query: FinanceInvoiceQuery): Promise> { + return request>({ + url: '/web/finance/invoice/page', + method: 'get', + params: { + status: query.status, + orderByColumn: query.orderByColumn, + isAsc: query.isAsc, + pageNum: query.page, + pageSize: query.pageSize, + }, + }) +} + +export function getInvoiceDetail(id: string): Promise { + return request({ + url: `/web/finance/invoice/${encodeURIComponent(id)}`, + method: 'get', + }) +} + +export function previewInvoice(id: string): Promise { + return request({ + url: `/web/finance/invoice/preview/${encodeURIComponent(id)}`, + method: 'get', + }) +} + +export interface InvoiceDownloadFile { + blob: Blob + /** 服务器通过 download-filename 响应头下发的文件名 */ + fileName?: string +} + +/** 从 download-filename 响应头取文件名(可能经过 URL 编码)。 */ +function resolveDownloadFileName(value: unknown): string | undefined { + const raw = Array.isArray(value) ? value[0] : value + if (typeof raw !== 'string' || !raw) return undefined + try { + return decodeURIComponent(raw) + } + catch { + return raw } } -export function createWechatNativeOrder( - orderNo: string, - amount: number, - billIds: string[] = [], -): Promise { - return request({ - url: '/pay/web/wechat/native', - method: 'post', - data: { orderNo, amount, billIds }, +/** 下载电子发票(PDF 文件流,不走统一 JSON 包装)。 */ +export async function downloadInvoice(id: string): Promise { + const resp = await service.get(`/web/finance/invoice/download/${encodeURIComponent(id)}`, { + responseType: 'blob', }) + return { + blob: resp.data, + fileName: resolveDownloadFileName(resp.headers['download-filename']), + } } -export function createAlipayPageOrder( - outTradeNo: string, - amount: number, - billIds: string[] = [], -): Promise { - return request({ - url: '/pay/web/alipay/page', +export function sendInvoiceEmail(payload: FinanceInvoiceSendEmailBo): Promise { + return request({ + url: '/web/finance/invoice/send-email', method: 'post', - data: { outTradeNo, amount, billIds }, + data: payload, }) } diff --git a/src/api/message.ts b/src/api/message.ts index 324a809..aad75f7 100644 --- a/src/api/message.ts +++ b/src/api/message.ts @@ -1,146 +1,145 @@ import type { PageResult } from '@/types/api' -import type { Message, MessageQuery } from '@/types/business/message' +import type { + Message, + MessageApiType, + MessageCenterVo, + MessagePageVo, + MessageQuery, + MessageType, + MessageVo, +} from '@/types/business/message' +import { getChatCenterMessages, readAllChatMessages } from '@/api/service' +import { request } from '@/utils/request' +import { + toCenterMessages, + toMessage, + toMessageApiType, + toMessageApiTypes, + toMessages, + WEB_MESSAGE_TYPES, +} from '@/utils/messageVo' -// TODO(api): 待接口文档到位后,将以下 mock 替换为 request 调用 +// ───────────────────────────────────────────────────────────────────────────── +// GET /web/message/center → 状态通知 / 系统通知入口未读数(cs 由客服模块提供) +// GET /web/message/list → type + pageNum/pageSize,返回 { total, rows } +// GET /web/message/detail → id + type +// POST /web/message/readAll → type +// GET /web/chat/message/centerList → 在线客服页签消息分页列表 +// POST /web/chat/message/readAll → 在线客服一键全部已读 +// 列表行字段见 SysMessageVo:messageId/title/message/content/createTime/path/data +// ───────────────────────────────────────────────────────────────────────────── -const MOCK_MESSAGES: Message[] = [ - { - id: 'msg-001', - type: '系统通知', - title: '【新功能】物联网全案"整机联调"看板正式上线', - summary: '整机联调看板已上线,支持联调进度、问题闭环与交付物一览。', - content: '尊敬的用户:\n\n为了提升物联网全案项目的交付透明度,平台已正式上线"整机联调"看板功能。\n\n一、功能亮点\n1、联调进度实时同步:设备接入、协议联调、场景验证各阶段进度一目了然;\n2、问题闭环跟踪:联调过程中产生的缺陷与阻塞项统一登记、分派、闭环;\n3、交付物一览:联调报告、测试记录、验收文档集中展示,随时查阅下载。\n\n二、使用方式\n进入「项目中心 → 项目详情 → 整机联调」即可查看对应看板。已有进行中的物联网全案项目将自动迁移历史数据,无需重新配置。\n\n三、温馨提示\n如在使用过程中遇到问题,可通过「在线客服」联系我们,或联系专属项目经理协助处理。\n\n智联智造平台产品团队\n2026年8月', - publishTime: '2026-08-06 10:00', - isRead: false, - attachments: [ - { name: '物联网全案服务介绍.pdf', size: 2.5 * 1024 * 1024, uploadTime: '2026-08-06 10:00', url: '' }, - ], - }, - { - id: 'msg-002', - type: '系统通知', - title: '平台 v2.6 版本更新公告', - summary: '新增需求提报模板、案例库对比功能,并优化了消息中心体验。', - content: '尊敬的用户:\n\n平台 v2.6 版本已于近日发布,本次更新内容如下:\n\n一、新增功能\n1、需求提报模板:常用需求类型支持保存为模板,一键复用;\n2、案例库对比:最多选择 4 个案例进行横向对比,辅助决策;\n3、消息中心改版:分类标签、关键词搜索、全部已读一站式处理。\n\n二、体验优化\n1、列表页加载性能提升约 40%;\n2、移动端适配细节修复;\n3、附件上传支持 1GB 大文件。\n\n感谢您一直以来的支持,祝使用愉快!', - publishTime: '2026-07-15 14:30', - isRead: false, - attachments: [], - }, - { - id: 'msg-003', - type: '系统通知', - title: '关于平台服务时间调整的通知', - summary: '自 2026-09-01 起,在线客服服务时间调整为 9:00-21:00。', - content: '尊敬的用户:\n\n为进一步提升服务质量,自 2026 年 9 月 1 日起,在线客服服务时间调整如下:\n\n服务时间:每日 9:00 - 21:00(法定节假日照常服务)\n非服务时段提交的留言,我们将在下一个服务时段内尽快回复。\n\n紧急事务可通过专属项目经理电话联系。\n\n感谢您的理解与支持!', - publishTime: '2026-08-28 09:00', - isRead: true, - attachments: [], - }, - { - id: 'msg-004', - type: '状态通知', - title: '合同生效通知', - summary: '您的合同已正式生效,合同编号 CZ-2026-0815 已开始生效。', - content: '您好:\n\n您的合同已正式生效。\n\n合同编号:CZ-2026-0815\n合同名称:智能园区综合管理平台开发合同\n生效日期:2026-08-15\n\n合同已开始生效,可随时在「合同中心」查看详情及履约进度。\n\n如有疑问,请联系您的专属项目经理。', - publishTime: '2026-08-15 16:42', - isRead: false, - attachments: [], - }, - { - id: 'msg-005', - type: '状态通知', - title: '项目进度更新:需求确认阶段已完成', - summary: '「智能工厂物联网整体解决方案」需求确认已完成,即将进入方案设计。', - content: '您好:\n\n您的项目进度已更新:\n\n项目名称:智能工厂物联网整体解决方案\n当前阶段:需求确认 ✅ 已完成\n下一阶段:方案设计\n\n项目组将于 3 个工作日内提交初步方案,届时会再次通知您。您也可以前往「项目中心」查看详细进度与里程碑。\n\n感谢您的配合!', - publishTime: '2026-08-20 11:05', - isRead: false, - attachments: [], - }, - { - id: 'msg-006', - type: '状态通知', - title: '账单待办提醒', - summary: '您有一笔待付款账单,账单编号 BILL-202608-023,请及时处理。', - content: '您好:\n\n您有一笔待付款账单,请及时处理:\n\n账单编号:BILL-202608-023\n关联项目:电商中台系统定制开发\n账单金额:150,000.00 元\n到期日期:2026-09-10\n\n请前往「财务中心 → 账单管理」完成支付。如对账单有疑问,请通过在线客服联系我们。\n\n温馨提示:逾期支付可能影响项目排期,请留意处理时间。', - publishTime: '2026-08-25 10:00', - isRead: true, - attachments: [], - }, - { - id: 'msg-007', - type: '在线客服', - title: '您好,请问有什么可以帮您的?', - summary: '专属客服小助手已收到您的咨询,将尽快为您答复。', - content: '您好,欢迎咨询智联智造平台!\n\n我是您的专属客服小助手,请问有什么可以帮您的?\n\n您可以咨询:\n1、物联网全案开发的流程与周期\n2、项目进度查询\n3、合同与账单相关问题\n4、平台操作指引\n\n我们将在服务时间内尽快回复您。', - publishTime: '2026-08-21 10:25', - isRead: false, - attachments: [], - }, - { - id: 'msg-008', - type: '在线客服', - title: '您的咨询已有回复', - summary: '关于"整机联调周期"的咨询已回复,点击查看详细内容。', - content: '您好:\n\n关于您咨询的"整机联调周期"问题,客服回复如下:\n\n一般物联网全案项目的整机联调周期为 2-4 周,具体取决于设备数量、协议复杂度与场景验证范围。常规智能家居类项目约 2 周,工业场景多设备联调约 3-4 周。\n\n详细排期以项目计划为准,您可在「项目中心」查看最新里程碑。\n\n如还有其他问题,欢迎继续咨询!', - publishTime: '2026-08-19 15:40', - isRead: true, - attachments: [], - }, - { - id: 'msg-009', - type: '在线客服', - title: '会话满意度回访', - summary: '您上次的会话已结束,欢迎对本次服务进行评价。', - content: '您好:\n\n您于 2026-08-18 的会话已结束,感谢您的咨询!\n\n欢迎对本次服务进行评价,您的反馈将帮助我们持续改进。如问题未得到解决,可直接回复本条消息,我们将重新为您跟进。\n\n祝您使用愉快!', - publishTime: '2026-08-18 17:00', - isRead: false, - attachments: [], - }, -] - -function applyFilters(query: MessageQuery): Message[] { - return MOCK_MESSAGES.filter((item) => { - if (query.type !== 'all' && item.type !== query.type) return false - if (query.keyword && !item.title.includes(query.keyword) && !item.summary.includes(query.keyword)) return false - return true +/** silent:轮询未读数时静默失败,避免瞬时网络异常反复弹提示。 */ +export function getMessageCenter(silent = false): Promise { + return request({ + url: '/web/message/center', + method: 'get', + silent, }) } -export function getMessageList(query: MessageQuery): Promise> { - const filtered = applyFilters(query) +function getMessagePage( + type: MessageApiType, + pageNum: number, + pageSize: number, +): Promise> { + return request>({ + url: '/web/message/list', + method: 'get', + params: { type, pageNum, pageSize }, + }) +} + +function filterByKeyword(list: Message[], keyword: string): Message[] { + if (!keyword) return list + return list.filter((item) => item.title.includes(keyword) || item.summary.includes(keyword)) +} + +/** + * 「全部」后端不支持一次查多个 type,按状态通知 + 系统通知 + 在线客服分别取到当前页并合并排序; + * 单个 tab 直接按 pageNum/pageSize 分页,在线客服走独立接口 /web/chat/message/centerList。 + */ +export async function getMessageList(query: MessageQuery): Promise> { + const keyword = query.keyword.trim() + + if (query.type === '在线客服') { + const page = await getChatCenterMessages({ pageNum: query.page, pageSize: query.pageSize }) + return { + list: filterByKeyword(toCenterMessages(page.rows), keyword), + total: Number(page.total ?? 0), + } + } + + const types: MessageApiType[] = query.type === 'all' ? WEB_MESSAGE_TYPES : [toMessageApiType(query.type)] + const fetchSize = query.type === 'all' ? query.page * query.pageSize : query.pageSize + + const [pages, chatPage] = await Promise.all([ + Promise.all( + types.map((type) => + query.type === 'all' + // 单个入口失败不影响另一个入口展示 + ? getMessagePage(type, 1, fetchSize).catch(() => null) + : getMessagePage(type, query.page, fetchSize), + ), + ), + query.type === 'all' + ? getChatCenterMessages({ pageNum: 1, pageSize: fetchSize }).catch(() => null) + : null, + ]) + + let total = 0 + const rows: Message[] = [] + pages.forEach((page, index) => { + if (!page) return + total += Number(page.total ?? 0) + rows.push(...toMessages(page.rows, types[index] ?? types[0])) + }) + if (chatPage) { + total += Number(chatPage.total ?? 0) + rows.push(...toCenterMessages(chatPage.rows)) + } + + const sorted = filterByKeyword(rows, keyword) + .sort((a, b) => b.publishTime.localeCompare(a.publishTime)) + + if (query.type !== 'all') { + return { list: sorted, total: Number(pages[0]?.total ?? 0) } + } + const start = (query.page - 1) * query.pageSize - return Promise.resolve({ - list: filtered.slice(start, start + query.pageSize), - total: filtered.length, + return { list: sorted.slice(start, start + query.pageSize), total } +} + +export async function getMessageDetail( + id: string, + type: MessageApiType, +): Promise { + const vo = await request({ + url: '/web/message/detail', + method: 'get', + params: { id, type }, }) + return vo ? toMessage(vo, type) : null } -export function getMessageDetail(id: string): Promise { - const found = MOCK_MESSAGES.find((item) => item.id === id) ?? null - return Promise.resolve(found ? { ...found } : null) -} +export async function markAllRead(type: MessageType | 'all'): Promise { + const requests: Promise[] = [] -export function markAllRead(): Promise { - for (const item of MOCK_MESSAGES) { - item.isRead = true + // 在线客服是独立接口且不区分 type,按范围分别调用 + if (type === 'all' || type === '在线客服') { + requests.push(readAllChatMessages()) } - return Promise.resolve() -} - -export function markRead(id: string): Promise { - const found = MOCK_MESSAGES.find((item) => item.id === id) - if (found) found.isRead = true - return Promise.resolve() -} - -export function getTabCounts(): Promise<{ all: number; 在线客服: number; 状态通知: number; 系统通知: number }> { - const counts = { all: MOCK_MESSAGES.length, 在线客服: 0, 状态通知: 0, 系统通知: 0 } - for (const item of MOCK_MESSAGES) { - counts[item.type] += 1 + if (type !== '在线客服') { + toMessageApiTypes(type).forEach((item) => { + requests.push( + request({ + url: '/web/message/readAll', + method: 'post', + params: { type: item }, + }), + ) + }) } - return Promise.resolve(counts) -} -export function getUnreadCount(): Promise { - return Promise.resolve(MOCK_MESSAGES.filter((item) => !item.isRead).length) + await Promise.all(requests) } diff --git a/src/api/oss.ts b/src/api/oss.ts index 7edcc63..cf42be2 100644 --- a/src/api/oss.ts +++ b/src/api/oss.ts @@ -1,4 +1,5 @@ import service from '@/utils/request' +import { readBlobErrorMessage } from '@/utils/download' export async function fetchOssPreviewBlob(ossId: string | number): Promise { const resp = await service.get(`/web/workOrderDraft/preview/${ossId}`, { @@ -6,3 +7,14 @@ export async function fetchOssPreviewBlob(ossId: string | number): Promise }) return resp.data as Blob } + +/** 下载 OSS 文件(用于编辑弹窗里刚上传、尚未保存的附件)。 */ +export async function downloadOssFile(ossId: string | number): Promise { + const resp = await service.get(`/web/resource/oss/download/${ossId}`, { + responseType: 'blob', + }) + if (resp.data.type.startsWith('application/json')) { + throw new Error(await readBlobErrorMessage(resp.data)) + } + return resp.data +} diff --git a/src/api/profile.ts b/src/api/profile.ts index 0aaacdc..75b59e3 100644 --- a/src/api/profile.ts +++ b/src/api/profile.ts @@ -1,350 +1,350 @@ -import type { BusinessType, PageResult } from '@/types/api' -import type { Case } from '@/types/business/cases' +import type { BusinessType, FileInfo, PageResult } from '@/types/api' +import type { Case, ProjectCaseVo } from '@/types/business/cases' import type { Address, ChangePasswordParams, Feedback, + FeedbackVo, FavoritesQuery, HelpFaqGroup, ListQuery, Profile, + ProfilePageVo, + ProfileUploadVo, Qualification, QualificationInput, + UserAddressVo, + UserQualificationVo, } from '@/types/business/profile' +import { getProjectCaseCount } from '@/api/cases' +import { + getAccountSecurity, + getUserProfile, + updateUserProfile as updateUserProfileApi, +} from '@/api/user' +import { formatDate, toBusinessType } from '@/utils/format' +import { toCase } from '@/utils/caseVo' +import { readBlobErrorMessage, resolveContentDispositionFileName } from '@/utils/download' +import { + toAddressBo, + toAddresses, + toFeedbackBo, + toProfile, + toQualificationBo, + toQualifications, +} from '@/utils/profileVo' +import service, { request } from '@/utils/request' -// TODO(api): 待接口文档到位后,将以下 mock 替换为 request 调用(页面 → store → api 数据流不变) +// ───────────────────────────────────────────────────────────────────────────── +// 个人资料 / 账号安全 +// ───────────────────────────────────────────────────────────────────────────── -const MOCK_PROFILE: Profile = { - nickname: '王永志', - phone: '186****618', - email: 'yongzh******4@163.com', - passwordModifiedAt: '15天前', +export async function getProfile(): Promise { + const [user, security] = await Promise.all([ + getUserProfile(), + // 账号安全接口异常不阻塞基本资料展示(老用户字段也可能为 null) + getAccountSecurity().catch(() => null), + ]) + return toProfile(user, security) } -export function getProfile(): Promise { - return Promise.resolve({ ...MOCK_PROFILE }) +export async function updateNickname(name: string): Promise { + await updateUserProfileApi({ nickName: name }) + return getProfile() } -export function updateNickname(name: string): Promise { - MOCK_PROFILE.nickname = name - return Promise.resolve({ ...MOCK_PROFILE }) +export async function updateAvatar(avatar: string): Promise { + await updateUserProfileApi({ avatar }) + return getProfile() +} + +/** 通用文件上传(POST /web/profile/upload,字段名固定 file)。 */ +export function uploadProfileFile(file: File): Promise { + const data = new FormData() + data.append('file', file) + return request({ + url: '/web/profile/upload', + method: 'post', + data, + headers: { 'Content-Type': 'multipart/form-data' }, + }) +} + +/** 上传并转成页面 FileInfo,便于附件列表统一展示。 */ +export async function uploadProfileAttachment(file: File): Promise { + const vo = await uploadProfileFile(file) + return { + ossId: vo.ossId, + name: vo.originalName || file.name, + size: file.size, + uploadTime: formatDate(new Date()), + url: vo.url, + } } export function changePassword(params: ChangePasswordParams): Promise { - MOCK_PROFILE.passwordModifiedAt = '刚刚' - void params - return Promise.resolve() + return request({ + url: '/web/profile/password/reset', + method: 'post', + data: { + phoneNumber: params.phoneNumber ?? '', + smsCode: params.code, + newPassword: params.password, + confirmPassword: params.password, + }, + }) } -export function bindPhone(phone: string, code: string): Promise { - void code - MOCK_PROFILE.phone = phone - return Promise.resolve({ ...MOCK_PROFILE }) +/** 发送绑定手机号用的短信验证码。 */ +export function sendBindSmsCode(phone: string): Promise { + return request({ + url: '/web/profile/sms/send', + method: 'post', + params: { phone }, + }) } -export function bindEmail(email: string, code: string): Promise { - void code - MOCK_PROFILE.email = email - return Promise.resolve({ ...MOCK_PROFILE }) +/** 发送绑定邮箱的邮件验证码(发到目标邮箱)。 */ +export function sendBindEmailCode(email: string): Promise { + return request({ + url: '/web/profile/email/send', + method: 'post', + params: { email }, + }) } -export function unbindEmail(): Promise { - MOCK_PROFILE.email = '' - return Promise.resolve({ ...MOCK_PROFILE }) +export async function bindPhone(phone: string, code: string): Promise { + await request({ + url: '/web/profile/phone/bind', + method: 'post', + params: { phone, code }, + }) + return getProfile() } -export function verifyIdentity(phone: string, code: string): Promise { - void phone - void code - return Promise.resolve() +export function unbindPhone(): Promise { + return request({ + url: '/web/profile/phone/unbind', + method: 'post', + }) } -export function deleteAccount(): Promise { - return Promise.resolve() +export async function bindEmail(email: string, code: string): Promise { + await request({ + url: '/web/profile/email/bind', + method: 'post', + params: { email, code }, + }) + return getProfile() } -const MOCK_ADDRESSES: Address[] = [ - { - id: 'addr-1', - receiverName: '王永志', - phone: '18556669516', - region: '山东省日照市东港区', - detailAddress: '凌云购物广场三楼', - isDefault: true, - }, - { - id: 'addr-2', - receiverName: '王永志', - phone: '18556669516', - region: '山东省日照市东港区', - detailAddress: '海曲东路 12 号研发中心 A 座 8 层', - isDefault: false, - }, - { - id: 'addr-3', - receiverName: '李晓婷', - phone: '13863331234', - region: '山东省青岛市市南区', - detailAddress: '香港中路 76 号 A 座 18 层', - isDefault: false, - }, - { - id: 'addr-4', - receiverName: '王永志', - phone: '18556669516', - region: '山东省济南市历下区', - detailAddress: '经十路 9999 号舜耕大厦 12 层', - isDefault: false, - }, -] +export async function unbindEmail(): Promise { + await request({ + url: '/web/profile/email/unbind', + method: 'post', + }) + return getProfile() +} -function paginate(list: T[], query: ListQuery): PageResult { +/** 注销账号:验证码合并到 cancel,phone 必须是账号绑定手机号。 */ +export function deleteAccount(phone: string, code: string): Promise { + return request({ + url: '/web/profile/cancel', + method: 'post', + params: { phone, code }, + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// 地址:/web/profile/address/* +// 列表接口返回全量数组,前端按页切片以复用现有分页组件。 +// ───────────────────────────────────────────────────────────────────────────── + +export async function getAddresses(query: ListQuery): Promise> { + const rows = await request({ + url: '/web/profile/address/list', + method: 'get', + }) + const list = toAddresses(rows) const start = (query.page - 1) * query.pageSize - return { - list: list.slice(start, start + query.pageSize), - total: list.length, - } + return { list: list.slice(start, start + query.pageSize), total: list.length } } -export function getAddresses(query: ListQuery): Promise> { - return Promise.resolve(paginate(MOCK_ADDRESSES, query)) +export async function createAddress(input: Omit): Promise
{ + const id = await request({ + url: '/web/profile/address', + method: 'post', + data: toAddressBo(input), + }) + return { id: String(id ?? ''), ...input, isDefault: false } } -export function createAddress(input: Omit): Promise
{ - const created: Address = { - ...input, - id: `addr-${Date.now()}`, - isDefault: MOCK_ADDRESSES.length === 0, - } - MOCK_ADDRESSES.push(created) - return Promise.resolve({ ...created }) -} - -export function updateAddress(id: string, input: Omit): Promise
{ - const found = MOCK_ADDRESSES.find((item) => item.id === id) - if (!found) return Promise.reject(new Error('地址不存在')) - Object.assign(found, input) - return Promise.resolve({ ...found }) +export async function updateAddress( + id: string, + input: Omit, +): Promise
{ + await request({ + url: `/web/profile/address/${encodeURIComponent(id)}`, + method: 'put', + data: toAddressBo(input), + }) + return { id, ...input, isDefault: false } } export function deleteAddress(id: string): Promise { - const index = MOCK_ADDRESSES.findIndex((item) => item.id === id) - if (index >= 0) MOCK_ADDRESSES.splice(index, 1) - return Promise.resolve() -} - -export function setDefaultAddress(id: string): Promise { - for (const item of MOCK_ADDRESSES) { - item.isDefault = item.id === id - } - return Promise.resolve(MOCK_ADDRESSES.map((item) => ({ ...item }))) -} - -const MOCK_FAVORITES: Case[] = [ - { - id: 'fav-1', - title: '自动化生产线升级改造项目', - category: 'manufacturing', - cover: '', - finishDate: '2026/8/10', - teamSize: 50, - scale: '300万', - industry: '自动化', - duration: '150个工作日', - clientType: '企业', - sections: [ - { title: '项目背景', content: '

传统产线效率低、人工依赖高,客户需要通过自动化升级提升产能与品控水平。

' }, - { title: '客户痛点', content: '

1、产线依赖人工巡检,异常响应慢;2、设备数据孤岛,缺乏统一监控;3、工艺参数无法追溯。

' }, - { title: '需求描述', content: '

建设产线数据采集与监控平台,完成关键工位自动化改造,打通 MES 系统接口。

' }, - { title: '交付物', content: '

1、产线自动化改造方案;2、PLC 控制程序与上位机软件;3、数据看板与运维手册;4、培训与质保服务。

' }, - ], - video: '', - isFavorite: true, - favoriteCount: 0, - }, - { - id: 'fav-2', - title: '智能工厂物联网整体解决方案', - category: 'iot', - cover: '', - finishDate: '2026/8/10', - teamSize: 30, - scale: '500万', - industry: '工厂服务', - duration: '200个工作日', - clientType: '企业', - sections: [ - { title: '项目背景', content: '

园区工厂多系统独立运行,能耗与设备管理粗放,需要整体数字化升级。

' }, - { title: '客户痛点', content: '

1、门禁/监控/能耗子系统数据不互通;2、能源浪费缺乏精细监测;3、决策缺少实时数据支撑。

' }, - { title: '需求描述', content: '

构建 IoT 平台接入设备数据,建设综合驾驶舱,实现能耗监测与智能告警。

' }, - { title: '交付物', content: '

1、IoT 接入平台;2、综合驾驶舱大屏;3、能耗分析系统;4、集成联调与培训服务。

' }, - ], - video: '', - isFavorite: true, - favoriteCount: 0, - }, - { - id: 'fav-3', - title: '智能穿戴设备PCB设计与量产', - category: 'hardware', - cover: '', - finishDate: '2026/8/10', - teamSize: 50, - scale: '10-50万', - industry: '智能设备', - duration: '30个工作日', - clientType: '企业', - sections: [ - { title: '项目背景', content: '

客户推出新一代智能穿戴产品,需要高集成度低功耗 PCB 设计并快速量产。

' }, - { title: '客户痛点', content: '

1、板载空间受限,器件布局密集;2、功耗要求严格;3、量产良率需爬坡。

' }, - { title: '需求描述', content: '

完成原理图与 PCB 设计、打样验证、SMT 贴片与整机装配量产。

' }, - { title: '交付物', content: '

1、原理图与 PCB 设计文件;2、样板与测试报告;3、量产良率报告;4、BOM 与工艺文件。

' }, - ], - video: '', - isFavorite: true, - favoriteCount: 0, - }, - { - id: 'fav-4', - title: '智能园区综合管理平台开发', - category: 'internet', - cover: '', - finishDate: '2026/8/10', - teamSize: 20, - scale: '200万', - industry: '园区服务', - duration: '200个工作日', - clientType: '企业', - sections: [ - { title: '项目背景', content: '

传统园区管理普遍"数据孤岛",安防、能耗、物业、招商等系统独立运行,缺乏联动,管理手段依赖人工巡检和纸质流程。

' }, - { title: '客户痛点', content: '

1、运营效率低下:安保依赖人工巡逻;2、系统孤岛严重:门禁、监控、停车、能耗等子系统独立建设;3、能源浪费突出;4、服务体验欠佳;5、决策缺乏依据;6、安全隐患犹存。

' }, - { title: '需求描述', content: '

打造集"感知、预警、分析、决策、服务"于一体的智能园区综合管理平台,打通园区各子系统壁垒,实现全场景数字化覆盖。

' }, - { title: '交付物', content: '

1、Web 端管理平台(驾驶舱/安防/能源/物业);2、移动端服务门户;3、IoT 平台与数据大屏;4、全套技术文档;5、培训与不少于1年免费质保。

' }, - ], - video: '', - isFavorite: true, - favoriteCount: 0, - }, -] - -export function getFavorites(query: FavoritesQuery): Promise> { - const filtered = MOCK_FAVORITES.filter((item) => { - if (query.category !== 'all' && item.category !== query.category) return false - if (query.keyword && !item.title.includes(query.keyword)) return false - return true + return request({ + url: `/web/profile/address/${encodeURIComponent(id)}`, + method: 'delete', }) +} + +export function setDefaultAddress(id: string): Promise { + return request({ + url: `/web/profile/address/${encodeURIComponent(id)}/default`, + method: 'post', + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// 收藏:/web/profile/favorite/{caseId}、/web/profile/favorite/page +// ───────────────────────────────────────────────────────────────────────────── + +export async function getFavorites(query: FavoritesQuery): Promise> { + const page = await request>({ + url: '/web/profile/favorite/page', + method: 'get', + params: { pageNum: query.page, pageSize: query.pageSize }, + }) + const rows = (page?.rows ?? []).filter((item) => item != null && item.id != null) + return { list: rows.map((vo) => toCase(vo)), total: Number(page?.total ?? 0) } +} + +/** 案例分类统计:走 /web/projectCase/count,不再拉收藏列表本地汇总。 */ +export async function getCaseCounts(): Promise>> { + const stats = await getProjectCaseCount() + const counts: Partial> = {} + for (const item of stats?.projectCaseCounts ?? []) { + if (item == null) continue + const type = toBusinessType(item.businessType) + counts[type] = (counts[type] ?? 0) + (item.caseCount ?? 0) + } + return counts +} + +export function favoriteCase(caseId: string): Promise { + return request({ + url: `/web/profile/favorite/${encodeURIComponent(caseId)}`, + method: 'post', + }) +} + +export function unfavoriteCase(caseId: string): Promise { + return request({ + url: `/web/profile/unfavorite/${encodeURIComponent(caseId)}`, + method: 'post', + }) +} + +// ───────────────────────────────────────────────────────────────────────────── +// 资质:/web/profile/qualification/* +// 列表接口返回全量数组,前端按页切片以复用现有分页组件。 +// ───────────────────────────────────────────────────────────────────────────── + +export async function getQualifications(query: ListQuery): Promise> { + const rows = await request({ + url: '/web/profile/qualification/list', + method: 'get', + }) + const list = toQualifications(rows) const start = (query.page - 1) * query.pageSize - return Promise.resolve({ - list: filtered.slice(start, start + query.pageSize).map((item) => ({ ...item })), - total: filtered.length, + return { list: list.slice(start, start + query.pageSize), total: list.length } +} + +export async function createQualification(input: QualificationInput): Promise { + const id = await request({ + url: '/web/profile/qualification', + method: 'post', + data: toQualificationBo(input), }) + return { id: String(id ?? ''), ...input, status: '审核中' } } -export function getCaseCounts(): Promise>> { - const counts: Partial> = { - internet: 1, - hardware: 1, - iot: 1, - manufacturing: 1, - } - return Promise.resolve(counts) -} - -const MOCK_QUALIFICATIONS: Qualification[] = [ - { - id: 'qual-1', - type: '体系认证', - certName: 'ISO9001 质量管理体系认证证书', - certNo: 'ISO202609080075', - issuer: '中国质量认证中心', - validFrom: '2026-9-10', - validTo: '2027-9-10', - status: '已认证', - attachments: [ - { name: '体系认证证书', size: 1_048_576, uploadTime: '2026-09-10', url: '' }, - ], - }, - { - id: 'qual-2', - type: '营业执照', - certName: '营业执照', - certNo: '91371102MA3XX8876Q', - issuer: '日照市东港区市场监督管理局', - validFrom: '2020-3-15', - validTo: '2030-3-14', - status: '审核中', - attachments: [ - { name: '营业执照', size: 820_000, uploadTime: '2026-09-12', url: '' }, - ], - }, - { - id: 'qual-3', - type: '检测报告', - certName: '智能终端产品第三方检测报告', - certNo: 'WT20260512001', - issuer: '山东省产品质量检验研究院', - validFrom: '2026-5-12', - validTo: '2027-5-12', - status: '未通过', - attachments: [ - { name: '检测报告', size: 2_097_152, uploadTime: '2026-05-15', url: '' }, - ], - }, - { - id: 'qual-4', - type: '生产许可证', - certName: '全国工业产品生产许可证', - certNo: 'XK06-123-45678', - issuer: '山东省市场监督管理局', - validFrom: '2024-1-8', - validTo: '2029-1-7', - status: '已认证', - attachments: [ - { name: '生产许可证', size: 1_258_291, uploadTime: '2024-01-10', url: '' }, - ], - }, -] - -export function getQualifications(query: ListQuery): Promise> { - return Promise.resolve(paginate(MOCK_QUALIFICATIONS, query)) -} - -export function createQualification(input: QualificationInput): Promise { - const created: Qualification = { - ...input, - id: `qual-${Date.now()}`, - status: '审核中', - } - MOCK_QUALIFICATIONS.unshift(created) - return Promise.resolve({ ...created }) -} - -export function updateQualification(id: string, input: QualificationInput): Promise { - const found = MOCK_QUALIFICATIONS.find((item) => item.id === id) - if (!found) return Promise.reject(new Error('资质不存在')) - found.type = input.type - found.certName = input.certName - found.certNo = input.certNo - found.issuer = input.issuer - found.validFrom = input.validFrom - found.validTo = input.validTo - found.attachments = input.attachments - if (found.status === '未通过') found.status = '审核中' - return Promise.resolve({ ...found }) +export async function updateQualification( + id: string, + input: QualificationInput, +): Promise { + await request({ + url: `/web/profile/qualification/${encodeURIComponent(id)}`, + method: 'put', + data: toQualificationBo(input), + }) + return { id, ...input, status: '审核中' } } export function deleteQualification(id: string): Promise { - const index = MOCK_QUALIFICATIONS.findIndex((item) => item.id === id) - if (index >= 0) MOCK_QUALIFICATIONS.splice(index, 1) - return Promise.resolve() + return request({ + url: `/web/profile/qualification/${encodeURIComponent(id)}`, + method: 'delete', + }) } -export function submitFeedback(feedback: Feedback): Promise { - void feedback - return Promise.resolve() +export function resubmitQualification(id: string): Promise { + return request({ + url: `/web/profile/qualification/${encodeURIComponent(id)}/resubmit`, + method: 'post', + }) } -/** TODO(api): 后端帮助中心接口就绪后改为 request 调用;暂用设计稿假数据 */ +export interface QualificationDownloadFile { + blob: Blob + /** 后端通过 Content-Disposition 下发的文件名(证书名称 + 序号 + 扩展名) */ + fileName?: string +} + +/** + * 下载已保存的资质附件(文件流,不走统一 JSON 包装)。 + * index 为该附件在列表中的下标,从 0 开始,不传默认 0。 + */ +export async function downloadQualificationAttachment( + id: string, + index = 0, +): Promise { + const resp = await service.get( + `/web/profile/qualification/${encodeURIComponent(id)}/download`, + { params: { index }, responseType: 'blob' }, + ) + // 后端报错时返回 JSON,被 axios 包成 Blob + if (resp.data.type.startsWith('application/json')) { + throw new Error(await readBlobErrorMessage(resp.data)) + } + return { + blob: resp.data, + fileName: resolveContentDispositionFileName(resp.headers['content-disposition']), + } +} + +// ───────────────────────────────────────────────────────────────────────────── +// 反馈:/web/profile/feedback、/web/profile/feedback/page +// ───────────────────────────────────────────────────────────────────────────── + +export async function submitFeedback(feedback: Feedback): Promise { + await request({ + url: '/web/profile/feedback', + method: 'post', + data: toFeedbackBo(feedback), + }) +} + +/** 我的反馈分页(页面暂未使用,接口先接好)。 */ +export function getFeedbackPage(query: ListQuery): Promise> { + return request>({ + url: '/web/profile/feedback/page', + method: 'get', + params: { pageNum: query.page, pageSize: query.pageSize }, + }) +} + +/** 后端确认不提供 FAQ 接口(2026-11-03),保留设计稿静态文案。 */ export function getHelpFaqs(): Promise { return Promise.resolve([ { diff --git a/src/api/service.ts b/src/api/service.ts index 37a430e..6dd2ce6 100644 --- a/src/api/service.ts +++ b/src/api/service.ts @@ -1,68 +1,94 @@ -import type { ChatMessage } from '@/types/business/service' +import type { + ChatUploadVo, + CsMessageCenterQuery, + CsMessagePageVo, + CsMessageVo, + CsSessionPreviewVo, + CsSessionVo, + SendCsMessageParams, +} from '@/types/business/service' +import { request } from '@/utils/request' -// TODO(api): 待接口文档到位后,将以下 mock 替换为 request 调用 +// ───────────────────────────────────────────────────────────────────────────── +// POST /web/chat/session/init → 获取/创建当前客户的客服会话 +// GET /web/chat/message/list → 按 sessionId 拉会话消息 +// POST /web/chat/message → 客户发送消息(TEXT/IMAGE/FILE/VOICE) +// GET /web/chat/session/preview → 消息中心「在线客服」卡片未读数 + 最新一条 +// GET /web/chat/message/centerList → 消息中心「在线客服」页签消息分页列表 +// POST /web/chat/message/readAll → 消息中心「在线客服」一键全部已读 +// 文档未提供聊天附件上传接口,复用用户端 OSS 上传(files 多文件,取首个结果) +// ───────────────────────────────────────────────────────────────────────────── -let seq = 0 - -function nextId(prefix: string): string { - seq += 1 - return `${prefix}-${Date.now()}-${seq}` -} - -function nowTime(): string { - const date = new Date() - const pad = (n: number): string => (n < 10 ? `0${n}` : String(n)) - return `今天 ${pad(date.getHours())}:${pad(date.getMinutes())}` -} - -export function getChatHistory(): Promise { - return Promise.resolve([ - { - id: 'chat-001', - role: 'assistant', - content: '您好,欢迎咨询智联智造平台!我是您的专属客服小助手,请问有什么可以帮您的?', - time: '今天 10:23', +export function initChatSession(params?: { + chatType?: string + contact?: string +}): Promise { + return request({ + url: '/web/chat/session/init', + method: 'post', + params: { + chatType: params?.chatType || undefined, + contact: params?.contact || undefined, }, - { - id: 'chat-002', - role: 'user', - content: '我想咨询一下物联网全案开发的流程和周期', - time: '今天 10:23', - }, - { - id: 'chat-003', - role: 'assistant', - content: '', - file: { name: '物联网全案服务介绍.pdf', size: 2.5 * 1024 * 1024 }, - time: '今天 10:24', - }, - ]) -} - -export function sendChatMessage(content: string): Promise { - return Promise.resolve({ - id: nextId('chat'), - role: 'user', - content, - time: nowTime(), }) } -export function uploadChatFile(file: File): Promise { - return Promise.resolve({ - id: nextId('chat'), - role: 'user', - content: '', - file: { name: file.name, size: file.size }, - time: nowTime(), +export function getChatMessages( + sessionId: number | string, + silent = false, +): Promise { + return request({ + url: '/web/chat/message/list', + method: 'get', + params: { sessionId }, + silent, }) } -export function mockAutoReply(): Promise { - return Promise.resolve({ - id: nextId('chat'), - role: 'assistant', - content: '收到您的消息,专属客服稍后为您答复~', - time: nowTime(), +export function sendChatMessage(payload: SendCsMessageParams): Promise { + return request({ + url: '/web/chat/message', + method: 'post', + data: payload, }) } + +/** 消息中心「在线客服」页签消息分页列表。 */ +export function getChatCenterMessages(query: CsMessageCenterQuery): Promise { + return request({ + url: '/web/chat/message/centerList', + method: 'get', + params: query, + }) +} + +/** 消息中心「在线客服」一键全部已读。 */ +export function readAllChatMessages(): Promise { + return request({ + url: '/web/chat/message/readAll', + method: 'post', + }) +} + +/** silent:轮询未读数时静默失败,避免瞬时网络异常反复弹提示。 */ +export function getChatSessionPreview(silent = false): Promise { + return request({ + url: '/web/chat/session/preview', + method: 'get', + silent, + }) +} + +export async function uploadChatFile(file: File): Promise { + const form = new FormData() + form.append('files', file) + const rows = await request({ + url: '/app/requirement/oss/upload', + method: 'post', + data: form, + headers: { 'Content-Type': 'multipart/form-data' }, + }) + const uploaded = rows?.[0] + if (!uploaded?.url) throw new Error('文件上传失败') + return { ...uploaded, url: uploaded.url } +} diff --git a/src/api/user.ts b/src/api/user.ts index 3c863b4..78a0058 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,5 +1,9 @@ import { request } from '@/utils/request' -import type { UserProfileVo } from '@/types/business/user' +import type { + AccountSecurityVo, + UserProfileUpdatePayload, + UserProfileVo, +} from '@/types/business/user' export async function getUserProfile(): Promise { const data = await request<{ user: UserProfileVo }>({ @@ -8,3 +12,23 @@ export async function getUserProfile(): Promise { }) return data.user } + +/** 账号安全信息:密码修改时间等(WEB 端复用 APP 接口)。 */ +export async function getAccountSecurity(): Promise { + const data = await request({ + url: '/app/account/security', + method: 'get', + silent: true, + }) + // 兼容后端可能包一层 accountSecurity 的返回结构 + return data?.accountSecurity ?? data +} + +/** 更新个人资料,只提交传入的字段。 */ +export function updateUserProfile(payload: UserProfileUpdatePayload): Promise { + return request({ + url: '/web/system/user/profile', + method: 'put', + data: payload, + }) +} diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue index 3807597..3652e53 100644 --- a/src/components/AppHeader.vue +++ b/src/components/AppHeader.vue @@ -1,8 +1,9 @@