* 对应后端的 /msg/* 所有 API
| 3 | * 对应后端的 /msg/* 所有 API |
| 4 | */ |
| 5 | class MsgService { |
| 6 | /** |
| 7 | * 取 msg(命名为 fetch 而非 get 主要是因为是远程操作) |
| 8 | * @param {String} options.author 作者名 |
| 9 | * @param {Number} options.pageIdx 目标页码(默认是第 1 页) |
| 10 | * @param {Number} options.quantity 单页请求 msg 的数量(默认每页显示 10 条) |
| 11 | * @param {Number} options.msgId |
| 12 | * @return {Promise} |
| 13 | */ |
| 14 | fetch ({ author = '', pageIdx = 1, quantity = 10, msgId } = {}) { |
| 15 | let url = '/msg/' |
| 16 | |
| 17 | if (msgId) { |
| 18 | url += msgId |
| 19 | } else { |
| 20 | url = `${url}?author=${author}&pageIdx=${pageIdx}&quantity=${quantity}` |
| 21 | } |
| 22 | |
| 23 | return xhr({ url }) |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * 新增 msg |
| 28 | * @param {Object} msgBody { title:{String}, content:{String} } |
| 29 | * @return {Promise} |
| 30 | */ |
| 31 | add (msgBody) { |
| 32 | return xhr({ |
| 33 | method: 'post', |
| 34 | url: '/msg', |
| 35 | body: msgBody |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * 修改 msg |
| 41 | * @param {Object} msgBody { title:{String}, content:{String} } |
| 42 | * @return {Promise} |
| 43 | */ |
| 44 | mod (msgBody) { |
| 45 | let msgId = msgBody.id |
| 46 | delete msgBody.msgId |
| 47 | |
| 48 | return xhr({ |
| 49 | method: 'put', |
| 50 | url: `/msg/${msgId}`, |
| 51 | body: msgBody |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * 删除 msg |
| 57 | * @param {Number} msgId |
| 58 | * @return {Promise} |
| 59 | */ |
| 60 | del (msgId) { |
| 61 | return xhr({ |
| 62 | method: 'delete', |
nothing calls this directly
no outgoing calls
no test coverage detected