nonebot2/docs/.vuepress/components/Bot.vue

191 lines
4.8 KiB
Vue
Raw Normal View History

2021-03-05 08:27:43 +00:00
<template>
<v-card flat class="bots">
<v-row>
2021-04-05 05:32:36 +00:00
<v-col cols="12" sm="6">
2021-03-05 08:27:43 +00:00
<v-text-field
v-model="filterText"
dense
rounded
outlined
clearable
hide-details
2021-04-05 05:32:36 +00:00
label="搜索机器人"
2021-03-05 08:27:43 +00:00
>
<template v-slot:prepend-inner>
<div class="v-input__icon v-input__icon--prepend-inner">
<v-icon small>fa-filter</v-icon>
</div>
</template>
</v-text-field>
</v-col>
2021-04-05 05:32:36 +00:00
<v-col cols="12" sm="6">
2021-03-05 08:27:43 +00:00
<v-dialog v-model="dialog" max-width="600px">
<template v-slot:activator="{ on, attrs }">
<v-btn dark block color="primary" v-bind="attrs" v-on="on"
2021-04-05 05:32:36 +00:00
>发布机器人
2021-03-05 08:27:43 +00:00
</v-btn>
</template>
<v-card>
<v-card-title>
2021-04-05 05:32:36 +00:00
<span class="headline">机器人信息</span>
2021-03-05 08:27:43 +00:00
</v-card-title>
<v-card-text>
<v-form ref="newBotForm" v-model="valid" lazy-validation>
<v-container>
<v-row>
<v-col cols="12">
<v-text-field
v-model="newBot.name"
label="机器人名称"
required
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
v-model="newBot.desc"
label="机器人介绍"
required
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
v-model="newBot.repo"
label="仓库/主页链接"
required
></v-text-field>
</v-col>
</v-row>
</v-container>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="dialog = false">
2021-04-05 05:32:36 +00:00
关闭
2021-03-05 08:27:43 +00:00
</v-btn>
<v-btn
:disabled="!valid"
color="blue darken-1"
text
@click="
2021-04-05 08:35:29 +00:00
dialog = false;
publishBot();
2021-03-05 08:27:43 +00:00
"
>
2021-04-05 05:32:36 +00:00
发布
2021-03-05 08:27:43 +00:00
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-col>
2021-04-05 05:32:36 +00:00
</v-row>
2021-04-05 08:35:29 +00:00
<v-row>
<v-col cols="12">
<v-pagination
v-model="page"
:length="pageNum"
prev-icon="fa-caret-left"
next-icon="fa-caret-right"
></v-pagination>
</v-col>
</v-row>
2021-03-05 08:27:43 +00:00
<v-row>
<v-col cols="12" sm="6" v-for="(bot, index) in displayBots" :key="index">
<PublishCard
:name="bot.name"
:desc="bot.desc"
:author="bot.author"
:link="bot.repo"
></PublishCard>
</v-col>
</v-row>
2021-04-05 08:39:26 +00:00
<v-row>
<v-col cols="12">
<v-pagination
v-model="page"
:length="pageNum"
prev-icon="fa-caret-left"
next-icon="fa-caret-right"
></v-pagination>
</v-col>
</v-row>
2021-03-05 08:27:43 +00:00
</v-card>
</template>
<script>
2021-04-05 08:35:29 +00:00
import PublishCard from "./PublishCard.vue";
import bots from "../public/bots.json";
2021-03-05 08:27:43 +00:00
export default {
2021-04-05 08:35:29 +00:00
name: "Bots",
2021-03-05 08:27:43 +00:00
components: {
2021-04-05 05:44:19 +00:00
PublishCard,
2021-03-05 08:27:43 +00:00
},
data() {
return {
bots: bots,
2021-04-05 08:35:29 +00:00
filterText: "",
2021-03-05 08:27:43 +00:00
page: 1,
dialog: false,
valid: false,
newBot: {
name: null,
desc: null,
2021-04-05 05:44:19 +00:00
repo: null,
},
2021-04-05 08:35:29 +00:00
};
2021-03-05 08:27:43 +00:00
},
computed: {
pageNum() {
2021-04-05 08:35:29 +00:00
return Math.ceil(this.filteredBots.length / 10);
2021-03-05 08:27:43 +00:00
},
filteredBots() {
2021-04-05 05:44:19 +00:00
return this.bots.filter((bot) => {
2021-03-05 08:27:43 +00:00
return (
2021-04-05 08:35:29 +00:00
bot.name.indexOf(this.filterText || "") != -1 ||
bot.desc.indexOf(this.filterText || "") != -1 ||
bot.author.indexOf(this.filterText || "") != -1
);
});
2021-03-05 08:27:43 +00:00
},
displayBots() {
2021-04-05 08:35:29 +00:00
return this.filteredBots.slice((this.page - 1) * 10, this.page * 10);
2021-03-05 08:27:43 +00:00
},
publishBot() {
if (!this.$refs.newBotForm.validate()) {
2021-04-05 08:35:29 +00:00
return;
2021-03-05 08:27:43 +00:00
}
const title = encodeURIComponent(`Bot: ${this.newBot.name}`).replace(
/%2B/gi,
2021-04-05 08:35:29 +00:00
"+"
);
2021-03-05 08:27:43 +00:00
const body = encodeURIComponent(
`
**机器人名称**
${this.newBot.name}
**机器人功能**
${this.newBot.desc}
**机器人项目仓库/主页链接**
${this.newBot.repo}
<!-- DO NOT EDIT ! -->
<!--
- name: ${this.newBot.name}
- desc: ${this.newBot.desc}
- repo: ${this.newBot.repo}
-->
`.trim()
2021-04-05 08:35:29 +00:00
).replace(/%2B/gi, "+");
2021-03-05 08:27:43 +00:00
window.open(
`https://github.com/nonebot/nonebot2/issues/new?title=${title}&body=${body}&labels=Bot`
2021-04-05 08:35:29 +00:00
);
2021-04-05 05:44:19 +00:00
},
},
2021-04-05 08:35:29 +00:00
};
2021-03-05 08:27:43 +00:00
</script>