Commit 6496fc47 authored by 谢卓城's avatar 谢卓城

完善:1.调整目录结构. 2.网络请求添加业务层

parent e02455fd
......@@ -12,4 +12,3 @@ dist
# Node.js
node_modules/
package/node_modules
dist/miniprogram_npm
......@@ -16,8 +16,8 @@
"un": "sh ./package/package.sh -d 0 -u 1 -p",
"page": "gulp new -i 0 -p",
"page:i": "gulp new -p",
"component": "gulp new -i 0 -c",
"component:i": "gulp new -c"
"ct": "gulp new -i 0 -c",
"ct:i": "gulp new -c"
},
"keywords": [],
"author": "",
......
const { axiosPost, axiosGet } = require("../utils/request.js");
/**
* test
* @returns {*|Promise|Promise<unknown>}
*/
const postTest = params => {
return axiosPost({
url: "page/test",
data: params
});
};
/**
* test
* @returns {*|Promise|Promise<unknown>}
*/
const getData = () => {
return axiosGet({
url: "/shakespeare/notes/28193853/user_notes"
});
};
module.exports = {
getData
};
\ No newline at end of file
//app.js
const Request = require("./utils/request.js");
App({
onLaunch: function() {
// 初始化axios
......@@ -37,35 +35,6 @@ App({
}
});
},
_get(url, successCall, failCall) {
wx.showNavigationBarLoading();
Request.axiosGet(
url,
res => {
wx.hideNavigationBarLoading();
successCall && successCall(res);
},
err => {
wx.hideNavigationBarLoading();
failCall && failCall(err);
}
);
},
_post(url, data, successCall, failCall) {
wx.showNavigationBarLoading();
Request.axiosPost(
url,
data,
res => {
wx.hideNavigationBarLoading();
successCall && successCall(res);
},
err => {
wx.hideNavigationBarLoading();
failCall && failCall(err);
}
);
},
globalData: {
userInfo: null
}
......
@import './styles/common.scss';
@import './scss/variables.scss';
@import './scss/style.scss';
@import './assets/styles/common.scss';
@import './assets/styles/variables.scss';
@import './assets/styles/style.scss';
.container{
width: 100%;
......
@import '../scss/style.scss';
@import './style.scss';
$colors: (
"themeColor": #8FBC8F,
......
// copy changein -> common/scss/style
@import '../scss/variables.scss';
@import './variables.scss';
.flex-1 {
flex: 1;
......
......@@ -5,7 +5,7 @@ import axios from "nmaxios";
* 初始化网络配置,会覆盖默认配置
*/
function initAxios() {
const baseUrl = API_URL.host + "/shakespeare/notes/28193853/user_notes";
const baseUrl = API_URL.host;
const header = {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
};
......@@ -47,47 +47,49 @@ function initAxios() {
});
}
/**
* axios的Get请求
* @param {url} url
* @param {successCall} 成功回调
* @param {failCall} 失败回调
*/
function axiosGet(url, successCall, failCall) {
axios
.get(url)
.then(res => {
// console.log("发起get请求-res", res);
successCall && successCall(res);
})
.catch(err => {
// console.log("发起get请求-err", err);
failCall && failCall(err);
const req = {
/**
* axios的Get请求
* @param {url} url
*/
get(opts) {
return new Promise((resolve, reject) => {
axios
.get(opts.url)
.then(res => {
// console.log("发起get请求-res", res);
resolve(res);
})
.catch(err => {
// console.log("发起get请求-err", err);
reject(err);
});
});
}
},
/**
* axios的Post请求
* @param {url} url
* @param {data} 参数
* @param {successCall} 成功回调
* @param {failCall} 失败回调
*/
function axiosPost(url, data, successCall, failCall) {
axios
.post(url, data)
.then(res => {
// console.log("发起post请求-res", res);
successCall && successCall(res);
})
.catch(err => {
// console.log("发起post请求-err", err);
failCall && failCall(err);
/**
* axios的Post请求
* @param {url} url
* @param {data} 参数
*/
post(opts) {
return new Promise((resolve, reject) => {
axios
.post(opts.url, opts.data)
.then(res => {
// console.log("发起post请求-res", res);
resolve(res);
})
.catch(err => {
// console.log("发起post请求-err", err);
reject(err);
});
});
}
}
};
module.exports = {
initAxios,
axiosGet,
axiosPost
axiosGet: req.get,
axiosPost: req.post
};
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