trigger.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: var(--el-color-warning-light-3)">
  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="500" 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 value="1">立即执行</el-radio>
  44. <el-radio value="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. const mapTip = {
  92. d: '天',
  93. h: '小时',
  94. m: '分钟'
  95. }
  96. export default {
  97. components: {
  98. addNode
  99. },
  100. props: {
  101. modelValue: { type: Object, default: () => {} },
  102. disabled: {
  103. type: Boolean,
  104. default: false
  105. }
  106. },
  107. data() {
  108. return {
  109. nodeConfig: {},
  110. drawer: false,
  111. isEditTitle: false,
  112. form: {},
  113. options: [
  114. { label: '天', value: 'd' },
  115. { label: '小时', value: 'h' },
  116. { label: '分钟', value: 'm' }
  117. ],
  118. // 固定时长 start
  119. fixedDuration: 0,
  120. fixedDurationType: 'm',
  121. selectedLabel: '分钟',
  122. // 固定时长 end
  123. // 自动计算 start
  124. automaticComputed: '',
  125. // 自动计算 end
  126. delayProcessSelfOptions
  127. }
  128. },
  129. watch: {
  130. modelValue() {
  131. this.nodeConfig = this.modelValue
  132. }
  133. },
  134. mounted() {
  135. this.nodeConfig = this.modelValue
  136. const { delayType, triggerType } = this.nodeConfig
  137. if (triggerType === '1') return
  138. const extendConfig = this.nodeConfig?.extendConfig?.time.split(':')
  139. if (delayType === '1') {
  140. this.fixedDuration = extendConfig[0]
  141. this.fixedDurationType = extendConfig[1]
  142. }
  143. if (delayType === '2') {
  144. this.automaticComputed = this.nodeConfig.extendConfig.time
  145. }
  146. },
  147. methods: {
  148. show() {
  149. if (this.disabled) return
  150. this.form = {}
  151. this.form = JSON.parse(JSON.stringify(this.nodeConfig))
  152. this.drawer = true
  153. },
  154. editTitle(refName) {
  155. if (this.disabled) return
  156. this.isEditTitle = true
  157. this.$nextTick(() => {
  158. if (this.$refs[refName]) {
  159. this.$refs[refName].focus()
  160. }
  161. })
  162. },
  163. saveTitle() {
  164. this.isEditTitle = false
  165. },
  166. save() {
  167. this.form.extendConfig.time =
  168. this.form.triggerType === '2'
  169. ? this.form.delayType === '1'
  170. ? `${this.fixedDuration}:${this.fixedDurationType}`
  171. : `${this.automaticComputed}`
  172. : ''
  173. this.$emit('update:modelValue', this.form)
  174. this.drawer = false
  175. },
  176. delNode() {
  177. this.$emit('update:modelValue', this.nodeConfig.childNode)
  178. },
  179. toText(nodeConfig) {
  180. const { triggerType, delayType } = nodeConfig
  181. if (triggerType === '1') {
  182. return `立即执行`
  183. } else if (triggerType === '2') {
  184. if (delayType === '1') {
  185. return `延迟执行,等待${this.fixedDuration}${mapTip[this.fixedDurationType]}`
  186. } else if (delayType === '2') {
  187. const tip = `延迟执行,至当天`
  188. return !this.automaticComputed ? tip : `${tip}${this.automaticComputed}`
  189. }
  190. } else {
  191. return false
  192. }
  193. }
  194. }
  195. }
  196. </script>
  197. <style></style>