// 把方法修改成Promise函数
export const convertPromise = function (FnName, params = {}) {
    return new Promise((resolve, reject) => {
        uni[FnName]({
            ...params,
            success: function (res) {
                return resolve(res)
            },
            fail: function (err) {
                console.log(err, `处理${FnName}方法信息报错`)
                return reject(err)
            },
            complete: function (res) {
                //console.log(res,`处理${FnName}方法信息完成`)
            }
        })
    });
}

// 初始化请求头的device参数信息
export const initHeaderDevice = function () {
    const common = {
        appName: 'DDH',
        appSourceId: "1",
        token: "c695fa285b9dc46a", // 设备令牌（device_token）  设备udid
        idfa: "", // IOS设备则为：IDFA 广告标识
        imei: "", //安卓设备为：imei
        mac: "", // mac
        wifiMac: "", // wifimac
        clientIp: "",
        carrierOperator: 'OperatorName', //运营商
        pushType: "1", //设备push接入类型(1. 小米PUSH，2. 极光PUSH)
        electricQuantity: "", //电量
        totalStorage: "", //存储总空间
        availableStorage: "" //可用存储空间
    };

    const deviceInfo = uni.getStorageSync('m-device-info')
    const networkInfo = uni.getStorageSync('m-network-info')
    const locationInfo = uni.getStorageSync('m-location-info')
	const loadUuid = uni.getStorageSync('m-load-udid')

    let device = {};
    if (deviceInfo) {
        device = Object.assign(device, common, JSON.parse(deviceInfo))
    }

    if (networkInfo) {
        device = Object.assign(device, common, JSON.parse(networkInfo))
    }

    if (locationInfo) {
        device = Object.assign(device, common, JSON.parse(locationInfo))
    }
	if(loadUuid){
		 device = Object.assign(device, common, JSON.parse(loadUuid))
	}
    if (deviceInfo && networkInfo && locationInfo && loadUuid) {
        const headerDeviceInfo = {
            ...JSON.parse(deviceInfo),
            ...JSON.parse(networkInfo),
            ...JSON.parse(locationInfo),
			...JSON.parse(loadUuid),
            ...common
        }

        // 存储所有请求的头部信息
        uni.setStorage({
            key: 'm-header-device',
            data: JSON.stringify(headerDeviceInfo),
            success: function () {
                console.log('m-header-device存储成功4');
            }
        });

        return headerDeviceInfo
    }

    return device

}
