From 7f6448d0ec99c4d66c3581959645468bfd1168d6 Mon Sep 17 00:00:00 2001 From: Ching Date: Sun, 3 Oct 2021 22:35:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(week=20recipe=20page):=20[A]=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90=E6=AF=8F=E5=91=A8?= =?UTF-8?q?=E8=8F=9C=E8=B0=B1=E9=80=BB=E8=BE=91=EF=BC=9B=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [A] 增加重新生成每周菜谱逻辑;一些样式调整 Signed-off-by: Ching --- frontend/src/components/input_recipe.vue | 12 +- frontend/src/components/recipe_list.vue | 103 +++++++++++++++++ frontend/src/components/week_recipe.vue | 93 ++++++++++++++++ frontend/src/router/index.js | 8 +- frontend/src/views/home.vue | 134 +++++------------------ frontend/src/views/recipeDetail.vue | 1 + frontend/src/views/weekRecipe.vue | 34 ++++++ recipe/models.py | 3 +- recipe/views.py | 6 +- 9 files changed, 283 insertions(+), 111 deletions(-) create mode 100644 frontend/src/components/recipe_list.vue create mode 100644 frontend/src/components/week_recipe.vue create mode 100644 frontend/src/views/weekRecipe.vue diff --git a/frontend/src/components/input_recipe.vue b/frontend/src/components/input_recipe.vue index 37eea5a..0f80b62 100644 --- a/frontend/src/components/input_recipe.vue +++ b/frontend/src/components/input_recipe.vue @@ -54,7 +54,11 @@ - 提交 @@ -119,3 +123,9 @@ export default { }, }; + + diff --git a/frontend/src/components/recipe_list.vue b/frontend/src/components/recipe_list.vue new file mode 100644 index 0000000..67ce9d7 --- /dev/null +++ b/frontend/src/components/recipe_list.vue @@ -0,0 +1,103 @@ + + + diff --git a/frontend/src/components/week_recipe.vue b/frontend/src/components/week_recipe.vue new file mode 100644 index 0000000..c560990 --- /dev/null +++ b/frontend/src/components/week_recipe.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 1a5693c..0368594 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -1,6 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import Home from '@/views/home.vue' import RecipeDetail from '@/views/recipeDetail.vue' +import WeekRecipe from '@/views/weekRecipe.vue' const routes = [ { @@ -12,7 +13,12 @@ const routes = [ path: '/recipe/:id', name: "RecipeDetail", component: RecipeDetail - } + }, + { + path: '/week-recipe/', + name: "WeekRecipe", + component: WeekRecipe + }, ]; const router = createRouter({ diff --git a/frontend/src/views/home.vue b/frontend/src/views/home.vue index fc8c6ae..38422b5 100644 --- a/frontend/src/views/home.vue +++ b/frontend/src/views/home.vue @@ -1,118 +1,40 @@ diff --git a/frontend/src/views/recipeDetail.vue b/frontend/src/views/recipeDetail.vue index 15c5528..6a7f080 100644 --- a/frontend/src/views/recipeDetail.vue +++ b/frontend/src/views/recipeDetail.vue @@ -1,5 +1,6 @@ + + + + diff --git a/recipe/models.py b/recipe/models.py index 40d65d9..cbc3021 100644 --- a/recipe/models.py +++ b/recipe/models.py @@ -96,6 +96,7 @@ class DailyRecipe(models.Model): value_.append(recipe.serialize()) date = now() - date.replace(year=self.date.year, month=self.date.month, day=self.date.day,) + date = date.replace(year=self.date.year, month=self.date.month, + day=self.date.day, hour=0, minute=0) data['date'] = utils.timestamp_of(utils.day_start(date)) return data diff --git a/recipe/views.py b/recipe/views.py index a5ad0ff..8735aaa 100644 --- a/recipe/views.py +++ b/recipe/views.py @@ -42,7 +42,7 @@ class WeekRecipeListAPI(rest_framework.generics.ListAPIView, recipes = [] for x in range(0, 7-today.weekday()): daily_recipe, __ = recipe.models.DailyRecipe.objects.get_or_create( - date=today + datetime.timedelta(days=1) + date=today + datetime.timedelta(days=x) ) daily_recipe.generate_recipe() recipes.append(daily_recipe.recipes.values_list('id', flat=True)) @@ -56,7 +56,9 @@ class WeekRecipeListAPI(rest_framework.generics.ListAPIView, date__gte=week_start, date__lte=week_end, ).order_by('date') - data = [] + data = [{}] * (7 - len(daily_recipes)) + for daily_recipe in daily_recipes: data.append(daily_recipe.serialize()) + return Response(data)