Skip to content

Commit 20ca58d

Browse files
committed
update
1 parent c53685c commit 20ca58d

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

controllers/key.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ module.exports = {
1414
await next();
1515
},
1616

17+
async getAllEmptyKeysCount(ctx, next) {
18+
try {
19+
const data = await Key.findAllByEmail(null)
20+
ctx.body = { msg: 1001, data }
21+
} catch (err) {
22+
ctx.body = { code: -1, msg: 1000, }
23+
}
24+
await next();
25+
},
26+
1727
async createKey(ctx, next) {
1828
const req = ctx.request.body
1929
if (!req.key) {

models/key.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ class Key extends Model {
5555
})
5656
}
5757

58+
/**
59+
* @description: 根据email查找所有key
60+
* @param {*} id
61+
* @return {*}
62+
*/
63+
static async findAllByEmail(email){
64+
return await this.findAndCountAll({
65+
where: {
66+
email
67+
}
68+
})
69+
}
70+
5871
}
5972
// 初始化表结构
6073
Key.init(

routes/key.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const Key = require('../controllers/key')
33

44
router.get('/getAllKeys', Key.getAllKeys)
55

6+
router.get('/getAllEmptyKeysCount', Key.getAllEmptyKeysCount)
7+
68
router.post('/createKey', Key.createKey)
79

810
router.post('/sendKey', Key.sendKey)

src/App.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<li>最终解释权归金庸群侠传3D重制版开源社区所有。</li>
1010
</ul>
1111
</a-form-item>
12+
<a-form-item label="剩余码数">
13+
{{ count }}
14+
</a-form-item>
1215
<a-form-item v-for="(question, index) in questions" :key="question.id" :label="`题目${index + 1}`">
1316
<div>{{ question.topic }}</div>
1417
<a-radio-group v-model="answers[index]">
@@ -58,21 +61,30 @@
5861
</template>
5962

6063
<script>
61-
import 'no-debugger'
64+
// import 'no-debugger'
6265
import axios from 'axios'
6366
export default {
6467
name: 'App',
6568
data() {
6669
return {
6770
questions: [],
6871
answers: [],
69-
form: this.$form.createForm(this)
72+
form: this.$form.createForm(this),
73+
count: 0
7074
}
7175
},
7276
mounted() {
77+
this.handleAllEmptyKeysCount()
7378
this.handleQuestion()
7479
},
7580
methods: {
81+
handleAllEmptyKeysCount() {
82+
axios.get('/api/getAllEmptyKeysCount')
83+
.then((response) => {
84+
const { data: { data: { count } } } = response
85+
this.count = count
86+
})
87+
},
7688
handleQuestion() {
7789
axios.get('/api/getAllQuestions')
7890
.then((response) => {

0 commit comments

Comments
 (0)