mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-30 09:24:46 +08:00
feat: icon-select 增强 (#253)
This commit is contained in:
parent
d14b0358ee
commit
e0d6002aa8
@ -1,10 +1,19 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { cloneDeep } from "lodash-unified";
|
import { cloneDeep } from "lodash-unified";
|
||||||
import { ref, computed, CSSProperties } from "vue";
|
import { ref, computed, CSSProperties, toRef, watch } from "vue";
|
||||||
import { IconJson } from "/@/components/ReIcon/data";
|
import { IconJson } from "/@/components/ReIcon/data";
|
||||||
type ParameterCSSProperties = (item?: string) => CSSProperties | undefined;
|
type ParameterCSSProperties = (item?: string) => CSSProperties | undefined;
|
||||||
|
|
||||||
let inputValue = ref("ep:add-location");
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
require: false,
|
||||||
|
type: String
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const emit = defineEmits<{ (e: "update:modelValue", v: string) }>();
|
||||||
|
|
||||||
|
let visible = ref(false);
|
||||||
|
let inputValue = toRef(props, "modelValue");
|
||||||
let iconList = ref(IconJson);
|
let iconList = ref(IconJson);
|
||||||
let icon = ref("add-location");
|
let icon = ref("add-location");
|
||||||
let currentActiveType = ref("ep:");
|
let currentActiveType = ref("ep:");
|
||||||
@ -35,15 +44,15 @@ let tabsList = [
|
|||||||
let pageList = computed(() => {
|
let pageList = computed(() => {
|
||||||
if (currentPage.value === 1) {
|
if (currentPage.value === 1) {
|
||||||
return copyIconList[currentActiveType.value]
|
return copyIconList[currentActiveType.value]
|
||||||
.slice(currentPage.value - 1, pageSize.value)
|
.filter(v => v.includes(filterValue.value))
|
||||||
.filter(v => v.includes(filterValue.value));
|
.slice(currentPage.value - 1, pageSize.value);
|
||||||
} else {
|
} else {
|
||||||
return copyIconList[currentActiveType.value]
|
return copyIconList[currentActiveType.value]
|
||||||
|
.filter(v => v.includes(filterValue.value))
|
||||||
.slice(
|
.slice(
|
||||||
pageSize.value * (currentPage.value - 1),
|
pageSize.value * (currentPage.value - 1),
|
||||||
pageSize.value * (currentPage.value - 1) + pageSize.value
|
pageSize.value * (currentPage.value - 1) + pageSize.value
|
||||||
)
|
);
|
||||||
.filter(v => v.includes(filterValue.value));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -60,29 +69,66 @@ const iconItemStyle = computed((): ParameterCSSProperties => {
|
|||||||
function handleClick({ props }) {
|
function handleClick({ props }) {
|
||||||
currentPage.value = 1;
|
currentPage.value = 1;
|
||||||
currentActiveType.value = props.name;
|
currentActiveType.value = props.name;
|
||||||
inputValue.value =
|
emit(
|
||||||
currentActiveType.value + iconList.value[currentActiveType.value][0];
|
"update:modelValue",
|
||||||
|
currentActiveType.value + iconList.value[currentActiveType.value][0]
|
||||||
|
);
|
||||||
icon.value = iconList.value[currentActiveType.value][0];
|
icon.value = iconList.value[currentActiveType.value][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChangeIcon(item) {
|
function onChangeIcon(item) {
|
||||||
inputValue.value = currentActiveType.value + item;
|
|
||||||
icon.value = item;
|
icon.value = item;
|
||||||
|
emit("update:modelValue", currentActiveType.value + item);
|
||||||
|
visible.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCurrentChange(page) {
|
function onCurrentChange(page) {
|
||||||
currentPage.value = page;
|
currentPage.value = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => {
|
||||||
|
return props.modelValue;
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
if (props.modelValue) {
|
||||||
|
currentActiveType.value = props.modelValue.substring(
|
||||||
|
0,
|
||||||
|
props.modelValue.indexOf(":") + 1
|
||||||
|
);
|
||||||
|
icon.value = props.modelValue.substring(
|
||||||
|
props.modelValue.indexOf(":") + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => {
|
||||||
|
return filterValue.value;
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
currentPage.value = 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="selector w-350px">
|
<div class="selector w-350px">
|
||||||
<el-input v-model="inputValue" disabled>
|
<el-input v-model="inputValue" disabled>
|
||||||
<template #append>
|
<template #append>
|
||||||
<el-popover :width="350" trigger="click" popper-class="pure-popper">
|
<el-popover
|
||||||
|
:width="350"
|
||||||
|
trigger="click"
|
||||||
|
popper-class="pure-popper"
|
||||||
|
:popper-options="{
|
||||||
|
placement: 'auto'
|
||||||
|
}"
|
||||||
|
:visible="visible"
|
||||||
|
>
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<div
|
<div
|
||||||
class="w-40px h-32px cursor-pointer flex justify-center items-center"
|
class="w-40px h-32px cursor-pointer flex justify-center items-center"
|
||||||
|
@click="visible = !visible"
|
||||||
>
|
>
|
||||||
<IconifyIconOnline :icon="icon" :type="currentActiveType" />
|
<IconifyIconOnline :icon="icon" :type="currentActiveType" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ref } from "vue";
|
||||||
import { IconSelect } from "/@/components/ReIcon";
|
import { IconSelect } from "/@/components/ReIcon";
|
||||||
|
let icon = ref("ep:add-location");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -9,6 +11,6 @@ import { IconSelect } from "/@/components/ReIcon";
|
|||||||
<span class="font-medium">图标选择器</span>
|
<span class="font-medium">图标选择器</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<IconSelect />
|
<IconSelect v-model="icon" />
|
||||||
</el-card>
|
</el-card>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user