mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-25 00:33:00 +08:00
fix: 新增组件搜索功能
This commit is contained in:
parent
17f29d3773
commit
798a7eb49a
@ -51,7 +51,8 @@ import {
|
|||||||
ColorWand as ColorWandIcon,
|
ColorWand as ColorWandIcon,
|
||||||
ArrowBack as ArrowBackIcon,
|
ArrowBack as ArrowBackIcon,
|
||||||
ArrowForward as ArrowForwardIcon,
|
ArrowForward as ArrowForwardIcon,
|
||||||
Planet as PawIcon
|
Planet as PawIcon,
|
||||||
|
Search as SearchIcon
|
||||||
} from '@vicons/ionicons5'
|
} from '@vicons/ionicons5'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -183,7 +184,9 @@ const ionicons5 = {
|
|||||||
// 前进
|
// 前进
|
||||||
ArrowForwardIcon,
|
ArrowForwardIcon,
|
||||||
// 狗爪
|
// 狗爪
|
||||||
PawIcon
|
PawIcon,
|
||||||
|
// 搜索(放大镜)
|
||||||
|
SearchIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
const carbon = {
|
const carbon = {
|
||||||
|
@ -2,6 +2,9 @@ body {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
/* 设置滚动条的样式 */
|
/* 设置滚动条的样式 */
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
width: 8px;
|
width: 8px;
|
||||||
|
@ -72,6 +72,14 @@
|
|||||||
background-size: 15px 15px, 15px 15px;
|
background-size: 15px 15px, 15px 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 省略号
|
||||||
|
.ellipsis-1 {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
// todo 使用 scss 循环写一套完整的
|
// todo 使用 scss 循环写一套完整的
|
||||||
// margin
|
// margin
|
||||||
.go-mt-0 {
|
.go-mt-0 {
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
import ChartsItemBox from './index.vue'
|
||||||
|
|
||||||
|
export { ChartsItemBox }
|
@ -0,0 +1,3 @@
|
|||||||
|
import ChartsOptionContent from './index.vue'
|
||||||
|
|
||||||
|
export { ChartsOptionContent }
|
@ -12,7 +12,7 @@
|
|||||||
></n-menu>
|
></n-menu>
|
||||||
<div class="chart-content-list">
|
<div class="chart-content-list">
|
||||||
<n-scrollbar>
|
<n-scrollbar>
|
||||||
<item-box :menuOptions="packages.selectOptions"></item-box>
|
<charts-item-box :menuOptions="packages.selectOptions"></charts-item-box>
|
||||||
</n-scrollbar>
|
</n-scrollbar>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -24,8 +24,8 @@ import { ConfigType } from '@/packages/index.d'
|
|||||||
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
||||||
import { loadAsyncComponent } from '@/utils'
|
import { loadAsyncComponent } from '@/utils'
|
||||||
|
|
||||||
const ItemBox = loadAsyncComponent(() =>
|
const ChartsItemBox = loadAsyncComponent(() =>
|
||||||
import('../ItemBox/index.vue')
|
import('../ChartsItemBox/index.vue')
|
||||||
)
|
)
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
@ -0,0 +1,3 @@
|
|||||||
|
import ChartsSearch from './index.vue'
|
||||||
|
|
||||||
|
export { ChartsSearch }
|
139
src/views/chart/ContentCharts/components/ChartsSearch/index.vue
Normal file
139
src/views/chart/ContentCharts/components/ChartsSearch/index.vue
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<template>
|
||||||
|
<div class="go-chart-search">
|
||||||
|
<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
|
||||||
|
v-model:value.trim="search"
|
||||||
|
size="small"
|
||||||
|
:loading="loading"
|
||||||
|
clearable
|
||||||
|
placeholder="请输入组件名称"
|
||||||
|
@update:value="searchHandle"
|
||||||
|
>
|
||||||
|
<template #suffix>
|
||||||
|
<n-icon :component="SearchIcon" />
|
||||||
|
</template>
|
||||||
|
</n-input>
|
||||||
|
</n-input-group>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="search-list-box">
|
||||||
|
<n-scrollbar style="max-height: 500px">
|
||||||
|
<n-text v-show="!searchRes.length">没有找到组件~</n-text>
|
||||||
|
<div
|
||||||
|
class="list-item ellipsis-1"
|
||||||
|
v-for="item in searchRes"
|
||||||
|
:key="item.key"
|
||||||
|
:title="item.title"
|
||||||
|
>
|
||||||
|
{{ item.title }}
|
||||||
|
</div>
|
||||||
|
</n-scrollbar>
|
||||||
|
<div class="popover-modal"></div>
|
||||||
|
</div>
|
||||||
|
</n-popover>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, onUnmounted } from 'vue'
|
||||||
|
import { icon } from '@/plugins'
|
||||||
|
import { themeColor, MenuOptionsType } from '../../hooks/useAside.hook'
|
||||||
|
import { ConfigType } from '@/packages/index.d'
|
||||||
|
import { isString, addEventListener, removeEventListener } from '@/utils'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
menuOptions: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { SearchIcon } = icon.ionicons5
|
||||||
|
const showPopover = ref<boolean>(false)
|
||||||
|
const loading = ref<boolean | undefined>(undefined)
|
||||||
|
const search = ref<string | null>(null)
|
||||||
|
const searchRes = ref<ConfigType[]>([])
|
||||||
|
|
||||||
|
// 组件数组提取
|
||||||
|
const listFormatHandle = (options: any[]) => {
|
||||||
|
const arr = []
|
||||||
|
for (const item of options) {
|
||||||
|
arr.push(...item.list)
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件列表
|
||||||
|
const List = listFormatHandle(props.menuOptions as unknown as ConfigType[])
|
||||||
|
|
||||||
|
// 搜索处理
|
||||||
|
const searchHandle = (key: string | null) => {
|
||||||
|
if (!isString(key) || !key.length) {
|
||||||
|
showPopover.value = false
|
||||||
|
searchRes.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showPopover.value = true
|
||||||
|
searchRes.value = List.filter(
|
||||||
|
(e: ConfigType) => !key || e.title.toLowerCase().includes(key.toLowerCase())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭处理
|
||||||
|
const closeHandle = (e: Event) => {
|
||||||
|
if (!showPopover.value) return
|
||||||
|
if (!e.target) return
|
||||||
|
if (!(e.target as any).closest('.go-chart-search')) {
|
||||||
|
showPopover.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListener(document, 'click', (e: Event) => {
|
||||||
|
closeHandle(e)
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
removeEventListener(document, 'click', closeHandle)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$width: 146px;
|
||||||
|
@include go('chart-search') {
|
||||||
|
width: $width;
|
||||||
|
margin-right: -10px;
|
||||||
|
.chart-search-popover {
|
||||||
|
.search-list-box {
|
||||||
|
width: $width;
|
||||||
|
.list-item {
|
||||||
|
z-index: 2;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 2px 0 2px 10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
&:hover {
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
opacity: 0.1;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: v-bind('themeColor');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,3 +0,0 @@
|
|||||||
import ItemBox from './index.vue'
|
|
||||||
|
|
||||||
export { ItemBox }
|
|
@ -1,3 +0,0 @@
|
|||||||
import OptionContent from './index.vue'
|
|
||||||
|
|
||||||
export { OptionContent }
|
|
@ -15,14 +15,17 @@ const {
|
|||||||
GraphicalDataFlowIcon,
|
GraphicalDataFlowIcon,
|
||||||
} = icon.carbon
|
} = icon.carbon
|
||||||
|
|
||||||
|
|
||||||
// 图表
|
// 图表
|
||||||
const { getPackagesList } = usePackagesStore()
|
export type MenuOptionsType = {
|
||||||
const menuOptions:{
|
|
||||||
key: string
|
key: string
|
||||||
icon: ReturnType<typeof renderIcon>
|
icon: ReturnType<typeof renderIcon>
|
||||||
label: ReturnType<typeof renderLang>
|
label: ReturnType<typeof renderLang>
|
||||||
list: PackagesType
|
list: PackagesType
|
||||||
}[] = []
|
}
|
||||||
|
|
||||||
|
const { getPackagesList } = usePackagesStore()
|
||||||
|
const menuOptions: MenuOptionsType[] = []
|
||||||
|
|
||||||
const packagesListObj = {
|
const packagesListObj = {
|
||||||
[PackagesCategoryEnum.CHARTS]: {
|
[PackagesCategoryEnum.CHARTS]: {
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
<bar-chart-icon></bar-chart-icon>
|
<bar-chart-icon></bar-chart-icon>
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template #top-right>
|
||||||
|
<charts-search v-show="getCharts" :menuOptions="menuOptions"></charts-search>
|
||||||
|
</template>
|
||||||
<!-- 图表 -->
|
<!-- 图表 -->
|
||||||
<aside>
|
<aside>
|
||||||
<div class="menu-width-box">
|
<div class="menu-width-box">
|
||||||
@ -22,20 +26,20 @@
|
|||||||
:icon-size="16"
|
:icon-size="16"
|
||||||
:indent="18"
|
:indent="18"
|
||||||
@update:value="clickItemHandle"
|
@update:value="clickItemHandle"
|
||||||
></n-menu>
|
></n-menu>
|
||||||
<div class="menu-component-box">
|
<div class="menu-component-box">
|
||||||
<go-skeleton
|
<go-skeleton
|
||||||
:load="!selectOptions"
|
:load="!selectOptions"
|
||||||
round
|
round
|
||||||
text
|
text
|
||||||
:repeat="2"
|
:repeat="2"
|
||||||
style="width: 90%;"
|
style="width: 90%"
|
||||||
></go-skeleton>
|
></go-skeleton>
|
||||||
<option-content
|
<charts-option-content
|
||||||
v-if="selectOptions"
|
v-if="selectOptions"
|
||||||
:selectOptions="selectOptions"
|
:selectOptions="selectOptions"
|
||||||
:key="selectValue"
|
:key="selectValue"
|
||||||
></option-content>
|
></charts-option-content>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
@ -44,7 +48,8 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ContentBox } from '../contentBox/index'
|
import { ContentBox } from '../contentBox/index'
|
||||||
import { OptionContent } from './components/OptionContent'
|
import { ChartsOptionContent } from './components/ChartsOptionContent'
|
||||||
|
import { ChartsSearch } from './components/ChartsSearch'
|
||||||
import {
|
import {
|
||||||
getCharts,
|
getCharts,
|
||||||
BarChartIcon,
|
BarChartIcon,
|
||||||
@ -52,7 +57,7 @@ import {
|
|||||||
selectOptions,
|
selectOptions,
|
||||||
selectValue,
|
selectValue,
|
||||||
clickItemHandle,
|
clickItemHandle,
|
||||||
menuOptions
|
menuOptions,
|
||||||
} from './hooks/useAside.hook'
|
} from './hooks/useAside.hook'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user