2025-04-12 14:54:02 +08:00
|
|
|
<template>
|
|
|
|
<!--选择图标-->
|
|
|
|
<div class="form-item-box choose-icon-zj" :style="{ width: width }">
|
2025-07-16 18:33:13 +08:00
|
|
|
<el-autocomplete
|
|
|
|
v-bind="$attrs"
|
|
|
|
v-model="modelValue"
|
|
|
|
:fetch-suggestions="querySearch"
|
|
|
|
popper-class="choose-icon-zj-autocomplete"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
@change="onInput"
|
|
|
|
@select="handleSelect"
|
|
|
|
>
|
2025-04-12 14:54:02 +08:00
|
|
|
<template #prefix>
|
|
|
|
<SvgIcon :icon="modelValue"></SvgIcon>
|
|
|
|
</template>
|
|
|
|
<template #default="{ item }">
|
|
|
|
<SvgIcon :icon="item.link"></SvgIcon>
|
|
|
|
<div class="value">{{ item.value }}</div>
|
|
|
|
</template>
|
|
|
|
</el-autocomplete>
|
|
|
|
<!-- <el-icon class="errorIcon">
|
|
|
|
<circle-close-filled />
|
|
|
|
</el-icon>
|
|
|
|
<el-icon class="checkIcon">
|
|
|
|
<circle-check-filled />
|
|
|
|
</el-icon> -->
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import { COMPONENT_WIDTH } from "@/constant";
|
|
|
|
import { ref, defineProps, defineEmits, defineExpose, onMounted } from "vue";
|
|
|
|
const props = defineProps({
|
|
|
|
placeholder: {
|
|
|
|
default: "请输入图标名称",
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
modelValue: {
|
|
|
|
default: "",
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
default: COMPONENT_WIDTH,
|
|
|
|
type: String
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const links = ref([]);
|
|
|
|
|
|
|
|
const querySearch = (queryString, cb) => {
|
|
|
|
const results = queryString
|
|
|
|
? links.value.filter(createFilter(queryString))
|
|
|
|
: links.value;
|
|
|
|
cb(results);
|
|
|
|
};
|
|
|
|
const createFilter = (queryString) => {
|
|
|
|
return (restaurant) => {
|
|
|
|
return (
|
|
|
|
restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSelect = (item) => {
|
|
|
|
emits("update:modelValue", item.value);
|
|
|
|
};
|
|
|
|
|
2025-07-16 18:33:13 +08:00
|
|
|
const handleIconClick = (ev) => {};
|
2025-04-12 14:54:02 +08:00
|
|
|
|
|
|
|
const loadAll = () => {
|
|
|
|
const svgRequire = require.context("@/icons/svg", false, /\.svg$/);
|
|
|
|
const re = svgRequire.keys().map((svgIcon) => {
|
|
|
|
const iconName = svgIcon.split("/")[1];
|
|
|
|
const prefixIconName = iconName.split(".")[0];
|
|
|
|
return { value: prefixIconName, link: prefixIconName };
|
|
|
|
});
|
|
|
|
return re;
|
|
|
|
};
|
|
|
|
const iconListShow = ref(false);
|
|
|
|
const showIconList = () => {
|
|
|
|
iconListShow.value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
links.value = loadAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
const emits = defineEmits(["update:modelValue"]);
|
|
|
|
const onInput = (e) => {
|
|
|
|
emits("update:modelValue", e);
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|