feat(daily recipe page): [A] 增加重新生成每日菜单接口
[A] 增加重新生成每日菜单接口 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
0cd1fd9358
commit
1b27f47771
@ -37,6 +37,14 @@
|
|||||||
</template></el-table-column
|
</template></el-table-column
|
||||||
>
|
>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
class="re-generate"
|
||||||
|
@click="reGenerateRecipe()"
|
||||||
|
>
|
||||||
|
重新生成
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -71,6 +79,35 @@ export default {
|
|||||||
this.daily_recipe = [data];
|
this.daily_recipe = [data];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
reGenerateRecipe() {
|
||||||
|
axios
|
||||||
|
.post('//localhost:8000/recipe/daily-recipe/' + this.$route.params.id)
|
||||||
|
.then((response) => {
|
||||||
|
response;
|
||||||
|
return axios.get(
|
||||||
|
'//localhost:8000/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];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
>
|
>
|
||||||
</template></el-table-column
|
</template></el-table-column
|
||||||
>
|
>
|
||||||
<el-table-column label="操作">
|
<el-table-column label="操作" width="80px">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button size="mini" @click="editDailyRecipe(scope.row)">
|
<el-button size="mini" @click="editDailyRecipe(scope.row)">
|
||||||
编辑
|
编辑
|
||||||
|
|||||||
@ -69,3 +69,8 @@ class DailyRecipeAPI(rest_framework.generics.RetrieveUpdateAPIView):
|
|||||||
|
|
||||||
queryset = recipe.models.DailyRecipe.objects.all()
|
queryset = recipe.models.DailyRecipe.objects.all()
|
||||||
serializer_class = recipe.serializers.DailyRecipeSerializer
|
serializer_class = recipe.serializers.DailyRecipeSerializer
|
||||||
|
|
||||||
|
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={})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user