1/**
2 * @description 获取图片宽度和高度
3 * @param {Object} file 图片文件对象
4 * @return {Object} {width: number, height: number} 图片宽度和高度
5 *  */
6const getImageRadio = file => {
7	return new Promise((resolve, reject) => {
8		// 创建读取文件对象
9		const reader = new FileReader();
10		// 读取文件对象
11		reader.readAsDataURL(file);
12		// 文件对象加载完成
13		reader.onload = () => {
14			// 创建image对象
15			const imageEl = new Image();
16			// 赋值src地址
17			imageEl.src = reader.result;
18			// 图片加载成功
19			imageEl.onload = () => {
20				let imgWH = {
21					with: imageEl.width,
22					height: imageEl.height
23				};
24				return resolve(imgWH);
25			};
26			// 图片加载失败
27			imageEl.onerror = () => {
28				return reject(null);
29			};
30		};
31		// 文件对象加载失败
32		reader.onerror = () => {
33			return reject(null);
34		};
35	});
36};