first commit
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,106 @@
|
||||
export default {
|
||||
// 数据列表
|
||||
options: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
// #ifndef VUE3
|
||||
// v-model值 vue2
|
||||
value: {
|
||||
type: [String, Number, Array],
|
||||
default: "",
|
||||
},
|
||||
// #endif
|
||||
// #ifdef VUE3
|
||||
// v-model值 (Vue3)
|
||||
modelValue: {
|
||||
type: [String, Number, Array],
|
||||
default: "",
|
||||
},
|
||||
// #endif
|
||||
// 是否可过滤
|
||||
filterable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 占位符
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: "请选择"
|
||||
},
|
||||
// 过滤输入框占位符;为空时沿用 placeholder
|
||||
filterPlaceholder: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
// 是否可清空
|
||||
clearable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 是否多选
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否禁用
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否显示选中值 up, down
|
||||
direction: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
// 显示文本的键名
|
||||
labelKey: {
|
||||
type: String,
|
||||
default: "label"
|
||||
},
|
||||
// 值的键名
|
||||
valueKey: {
|
||||
type: String,
|
||||
default: "value"
|
||||
},
|
||||
// 空数据文本
|
||||
emptyText: {
|
||||
type: String,
|
||||
default: "No Data"
|
||||
},
|
||||
// change事件返回类型
|
||||
changeType: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
// 是否开启虚拟列表
|
||||
virtualList: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 边框样式
|
||||
border: {
|
||||
type: String,
|
||||
default: "1px solid #e5e5e5"
|
||||
},
|
||||
// 高度
|
||||
height: {
|
||||
type: String,
|
||||
default: "35px"
|
||||
},
|
||||
// 是否显示省略号
|
||||
showEllipsis: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 是否折叠选项
|
||||
collapseTags: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 折叠数量
|
||||
collapseTagsNum: {
|
||||
type: Number,
|
||||
default: 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 防抖函数
|
||||
* @param {Function} fn 需要防抖的函数
|
||||
* @param {Number} delay 延迟时间
|
||||
*/
|
||||
export const debounce = (fn, delay) => {
|
||||
let timer = null;
|
||||
return function(...args) {
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => fn.apply(this, args), delay);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 节流函数
|
||||
* @param {Function} fn 需要节流的函数
|
||||
* @param {Number} wait 等待时间
|
||||
*/
|
||||
export const throttle = (fn, wait) => {
|
||||
let timer = null;
|
||||
return function(...args) {
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(this, args);
|
||||
timer = null;
|
||||
}, wait);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 数据处理函数
|
||||
* @param {Array} options 数据源
|
||||
* @param {String} valueKey 值键名
|
||||
* @param {String} labelKey 标签键名
|
||||
*/
|
||||
export const formatOptions = (options, valueKey, labelKey) => {
|
||||
return options.map(item => ({
|
||||
...item,
|
||||
value: item[valueKey],
|
||||
label: item[labelKey]
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* 搜索过滤
|
||||
* @param {Array} data 数据源
|
||||
* @param {String} searchText 搜索文本
|
||||
* @param {String} labelKey 标签键名
|
||||
*/
|
||||
export const filterData = (data, searchText, labelKey) => {
|
||||
const loweredText = searchText.toLowerCase();
|
||||
return data.filter(item => {
|
||||
const label = String(item[labelKey]).toLowerCase();
|
||||
return label.includes(loweredText);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 计算虚拟列表可视区域数据
|
||||
* @param {Array} data 数据源
|
||||
* @param {Number} start 起始索引
|
||||
* @param {Number} pageSize 每页数量
|
||||
*/
|
||||
export const getVisibleData = (data, start, pageSize) => {
|
||||
const end = Math.min(start + pageSize, data.length); // 限制结束索引不超过数据长度
|
||||
return data.slice(start, end);
|
||||
};
|
||||
Reference in New Issue
Block a user