This repository has been archived by the owner on Nov 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
8,060 additions
and
5 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,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 | ||
}); | ||
} |
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,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 | ||
}); | ||
} |
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,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 | ||
}); | ||
} |
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,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> |
Oops, something went wrong.