zan-upload
Advanced tools
Comparing version 7.0.1 to 7.0.2-beta1
@@ -65,6 +65,2 @@ 'use strict'; | ||
var _cloneDeep = require('lodash/cloneDeep'); | ||
var _cloneDeep2 = _interopRequireDefault(_cloneDeep); | ||
var _ImageList = require('./ImageList'); | ||
@@ -184,3 +180,4 @@ | ||
currPageNo: 1, | ||
categoryId: props.options.categoryId | ||
categoryId: props.options.categoryId, | ||
showSearch: false | ||
}; | ||
@@ -201,2 +198,4 @@ _this.typeName = props.options.type === 'voice' ? '语音' : '图片'; | ||
this.isShowSearch(); | ||
this.getCache().then(function () { | ||
@@ -210,13 +209,51 @@ // 存在缓存信息且可用 | ||
} | ||
/** | ||
* 判断是否展示搜索框 | ||
*/ | ||
}, { | ||
key: 'isShowSearch', | ||
value: function isShowSearch() { | ||
var _this3 = this; | ||
// 获取是否存在 是否展示搜索框 的信息 | ||
var _window$_global$mater = window._global.materialsShowSearch, | ||
materialsShowSearch = _window$_global$mater === undefined ? false : _window$_global$mater; | ||
if (materialsShowSearch) { | ||
return this.setState({ | ||
showSearch: materialsShowSearch.value || false | ||
}); | ||
} | ||
// 请求判断是否需要展示搜索框 | ||
var options = this.props.options; | ||
var isSupportSearchUrl = options.isSupportSearchUrl, | ||
type = options.type; | ||
(0, _zanPcAjax2['default'])({ | ||
url: isSupportSearchUrl, | ||
data: { type: type } | ||
}).then(function (showSearch) { | ||
_this3.setState({ showSearch: showSearch }); | ||
// 缓存该结果 | ||
window._global.materialsShowSearch = { | ||
value: showSearch | ||
}; | ||
}); | ||
} | ||
}, { | ||
key: 'getMediaList', | ||
value: function getMediaList() { | ||
var _this3 = this; | ||
var _this4 = this; | ||
var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var keyword = arguments[1]; | ||
var categoryId = this.state.categoryId; | ||
var options = this.props.options; | ||
var categoryId = this.state.categoryId; | ||
var type = options.type, | ||
mediaListUrl = options.mediaListUrl; | ||
var pageSize = options.type === 'voice' ? VOICE_PAGE_SIZE : IMAGE_PAGE_SIZE; | ||
var pageSize = type === 'voice' ? VOICE_PAGE_SIZE : IMAGE_PAGE_SIZE; | ||
if (typeof keyword === 'undefined') { | ||
@@ -226,19 +263,32 @@ keyword = this.state.keyword; | ||
return (0, _zanPcAjax2['default'])({ | ||
url: options.mediaListUrl, | ||
url: mediaListUrl, | ||
withCredentials: true, | ||
noXRequestedWithHeader: true, | ||
data: { | ||
p: page, | ||
categoryId: categoryId, | ||
keyword: keyword, | ||
type: type, | ||
partnerBizType: 1, | ||
pageSize: pageSize, | ||
mediaType: options.type, | ||
categoryId: categoryId, | ||
keyword: keyword | ||
pageNum: page, | ||
// 兼容老的接口传参,防止业务方使用自己定义的接口 | ||
mediaType: type, | ||
p: page | ||
} | ||
}).then(function (data) { | ||
_this3.setState({ | ||
count: data.count, | ||
currPageNo: data.currPageNo, | ||
mediaList: (0, _cloneDeep2['default'])(data.dataList) || [], | ||
var _data$items = data.items, | ||
items = _data$items === undefined ? [] : _data$items, | ||
_data$paginator = data.paginator, | ||
paginator = _data$paginator === undefined ? {} : _data$paginator; | ||
var _paginator$totalCount = paginator.totalCount, | ||
totalCount = _paginator$totalCount === undefined ? 0 : _paginator$totalCount; | ||
var mediaList = (0, _utils.transformData)(items); | ||
_this4.setState({ | ||
count: totalCount, | ||
currPageNo: page, | ||
mediaList: mediaList, | ||
keyword: keyword | ||
}, _this3.setCache); | ||
}, _this4.setCache); | ||
}); | ||
@@ -249,3 +299,3 @@ } | ||
value: function renderCategoryRegion() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -264,3 +314,3 @@ var _state = this.state, | ||
}, 'clearfix'), | ||
onClick: _this4.setCategoryId(data.id) | ||
onClick: _this5.setCategoryId(data.id) | ||
}, | ||
@@ -292,3 +342,4 @@ _react2['default'].createElement( | ||
categoryList = _state2.categoryList, | ||
categoryId = _state2.categoryId; | ||
categoryId = _state2.categoryId, | ||
showSearch = _state2.showSearch; | ||
var onShowUpload = this.props.onShowUpload; | ||
@@ -311,3 +362,3 @@ | ||
), | ||
_react2['default'].createElement(_searchInput2['default'], { | ||
showSearch && _react2['default'].createElement(_searchInput2['default'], { | ||
className: 'pull-right', | ||
@@ -314,0 +365,0 @@ value: keyword, |
@@ -448,2 +448,3 @@ 'use strict'; | ||
* @property {String} [scope='kdt_img'] 图片空间名 | ||
* @property {String} [isSupportSearchUrl=''] 判断是否展示搜索框 | ||
* @property {Function} [trigger=() => <a href="javascript:;">上传图片</a>] 自定义触发器 | ||
@@ -472,5 +473,6 @@ */ | ||
auto: false, | ||
mediaListUrl: materialsHost + '/media/mediaList.json', | ||
mediaListUrl: '/v4/shop/api/materials/list', | ||
categoryListUrl: materialsHost + '/category/categoryList.json', | ||
iconListUrl: materialsHost + '/icon/list.json', | ||
isSupportSearchUrl: '/v4/shop/api/search/support', | ||
fetchUrl: '', | ||
@@ -477,0 +479,0 @@ tokenUrl: '', |
@@ -14,3 +14,15 @@ 'use strict'; | ||
exports.formatError = formatError; | ||
exports.transformData = transformData; | ||
exports.parsePath = parsePath; | ||
var _makeDateTimeStr = require('zan-utils/date/makeDateTimeStr'); | ||
var _makeDateTimeStr2 = _interopRequireDefault(_makeDateTimeStr); | ||
var _parse = require('zan-utils/url/parse'); | ||
var _parse2 = _interopRequireDefault(_parse); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
@@ -135,2 +147,56 @@ | ||
return '上传失败'; | ||
} | ||
/** | ||
* 转换新数据结构,兼容老的数据展示 | ||
* 不在node层做转化的原因:之后迁移的时候可以直接使用新的数据结构 | ||
* @param {Array} data: 需要转换的数据 | ||
*/ | ||
function transformData() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
if (data.length === 0) return data; | ||
return data.map(function (item) { | ||
var createdAt = item.createdAt, | ||
fileExt = item.fileExt, | ||
mediaId = item.mediaId, | ||
meta = item.meta, | ||
size = item.size, | ||
thumbnailUrl = item.thumbnailUrl, | ||
title = item.title, | ||
url = item.url, | ||
width = item.width, | ||
height = item.height; | ||
var fileUrl = parsePath(url); | ||
var params = { | ||
attachmentId: mediaId, | ||
attachmentTitle: title, | ||
attachmentFullUrl: url, | ||
attachmentUrl: url, | ||
attachmentSize: size, | ||
createTime: (0, _makeDateTimeStr2['default'])(new Date(createdAt)), | ||
fileExt: fileExt, | ||
meta: meta, | ||
attachmentFile: fileUrl, | ||
thumbFile: fileUrl, | ||
thumbUrl: parsePath(thumbnailUrl), | ||
height: height, | ||
width: width | ||
}; | ||
return params; | ||
}); | ||
} | ||
/** | ||
* 将url转换为开头不带/的path路径 | ||
* @param {String} url | ||
* @return {String} | ||
*/ | ||
function parsePath(url) { | ||
var urlArr = new _parse2['default'](url); | ||
var path = urlArr.pathname; | ||
// 对解析后的path进行校验,去除第一个字符为/的情况 | ||
return path.indexOf('/') === 0 ? path.slice(1) : path; | ||
} |
{ | ||
"name": "zan-upload", | ||
"version": "7.0.1", | ||
"version": "7.0.2-beta1", | ||
"description": "这是一个React Upload 组件", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
116173
2703
0
2