export function objToUrl(obj) {
  let uri = '';
  let keys = Object.keys(obj);
  keys.forEach(item => {
    uri += '&' + item + '=' + obj[item];
  });

  uri = uri.substr(1);

  return uri;
}

export function parseQueryString(url) {
    var obj = {};
    var keyvalue = [];
    var key = "",
        value = "";
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    for (var i in paraString) {
        keyvalue = paraString[i].split("=");
        key = keyvalue[0];
        value = keyvalue[1];
        obj[key] = value;
    }
    return obj;
}

//分享图片给好友按钮的点击事件函数
export function getZbdQrCode(){
	return "data:image/png;base64,[encoded data, 51628 characters]"
}
export function sharePic() {
	let that = this
	const picData = getZbdQrCode()
	base64ToFilePath(picData, (filePath) => {
		console.log(filePath);
		uni.showShareImageMenu({ //分享给朋友
			path: filePath,
			success: (res) => {
				console.log("分享成功：", res);
			},
			fail: (err) => {
				console.log("分享取消：", err);
			},
		})
	})
}
//封装的base64转换成临时文件路径的函数
export function base64ToFilePath(base64data, fun) {
	const base64 = base64data; //base64格式图片
	const time = new Date().getTime();
	//去掉data:image/png;base64,如果图片字符串不含要清空的前缀,可以不执行下行代码.
	const imgPath = wx.env.USER_DATA_PATH + "/addFriends" + time + "share_qrcode" + ".png"; 
	const imageData = base64.replace(/^data:image\/\w+;base64,/, "");
	const file = wx.getFileSystemManager();
	file.writeFileSync(imgPath, imageData, "base64");
	fun(imgPath);
}

  