trigger.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div class="node-wrap">
  3. <!-- 节点显示 start -->
  4. <div class="node-wrap-box" :class="[disabled ? 'node-wrap-box--disabled' : '', `node-wrap-box--${nodeConfig.local_status}`]">
  5. <div class="title" style="background: #2bb58b">
  6. <el-icon class="icon"><Clock /></el-icon>
  7. <span v-show="!isEditTitle" class="title_label" @click="editTitle('box_nodeTitle')"
  8. >{{ nodeConfig.nodeName }}<el-icon v-if="!disabled" class="edit-icon"><edit /></el-icon
  9. ></span>
  10. <el-input
  11. v-show="isEditTitle"
  12. ref="box_nodeTitle"
  13. v-model="nodeConfig.nodeName"
  14. clearable
  15. size="small"
  16. @blur="saveTitle"
  17. @keyup.enter="saveTitle"
  18. ></el-input>
  19. <el-icon v-if="!disabled" class="close" @click.stop="delNode()"><close /></el-icon>
  20. </div>
  21. <div class="content" @click="show">
  22. <span v-if="toText(nodeConfig)">{{ toText(nodeConfig) }}</span>
  23. <span v-else class="placeholder">请选择触发器规则</span>
  24. </div>
  25. </div>
  26. <!-- 节点显示 end -->
  27. <!-- 添加节点 start -->
  28. <add-node v-model="nodeConfig.childNode" :disabled="disabled"></add-node>
  29. <!-- 添加节点 end -->
  30. <!-- 打开侧边弹窗 start -->
  31. <el-drawer v-model="drawer" title="触发器设置" destroy-on-close append-to-body :size="600" class="aDrawer">
  32. <template #header>
  33. <div class="node-wrap-drawer__title">
  34. <label v-show="!isEditTitle" @click="editTitle('nodeTitle')"
  35. >{{ form.nodeName }}<el-icon class="node-wrap-drawer__title-edit"><edit /></el-icon
  36. ></label>
  37. <el-input v-show="isEditTitle" ref="nodeTitle" v-model="form.nodeName" clearable @blur="saveTitle" @keyup.enter="saveTitle"></el-input>
  38. </div>
  39. </template>
  40. <el-container>
  41. <el-main>
  42. <el-radio-group v-model="form.triggerType" style="margin-bottom: 15px">
  43. <el-radio label="1">立即执行</el-radio>
  44. <el-radio label="2">延迟执行</el-radio>
  45. </el-radio-group>
  46. <el-form label-position="top">
  47. <template v-if="form.triggerType === '2'">
  48. <el-form-item label="">
  49. <el-radio-group v-model="form.delayType">
  50. <el-radio-button v-for="v of delayProcessSelfOptions" :key="v.value" :label="v.value">{{ v.label }}</el-radio-button>
  51. </el-radio-group>
  52. </el-form-item>
  53. <el-form-item v-if="form.delayType === '1'">
  54. <el-input v-model="fixedDuration" style="max-width: 300px" type="number" min="0" class="input-with-select">
  55. <template #append>
  56. <el-select v-model="fixedDurationType" style="width: 115px">
  57. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  58. </el-select>
  59. </template> </el-input
  60. ><span>后进入下一步</span>
  61. </el-form-item>
  62. <el-form-item v-if="form.delayType === '2'">
  63. <el-time-picker v-model="automaticComputed" placeholder="时间点" value-format="HH:mm:ss" />
  64. <span>后进入下一步</span>
  65. </el-form-item>
  66. </template>
  67. <el-form-item label="">
  68. <el-input v-model="form.extendConfig.args" :rows="5" type="textarea" placeholder="请输入执行参数(json格式)" />
  69. </el-form-item>
  70. <el-form-item label="">
  71. <el-input
  72. v-model="form.extendConfig.trigger"
  73. placeholder="必填项,接口 TaskTrigger 实现
  74. class 如果不配置,调用全局实现子类"
  75. />
  76. </el-form-item>
  77. </el-form>
  78. </el-main>
  79. <el-footer>
  80. <el-button type="primary" @click="save">保存</el-button>
  81. <el-button @click="drawer = false">取消</el-button>
  82. </el-footer>
  83. </el-container>
  84. </el-drawer>
  85. <!-- 打开侧边弹窗 end -->
  86. </div>
  87. </template>
  88. <script>
  89. import addNode from './addNode'
  90. import { delayProcessSelfOptions } from './config'
  91. import { ElMessage } from 'element-plus'
  92. const mapTip = {
  93. d: '天',
  94. h: '小时',
  95. m: '分钟'
  96. }
  97. export default {
  98. components: {
  99. addNode
  100. },
  101. props: {
  102. modelValue: { type: Object, default: () => {} },
  103. disabled: {
  104. type: Boolean,
  105. default: false
  106. }
  107. },
  108. data() {
  109. return {
  110. nodeConfig: {},
  111. drawer: false,
  112. isEditTitle: false,
  113. form: {},
  114. options: [
  115. { label: '天', value: 'd' },
  116. { label: '小时', value: 'h' },
  117. { label: '分钟', value: 'm' }
  118. ],
  119. // 固定时长 start
  120. fixedDuration: 1,
  121. fixedDurationType: 'm',
  122. selectedLabel: '分钟',
  123. // 固定时长 end
  124. // 自动计算 start
  125. automaticComputed: '',
  126. // 自动计算 end
  127. delayProcessSelfOptions
  128. }
  129. },
  130. watch: {
  131. modelValue() {
  132. this.nodeConfig = this.modelValue
  133. }
  134. },
  135. mounted() {
  136. this.nodeConfig = this.modelValue
  137. const { delayType, triggerType } = this.nodeConfig
  138. if (triggerType === '1') return
  139. const extendConfig = this.nodeConfig?.extendConfig?.time.split(':')
  140. if (delayType === '1') {
  141. this.fixedDuration = extendConfig[0]
  142. this.fixedDurationType = extendConfig[1]
  143. }
  144. if (delayType === '2') {
  145. this.automaticComputed = this.nodeConfig.extendConfig.time
  146. }
  147. },
  148. methods: {
  149. show() {
  150. if (this.disabled) return
  151. this.form = {}
  152. this.form = JSON.parse(JSON.stringify(this.nodeConfig))
  153. this.drawer = true
  154. },
  155. editTitle(refName) {
  156. if (this.disabled) return
  157. this.isEditTitle = true
  158. this.$nextTick(() => {
  159. if (this.$refs[refName]) {
  160. this.$refs[refName].focus()
  161. }
  162. })
  163. },
  164. saveTitle() {
  165. this.isEditTitle = false
  166. },
  167. save() {
  168. if (this.form.triggerType === '2' && this.form.delayType === '1' && !Number(this.fixedDuration)) {
  169. return ElMessage.warning('等待时间数值最小为1')
  170. }
  171. this.form.extendConfig.time =
  172. this.form.triggerType === '2'
  173. ? this.form.delayType === '1'
  174. ? `${this.fixedDuration}:${this.fixedDurationType}`
  175. : `${this.automaticComputed}`
  176. : ''
  177. this.$emit('update:modelValue', this.form)
  178. this.drawer = false
  179. },
  180. delNode() {
  181. this.$emit('update:modelValue', this.nodeConfig.childNode)
  182. },
  183. toText(nodeConfig) {
  184. const { triggerType, delayType } = nodeConfig
  185. if (triggerType === '1') {
  186. return `立即执行`
  187. } else if (triggerType === '2') {
  188. if (delayType === '1') {
  189. return `延迟执行,等待${this.fixedDuration}${mapTip[this.fixedDurationType]}`
  190. } else if (delayType === '2') {
  191. const tip = `延迟执行,至当天`
  192. return !this.automaticComputed ? tip : `${tip}${this.automaticComputed}`
  193. }
  194. } else {
  195. return false
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style></style>