alaska-field-image
Advanced tools
Comparing version 0.11.7 to 0.11.8
22
index.js
@@ -18,3 +18,7 @@ // @flow | ||
cell: 'ImageFieldCell', | ||
view: 'ImageFieldView' | ||
view: 'ImageFieldView', | ||
dir: 'public/uploads/', | ||
pathFormat: 'YYYY/MM/DD/', | ||
prefix: '/uploads/', | ||
allowed: ['jpg', 'png', 'gif'] | ||
}; | ||
@@ -177,18 +181,2 @@ | ||
if (!field.dir) { | ||
field.dir = ''; | ||
} | ||
if (!field.pathFormat) { | ||
field.pathFormat = ''; | ||
} | ||
if (!field.prefix) { | ||
field.prefix = ''; | ||
} | ||
if (!field.allowed) { | ||
field.allowed = ['jpg', 'png', 'gif']; | ||
} | ||
this.underscoreMethod('upload', function (file) { | ||
@@ -195,0 +183,0 @@ let record = this; |
{ | ||
"name": "alaska-field-image", | ||
"version": "0.11.7", | ||
"version": "0.11.8", | ||
"description": "Alaska image field", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -18,3 +18,3 @@ // @flow | ||
if (!value || !value.thumbUrl) { | ||
return <div />; | ||
return <div className="image-field-cell" />; | ||
} | ||
@@ -28,5 +28,7 @@ let styles = { | ||
return ( | ||
<img alt="" src={value.thumbUrl} style={styles.img} /> | ||
<div className="image-field-cell"> | ||
<img alt="" src={value.thumbUrl} style={styles.img} /> | ||
</div> | ||
); | ||
} | ||
} |
@@ -61,3 +61,2 @@ // @flow | ||
handleAddImage = () => { | ||
let me = this; | ||
const t = this.context.t; | ||
@@ -88,4 +87,5 @@ let { model, field, data, value } = this.props; | ||
}; | ||
_.forEach(this.imageInput.files, (file) => { | ||
if (value.length >= me.state.max || !file) return; | ||
if (value.length >= this.state.max || !file) return; | ||
let matchs = file.name.match(/\.(\w+)$/); | ||
@@ -97,7 +97,3 @@ let temp: boolean = (field.allowed || ['jpg', 'png']).indexOf(matchs[1].replace('jpeg', 'jpg').toLowerCase()) < 0; | ||
} | ||
let data = new FormData(); | ||
data.append('file', file); | ||
data.append('id', id); | ||
data.append('path', field.path || 'avatar'); | ||
api.post('/api/upload', { | ||
api.upload('/api/upload', { | ||
params: { | ||
@@ -107,10 +103,10 @@ _service: serviceId, | ||
}, | ||
body: data | ||
body: { file, id, path: field.path || 'avatar' } | ||
}).then((res) => { | ||
value.push(res); | ||
if (me.props.onChange) { | ||
me.props.onChange(multi ? value : res); | ||
value = value.concat(res); | ||
if (this.props.onChange) { | ||
this.props.onChange(multi ? value : res); | ||
} | ||
}, (error) => { | ||
me.setState({ errorText: error.message }); | ||
this.setState({ errorText: error.message }); | ||
}); | ||
@@ -123,6 +119,8 @@ }); | ||
let multi = this.props.field.multi; | ||
let value: any[] = []; | ||
let value = null; | ||
if (multi) { | ||
value = []; | ||
_.forEach(this.props.value, (i) => { | ||
if (i !== item) { | ||
// $Flow 我们知道此处value 为数组 | ||
value.push(i); | ||
@@ -129,0 +127,0 @@ } |
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
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
11861
387