index.vue
4.1 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
<script setup lang="ts">
import { ref, computed, onBeforeUnmount, watchEffect, toRaw, unref } from 'vue'
import { icon } from '@/plugins'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { RequestDataTypeEnum } from '@/enums/external/httpEnum'
import { ChartDataMatchingAndShow } from '../../../external/components/ChartDataMatchingAndShow'
import { newFunctionHandle } from '@/utils'
import { useTargetData } from '../../../../hooks/useTargetData.hook'
import { NButton, NSelect, NTooltip, NIcon, SelectOption } from 'naive-ui'
import { RequestInfoPanel } from '../RequestInfoPanel'
import { RequestModal } from '../RequestModal'
import { customRequest } from '@/api/external/customRequest'
const { HelpOutlineIcon, FlashIcon } = icon.ionicons5
const { targetData } = useTargetData()
const requestModal = ref<InstanceType<typeof RequestModal>>()
const designStore = useDesignStore()
const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.AJAX)
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 sendHandle = async () => {
if (!targetData.value?.request) return
loading.value = true
try {
console.log('enter')
const res = await customRequest(toRaw(targetData.value.request))
loading.value = false
if (res) {
targetData.value.option.dataset = newFunctionHandle(res, res, targetData.value.filter)
showMatching.value = true
return
}
window['$message'].warning('数据异常,请检查参数!')
} catch (error) {
loading.value = false
window['$message'].warning('数据异常,请检查参数!')
}
}
// 颜色
const themeColor = computed(() => {
return designStore.getAppTheme
})
const handleClickPanel = () => {
unref(requestModal)?.openModal(true, unref(selectedRequestType))
}
watchEffect(() => {
const filter = targetData.value?.filter
if (lastFilter !== filter && firstFocus) {
lastFilter = filter
sendHandle()
}
firstFocus++
})
onBeforeUnmount(() => {
lastFilter = null
})
</script>
<template>
<div class="things-kit-chart-configurations-data-ajax">
<SettingItemBox name="接口方式" :alone="true">
<NSelect v-model:value="selectedRequestType" :options="getApiRequestType" />
</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" />
</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>