(component): 更新日志

This commit is contained in:
就眠儀式 2022-09-27 11:40:29 +08:00
parent 0e8a649fa2
commit 568b8f6131
4 changed files with 193 additions and 172 deletions

View File

@ -1,3 +1,8 @@
@import "../checkbox/index.less";
@import "../input/index.less";
@import "../dropdown/index.less";
@import "../tagInput/index.less";
.layui-select { .layui-select {
width: 220px; width: 220px;

View File

@ -1,12 +1,12 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: "LaySelect", name: "LaySelect",
}; };
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import "./index.less"; import "./index.less";
import { import {
provide, provide,
computed, computed,
ref, ref,
@ -16,51 +16,59 @@ import {
VNode, VNode,
Component, Component,
watch, watch,
} from "vue"; } from "vue";
import LayInput from "../input/index.vue"; import LayInput from "../input/index.vue";
import LayTagInput from "../tagInput/index.vue"; import LayTagInput from "../tagInput/index.vue";
import LayDropdown from "../dropdown/index.vue"; import LayDropdown from "../dropdown/index.vue";
import LaySelectOption, { import LaySelectOption, {
LaySelectOptionProps, LaySelectOptionProps,
} from "../selectOption/index.vue"; } from "../selectOption/index.vue";
export interface LaySelectProps { export interface LaySelectProps {
name?: string; name?: string;
create?: boolean; create?: boolean;
disabled?: boolean; disabled?: boolean;
placeholder?: string; placeholder?: string;
showEmpty?: boolean;
emptyMessage?: string;
modelValue?: any; modelValue?: any;
multiple?: boolean; multiple?: boolean;
items?: LaySelectOptionProps[]; items?: LaySelectOptionProps[];
size?: "lg" | "md" | "sm" | "xs"; size?: "lg" | "md" | "sm" | "xs";
collapseTagsTooltip?: boolean;
minCollapsedNum?: number;
allowClear?: boolean; allowClear?: boolean;
} }
export interface SelectEmits { export interface SelectEmits {
(e: "update:modelValue", value: string): void; (e: "update:modelValue", value: string): void;
(e: "change", value: string): void; (e: "change", value: string): void;
} }
const props = withDefaults(defineProps<LaySelectProps>(), { const props = withDefaults(defineProps<LaySelectProps>(), {
modelValue: null, modelValue: null,
placeholder: "请选择", placeholder: "请选择",
showEmpty: true,
emptyMessage: "请选择",
collapseTagsTooltip: true,
minCollapsedNum: 3,
disabled: false, disabled: false,
multiple: false, multiple: false,
create: false, create: false,
size: "md", size: "md",
allowClear: false, allowClear: false,
}); });
const slots = useSlots(); const slots = useSlots();
const searchValue = ref(""); const searchValue = ref("");
const singleValue = ref(""); const singleValue = ref("");
const multipleValue = ref([]); const multipleValue = ref([]);
const openState: Ref<boolean> = ref(false); const openState: Ref<boolean> = ref(false);
const selectedItem: Ref<any> = ref([]); const selectedItem: Ref<any> = ref([]);
const options = ref<any>([]); const options = ref<any>([]);
const emits = defineEmits<SelectEmits>(); const emits = defineEmits<SelectEmits>();
onMounted(() => { onMounted(() => {
if (slots.default) { if (slots.default) {
getOption(slots.default()); getOption(slots.default());
} }
@ -71,9 +79,13 @@ onMounted(() => {
selectedValue, selectedValue,
() => { () => {
if (multiple.value) { if (multiple.value) {
multipleValue.value = selectedValue.value.map((value: any) =>{ multipleValue.value = selectedValue.value.map((value: any) => {
   return options.value.find((item: any) => item.value === value) return options.value.find((item: any) => {
}) item.disabled == "" || item.disabled == true ? item.closable = false : item.closable = true;
return item.value === value;
});
});
} else { } else {
singleValue.value = options.value.find((item: any) => { singleValue.value = options.value.find((item: any) => {
return item.value === selectedValue.value; return item.value === selectedValue.value;
@ -82,9 +94,9 @@ onMounted(() => {
}, },
{ immediate: true } { immediate: true }
); );
}); });
const getOption = function (nodes: VNode[]) { const getOption = function (nodes: VNode[]) {
nodes?.map((item: VNode) => { nodes?.map((item: VNode) => {
let component = item.type as Component; let component = item.type as Component;
if (component.name === LaySelectOption.name) { if (component.name === LaySelectOption.name) {
@ -93,9 +105,9 @@ const getOption = function (nodes: VNode[]) {
getOption(item.children as VNode[]); getOption(item.children as VNode[]);
} }
}); });
}; };
const selectedValue = computed({ const selectedValue = computed({
get() { get() {
return props.modelValue; return props.modelValue;
}, },
@ -103,20 +115,20 @@ const selectedValue = computed({
emits("update:modelValue", val); emits("update:modelValue", val);
emits("change", val); emits("change", val);
}, },
}); });
const multiple = computed(() => { const multiple = computed(() => {
return props.multiple; return props.multiple;
}); });
provide("openState", openState); provide("openState", openState);
provide("selectedItem", selectedItem); provide("selectedItem", selectedItem);
provide("selectedValue", selectedValue); provide("selectedValue", selectedValue);
provide("searchValue", searchValue); provide("searchValue", searchValue);
provide("multiple", multiple); provide("multiple", multiple);
</script> </script>
<template> <template>
<div class="layui-select"> <div class="layui-select">
<lay-dropdown <lay-dropdown
:disabled="disabled" :disabled="disabled"
@ -128,6 +140,8 @@ provide("multiple", multiple);
v-if="multiple" v-if="multiple"
v-model="multipleValue" v-model="multipleValue"
:allow-clear="allowClear" :allow-clear="allowClear"
:collapseTagsTooltip="collapseTagsTooltip"
:minCollapsedNum="minCollapsedNum"
:disabledInput="true" :disabledInput="true"
> >
<template #suffix> <template #suffix>
@ -161,6 +175,7 @@ provide("multiple", multiple);
size="sm" size="sm"
></lay-input> ></lay-input>
</div> </div>
<lay-select-option v-if="showEmpty && !multiple" :label="emptyMessage" value=""></lay-select-option>
<template v-if="items"> <template v-if="items">
<lay-select-option <lay-select-option
v-for="(item, index) in items" v-for="(item, index) in items"
@ -173,4 +188,4 @@ provide("multiple", multiple);
</template> </template>
</lay-dropdown> </lay-dropdown>
</div> </div>
</template> </template>

View File

@ -14,7 +14,6 @@ import {
Ref, Ref,
onMounted, onMounted,
} from "vue"; } from "vue";
import { arrayExpression } from "@babel/types";
export interface LaySelectOptionProps { export interface LaySelectOptionProps {
label: string; label: string;

View File

@ -19,6 +19,8 @@
<li>[新增] tag-input 标签输入框组件, 用于录入事物的属性与纬度。</li> <li>[新增] tag-input 标签输入框组件, 用于录入事物的属性与纬度。</li>
<li>[新增] table 组件 header 插槽, 用于在工具栏与表格之间插入元素。</li> <li>[新增] table 组件 header 插槽, 用于在工具栏与表格之间插入元素。</li>
<li>[新增] tabitem 组件 icon 属性, 提供 title 属性前置 icon 设置。</li> <li>[新增] tabitem 组件 icon 属性, 提供 title 属性前置 icon 设置。</li>
<li>[新增] select 组件 collapseTagsTooltip 属性, 多选模式下是否悬浮显示折叠的选中项。</li>
<li>[新增] select 组件 minCollapsedNum 属性, 多选模式选中项超过多少时折叠。</li>
<li>[修复] tolltip 组件 content 变化时, 位置无法自动计算调整的问题。</li> <li>[修复] tolltip 组件 content 变化时, 位置无法自动计算调整的问题。</li>
<li>[修复] breadcrumb-item 组件无法正确传递 attrs, 导致 @click 等自定义事件失效。</li> <li>[修复] breadcrumb-item 组件无法正确传递 attrs, 导致 @click 等自定义事件失效。</li>
<li>[修复] layout 组件仅引入了 footer 作为内容元素时, layui-layout-vertical 样式不生效, 导致布局错误。</li> <li>[修复] layout 组件仅引入了 footer 作为内容元素时, layui-layout-vertical 样式不生效, 导致布局错误。</li>