vars-detail.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <CzrDialog
  3. :show="show"
  4. :title="titleCpt"
  5. @onClose="$emit('update:show', false)"
  6. width="500px"
  7. height="auto"
  8. maxHeight="80%"
  9. :loading="state.loading"
  10. @onSubmit="onSubmit"
  11. >
  12. <div class="vars-detail">
  13. <div class="vars-detail-types">
  14. <template v-for="item in optionsType">
  15. <div
  16. class="__hover"
  17. :class="{ active: state.form.type === item.type }"
  18. @click="() => (state.form.type = item.type)"
  19. >
  20. {{ item.label }}
  21. </div>
  22. </template>
  23. </div>
  24. <CzrForm ref="ref_form" class="vars-detail-form" layout="y">
  25. <CzrFormColumn
  26. :span="24"
  27. required
  28. label="显示名称"
  29. v-model:param="state.form.label"
  30. />
  31. <CzrFormColumn
  32. :span="24"
  33. required
  34. label="变量名称"
  35. v-model:param="state.form.key"
  36. />
  37. <template
  38. v-if="state.form.type === 'String' || state.form.type === 'Textarea'"
  39. >
  40. <CzrFormColumn
  41. :span="24"
  42. required
  43. label="最大长度"
  44. v-model:param="state.form.length"
  45. />
  46. </template>
  47. </CzrForm>
  48. </div>
  49. </CzrDialog>
  50. </template>
  51. <script setup lang="ts">
  52. import {
  53. computed,
  54. getCurrentInstance,
  55. nextTick,
  56. reactive,
  57. ref,
  58. watch,
  59. } from 'vue'
  60. import { ElMessage, ElMessageBox } from 'element-plus'
  61. import { VarsSource } from '@/views/workflow/types'
  62. const emit = defineEmits(['update:show', 'refresh'])
  63. const { proxy } = getCurrentInstance()
  64. const props = defineProps({
  65. show: { default: false },
  66. transfer: <any>{},
  67. })
  68. const state: any = reactive({
  69. loading: false,
  70. form: {
  71. type: 'String',
  72. },
  73. })
  74. const optionsType = [
  75. { type: 'String', label: '文本' },
  76. // {type: 'Textarea', label: '段落'},
  77. { type: 'Number', label: '数字' },
  78. // {type: 'Select', label: '下拉选项'},
  79. ]
  80. const titleCpt = computed(() => {
  81. let t = '变量'
  82. switch (props.transfer.mode) {
  83. case 'add':
  84. t = '新增' + t
  85. break
  86. case 'edit':
  87. t = '编辑' + t
  88. break
  89. }
  90. return t
  91. })
  92. const ref_form = ref()
  93. watch(
  94. () => props.show,
  95. (n) => {
  96. if (n) {
  97. state.form = props.transfer.row || {
  98. type: 'String',
  99. source: VarsSource.Param,
  100. }
  101. nextTick(() => {
  102. ref_form.value.reset()
  103. })
  104. }
  105. },
  106. )
  107. const onSubmit = () => {
  108. ref_form.value
  109. .submit()
  110. .then(() => {
  111. emit('update:show', false)
  112. const res: any = {
  113. label: state.form.label,
  114. key: state.form.key,
  115. type: state.form.type,
  116. }
  117. if (state.form.type === 'String' || state.form.type === 'Textarea') {
  118. res.length = state.form.length
  119. }
  120. emit('refresh', res)
  121. })
  122. .catch((e) => {
  123. ElMessage({
  124. message: e[0].message,
  125. grouping: true,
  126. type: 'warning',
  127. })
  128. })
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. @use '@/views/workflow/instance/component/style';
  133. .vars-detail {
  134. padding: 10px 20px 0;
  135. .vars-detail-types {
  136. display: grid;
  137. grid-template-columns: repeat(3, 1fr);
  138. gap: 10px;
  139. > div {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. border: style.$borderStyle;
  144. border-radius: 8px;
  145. padding: 20px;
  146. &.active,
  147. &:hover {
  148. border-color: var(--czr-main-color);
  149. color: var(--czr-main-color);
  150. }
  151. }
  152. }
  153. .vars-detail-form {
  154. margin-top: 20px;
  155. }
  156. }
  157. </style>