import { baseUrl } from '@/common/config.js';

export default (params) => {
    let { data = '', header = {} } = params;
    // promise请求
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + params.url,
			method: params.method,
			header: {
				'Authorization': 'tf:' + uni.getStorageSync('access-token'),
				'content-type': 'application/json',
				...header
			},
			data: data,
			success(res) {
				if (res.statusCode === 200) {
                    // 401
                    if (res.data.code == 401) {
						console.log(res.data,'401')
						// uni.clearStorage();
						// uni.removeStorageSync('access-token');
						
                    }
					resolve(res);
                } else {
                    reject(res);
                }
			},
			fail(err) {
				console.log(err.errMsg)
				reject(err)
			}
		})
	})
}