forked from Tencent/tdesign-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
40 lines (37 loc) · 1.16 KB
/
util.ts
File metadata and controls
40 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable no-restricted-syntax */
import cloneDeep from 'lodash/cloneDeep';
import {
SelectOption, SelectValue, TdOptionProps, TdSelectProps,
} from './type';
export const getSingleContent = (value: TdSelectProps['value'], options: SelectOption[]): string => {
for (const option of options) {
if ((option as TdOptionProps).value === value) {
// 保底使用 value 作为显示
return option?.label || String((option as TdOptionProps).value);
}
}
return value !== undefined ? String(value) : undefined;
};
export const getMultipleContent = (value: SelectValue[], options: SelectOption[]) => {
const res: string[] = [];
for (const iterator of value) {
const resLabel = getSingleContent(iterator, options);
if (resLabel) {
res.push(resLabel);
}
}
return res;
};
export const getNewMultipleValue = (innerValue: SelectValue[], optionValue: SelectValue) => {
const value = cloneDeep(innerValue) as SelectValue[];
const valueIndex = value.indexOf(optionValue);
if (valueIndex < 0) {
value.push(optionValue);
} else {
value.splice(valueIndex, 1);
}
return {
value,
isCheck: valueIndex < 0,
};
};