Skip to content

Commit

Permalink
feat(ImagePicker): 新增 cells 属性
Browse files Browse the repository at this point in the history
cells 属性取代 urls 传入对象类型参数
此后 urls 仅负责接收字符串数组,cells 负责接收对象数组

close #921

BREAKING CHANGE: urls 不再接收对象数组
  • Loading branch information
juzi214032 committed Jul 30, 2020
1 parent ddc03fd commit 08cbad7
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/image-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Component({
maxImageSize: {
type: Number,
value: 10000000,
},
// 以对象方式传入图片链接
cells: {
type: Array,
value: null
}
},

Expand All @@ -72,12 +77,19 @@ Component({
lifetimes: {
attached: function () {
// 在组件实例进入页面节点树时执行
const newOrOld = this.judgeNewOrOld();
this.setData({
newOrOld
});
if (newOrOld === 'old') {
console.warn('image-picker组件已经升级,建议使用最新版本,当前用法会在后续版本中暂停支持');
let newOrOld = this.judgeNewOrOld();

// 对 cells 的兼容处理
if (this.data.cells !== null) {
newOrOld = 'new';
this.setData({
newOrOld,
urls: this.data.cells
});
} else {
this.setData({
newOrOld
});
}
},
},
Expand Down Expand Up @@ -110,7 +122,14 @@ Component({
let previewImageList = [];
const newOrOld = this.data.newOrOld;

if (newOrOld === 'old') {
// 第一个 if 是对 cells 的兼容处理
if (typeof (this.data.cells) !== 'undefined') {
const cells = this.data.cells;
tempFilePath = cells[index].url;
for (let i = 0; i < cells.length; i++) {
previewImageList.push(cells[i].url);
}
} else if (newOrOld === 'old') {
tempFilePath = this.data.urls[index];
previewImageList = this.data.urls;

Expand Down

0 comments on commit 08cbad7

Please sign in to comment.