feat: 更多改进 #21
@@ -20,11 +20,9 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { useOilsStore } from '../stores/oils'
|
||||
import { useRecipesStore } from '../stores/recipes'
|
||||
import { useRecipesStore, EDITOR_ONLY_TAGS } from '../stores/recipes'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
|
||||
const EDITOR_ONLY_TAGS = ['已审核']
|
||||
|
||||
const props = defineProps({
|
||||
recipe: { type: Object, required: true },
|
||||
index: { type: Number, required: true },
|
||||
|
||||
@@ -2,6 +2,8 @@ import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { api } from '../composables/useApi'
|
||||
|
||||
export const EDITOR_ONLY_TAGS = ['已审核']
|
||||
|
||||
export const useRecipesStore = defineStore('recipes', () => {
|
||||
const recipes = ref([])
|
||||
const allTags = ref([])
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div v-if="showTagFilter" class="tag-list-bar">
|
||||
<span
|
||||
v-for="tag in recipeStore.allTags"
|
||||
v-for="tag in visibleAllTags"
|
||||
:key="tag"
|
||||
class="tag-chip"
|
||||
:class="{ active: selectedTags.includes(tag) }"
|
||||
@@ -126,7 +126,7 @@
|
||||
<div class="row-info" @click="editDiaryRecipe(d)">
|
||||
<span class="row-name">{{ d.name }}</span>
|
||||
<span class="row-tags">
|
||||
<span v-for="t in (d.tags || [])" :key="t" class="mini-tag">{{ t }}</span>
|
||||
<span v-for="t in (d.tags || []).filter(t => auth.canEdit || !EDITOR_ONLY_TAGS.includes(t))" :key="t" class="mini-tag">{{ t }}</span>
|
||||
</span>
|
||||
<span class="row-cost">{{ oils.fmtPrice(oils.calcCost(d.ingredients || [])) }}</span>
|
||||
<span v-if="getDiaryShareStatus(d) === 'shared'" class="share-tag shared">已共享</span>
|
||||
@@ -165,7 +165,7 @@
|
||||
<div class="row-info" @click="editRecipe(r)">
|
||||
<span class="row-name">{{ r.name }}</span>
|
||||
<span class="row-tags">
|
||||
<span v-for="t in r.tags" :key="t" class="mini-tag">{{ t }}</span>
|
||||
<span v-for="t in (r.tags || []).filter(t => auth.canEdit || !EDITOR_ONLY_TAGS.includes(t))" :key="t" class="mini-tag">{{ t }}</span>
|
||||
</span>
|
||||
<span class="row-cost">{{ oils.fmtPrice(oils.calcCost(r.ingredients)) }}</span>
|
||||
</div>
|
||||
@@ -397,7 +397,7 @@
|
||||
import { ref, computed, reactive, onMounted, watch } from 'vue'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useOilsStore } from '../stores/oils'
|
||||
import { useRecipesStore } from '../stores/recipes'
|
||||
import { useRecipesStore, EDITOR_ONLY_TAGS } from '../stores/recipes'
|
||||
import { useDiaryStore } from '../stores/diary'
|
||||
import { useUiStore } from '../stores/ui'
|
||||
import { api } from '../composables/useApi'
|
||||
@@ -1128,6 +1128,11 @@ async function loadContribution() {
|
||||
const previewRecipeIndex = ref(null)
|
||||
const previewRecipeData = ref(null)
|
||||
const showBatchMenu = ref(false)
|
||||
const visibleAllTags = computed(() => {
|
||||
const tags = recipeStore.allTags
|
||||
if (auth.canEdit) return tags
|
||||
return tags.filter(t => !EDITOR_ONLY_TAGS.includes(t))
|
||||
})
|
||||
const showBatchTagPicker = ref(false)
|
||||
const batchTagsSelected = ref([])
|
||||
const batchNewTag = ref('')
|
||||
|
||||
@@ -169,7 +169,7 @@ import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useOilsStore } from '../stores/oils'
|
||||
import { useRecipesStore } from '../stores/recipes'
|
||||
import { useRecipesStore, EDITOR_ONLY_TAGS } from '../stores/recipes'
|
||||
import { useDiaryStore } from '../stores/diary'
|
||||
import { useUiStore } from '../stores/ui'
|
||||
import { api } from '../composables/useApi'
|
||||
@@ -315,7 +315,8 @@ const exactResults = computed(() => {
|
||||
const q = searchQuery.value.trim().toLowerCase()
|
||||
return recipeStore.recipes.filter(r => {
|
||||
const nameMatch = r.name.toLowerCase().includes(q)
|
||||
const tagMatch = r.tags && r.tags.some(t => t.toLowerCase().includes(q))
|
||||
const visibleTags = auth.canEdit ? (r.tags || []) : (r.tags || []).filter(t => !EDITOR_ONLY_TAGS.includes(t))
|
||||
const tagMatch = visibleTags.some(t => t.toLowerCase().includes(q))
|
||||
return nameMatch || tagMatch
|
||||
}).sort((a, b) => a.name.localeCompare(b.name, 'zh'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user