index.vue
8.85 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<template>
<n-collapse-item title="组件交互" name="1" v-if="interactActions.length">
<template #header-extra>
<n-button type="primary" tertiary size="small" @click.stop="evAddEventsFn">
<template #icon>
<n-icon>
<add-icon />
</n-icon>
</template>
新增
</n-button>
</template>
<!-- 无数据 -->
<div v-if="!targetData.events.interactEvents.length" class="no-data go-flex-center">
<img :src="noData" alt="暂无数据" />
<n-text :depth="3">暂无内容</n-text>
</div>
<n-card
v-for="(item, cardIndex) in targetData.events.interactEvents"
:key="cardIndex"
class="n-card-shallow"
size="small"
>
<n-space justify="space-between">
<n-text>关联组件 - {{ cardIndex + 1 }}</n-text>
<n-button type="error" text size="small" @click="evDeleteEventsFn(cardIndex)">
<template #icon>
<n-icon>
<close-icon />
</n-icon>
</template>
</n-button>
</n-space>
<n-divider style="margin: 10px 0" />
<n-tag :bordered="false" type="primary"> 选择目标组件 </n-tag>
<setting-item-box name="触发事件" :alone="true">
<n-input-group v-if="interactActions">
<n-select
class="select-type-options"
v-model:value="item.interactOn"
size="tiny"
:options="interactActions"
/>
</n-input-group>
</setting-item-box>
<setting-item-box :alone="true">
<template #name>
<n-text>绑定</n-text>
<n-tooltip trigger="hover">
<template #trigger>
<n-icon size="21" :depth="3">
<help-outline-icon></help-outline-icon>
</n-icon>
</template>
<n-text>不支持「静态组件」支持「组件」「公共APi」</n-text>
</n-tooltip>
</template>
<n-select
class="select-type-options"
value-field="id"
label-field="title"
size="tiny"
filterable
placeholder="仅展示符合条件的组件"
v-model:value="item.interactComponentId"
:options="fnEventsOptions()"
/>
</setting-item-box>
<setting-item-box v-if="fnDimensionsAndSource(item.interactOn).length" name="查询结果" :alone="true">
<n-table size="small" striped>
<thead>
<tr>
<th v-for="item in ['参数', '说明']" :key="item">{{ item }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(cItem, index) in fnDimensionsAndSource(item.interactOn)" :key="index">
<td>{{ cItem.value }}</td>
<td>{{ cItem.label }}</td>
</tr>
</tbody>
</n-table>
</setting-item-box>
<n-tag :bordered="false" type="primary"> 关联目标请求参数 </n-tag>
<setting-item-box
:name="requestParamsItem"
v-for="requestParamsItem in requestParamsTypeList"
:key="requestParamsItem"
>
<setting-item
v-for="(ovlValue, ovlKey, index) in fnGetRequest(item.interactComponentId, requestParamsItem)"
:key="index"
:name="`${ovlKey}`"
>
<n-select
size="tiny"
v-model:value="item.interactFn[ovlKey]"
:options="fnDimensionsAndSource(item.interactOn)"
clearable
></n-select>
</setting-item>
<n-text
v-show="JSON.stringify(fnGetRequest(item.interactComponentId, requestParamsItem)) === '{}'"
class="go-pt-1"
depth="3"
>
暂无数据
</n-text>
</setting-item-box>
</n-card>
</n-collapse-item>
</template>
<script lang="ts" setup>
import { VNodeChild, computed } from 'vue'
import { SelectOption, SelectGroupOption } from 'naive-ui'
import { SettingItemBox, SettingItem, CollapseItem } from '@/components/Pages/ChartItemSetting'
import { CreateComponentType, CreateComponentGroupType, ChartFrameEnum } from '@/packages/index.d'
import { RequestParamsTypeEnum, RequestDataTypeEnum } from '@/enums/httpEnum'
import { InteractEventOn, COMPONENT_INTERACT_EVENT_KET } from '@/enums/eventEnum'
import { icon } from '@/plugins'
import noData from '@/assets/images/canvas/noData.png'
import { goDialog } from '@/utils'
import { useTargetData } from '../../../hooks/useTargetData.hook'
const { CloseIcon, AddIcon, HelpOutlineIcon } = icon.ionicons5
const { targetData, chartEditStore } = useTargetData()
const requestParamsTypeList = [RequestParamsTypeEnum.PARAMS, RequestParamsTypeEnum.HEADER]
// 获取组件交互事件列表
const interactActions = computed(() => {
const interactActions = targetData.value.interactActions
if (!interactActions) return []
return interactActions.map(value => ({
label: value.interactName,
value: value.interactType
}))
})
// 获取组件事件
const option = computed(() => {
return targetData.value.option
})
// 绑定组件数据 request
const fnGetRequest = (id: string | undefined, key: RequestParamsTypeEnum) => {
if (!id) return {}
const globalConfigPindApr = chartEditStore.requestGlobalConfig.requestDataPond.find(item => {
return item.dataPondId === id
})?.dataPondRequestConfig.requestParams
if (globalConfigPindApr) return globalConfigPindApr[key]
return chartEditStore.componentList[chartEditStore.fetchTargetIndex(id)]?.request.requestParams[key]
}
// 查询结果
const fnDimensionsAndSource = (interactOn: InteractEventOn | undefined) => {
if (!interactOn || !targetData.value.interactActions) return []
const tableData = targetData.value.interactActions.find(item => {
return item.interactType === interactOn
})
return tableData?.componentEmitEvents[option.value[COMPONENT_INTERACT_EVENT_KET]] || []
}
// 绑定组件列表
const fnEventsOptions = (): Array<SelectOption | SelectGroupOption> => {
// 扁平化树形数据
const fnFlattern = (
data: Array<CreateComponentType | CreateComponentGroupType>
): Array<CreateComponentType | CreateComponentGroupType> => {
return data.reduce(
(
iter: Array<CreateComponentType | CreateComponentGroupType>,
val: CreateComponentType | CreateComponentGroupType
) => {
/**
* WARNING 这里升级版本有冲突
* 不修改这里的话,会造成联动组件绑定不了动态请求相关的组件
* 由于只修改一处,所以没必要进行重写,原因是原作者用的是AJAX,此项目重写了原作者的动态请求方式,此项目使用的是Pond
* 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯
* 源代码 RequestDataTypeEnum.AJAX
* 修改后的代码 RequestDataTypeEnum.Pond
* 修改后代码在//之间
*/
if (!val.groupList && val.request.requestDataType === RequestDataTypeEnum.Pond && val.request.requestUrl) {
iter.push(val)
}
//
return val.groupList && val.groupList.length > 0 ? [...iter, ...fnFlattern(val.groupList)] : iter
},
[]
)
}
const filterOptionList = fnFlattern(chartEditStore.componentList).filter(item => {
// 排除自己
const isNotSelf = item.id !== targetData.value.id
// 排除静态组件
const isNotStatic = item.chartConfig.chartFrame !== ChartFrameEnum.STATIC
// 排除分组
const isNotGroup = !item.isGroup
return isNotSelf && isNotStatic && isNotGroup
})
const mapOptionList = filterOptionList.map(item => ({
id: item.id,
title: item.chartConfig.title,
disabled: false,
type: 'componentList'
}))
const requestDataPond = chartEditStore.requestGlobalConfig.requestDataPond.map(item => ({
id: item.dataPondId,
title: item.dataPondName,
disabled: false,
type: 'requestDataPond'
}))
const tarArr = requestDataPond.concat(mapOptionList)
targetData.value.events.interactEvents?.forEach(iaItem => {
mapOptionList.forEach(optionItem => {
if (optionItem.id === iaItem.interactComponentId) {
optionItem.disabled = true
}
})
})
return tarArr
}
// 新增模块
const evAddEventsFn = () => {
targetData.value.events.interactEvents.push({
interactOn: undefined,
interactComponentId: undefined,
interactFn: {}
})
}
// 删除模块
const evDeleteEventsFn = (index: number) => {
goDialog({
message: '是否删除此关联交互模块?',
onPositiveCallback: () => {
targetData.value.events.interactEvents.splice(index, 1)
}
})
}
</script>
<style lang="scss" scoped>
.mill-chart-target-data {
:deep(pre) {
white-space: pre-wrap;
word-wrap: break-word;
}
}
.n-input-group {
height: 30px;
}
.no-data {
flex-direction: column;
width: 100%;
img {
width: 120px;
}
}
:deep(.n-base-selection .n-base-selection-label) {
height: 32px;
}
</style>