index.vue
8.61 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
285
286
287
288
289
290
291
292
293
294
295
<template>
<div class="go-chart-search-box">
<div class="chart-search go-transition" :class="{ 'chart-search-focus': isFocus }">
<n-popover
class="chart-search-popover"
:show-arrow="false"
:show="showPopover"
:to="false"
trigger="hover"
placement="bottom-start"
>
<template #trigger>
<n-input-group>
<n-input
size="small"
:placeholder="t('common.searchComponentText')"
v-model:value.trim="search"
:loading="loading"
@focus="focusHandle(true)"
@blur="focusHandle(false)"
@update:value="searchHandle"
>
<template #suffix>
<n-icon v-show="!loading" :component="SearchIcon" />
</template>
</n-input>
</n-input-group>
</template>
<div class="search-list-box">
<n-scrollbar style="max-height: 500px">
<n-empty v-show="!searchRes.length" size="small" :description="t('business.notComponent')"></n-empty>
<div
class="list-item go-flex-items-center go-ellipsis-1"
v-for="item in searchRes"
:key="item.key"
:title="item.title"
@click="selectChartHandle(item)"
>
<Icon v-if="item.icon" class="list-img" :icon="item.icon" color="#999" width="20" />
<chart-glob-image v-else class="list-item-img" :chartConfig="item" />
<n-text class="list-item-fs" depth="2">{{ item.title }}</n-text>
</div>
</n-scrollbar>
<div class="popover-modal"></div>
</div>
</n-popover>
</div>
<n-button-group class="btn-group go-transition" :class="{ 'btn-group-focus': isFocus }" style="display: flex">
<n-button
ghost
size="small"
:key="index"
:type="chartMode === item.value ? 'primary' : 'tertiary'"
v-for="(item, index) in chartModeList"
@click="changeChartModeType(item.value)"
>
<n-tooltip :show-arrow="false" trigger="hover">
<template #trigger>
<n-icon size="14" :component="item.icon" />
</template>
{{ item.label }}
</n-tooltip>
</n-button>
</n-button-group>
</div>
</template>
<script setup lang="ts">
import { ref, onUnmounted } from 'vue'
import { icon } from '@/plugins'
// import { createComponent } from '@/packages'
// THINGS_KIT 覆盖原始创建组件逻辑
import { createComponent } from '@/packages/external/override'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import { themeColor } from '../../hooks/useLayout.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { ChartModeEnum, ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { isString, addEventListener, removeEventListener } from '@/utils'
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
import { componentInstall, loadingStart, loadingFinish, loadingError } from '@/utils'
import { ChartGlobImage } from '@/components/Pages/ChartGlobImage'
import { Icon } from '@iconify/vue'
// THINGS_KIT 修改搜索未过滤隐藏的组件
import { hideAsideComponentsObj } from '../../external/components/ChartsOptionContent/config'
import { cloneDeep } from 'lodash'
//
const props = defineProps({
menuOptions: {
type: Array,
default: () => []
}
})
const t = window['$t']
const chartEditStore = useChartEditStore()
const chartLayoutStore = useChartLayoutStore()
const { SearchIcon, AlbumsIcon, GridIcon } = icon.ionicons5
const isFocus = ref<boolean>(false)
const showPopover = ref<boolean>(false)
const loading = ref<boolean | undefined>(undefined)
const search = ref<string | null>(null)
const searchRes = ref<ConfigType[]>([])
const chartMode = ref<ChartModeEnum>(chartLayoutStore.getChartType)
const chartModeList = [
{ label: t('business.chartMode.singleRow'), icon: AlbumsIcon, value: ChartModeEnum.SINGLE },
{ label: t('business.chartMode.biserial'), icon: GridIcon, value: ChartModeEnum.DOUBLE }
]
// 组件数组提取
const listFormatHandle = (options: any[]) => {
const realt = window['$t']
const arr = []
for (const item of options) {
arr.push(...item.list)
}
// THINGS_KIT 修改搜索未过滤隐藏的组件
const realArr = arr.filter((e: ConfigType) => !hideAsideComponentsObj['all'].includes(e.chartKey))
//
realArr.forEach(realItem=>{
realItem.title = realt(realItem.title)
realItem.categoryName = realt(realItem.categoryName)
})
return realArr
}
// 组件列表
const List = listFormatHandle(cloneDeep(props.menuOptions as unknown as ConfigType[]))
// 关闭处理
const closeHandle = () => {
loading.value = undefined
showPopover.value = false
search.value = null
searchRes.value = []
}
// 搜索处理
const searchHandle = (key: string | null) => {
if (!isString(key) || !key.length) {
closeHandle()
return
}
loading.value = true
showPopover.value = true
searchRes.value = List.filter(
(e: ConfigType) => !e.disabled && (!key || e.title.toLowerCase().includes(key.toLowerCase()))
)
setTimeout(() => {
loading.value = undefined
}, 500)
}
// 关闭处理
const listenerCloseHandle = (e: Event) => {
if (!showPopover.value) return
if (!e.target) return
if (!(e.target as any).closest('.go-chart-search')) {
closeHandle()
}
}
// 选择处理
const selectChartHandle = async (item: ConfigType) => {
if (item.disabled) return
try {
loadingStart()
// 动态注册图表组件
componentInstall(item.chartKey, fetchChartComponent(item))
componentInstall(item.conKey, fetchConfigComponent(item))
// 创建新图表组件
let newComponent: CreateComponentType = await createComponent(item)
if (item.redirectComponent) {
item.dataset && (newComponent.option.dataset = item.dataset)
newComponent.chartConfig.title = item.title
newComponent.chartConfig.chartFrame = item.chartFrame
}
// 添加
chartEditStore.addComponentList(newComponent, false, true)
// 选中
chartEditStore.setTargetSelectChart(newComponent.id)
// 清空搜索
closeHandle()
loadingFinish()
} catch (error) {
loadingError()
window['$message'].warning(`图表正在研发中, 敬请期待...`)
}
}
// 聚焦设置
const focusHandle = (value: boolean) => {
isFocus.value = value
}
// 修改图表展示方式
const changeChartModeType = (value: ChartModeEnum) => {
chartMode.value = value
chartLayoutStore.setItem(ChartLayoutStoreEnum.Chart_TYPE, value)
}
addEventListener(document, 'click', (e: Event) => {
listenerCloseHandle(e)
})
onUnmounted(() => {
removeEventListener(document, 'click', listenerCloseHandle)
})
</script>
<style lang="scss" scoped>
$width: 98px;
$searchWidth: 176px;
@include go('chart-search-box') {
display: flex;
.chart-search {
width: $width;
margin-right: 10px;
&.chart-search-focus {
width: $searchWidth;
&.chart-search {
margin-right: 0;
}
}
@include deep() {
.chart-search-popover {
padding-left: 5px;
padding-right: 8px;
}
}
.chart-search-popover {
.search-list-box {
width: 163px;
.list-item {
z-index: 2;
position: relative;
cursor: pointer;
padding: 2px;
padding-left: 6px;
margin-bottom: 5px;
&-fs {
font-size: 12px;
}
&-img {
height: 20px;
max-width: 30px;
margin-right: 5px;
border-radius: 5px;
}
& > svg {
min-width: 20px;
min-height: 20px;
margin-right: 5px;
}
&:hover {
&::before {
content: '';
position: absolute;
width: 3px;
height: 100%;
left: 0;
top: 0;
border-radius: 2px;
background-color: v-bind('themeColor');
}
&::after {
z-index: -1;
content: '';
position: absolute;
width: 100%;
height: 100%;
opacity: 0.1;
left: 0;
top: 0;
border-radius: 5px;
background-color: v-bind('themeColor');
}
}
}
}
}
}
.btn-group {
width: 68px;
overflow: hidden;
&.btn-group-focus {
width: 0px;
}
}
}
</style>