chore: 导入清理前的完整工程状态(含 Capacitor 原生壳,作为回滚备份点)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import type { RecipeItem } from '~/types'
|
||||
import { useStorage } from '@vueuse/core'
|
||||
import { namespace } from '~/constants'
|
||||
|
||||
/**
|
||||
* 随机几道菜:候选跟随首页选的食材、厨具和忌口(见 recipe store 的 randomPool)
|
||||
* @param total
|
||||
*/
|
||||
export function useRandomRecipe(total: Ref<number>) {
|
||||
const rStore = useRecipeStore()
|
||||
const randomRecipes = useStorage<(RecipeItem | undefined)[]>(`${namespace}:random:recipes`, [])
|
||||
|
||||
async function random() {
|
||||
await rStore.loadRecipes()
|
||||
const pool = rStore.randomPool
|
||||
const indexes = generateRandomArray(pool.length, Math.min(total.value, pool.length))
|
||||
randomRecipes.value = indexes.map(i => pool[i]).filter(item => !!item)
|
||||
}
|
||||
|
||||
watch(total, () => {
|
||||
random()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
// 如果没有随机菜谱,就生成一次
|
||||
if (randomRecipes.value.length <= 0)
|
||||
random()
|
||||
})
|
||||
|
||||
return {
|
||||
random,
|
||||
|
||||
randomRecipes,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user