fetch.js 2 KB
import configApi from './configApi'

// 第一种写法
export function fetch(method = 'GET', url, params = null, headers = {}) {
	method = method.toLocaleUpperCase();
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: method,
			data: params,
			header: headers,
			success: (res) => {
				resolve(res)
			},
			fail: (err) => {
				reject(err);
			}
		})
	})
}

// 第二种写法
// 接口基类
const http = (options) => {
	const { method = 'get', data, url, headers = {} } = options;
	method = method.toLocaleUpperCase();
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: method,
			data: data,
			header: headers,
			success: (res) => {
				resolve(res)
			},
			fail: (err) => {
				reject(err);
			}
		})
	})
}

export default {
	// 接口应用层
	// 集团列表
	loadAccountList({ method, data, headers }) {
		return http({
			url: configApi.LOAD_ACCOUNT_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 商场列表
	loadMallList(method, data, headers) {
		return http({
			url: configApi.LOAD_MALL_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 楼层列表
	loadFloorList(method, data, headers) {
		return http({
			url: configApi.LOAD_FLOOR_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 店铺列表
	loadZoneList(method, data, headers) {
		return http({
			url: configApi.LOAD_ZONE_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 监控点列表
	loadGateList(method, data, headers) {
		return http({
			url: configApi.LOAD_GATE_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 字典列表
	loadDictList(method, data, headers) {
		return http({
			url: configApi.LOAD_DICT_LIST,
			method: method,
			data: data,
			headers: headers
		})
	},
	// 抓拍记录列表
	loadFacerecognitionList(method, data, headers) {
		return http({
			url: configApi.LOAD_FACERECOGNITION_LIST,
			method: method,
			data: data,
			headers: headers
		})
	}
}