Files
guoju0808/ry-vue3/src/api/public.js
T

167 lines
7.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 公开门户 API
import request from '@/utils/request'
// 首页:项目公示 + 公示公告 + 资源
export const getPublicIndex = () => request.get('/business/public/index')
// 项目公示分页
export const listPublicProjects = (params) => request.get('/business/public/announcements', { params })
// 公示详情
export const getPublicAnnouncement = (annId) => request.get(`/business/public/announcement/${annId}`)
// 支持函详情
export const getPublicSupportLetter = (annId) => request.get(`/business/public/supportLetter/${annId}`)
// 邀请函详情(参会邀请)
export const getPublicInvitation = (annId) => request.get(`/business/public/invitation/${annId}`)
// 业务字典
export const getDictTypes = () => request.get('/business/dict/types')
export const getDictData = (dictType) => request.get('/business/dict/data', { params: { dictType } })
// 业务认证
export const bizLogin = (data) => request.post('/business/auth/login', data)
export const registerExpert = (data) => request.post('/business/auth/registerExpert', data)
export const registerExecutor = (data) => request.post('/business/auth/registerExecutor', data)
export const registerSponsor = (data) => request.post('/business/auth/registerSponsor', data)
// 支持方注册选企业下拉 (匿名公开): 返回 [{orgId, orgName, mainUserId}]
export const sponsorOrgOptions = (query) => request.get('/business/auth/sponsorOrgOptions', { params: query })
// 业务 CRUDgeneric
// announcement 后端接口未实现, 已改为调 RuoYi 系统通知接口 /system/notice/list
const STUB_ENTITIES = new Set(['announcement'])
export const bizList = (entity, params) => {
if (STUB_ENTITIES.has(entity)) {
return Promise.resolve({ code: 200, msg: 'ok', data: { rows: [], total: 0 } })
}
return request.get(`/business/${entity}/list`, { params })
}
// 系统通知(RuoYi sys_notice 表)
// 返回 {id, title, category, text, time, read, type, content}
export const listNotices = async (params = { pageNum: 1, pageSize: 5 }) => {
const { data } = await request.get('/system/notice/list', { params })
const rows = data?.rows || []
return rows.map(n => {
// notice_content 是 longblob HTML, 提取纯文本
const html = String(n.noticeContent || '')
const text = html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 200)
return {
id: n.noticeId,
title: n.noticeTitle,
category: n.noticeType === '2' ? '公告' : '通知',
text: text || (n.remark || '请查看通知内容'),
time: n.createTime ? new Date(n.createTime.replace(/-/g, '/')).toLocaleString('zh-CN') : '',
read: !!n.isRead,
type: n.noticeType,
content: html,
}
})
}
// 个人通知 (biz_message 表) — 给当前用户发
// 返回 {rows: [{id, title, text, time, read, type, content, bizType, bizId}], unread, total}
const MSG_TYPE_LABEL = { '1': '通知', '2': '待办', '3': '系统' }
export const listMyMessages = async (params = { limit: 5 }) => {
const { data } = await request.get('/business/message/my', { params })
const rows = data?.rows || []
return {
rows: rows.map(m => ({
id: m.msgId,
title: m.title,
category: MSG_TYPE_LABEL[m.msgType] || '通知',
text: String(m.content || '').replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 200),
time: m.createTime ? new Date(m.createTime.replace(/-/g, '/')).toLocaleString('zh-CN') : '',
read: m.isRead === '1',
type: m.msgType,
content: m.content,
bizType: m.bizType,
bizId: m.bizId,
})),
unread: data?.unread || 0,
total: data?.total || 0,
}
}
// 标记单条已读
export const markMessageRead = (msgId) => request.put(`/business/message/read/${msgId}`)
// 全部标记已读
export const markAllMessagesRead = () => request.put('/business/message/readAll')
export const bizGet = (entity, id) => request.get(`/business/${entity}/${id}`)
// opts 透传给 request (例如 { __silentError: true } 让拦截器不自动 toast, 由调用方控制)
export const bizAdd = (entity, data, opts) => request.post(`/business/${entity}`, data, opts)
export const bizUpdate = (entity, data, opts) => request.put(`/business/${entity}`, data, opts)
// org 启用/禁用: PUT /business/org/toggleStatus, 同步主账号 sys_user.status
// (bizUpdate('org', {orgId, status}) 只改 biz_org.status, 不联动主账号, 已被 toggleStatus 替代)
export const toggleOrgStatus = (orgId, status) => request.put('/business/org/toggleStatus', { orgId, status })
export const bizDelete = (entity, ids) => request.delete(`/business/${entity}/${ids}`)
// 更换机构管理员 (admin/sponsor-people 管理员 switch): 目标人员晋升 MAIN, 原管理员降 SUB
export const changePersonAdmin = (personId) => request.put('/business/person/changeAdmin', { personId })
// 人员批量导入 (unitType: 'sponsor' | 'executor')
export const importPerson = (unitType, file, orgId) => {
const form = new FormData()
form.append('file', file)
if (orgId != null) form.append('orgId', orgId)
return request.post(`/business/person/${unitType}Import`, form, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
// 人员导入模板下载
export const downloadImportTemplate = (unitType) =>
request.get(`/business/person/${unitType}ImportTemplate`, { responseType: 'blob' })
// 专家导入模板下载
export const downloadExpertTemplate = () =>
request.get('/business/expert/importTemplate', { responseType: 'blob' })
// ========== 公示页意向 (公开匿名提交, 已在登录或未登录时均可调) ==========
// 提交支持意向: body { projectId, name, phone, workUnit, department?, position? }
export function submitPublicitySupportIntent(data) {
return request.post('/business/publicity/supportIntent', data)
}
// 提交执行意向
export function submitPublicityExecutionIntent(data) {
return request.post('/business/publicity/executionIntent', data)
}
// 持久化查重: GET /business/publicity/hasIntent?projectId=&phone=&type=support|execution
export function hasPublicityIntent(projectId, phone, type) {
return request.get('/business/publicity/hasIntent', { params: { projectId, phone, type } })
}
// ========== 公示页意向 管理端 (manager / admin 后台) ==========
// 列表分页 (后端 startPage 模式)
export function listPublicitySupportIntent(params) {
return request.get('/business/publicitySupportIntent/list', { params })
}
export function listPublicityExecutionIntent(params) {
return request.get('/business/publicityExecutionIntent/list', { params })
}
// 编辑 (改 intentStatus / remark)
export function updatePublicitySupportIntent(data, opts) {
return request.put('/business/publicitySupportIntent', data, opts)
}
export function updatePublicityExecutionIntent(data, opts) {
return request.put('/business/publicityExecutionIntent', data, opts)
}
// 删除 (单/多)
export function deletePublicitySupportIntent(ids) {
return request.delete(`/business/publicitySupportIntent/${Array.isArray(ids) ? ids.join(',') : ids}`)
}
export function deletePublicityExecutionIntent(ids) {
return request.delete(`/business/publicityExecutionIntent/${Array.isArray(ids) ? ids.join(',') : ids}`)
}
// 导出 (后端 ExcelUtil 写 .xlsx, responseType=blob, 由前端触发下载)
// 用法: exportPublicityExecutionIntent(q.value).then(res => { /* res: { data: blob } */ })
export function exportPublicityExecutionIntent(params) {
return request.post('/business/publicityExecutionIntent/export', null, { params, responseType: 'blob' })
}
export function exportPublicitySupportIntent(params) {
return request.post('/business/publicitySupportIntent/export', null, { params, responseType: 'blob' })
}