Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
feat(Question): 增加「问答」大部分功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Feb 12, 2018
1 parent ef4ea9d commit f7b4166
Show file tree
Hide file tree
Showing 24 changed files with 8,060 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
"css-loader": "^0.28.7",
"file-loader": "^1.1.6",
"lodash": "^4.17.4",
"markdown-it": "^8.4.0",
"markdown-it-plus-image": "^1.0.1",
"normalize.css": "^8.0.0",
"plus-message-bundle": "0.0.5",
"plus-message-bundle": "^1.0.0",
"store": "^2.0.12",
"swiper": "^4.1.6",
"vue": "^2.5.13",
Expand Down
59 changes: 59 additions & 0 deletions src/api/question/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import request from '../../http';

/**
* List answers by default
*
* @param {number} question
* @param {Number} offset
* @param {Number} limit
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function listByDefault(question, offset = 0, limit = 15) {
return request.get(`/questions/${question}/answers`, {
params: { offset, limit, order_type: 'default' },
validateStatus: status => status === 200
});
}

/**
* List answers by time.
*
* @param {number} question
* @param {Number} offset
* @param {Number} limit
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function listByTime(question, offset = 0, limit = 15) {
return request.get(`/questions/${question}/answers`, {
params: { offset, limit, order_type: 'time' },
validateStatus: status => status === 200
});
}

/**
* Like a answer.
*
* @param {number} answer
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function like(answer) {
return request.post(`/question-answers/${answer}/likes`, {}, {
validateStatus: status => status === 201
});
}

/**
* Unlike a answer.
*
* @param {number} answer
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function unlike(answer) {
return request.delete(`/question-answers/${answer}/likes`, {
validateStatus: status => status === 204
});
}
67 changes: 67 additions & 0 deletions src/api/question/questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import request from '../../http';

/**
* Query questions list.
*
* @param {Object} query
* @return {Promise}
* @author Seven Du <[email protected]>
*/
function queryList(query = {}) {
return request.get('/questions', {
params: query,
validateStatus: status => status === 200
});
}

/**
* All questions.
*
* @param {string} type
* @param {number} offset
* @param {number} limit
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function list(type, offset = 0, limit = 15) {
return queryList({ type, limit, offset });
}

/**
* show a question.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function show(id) {
return request.get(`/questions/${id}`, {
validateStatus: status => status === 200
});
}

/**
* Watch a question.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function watch(id) {
return request.put(`/user/question-watches/${id}`, {}, {
validateStatus: status => status === 204
});
}

/**
* unwatch a question.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function unwatch(id) {
return request.delete(`/user/question-watches/${id}`, {
validateStatus: status => status === 204
});
}
109 changes: 109 additions & 0 deletions src/api/question/topics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import request from '../../http';

/**
* The topics API query function.
*
* @param {Object} query
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function query(query = {}) {
return request.get('/question-topics', {
params: query,
validateStatus: status => status === 200
});
}

/**
* Get all topic query method.
*
* @param {Number} offset
* @param {Number} limit
* @param {Boolean} follow
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function all(offset = 0, limit = 15, follow = true) {
return query({ offset, limit, follow });
}

/**
* Search topics method.
*
* @param {String} name
* @param {Number} offset
* @param {Number} limit
* @param {Boolean} follow
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function search(name = null, offset = 0, limit = 15, follow = true) {
return query({ name, offset, limit, follow });
}

export function userQuery(query = {}) {
return request.get('/user/question-topics', {
params: query,
validateStatus: status => status === 200
});
}

export function followTopics(after = 0, limit = 15) {
return userQuery({ after, limit, type: 'follow' });
}

/**
* Follow a topic.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function follow(id) {
return request.put(`/user/question-topics/${id}`, {}, {
validateStatus: status => status === 201
});
}

/**
* Unfollow a topic.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function unfollow(id) {
return request.delete(`/user/question-topics/${id}`, {
validateStatus: status => status === 204
});
}

/**
* Show a topic.
*
* @param {number} topic
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function show(topic) {
return request.get(`/question-topics/${topic}`, {
validateStatus: status => status === 200
});
}

/**
* Fetch question by topic.
*
* @param {number} topic
* @param {string} type
* @param {number} offset
* @param {Number} limit
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function questions(topic, type, offset = 0, limit = 15) {
return request.get(`/question-topics/${topic}/questions`, {
params: { type, offset, limit },
validateStatus: status => status === 200
});
}
117 changes: 117 additions & 0 deletions src/components/modules/Avatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<template>
<div v-bind="$props" :class="rootClassName" :style="rootStyles" @click="handleClick">
<slot></slot>
</div>
</template>

<script>
export default {
/**
* The component name.
*
* @type {String}
*/
name: 'module-avatar',
/**
* The component props.
*
* @type {Object}
*/
props: {
classes: { type: [Array, String] },
size: { type: [String, Number], default: 0.4 },
sizeUnit: { type: String, default: 'rem' }
},
/**
* The component methods.
*
* @type {Object}
*/
methods: {
/**
* Class name builder.
*
* @param {string} className
* @return {string}
* @author Seven Du <[email protected]>
*/
classNameBuilder(className) {
return `module-avatar-${className}`;
},
/**
* The click handle.
*
* @param {Object} event
* @return {void}
* @author Seven Du <[email protected]>
*/
handleClick(event) {
this.$emit('click', event);
}
},
/**
* The component computed data.
*
* @type {Object}
*/
computed: {
/**
* Root element class name.
*
* @return {Array}
* @author Seven Du <[email protected]>
*/
rootClassName() {
let classes = this.classes || [];
if (typeof classes === 'string' || classes instanceof String) {
classes = [classes];
}
return ['module-avatar', ...classes];
},
/**
* Root element styles.
*
* @return {Object}
* @author Seven Du <[email protected]>
*/
rootStyles() {
let size = this.size;
if (typeof size === 'number' || size instanceof Number) {
size = size + this.sizeUnit;
}
return {
width: size,
height: size
};
}
}
};
</script>

<style lang="less">
@root: module-avatar;
.@{root} {
background-color: #999;
color: #fff;
border-radius: 100%;
display: inline-flex;
justify-content: center;
align-items: center;
font-size: 24px;
vertical-align: middle;
> * {
width: 100%;
height: 100%;
border-radius: 100%;
}
}
</style>
Loading

0 comments on commit f7b4166

Please sign in to comment.