ExtraSettings.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <el-form ref="formRef" :model="modelData" label-width="120px" class="mt-20px">
  3. <el-form-item class="mb-20px">
  4. <template #label>
  5. <el-text size="large" tag="b">提交人权限</el-text>
  6. </template>
  7. <div class="flex flex-col">
  8. <el-checkbox v-model="modelData.allowCancelRunningProcess" label="允许撤销审批中的申请" />
  9. <div class="ml-22px">
  10. <el-text type="info"> 第一个审批节点通过后,提交人仍可撤销申请 </el-text>
  11. </div>
  12. </div>
  13. </el-form-item>
  14. <el-form-item v-if="modelData.processIdRule" class="mb-20px">
  15. <template #label>
  16. <el-text size="large" tag="b">流程编码</el-text>
  17. </template>
  18. <div class="flex flex-col">
  19. <div>
  20. <el-input
  21. v-model="modelData.processIdRule.prefix"
  22. class="w-130px!"
  23. placeholder="前缀"
  24. :disabled="!modelData.processIdRule.enable"
  25. >
  26. <template #prepend>
  27. <el-checkbox v-model="modelData.processIdRule.enable" />
  28. </template>
  29. </el-input>
  30. <el-select
  31. v-model="modelData.processIdRule.infix"
  32. class="w-130px! ml-5px"
  33. placeholder="中缀"
  34. :disabled="!modelData.processIdRule.enable"
  35. >
  36. <el-option
  37. v-for="item in timeOptions"
  38. :key="item.value"
  39. :label="item.label"
  40. :value="item.value"
  41. />
  42. </el-select>
  43. <el-input
  44. v-model="modelData.processIdRule.postfix"
  45. class="w-80px! ml-5px"
  46. placeholder="后缀"
  47. :disabled="!modelData.processIdRule.enable"
  48. />
  49. <el-input-number
  50. v-model="modelData.processIdRule.length"
  51. class="w-120px! ml-5px"
  52. :min="5"
  53. :disabled="!modelData.processIdRule.enable"
  54. />
  55. </div>
  56. <div class="ml-22px" v-if="modelData.processIdRule.enable">
  57. <el-text type="info"> 编码示例:{{ numberExample }} </el-text>
  58. </div>
  59. </div>
  60. </el-form-item>
  61. <el-form-item class="mb-20px">
  62. <template #label>
  63. <el-text size="large" tag="b">自动去重</el-text>
  64. </template>
  65. <div class="flex flex-col">
  66. <div>
  67. <el-text> 同一审批人在流程中重复出现时: </el-text>
  68. </div>
  69. <el-radio-group v-model="modelData.autoApprovalType">
  70. <div class="flex flex-col">
  71. <el-radio :value="0">不自动通过</el-radio>
  72. <el-radio :value="1">仅审批一次,后续重复的审批节点均自动通过</el-radio>
  73. <el-radio :value="2">仅针对连续审批的节点自动通过</el-radio>
  74. </div>
  75. </el-radio-group>
  76. </div>
  77. </el-form-item>
  78. <el-form-item v-if="modelData.titleSetting" class="mb-20px">
  79. <template #label>
  80. <el-text size="large" tag="b">标题设置</el-text>
  81. </template>
  82. <div class="flex flex-col">
  83. <el-radio-group v-model="modelData.titleSetting.enable">
  84. <div class="flex flex-col">
  85. <el-radio :value="false"
  86. >系统默认 <el-text type="info"> 展示流程名称 </el-text></el-radio
  87. >
  88. <el-radio :value="true">
  89. 自定义标题
  90. <el-text>
  91. <el-tooltip content="输入字符 '{' 即可插入表单字段" effect="light" placement="top">
  92. <Icon icon="ep:question-filled" class="ml-5px" />
  93. </el-tooltip>
  94. </el-text>
  95. </el-radio>
  96. </div>
  97. </el-radio-group>
  98. <el-mention
  99. v-if="modelData.titleSetting.enable"
  100. v-model="modelData.titleSetting.title"
  101. type="textarea"
  102. prefix="{"
  103. split="}"
  104. whole
  105. :options="formFieldOptions4Title"
  106. placeholder="请插入表单字段(输入 '{' 可以选择表单字段)或输入文本"
  107. class="w-600px!"
  108. />
  109. </div>
  110. </el-form-item>
  111. <el-form-item
  112. v-if="modelData.summarySetting && modelData.formType === BpmModelFormType.NORMAL"
  113. class="mb-20px"
  114. >
  115. <template #label>
  116. <el-text size="large" tag="b">摘要设置</el-text>
  117. </template>
  118. <div class="flex flex-col">
  119. <el-radio-group v-model="modelData.summarySetting.enable">
  120. <div class="flex flex-col">
  121. <el-radio :value="false">
  122. 系统默认 <el-text type="info"> 展示表单前 3 个字段 </el-text>
  123. </el-radio>
  124. <el-radio :value="true"> 自定义摘要 </el-radio>
  125. </div>
  126. </el-radio-group>
  127. <el-select
  128. class="w-500px!"
  129. v-if="modelData.summarySetting.enable"
  130. v-model="modelData.summarySetting.summary"
  131. multiple
  132. placeholder="请选择要展示的表单字段"
  133. >
  134. <el-option
  135. v-for="item in formFieldOptions4Summary"
  136. :key="item.value"
  137. :label="item.label"
  138. :value="item.value"
  139. />
  140. </el-select>
  141. </div>
  142. </el-form-item>
  143. <el-form-item class="mb-20px">
  144. <template #label>
  145. <el-text size="large" tag="b">流程前置通知</el-text>
  146. </template>
  147. <div class="flex flex-col w-100%">
  148. <div class="flex">
  149. <el-switch
  150. v-model="preProcessNotifyEnable"
  151. @change="handlePreProcessNotifyEnableChange"
  152. />
  153. <div class="ml-80px">流程启动后通知</div>
  154. </div>
  155. <HttpRequestSetting
  156. v-if="preProcessNotifyEnable"
  157. v-model:setting="modelData.preProcessNotifySetting"
  158. :responseEnable="true"
  159. :formItemPrefix="'preProcessNotifySetting'"
  160. />
  161. </div>
  162. </el-form-item>
  163. <el-form-item class="mb-20px">
  164. <template #label>
  165. <el-text size="large" tag="b">流程后置通知</el-text>
  166. </template>
  167. <div class="flex flex-col w-100%">
  168. <div class="flex">
  169. <el-switch
  170. v-model="postProcessNotifyEnable"
  171. @change="handlePostProcessNotifyEnableChange"
  172. />
  173. <div class="ml-80px">流程启动后通知</div>
  174. </div>
  175. <HttpRequestSetting
  176. v-if="postProcessNotifyEnable"
  177. v-model:setting="modelData.postProcessNotifySetting"
  178. :responseEnable="true"
  179. :formItemPrefix="'postProcessNotifySetting'"
  180. />
  181. </div>
  182. </el-form-item>
  183. </el-form>
  184. </template>
  185. <script setup lang="ts">
  186. import dayjs from 'dayjs'
  187. import { BpmAutoApproveType, BpmModelFormType } from '@/utils/constants'
  188. import * as FormApi from '@/api/bpm/form'
  189. import { parseFormFields } from '@/components/FormCreate/src/utils'
  190. import { ProcessVariableEnum } from '@/components/SimpleProcessDesignerV2/src/consts'
  191. import HttpRequestSetting from '@/components/SimpleProcessDesignerV2/src/nodes-config/components/HttpRequestSetting.vue'
  192. const modelData = defineModel<any>()
  193. /** 自定义 ID 流程编码 */
  194. const timeOptions = ref([
  195. {
  196. value: '',
  197. label: '无'
  198. },
  199. {
  200. value: 'DAY',
  201. label: '精确到日'
  202. },
  203. {
  204. value: 'HOUR',
  205. label: '精确到时'
  206. },
  207. {
  208. value: 'MINUTE',
  209. label: '精确到分'
  210. },
  211. {
  212. value: 'SECOND',
  213. label: '精确到秒'
  214. }
  215. ])
  216. const numberExample = computed(() => {
  217. if (modelData.value.processIdRule.enable) {
  218. let infix = ''
  219. switch (modelData.value.processIdRule.infix) {
  220. case 'DAY':
  221. infix = dayjs().format('YYYYMMDD')
  222. break
  223. case 'HOUR':
  224. infix = dayjs().format('YYYYMMDDHH')
  225. break
  226. case 'MINUTE':
  227. infix = dayjs().format('YYYYMMDDHHmm')
  228. break
  229. case 'SECOND':
  230. infix = dayjs().format('YYYYMMDDHHmmss')
  231. break
  232. default:
  233. break
  234. }
  235. return (
  236. modelData.value.processIdRule.prefix +
  237. infix +
  238. modelData.value.processIdRule.postfix +
  239. '1'.padStart(modelData.value.processIdRule.length - 1, '0')
  240. )
  241. } else {
  242. return ''
  243. }
  244. })
  245. /** 是否开启流程前置通知 */
  246. const preProcessNotifyEnable = ref(false)
  247. const handlePreProcessNotifyEnableChange = (val: boolean | string | number) => {
  248. if (val) {
  249. modelData.value.preProcessNotifySetting = {
  250. url: '',
  251. header: [],
  252. body: [],
  253. response: []
  254. }
  255. } else {
  256. modelData.value.preProcessNotifySetting = null
  257. }
  258. }
  259. /** 是否开启流程后置通知 */
  260. const postProcessNotifyEnable = ref(false)
  261. const handlePostProcessNotifyEnableChange = (val: boolean | string | number) => {
  262. if (val) {
  263. modelData.value.postProcessNotifySetting = {
  264. url: '',
  265. header: [],
  266. body: [],
  267. response: []
  268. }
  269. } else {
  270. modelData.value.postProcessNotifySetting = null
  271. }
  272. }
  273. /** 表单选项 */
  274. const formField = ref<Array<{ field: string; title: string }>>([])
  275. const formFieldOptions4Title = computed(() => {
  276. let cloneFormField = formField.value.map((item) => {
  277. return {
  278. label: item.title,
  279. value: item.field
  280. }
  281. })
  282. // 固定添加发起人 ID 字段
  283. cloneFormField.unshift({
  284. label: '流程名称',
  285. value: ProcessVariableEnum.PROCESS_DEFINITION_NAME
  286. })
  287. cloneFormField.unshift({
  288. label: '发起时间',
  289. value: ProcessVariableEnum.START_TIME
  290. })
  291. cloneFormField.unshift({
  292. label: '发起人',
  293. value: ProcessVariableEnum.START_USER_ID
  294. })
  295. return cloneFormField
  296. })
  297. const formFieldOptions4Summary = computed(() => {
  298. return formField.value.map((item) => {
  299. return {
  300. label: item.title,
  301. value: item.field
  302. }
  303. })
  304. })
  305. /** 兼容以前未配置更多设置的流程 */
  306. const initData = () => {
  307. if (!modelData.value.processIdRule) {
  308. modelData.value.processIdRule = {
  309. enable: false,
  310. prefix: '',
  311. infix: '',
  312. postfix: '',
  313. length: 5
  314. }
  315. }
  316. if (!modelData.value.autoApprovalType) {
  317. modelData.value.autoApprovalType = BpmAutoApproveType.NONE
  318. }
  319. if (!modelData.value.titleSetting) {
  320. modelData.value.titleSetting = {
  321. enable: false,
  322. title: ''
  323. }
  324. }
  325. if (!modelData.value.summarySetting) {
  326. modelData.value.summarySetting = {
  327. enable: false,
  328. summary: []
  329. }
  330. }
  331. if (modelData.value.preProcessNotifySetting) {
  332. preProcessNotifyEnable.value = true
  333. }
  334. if (modelData.value.postProcessNotifySetting) {
  335. postProcessNotifyEnable.value = true
  336. }
  337. }
  338. defineExpose({ initData })
  339. /** 监听表单 ID 变化,加载表单数据 */
  340. watch(
  341. () => modelData.value.formId,
  342. async (newFormId) => {
  343. if (newFormId && modelData.value.formType === BpmModelFormType.NORMAL) {
  344. const data = await FormApi.getForm(newFormId)
  345. const result: Array<{ field: string; title: string }> = []
  346. if (data.fields) {
  347. data.fields.forEach((fieldStr: string) => {
  348. parseFormFields(JSON.parse(fieldStr), result)
  349. })
  350. }
  351. formField.value = result
  352. } else {
  353. formField.value = []
  354. }
  355. },
  356. { immediate: true }
  357. )
  358. </script>