[U] update recipe detail page

This commit is contained in:
Ching 2021-09-08 00:28:31 +08:00
parent 0cfb215133
commit 30fa1f19bb
3 changed files with 81 additions and 12 deletions

View File

@ -54,7 +54,9 @@
<el-input type="textarea" v-model="form.note"></el-input> <el-input type="textarea" v-model="form.note"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit">提交</el-button> <el-button type="primary" @click="onSubmit(recipe_id)"
>提交</el-button
>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
@ -77,10 +79,11 @@ export default {
rules: { rules: {
name: [{ required: true, trigger: 'blur', message: '输入菜名' }], name: [{ required: true, trigger: 'blur', message: '输入菜名' }],
}, },
recipe_id: null,
}; };
}, },
methods: { methods: {
onSubmit() { onSubmit(recipe_id) {
let data = { let data = {
name: this.form.name, name: this.form.name,
recipe_type: this.form.recipe_type, recipe_type: this.form.recipe_type,
@ -88,6 +91,7 @@ export default {
rate: this.form.rate, rate: this.form.rate,
note: this.form.note, note: this.form.note,
}; };
if (!recipe_id) {
axios axios
.post('//localhost:8000/recipe/recipe/', data) .post('//localhost:8000/recipe/recipe/', data)
.then(function() { .then(function() {
@ -96,6 +100,16 @@ export default {
.catch(function(error) { .catch(function(error) {
console.log(error); console.log(error);
}); });
} else {
axios
.put('//localhost:8000/recipe/recipe/' + recipe_id, data)
.then(function() {
location.reload();
})
.catch(function(error) {
console.log(error);
});
}
}, },
}, },
}; };

View File

@ -48,6 +48,7 @@
import axios from 'axios'; import axios from 'axios';
import input_recipe from '@/components/input_recipe.vue'; import input_recipe from '@/components/input_recipe.vue';
import router from '@/router/index'; import router from '@/router/index';
import 'element-plus/dist/index.css';
// const api_root = 'localhost:8000' // const api_root = 'localhost:8000'
const type_map = { const type_map = {
vegetable: '青菜', vegetable: '青菜',
@ -115,7 +116,6 @@ export default {
}, },
}; };
</script> </script>
<style> <style>
.el-row { .el-row {
margin-bottom: 20px; margin-bottom: 20px;
@ -126,4 +126,12 @@ export default {
.el-col { .el-col {
border-radius: 4px; border-radius: 4px;
} }
.grid-content {
border-radius: 4px;
min-height: 36px;
}
.row-bg {
padding: 10px 0;
background-color: #f9fafc;
}
</style> </style>

View File

@ -1,8 +1,55 @@
<template> <template>
recipe detail <!-- <div @click="goHome()">
首页
</div> -->
<el-page-header @back="goHome" content="$recipe"></el-page-header>
<div v-if="recipe != null">
<el-row :gutter="10">
<el-col :span="6">
<el-icon :size="25"> <bowl /> </el-icon>{{ recipe.name }}
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="6" :offset="6"> 类型{{ recipe.recipe_type }} </el-col>
<el-col :span="6"> 难度{{ recipe.difficulty }} </el-col>
<el-col :span="6"> 评分{{ recipe.rate }} </el-col>
</el-row>
<el-row :gutter="10"> 备注{{ recipe.note }} </el-row>
</div>
<el-row justify="center">
<el-col :span="18">
<input_recipe :recipe-id="recipe.id"></input_recipe>
</el-col>
</el-row>
</template> </template>
<script> <script>
import axios from 'axios';
import 'element-plus/dist/index.css';
import { Bowl } from '@element-plus/icons';
import router from '@/router/index';
import input_recipe from '@/components/input_recipe.vue';
export default { export default {
name: 'RecipeDetail', name: 'RecipeDetail',
components: { Bowl, input_recipe },
data: function() {
return {
recipe: null,
};
},
mounted() {
axios
.get('//localhost:8000/recipe/recipe/' + this.$route.params.id)
.then((response) => (this.recipe = response.data));
},
methods: {
goHome() {
router.push({ name: 'Home' });
},
},
}; };
</script> </script>
<style>
@import url('//unpkg.com/element-plus/dist/index.css');
</style>