Commit 5b1cad8c authored by haiyoucuv's avatar haiyoucuv

init

parent eab6b9df
// 【开发环境】 // 【开发环境】
export const devOptions = { export const devOptions = {
BASE_URL: 'https://activity.m.duibadev.com.cn/', BASE_URL: 'https://activity.m.duibadev.com.cn/',
appKey: 'jlg88lyxz7siqtmr', appKey: 'jlg88lyxz7siqtmr',
} }
// 【测试环境】 // 【测试环境】
export const testOptions = { export const testOptions = {
BASE_URL: 'https://activity.m.duibatest.com.cn/', BASE_URL: 'https://activity.m.duibatest.com.cn/',
appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA', appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA',
projectId: "test",
} }
// 【预发环境】 // 【预发环境】
export const prevOptions = { export const prevOptions = {
BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境 BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6', appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "prev",
} }
// 【线上环境】 // 【线上环境】
export const publishOptions = { export const publishOptions = {
BASE_URL: 'https://activity.m.duiba.com.cn/', BASE_URL: 'https://activity.m.duiba.com.cn/',
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6', appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "publish",
} }
export default publishOptions export default publishOptions;
\ No newline at end of file
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'; import env from './config';
const headersConfig = { 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) => { type IReqMethod = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
const method = config.method.toUpperCase() || 'GET';
const { BASE_URL } = env; interface IReqConfig {
url: string;
wx.request({ headers?: object;
method, data?: object;
url: config.url ? `${BASE_URL}${config.url}` : '', method?: IReqMethod;
data: config.data, }
header: {
...headersConfig, let loginToken: string = "";
...config.headers
}, export const request = (config: IReqConfig) => new Promise((resolve, reject) => {
success(response) { const {BASE_URL, projectId} = env;
if (+response.statusCode === 200) {
resolve(response.data); const {url, headers, data, method = "GET"} = config;
} else {
reject(new Error(`请求失败 statusCode: ${response.statusCode}`)); const type = (method.toUpperCase() as IReqMethod) || 'GET';
}
}, const header = {
fail(error) { ...headersConfig,
reject(new Error(error.errMsg)); ...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