Skip to content

Commit

Permalink
delete types
Browse files Browse the repository at this point in the history
  • Loading branch information
SunYiwen committed Feb 27, 2020
1 parent bc335c8 commit d9d8d47
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 65 deletions.
49 changes: 23 additions & 26 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var usersRouter = require('./routes/users');
var blogRouter = require('./routes/blog');
var typeRouter = require('./routes/type');
var tagRouter = require('./routes/tag');
var typeDeleteRouter = require('./routes/types/delete');

var app = express();

Expand Down Expand Up @@ -36,6 +37,7 @@ app.use('/', usersRouter);
app.use('/',blogRouter);
app.use('/',typeRouter);
app.use('/',tagRouter);
app.use('/types',typeDeleteRouter)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
1 change: 0 additions & 1 deletion front-end/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ const router = new VueRouter({
base: process.env.BASE_URL,
routes
})

export default router
2 changes: 1 addition & 1 deletion front-end/src/views/admin/AdminBlog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<th scope="row">{{ index }}</th>
<td>{{ blog.id }}</td>
<td>{{ blog.title }}</td>
<td><a href="#" role="button">删除</a></td>
<td><a v-bind:href="'/admin/blogs/delete?id='+blog.id" role="button">删除</a></td>
<td><a href="#" role="button">修改</a></td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/views/admin/AdminTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<th scope="row">{{ index }}</th>
<td>{{ tag.tag_id }}</td>
<td>{{ tag.tag_name }}</td>
<td><a href="#" role="button">删除</a></td>
<td><a v-bind:href="'/admin/tags/delete?id='+tag.tag_id" role="button">删除</a></td>
<td><a href="#" role="button">修改</a></td>
</tr>
</tbody>
Expand Down
24 changes: 23 additions & 1 deletion front-end/src/views/admin/AdminTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<th scope="row">{{ index }}</th>
<td>{{ type.type_id }}</td>
<td>{{ type.type_name }}</td>
<td><a href="#" role="button">删除</a></td>
<td><a role="button" v-on:click="deleteTypes(type.type_id)">删除</a></td>
<td><a href="#" role="button">修改</a></td>
</tr>
</tbody>
Expand All @@ -44,6 +44,28 @@ export default {
.catch((err) => {
console.log(err)
})
},
methods: {
deleteTypes: function (id) {
const that = this
console.log(id)
https.fetchPost('/types/delete', {
id: id
})
.then(function (ret) {
console.log(ret.data)
if (ret.data) {
that.$router.push({
path: '/admin/types'
})
// eslint-disable-next-line no-unused-expressions
.catch(err => { err })
}
})
.catch(function (err) {
console.log(err)
})
}
}
}
Expand Down
71 changes: 36 additions & 35 deletions public/javascripts/mongodb/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,31 @@ let Passage = require('./passage')
let Type = require('./type')
let Tag = require('./tag')
let User = require('./user')
let user={
username:'syw',
password:'syw'
}
new User(user).save(function (err) {
if(err){
console.log(err)
}
else{
console.log('保存成功!')
}

})
// let tag ={
// tag_id: 4,
// tag_name: 'hhh'
// let user={
// username:'syw',
// password:'syw'
// }
// Tag.find(function (err,ret) {
// new User(user).save(function (err) {
// if(err){
// console.log(err)
// }
// else{
// console.log(ret)
// console.log('保存成功!')
// }
//
// })
// new Tag(tag).save(function (err) {
let tag ={
tag_id: 5,
tag_name: 'hhlalh'
}
// Tag.find(function (err,ret) {
// if(err){
// console.log(err)
// }
// else{
// console.log('保存成功!')
// console.log(ret)
// }
// })
// let type = {
// type_id: 3,
// type_name: 'Algorithm'
// }
// new Tag(tag).save(function (err) {
// if(err){
// console.log(err)
Expand All @@ -47,15 +35,28 @@ new User(user).save(function (err) {
// console.log('保存成功!')
// }
// })
// let type = {
// type_id: 2,
// type_name: 'Nodejs'
// }
new Tag(tag).save(function (err) {
if(err){
console.log(err)
}
else{
console.log('保存成功!')
}
})
// new Type(type).save(function (err) {
// if(err){
// console.log(err)
// console.log('hh'+err)
// }
// else{
// console.log('保存成功!')
//
// console.log('ppp')
// }
// })

// console.log('hhh')
// let passage = {
// id:5,
// content:"## 1. 什么是AJAX?\n" +
Expand All @@ -74,14 +75,14 @@ new User(user).save(function (err) {
// console.log('保存成功')
// }
// })
Passage.find(function (err,ret) {
if(err){
console.log(err);
}
else{
console.log((ret));
}
})
// Passage.find(function (err,ret) {
// if(err){
// console.log(err);
// }
// else{
// console.log((ret));
// }
// })
// Passage.updateOne({
// id:5
// },{
Expand Down
20 changes: 20 additions & 0 deletions routes/types/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let express = require('express')
let router = express.Router()
let Type = require('../../public/javascripts/mongodb/type')

router.post('/delete', function(req, res, next) {
console.log('id='+req.body.id)
Type.deleteOne({
type_id:req.body.id
})
.then(function (ret) {
console.log(ret)
res.send(true)
})
.catch(function (err) {
console.log(err)
res.send(false)
})
});

module.exports = router;

0 comments on commit d9d8d47

Please sign in to comment.