chore: initialize qiming workspace repository
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// @ts-nocheck
|
||||
import type { ComputedRef } from './type';
|
||||
import type { CheckboxStatus } from '../l-checkbox/type';
|
||||
// #ifndef UNI-APP-X
|
||||
import { computed } from '@/uni_modules/lime-shared/vue';
|
||||
// #endif
|
||||
|
||||
function intersection<T>(...arrays : T[][]): T[] {
|
||||
// 创建一个空数组来存储相交元素
|
||||
const result : T[] = [];
|
||||
|
||||
for (let i = 0; i < arrays[0].length; i++) {
|
||||
const item = arrays[0][i]
|
||||
// 检查该元素是否存在于所有其他数组中
|
||||
let isCommon = true;
|
||||
for (let j = 1; j < arrays.length; j++) {
|
||||
if (!arrays[j].includes(item)) {
|
||||
isCommon = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果该元素存在于所有数组中,并且尚未添加到结果数组中,则将其添加到结果数组中
|
||||
if (isCommon && !result.includes(item)) {
|
||||
result.push(item);
|
||||
}
|
||||
}
|
||||
// 返回包含相交元素的结果数组
|
||||
return result;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export function setCheckAllStatus(
|
||||
children: LCheckboxComponentPublicInstance[],
|
||||
innerValue: ComputedRef<any[]>,
|
||||
checkedSet: ComputedRef<Set<any>>
|
||||
): ComputedRef<CheckboxStatus> {
|
||||
|
||||
const intersectionLen = computed(()=>{
|
||||
const values:any[] = []
|
||||
children.forEach(item => {
|
||||
const value = item.value ?? item.name;
|
||||
if(value == null) return
|
||||
values.push(value)
|
||||
})
|
||||
if (Array.isArray(innerValue.value)) {
|
||||
return intersection(innerValue.value, values).length;
|
||||
}
|
||||
return 0
|
||||
})
|
||||
const isAllChecked = computed((): boolean=>{
|
||||
if (checkedSet.value.size != children.length - 1) {
|
||||
return false;
|
||||
}
|
||||
return intersectionLen.value == children.length - 1;
|
||||
})
|
||||
const isIndeterminate = computed((): boolean=>{
|
||||
return !isAllChecked.value && intersectionLen.value < children.length && intersectionLen.value > 0;
|
||||
})
|
||||
return computed(():CheckboxStatus => {
|
||||
if (isAllChecked.value) return 'checked';
|
||||
if (isIndeterminate.value) return 'indeterminate';
|
||||
return 'uncheck';
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user