Commit 5b1cad8c authored by haiyoucuv's avatar haiyoucuv

init

parent eab6b9df
// 【开发环境】
export const devOptions = {
BASE_URL: 'https://activity.m.duibadev.com.cn/',
BASE_URL: 'https://activity.m.duibadev.com.cn/',
appKey: 'jlg88lyxz7siqtmr',
}
// 【测试环境】
export const testOptions = {
BASE_URL: 'https://activity.m.duibatest.com.cn/',
BASE_URL: 'https://activity.m.duibatest.com.cn/',
appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA',
projectId: "test",
}
// 【预发环境】
export const prevOptions = {
BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境
BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "prev",
}
// 【线上环境】
export const publishOptions = {
BASE_URL: 'https://activity.m.duiba.com.cn/',
BASE_URL: 'https://activity.m.duiba.com.cn/',
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "publish",
}
export default publishOptions
\ No newline at end of file
export default publishOptions;
export enum API_PATH {
index = "/home/coop_index.do",
activity = "/home/coop_activity.do",
login = "/wechat/jlb/login",
subscribe = "/home/coop_subscribe.do",
}
\ No newline at end of file
import env from './config';
const headersConfig = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
}
export let request = (config: any) => new Promise((resolve, reject) => {
const method = config.method.toUpperCase() || 'GET';
const { BASE_URL } = env;
wx.request({
method,
url: config.url ? `${BASE_URL}${config.url}` : '',
data: config.data,
header: {
...headersConfig,
...config.headers
},
success(response) {
if (+response.statusCode === 200) {
resolve(response.data);
} else {
reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
}
},
fail(error) {
reject(new Error(error.errMsg));
},
})
type IReqMethod = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
interface IReqConfig {
url: string;
headers?: object;
data?: object;
method?: IReqMethod;
}
let loginToken: string = "";
export const request = (config: IReqConfig) => new Promise((resolve, reject) => {
const {BASE_URL, projectId} = env;
const {url, headers, data, method = "GET"} = config;
const type = (method.toUpperCase() as IReqMethod) || 'GET';
const header = {
...headersConfig,
...headers,
loginToken,
};
const params = {
...data,
};
wx.request({
method: type,
url: `${BASE_URL}${projectId}${url}`,
data: params,
header,
success(response) {
if (+response.statusCode === 200) {
resolve(response.data);
} else {
reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
}
},
fail(error) {
reject(new Error(error.errMsg));
},
})
})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment