import { getCurrentScope, onScopeDispose, ref } from 'vue';
|
|
import { useMessage } from '@jnpf/hooks';
|
|
import { cloneDeep } from 'lodash-es';
|
|
import { resolveAuditBizSign } from '#/api/onlineDev/auditHeaders';
|
import { delFlowLaunch, getFlowTaskInfo } from '#/api/workFlow/task';
|
import { $t } from '#/locales';
|
import { onlineUtils } from '#/utils/jnpf';
|
|
/** 我发起的删除沿用已发布起始表单的列表删除按钮签名配置。 */
|
export function useLaunchDelete(reload: () => unknown) {
|
const { createConfirm, createMessage } = useMessage();
|
const deleting = ref(false);
|
let loading = false;
|
function startLoading() {
|
loading = true;
|
onlineUtils.showLoading();
|
}
|
function stopLoading() {
|
if (!loading) return;
|
loading = false;
|
onlineUtils.hideLoading();
|
}
|
function finish() {
|
stopLoading();
|
deleting.value = false;
|
}
|
if (getCurrentScope()) onScopeDispose(stopLoading);
|
|
function remove(id: string, signData?: { biz_sign: string }) {
|
startLoading();
|
return delFlowLaunch(id, signData)
|
.then((res) => {
|
createMessage.success(res.msg);
|
reload();
|
})
|
.finally(finish);
|
}
|
|
async function handleDelete(record: { flowId: string; id: string }) {
|
if (deleting.value) return;
|
deleting.value = true;
|
startLoading();
|
try {
|
// 不传 isFlow,读取配置不计入发起次数;-1 固定读取起始节点表单。
|
const res = await getFlowTaskInfo(record.id, { flowId: record.flowId, opType: '-1' });
|
const { formInfo, formData } = res.data || {};
|
if (!formInfo) throw new Error('流程表单配置不存在');
|
const columnData = formInfo.columnData ? JSON.parse(formInfo.columnData) : {};
|
const button = columnData.columnBtnsList?.find((item) => item.value === 'remove');
|
if (button?.event?.biz_sign_enabled) {
|
onlineUtils.sign({
|
isFaceToFace: false,
|
metaData: {
|
biz_button: button.labelI18nCode ? $t(button.labelI18nCode, button.label) : button.label || $t('common.delText'),
|
biz_data: cloneDeep([formData || {}]),
|
biz_form_id: formInfo.id,
|
biz_module: '',
|
biz_title: '',
|
is_biz_form: false,
|
is_review_button: false,
|
},
|
onCancel: finish,
|
onOpen: stopLoading,
|
onOpenError: finish,
|
onSubmit: (signData) => {
|
const bizSign = resolveAuditBizSign(signData);
|
if (!bizSign) {
|
createMessage.error('未获取到有效的电子签名,请重新签名');
|
return;
|
}
|
return remove(record.id, { biz_sign: bizSign });
|
},
|
});
|
return;
|
}
|
stopLoading();
|
createConfirm({
|
iconType: 'warning',
|
title: $t('common.tipTitle'),
|
content: $t('common.delTip'),
|
onCancel: finish,
|
onOk: () => remove(record.id),
|
});
|
} catch {
|
finish();
|
createMessage.error('无法读取流程删除配置,请重试');
|
}
|
}
|
|
return { deleting, handleDelete };
|
}
|