ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<script lang="ts" setup>
import { ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { buildUUID } from '@jnpf/utils';
 
import { cloneDeep } from 'lodash-es';
 
const emit = defineEmits(['register', 'confirm']);
const globalParameterList = ref<any[]>([]);
const approvalFieldList = ref<any[]>([]);
const activeKey = ref<number>(0);
const { createMessage } = useMessage();
const [registerModal, { closeModal }] = useModalInner(init);
const globalParameterColumns = [
  { title: '变量类型', dataIndex: 'dataType', key: 'dataType', width: 220 },
  { title: '变量名称', dataIndex: 'fieldName', key: 'fieldName', width: 250 },
  { title: '默认值', dataIndex: 'defaultValue', key: 'defaultValue', width: 280 },
  { title: '操作', dataIndex: 'action', key: 'action', width: 50, align: 'center' },
];
const approvalFieldColumns = [
  { title: '字段名称', dataIndex: 'fieldName', key: 'fieldName', width: 450 },
  { title: '控件类型', dataIndex: 'jnpfKey', key: 'jnpfKey', width: 300 },
  { title: '操作', dataIndex: 'action', key: 'action', width: 50, align: 'center' },
];
const dataTypeOptions = [
  { fullName: '字符串', id: 'varchar' },
  { fullName: '整型', id: 'int' },
  { fullName: '日期时间', id: 'datetime' },
  { fullName: '浮点', id: 'decimal' },
];
const jnpfKeyOptions = [
  { fullName: '单行输入', id: 'input' },
  { fullName: '多行输入', id: 'textarea' },
  { fullName: '数字输入', id: 'inputNumber' },
];
 
function init(data) {
  globalParameterList.value = cloneDeep(data.globalParameterList) || [];
  approvalFieldList.value = cloneDeep(data.approvalFieldList) || [];
}
function handleAdd() {
  if (activeKey.value == 0) {
    globalParameterList.value.push({ dataType: 'varchar', fieldName: getFieldName(), id: buildUUID() });
  } else {
    approvalFieldList.value.push({ jnpfKey: 'input', fieldName: '', id: buildUUID() });
  }
}
function handleDel(index) {
  const list = activeKey.value == 0 ? globalParameterList.value : approvalFieldList.value;
  list.splice(index, 1);
}
// 生成参数名称
function getFieldName() {
  if (!globalParameterList.value.length) return 'flow_var1';
  let maxNumber = 0;
  const regex = /flow_var(\d+)/;
  globalParameterList.value.forEach((o) => {
    const match = o.fieldName.match(regex);
    if (match) {
      const number = Number.parseInt(match[1]);
      if (number > maxNumber) maxNumber = number;
    }
  });
  return `flow_var${++maxNumber}`;
}
async function handleSubmit() {
  for (let i = 0; i < globalParameterList.value.length; i++) {
    if (!globalParameterList.value[i].fieldName) return createMessage.warning('变量名称不能为空');
    if (globalParameterList.value.some((o, index) => o?.fieldName == globalParameterList.value[i]?.fieldName && index != i))
      return createMessage.warning('变量名称不能重复');
  }
  for (let i = 0; i < approvalFieldList.value.length; i++) {
    if (!approvalFieldList.value[i]?.fieldName) return createMessage.warning('字段名称不能为空');
    if (approvalFieldList.value.some((o, index) => o?.fieldName == approvalFieldList.value[i]?.fieldName && index != i))
      return createMessage.warning('字段名称不能重复');
  }
  emit('confirm', { globalParameterList: globalParameterList.value, approvalFieldList: approvalFieldList.value });
  closeModal();
}
</script>
<template>
  <BasicModal v-bind="$attrs" width="1000px" class="jnpf-global-setting-modal" @register="registerModal" title="全局设置" @ok="handleSubmit" destroy-on-close>
    <div class="global-setting">
      <a-tabs v-model:active-key="activeKey" tab-position="left" class="common-left-tabs flow-left-tabs">
        <a-tab-pane :key="0" tab="全局变量" />
        <a-tab-pane :key="1" tab="审批字段" />
      </a-tabs>
      <div class="table-box">
        <template v-if="activeKey == 0">
          <a-alert message="可通过节点属性给全局变量赋值" type="warning" show-icon />
          <a-table :data-source="globalParameterList" :columns="globalParameterColumns" size="small" :pagination="false" class="mt-[10px]">
            <template #bodyCell="{ column, record, index }">
              <template v-if="column.key === 'dataType'">
                <jnpf-select v-model:value="record.dataType" :options="dataTypeOptions" />
              </template>
              <template v-if="column.key === 'fieldName'">
                <a-input v-model:value="record.fieldName" placeholder="请输入" :maxlength="50" />
              </template>
              <template v-if="column.key === 'defaultValue'">
                <jnpf-input-number v-if="['int', 'decimal'].includes(record.dataType)" v-model:value="record.defaultValue" placeholder="请输入" />
                <jnpf-date-picker v-else-if="record.dataType === 'datetime'" v-model:value="record.defaultValue" class="w-full" placeholder="请选择" />
                <jnpf-input v-else v-model:value="record.defaultValue" placeholder="请输入" />
              </template>
              <template v-if="column.key === 'action'">
                <a-button type="link" danger @click="handleDel(index)"><i class="icon-ym icon-ym-app-delete"></i></a-button>
              </template>
            </template>
          </a-table>
          <span class="link-text mt-[10px] inline-block" @click="handleAdd()"><i class="icon-ym icon-ym-btn-add mr-[4px] text-[14px]"></i>新增变量</span>
        </template>
        <template v-else>
          <a-alert message="用于流程审批时自定义审批拓展字段,可在节点属性中启用字段。" type="warning" show-icon />
          <a-table :data-source="approvalFieldList" :columns="approvalFieldColumns" size="small" :pagination="false" class="mt-[10px]">
            <template #bodyCell="{ column, record, index }">
              <template v-if="column.key === 'jnpfKey'">
                <jnpf-select v-model:value="record.jnpfKey" :options="jnpfKeyOptions" />
              </template>
              <template v-if="column.key === 'fieldName'">
                <a-input v-model:value="record.fieldName" placeholder="请输入" :maxlength="50" />
              </template>
              <template v-if="column.key === 'action'">
                <a-button type="link" danger @click="handleDel(index)"><i class="icon-ym icon-ym-app-delete"></i></a-button>
              </template>
            </template>
          </a-table>
          <span class="link-text mt-[10px] inline-block" @click="handleAdd()"><i class="icon-ym icon-ym-btn-add mr-[4px] text-[14px]"></i>新增字段</span>
        </template>
      </div>
    </div>
  </BasicModal>
</template>
<style lang="scss">
.jnpf-global-setting-modal {
  .ant-modal-body > .scrollbar {
    height: 60vh;
    padding: 0;
 
    .ant-tabs.common-left-tabs {
      display: flex;
      height: 60vh;
    }
 
    .global-setting {
      display: flex;
      height: 60vh;
 
      .table-box {
        flex: 1;
        padding: 20px 20px 20px 10px;
        overflow: auto;
      }
    }
  }
}
</style>