/**
 * 判断是否有网络
 */
export default function useNetWork() {
	getNetStatus().then(res => {
	  console.log('有网', res);
	}).catch(res => {
		setTimeout(() => {
			uni.showToast({
				title: '请检查您的网络连接',
				icon: 'none',
				duration: 3000,
			})
		}, 100)
		wx.onNetworkStatusChange(function(res) {
			if (res.isConnected) {
				uni.showToast({
					title: '网络已恢复',
					icon: 'none',
					duration: 1000,
				})
			} else {
			 useNetWork();
			}
		})
	})
}

function getNetStatus(){
	return new Promise((resolve, reject) => {
		wx.getNetworkType({
			success (res) {
				const networkType = res.networkType;
				if (res.networkType === 'none') {
					reject();
				} else {
					resolve();
				}
			}
		})
	})
}