Skip to content

Commit

Permalink
feat: show custom cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Aug 19, 2023
1 parent 98123b0 commit 94a9ff5
Show file tree
Hide file tree
Showing 25 changed files with 333 additions and 20 deletions.
5 changes: 1 addition & 4 deletions components/TheBottomMenu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts" setup>
import type { BottomMenuItem } from '@yunlefun/vue'
import { ref } from 'vue'
const items: BottomMenuItem[] = [
{
Expand Down Expand Up @@ -38,9 +37,7 @@ const items: BottomMenuItem[] = [
const route = useRoute()
const router = useRouter()
const active = ref(route.path)
function onClick(item: BottomMenuItem) {
active.value = item.to || ''
router.push(item.to || '/')
}
</script>
Expand All @@ -51,7 +48,7 @@ function onClick(item: BottomMenuItem) {
v-for="item in items"
:key="item.to"
:item="item"
:active="active === item.to"
:active="route.path === item.to"
@click="onClick"
/>
</YlfBottomMenu>
Expand Down
13 changes: 13 additions & 0 deletions components/common/BackBtn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts" setup>
const router = useRouter()
function back() {
router.back()
}
</script>

<template>
<YlfIconButton
icon="i-ri-arrow-left-s-line"
@click="back"
/>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ function toggleDark() {
</script>

<template>
<button class="mx-2 icon-btn hover:text-yellow-400 !outline-none" title="切换" @click="toggleDark()">
<YlfIconButton
class="icon-btn hover:text-yellow-400 !outline-none"
text-xl
title="切换" @click="toggleDark()"
>
<div i="ri-sun-line dark:ri-moon-line" />
</button>
</YlfIconButton>
</template>
31 changes: 31 additions & 0 deletions components/cookbook/CookbookCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts" setup>
import type { Cookbook } from '~/types'
defineProps<{
cookbook: Cookbook
}>()
const showDetail = ref(false)
</script>

<template>
<button
class="bg-$c-bg-alt"
h-36 w-full inline-flex cursor-pointer items-center justify-center shadow
@click="showDetail = true"
>
<slot />
</button>

<CookbookDetail
v-if="showDetail"
absolute bottom-17 left-2 right-2 top-2 z-1 overflow-hidden shadow
:cookbook="cookbook"
>
<YlfIconButton
icon="i-ri-close-line"
class="absolute right-2 top-2"
@click="showDetail = false"
/>
</CookbookDetail>
</template>
27 changes: 27 additions & 0 deletions components/cookbook/CookbookDetail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts" setup>
import type { Cookbook } from '~/types'
const props = defineProps<{
cookbook: Cookbook
}>()
const recipes = ref<Cookbook['recipes']>(props.cookbook.recipes)
onMounted(async () => {
recipes.value = (await import('../../data/recipe.json')).default
})
</script>

<template>
<div class="bg-$c-bg-alt" flex="~ col">
<h3 mt-4 font-bold>
{{ cookbook.title }}
</h3>
<sub op="90" my-3>
{{ cookbook.description }}
</sub>
<div mx-auto mt-2 p-0 border="1px" overflow-y="scroll">
<RecipeTable h="full" :recipes="recipes" />
</div>
<slot />
</div>
</template>
18 changes: 18 additions & 0 deletions components/cookbook/NewCookbookCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts" setup>
definePageMeta({
layout: 'child',
title: '新建食谱书',
})
</script>

<template>
<NuxtLink
class="bg-$c-bg-alt"
h-36 w-full inline-flex cursor-pointer items-center justify-center shadow
to="/cookbooks/new"
>
<slot>
<div i-ri-add-line />
</slot>
</NuxtLink>
</template>
46 changes: 46 additions & 0 deletions components/recipe/RecipeTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script lang="ts" setup>
import type { Recipes } from 'types'
defineProps<{
recipes: Recipes
}>()
</script>

<template>
<table
class="recipe-table bg-$c-bg"
overflow="auto" h="full"
>
<thead>
<tr>
<th />
<th>
名称
</th>
<th>
工具
</th>
<th>
材料
</th>
</tr>
</thead>
<tbody>
<RecipeTableItem
v-for="(recipe, i) in recipes"
:key="recipe.name"
:index="i" :recipe="recipe"
/>
</tbody>
</table>
</template>

<style lang="scss">
.recipe-table {
font-size: 0.8rem;
}
tr, th, td {
border: 1px solid black;
}
</style>
31 changes: 31 additions & 0 deletions components/recipe/RecipeTableItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts" setup>
import type { RecipeItem } from 'types'
defineProps<{
index: number
recipe: RecipeItem
}>()
</script>

<template>
<tr>
<td>
{{ index }}
</td>
<td>
<a
class="text-blue-500" font-bold
:href="recipe.link || `https://www.bilibili.com/video/${recipe.bv}`"
target="_blank"
>
{{ recipe.name }}
</a>
</td>
<td>
{{ recipe.tools.join('') }}
</td>
<td>
{{ recipe.stuff.join('') }}
</td>
</tr>
</template>
7 changes: 4 additions & 3 deletions components/common/YlfForm.vue → components/ylf/YlfForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="ylf-form" flex="~ col">
<div class="ylf-form" flex="~ col" rounded-md>
<slot />
</div>
</template>
Expand All @@ -8,13 +8,14 @@
.ylf-form {
background-color: var(--ylf-c-bg-alt);
border-top: 1px solid var(--ylf-c-border);
border-bottom: 1px solid var(--ylf-c-border);
border: 1px solid var(--ylf-c-border);
margin: 10px 0;
overflow: hidden;
.ylf-form-item {
border-bottom: 1px solid var(--ylf-c-border);
&:last-child {
border-bottom: none;
}
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions components/ylf/YlfIconButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts" setup>
defineProps<{
icon?: string
}>()
</script>

<template>
<button
class="ylf-icon-button hover:(bg-blue-300 bg-opacity-20)"
h-10 w-10 inline-flex items-center justify-center rounded-full
>
<slot>
<div v-if="icon" text-xl :class="icon" />
</slot>
</button>
</template>
File renamed without changes.
22 changes: 22 additions & 0 deletions layouts/child.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts" setup>
defineProps<{
title?: string
}>()
const route = useRoute()
</script>

<template>
<main class="text-center text-gray-700 dark:text-gray-200" p="t-5 b-15">
<div flex items-center justify-between>
<BackBtn ml-3 />
<h2 flex items-center justify-center text-lg>
{{ route.meta.title }}
</h2>
<DarkToggle mr-3 />
</div>

<slot />
<TheBottomMenu fixed bottom-0 left-0 right-0 />
</main>
</template>
2 changes: 1 addition & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<main class="text-center text-gray-700 dark:text-gray-200" p="t-8 b-15">
<slot />
<DarkToggle absolute right-5 top-5 />
<DarkToggle absolute right-3 top-5 />
<TheBottomMenu fixed bottom-0 left-0 right-0 />
</main>
</template>
5 changes: 5 additions & 0 deletions pages/about.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
关于
</div>
</template>
25 changes: 25 additions & 0 deletions pages/cookbooks/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts" setup>
definePageMeta({
layout: 'child',
title: '自定义菜谱',
})
const route = useRoute()
const id = computed(() => route.query.id)
</script>

<template>
<div>
<h3>
开发中,敬请期待
</h3>

<div grid="~ cols-3" gap="4" p="4">
<CookbookCard :cookbook="defaultCookbook">
默认菜谱
</CookbookCard>

<NewCookbookCard />
</div>
</div>
</template>
5 changes: 5 additions & 0 deletions pages/cookbooks/new.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
新建 Cookbook
</div>
</template>
12 changes: 12 additions & 0 deletions pages/recipes/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts" setup>
definePageMeta({
layout: 'child',
title: '菜谱 - ?',
})
</script>

<template>
<div>
asd
</div>
</template>
5 changes: 5 additions & 0 deletions pages/recipes/new.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
新建 Recipe
</div>
</template>
25 changes: 23 additions & 2 deletions pages/settings.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
<script lang="ts" setup>
const app = useAppStore()
definePageMeta({
layout: 'child',
})
</script>

<template>
<div>
<button>
<CommonHeader>
设置
</button>
</CommonHeader>

<div
class="mx-auto max-w-md w-full"
px-2
text-left
>
<YlfForm>
<YlfFormItem label="离开网页后保留选中数据">
<YlfSwitch v-model="app.settings.keepLocalData" />
</YlfFormItem>
<YlfFormItem label="更多设置,敬请期待" />
</YlfForm>
</div>
</div>
</template>

1 comment on commit 94a9ff5

@vercel
Copy link

@vercel vercel bot commented on 94a9ff5 Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cook – ./

cook-today.vercel.app
cook-yunyoujun.vercel.app
cook-git-dev-yunyoujun.vercel.app
cook.yunle.app

Please sign in to comment.