app/docs/components/ResStore.vue

105 lines
3.0 KiB
Vue
Raw Normal View History

2024-08-31 21:50:58 +08:00
<script setup lang="ts">
import {computed, ref} from 'vue'
import ItemCard from './ResItemCard.vue'
import ResPubWindow from "./ResPubWindow.vue";
2024-09-22 01:38:44 +08:00
import {getTextRef, formatLang} from "./scripts/i18n";
import {RepoUrl} from "./scripts/statsApi";
2024-08-31 21:50:58 +08:00
import resourcesJson from "../public/resources.json"
2024-09-22 01:38:44 +08:00
import {useData} from "vitepress";
2024-09-22 01:48:53 +08:00
// formLan
2024-08-31 21:50:58 +08:00
// 从public/assets/resources.json加载插件
let filteredItems = computed(() => {
if (!search.value) {
return items.value.reverse()
}
return items.value.filter(item =>
item.name.toLowerCase().includes(search.value.toLowerCase()) ||
item.description.toLowerCase().includes(search.value.toLowerCase()) ||
item.author.toLowerCase().includes(search.value.toLowerCase())
).reverse()
})
// 插件商店Nonebot
let items = ref([])
let search = ref('')
items.value = resourcesJson
2024-08-31 21:50:58 +08:00
// 列表倒序
const isPublishWindowOpen = ref(false)
let newRes = ref({
name: '',
})
function openPublishWindow() {
isPublishWindowOpen.value = true
}
function closePublishWindow() {
isPublishWindowOpen.value = false
}
2024-09-22 01:48:53 +08:00
let submitLang = ""
if (formatLang(useData().site.value.lang) === "zh") {
submitLang = "zh"
} else {
submitLang = "en"
}
2024-09-22 01:38:44 +08:00
function submitForm() {
const title = encodeURI(`Resource: ${newRes.value.name}`)
2024-09-22 01:38:44 +08:00
const issueURL = `${RepoUrl}/issues/new?assignees=&labels=Resource&template=resource_publish_${submitLang}.yml&title=${title}`
console.log(issueURL)
window.open(issueURL, '_blank')
}
2024-08-31 21:50:58 +08:00
</script>
<template>
<div class="market">
2024-09-01 22:14:09 +08:00
<h1>{{ getTextRef('resourceStore') }}</h1>
2024-09-22 01:38:44 +08:00
<div class="search-box-div"><input class="item-search-box" type="text" :placeholder="getTextRef('search')"
v-model="search"/></div>
<div class="store-tabs" style="display: flex">
<button class="store-button publish-button" @click="openPublishWindow">{{ getTextRef('publishRes') }}</button>
</div>
2024-08-31 21:50:58 +08:00
<div class="items">
<!-- 使用filteredItems来布局商品 -->
<ItemCard v-for="item in filteredItems" :key="item.id" :item="item"/>
</div>
<ResPubWindow class="pub-window" :is-visible="isPublishWindowOpen">
<h2>{{ getTextRef("publishRes") }}</h2>
<form @submit.prevent="submitForm">
<label for="name">{{ getTextRef("resName") }}</label>
<input type="text" id="name" v-model="newRes.name" :placeholder="getTextRef('resNameText')"/>
<div class="pub-options" style="display: flex; justify-content: center">
2024-09-22 01:38:44 +08:00
<button class="pub-option close" type="button" @click="closePublishWindow">{{
getTextRef("closeButtonText")
}}
</button>
<button class="pub-option submit" type="submit" @click="submitForm">{{
getTextRef("submitButtonText")
}}
</button>
</div>
</form>
</ResPubWindow>
2024-08-31 21:50:58 +08:00
</div>
</template>
<style scoped>
h1 {
color: #00a6ff;
text-align: center;
font-weight: bold;
}
.items {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
gap: 10px;
}
2024-08-31 21:50:58 +08:00
</style>