-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from studygolang/nonespace
http module
- Loading branch information
Showing
5 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { get, post } from '../utils/request' | ||
|
||
export function getTotic(params) { | ||
/** | ||
* @description 获取主题 | ||
* @param {string} tab 顶部tab,如果全部,可不传或all,其他使用 node name | ||
* @param {number} p 第几页,不传代表第1页 | ||
*/ | ||
return get('/topics', params) | ||
} | ||
export function getToticDetail(tid) { | ||
/** | ||
* @description 获取主题详情 | ||
* @param {number} tid 主题id | ||
*/ | ||
return get('/topic/detail', { tid }) | ||
} | ||
|
||
export function checkSession(code) { | ||
/** | ||
* @description 检查登录 | ||
* @param {string} code 小程序登录code | ||
*/ | ||
return get('/wechat/check_session', { code }) | ||
} | ||
|
||
export function register(params) { | ||
/** | ||
* @description 注册系统账号并绑定 | ||
* @param {string} params.unbind_token | ||
* @param {string} params.username 用户名 | ||
* @param {string} params.email 邮箱 | ||
* @param {string} params.passwd 密码 | ||
* @param {string} params.pass2 确认密码 | ||
* @param {string} params.userInfo 小程序 wx.getUserInfo 返回的 userInfo,json 格式原样传过来 | ||
*/ | ||
return post('/wechat/register', params) | ||
} | ||
|
||
export function login(params) { | ||
/** | ||
* @description 登录 | ||
* @param {string} params.token token | ||
* @param {number} params.uid 中文网用户uid | ||
* @param {string} params.nickname 微信昵称 | ||
* @param {string} params.avatar 微信头像 | ||
*/ | ||
return get('/wechat/login', params) | ||
} | ||
|
||
export function getArticles(p) { | ||
/** | ||
* @description 文章列表 | ||
* @param {number} p token | ||
*/ | ||
return get('/articles', { p }) | ||
} | ||
|
||
export function articleDetail(id) { | ||
/** | ||
* @description 文章详情 | ||
* @param {number} id | ||
*/ | ||
return get('/article/detail', { id }) | ||
} | ||
|
||
export function getSources(p) { | ||
/** | ||
* @description 资源列表 | ||
* @param {number} p | ||
*/ | ||
return get('/resources', { p }) | ||
} | ||
|
||
export function getSourceDetail(id) { | ||
/** | ||
* @description 资源详情 | ||
* @param {number} id | ||
*/ | ||
return get('/resource/detail', { id }) | ||
} | ||
|
||
export function getProjects(p) { | ||
/** | ||
* @description 项目列表 | ||
* @param {number} p | ||
*/ | ||
return get('/projects', { p }) | ||
} | ||
|
||
export function getProjectDetail(id) { | ||
/** | ||
* @description 项目详情 | ||
* @param {number} id | ||
*/ | ||
return get('/project/detail', { id }) | ||
} | ||
|
||
export function comment(objid, data) { | ||
/** | ||
* @description 提交评论 | ||
* @param {number} objid | ||
* @param {number} data.objtype 0-主题;1-文章;2-资源;3-wiki;4-开源项目;5-图书; | ||
* @param {string} data.content | ||
*/ | ||
return post(`comment/${objid}`, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
const baseUrl = 'https://studygolang.com/app' | ||
function request({ url, data, method }) { | ||
const header = { | ||
token: wx.getStorageSync('token') || '', | ||
} | ||
return new Promise((resove, reject) => { | ||
wx.request({ | ||
url: baseUrl + url, | ||
method, | ||
data: { ...data, from: 4 }, | ||
header, | ||
success: (res) => { | ||
resove(res.data) | ||
}, | ||
fail: (res) => { | ||
reject(res) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function get(url, data) { | ||
return request({ url, method: 'get', data }) | ||
} | ||
function post(url, data) { | ||
return request({ url, method: 'post', data }) | ||
} | ||
|
||
export { | ||
request, | ||
get, | ||
post | ||
} |