/** * @file Task * @author svon.me@gmail.copm */ import { API, get, post, required, tryError, validate } from '@js-lion/api'; import { $error, $success } from '@ue/message'; import { $debounce, trim } from '@ue/utils'; import { request } from '@eciol/request'; import * as _ from 'lodash-es'; import i18n from '@/utils/i18n'; import { JasList, TaskDetail, TaskType, Type } from '#/jas'; export default class User { /** * 对 task type 类型进行归类 * @param list * @returns */ private typeTransform(list: TaskDetail[]): TaskDetail[] { return _.map(list, function (data: TaskDetail) { let type: Type; switch (_.toUpper(data.taskType)) { case _.toUpper(TaskType.TEP): type = Type.TEP; break; case _.toUpper(TaskType.T): case _.toUpper(TaskType.E): case _.toUpper(TaskType.QA): case _.toUpper(TaskType.P): type = Type.T; break; default: type = Type.DTP; break; } return { ...new TaskDetail(), ...data, type }; }); } /** * 获取 jas 列表 * @param query * @returns */ @tryError(new JasList()) @post('/:task/partner/jas/getTaskInfo') @validate list(@required query: object = {}): Promise> { const callback = async (value: JasList) => { const results = _.get(value, 'results'); const _results = [...(results ?? [])]; return { ..._.pick(value, ['newCount', 'total']), results: this.typeTransform(_results) }; }; return { callback, data: trim(query) } as any; } /** * 任务详情接口 * @param id 任务ID * @param type 任务类型 * @returns */ @tryError(new TaskDetail()) @validate detail(@required id: string, @required type: Type): Promise { const api = new API(); if (type === Type.TEP) { return api.post('/:task/partner/outerTaskDetailTep', { taskId: id }); } if (type === Type.T) { return api.post('/:task/partner/outerTaskDetailT', { taskId: id }); } return api.get(`/:task/partner/task/detail/dtp/${id}`); } /** * 确认任务 * @param id 单个或者多个任务ID */ @$debounce() @tryError(false) @$error() @post('/:task/partner/confirm') @validate confirm(@required id: string | number | Array): Promise { const data = Array.isArray(id) ? id : [id]; return { data } as any; } /** * 提交任务 * @param id 单个或者多个任务ID */ // @$debounce() // @tryError(false) // @$success(i18n.message.SUBMIT_SUCCESSFULLY) // @post('/:task/partner/submit') // @validate // submit(@required id: string | number | Array): Promise { // const taskIds = Array.isArray(id) ? id : [id]; // const data = { taskIds }; // return { data } as any; // } submit(id: string | number | Array) { const taskIds = Array.isArray(id) ? id : [id]; const data = { taskIds }; return request.post( { url: '/tbms-task/partner/submit', data, }, { showLoading: true, errorMessageMode: 'none', successMessageMode: 'message', successMessage: i18n.message.SUBMIT_SUCCESSFULLY, }, ); } /** * 拒绝任务 * @param id 单个或者多个任务ID * @param reason 拒绝原因 */ @$debounce() @tryError(false) @$error() @post('/:task/partner/reject') @validate reject( @required id: string | number | Array, reason?: string, ): Promise { const data = { taskIds: Array.isArray(id) ? id : [id], reason: reason || '' }; return { data } as any; } /** * 重置memoQ密码 * @param password 密码 */ @$debounce() @tryError(false) @$error() @$success(i18n.message.CONFIRM_SUCCESSFULLY) @get('/:task/partner/memoq/resetPassword/:password') @validate resetPassword(@required password: string | number): Promise { const params = { password }; return { params } as any; } }