chore: prettier source code

This commit is contained in:
chenjiahan
2020-04-02 15:36:02 +08:00
parent 340c56b3b5
commit 2fb5cca49a
93 changed files with 272 additions and 283 deletions
+7 -7
View File
@@ -117,7 +117,7 @@ export default createComponent({
if (isPromise(response)) {
response
.then(data => {
.then((data) => {
if (data) {
this.readFile(data);
} else {
@@ -143,8 +143,8 @@ export default createComponent({
files = files.slice(0, maxCount);
}
Promise.all(files.map(file => readFile(file, this.resultType))).then(
contents => {
Promise.all(files.map((file) => readFile(file, this.resultType))).then(
(contents) => {
const fileList = files.map((file, index) => {
const result = { file, status: '' };
@@ -159,7 +159,7 @@ export default createComponent({
}
);
} else {
readFile(files, this.resultType).then(content => {
readFile(files, this.resultType).then((content) => {
const result = { file: files, status: '' };
if (content) {
@@ -227,8 +227,8 @@ export default createComponent({
return;
}
const imageFiles = this.fileList.filter(item => isImageFile(item));
const imageContents = imageFiles.map(item => item.content || item.url);
const imageFiles = this.fileList.filter((item) => isImageFile(item));
const imageContents = imageFiles.map((item) => item.content || item.url);
this.imagePreview = ImagePreview({
images: imageContents,
@@ -287,7 +287,7 @@ export default createComponent({
<Icon
name="clear"
class={bem('preview-delete')}
onClick={event => {
onClick={(event) => {
event.stopPropagation();
this.onDelete(item, index);
}}
+11 -11
View File
@@ -1,7 +1,7 @@
import Uploader from '..';
import { mount, later, triggerDrag } from '../../../test';
window.File = function() {
window.File = function () {
this.size = 10000;
};
@@ -12,8 +12,8 @@ const multiFile = { target: { files: [mockFile, mockFile] } };
const IMAGE = 'https://img.yzcdn.cn/vant/cat.jpeg';
const PDF = 'https://img.yzcdn.cn/vant/test.pdf';
window.FileReader = function() {
this.readAsText = function() {
window.FileReader = function () {
this.readAsText = function () {
this.onload &&
this.onload({
target: {
@@ -37,11 +37,11 @@ test('disabled', () => {
expect(afterRead).toHaveBeenCalledTimes(0);
});
test('result-type as text', done => {
test('result-type as text', (done) => {
const wrapper = mount(Uploader, {
propsData: {
resultType: 'text',
afterRead: readFile => {
afterRead: (readFile) => {
expect(readFile.content).toEqual(mockFileDataUrl);
done();
},
@@ -51,11 +51,11 @@ test('result-type as text', done => {
wrapper.vm.onChange(file);
});
test('result-type as file', done => {
test('result-type as file', (done) => {
const wrapper = mount(Uploader, {
propsData: {
resultType: 'file',
afterRead: readFile => {
afterRead: (readFile) => {
expect(readFile.file).toBeTruthy();
expect(readFile.content).toBeFalsy();
done();
@@ -66,7 +66,7 @@ test('result-type as file', done => {
wrapper.vm.onChange(file);
});
test('set input name', done => {
test('set input name', (done) => {
const wrapper = mount(Uploader, {
propsData: {
name: 'uploader',
@@ -117,7 +117,7 @@ test('before read return promise and resolve', async () => {
const wrapper = mount(Uploader, {
propsData: {
beforeRead: () =>
new Promise(resolve => {
new Promise((resolve) => {
resolve(file);
}),
afterRead,
@@ -135,7 +135,7 @@ test('before read return promise and resolve no value', async () => {
const wrapper = mount(Uploader, {
propsData: {
beforeRead: () =>
new Promise(resolve => {
new Promise((resolve) => {
resolve();
}),
afterRead,
@@ -360,7 +360,7 @@ test('before-delete prop resolved', async () => {
const wrapper = mount(Uploader, {
propsData: {
fileList: [{ url: IMAGE }],
beforeDelete: () => new Promise(resolve => resolve()),
beforeDelete: () => new Promise((resolve) => resolve()),
},
});
+3 -3
View File
@@ -9,7 +9,7 @@ export function toArray<T>(item: T | T[]): T[] {
}
export function readFile(file: File, resultType: ResultType) {
return new Promise(resolve => {
return new Promise((resolve) => {
if (resultType === 'file') {
resolve();
return;
@@ -17,7 +17,7 @@ export function readFile(file: File, resultType: ResultType) {
const reader = new FileReader();
reader.onload = event => {
reader.onload = (event) => {
resolve((event.target as FileReader).result);
};
@@ -33,7 +33,7 @@ export function isOversize(
files: File | File[],
maxSize: number | string
): boolean {
return toArray(files).some(file => file.size > maxSize);
return toArray(files).some((file) => file.size > maxSize);
}
export type FileListItem = {