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

187 lines
4.8 KiB
Vue
Raw Normal View History

2021-03-05 16:27:43 +08:00
<template>
<v-card flat class="bots">
<v-row>
2021-04-05 13:32:36 +08:00
<v-col cols="12" sm="6">
2021-03-05 16:27:43 +08:00
<v-text-field
v-model="filterText"
dense
rounded
outlined
clearable
hide-details
2021-04-05 13:32:36 +08:00
label="搜索机器人"
2021-03-05 16:27:43 +08: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 13:32:36 +08:00
<v-col cols="12" sm="6">
2021-03-05 16:27:43 +08: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 13:32:36 +08:00
>发布机器人
2021-03-05 16:27:43 +08:00
</v-btn>
</template>
<v-card>
<v-card-title>
2021-04-05 13:32:36 +08:00
<span class="headline">机器人信息</span>
2021-03-05 16:27:43 +08: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 13:32:36 +08:00
关闭
2021-03-05 16:27:43 +08:00
</v-btn>
<v-btn
:disabled="!valid"
color="blue darken-1"
text
@click="
dialog = false;
publishBot();
"
>
2021-04-05 13:32:36 +08:00
发布
2021-03-05 16:27:43 +08:00
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-col>
2021-04-05 13:32:36 +08:00
</v-row>
<v-col cols="12">
2021-03-05 16:27:43 +08:00
<v-pagination
v-model="page"
:length="pageNum"
prev-icon="fa-caret-left"
next-icon="fa-caret-right"
></v-pagination>
</v-col>
<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>
<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-card>
</template>
<script>
import PublishCard from "./PublishCard.vue";
import bots from "../public/bots.json";
export default {
name: "Bots",
components: {
PublishCard
},
data() {
return {
bots: bots,
filterText: "",
page: 1,
dialog: false,
valid: false,
newBot: {
name: null,
desc: null,
repo: null
}
};
},
computed: {
pageNum() {
return Math.ceil(this.filteredBots.length / 10);
},
filteredBots() {
return this.bots.filter(bot => {
return (
bot.name.indexOf(this.filterText || "") != -1 ||
bot.desc.indexOf(this.filterText || "") != -1 ||
bot.author.indexOf(this.filterText || "") != -1
);
});
},
displayBots() {
return this.filteredBots.slice((this.page - 1) * 10, this.page * 10);
},
publishBot() {
if (!this.$refs.newBotForm.validate()) {
return;
}
const title = encodeURIComponent(`Bot: ${this.newBot.name}`).replace(
/%2B/gi,
"+"
);
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()
).replace(/%2B/gi, "+");
window.open(
`https://github.com/nonebot/nonebot2/issues/new?title=${title}&body=${body}&labels=Bot`
);
}
}
};
</script>