perf(IconPicker): input trigger popover by click (#3278)
This commit is contained in:
parent
89323186b5
commit
2bbc2d2811
|
|
@ -1,10 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<a-input
|
<a-input
|
||||||
disabled
|
readonly
|
||||||
:style="{ width }"
|
:style="{ width }"
|
||||||
:placeholder="t('component.icon.placeholder')"
|
:placeholder="t('component.icon.placeholder')"
|
||||||
:class="prefixCls"
|
:class="prefixCls"
|
||||||
v-model:value="currentSelect"
|
v-model:value="currentSelect"
|
||||||
|
@click="triggerPopover"
|
||||||
>
|
>
|
||||||
<template #addonAfter>
|
<template #addonAfter>
|
||||||
<a-popover
|
<a-popover
|
||||||
|
|
@ -56,10 +57,19 @@
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<span class="cursor-pointer px-2 py-1 flex items-center" v-if="isSvgMode && currentSelect">
|
<div ref="trigger">
|
||||||
<SvgIcon :name="currentSelect" />
|
<span
|
||||||
</span>
|
class="cursor-pointer px-2 py-1 flex items-center"
|
||||||
<Icon :icon="currentSelect || 'ion:apps-outline'" class="cursor-pointer px-2 py-1" v-else />
|
v-if="isSvgMode && currentSelect"
|
||||||
|
>
|
||||||
|
<SvgIcon :name="currentSelect" />
|
||||||
|
</span>
|
||||||
|
<Icon
|
||||||
|
:icon="currentSelect || 'ion:apps-outline'"
|
||||||
|
class="cursor-pointer px-2 py-1"
|
||||||
|
v-else
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</a-popover>
|
</a-popover>
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
|
|
@ -78,6 +88,7 @@
|
||||||
import { useI18n } from '/@/hooks/web/useI18n';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
||||||
import svgIcons from 'virtual:svg-icons-names';
|
import svgIcons from 'virtual:svg-icons-names';
|
||||||
import { copyText } from '/@/utils/copyTextToClipboard';
|
import { copyText } from '/@/utils/copyTextToClipboard';
|
||||||
|
|
||||||
// 没有使用别名引入,是因为WebStorm当前版本还不能正确识别,会报unused警告
|
// 没有使用别名引入,是因为WebStorm当前版本还不能正确识别,会报unused警告
|
||||||
const AInput = Input;
|
const AInput = Input;
|
||||||
const APopover = Popover;
|
const APopover = Popover;
|
||||||
|
|
@ -85,15 +96,8 @@
|
||||||
const AEmpty = Empty;
|
const AEmpty = Empty;
|
||||||
|
|
||||||
function getIcons() {
|
function getIcons() {
|
||||||
const data = iconsData as any;
|
const prefix = iconsData.prefix;
|
||||||
const prefix: string = data?.prefix ?? '';
|
return iconsData.icons.map((icon) => `${prefix}:${icon}`);
|
||||||
let result: string[] = [];
|
|
||||||
if (prefix) {
|
|
||||||
result = (data?.icons ?? []).map((item) => `${prefix}:${item}`);
|
|
||||||
} else if (Array.isArray(iconsData)) {
|
|
||||||
result = iconsData as string[];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSvgIcons() {
|
function getSvgIcons() {
|
||||||
|
|
@ -116,6 +120,11 @@
|
||||||
mode: 'iconify',
|
mode: 'iconify',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Don't inherit FormItem disabled、placeholder...
|
||||||
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['change', 'update:value']);
|
const emit = defineEmits(['change', 'update:value']);
|
||||||
|
|
||||||
const isSvgMode = props.mode === 'svg';
|
const isSvgMode = props.mode === 'svg';
|
||||||
|
|
@ -124,6 +133,13 @@
|
||||||
const currentSelect = ref('');
|
const currentSelect = ref('');
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const currentList = ref(icons);
|
const currentList = ref(icons);
|
||||||
|
const trigger = ref<HTMLDivElement>();
|
||||||
|
|
||||||
|
const triggerPopover = () => {
|
||||||
|
if (trigger.value) {
|
||||||
|
trigger.value.click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { prefixCls } = useDesign('icon-picker');
|
const { prefixCls } = useDesign('icon-picker');
|
||||||
|
|
@ -143,10 +159,9 @@
|
||||||
() => currentSelect.value,
|
() => currentSelect.value,
|
||||||
(v) => {
|
(v) => {
|
||||||
emit('update:value', v);
|
emit('update:value', v);
|
||||||
return emit('change', v);
|
emit('change', v);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function handlePageChange(page: number) {
|
function handlePageChange(page: number) {
|
||||||
setCurrentPage(page);
|
setCurrentPage(page);
|
||||||
}
|
}
|
||||||
|
|
@ -177,6 +192,10 @@
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ant-input {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
&-popover {
|
&-popover {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue