schangxiang@126.com
2025-05-21 496f78c085e7f8c5ba261835f9b8bda99c25b4cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import Dialog from '@/components/BaseDialog/index.vue'
const BaseDialog: any = Dialog
import { computed, defineComponent, inject, ref, SetupContext } from 'vue'
import styles from './FlowContextDialog.module.scss'
import { useRelationMaterial } from '@/hooks//Dialog'
import BaseTable from '@/components/Table/Table'
import { columns } from './config'
import Search from '@/components/Search/Search'
import { _t } from '@/libs/Language/Language'
import { ElMessage } from 'element-plus'
import { get } from 'lodash'
 
export default defineComponent({
  name: '流程上下文',
  props: {
    modelValue: {
      type: String,
      default: '',
    },
    title: {
      type: String,
      default: '',
    },
 
    readonly: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: 'input',
    },
    clearable: {
      type: Boolean,
      default: false,
    },
    flowType: {
      type: String,
    },
    // 用来定义数据结构
    dyStruct: {
      type: Boolean,
      default: false,
    },
    radio: {
      type: Boolean,
      default: false,
    },
  },
  emits: ['update:modelValue', 'close', 'confirm'],
  setup(props: any, ctx: SetupContext) {
    const modelValue = computed({
      get() {
        return props.modelValue
      },
      set(v) {
        ctx.emit('update:modelValue', v)
      },
    })
    const flowType = props.flowType || inject('flowType')
    const data = ref([])
    const visible = ref(false)
    const tableRef = ref()
    const search = ref('')
    const selected = ref('')
    const originData = ref([])
    const current = ref()
    const dyModel = computed(() => {
      if (props.dyStruct) {
        return modelValue.value
      }
      return modelValue
    })
    const onSelect = () => {
      visible.value = true
    }
    const onClose = () => {
      visible.value = false
    }
    const onConfirm = () => {
      visible.value = false
      if (props.dyStruct) {
        modelValue.value = {
          name: current.value?.description,
          value: selected.value,
        }
      } else {
        modelValue.value = selected.value
      }
    }
    const onSearch = (val: string) => {
      if (val) {
        data.value = originData.value.filter((item: any) => {
          return (
            item.name.includes(val) ||
            item.value.includes(val) ||
            item.description.includes(val)
          )
        })
      } else {
        data.value = originData.value
      }
    }
    const onCheck = (row: any[]) => {
      if (row.length > 1) {
        return ElMessage.warning('仅支持对一条数据进行操作!')
      }
      if (row[0]) {
        selected.value = row[0].value
        current.value = row[0]
      }
    }
    const onOpen = () => {
      if (dyModel.value) {
        tableRef.value?.setSelectRow([dyModel.value?.value])
      }
    }
 
    const onLoad = () => {
      originData.value = data.value
    }
 
    const Input = () => {
      const readonly =
        typeof props.readonly?.value === 'boolean'
          ? (props.readonly?.value as boolean)
          : (props.readonly as boolean)
      return (
        <el-input
          v-model={dyModel.value.value}
          clearable={props.clearable}
          class={styles.selectVariable}
          placeholder={_t('请选择')}
          readonly={readonly}
          title={props.title}
          suffix-icon={
            <el-button
              link
              type="primary"
              size="small"
              style="margin-right: 10px;"
              onClick={onSelect}
            >
              {_t('选择')}
            </el-button>
          }
        ></el-input>
      )
    }
    return () => {
      return (
        <div class={styles.relationDialog}>
          <Input />
          <BaseDialog
            width="1200px"
            height="536px"
            v-model={visible.value}
            title={_t('流程上下文')}
            onClose={onClose}
            onConfirm={onConfirm}
            onOpen={onOpen}
            destroy-on-close
            append-to-body
          >
            <div class={styles.header}>
              <label class={styles.key}>{_t('关键字')}</label>
              <Search
                v-model={search.value}
                field="filter"
                onConfirm={onSearch}
                placeholder={_t('请输入关键字')}
              />
            </div>
            <div class={styles.table}>
              <BaseTable
                url={`/api/v1/flowmanagement/flowdesign/flowitemkey`}
                ref={tableRef}
                params={{
                  flowType: flowType,
                }}
                columns={columns}
                size="mini"
                v-model:dataSource={data.value}
                isChecked={true}
                isVScroll
                onCheck={onCheck}
                isStop={true}
                id="value"
                isHidePagination={true}
                onLoad={onLoad}
                radio={props.radio}
              />
            </div>
          </BaseDialog>
        </div>
      )
    }
  },
})