刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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 };
}