export default {
	getToken() {
		let code = this.GetQueryString('code');
		let token = uni.getStorageSync('token');
		if (code && !token) {
			uni.$u.http.post('/api/official_account/wx_login', {
				code: code
			}).then(res => {
				uni.setStorageSync('token', res.msg);
			})
		}
	},
	GetQueryString(name) {
		var url = window.location.href;
		try {
			var cs = url.split('?')[1]; //获取?之后的参数字符串
			var cs_arr = cs.split('&'); //参数字符串分割为数组
			for (var i = 0; i < cs_arr.length; i++) { //遍历数组，拿到json对象
				if (cs_arr[i].split('=')[0] == name) {
					return cs_arr[i].split('=')[1];
				}
			}
			return null;
		} catch {
			return null;
		}
	},
	// 获取手机类型
	getPhoneType() {
		let phoneType="";
		uni.getSystemInfo({
			success:(res)=>{
				phoneType=res.model
			}
		});
		return phoneType
	},
	/**
	 * 文件大小单位计算
	 */
	unitConversion (size) {
	  var data = "";
	  if (size < 0.1 * 1024) { //如果小于0.1KB转化成B
	    data = size.toFixed(2) + "B";
	  } else if (size < 0.1 * 1024 * 1024) {//如果小于0.1MB转化成KB
	    data = (size / 1024).toFixed(2) + "KB";
	  } else if (size < 0.1 * 1024 * 1024 * 1024) { //如果小于0.1GB转化成MB
	    data = (size / (1024 * 1024)).toFixed(2) + "MB";
	  } else { //其他转化成GB
	    data = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB";
	  }
	  var sizestr = data + "";
	  var len = sizestr.indexOf("\.");
	  var dec = sizestr.substr(len + 1, 2);
	  if (dec == "00") {//当小数点后为00时 去掉小数部分
	    return sizestr.substring(0, len) + sizestr.substr(len + 3, 2);
	  }
	  return sizestr;
	}
}
