wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
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
<script lang="ts" setup>
import { ref, reactive, inject, type Ref } from 'vue'
import UnionFieldList from './UnionFieldList.vue'
import UnionItemEdit from './UnionItemEdit.vue'
import type { Field, NodeType, UnionType, Node } from './util'
import { getTableField } from '@/api/dataset'
import { cloneDeep } from 'lodash-es'
 
const isCross = inject<Ref>('isCross')
 
const changeParentFields = val => {
  parent.currentDsFields = val
}
const changeNodeFields = val => {
  node.currentDsFields = val
}
 
const changeUnionFields = (index?: number) => {
  if (index !== undefined) {
    node.unionFields.splice(index, 1)
  } else {
    node.unionFields.push({
      parentField: null,
      currentField: null
    })
  }
}
const defaultNode = {
  info: '',
  tableName: '',
  type: 'db' as NodeType,
  datasourceId: '',
  id: '',
  unionType: 'left' as UnionType,
  unionFields: [],
  currentDsFields: [],
  sqlVariableDetails: null,
  confirm: false,
  isShadow: false,
  flag: ''
}
const parentField = ref<Field[]>([])
const nodeField = ref<Field[]>([])
const node = reactive<Node>(cloneDeep(defaultNode))
const parent = reactive<Node>(cloneDeep(defaultNode))
const loading = ref(false)
const props = defineProps({
  editArr: {
    type: Array,
    default: () => []
  }
})
 
const clearState = () => {
  Object.assign(node, cloneDeep(defaultNode))
  Object.assign(parent, cloneDeep(defaultNode))
  parentField.value = []
  nodeField.value = []
}
 
const initState = () => {
  node.confirm = false
  node.isShadow = false
  node.flag = ''
  parent.confirm = false
  parent.isShadow = false
  parent.flag = ''
  Object.assign(node, cloneDeep(props.editArr[0]))
  Object.assign(parent, cloneDeep(props.editArr[1]))
  getFields()
}
 
const getParams = (obj: Node) => {
  return ['datasourceId', 'id', 'info', 'tableName', 'type'].reduce(
    (pre, next) => {
      pre[next] = obj[next]
      return pre
    },
    {
      isCross: isCross.value
    }
  )
}
const getFields = async () => {
  try {
    loading.value = true
    const [n, p] = props.editArr as Node[]
    const [nr, pr] = await Promise.all([getTableField(getParams(n)), getTableField(getParams(p))])
    loading.value = false
    parentField.value = pr as unknown as Field[]
    parentField.value.forEach(ele => {
      ele.checked = p.currentDsFields.map(ele => ele.originName).includes(ele.originName)
    })
    nodeField.value = nr as unknown as Field[]
    nodeField.value.forEach(ele => {
      ele.checked = n.currentDsFields.map(ele => ele.originName).includes(ele.originName)
    })
  } catch (error) {
    loading.value = false
    console.error(error)
  }
}
 
defineExpose({
  node,
  parent,
  clearState,
  initState
})
</script>
 
<template>
  <div style="height: 100%; overflow-y: auto">
    <div class="field-style">
      <div class="fields" v-loading="loading">
        <p :title="parent.tableName">
          {{ parent.tableName }}
        </p>
        <union-field-list
          :field-list="parentField"
          v-if="parentField.length"
          :node="parent"
          @checkedFields="changeParentFields"
        />
      </div>
      <div class="fields" v-loading="loading">
        <p :title="node.tableName">
          {{ node.tableName }}
        </p>
        <union-field-list
          :field-list="nodeField"
          :node="node"
          v-if="nodeField.length"
          @checkedFields="changeNodeFields"
        />
      </div>
    </div>
    <union-item-edit
      :parent-field-list="parentField"
      :node-field-list="nodeField"
      :node="node"
      @change-union-type="val => (node.unionType = val)"
      v-if="node.tableName"
      @change-union-fields="changeUnionFields"
      :table-name="parent.tableName"
    />
  </div>
</template>
 
<style lang="less" scoped>
.field-style {
  height: 430px;
  border: 1px solid var(--deCardStrokeColor, #dee0e3);
  border-radius: 4px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  margin-bottom: 36px;
}
.fields {
  box-sizing: border-box;
  padding: 16px;
  width: 50%;
 
  & > p {
    font-family: var(--de-custom_font, 'PingFang');
    font-size: 14px;
    font-weight: 500;
    margin: 0;
    margin-bottom: 16px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
    color: var(--deTextPrimary, #1f2329);
  }
  &:nth-child(1) {
    border-right: 1px solid var(--deCardStrokeColor, #dee0e3);
  }
}
</style>