jiaqingjiayi-xiaochengxu/甲情_甲意/miniprogram/node_modules/antd-mini/es/Picker/utils.js

100 lines
3.6 KiB
JavaScript
Raw Normal View History

2024-11-10 07:01:22 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMatchedItemByIndex = exports.getMatchedItemByValue = exports.getStrictMatchedItemByValue = void 0;
function getColumnValue(columnItem) {
if (typeof columnItem === 'object')
return columnItem.value;
return columnItem;
}
function getStrictMatchedItemByValue(columns, value, single) {
if (single) {
value = [value];
}
var matchedValues = [];
var matchedColumn = [];
var index = null;
var _loop_1 = function (i) {
var column = columns[i];
var compareValue = value[i];
index = column.findIndex(function (c) {
var columnValue = getColumnValue(c);
return columnValue === compareValue;
});
matchedColumn[i] = column[index];
matchedValues[i] = getColumnValue(column[index]);
};
for (var i = 0; i < columns.length; i++) {
_loop_1(i);
}
return {
matchedColumn: single ? matchedColumn === null || matchedColumn === void 0 ? void 0 : matchedColumn[0] : matchedColumn,
matchedValues: single ? matchedValues === null || matchedValues === void 0 ? void 0 : matchedValues[0] : matchedValues
};
}
exports.getStrictMatchedItemByValue = getStrictMatchedItemByValue;
// 如果找不到value对应的item项目返回第一项
function getMatchedItemByValue(columns, value, single) {
if (single) {
value = [value];
}
var matchedValues = [];
var matchedColumn = [];
var index = null;
var _loop_2 = function (i) {
var column = columns[i];
var compareValue = value[i];
if (compareValue === undefined || compareValue === null) {
index = 0;
}
else {
index = column.findIndex(function (c) {
var columnValue = getColumnValue(c);
return columnValue === compareValue;
});
if (index === -1) {
index = 0;
} // 没有找到, 默认选择第一个
}
matchedColumn[i] = column[index];
matchedValues[i] = getColumnValue(column[index]);
};
for (var i = 0; i < columns.length; i++) {
_loop_2(i);
}
return {
matchedColumn: single ? matchedColumn[0] : matchedColumn,
matchedValues: single ? matchedValues[0] : matchedValues
};
}
exports.getMatchedItemByValue = getMatchedItemByValue;
function getMatchedItemByIndex(columns, selectedIndex, single) {
var _a;
var matchedValues = [];
var matchedColumn = [];
var index = null;
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
var compareValue = selectedIndex[i];
index = null;
if (compareValue === undefined || compareValue === null) {
index = 0;
}
else {
index = compareValue;
// 当column变化时 picker-view onChange 里抛出来的selectedIndex有可能不正确
if (((_a = columns === null || columns === void 0 ? void 0 : columns[i]) === null || _a === void 0 ? void 0 : _a[compareValue]) === undefined) {
index = 0;
}
if (index === -1) {
index = 0;
} // 没有找到, 默认选择第一个
}
matchedColumn[i] = column[index];
matchedValues[i] = getColumnValue(column[index]);
}
return {
matchedColumn: single ? matchedColumn[0] : matchedColumn,
matchedValues: single ? matchedValues[0] : matchedValues
};
}
exports.getMatchedItemByIndex = getMatchedItemByIndex;