feat(recipe detail): 编辑详情时编辑框展示当前详情内容

编辑详情时编辑框展示当前详情内容

Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
Ching 2021-10-02 17:28:06 +08:00
parent 2d431e5bb1
commit b4fa5d9519
4 changed files with 68 additions and 14 deletions

View File

@ -62,18 +62,23 @@
</el-col> </el-col>
</el-row> </el-row>
</template> </template>
<script> <script>
import axios from 'axios'; import axios from 'axios';
export default { export default {
inject: ['reload'], props: ['recipe_'],
watch: {
recipe_(val) {
this.form = val;
this.recipe_id = val.id;
},
},
data: function() { data: function() {
return { return {
form: { form: {
name: '', name: null,
recipe_type: 'meat', recipe_type: null,
difficulty: '1', difficulty: null,
rate: '1', rate: null,
note: null, note: null,
}, },
rules: { rules: {

View File

@ -1,5 +1,38 @@
const type_map = {
vegetable: '青菜',
meat: '肉',
soup: '汤',
};
const rate_map = {
1: '🍚',
2: '🍚 🍚',
3: '🍚 🍚 🍚',
4: '🍚 🍚 🍚 🍚',
5: '🍚 🍚 🍚 🍚 🍚',
};
const difficulty_map = {
1: '⭐',
2: '⭐ ⭐',
3: '⭐ ⭐ ⭐',
4: '⭐ ⭐ ⭐ ⭐',
5: '⭐ ⭐ ⭐ ⭐ ⭐',
};
function formatRecipeType(recipe_type) {
return type_map[recipe_type];
}
function formatRate(rate) {
return rate_map[rate];
}
function formatDifficulty(difficulty) {
return difficulty_map[difficulty];
}
module.exports = { module.exports = {
RECIPE_TYPE_VEGETABLE: 'vegetable', RECIPE_TYPE_VEGETABLE: 'vegetable',
RECIPE_TYPE_META: 'meat', RECIPE_TYPE_META: 'meat',
RECIPE_TYPE_SOUP: 'soup', RECIPE_TYPE_SOUP: 'soup',
formatRecipeType,
formatDifficulty,
formatRate,
} }

View File

@ -40,7 +40,7 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row justify="center"> <el-row justify="center">
<el-col :span="18"> <input_recipe></input_recipe> </el-col> <el-col :span="18"> <input_recipe :recipe="{}"></input_recipe> </el-col>
</el-row> </el-row>
</template> </template>

View File

@ -5,17 +5,27 @@
v-bind:content="recipe.name" v-bind:content="recipe.name"
></el-page-header> ></el-page-header>
<div v-if="recipe != null"> <div v-if="recipe != null" class="content">
<el-row :gutter="10"> <el-row justify="center">
<el-col :span="8"> 类型{{ recipe.recipe_type }} </el-col> <el-col :span="18">
<el-col :span="8"> 难度{{ recipe.difficulty }} </el-col> <el-row justify="center">
<el-col :span="8"> 评分{{ recipe.rate }} </el-col> <el-col :span="8">
类型{{ constants.formatRecipeType(recipe.recipe_type) }}
</el-col>
<el-col :span="8">
难度{{ constants.formatDifficulty(recipe.difficulty) }}
</el-col>
<el-col :span="8">
评分{{ constants.formatRate(recipe.rate) }}
</el-col>
</el-row>
<el-row> 备注{{ recipe.note }} </el-row>
</el-col>
</el-row> </el-row>
<el-row :gutter="10"> 备注{{ recipe.note }} </el-row>
</div> </div>
<el-row justify="center"> <el-row justify="center">
<el-col :span="18"> <el-col :span="18">
<input_recipe :recipe-id="recipe.id"></input_recipe> <input_recipe :recipe-id="recipe.id" :recipe_="recipe"></input_recipe>
</el-col> </el-col>
</el-row> </el-row>
</template> </template>
@ -24,12 +34,14 @@ import axios from 'axios';
import 'element-plus/dist/index.css'; import 'element-plus/dist/index.css';
import router from '@/router/index'; import router from '@/router/index';
import input_recipe from '@/components/input_recipe.vue'; import input_recipe from '@/components/input_recipe.vue';
import constants from '@/utils/constants.js';
export default { export default {
name: 'RecipeDetail', name: 'RecipeDetail',
components: { input_recipe }, components: { input_recipe },
data: function() { data: function() {
return { return {
recipe: {}, recipe: {},
constants: constants,
}; };
}, },
mounted() { mounted() {
@ -47,4 +59,8 @@ export default {
<style> <style>
@import url('//unpkg.com/element-plus/dist/index.css'); @import url('//unpkg.com/element-plus/dist/index.css');
.content {
padding: 20px 10px;
}
</style> </style>