feat(daily recipe api; daily recipe page): [A] 每日菜谱接口增加修改功能 [M] 修改每日菜谱页面
[A] 每日菜谱接口增加修改功能 [M] 修改每日菜谱页面 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
93bee3544a
commit
982df005a1
2
frontend/dist/index.html
vendored
2
frontend/dist/index.html
vendored
@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>frontend</title><link href="/css/app.0786e41a.css" rel="preload" as="style"><link href="/css/chunk-vendors.8823d44d.css" rel="preload" as="style"><link href="/js/app.df0986dc.js" rel="preload" as="script"><link href="/js/chunk-vendors.bb844861.js" rel="preload" as="script"><link href="/css/chunk-vendors.8823d44d.css" rel="stylesheet"><link href="/css/app.0786e41a.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.bb844861.js"></script><script src="/js/app.df0986dc.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>frontend</title><link href="/css/app.0786e41a.css" rel="preload" as="style"><link href="/css/chunk-vendors.8823d44d.css" rel="preload" as="style"><link href="/js/app.3102fbaf.js" rel="preload" as="script"><link href="/js/chunk-vendors.bb844861.js" rel="preload" as="script"><link href="/css/chunk-vendors.8823d44d.css" rel="stylesheet"><link href="/css/app.0786e41a.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.bb844861.js"></script><script src="/js/app.3102fbaf.js"></script></body></html>
|
||||
2
frontend/dist/js/app.3102fbaf.js
vendored
Normal file
2
frontend/dist/js/app.3102fbaf.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
frontend/dist/js/app.3102fbaf.js.map
vendored
Normal file
1
frontend/dist/js/app.3102fbaf.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
frontend/dist/js/app.df0986dc.js
vendored
2
frontend/dist/js/app.df0986dc.js
vendored
File diff suppressed because one or more lines are too long
1
frontend/dist/js/app.df0986dc.js.map
vendored
1
frontend/dist/js/app.df0986dc.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1,61 +1,61 @@
|
||||
<template>
|
||||
<el-table border :data="daily_recipe">
|
||||
<el-table-column prop="meat" label="肉">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
id="meal"
|
||||
v-for="recipe in scope.row.meat"
|
||||
:key="recipe.name"
|
||||
closable
|
||||
size="small"
|
||||
<el-select v-model="meat" multiple size="mini" placeholder="选个肉">
|
||||
<el-option
|
||||
v-for="recipe in meat_recipe"
|
||||
:key="recipe.id"
|
||||
:label="recipe.name"
|
||||
:value="recipe.id"
|
||||
>
|
||||
<router-link
|
||||
:to="{ name: 'RecipeDetail', params: { id: recipe.id } }"
|
||||
>{{ recipe.name }}</router-link
|
||||
>
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-table-column>
|
||||
<el-table-column prop="vegetable" label="菜">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
id="meal"
|
||||
v-for="recipe in scope.row.vegetable"
|
||||
:key="recipe.name"
|
||||
closable
|
||||
size="small"
|
||||
<el-select v-model="vegetable" multiple size="mini" placeholder="选个菜">
|
||||
<el-option
|
||||
v-for="recipe in vegetable_recipe"
|
||||
:key="recipe.id"
|
||||
:label="recipe.name"
|
||||
:value="recipe.id"
|
||||
>
|
||||
<router-link
|
||||
:to="{ name: 'RecipeDetail', params: { id: recipe.id } }"
|
||||
>{{ recipe.name }}</router-link
|
||||
>
|
||||
</el-tag>
|
||||
</template></el-table-column
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-table-column>
|
||||
<el-table-column prop="soup" label="汤">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
id="meal"
|
||||
v-for="recipe in scope.row.soup"
|
||||
:key="recipe.name"
|
||||
closable
|
||||
size="small"
|
||||
><router-link
|
||||
:to="{ name: 'RecipeDetail', params: { id: recipe.id } }"
|
||||
>{{ recipe.name }}</router-link
|
||||
></el-tag
|
||||
<el-select v-model="soup" multiple size="mini" placeholder="选个汤">
|
||||
<el-option
|
||||
v-for="recipe in soup_recipe"
|
||||
:key="recipe.id"
|
||||
:label="recipe.name"
|
||||
:value="recipe.id"
|
||||
>
|
||||
</template></el-table-column
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
class="re-generate"
|
||||
@click="reGenerateRecipe()"
|
||||
>
|
||||
重新生成
|
||||
</el-button>
|
||||
<el-row gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
class="re-generate"
|
||||
@click="reGenerateRecipe()"
|
||||
>
|
||||
重新生成
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
class="re-generate"
|
||||
@click="submitRecipe()"
|
||||
>
|
||||
提交
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -68,28 +68,30 @@ export default {
|
||||
daily_recipe: [],
|
||||
inputVisible: false,
|
||||
inputValue: null,
|
||||
meat_recipe: [],
|
||||
meat: [],
|
||||
vegetable_recipe: [],
|
||||
vegetable: [],
|
||||
soup_recipe: [],
|
||||
soup: [],
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.getDailyRecipy(),
|
||||
axios
|
||||
.get(
|
||||
config.publicPath + '/recipe/recipe/?recipe_type=meat&page_size=500'
|
||||
)
|
||||
.then((response) => (this.meat_recipe = response.data.results));
|
||||
axios
|
||||
.get(config.publicPath + '/recipe/daily-recipe/' + this.$route.params.id)
|
||||
.then((response) => {
|
||||
var data = {
|
||||
meat: [],
|
||||
vegetable: [],
|
||||
soup: [],
|
||||
};
|
||||
for (let i = 0; i < response.data.recipes.length; i++) {
|
||||
if (response.data.recipes[i].recipe_type == 'meat') {
|
||||
data.meat.push(response.data.recipes[i]);
|
||||
} else if (response.data.recipes[i].recipe_type == 'vegetable') {
|
||||
data.vegetable.push(response.data.recipes[i]);
|
||||
} else if (response.data.recipes[i].recipe_type == 'soup') {
|
||||
data.soup.push(response.data.recipes[i]);
|
||||
}
|
||||
}
|
||||
this.daily_recipe = [data];
|
||||
});
|
||||
.get(
|
||||
config.publicPath +
|
||||
'/recipe/recipe/?recipe_type=vegetable&page_size=500'
|
||||
)
|
||||
.then((response) => (this.vegetable_recipe = response.data.results));
|
||||
axios
|
||||
.get(config.publicPath + '/recipe/recipe/?recipe_type=soup&page_size=500')
|
||||
.then((response) => (this.soup_recipe = response.data.results));
|
||||
},
|
||||
methods: {
|
||||
reGenerateRecipe() {
|
||||
@ -97,25 +99,44 @@ export default {
|
||||
.post(
|
||||
config.publicPath + '/recipe/daily-recipe/' + this.$route.params.id
|
||||
)
|
||||
.then((response) => {
|
||||
response;
|
||||
return axios.get(
|
||||
config.publicPath + '/recipe/daily-recipe/' + this.$route.params.id
|
||||
);
|
||||
})
|
||||
.then((response) => (response, this.getDailyRecipy()));
|
||||
},
|
||||
submitRecipe() {
|
||||
console.log(this.meat, this.vegetable, this.soup);
|
||||
axios.put(
|
||||
config.publicPath + '/recipe/daily-recipe/' + this.$route.params.id,
|
||||
{
|
||||
meat: this.meat,
|
||||
vegetable: this.vegetable,
|
||||
soup: this.soup,
|
||||
}
|
||||
);
|
||||
},
|
||||
getDailyRecipy() {
|
||||
axios
|
||||
.get(
|
||||
config.publicPath + '/recipe/daily-recipe/' + this.$route.params.id
|
||||
)
|
||||
.then((response) => {
|
||||
var data = {
|
||||
meat: [],
|
||||
vegetable: [],
|
||||
soup: [],
|
||||
};
|
||||
this.meat = [];
|
||||
this.vegetable = [];
|
||||
this.soup = [];
|
||||
|
||||
for (let i = 0; i < response.data.recipes.length; i++) {
|
||||
if (response.data.recipes[i].recipe_type == 'meat') {
|
||||
data.meat.push(response.data.recipes[i]);
|
||||
this.meat.push(response.data.recipes[i]['id']);
|
||||
} else if (response.data.recipes[i].recipe_type == 'vegetable') {
|
||||
data.vegetable.push(response.data.recipes[i]);
|
||||
this.vegetable.push(response.data.recipes[i]['id']);
|
||||
} else if (response.data.recipes[i].recipe_type == 'soup') {
|
||||
data.soup.push(response.data.recipes[i]);
|
||||
this.soup.push(response.data.recipes[i]['id']);
|
||||
}
|
||||
}
|
||||
this.daily_recipe = [data];
|
||||
|
||||
@ -79,4 +79,15 @@ class DailyRecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
daily_recipe = recipe.models.DailyRecipe.objects.get(id=kwargs['pk'])
|
||||
daily_recipe.generate_recipe()
|
||||
return Response({}, status=status.HTTP_201_CREATED, headers={})
|
||||
return Response(daily_recipe.serialize(), status=status.HTTP_201_CREATED,
|
||||
headers={})
|
||||
|
||||
def put(self, request, *args, **kwargs):
|
||||
daily_recipe = recipe.models.DailyRecipe.objects.get(id=kwargs['pk'])
|
||||
recipes = request.data.get('meat',[])
|
||||
recipes.extend(request.data.get('vegetable', []))
|
||||
recipes.extend(request.data.get('soup', []))
|
||||
daily_recipe.recipes.set(recipe.models.Recipe.objects.filter(
|
||||
id__in=recipes))
|
||||
return Response(daily_recipe.serialize(), status=status.HTTP_201_CREATED,
|
||||
headers={})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user