@beisen-platform/area-selector
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -45,2 +45,3 @@ import "core-js/modules/es6.function.name"; | ||
id: _id, | ||
isForeign: _this.props.isForeign, | ||
province: _this.props.province, | ||
@@ -73,3 +74,3 @@ area: _this.props.area, | ||
_this.props.goNextLevel(_this.props.name, parseInt(_this.props.id), _this.props.pIndex); | ||
_this.props.goNextLevel(_this.props.name, parseInt(_this.props.id), _this.props.pIndex, _this.props.isChecked); | ||
@@ -106,5 +107,6 @@ if (!_this.props.hiddenTip) { | ||
hiddenTip = _this$props2.hiddenTip, | ||
sideTip = _this$props2.sideTip; | ||
sideTip = _this$props2.sideTip, | ||
disabled = _this$props2.disabled; | ||
var _name = name.length > 6 ? decode(name).substr(0, 5) + '...' : decode(name); | ||
var _name = decode(name); | ||
@@ -121,2 +123,3 @@ return React.createElement("span", { | ||
defaultChecked: isChecked, | ||
disabled: disabled, | ||
onChange: this._onChange | ||
@@ -154,3 +157,3 @@ }), React.createElement("label", { | ||
}, React.createElement("span", { | ||
className: "area-select__text " + (isMore ? '' : 'area-select__text_is-nomore') | ||
className: "area-select__text" + (isMore ? '' : ' area-select__text_is-nomore') | ||
}, _name)), React.createElement("i", { | ||
@@ -157,0 +160,0 @@ className: "icon-arrow-right" |
259
lib/index.js
@@ -0,7 +1,12 @@ | ||
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import "core-js/modules/es6.object.assign"; | ||
import "core-js/modules/es7.array.includes"; | ||
import "core-js/modules/es6.string.includes"; | ||
import "core-js/modules/es6.array.find-index"; | ||
import "core-js/modules/es6.regexp.split"; | ||
import "core-js/modules/es6.function.name"; | ||
import "core-js/modules/es6.regexp.to-string"; | ||
import "core-js/modules/es7.symbol.async-iterator"; | ||
import "core-js/modules/es6.symbol"; | ||
import "core-js/modules/web.dom.iterable"; | ||
import "core-js/modules/es6.array.find-index"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
@@ -12,3 +17,2 @@ import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; | ||
import React, { Component } from 'react'; | ||
@@ -20,4 +24,13 @@ import BreadCrumb from './bread.js'; | ||
import TabComponent from '@beisen-platform/tab-component'; | ||
import './index.css'; // 模拟空回调 | ||
import './index.css'; | ||
var defaultTranslation = { | ||
nationWide: '全国省市', | ||
foreignWide: '国外地区', | ||
confirmText: '确定', | ||
cancelText: '取消', | ||
clearSelected: '清空已选', | ||
AreaSelected: '已选地区' // 模拟空回调 | ||
}; | ||
function emptyFunc() {} | ||
@@ -37,6 +50,68 @@ | ||
_this.sortData = function (data) { | ||
_this.handleDefaultResults = function (data) { | ||
if (_this.props.isSingleSelect) { | ||
return data; | ||
} | ||
/* | ||
由于外部传入的已选数据仅包含id和name,在多级交互时会出现问题 | ||
所以在此处找到全数据中每一个已选数据并抛出 | ||
*/ | ||
try { | ||
var arr = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = data[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var i = _step.value; | ||
var assignData = deepClone(_this.chinaData); | ||
var subIndex = 2; | ||
var allLevelName = ''; | ||
for (var m = 0; m < assignData.length; m++) { | ||
var item = assignData[m]; | ||
var subId = i.id.toString().substring(0, subIndex); | ||
if (item.id == i.id) { | ||
if (allLevelName.length > 0) item.name = allLevelName + item.name; | ||
arr.push(item); | ||
} else if (item.id.toString().length > 1 && item.id.toString().indexOf(subId) == 0 && item.childList) { | ||
if (_this.props.allLevelDisplay) allLevelName += item.name; //全路径显示名称 | ||
assignData = item.childList; //循环遍历子集 | ||
m = -1; //当进入子集时会执行m++,如果是0的话会变成1 | ||
subIndex += 2; //每进入下一级,id长度会加2,所以此处subString的index也需加2 | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return arr; | ||
} catch (e) { | ||
console.error("地区已选数据处理有误", e); | ||
} | ||
}; | ||
_this.sortData = function (data, isForeign) { | ||
var _newData = []; | ||
var _sortfunc = function _sortfunc(data, pIndex) { | ||
var _sortfunc = function _sortfunc(data, pIndex, isForeign) { | ||
return data && data.map(function (item, index) { | ||
@@ -50,6 +125,7 @@ var _pIndex = pIndex || ''; | ||
index: index, | ||
isForeign: isForeign, | ||
pIndex: _pIndex + index, | ||
isMore: item.length > 2 ? true : false | ||
}; | ||
_data.childList = item[2] && _sortfunc(item[2], _data.pIndex + '/') || null; | ||
_data.childList = item[2] && _sortfunc(item[2], _data.pIndex + '/', isForeign) || null; | ||
return _data; | ||
@@ -59,3 +135,3 @@ }); | ||
_newData = _sortfunc(data); | ||
_newData = _sortfunc(data, null, isForeign); | ||
return _newData; | ||
@@ -70,2 +146,39 @@ }; | ||
} else { | ||
//合并数据,清空包含的子集数据,仅显示父级数据 | ||
if (_this.props.allowContainsChildren) { | ||
var newData = []; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = _resultsData[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var i = _step2.value; | ||
if (i.isForeign == data.isForeign) { | ||
if (i.pIndex && i.pIndex.indexOf(data.pIndex) != 0) { | ||
newData.push(i); | ||
} | ||
} else { | ||
newData.push(i); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
_resultsData = newData; // _resultsData = _resultsData.filter(item => item.pIndex && item.pIndex.indexOf(data.pIndex)!=0) | ||
} | ||
_resultsData.push(data); | ||
@@ -80,2 +193,3 @@ } | ||
_this.clearResultsData = function (index) { | ||
var breadlist = _this.state.breadlist; | ||
var _resultsData = _this.state.resultsData; | ||
@@ -85,3 +199,13 @@ | ||
_resultsData.length = 0; | ||
breadlist.map(function (item) { | ||
return item.isChecked = false; | ||
}); | ||
} else { | ||
//重置导航状态 | ||
if (_this.props.allowContainsChildren && !_this.props.isSingleSelect) { | ||
breadlist.map(function (item) { | ||
if (item.index.toString().split("/")[0] == _resultsData[index].pIndex.split("/")[0]) item.isChecked = false; | ||
}); | ||
} | ||
_resultsData.splice(index, 1); | ||
@@ -91,3 +215,4 @@ } | ||
_this.setState({ | ||
resultsData: _resultsData | ||
resultsData: _resultsData, | ||
breadlist: breadlist | ||
}); | ||
@@ -136,18 +261,18 @@ }; | ||
_this.getCurrentData = function () { | ||
var _areaData = _this.state.currentAreaTab === 0 ? _this.chinaData : _this.foreignData; | ||
var _lastBread = _this.state.breadlist[_this.state.breadlist.length - 1]; | ||
var _currentData = []; | ||
var self = _assertThisInitialized(_assertThisInitialized(_this)); | ||
switch (_this.state.breadlist.length) { | ||
case 1: | ||
_currentData = _this.chinaData; | ||
_currentData = _areaData; | ||
break; | ||
case 2: | ||
_currentData = _this.chinaData[parseInt(_lastBread['index'])]['childList']; | ||
_currentData = _areaData[parseInt(_lastBread['index'])]['childList']; | ||
if (_this.props.allLevelDisplay) { | ||
_currentData.forEach(function (item) { | ||
item.province = self.chinaData[parseInt(_lastBread['index'])].name; | ||
item.province = _areaData[parseInt(_lastBread['index'])].name; | ||
}); | ||
@@ -161,8 +286,8 @@ } | ||
_currentData = _this.chinaData[parseInt(_pIndexArr[0])]['childList'][parseInt(_pIndexArr[1])]['childList']; | ||
_currentData = _areaData[parseInt(_pIndexArr[0])]['childList'][parseInt(_pIndexArr[1])]['childList']; | ||
if (_this.props.allLevelDisplay) { | ||
_currentData.forEach(function (item) { | ||
item.province = self.chinaData[parseInt(_pIndexArr[0])].name; | ||
item.area = self.chinaData[parseInt(_pIndexArr[0])]['childList'][parseInt(_pIndexArr[1])].name; | ||
item.province = _areaData[parseInt(_pIndexArr[0])].name; | ||
item.area = _areaData[parseInt(_pIndexArr[0])]['childList'][parseInt(_pIndexArr[1])].name; | ||
}); | ||
@@ -175,6 +300,6 @@ } | ||
_this.setItemActive(_currentData); | ||
_this.setItemActive(_currentData, _lastBread); | ||
}; | ||
_this.setItemActive = function (currentData) { | ||
_this.setItemActive = function (currentData, _lastBread) { | ||
var _resultdIdArr = []; | ||
@@ -188,2 +313,3 @@ | ||
item.isChecked = false; | ||
if (_this.props.allowContainsChildren && !_this.props.isSingleSelect) item.disabled = false; | ||
@@ -193,3 +319,8 @@ if (_resultdIdArr.length && _this.contains(_resultdIdArr, item.id)) { | ||
} | ||
}); | ||
}); // if(_lastBread.isChecked){ | ||
// currentData.map(item => { | ||
// item.isChecked = true | ||
// }) | ||
// } | ||
_this.currentData = currentData; | ||
@@ -210,3 +341,3 @@ }; | ||
_this.goNextLevel = function (name, id, pIndex) { | ||
_this.goNextLevel = function (name, id, pIndex, isChecked) { | ||
var _breadData = _this.state.breadlist; | ||
@@ -216,3 +347,5 @@ | ||
name: name, | ||
index: pIndex | ||
index: pIndex, | ||
isChecked: isChecked, | ||
id: id | ||
}); | ||
@@ -246,7 +379,23 @@ | ||
var chinaData; | ||
_this.handleAreaTabChange = function (key) { | ||
_this.setState({ | ||
currentAreaTab: key, | ||
breadlist: [{ | ||
name: key === 0 ? _this.translation.nationWide : _this.translation.foreignWide, | ||
index: 0 | ||
}] | ||
}); | ||
}; | ||
if (props.data[1][0] == '2' && props.data[1][1] == '国外') { | ||
chinaData = props.data.slice(2, -1); | ||
chinaData.unshift(props.data[0]); | ||
_this.translation = Object.assign({}, defaultTranslation, props.translation); | ||
var chinaData, foreignData; // 当数据源中有国外数据时,设置国外数据的值 | ||
if (props.data[1][0] === '2') { | ||
chinaData = props.data.filter(function (_, i) { | ||
return i !== 1; | ||
}); // 切割国外数据,将国外与其他地区整理为并列的结构然后格式化数据 | ||
foreignData = _this.sortData([[props.data[1][0], props.data[1][1]]].concat(_toConsumableArray(props.data[1][2])), true); | ||
} else { | ||
chinaData = props.data; | ||
} | ||
@@ -257,8 +406,11 @@ | ||
_this.foreignData = foreignData; // 国外数据 | ||
_this.currentData = chinaData; // 当前需要渲染数据 | ||
_this.state = { | ||
resultsData: props.defaultResults.length ? props.defaultResults : [], | ||
currentAreaTab: 0, | ||
resultsData: props.defaultResults.length ? _this.handleDefaultResults(props.defaultResults) : [], | ||
breadlist: [{ | ||
name: '全国省市', | ||
name: _this.translation.nationWide, | ||
index: 0 | ||
@@ -273,2 +425,4 @@ }] | ||
value: function render() { | ||
var data = this.props.data; | ||
var currentAreaTab = this.state.currentAreaTab; | ||
this.getCurrentData(); // 面包屑数据 | ||
@@ -282,12 +436,43 @@ | ||
bsStyle: 'tabs', | ||
activeKey: 0, | ||
activeKey: currentAreaTab, | ||
tabItems: [{ | ||
idx: 'tab0', | ||
eventKey: 0, | ||
title: '全国', | ||
active: true | ||
title: data[0][1], | ||
active: currentAreaTab === 0 | ||
}], | ||
callBack: function callBack() {} // 地区列表 数据 | ||
callBack: this.handleAreaTabChange | ||
}; | ||
}; | ||
if (this.foreignData) { | ||
_tabComponentData.tabItems.push({ | ||
idx: 'tab1', | ||
eventKey: 1, | ||
title: data[1][1], | ||
active: currentAreaTab === 1 | ||
}); | ||
} //选中父级,子集也选中 | ||
if (this.props.allowContainsChildren && !this.props.isSingleSelect) { | ||
var pIndex = ""; | ||
for (var i = 0; i < this.state.breadlist.length - 1; i++) { | ||
//根据面包屑数据获取pIndex | ||
pIndex = pIndex + (pIndex == "" ? "" : "/") + this.currentData[0].pIndex.split("/")[i]; | ||
} | ||
var lastBreadData = this.state.breadlist[this.state.breadlist.length - 1]; //判断进入下一级时父级是否被选中 | ||
if (this.state.resultsData.filter(function (item) { | ||
return item.pIndex == pIndex; | ||
}).length > 0 || lastBreadData.isChecked && lastBreadData.index == pIndex) { | ||
this.currentData.map(function (item) { | ||
item.isChecked = true; | ||
item.disabled = true; | ||
}); | ||
} | ||
} // 地区列表 数据 | ||
var _optionsItemData = { | ||
@@ -309,3 +494,4 @@ isSingleSelect: this.props.isSingleSelect, | ||
hasCount: this.state.resultsData.length, | ||
clearResultsData: this.clearResultsData // 已选地区列表 数据 | ||
clearResultsData: this.clearResultsData, | ||
translation: this.translation // 已选地区列表 数据 | ||
@@ -337,6 +523,6 @@ }; | ||
onClick: this.cancelClick | ||
}, "\u53D6\u6D88"), React.createElement("button", { | ||
}, this.translation.cancelText), React.createElement("button", { | ||
className: "btn btn_default btn_sm", | ||
onClick: this.sureClick | ||
}, "\u786E\u5B9A"))); | ||
}, this.translation.confirmText))); | ||
} | ||
@@ -356,5 +542,4 @@ }]); | ||
hiddenTip: false, | ||
sideTip: false // 对数据进行处理, 添加需要字段 | ||
sideTip: false | ||
}; | ||
export { AreaSelect as default }; |
@@ -99,3 +99,3 @@ import "core-js/modules/es6.function.name"; | ||
}, React.createElement("span", { | ||
className: "area-select__text " + (isMore ? '' : 'area-select__text_is-nomore') | ||
className: "area-select__text" + (isMore ? '' : ' area-select__text_is-nomore') | ||
}, _name)), React.createElement("i", { | ||
@@ -102,0 +102,0 @@ className: "icon-arrow-right" |
@@ -33,2 +33,4 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
value: function render() { | ||
var translation = this.props.translation; | ||
var _clearClass = this.props.hasCount == 0 ? 'area-select__text_is-disabled' : 'area-select__text_is-active'; | ||
@@ -40,3 +42,3 @@ | ||
className: "area-select__text" | ||
}, "\u5DF2\u9009\u5730\u533A\xA0\xA0\xA0"), React.createElement("span", { | ||
}, translation.areaSelected, "\xA0\xA0\xA0"), React.createElement("span", { | ||
className: "area-select__text" | ||
@@ -49,3 +51,3 @@ }, this.props.hasCount + '/'), React.createElement("span", { | ||
onClick: this.clearClick | ||
}, "\u6E05\u7A7A\u5DF2\u9009")); | ||
}, translation.clearSelected)); | ||
} | ||
@@ -52,0 +54,0 @@ }]); |
{ | ||
"name": "@beisen-platform/area-selector", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "平台地区组件", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -22,2 +22,3 @@ # area-selector 使用说明 | ||
allLevelDisplay:true, //是否显示所有级别,默认true | ||
allowContainsChildren: true, // 选中父级默认选中子集,且子集无法取消勾选,仅在多选状态下生效 | ||
hiddenTip:false, //ToolTip的hidden字段,默认false | ||
@@ -24,0 +25,0 @@ sideTip:false, //ToolTip的side字段,默认false |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1216783
18
27274
96
308
8