Skip to content

Commit f5e1385

Browse files
committed
feat: show form stat results; (zh) 显示表单统计结果
1 parent 79ec52a commit f5e1385

File tree

9 files changed

+177
-24
lines changed

9 files changed

+177
-24
lines changed

back-end/h5-api/api/work/config/routes.json

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"policies": []
99
}
1010
},
11+
{
12+
"method": "GET",
13+
"path": "/works/has-forms",
14+
"handler": "Work.queryWorksWithForms",
15+
"config": {
16+
"policies": []
17+
}
18+
},
1119
{
1220
"method": "GET",
1321
"path": "/works",

back-end/h5-api/api/work/controllers/Work.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/*
22
* @Author: ly525
33
* @Date: 2019-12-04 19:55:24
4-
* @LastEditors: ly525
5-
* @LastEditTime: 2019-12-15 18:56:44
4+
* @LastEditors : ly525
5+
* @LastEditTime : 2019-12-21 19:32:05
66
* @FilePath: /luban-h5/back-end/h5-api/api/work/controllers/Work.js
77
* @Github: https://github.com/ly525/luban-h5
88
* @Description:
99
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
1010
*/
1111
'use strict';
1212
const request = require('request');
13+
const _ = require('lodash');
1314

1415
/**
1516
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html#core-controllers)
@@ -52,8 +53,7 @@ module.exports = {
5253
const work = await strapi.services.work.findOne(ctx.params);
5354

5455
// learn the query from: https://github.com/strapi/foodadvisor/blob/master/api/api/restaurant/controllers/Restaurant.js#L40
55-
// eslint-disable-next-line no-undef
56-
let formRecords = await Workform.query(qb => {
56+
let formRecords = await strapi.services.workform.query(qb => {
5757
qb.where('work', '=', work.id);
5858
}).fetchAll();
5959
formRecords = formRecords.toJSON();
@@ -62,6 +62,26 @@ module.exports = {
6262
// eslint-disable-next-line require-atomic-updates
6363
return ctx.body = { uuidMap2Name, formRecords };
6464
},
65+
queryWorksWithForms: async (ctx) => {
66+
let formRecords = await strapi.services.workform.fetchAll({
67+
withRelated: [
68+
{'work': qb => qb.column('id') }
69+
],
70+
columns: ['id', 'work']
71+
});
72+
formRecords = formRecords.toJSON();
73+
const groupedFormRecords = _.groupBy(formRecords, 'work.id');
74+
75+
let workRecords = await strapi.services.work.fetchAll({
76+
columns: ['id', 'title']
77+
});
78+
workRecords = workRecords.toJSON().map(work => ({
79+
...work,
80+
form_count: groupedFormRecords[work.id].length
81+
})).filter(work => work.form_count);
82+
83+
return ctx.body = workRecords;
84+
},
6585
setAsTemplate: async (ctx) => {
6686
const work = await strapi.services.work.findOne(ctx.params);
6787

back-end/h5-api/api/work/documentation/1.0.0/work.json

+57
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,63 @@
5757
"parameters": []
5858
}
5959
},
60+
"/works/has-forms": {
61+
"get": {
62+
"deprecated": false,
63+
"description": "",
64+
"responses": {
65+
"200": {
66+
"description": "response",
67+
"content": {
68+
"application/json": {
69+
"schema": {
70+
"properties": {
71+
"foo": {
72+
"type": "string"
73+
}
74+
}
75+
}
76+
}
77+
}
78+
},
79+
"403": {
80+
"description": "Forbidden",
81+
"content": {
82+
"application/json": {
83+
"schema": {
84+
"$ref": "#/components/schemas/Error"
85+
}
86+
}
87+
}
88+
},
89+
"404": {
90+
"description": "Not found",
91+
"content": {
92+
"application/json": {
93+
"schema": {
94+
"$ref": "#/components/schemas/Error"
95+
}
96+
}
97+
}
98+
},
99+
"default": {
100+
"description": "unexpected error",
101+
"content": {
102+
"application/json": {
103+
"schema": {
104+
"$ref": "#/components/schemas/Error"
105+
}
106+
}
107+
}
108+
}
109+
},
110+
"summary": "",
111+
"tags": [
112+
"Work"
113+
],
114+
"parameters": []
115+
}
116+
},
60117
"/works": {
61118
"get": {
62119
"deprecated": false,

back-end/h5-api/extensions/documentation/documentation/1.0.0/full_documentation.json

+58-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"name": "Apache 2.0",
1515
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
1616
},
17-
"x-generation-date": "12/16/2019 8:50:56 AM"
17+
"x-generation-date": "12/16/2019 10:29:14 PM"
1818
},
1919
"x-strapi-config": {
2020
"path": "/documentation",
@@ -101,6 +101,63 @@
101101
"parameters": []
102102
}
103103
},
104+
"/works/has-forms": {
105+
"get": {
106+
"deprecated": false,
107+
"description": "",
108+
"responses": {
109+
"200": {
110+
"description": "response",
111+
"content": {
112+
"application/json": {
113+
"schema": {
114+
"properties": {
115+
"foo": {
116+
"type": "string"
117+
}
118+
}
119+
}
120+
}
121+
}
122+
},
123+
"403": {
124+
"description": "Forbidden",
125+
"content": {
126+
"application/json": {
127+
"schema": {
128+
"$ref": "#/components/schemas/Error"
129+
}
130+
}
131+
}
132+
},
133+
"404": {
134+
"description": "Not found",
135+
"content": {
136+
"application/json": {
137+
"schema": {
138+
"$ref": "#/components/schemas/Error"
139+
}
140+
}
141+
}
142+
},
143+
"default": {
144+
"description": "unexpected error",
145+
"content": {
146+
"application/json": {
147+
"schema": {
148+
"$ref": "#/components/schemas/Error"
149+
}
150+
}
151+
}
152+
}
153+
},
154+
"summary": "",
155+
"tags": [
156+
"Work"
157+
],
158+
"parameters": []
159+
}
160+
},
104161
"/works": {
105162
"get": {
106163
"deprecated": false,

back-end/h5-api/extensions/documentation/public/index.html

+1-1
Large diffs are not rendered by default.

front-end/h5/src/store/modules/work.js

+10
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ export const actions = {
7979
customRequest: strapi.getEntries.bind(strapi)
8080
}).get('works', { is_template: false })
8181
},
82+
fetchWorksWithForms ({ commit, dispatch, state }, workId) {
83+
new AxiosWrapper({
84+
dispatch,
85+
commit,
86+
name: 'editor/setWorks',
87+
loading_name: 'fetchWorks_loading',
88+
successMsg: '获取作品列表成功',
89+
customRequest: strapi.getEntries.bind(strapi)
90+
}).get('works/has-forms', { is_template: false })
91+
},
8292
fetchWorkTemplates ({ commit, dispatch, state }, workId) {
8393
new AxiosWrapper({
8494
dispatch,

front-end/h5/src/views/work-manager/form-stat/column.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ export const columns = [
1010
dataIndex: 'title',
1111
key: 'title'
1212
},
13-
{
14-
title: 'PV',
15-
dataIndex: 'pv',
16-
key: 'pv'
17-
},
18-
{
19-
title: 'Uv',
20-
dataIndex: 'uv',
21-
key: 'uv'
22-
},
13+
// {
14+
// title: 'PV',
15+
// dataIndex: 'pv',
16+
// key: 'pv'
17+
// },
18+
// {
19+
// title: 'Uv',
20+
// dataIndex: 'uv',
21+
// key: 'uv'
22+
// },
2323
{
2424
// i18n for title
25-
title: 'Form Count',
25+
title: 'Forms',
2626
key: 'formCount',
27-
dataIndex: 'formCount'
27+
dataIndex: 'formCount',
28+
align: 'center'
2829
},
2930
{
3031
title: 'Action',

front-end/h5/src/views/work-manager/form-stat/index.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
* @Author: ly525
33
* @Date: 2019-11-24 18:51:58
4-
* @LastEditors: ly525
5-
* @LastEditTime: 2019-12-08 15:28:33
4+
* @LastEditors : ly525
5+
* @LastEditTime : 2019-12-21 19:19:38
66
* @FilePath: /luban-h5/front-end/h5/src/views/work-manager/form-stat/index.vue
77
* @Github: https://github.com/ly525/luban-h5
88
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
@@ -28,13 +28,13 @@ export default {
2828
title: w.title,
2929
pv: w.pv || 0,
3030
uv: w.uv || 0,
31-
formCount: w.formCount || 0
31+
formCount: w.form_count || 0
3232
}))
3333
}
3434
},
3535
methods: {
3636
...mapActions('editor', [
37-
'fetchWorks'
37+
'fetchWorksWithForms'
3838
])
3939
},
4040
render (h) {
@@ -60,7 +60,7 @@ export default {
6060
)
6161
},
6262
created () {
63-
this.fetchWorks()
63+
this.fetchWorksWithForms()
6464
}
6565
}
6666
</script>

front-end/h5/src/views/work-manager/list.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const AddNewCard = {
8484
render (h, { props, parent }) {
8585
return (
8686
<a-card hoverable>
87-
<div slot="cover" class="flex-center" style="height: 415px;background: #f7f5f557;" onClick={props.handleCreate}>
87+
<div slot="cover" class="flex-center" style="height: 405px;background: #f7f5f557;" onClick={props.handleCreate}>
8888
<a-icon type="plus" />
8989
</div>
9090
<template class="ant-card-actions" slot="actions">

0 commit comments

Comments
 (0)