Skip to content

Commit

Permalink
Merge pull request #22 from studygolang/nonespace
Browse files Browse the repository at this point in the history
http module
  • Loading branch information
deancn authored Mar 20, 2020
2 parents 5001ae2 + f60fbd5 commit 9007173
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build/miniprogram.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

module.exports = {
origin: 'https://mina.baobeihuijia.com',
entry: '/',
origin: 'https://studygolang.com/',
entry: '/app',
router: {
home: [
'/(home|index)?',
Expand Down
107 changes: 107 additions & 0 deletions src/api/commont.js
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)
}
2 changes: 1 addition & 1 deletion src/article/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default Vue.extend({
name: 'Article',
data() {
return {
article:{
article: {
author: {
avatar: 'http://img1.3lian.com/gif/more/11/2012/03/d037a77443c0a72a1432d815cd3b5724.jpg',
nickname: '昵称'
Expand Down
6 changes: 6 additions & 0 deletions src/home/Tabs/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script>
import Vue from 'vue'
import ListContent from '../../component/ListContent.vue'
import { getArticles } from '../../api/commont'
export default Vue.extend({
name: 'Tabs',
Expand Down Expand Up @@ -70,6 +71,11 @@ export default Vue.extend({
this.activeKey = activeKey
this.$emit('onChange', activeKey)
}
},
created() {
getArticles(1).then((res) => {
console.log(res)
})
}
})
</script>
Expand Down
34 changes: 34 additions & 0 deletions src/utils/request.js
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
}

0 comments on commit 9007173

Please sign in to comment.