vars-select.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="vars-select">
  3. <el-popover
  4. placement="bottom"
  5. trigger="click"
  6. :width="400"
  7. :popper-style="{
  8. padding: 0
  9. }"
  10. >
  11. <template #reference>
  12. <div class="vars-display __hover">
  13. <varsValue :vars="state.vars"/>
  14. </div>
  15. </template>
  16. <div class="vars-select-block">
  17. <div class="filter">
  18. <el-input v-model="state.text" :prefix-icon="Search" placeholder="搜索变量" clearable/>
  19. </div>
  20. <div class="list">
  21. <template v-for="item in optionsCpt">
  22. <div class="list-group">
  23. <div class="px-2 text-sm mb-1 text-gray-400">{{item.label}}</div>
  24. <template v-for="son in item.options">
  25. <div class="__hover-bg px-2 py-1" @click="state.vars = son">
  26. <varsItem :item="son"/>
  27. </div>
  28. </template>
  29. </div>
  30. </template>
  31. </div>
  32. </div>
  33. </el-popover>
  34. </div>
  35. </template>
  36. <script setup lang="ts">
  37. import {computed, getCurrentInstance, reactive, ref, watch} from "vue";
  38. import {useWorkflowStore} from "@/stores";
  39. import { Search } from '@element-plus/icons-vue'
  40. import varsItem from './vars-item.vue'
  41. import varsValue from './vars-value.vue'
  42. const WorkflowStore = useWorkflowStore()
  43. const emits = defineEmits([])
  44. const props = defineProps({
  45. node: {}
  46. })
  47. const {proxy}: any = getCurrentInstance()
  48. const state: any = reactive({
  49. vars: null,
  50. options: [],
  51. text: ''
  52. })
  53. watch(() => props.node, (n) => {
  54. if (n) {
  55. state.options = WorkflowStore.getInVars(n)
  56. }
  57. }, {immediate: true})
  58. const optionsCpt = computed(() => {
  59. if (!state.text) {
  60. return state.options
  61. }
  62. return state.options.map(v => {
  63. const obj = {...v}
  64. obj.options = obj.options.filter(s => s.label.includes(state.text) || s.key.includes(state.text))
  65. return obj
  66. }).filter(v => v.options.length > 0)
  67. })
  68. </script>
  69. <style lang="scss" scoped>
  70. @import "@/views/workflow/instance/component/style";
  71. .vars-display {
  72. border: $borderStyle;
  73. width: 100%;
  74. padding: 0 10px;
  75. border-radius: 4px;
  76. font-size: 12px;
  77. height: 32px;
  78. display: flex;
  79. align-items: center;
  80. }
  81. .vars-select-block {
  82. .filter {
  83. padding: 10px;
  84. border-bottom: $borderStyle;
  85. }
  86. .list {
  87. padding: 4px;
  88. display: flex;
  89. flex-direction: column;
  90. gap: 6px;
  91. .list-group {
  92. display: flex;
  93. flex-direction: column;
  94. }
  95. }
  96. }
  97. </style>