zan-upload
Advanced tools
Comparing version 5.5.0 to 5.5.3
@@ -105,2 +105,33 @@ 'use strict'; | ||
_this.getMediaList = function () { | ||
var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var options = _this.props.options; | ||
var iconListUrl = options.iconListUrl; | ||
var searchQuery = _this.state.searchQuery; | ||
var pageSize = ICON_PAGE_SIZE; | ||
return (0, _zanPcAjax2['default'])({ | ||
url: iconListUrl, | ||
withCredentials: true, | ||
noXRequestedWithHeader: true, | ||
data: _extends({ | ||
p: page, | ||
pageSize: pageSize | ||
}, searchQuery) | ||
}).then(function (data) { | ||
_this.setState({ | ||
count: data.count, | ||
currPageNo: data.currPageNo, | ||
// 根据data.count判断是否有图片,后端在无图片时返回了null | ||
mediaList: (data.dataList || []).map(function (item) { | ||
return _extends({}, item, { | ||
// 后端返回的数据无此字段 | ||
attachmentFullUrl: item.attachmentUrl | ||
}); | ||
}) | ||
}, _this.setCache); | ||
}); | ||
}; | ||
_this.renderSearchSelect = function () { | ||
@@ -151,2 +182,48 @@ var searchQuery = _this.state.searchQuery; | ||
_this.selectMedia = function (media) { | ||
var options = _this.props.options; | ||
var selectedItems = _this.state.selectedItems; | ||
var maxAmount = options.maxAmount; | ||
var selectedIndex = selectedItems.map(function (item) { | ||
return item.attachmentId; | ||
}).indexOf(media.attachmentId); | ||
var isMediaSelected = selectedIndex > -1; | ||
if (!isMediaSelected && maxAmount > 1 && selectedItems.length >= maxAmount) { | ||
// 最大数量超过1,当达到最大选择数量,增加提示 | ||
_notify2['default'].error('\u4F60\u6700\u591A\u53EA\u80FD\u9009\u62E9' + maxAmount + '\u5F20\u56FE\u7247'); | ||
return; | ||
} | ||
if (isMediaSelected) { | ||
// 取消选择 | ||
selectedItems.splice(selectedIndex, 1); | ||
} else if (maxAmount === 1) { | ||
// 只能选择一张特殊处理 | ||
selectedItems.splice(0, 1, media); | ||
} else { | ||
selectedItems.push(media); | ||
} | ||
_this.setState({ | ||
selectedItems: selectedItems | ||
}); | ||
}; | ||
_this.confirm = function () { | ||
var selectedItems = _this.state.selectedItems; | ||
var _this$props = _this.props, | ||
options = _this$props.options, | ||
showUploadPopup = _this$props.showUploadPopup; | ||
if (typeof options.onSuccess === 'function') { | ||
options.onSuccess(selectedItems.map(function (item) { | ||
return (0, _utils.responseParse)(item); | ||
})); | ||
showUploadPopup(false); | ||
} | ||
}; | ||
_this.state = { | ||
@@ -165,5 +242,2 @@ mediaList: [], | ||
_this.localStorgeKey = 'widget-attachment-icon-' + props.options.kdtId; | ||
_this.confirm = _this.confirm.bind(_this); | ||
_this.getMediaList = _this.getMediaList.bind(_this); | ||
_this.selectMedia = _this.selectMedia.bind(_this); | ||
return _this; | ||
@@ -178,35 +252,2 @@ } | ||
}, { | ||
key: 'getMediaList', | ||
value: function getMediaList() { | ||
var _this2 = this; | ||
var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var options = this.props.options; | ||
var iconListUrl = options.iconListUrl; | ||
var searchQuery = this.state.searchQuery; | ||
var pageSize = ICON_PAGE_SIZE; | ||
return (0, _zanPcAjax2['default'])({ | ||
url: iconListUrl, | ||
withCredentials: true, | ||
noXRequestedWithHeader: true, | ||
data: _extends({ | ||
p: page, | ||
pageSize: pageSize | ||
}, searchQuery) | ||
}).then(function (data) { | ||
_this2.setState({ | ||
count: data.count, | ||
currPageNo: data.currPageNo, | ||
mediaList: data.dataList.map(function (item) { | ||
return _extends({}, item, { | ||
// 后端返回的数据无此字段 | ||
attachmentFullUrl: item.attachmentUrl | ||
}); | ||
}) || [] | ||
}, _this2.setCache); | ||
}); | ||
} | ||
}, { | ||
key: 'renderMediaRegion', | ||
@@ -268,50 +309,2 @@ value: function renderMediaRegion() { | ||
}, { | ||
key: 'selectMedia', | ||
value: function selectMedia(media) { | ||
var options = this.props.options; | ||
var selectedItems = this.state.selectedItems; | ||
var maxAmount = options.maxAmount; | ||
var selectedIndex = selectedItems.map(function (item) { | ||
return item.attachmentId; | ||
}).indexOf(media.attachmentId); | ||
var isMediaSelected = selectedIndex > -1; | ||
if (!isMediaSelected && maxAmount > 1 && selectedItems.length >= maxAmount) { | ||
// 最大数量超过1,当达到最大选择数量,增加提示 | ||
_notify2['default'].error('\u4F60\u6700\u591A\u53EA\u80FD\u9009\u62E9' + maxAmount + '\u5F20\u56FE\u7247'); | ||
return; | ||
} | ||
if (isMediaSelected) { | ||
// 取消选择 | ||
selectedItems.splice(selectedIndex, 1); | ||
} else if (maxAmount === 1) { | ||
// 只能选择一张特殊处理 | ||
selectedItems.splice(0, 1, media); | ||
} else { | ||
selectedItems.push(media); | ||
} | ||
this.setState({ | ||
selectedItems: selectedItems | ||
}); | ||
} | ||
}, { | ||
key: 'confirm', | ||
value: function confirm() { | ||
var selectedItems = this.state.selectedItems; | ||
var _props = this.props, | ||
options = _props.options, | ||
showUploadPopup = _props.showUploadPopup; | ||
if (typeof options.onSuccess === 'function') { | ||
options.onSuccess(selectedItems.map(function (item) { | ||
return (0, _utils.responseParse)(item); | ||
})); | ||
showUploadPopup(false); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -340,4 +333,3 @@ value: function render() { | ||
IconsPopup.defaultProps = { | ||
options: {}, | ||
className: '' | ||
options: {} | ||
}; | ||
@@ -344,0 +336,0 @@ |
@@ -380,5 +380,3 @@ 'use strict'; | ||
value: function renderIconPopup(options) { | ||
var _props3 = this.props, | ||
prefix = _props3.prefix, | ||
className = _props3.className; | ||
var prefix = this.props.prefix; | ||
var showLocalUpload = this.state.showLocalUpload; | ||
@@ -398,3 +396,2 @@ | ||
options: options, | ||
className: className, | ||
showUploadPopup: this.showUpload | ||
@@ -401,0 +398,0 @@ }) |
{ | ||
"name": "zan-upload", | ||
"version": "5.5.0", | ||
"version": "5.5.3", | ||
"description": "这是一个React Upload 组件", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1373831
37699