147 lines
3.7 KiB
JavaScript
147 lines
3.7 KiB
JavaScript
import { get, post, request } from './request.js'
|
|
import { getToken } from './auth.js'
|
|
|
|
function authHeader() {
|
|
const token = getToken()
|
|
return token ? { Authorization: 'Bearer ' + token } : {}
|
|
}
|
|
|
|
/** 小程序侧无 URLSearchParams 时用手写 query */
|
|
function buildQuery(params) {
|
|
const parts = []
|
|
Object.keys(params || {}).forEach((k) => {
|
|
const v = params[k]
|
|
if (v == null || v === '') return
|
|
parts.push(encodeURIComponent(k) + '=' + encodeURIComponent(String(v)))
|
|
})
|
|
return parts.join('&')
|
|
}
|
|
|
|
function withQuery(path, params) {
|
|
const qs = buildQuery(params)
|
|
return qs ? path + '?' + qs : path
|
|
}
|
|
|
|
export function fetchOaGroupList() {
|
|
return get('/web/admin/oa-approval/groups', authHeader())
|
|
}
|
|
|
|
export function fetchOaTemplates() {
|
|
return get('/web/admin/oa-approval/templates', authHeader())
|
|
}
|
|
|
|
export function fetchOaTemplateDetail(appId) {
|
|
return get(
|
|
'/web/admin/oa-approval/templates/' + encodeURIComponent(appId),
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
// —— drafts ——
|
|
|
|
export function fetchOaInstanceDraftList(params) {
|
|
const p = params || {}
|
|
return get(
|
|
withQuery('/web/admin/oa-approval/drafts', {
|
|
keyword: p.keyword,
|
|
groupId: p.groupId,
|
|
updateTimeFrom: p.updateTimeFrom,
|
|
updateTimeTo: p.updateTimeTo,
|
|
page: p.page != null ? p.page : 1,
|
|
pageSize: p.pageSize != null ? p.pageSize : 20
|
|
}),
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchOaInstanceDraftCount() {
|
|
return get('/web/admin/oa-approval/drafts/count', authHeader())
|
|
}
|
|
|
|
export function fetchDeleteOaInstanceDraft(id) {
|
|
return request({
|
|
url: '/web/admin/oa-approval/drafts/' + encodeURIComponent(id),
|
|
method: 'DELETE',
|
|
header: authHeader()
|
|
})
|
|
}
|
|
|
|
export function fetchBatchDeleteOaInstanceDrafts(ids) {
|
|
return post(
|
|
'/web/admin/oa-approval/drafts/batch-delete',
|
|
{ ids: ids || [] },
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchSubmitOaInstanceDraft(id, data) {
|
|
return post(
|
|
'/web/admin/oa-approval/drafts/' + encodeURIComponent(id) + '/submit',
|
|
data || {},
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
// —— tasks ——
|
|
|
|
export function fetchOaTasks(kind, params) {
|
|
const p = params || {}
|
|
const keyword = (p.keyword || '').trim()
|
|
const appName = (p.appName || '').trim()
|
|
const initiatorName = (p.initiatorName || '').trim()
|
|
const query = {
|
|
page: p.page != null ? p.page : 1,
|
|
pageSize: p.pageSize != null ? p.pageSize : 20
|
|
}
|
|
if (kind === 'cc') {
|
|
query.readStatus = p.readStatus != null && p.readStatus !== '' ? p.readStatus : 'unread'
|
|
}
|
|
if (keyword) query.keyword = keyword
|
|
if (appName) query.appName = appName
|
|
if (initiatorName) query.initiatorName = initiatorName
|
|
return get(
|
|
withQuery('/web/admin/oa-approval/tasks/' + encodeURIComponent(kind), query),
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchOaPendingTaskCount() {
|
|
return get('/web/admin/oa-approval/tasks/pending/count', authHeader())
|
|
}
|
|
|
|
export function fetchOaCcUnreadCount() {
|
|
return get('/web/admin/oa-approval/tasks/cc/unread-count', authHeader())
|
|
}
|
|
|
|
export function fetchMarkOaCcTaskRead(taskId) {
|
|
return post(
|
|
'/web/admin/oa-approval/tasks/' + encodeURIComponent(taskId) + '/read',
|
|
{},
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchBatchMarkOaCcTasksRead(ids) {
|
|
return post(
|
|
'/web/admin/oa-approval/tasks/cc/read-batch',
|
|
{ ids: ids || [] },
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchApproveOaTask(taskId, comment) {
|
|
return post(
|
|
'/web/admin/oa-approval/tasks/' + encodeURIComponent(taskId) + '/approve',
|
|
{ comment: comment || undefined },
|
|
authHeader()
|
|
)
|
|
}
|
|
|
|
export function fetchReturnOaTask(taskId, comment) {
|
|
return post(
|
|
'/web/admin/oa-approval/tasks/' + encodeURIComponent(taskId) + '/return',
|
|
{ comment: comment || undefined },
|
|
authHeader()
|
|
)
|
|
}
|