| @@ -1,3 +1,9 @@ | |||
| /* | |||
| * @Author: 赵伟 | |||
| * @Date: 2025-03-24 15:41:42 | |||
| * @Description: 版本文件列表 | |||
| */ | |||
| import KFIcon from '@/components/KFIcon'; | |||
| import { | |||
| ResourceData, | |||
| @@ -11,6 +11,7 @@ import { | |||
| removeWorkflow, | |||
| } from '@/services/pipeline/index.js'; | |||
| import themes from '@/styles/theme.less'; | |||
| import { to } from '@/utils/promise'; | |||
| import tableCellRender, { TableCellValueType } from '@/utils/table'; | |||
| import { modalConfirm } from '@/utils/ui'; | |||
| import { App, Button, ConfigProvider, Form, Input, Space, Table } from 'antd'; | |||
| @@ -132,23 +133,38 @@ const Pipeline = () => { | |||
| modalConfirm({ | |||
| title: '删除后,该流水线将不可恢复', | |||
| content: '是否确认删除?', | |||
| onOk: () => { | |||
| removeWorkflow(record.id).then((ret) => { | |||
| if (ret.code === 200) { | |||
| message.success('删除成功'); | |||
| // 如果是一页的唯一数据,删除后,请求第一页的数据 | |||
| // 否则直接刷新这一页的数据 | |||
| setPagination((prev) => { | |||
| return { | |||
| ...prev, | |||
| current: pipeList.length === 1 ? Math.max(1, prev.current - 1) : prev.current, | |||
| }; | |||
| }); | |||
| getList(); | |||
| } else { | |||
| message.error(ret.msg); | |||
| } | |||
| }); | |||
| onOk: async () => { | |||
| const { id } = record; | |||
| const [res] = await to(removeWorkflow(id)); | |||
| if (res) { | |||
| message.success('删除成功'); | |||
| // 如果是一页的唯一数据,删除后,请求第一页的数据 | |||
| // 否则直接刷新这一页的数据 | |||
| setPagination((prev) => { | |||
| return { | |||
| ...prev, | |||
| current: pipeList.length === 1 ? Math.max(1, prev.current - 1) : prev.current, | |||
| }; | |||
| }); | |||
| } | |||
| }, | |||
| }); | |||
| }; | |||
| // 处理复制 | |||
| const handlePipelineCopy = (record) => { | |||
| modalConfirm({ | |||
| title: '确定复制该条流水线吗?', | |||
| okText: '确认', | |||
| cancelText: '取消', | |||
| isDelete: false, | |||
| onOk: async () => { | |||
| const { id } = record; | |||
| const [res] = await to(cloneWorkflow(id)); | |||
| if (res) { | |||
| message.success('复制成功'); | |||
| getList(); | |||
| } | |||
| }, | |||
| }); | |||
| }; | |||
| @@ -225,30 +241,7 @@ const Pipeline = () => { | |||
| size="small" | |||
| key="clone" | |||
| icon={<KFIcon type="icon-fuzhi" />} | |||
| onClick={async () => { | |||
| modalConfirm({ | |||
| title: '确定复制该条流水线吗?', | |||
| okText: '确认', | |||
| cancelText: '取消', | |||
| isDelete: false, | |||
| onOk: () => { | |||
| cloneWorkflow(record.id).then((ret) => { | |||
| if (ret.code === 200) { | |||
| message.success('复制成功'); | |||
| getList(); | |||
| } else { | |||
| message.error('复制失败'); | |||
| } | |||
| }); | |||
| // if (success) { | |||
| // if (actionRef.current) { | |||
| // actionRef.current.reload(); | |||
| // } | |||
| // } | |||
| }, | |||
| }); | |||
| }} | |||
| onClick={() => handlePipelineCopy(record)} | |||
| > | |||
| 复制 | |||
| </Button> | |||
| @@ -53,7 +53,7 @@ export const requestConfig: RequestConfig = { | |||
| ], | |||
| responseInterceptors: [ | |||
| [ | |||
| (response: AxiosResponse) => { | |||
| async (response: AxiosResponse) => { | |||
| const { status, data, config } = response || {}; | |||
| const options = config as RequestOptions; | |||
| const skipErrorHandler = options?.skipErrorHandler; | |||
| @@ -63,20 +63,45 @@ export const requestConfig: RequestConfig = { | |||
| Loading.hide(); | |||
| } | |||
| if (status >= 200 && status < 300) { | |||
| if (status === 204) { | |||
| // 无内容或者无需验证 | |||
| if (status === 204 || skipValidating) { | |||
| return response; | |||
| } else if (data && (skipValidating || data instanceof Blob || data.code === 200)) { | |||
| } | |||
| if (data && data.code === 200) { | |||
| return response; | |||
| } | |||
| // Blob 数据 | |||
| if (data && data instanceof Blob && data.size > 0) { | |||
| // 下载文件失败时,返回的是 JSON 数据,格式为:{code: 500, msg: "xxx"} | |||
| if (data.type === 'application/json') { | |||
| try { | |||
| const text = await data.text(); | |||
| const json = JSON.parse(text); | |||
| if (json.code === 500) { | |||
| popupError(json.msg || '请求失败', skipErrorHandler); | |||
| return Promise.reject(json); | |||
| } | |||
| } catch (error) { | |||
| console.error('JSON 解析失败', error); | |||
| } | |||
| } | |||
| return response; | |||
| } else if (data && data.code === 401) { | |||
| } | |||
| // Token 失效 | |||
| if (data && data.code === 401) { | |||
| clearSessionToken(); | |||
| setRemoteMenu(null); | |||
| gotoLoginPage(false); | |||
| popupError('请重新登录'); | |||
| return Promise.reject(response); | |||
| } else { | |||
| popupError(data?.msg ?? '请求失败', skipErrorHandler); | |||
| return Promise.reject(response); | |||
| } | |||
| popupError(data?.msg ?? '请求失败', skipErrorHandler); | |||
| return Promise.reject(response); | |||
| } else { | |||
| popupError('请求失败', skipErrorHandler); | |||
| return Promise.reject(response); | |||
| @@ -29,22 +29,30 @@ export const elapsedTime = (begin?: string | null, end?: string | null): string | |||
| const hours = duration.hours(); | |||
| const minutes = duration.minutes(); | |||
| const seconds = duration.seconds(); | |||
| const elspsedArray = []; | |||
| if (years !== 0) { | |||
| return `${years}年${months}个月`; | |||
| elspsedArray.push(`${years}年`); | |||
| } | |||
| if (months !== 0) { | |||
| return `${months}个月${days}天`; | |||
| elspsedArray.push(`${months}个月`); | |||
| } | |||
| if (days !== 0) { | |||
| return `${days}天${hours}小时`; | |||
| elspsedArray.push(`${days}天`); | |||
| } | |||
| if (hours !== 0) { | |||
| return `${hours}小时${minutes}分`; | |||
| elspsedArray.push(`${hours}小时`); | |||
| } | |||
| if (minutes !== 0) { | |||
| return `${minutes}分${seconds}秒`; | |||
| elspsedArray.push(`${minutes}分`); | |||
| } | |||
| return `${seconds}秒`; | |||
| if (seconds !== 0) { | |||
| elspsedArray.push(`${seconds}秒`); | |||
| } | |||
| if (elspsedArray.length === 0) { | |||
| return '0秒'; | |||
| } | |||
| return elspsedArray.slice(0, 2).join(''); | |||
| }; | |||
| /** | |||
| @@ -28,7 +28,7 @@ export class Loading { | |||
| } | |||
| const container = document.createElement('div'); | |||
| container.id = 'loading'; | |||
| const rootContainer = document.body; //document.getElementsByTagName('main')[0]; | |||
| const rootContainer = document.body; // document.getElementsByTagName('main')[0]; | |||
| rootContainer?.appendChild(container); | |||
| const root = createRoot(container); | |||
| const global = globalConfig(); | |||
| @@ -69,10 +69,9 @@ export class Loading { | |||
| static removeLoading() { | |||
| this.clearRemoveTimeout(); | |||
| const rootContainer = document.body; //document.getElementsByTagName('main')[0]; | |||
| const container = document.getElementById('loading'); | |||
| if (container) { | |||
| rootContainer?.removeChild(container); | |||
| container.parentNode?.removeChild(container); | |||
| } | |||
| this.isShowing = false; | |||
| } | |||