index.vue
5.24 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
<script setup lang="ts">
import { ref, computed, onBeforeUnmount, watchEffect, unref } from 'vue'
import { icon } from '@/plugins'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { ChartDataMatchingAndShow } from '../../../external/components/ChartDataMatchingAndShow'
import { ChartDataPondControl } from '../ChartDataPond/components/ChartDataPondControl'
import { useTargetData } from '../../../../hooks/useTargetData.hook'
import { NButton, NSelect, NTooltip, NIcon, SelectOption } from 'naive-ui'
import { RequestInfoPanel } from '../RequestInfoPanel'
import { RequestModal } from '../RequestModal'
import { useFetchTargetData } from '@/hooks/external/useFetchTargetData'
import { useFilterFn } from '@/hooks/external/useFilterFn'
import { RequestDataTypeEnum } from '@/enums/external/httpEnum'
const { HelpOutlineIcon, FlashIcon } = icon.ionicons5
const { targetData } = useTargetData()
const requestModal = ref<InstanceType<typeof RequestModal>>()
const designStore = useDesignStore()
/**
* ft 修改在公共接口下拉框里默认选择公共接口
* 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯
* 源代码 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.AJAX)
* 修改后的代码 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond)
* 修改后代码在//ft之间
*/
const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond)
const getApiRequestType: SelectOption[] = [
{ label: '自定义请求', value: RequestDataTypeEnum.AJAX },
{ label: '公共接口', value: RequestDataTypeEnum.Pond }
]
// 是否展示数据分析
const loading = ref(false)
const showMatching = ref(false)
let firstFocus = 0
let lastFilter: any = undefined
const { fetchTargetData } = useFetchTargetData()
// 发送请求
const sendHandle = async () => {
if (!targetData.value?.request || !targetData.value.request.requestUrl) {
window['$message'].warning('请先配置请求')
return
}
loading.value = true
try {
const res = await fetchTargetData()
if (res) {
const { value } = useFilterFn(targetData.value.filter, res)
targetData.value.option.dataset = value
showMatching.value = true
return
}
} finally {
loading.value = false
}
}
// 颜色
const themeColor = computed(() => {
return designStore.getAppTheme
})
const handleClickPanel = () => {
unref(requestModal as any)?.openModal?.(true, unref(selectedRequestType))
if (selectedRequestType.value === RequestDataTypeEnum.AJAX) {
targetData.value.request.requestDataType = RequestDataTypeEnum.AJAX
}
}
// TODO socket 请求时会触发
watchEffect(() => {
const filter = targetData.value?.filter
/**
* FT 修改
*/
if (!filter) return
//ft
if (lastFilter !== filter && firstFocus) {
lastFilter = filter
sendHandle()
}
firstFocus++
})
onBeforeUnmount(() => {
lastFilter = null
})
const controlModel = ref(false)
const handleOpenChartDataPondModal = () => controlModel.value = true
</script>
<template>
<div class="things-kit-chart-configurations-data-ajax">
<SettingItemBox name="接口方式" :alone="true">
<NSelect v-model:value="selectedRequestType" :options="getApiRequestType" />
</SettingItemBox>
<SettingItemBox v-if="selectedRequestType === RequestDataTypeEnum.AJAX" name="全局配置" :alone="true">
<NButton @click="handleOpenChartDataPondModal" type="success">配置</NButton>
</SettingItemBox>
<RequestInfoPanel @clickPanel="handleClickPanel" />
<SettingItemBox :alone="true">
<template #name>
测试
<NTooltip trigger="hover">
<template #trigger>
<NIcon size="21" :depth="3">
<HelpOutlineIcon />
</NIcon>
</template>
默认赋值给 dataset 字段
</NTooltip>
</template>
<NButton type="primary" ghost @click="sendHandle">
<template #icon>
<NIcon>
<FlashIcon />
</NIcon>
</template>
发送请求
</NButton>
</SettingItemBox>
<!-- 底部数据展示 -->
<ChartDataMatchingAndShow :show="showMatching && !loading" :ajax="true"></ChartDataMatchingAndShow>
<!-- 骨架图 -->
<go-skeleton :load="loading" :repeat="3"></go-skeleton>
<RequestModal ref="requestModal" />
<chart-data-pond-control v-model:modelShow="controlModel" @sendHandle="sendHandle"></chart-data-pond-control>
</div>
</template>
<style lang="scss" scoped>
@include thingsKit('chart-configurations-data-ajax') {
.n-card-shallow {
&.n-card {
@extend .go-background-filter;
@include deep() {
.n-card__content {
padding: 10px;
}
}
}
.edit-text {
position: absolute;
top: 0px;
left: 0px;
width: 325px;
height: 270px;
cursor: pointer;
opacity: 0;
transition: all 0.3s;
@extend .go-background-filter;
backdrop-filter: blur(2px) !important;
}
&:hover {
border-color: v-bind('themeColor');
.edit-text {
opacity: 1;
}
}
}
}
</style>