mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
frontend: 系统菜单/字段/权限页面 UI 优化
- IconSelector.vue: 重构,精简代码 - MenuFormModal / index: 表单和页面优化 - field / system-permission: 小幅调整
This commit is contained in:
@@ -98,13 +98,12 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
height: 'auto',
|
height: 'auto',
|
||||||
border: true,
|
border: true,
|
||||||
stripe: true,
|
stripe: true,
|
||||||
rowConfig: { isHover: true },
|
|
||||||
showOverflow: true,
|
|
||||||
size: 'small',
|
|
||||||
resizable: true,
|
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
|
isHover: true,
|
||||||
drag: true, // 启用行拖拽
|
drag: true, // 启用行拖拽
|
||||||
},
|
},
|
||||||
|
showOverflow: true,
|
||||||
|
size: 'small',
|
||||||
rowDragConfig: {
|
rowDragConfig: {
|
||||||
isPeerDrag: true, // 启用同层级拖拽限制
|
isPeerDrag: true, // 启用同层级拖拽限制
|
||||||
},
|
},
|
||||||
|
|||||||
+212
-478
@@ -1,9 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
import { useDebounceFn } from '@vueuse/core';
|
||||||
|
|
||||||
import { Input } from 'ant-design-vue';
|
import { Input, Select, Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue?: string;
|
modelValue?: string;
|
||||||
@@ -16,435 +17,143 @@ interface Emits {
|
|||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
const searchKeyword = ref('');
|
const ICONIFY = 'https://api.iconify.design';
|
||||||
const selectedIcon = ref(props.modelValue || '');
|
|
||||||
const currentPage = ref(1);
|
|
||||||
const pageSize = 36; // 6列 x 6行
|
|
||||||
|
|
||||||
// 常用图标列表
|
const GLOBAL_PREFIX = '__global__';
|
||||||
const iconList = [
|
|
||||||
{ name: 'lucide:plus', component: createIconifyIcon('lucide:plus') },
|
/** 常用图标集(Iconify prefix),可继续扩充 */
|
||||||
{ name: 'lucide:home', component: createIconifyIcon('lucide:home') },
|
const COLLECTION_OPTIONS = [
|
||||||
{ name: 'lucide:user', component: createIconifyIcon('lucide:user') },
|
|
||||||
{ name: 'lucide:settings', component: createIconifyIcon('lucide:settings') },
|
|
||||||
{ name: 'lucide:menu', component: createIconifyIcon('lucide:menu') },
|
|
||||||
{ name: 'lucide:search', component: createIconifyIcon('lucide:search') },
|
|
||||||
{ name: 'lucide:edit', component: createIconifyIcon('lucide:edit') },
|
|
||||||
{ name: 'lucide:trash-2', component: createIconifyIcon('lucide:trash-2') },
|
|
||||||
{ name: 'lucide:save', component: createIconifyIcon('lucide:save') },
|
|
||||||
{ name: 'lucide:download', component: createIconifyIcon('lucide:download') },
|
|
||||||
{ name: 'lucide:upload', component: createIconifyIcon('lucide:upload') },
|
|
||||||
{ name: 'lucide:folder', component: createIconifyIcon('lucide:folder') },
|
|
||||||
{ name: 'lucide:file', component: createIconifyIcon('lucide:file') },
|
|
||||||
{ name: 'lucide:image', component: createIconifyIcon('lucide:image') },
|
|
||||||
{ name: 'lucide:video', component: createIconifyIcon('lucide:video') },
|
|
||||||
{ name: 'lucide:music', component: createIconifyIcon('lucide:music') },
|
|
||||||
{ name: 'lucide:mail', component: createIconifyIcon('lucide:mail') },
|
|
||||||
{ name: 'lucide:phone', component: createIconifyIcon('lucide:phone') },
|
|
||||||
{ name: 'lucide:calendar', component: createIconifyIcon('lucide:calendar') },
|
|
||||||
{ name: 'lucide:clock', component: createIconifyIcon('lucide:clock') },
|
|
||||||
{ name: 'lucide:star', component: createIconifyIcon('lucide:star') },
|
|
||||||
{ name: 'lucide:heart', component: createIconifyIcon('lucide:heart') },
|
|
||||||
{
|
{
|
||||||
name: 'lucide:thumbs-up',
|
label: '全局搜索(不限图标集,仅关键词)',
|
||||||
component: createIconifyIcon('lucide:thumbs-up'),
|
value: GLOBAL_PREFIX,
|
||||||
},
|
},
|
||||||
{
|
{ label: 'Lucide', value: 'lucide' },
|
||||||
name: 'lucide:thumbs-down',
|
{ label: 'Material Design Icons', value: 'mdi' },
|
||||||
component: createIconifyIcon('lucide:thumbs-down'),
|
{ label: 'Carbon', value: 'carbon' },
|
||||||
},
|
{ label: 'Tabler', value: 'tabler' },
|
||||||
{ name: 'lucide:eye', component: createIconifyIcon('lucide:eye') },
|
{ label: 'Phosphor', value: 'ph' },
|
||||||
{ name: 'lucide:eye-off', component: createIconifyIcon('lucide:eye-off') },
|
{ label: 'Remix Icon', value: 'ri' },
|
||||||
{ name: 'lucide:lock', component: createIconifyIcon('lucide:lock') },
|
{ label: 'Heroicons', value: 'heroicons' },
|
||||||
{ name: 'lucide:unlock', component: createIconifyIcon('lucide:unlock') },
|
{ label: 'Material Symbols', value: 'material-symbols' },
|
||||||
{ name: 'lucide:shield', component: createIconifyIcon('lucide:shield') },
|
{ label: 'Ant Design Icons', value: 'ant-design' },
|
||||||
{ name: 'lucide:key', component: createIconifyIcon('lucide:key') },
|
{ label: 'Bootstrap Icons', value: 'bi' },
|
||||||
{ name: 'lucide:bell', component: createIconifyIcon('lucide:bell') },
|
{ label: 'MingCute', value: 'mingcute' },
|
||||||
{
|
{ label: 'Logos', value: 'logos' },
|
||||||
name: 'lucide:message-circle',
|
{ label: 'Simple Icons', value: 'simple-icons' },
|
||||||
component: createIconifyIcon('lucide:message-circle'),
|
{ label: 'Font Awesome 6', value: 'fa6-solid' },
|
||||||
},
|
{ label: 'Iconoir', value: 'iconoir' },
|
||||||
{ name: 'lucide:users', component: createIconifyIcon('lucide:users') },
|
|
||||||
{
|
|
||||||
name: 'lucide:user-plus',
|
|
||||||
component: createIconifyIcon('lucide:user-plus'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:user-minus',
|
|
||||||
component: createIconifyIcon('lucide:user-minus'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:user-check',
|
|
||||||
component: createIconifyIcon('lucide:user-check'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:user-x', component: createIconifyIcon('lucide:user-x') },
|
|
||||||
{ name: 'lucide:grid', component: createIconifyIcon('lucide:grid') },
|
|
||||||
{ name: 'lucide:list', component: createIconifyIcon('lucide:list') },
|
|
||||||
{ name: 'lucide:layout', component: createIconifyIcon('lucide:layout') },
|
|
||||||
{ name: 'lucide:sidebar', component: createIconifyIcon('lucide:sidebar') },
|
|
||||||
{
|
|
||||||
name: 'lucide:panel-left',
|
|
||||||
component: createIconifyIcon('lucide:panel-left'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:panel-right',
|
|
||||||
component: createIconifyIcon('lucide:panel-right'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:panel-top',
|
|
||||||
component: createIconifyIcon('lucide:panel-top'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:panel-bottom',
|
|
||||||
component: createIconifyIcon('lucide:panel-bottom'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:chevron-up',
|
|
||||||
component: createIconifyIcon('lucide:chevron-up'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:chevron-down',
|
|
||||||
component: createIconifyIcon('lucide:chevron-down'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:chevron-left',
|
|
||||||
component: createIconifyIcon('lucide:chevron-left'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:chevron-right',
|
|
||||||
component: createIconifyIcon('lucide:chevron-right'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:arrow-up', component: createIconifyIcon('lucide:arrow-up') },
|
|
||||||
{
|
|
||||||
name: 'lucide:arrow-down',
|
|
||||||
component: createIconifyIcon('lucide:arrow-down'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:arrow-left',
|
|
||||||
component: createIconifyIcon('lucide:arrow-left'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:arrow-right',
|
|
||||||
component: createIconifyIcon('lucide:arrow-right'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:external-link',
|
|
||||||
component: createIconifyIcon('lucide:external-link'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:link', component: createIconifyIcon('lucide:link') },
|
|
||||||
{ name: 'lucide:unlink', component: createIconifyIcon('lucide:unlink') },
|
|
||||||
{ name: 'lucide:copy', component: createIconifyIcon('lucide:copy') },
|
|
||||||
{ name: 'lucide:cut', component: createIconifyIcon('lucide:cut') },
|
|
||||||
{ name: 'lucide:paste', component: createIconifyIcon('lucide:paste') },
|
|
||||||
{ name: 'lucide:undo', component: createIconifyIcon('lucide:undo') },
|
|
||||||
{ name: 'lucide:redo', component: createIconifyIcon('lucide:redo') },
|
|
||||||
{
|
|
||||||
name: 'lucide:refresh-cw',
|
|
||||||
component: createIconifyIcon('lucide:refresh-cw'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:rotate-cw',
|
|
||||||
component: createIconifyIcon('lucide:rotate-cw'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:rotate-ccw',
|
|
||||||
component: createIconifyIcon('lucide:rotate-ccw'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:zoom-in', component: createIconifyIcon('lucide:zoom-in') },
|
|
||||||
{ name: 'lucide:zoom-out', component: createIconifyIcon('lucide:zoom-out') },
|
|
||||||
{ name: 'lucide:maximize', component: createIconifyIcon('lucide:maximize') },
|
|
||||||
{ name: 'lucide:minimize', component: createIconifyIcon('lucide:minimize') },
|
|
||||||
{ name: 'lucide:monitor', component: createIconifyIcon('lucide:monitor') },
|
|
||||||
{
|
|
||||||
name: 'lucide:smartphone',
|
|
||||||
component: createIconifyIcon('lucide:smartphone'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:tablet', component: createIconifyIcon('lucide:tablet') },
|
|
||||||
{ name: 'lucide:laptop', component: createIconifyIcon('lucide:laptop') },
|
|
||||||
{ name: 'lucide:desktop', component: createIconifyIcon('lucide:desktop') },
|
|
||||||
{ name: 'lucide:server', component: createIconifyIcon('lucide:server') },
|
|
||||||
{ name: 'lucide:database', component: createIconifyIcon('lucide:database') },
|
|
||||||
{
|
|
||||||
name: 'lucide:hard-drive',
|
|
||||||
component: createIconifyIcon('lucide:hard-drive'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:wifi', component: createIconifyIcon('lucide:wifi') },
|
|
||||||
{
|
|
||||||
name: 'lucide:bluetooth',
|
|
||||||
component: createIconifyIcon('lucide:bluetooth'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:usb', component: createIconifyIcon('lucide:usb') },
|
|
||||||
{ name: 'lucide:plug', component: createIconifyIcon('lucide:plug') },
|
|
||||||
{ name: 'lucide:battery', component: createIconifyIcon('lucide:battery') },
|
|
||||||
{
|
|
||||||
name: 'lucide:battery-charging',
|
|
||||||
component: createIconifyIcon('lucide:battery-charging'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:power', component: createIconifyIcon('lucide:power') },
|
|
||||||
{ name: 'lucide:volume-2', component: createIconifyIcon('lucide:volume-2') },
|
|
||||||
{ name: 'lucide:volume-x', component: createIconifyIcon('lucide:volume-x') },
|
|
||||||
{ name: 'lucide:play', component: createIconifyIcon('lucide:play') },
|
|
||||||
{ name: 'lucide:pause', component: createIconifyIcon('lucide:pause') },
|
|
||||||
{ name: 'lucide:stop', component: createIconifyIcon('lucide:stop') },
|
|
||||||
{
|
|
||||||
name: 'lucide:skip-back',
|
|
||||||
component: createIconifyIcon('lucide:skip-back'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:skip-forward',
|
|
||||||
component: createIconifyIcon('lucide:skip-forward'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:repeat', component: createIconifyIcon('lucide:repeat') },
|
|
||||||
{ name: 'lucide:shuffle', component: createIconifyIcon('lucide:shuffle') },
|
|
||||||
{ name: 'lucide:mic', component: createIconifyIcon('lucide:mic') },
|
|
||||||
{ name: 'lucide:mic-off', component: createIconifyIcon('lucide:mic-off') },
|
|
||||||
{ name: 'lucide:camera', component: createIconifyIcon('lucide:camera') },
|
|
||||||
{
|
|
||||||
name: 'lucide:camera-off',
|
|
||||||
component: createIconifyIcon('lucide:camera-off'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:video-off',
|
|
||||||
component: createIconifyIcon('lucide:video-off'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:cast', component: createIconifyIcon('lucide:cast') },
|
|
||||||
{ name: 'lucide:airplay', component: createIconifyIcon('lucide:airplay') },
|
|
||||||
{
|
|
||||||
name: 'lucide:headphones',
|
|
||||||
component: createIconifyIcon('lucide:headphones'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:speaker', component: createIconifyIcon('lucide:speaker') },
|
|
||||||
{ name: 'lucide:radio', component: createIconifyIcon('lucide:radio') },
|
|
||||||
{ name: 'lucide:tv', component: createIconifyIcon('lucide:tv') },
|
|
||||||
{
|
|
||||||
name: 'lucide:gamepad-2',
|
|
||||||
component: createIconifyIcon('lucide:gamepad-2'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:joystick', component: createIconifyIcon('lucide:joystick') },
|
|
||||||
{
|
|
||||||
name: 'lucide:controller',
|
|
||||||
component: createIconifyIcon('lucide:controller'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:mouse', component: createIconifyIcon('lucide:mouse') },
|
|
||||||
{ name: 'lucide:keyboard', component: createIconifyIcon('lucide:keyboard') },
|
|
||||||
{ name: 'lucide:printer', component: createIconifyIcon('lucide:printer') },
|
|
||||||
{ name: 'lucide:scanner', component: createIconifyIcon('lucide:scanner') },
|
|
||||||
{ name: 'lucide:fax', component: createIconifyIcon('lucide:fax') },
|
|
||||||
{
|
|
||||||
name: 'lucide:calculator',
|
|
||||||
component: createIconifyIcon('lucide:calculator'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:watch', component: createIconifyIcon('lucide:watch') },
|
|
||||||
{
|
|
||||||
name: 'lucide:alarm-clock',
|
|
||||||
component: createIconifyIcon('lucide:alarm-clock'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:timer', component: createIconifyIcon('lucide:timer') },
|
|
||||||
{
|
|
||||||
name: 'lucide:stopwatch',
|
|
||||||
component: createIconifyIcon('lucide:stopwatch'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:hourglass',
|
|
||||||
component: createIconifyIcon('lucide:hourglass'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:thermometer',
|
|
||||||
component: createIconifyIcon('lucide:thermometer'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:gauge', component: createIconifyIcon('lucide:gauge') },
|
|
||||||
{ name: 'lucide:activity', component: createIconifyIcon('lucide:activity') },
|
|
||||||
{
|
|
||||||
name: 'lucide:trending-up',
|
|
||||||
component: createIconifyIcon('lucide:trending-up'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:trending-down',
|
|
||||||
component: createIconifyIcon('lucide:trending-down'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:bar-chart',
|
|
||||||
component: createIconifyIcon('lucide:bar-chart'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:line-chart',
|
|
||||||
component: createIconifyIcon('lucide:line-chart'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:pie-chart',
|
|
||||||
component: createIconifyIcon('lucide:pie-chart'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:credit-card',
|
|
||||||
component: createIconifyIcon('lucide:credit-card'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:wallet', component: createIconifyIcon('lucide:wallet') },
|
|
||||||
{ name: 'lucide:banknote', component: createIconifyIcon('lucide:banknote') },
|
|
||||||
{ name: 'lucide:coins', component: createIconifyIcon('lucide:coins') },
|
|
||||||
{ name: 'lucide:receipt', component: createIconifyIcon('lucide:receipt') },
|
|
||||||
{
|
|
||||||
name: 'lucide:shopping-cart',
|
|
||||||
component: createIconifyIcon('lucide:shopping-cart'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:shopping-bag',
|
|
||||||
component: createIconifyIcon('lucide:shopping-bag'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:store', component: createIconifyIcon('lucide:store') },
|
|
||||||
{ name: 'lucide:building', component: createIconifyIcon('lucide:building') },
|
|
||||||
{
|
|
||||||
name: 'lucide:building-2',
|
|
||||||
component: createIconifyIcon('lucide:building-2'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:map', component: createIconifyIcon('lucide:map') },
|
|
||||||
{ name: 'lucide:map-pin', component: createIconifyIcon('lucide:map-pin') },
|
|
||||||
{
|
|
||||||
name: 'lucide:navigation',
|
|
||||||
component: createIconifyIcon('lucide:navigation'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:compass', component: createIconifyIcon('lucide:compass') },
|
|
||||||
{ name: 'lucide:globe', component: createIconifyIcon('lucide:globe') },
|
|
||||||
{ name: 'lucide:earth', component: createIconifyIcon('lucide:earth') },
|
|
||||||
{ name: 'lucide:flag', component: createIconifyIcon('lucide:flag') },
|
|
||||||
{ name: 'lucide:bookmark', component: createIconifyIcon('lucide:bookmark') },
|
|
||||||
{ name: 'lucide:tag', component: createIconifyIcon('lucide:tag') },
|
|
||||||
{ name: 'lucide:tags', component: createIconifyIcon('lucide:tags') },
|
|
||||||
{ name: 'lucide:archive', component: createIconifyIcon('lucide:archive') },
|
|
||||||
{ name: 'lucide:inbox', component: createIconifyIcon('lucide:inbox') },
|
|
||||||
{ name: 'lucide:outbox', component: createIconifyIcon('lucide:outbox') },
|
|
||||||
{ name: 'lucide:send', component: createIconifyIcon('lucide:send') },
|
|
||||||
{ name: 'lucide:reply', component: createIconifyIcon('lucide:reply') },
|
|
||||||
{ name: 'lucide:forward', component: createIconifyIcon('lucide:forward') },
|
|
||||||
{ name: 'lucide:share', component: createIconifyIcon('lucide:share') },
|
|
||||||
{ name: 'lucide:share-2', component: createIconifyIcon('lucide:share-2') },
|
|
||||||
{
|
|
||||||
name: 'lucide:git-branch',
|
|
||||||
component: createIconifyIcon('lucide:git-branch'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:git-commit',
|
|
||||||
component: createIconifyIcon('lucide:git-commit'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:git-merge',
|
|
||||||
component: createIconifyIcon('lucide:git-merge'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:git-pull-request',
|
|
||||||
component: createIconifyIcon('lucide:git-pull-request'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:github', component: createIconifyIcon('lucide:github') },
|
|
||||||
{ name: 'lucide:gitlab', component: createIconifyIcon('lucide:gitlab') },
|
|
||||||
{
|
|
||||||
name: 'lucide:bitbucket',
|
|
||||||
component: createIconifyIcon('lucide:bitbucket'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:code', component: createIconifyIcon('lucide:code') },
|
|
||||||
{ name: 'lucide:code-2', component: createIconifyIcon('lucide:code-2') },
|
|
||||||
{ name: 'lucide:terminal', component: createIconifyIcon('lucide:terminal') },
|
|
||||||
{ name: 'lucide:command', component: createIconifyIcon('lucide:command') },
|
|
||||||
{ name: 'lucide:hash', component: createIconifyIcon('lucide:hash') },
|
|
||||||
{ name: 'lucide:brackets', component: createIconifyIcon('lucide:brackets') },
|
|
||||||
{ name: 'lucide:braces', component: createIconifyIcon('lucide:braces') },
|
|
||||||
{
|
|
||||||
name: 'lucide:parentheses',
|
|
||||||
component: createIconifyIcon('lucide:parentheses'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:slash', component: createIconifyIcon('lucide:slash') },
|
|
||||||
{
|
|
||||||
name: 'lucide:backslash',
|
|
||||||
component: createIconifyIcon('lucide:backslash'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:at-sign', component: createIconifyIcon('lucide:at-sign') },
|
|
||||||
{ name: 'lucide:percent', component: createIconifyIcon('lucide:percent') },
|
|
||||||
{ name: 'lucide:asterisk', component: createIconifyIcon('lucide:asterisk') },
|
|
||||||
{
|
|
||||||
name: 'lucide:ampersand',
|
|
||||||
component: createIconifyIcon('lucide:ampersand'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:equal', component: createIconifyIcon('lucide:equal') },
|
|
||||||
{
|
|
||||||
name: 'lucide:not-equal',
|
|
||||||
component: createIconifyIcon('lucide:not-equal'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:greater-than',
|
|
||||||
component: createIconifyIcon('lucide:greater-than'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:less-than',
|
|
||||||
component: createIconifyIcon('lucide:less-than'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:greater-than-equal',
|
|
||||||
component: createIconifyIcon('lucide:greater-than-equal'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'lucide:less-than-equal',
|
|
||||||
component: createIconifyIcon('lucide:less-than-equal'),
|
|
||||||
},
|
|
||||||
{ name: 'lucide:minus', component: createIconifyIcon('lucide:minus') },
|
|
||||||
{ name: 'lucide:divide', component: createIconifyIcon('lucide:divide') },
|
|
||||||
{ name: 'lucide:multiply', component: createIconifyIcon('lucide:multiply') },
|
|
||||||
{ name: 'lucide:infinity', component: createIconifyIcon('lucide:infinity') },
|
|
||||||
{ name: 'lucide:pi', component: createIconifyIcon('lucide:pi') },
|
|
||||||
{ name: 'lucide:sigma', component: createIconifyIcon('lucide:sigma') },
|
|
||||||
{ name: 'lucide:alpha', component: createIconifyIcon('lucide:alpha') },
|
|
||||||
{ name: 'lucide:beta', component: createIconifyIcon('lucide:beta') },
|
|
||||||
{ name: 'lucide:gamma', component: createIconifyIcon('lucide:gamma') },
|
|
||||||
{ name: 'lucide:delta', component: createIconifyIcon('lucide:delta') },
|
|
||||||
{ name: 'lucide:epsilon', component: createIconifyIcon('lucide:epsilon') },
|
|
||||||
{ name: 'lucide:zeta', component: createIconifyIcon('lucide:zeta') },
|
|
||||||
{ name: 'lucide:eta', component: createIconifyIcon('lucide:eta') },
|
|
||||||
{ name: 'lucide:theta', component: createIconifyIcon('lucide:theta') },
|
|
||||||
{ name: 'lucide:iota', component: createIconifyIcon('lucide:iota') },
|
|
||||||
{ name: 'lucide:kappa', component: createIconifyIcon('lucide:kappa') },
|
|
||||||
{ name: 'lucide:lambda', component: createIconifyIcon('lucide:lambda') },
|
|
||||||
{ name: 'lucide:mu', component: createIconifyIcon('lucide:mu') },
|
|
||||||
{ name: 'lucide:nu', component: createIconifyIcon('lucide:nu') },
|
|
||||||
{ name: 'lucide:xi', component: createIconifyIcon('lucide:xi') },
|
|
||||||
{ name: 'lucide:omicron', component: createIconifyIcon('lucide:omicron') },
|
|
||||||
{ name: 'lucide:rho', component: createIconifyIcon('lucide:rho') },
|
|
||||||
{ name: 'lucide:tau', component: createIconifyIcon('lucide:tau') },
|
|
||||||
{ name: 'lucide:upsilon', component: createIconifyIcon('lucide:upsilon') },
|
|
||||||
{ name: 'lucide:phi', component: createIconifyIcon('lucide:phi') },
|
|
||||||
{ name: 'lucide:chi', component: createIconifyIcon('lucide:chi') },
|
|
||||||
{ name: 'lucide:psi', component: createIconifyIcon('lucide:psi') },
|
|
||||||
{ name: 'lucide:omega', component: createIconifyIcon('lucide:omega') },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// 过滤后的图标
|
const searchKeyword = ref('');
|
||||||
const filteredIcons = computed(() => {
|
const selectedCollection = ref('lucide');
|
||||||
let icons = iconList;
|
const selectedIcon = ref(props.modelValue || '');
|
||||||
|
const currentPage = ref(1);
|
||||||
|
const pageSize = 36;
|
||||||
|
|
||||||
if (searchKeyword.value) {
|
const browseFlat = ref<string[]>([]);
|
||||||
icons = icons.filter((icon) =>
|
const searchResultIcons = ref<string[]>([]);
|
||||||
icon.name.toLowerCase().includes(searchKeyword.value.toLowerCase()),
|
const loading = ref(false);
|
||||||
);
|
const loadError = ref('');
|
||||||
|
|
||||||
|
const collectionCache = new Map<string, string[]>();
|
||||||
|
|
||||||
|
function flattenCollectionBody(
|
||||||
|
prefix: string,
|
||||||
|
data: {
|
||||||
|
uncategorized?: string[];
|
||||||
|
categories?: Record<string, string[]>;
|
||||||
|
},
|
||||||
|
): string[] {
|
||||||
|
const set = new Set<string>();
|
||||||
|
for (const n of data.uncategorized || []) {
|
||||||
|
set.add(`${prefix}:${n}`);
|
||||||
}
|
}
|
||||||
|
if (data.categories) {
|
||||||
|
for (const arr of Object.values(data.categories)) {
|
||||||
|
for (const n of arr) {
|
||||||
|
set.add(`${prefix}:${n}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [...set].sort((a, b) => a.localeCompare(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchCollectionIcons(prefix: string): Promise<string[]> {
|
||||||
|
const hit = collectionCache.get(prefix);
|
||||||
|
if (hit) {
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
const res = await fetch(
|
||||||
|
`${ICONIFY}/collection?prefix=${encodeURIComponent(prefix)}`,
|
||||||
|
);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Iconify collection ${res.status}`);
|
||||||
|
}
|
||||||
|
const data = await res.json();
|
||||||
|
const list = flattenCollectionBody(prefix, data);
|
||||||
|
collectionCache.set(prefix, list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGlobalMode = computed(
|
||||||
|
() => selectedCollection.value === GLOBAL_PREFIX,
|
||||||
|
);
|
||||||
|
|
||||||
|
async function refreshIcons() {
|
||||||
|
const q = searchKeyword.value.trim();
|
||||||
|
const prefix = selectedCollection.value;
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = '';
|
||||||
|
try {
|
||||||
|
if (q) {
|
||||||
|
let url = `${ICONIFY}/search?query=${encodeURIComponent(q)}&limit=400`;
|
||||||
|
if (!isGlobalMode.value) {
|
||||||
|
url += `&prefix=${encodeURIComponent(prefix)}`;
|
||||||
|
}
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Iconify search ${res.status}`);
|
||||||
|
}
|
||||||
|
const data = await res.json();
|
||||||
|
searchResultIcons.value = Array.isArray(data.icons) ? data.icons : [];
|
||||||
|
} else {
|
||||||
|
searchResultIcons.value = [];
|
||||||
|
if (isGlobalMode.value) {
|
||||||
|
browseFlat.value = [];
|
||||||
|
} else {
|
||||||
|
browseFlat.value = await fetchCollectionIcons(prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: unknown) {
|
||||||
|
loadError.value = e instanceof Error ? e.message : '加载失败';
|
||||||
|
browseFlat.value = [];
|
||||||
|
searchResultIcons.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedRefresh = useDebounceFn(refreshIcons, 320);
|
||||||
|
|
||||||
|
const activeSource = computed(() => {
|
||||||
|
return searchKeyword.value.trim()
|
||||||
|
? searchResultIcons.value
|
||||||
|
: browseFlat.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayedIconNames = computed(() => {
|
||||||
|
const source = activeSource.value;
|
||||||
const start = (currentPage.value - 1) * pageSize;
|
const start = (currentPage.value - 1) * pageSize;
|
||||||
const end = start + pageSize;
|
return source.slice(start, start + pageSize);
|
||||||
|
|
||||||
return icons.slice(start, end);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 总页数
|
|
||||||
const totalPages = computed(() => {
|
const totalPages = computed(() => {
|
||||||
let total = iconList.length;
|
const n = activeSource.value.length;
|
||||||
|
return Math.max(1, Math.ceil(n / pageSize));
|
||||||
if (searchKeyword.value) {
|
|
||||||
total = iconList.filter((icon) =>
|
|
||||||
icon.name.toLowerCase().includes(searchKeyword.value.toLowerCase()),
|
|
||||||
).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Math.ceil(total / pageSize);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 可见页码
|
|
||||||
const visiblePages = computed(() => {
|
const visiblePages = computed(() => {
|
||||||
const pages = [];
|
const pages: number[] = [];
|
||||||
const total = totalPages.value;
|
const total = totalPages.value;
|
||||||
const current = currentPage.value;
|
const current = currentPage.value;
|
||||||
|
|
||||||
@@ -452,26 +161,23 @@ const visiblePages = computed(() => {
|
|||||||
for (let i = 1; i <= total; i++) {
|
for (let i = 1; i <= total; i++) {
|
||||||
pages.push(i);
|
pages.push(i);
|
||||||
}
|
}
|
||||||
|
} else if (current <= 4) {
|
||||||
|
for (let i = 1; i <= 5; i++) {
|
||||||
|
pages.push(i);
|
||||||
|
}
|
||||||
|
} else if (current >= total - 3) {
|
||||||
|
for (let i = total - 4; i <= total; i++) {
|
||||||
|
pages.push(i);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (current <= 4) {
|
for (let i = current - 2; i <= current + 2; i++) {
|
||||||
for (let i = 1; i <= 5; i++) {
|
pages.push(i);
|
||||||
pages.push(i);
|
|
||||||
}
|
|
||||||
} else if (current >= total - 3) {
|
|
||||||
for (let i = total - 4; i <= total; i++) {
|
|
||||||
pages.push(i);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = current - 2; i <= current + 2; i++) {
|
|
||||||
pages.push(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 是否显示省略号
|
|
||||||
const showEllipsis = computed(() => {
|
const showEllipsis = computed(() => {
|
||||||
return (
|
return (
|
||||||
totalPages.value > 7 &&
|
totalPages.value > 7 &&
|
||||||
@@ -480,70 +186,101 @@ const showEllipsis = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 选择图标
|
|
||||||
const selectIcon = (iconName: string) => {
|
const selectIcon = (iconName: string) => {
|
||||||
selectedIcon.value = iconName;
|
selectedIcon.value = iconName;
|
||||||
emit('update:modelValue', iconName);
|
emit('update:modelValue', iconName);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 搜索处理
|
|
||||||
const handleSearch = () => {
|
|
||||||
currentPage.value = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 跳转页面
|
|
||||||
const goToPage = (page: number) => {
|
const goToPage = (page: number) => {
|
||||||
if (page >= 1 && page <= totalPages.value) {
|
if (page >= 1 && page <= totalPages.value) {
|
||||||
currentPage.value = page;
|
currentPage.value = page;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 监听props变化
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
selectedIcon.value = newVal || '';
|
selectedIcon.value = newVal || '';
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watch(selectedCollection, () => {
|
||||||
|
currentPage.value = 1;
|
||||||
|
debouncedRefresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(searchKeyword, () => {
|
||||||
|
currentPage.value = 1;
|
||||||
|
debouncedRefresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void refreshIcons();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="icon-selector">
|
<div class="icon-selector">
|
||||||
<!-- 搜索框 -->
|
<div class="mb-2 flex flex-col gap-2 px-2">
|
||||||
<div class="mb-2 flex w-full">
|
<Select
|
||||||
|
v-model:value="selectedCollection"
|
||||||
|
:options="COLLECTION_OPTIONS"
|
||||||
|
class="w-full"
|
||||||
|
placeholder="图标集"
|
||||||
|
/>
|
||||||
<Input
|
<Input
|
||||||
v-model:value="searchKeyword"
|
v-model:value="searchKeyword"
|
||||||
placeholder="搜索图标..."
|
placeholder="搜索图标(留空则浏览当前图标集)"
|
||||||
class="mx-2"
|
allow-clear
|
||||||
@input="handleSearch"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 图标网格 -->
|
<Spin :spinning="loading">
|
||||||
<div
|
<div
|
||||||
class="grid max-h-[360px] w-full grid-cols-6 justify-items-center overflow-y-auto"
|
v-if="loadError"
|
||||||
>
|
class="text-destructive px-2 py-4 text-center text-sm"
|
||||||
<button
|
|
||||||
v-for="icon in filteredIcons"
|
|
||||||
:key="icon.name"
|
|
||||||
class="focus-visible:ring-ring hover:bg-accent hover:text-accent-foreground text-foreground/80 inline-flex h-8 w-8 items-center justify-center whitespace-nowrap rounded-full px-1 text-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
||||||
:class="{
|
|
||||||
'bg-primary text-primary-foreground': selectedIcon === icon.name,
|
|
||||||
}"
|
|
||||||
@click="selectIcon(icon.name)"
|
|
||||||
:title="icon.name"
|
|
||||||
>
|
>
|
||||||
<component :is="icon.component" />
|
{{ loadError }}
|
||||||
</button>
|
</div>
|
||||||
</div>
|
|
||||||
|
<div
|
||||||
|
v-else-if="
|
||||||
|
!searchKeyword.trim() &&
|
||||||
|
isGlobalMode &&
|
||||||
|
displayedIconNames.length === 0
|
||||||
|
"
|
||||||
|
class="text-muted-foreground px-2 py-8 text-center text-sm"
|
||||||
|
>
|
||||||
|
「全局搜索」模式下请在上框输入关键词;或切换到具体图标集以分页浏览。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="grid max-h-[360px] w-full grid-cols-6 justify-items-center overflow-y-auto"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="name in displayedIconNames"
|
||||||
|
:key="name"
|
||||||
|
type="button"
|
||||||
|
class="focus-visible:ring-ring hover:bg-accent hover:text-accent-foreground text-foreground/80 inline-flex h-8 w-8 items-center justify-center whitespace-nowrap rounded-full px-1 text-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:class="{
|
||||||
|
'bg-primary text-primary-foreground': selectedIcon === name,
|
||||||
|
}"
|
||||||
|
:title="name"
|
||||||
|
@click="selectIcon(name)"
|
||||||
|
>
|
||||||
|
<IconifyIcon :icon="name" class="size-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
|
||||||
<!-- 分页 -->
|
|
||||||
<div
|
<div
|
||||||
class="flex-center flex justify-end overflow-hidden border-t py-2 pr-3"
|
class="flex-center flex justify-end overflow-hidden border-t py-2 pr-3"
|
||||||
>
|
>
|
||||||
<nav size="small">
|
<nav size="small">
|
||||||
<div class="flex w-full items-center gap-1">
|
<div class="flex w-full items-center gap-1">
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
:disabled="currentPage === 1"
|
:disabled="currentPage === 1"
|
||||||
@click="goToPage(1)"
|
@click="goToPage(1)"
|
||||||
@@ -566,6 +303,7 @@ watch(
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
:disabled="currentPage === 1"
|
:disabled="currentPage === 1"
|
||||||
@click="goToPage(currentPage - 1)"
|
@click="goToPage(currentPage - 1)"
|
||||||
@@ -586,17 +324,18 @@ watch(
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<template v-for="page in visiblePages" :key="page">
|
||||||
v-for="page in visiblePages"
|
<button
|
||||||
:key="page"
|
type="button"
|
||||||
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-xs font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
:class="{
|
:class="{
|
||||||
'bg-primary text-primary-foreground shadow': page === currentPage,
|
'bg-primary text-primary-foreground': currentPage === page,
|
||||||
}"
|
}"
|
||||||
@click="goToPage(page)"
|
@click="goToPage(page)"
|
||||||
>
|
>
|
||||||
{{ page }}
|
{{ page }}
|
||||||
</button>
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="showEllipsis"
|
v-if="showEllipsis"
|
||||||
@@ -621,6 +360,7 @@ watch(
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
:disabled="currentPage === totalPages"
|
:disabled="currentPage === totalPages"
|
||||||
@click="goToPage(currentPage + 1)"
|
@click="goToPage(currentPage + 1)"
|
||||||
@@ -642,6 +382,7 @@ watch(
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
class="focus-visible:ring-ring border-input bg-background hover:bg-accent hover:text-accent-foreground inline-flex size-5 items-center justify-center whitespace-nowrap rounded-md border p-0 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
:disabled="currentPage === totalPages"
|
:disabled="currentPage === totalPages"
|
||||||
@click="goToPage(totalPages)"
|
@click="goToPage(totalPages)"
|
||||||
@@ -674,13 +415,6 @@ watch(
|
|||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(6, 1fr);
|
|
||||||
gap: 4px;
|
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-41
@@ -1,10 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { MenuVO } from '#/api/system/menu/types';
|
import type { MenuVO } from '#/api/system/menu/types';
|
||||||
|
|
||||||
import { h, ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { createIconifyIcon, IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
createMenuApi,
|
createMenuApi,
|
||||||
getAllMenusApi,
|
getAllMenusApi,
|
||||||
|
getMenuDetailApi,
|
||||||
updateMenuApi,
|
updateMenuApi,
|
||||||
} from '#/api/system/menu';
|
} from '#/api/system/menu';
|
||||||
import {
|
import {
|
||||||
@@ -30,9 +31,13 @@ import { getAllPermissionsApi } from '#/api/system/permission';
|
|||||||
|
|
||||||
import IconSelector from './IconSelector.vue';
|
import IconSelector from './IconSelector.vue';
|
||||||
|
|
||||||
|
type MenuFormSuccessPayload =
|
||||||
|
| { mode: 'update'; menu: MenuVO.MenuInfo }
|
||||||
|
| { mode: 'create' };
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
cancel: [];
|
cancel: [];
|
||||||
success: [];
|
success: [payload?: MenuFormSuccessPayload];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// 创建Vben Modal实例
|
// 创建Vben Modal实例
|
||||||
@@ -95,17 +100,9 @@ const permissionOptions = ref<{ label: string; value: number }[]>([]);
|
|||||||
const selectedPermissions = ref<number[]>([]);
|
const selectedPermissions = ref<number[]>([]);
|
||||||
const originalPermissions = ref<number[]>([]);
|
const originalPermissions = ref<number[]>([]);
|
||||||
|
|
||||||
// 创建图标组件
|
/** 无图标时占位,点击仍打开选择器 */
|
||||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||||
|
|
||||||
// 图标选择器内容
|
|
||||||
const iconSelectorContent = h(IconSelector, {
|
|
||||||
modelValue: formData.value.icon,
|
|
||||||
'onUpdate:modelValue': (value: string) => {
|
|
||||||
formData.value.icon = value;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 获取父菜单选项
|
// 获取父菜单选项
|
||||||
async function fetchParentMenuOptions() {
|
async function fetchParentMenuOptions() {
|
||||||
try {
|
try {
|
||||||
@@ -301,31 +298,36 @@ async function handleSubmit() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isEdit.value && currentRecord.value) {
|
if (isEdit.value && currentRecord.value) {
|
||||||
// 更新菜单
|
const menuId = currentRecord.value.id;
|
||||||
await updateMenuApi(currentRecord.value.id, submitData);
|
await updateMenuApi(menuId, submitData);
|
||||||
message.success('更新菜单成功');
|
message.success('更新菜单成功');
|
||||||
|
|
||||||
// 处理权限变更
|
// 处理权限变更
|
||||||
await handlePermissionChange();
|
await handlePermissionChange();
|
||||||
} else {
|
|
||||||
// 创建菜单
|
|
||||||
const newMenu = await createMenuApi(submitData);
|
|
||||||
message.success('创建菜单成功');
|
|
||||||
|
|
||||||
// 如果有选择的权限,为新菜单添加权限
|
// 详情含最新权限,供列表行就地合并,避免整表 reload 导致树折叠
|
||||||
if (selectedPermissions.value.length > 0 && newMenu?.id) {
|
const menu = await getMenuDetailApi(menuId);
|
||||||
for (const permissionId of selectedPermissions.value) {
|
emit('success', { mode: 'update', menu });
|
||||||
await addMenuPermissionApi({
|
close();
|
||||||
menuId: newMenu.id,
|
return;
|
||||||
permissionId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
message.success('权限分配成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建菜单(结构变化多,仍整表刷新)
|
||||||
|
const newMenu = await createMenuApi(submitData);
|
||||||
|
message.success('创建菜单成功');
|
||||||
|
|
||||||
|
if (selectedPermissions.value.length > 0 && newMenu?.id) {
|
||||||
|
for (const permissionId of selectedPermissions.value) {
|
||||||
|
await addMenuPermissionApi({
|
||||||
|
menuId: newMenu.id,
|
||||||
|
permissionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('权限分配成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('success', { mode: 'create' });
|
||||||
close();
|
close();
|
||||||
emit('success');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('提交菜单失败:', error);
|
console.error('提交菜单失败:', error);
|
||||||
message.error('提交菜单失败');
|
message.error('提交菜单失败');
|
||||||
@@ -419,23 +421,38 @@ defineExpose({
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="路由图标" name="icon">
|
<!-- 外层只负责标签;name 仅绑在触发 Input 上,避免 Popover 浮层内控件被同一 Form.Item 收集导致 FormItemContext 刷屏 -->
|
||||||
|
<Form.Item label="路由图标">
|
||||||
<Popover
|
<Popover
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
trigger="click"
|
trigger="click"
|
||||||
:content="iconSelectorContent"
|
|
||||||
overlay-class-name="icon-selector-popover"
|
overlay-class-name="icon-selector-popover"
|
||||||
>
|
>
|
||||||
<Input
|
<template #content>
|
||||||
v-model:value="formData.icon"
|
<IconSelector v-model="formData.icon" />
|
||||||
placeholder="请输入路由图标"
|
</template>
|
||||||
readonly
|
<!-- Popover Trigger 需要落在真实 DOM 上;no-style 的 Form.Item 常无包裹节点,会导致点击无响应 -->
|
||||||
style="cursor: pointer"
|
<div class="w-full">
|
||||||
>
|
<Form.Item name="icon" no-style>
|
||||||
<template #suffix>
|
<Input
|
||||||
<GridIcon class="h-4 w-4 cursor-pointer" />
|
v-model:value="formData.icon"
|
||||||
</template>
|
placeholder="点击选择或查看 Iconify 图标名"
|
||||||
</Input>
|
readonly
|
||||||
|
style="cursor: pointer"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<span class="inline-flex items-center pr-1">
|
||||||
|
<IconifyIcon
|
||||||
|
v-if="formData.icon"
|
||||||
|
:icon="formData.icon"
|
||||||
|
class="size-4 shrink-0 text-foreground"
|
||||||
|
/>
|
||||||
|
<GridIcon v-else class="size-4 shrink-0 opacity-40" />
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</Input>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
</Popover>
|
</Popover>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type { MenuVO } from '#/api/system/menu/types';
|
|||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { createIconifyIcon, IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
@@ -23,8 +23,6 @@ defineOptions({ name: 'MenuManagement' });
|
|||||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||||
const EditIcon = createIconifyIcon('lucide:edit');
|
const EditIcon = createIconifyIcon('lucide:edit');
|
||||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||||
const FolderIcon = createIconifyIcon('lucide:folder');
|
|
||||||
const FileIcon = createIconifyIcon('lucide:file');
|
|
||||||
const PlusCircleIcon = createIconifyIcon('lucide:plus-circle');
|
const PlusCircleIcon = createIconifyIcon('lucide:plus-circle');
|
||||||
const ExpandIcon = createIconifyIcon('lucide:chevrons-down');
|
const ExpandIcon = createIconifyIcon('lucide:chevrons-down');
|
||||||
const CollapseIcon = createIconifyIcon('lucide:chevrons-up');
|
const CollapseIcon = createIconifyIcon('lucide:chevrons-up');
|
||||||
@@ -33,6 +31,21 @@ const CollapseIcon = createIconifyIcon('lucide:chevrons-up');
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const menuFormModalRef = ref();
|
const menuFormModalRef = ref();
|
||||||
|
|
||||||
|
/** 与 proxy query 返回的 `items` 同一数组引用,用于就地更新行,避免依赖 getTableData 结构差异导致误判走 reload */
|
||||||
|
const lastMenuFlatItems = ref<MenuVO.MenuInfo[]>([]);
|
||||||
|
|
||||||
|
function normalizeMenuParentId(v: unknown): number | null {
|
||||||
|
if (v === null || v === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const n = Number(v);
|
||||||
|
return Number.isFinite(n) && n > 0 ? n : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameMenuParent(a: unknown, b: unknown) {
|
||||||
|
return normalizeMenuParentId(a) === normalizeMenuParentId(b);
|
||||||
|
}
|
||||||
|
|
||||||
// VbenVxeGrid 表格配置
|
// VbenVxeGrid 表格配置
|
||||||
const gridOptions: VxeGridProps<any> = {
|
const gridOptions: VxeGridProps<any> = {
|
||||||
columns: [
|
columns: [
|
||||||
@@ -56,6 +69,13 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
minWidth: 150,
|
minWidth: 150,
|
||||||
showOverflow: 'tooltip' as const,
|
showOverflow: 'tooltip' as const,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'icon',
|
||||||
|
title: '图标',
|
||||||
|
width: 72,
|
||||||
|
align: 'center' as const,
|
||||||
|
slots: { default: 'icon' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'path',
|
field: 'path',
|
||||||
title: '路由路径',
|
title: '路由路径',
|
||||||
@@ -98,19 +118,15 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
height: 'auto',
|
height: 'auto',
|
||||||
border: true,
|
border: true,
|
||||||
stripe: true,
|
stripe: true,
|
||||||
rowConfig: { isHover: true },
|
|
||||||
showOverflow: true,
|
|
||||||
size: 'small',
|
|
||||||
resizable: true, // 启用列宽调整
|
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
|
isHover: true,
|
||||||
drag: true, // 启用行拖拽
|
drag: true, // 启用行拖拽
|
||||||
},
|
},
|
||||||
|
showOverflow: true,
|
||||||
|
size: 'small',
|
||||||
rowDragConfig: {
|
rowDragConfig: {
|
||||||
isPeerDrag: true, // 启用同层级拖拽限制
|
isPeerDrag: true, // 启用同层级拖拽限制
|
||||||
},
|
},
|
||||||
columnConfig: {
|
|
||||||
// 列配置
|
|
||||||
},
|
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
custom: true,
|
custom: true,
|
||||||
refresh: true,
|
refresh: true,
|
||||||
@@ -130,6 +146,7 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const data = await getAllMenusApi();
|
const data = await getAllMenusApi();
|
||||||
|
lastMenuFlatItems.value = data;
|
||||||
// 直接返回扁平化数据,让 vxe-table 自动构建树形结构
|
// 直接返回扁平化数据,让 vxe-table 自动构建树形结构
|
||||||
return {
|
return {
|
||||||
items: data,
|
items: data,
|
||||||
@@ -138,6 +155,7 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取菜单列表失败:', error);
|
console.error('获取菜单列表失败:', error);
|
||||||
message.error('获取菜单列表失败');
|
message.error('获取菜单列表失败');
|
||||||
|
lastMenuFlatItems.value = [];
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [],
|
||||||
total: 0,
|
total: 0,
|
||||||
@@ -157,6 +175,39 @@ function refreshTable() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGridMenuFlatFallback(): MenuVO.MenuInfo[] {
|
||||||
|
const grid = gridApi?.grid as any;
|
||||||
|
if (!grid?.getTableData) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const td = grid.getTableData();
|
||||||
|
return (td?.fullData ?? td?.tableData ?? []) as MenuVO.MenuInfo[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 就地合并更新后的菜单行,保持树展开状态;父级变更时需整表重建树结构 */
|
||||||
|
function patchMenuRowFromServer(menu: MenuVO.MenuInfo) {
|
||||||
|
if (!menu?.id) {
|
||||||
|
refreshTable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const idNum = Number(menu.id);
|
||||||
|
const list =
|
||||||
|
lastMenuFlatItems.value.length > 0
|
||||||
|
? lastMenuFlatItems.value
|
||||||
|
: getGridMenuFlatFallback();
|
||||||
|
const row = list.find((r) => Number(r.id) === idNum);
|
||||||
|
if (!row) {
|
||||||
|
refreshTable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!sameMenuParent(row.parentId, menu.parentId)) {
|
||||||
|
refreshTable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object.assign(row, menu);
|
||||||
|
row.permissions = menu.permissions ? [...menu.permissions] : [];
|
||||||
|
}
|
||||||
|
|
||||||
// 处理添加菜单
|
// 处理添加菜单
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
menuFormModalRef.value?.open(false);
|
menuFormModalRef.value?.open(false);
|
||||||
@@ -184,8 +235,14 @@ async function handleDelete(record: MenuVO.MenuInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理模态框成功
|
// 处理模态框成功:更新菜单只合并当前行;新建仍整表刷新
|
||||||
function handleModalSuccess() {
|
function handleModalSuccess(
|
||||||
|
payload?: { mode: 'update'; menu: MenuVO.MenuInfo } | { mode: 'create' },
|
||||||
|
) {
|
||||||
|
if (payload?.mode === 'update' && payload.menu) {
|
||||||
|
patchMenuRowFromServer(payload.menu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
refreshTable();
|
refreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,26 +331,6 @@ function getMenuTypeColor(type: string) {
|
|||||||
return colorMap[type] || 'default';
|
return colorMap[type] || 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取菜单图标
|
|
||||||
function getMenuIcon(menu: MenuVO.MenuInfo) {
|
|
||||||
if (menu.icon) {
|
|
||||||
return createIconifyIcon(menu.icon);
|
|
||||||
}
|
|
||||||
// 根据菜单类型返回默认图标
|
|
||||||
switch (menu.type) {
|
|
||||||
case 'catalog': {
|
|
||||||
return FolderIcon;
|
|
||||||
}
|
|
||||||
case 'embedded':
|
|
||||||
case 'menu': {
|
|
||||||
return FileIcon;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return FileIcon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建 VbenVxeGrid 实例
|
// 创建 VbenVxeGrid 实例
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
gridOptions,
|
gridOptions,
|
||||||
@@ -355,9 +392,13 @@ onMounted(() => {
|
|||||||
<!-- 菜单名称列 - 移除自定义插槽以支持拖拽控件正常显示 -->
|
<!-- 菜单名称列 - 移除自定义插槽以支持拖拽控件正常显示 -->
|
||||||
|
|
||||||
<!-- 图标列 -->
|
<!-- 图标列 -->
|
||||||
<template #icon="{ row }: { row: any }">
|
<template #icon="{ row }: { row: MenuVO.MenuInfo }">
|
||||||
<div v-if="row.icon" class="flex items-center justify-center">
|
<div
|
||||||
<component :is="getMenuIcon(row)" class="h-4 w-4 text-blue-600" />
|
v-if="row.icon"
|
||||||
|
class="flex items-center justify-center"
|
||||||
|
:title="row.icon"
|
||||||
|
>
|
||||||
|
<IconifyIcon :icon="row.icon" class="size-4 text-blue-600" />
|
||||||
</div>
|
</div>
|
||||||
<span v-else class="text-gray-400">-</span>
|
<span v-else class="text-gray-400">-</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ function flattenTree(nodes: PermissionVO.PermissionInfoVO[], level = 0, result:
|
|||||||
const gridOptions: VxeGridProps<FlatNode> = {
|
const gridOptions: VxeGridProps<FlatNode> = {
|
||||||
border: true,
|
border: true,
|
||||||
stripe: true,
|
stripe: true,
|
||||||
rowConfig: { isHover: true },
|
|
||||||
showOverflow: true,
|
showOverflow: true,
|
||||||
size: 'small',
|
size: 'small',
|
||||||
expandAll: true,
|
expandAll: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user