|
|
|
@ -4,7 +4,7 @@ |
|
|
|
|
<div class="col-3"> |
|
|
|
|
<div class="card" style="margin-top: 30px"> |
|
|
|
|
<div class="card-body"> |
|
|
|
|
<img :src="$store.state.user.photo" alt=""> |
|
|
|
|
<img :src="$store.state.user.photo" alt="" /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
@ -13,42 +13,90 @@ |
|
|
|
|
<div class="card" style="margin-top: 30px"> |
|
|
|
|
<div class="card-header"> |
|
|
|
|
<span style="font-size: 20px; font-weight: bold">我的bots</span> |
|
|
|
|
<button type="button" class="btn btn-primary float-end" btn-sm data-bs-toggle="modal" data-bs-target="#add_bot_btn">创建bot</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-primary float-end" |
|
|
|
|
btn-sm |
|
|
|
|
data-bs-toggle="modal" |
|
|
|
|
data-bs-target="#add_bot_btn" |
|
|
|
|
> |
|
|
|
|
创建bot |
|
|
|
|
</button> |
|
|
|
|
<!-- Modal --> |
|
|
|
|
<div class="modal fade" id="add_bot_btn" tabindex="-1"> |
|
|
|
|
<div class="modal-dialog modal-lg"> |
|
|
|
|
<div class="modal-content"> |
|
|
|
|
<div class="modal-header"> |
|
|
|
|
<h5 class="modal-title" id="exampleModalLabel">创建新的bot</h5> |
|
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
|
|
|
<h5 class="modal-title" id="exampleModalLabel"> |
|
|
|
|
创建新的bot |
|
|
|
|
</h5> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn-close" |
|
|
|
|
data-bs-dismiss="modal" |
|
|
|
|
aria-label="Close" |
|
|
|
|
></button> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-body"> |
|
|
|
|
<form> |
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_title" class="form-label">bot名称</label> |
|
|
|
|
<input type="text" v-model="new_bot.title" class="form-control" id="add_bot_title" placeholder="请输入新bot的名称"> |
|
|
|
|
<label for="add_bot_title" class="form-label" |
|
|
|
|
>bot名称</label |
|
|
|
|
> |
|
|
|
|
<input |
|
|
|
|
type="text" |
|
|
|
|
v-model="new_bot.title" |
|
|
|
|
class="form-control" |
|
|
|
|
id="add_bot_title" |
|
|
|
|
placeholder="请输入新bot的名称" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_description" class="form-label">bot简介</label> |
|
|
|
|
<textarea class="form-control" v-model="new_bot.description" id="add_bot_description" rows= "3" placeholder="请输入新bot的简介"></textarea> |
|
|
|
|
<label for="add_bot_description" class="form-label" |
|
|
|
|
>bot简介</label |
|
|
|
|
> |
|
|
|
|
<textarea |
|
|
|
|
class="form-control" |
|
|
|
|
v-model="new_bot.description" |
|
|
|
|
id="add_bot_description" |
|
|
|
|
rows="3" |
|
|
|
|
placeholder="请输入新bot的简介" |
|
|
|
|
></textarea> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_code" class="form-label">bot的代码</label> |
|
|
|
|
<label for="add_bot_code" class="form-label" |
|
|
|
|
>bot的代码</label |
|
|
|
|
> |
|
|
|
|
<VAceEditor |
|
|
|
|
v-model:value="new_bot.content" |
|
|
|
|
@init="editorInit" |
|
|
|
|
lang="c_cpp" |
|
|
|
|
theme="textmate" |
|
|
|
|
:options="{ fontSize: 16 }" |
|
|
|
|
style="height: 300px" /> |
|
|
|
|
style="height: 200px" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
</form> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-footer"> |
|
|
|
|
<div class="error_msg">{{ new_bot.error_msg }}</div> |
|
|
|
|
<button type="button" class="btn btn-success" @click="add_bot" btn-sm>创建</button> |
|
|
|
|
<button type="button" class="btn btn-danger" btn-sm @click="cancel_add">取消</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-success" |
|
|
|
|
@click="add_bot" |
|
|
|
|
btn-sm |
|
|
|
|
> |
|
|
|
|
创建 |
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-danger" |
|
|
|
|
btn-sm |
|
|
|
|
@click="cancel_add" |
|
|
|
|
> |
|
|
|
|
取消 |
|
|
|
|
</button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
@ -71,43 +119,141 @@ |
|
|
|
|
<td>{{ bot.title }}</td> |
|
|
|
|
<td>{{ bot.createTime }}</td> |
|
|
|
|
<td> |
|
|
|
|
<button type="button" class="btn btn-success" btn-sm style="margin-right: 10px" data-bs-toggle="modal" :data-bs-target="'#update-bot-btn-'+bot.id" >修改</button> |
|
|
|
|
<button type="button" class="btn btn-danger" btn-sm @click="remove_bot(bot)">删除</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-success" |
|
|
|
|
btn-sm |
|
|
|
|
style="margin-right: 10px" |
|
|
|
|
data-bs-toggle="modal" |
|
|
|
|
:data-bs-target="'#update-bot-btn-' + bot.id" |
|
|
|
|
> |
|
|
|
|
修改 |
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-danger" |
|
|
|
|
btn-sm |
|
|
|
|
data-bs-toggle="modal" |
|
|
|
|
:data-bs-target="'#remove-bot-btn-' + bot.id" |
|
|
|
|
> |
|
|
|
|
删除 |
|
|
|
|
</button> |
|
|
|
|
|
|
|
|
|
<div class="modal fade" :id="'update-bot-btn-'+bot.id" tabindex="-1"> |
|
|
|
|
<div |
|
|
|
|
class="modal fade" |
|
|
|
|
:id="'remove-bot-btn-' + bot.id" |
|
|
|
|
tabindex="-1" |
|
|
|
|
> |
|
|
|
|
<div class="modal-dialog"> |
|
|
|
|
<div class="modal-content"> |
|
|
|
|
<div class="modal-header"> |
|
|
|
|
<h5 class="modal-title">删除提示框</h5> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn-close" |
|
|
|
|
data-bs-dismiss="modal" |
|
|
|
|
aria-label="Close" |
|
|
|
|
></button> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-body"> |
|
|
|
|
<p>是否确定要删除该bot</p> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-footer"> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-info" |
|
|
|
|
data-bs-dismiss="modal" |
|
|
|
|
> |
|
|
|
|
我再想想 |
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-danger" |
|
|
|
|
@click="remove_bot(bot)" |
|
|
|
|
> |
|
|
|
|
确认删除 |
|
|
|
|
</button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div |
|
|
|
|
class="modal fade" |
|
|
|
|
:id="'update-bot-btn-' + bot.id" |
|
|
|
|
tabindex="-1" |
|
|
|
|
> |
|
|
|
|
<div class="modal-dialog modal-lg"> |
|
|
|
|
<div class="modal-content"> |
|
|
|
|
<div class="modal-header"> |
|
|
|
|
<h5 class="modal-title">修改bot信息</h5> |
|
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn-close" |
|
|
|
|
data-bs-dismiss="modal" |
|
|
|
|
aria-label="Close" |
|
|
|
|
></button> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-body"> |
|
|
|
|
<form> |
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_title" class="form-label">bot名称</label> |
|
|
|
|
<input type="text" v-model="bot.title" class="form-control" id="add_bot_title" > |
|
|
|
|
<label for="add_bot_title" class="form-label" |
|
|
|
|
>bot名称</label |
|
|
|
|
> |
|
|
|
|
<input |
|
|
|
|
type="text" |
|
|
|
|
v-model="bot.title" |
|
|
|
|
class="form-control" |
|
|
|
|
id="add_bot_title" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_description" class="form-label">bot简介</label> |
|
|
|
|
<textarea class="form-control" v-model="bot.description" id="add_bot_description" rows= "3" ></textarea> |
|
|
|
|
<label |
|
|
|
|
for="add_bot_description" |
|
|
|
|
class="form-label" |
|
|
|
|
>bot简介</label |
|
|
|
|
> |
|
|
|
|
<textarea |
|
|
|
|
class="form-control" |
|
|
|
|
v-model="bot.description" |
|
|
|
|
id="add_bot_description" |
|
|
|
|
rows="3" |
|
|
|
|
></textarea> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div class="mb-3"> |
|
|
|
|
<label for="add_bot_code" class="form-label">bot的代码</label> |
|
|
|
|
<label for="add_bot_code" class="form-label" |
|
|
|
|
>bot的代码</label |
|
|
|
|
> |
|
|
|
|
<VAceEditor |
|
|
|
|
v-model:value="bot.content" |
|
|
|
|
@init="editorInit" |
|
|
|
|
lang="c_cpp" |
|
|
|
|
theme="textmate" |
|
|
|
|
:options="{ fontSize: 16 }" |
|
|
|
|
style="height: 300px" /> |
|
|
|
|
style="height: 200px" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
</form> |
|
|
|
|
</div> |
|
|
|
|
<div class="modal-footer"> |
|
|
|
|
<div class="error_msg">{{ bot.error_msg }}</div> |
|
|
|
|
<button type="button" class="btn btn-success" @click="update_bot(bot)" btn-sm>保存修改</button> |
|
|
|
|
<button type="button" class="btn btn-danger" btn-sm @click="cancel_update(bot)">取消</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-success" |
|
|
|
|
@click="update_bot(bot)" |
|
|
|
|
btn-sm |
|
|
|
|
> |
|
|
|
|
保存修改 |
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
type="button" |
|
|
|
|
class="btn btn-danger" |
|
|
|
|
btn-sm |
|
|
|
|
@click="cancel_update(bot)" |
|
|
|
|
> |
|
|
|
|
取消 |
|
|
|
|
</button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
@ -124,13 +270,13 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import { ref,reactive } from "vue" |
|
|
|
|
import $ from 'jquery' |
|
|
|
|
import { useStore } from "vuex" |
|
|
|
|
import {Modal} from "bootstrap/dist/js/bootstrap" |
|
|
|
|
import { ref, reactive } from "vue"; |
|
|
|
|
import $ from "jquery"; |
|
|
|
|
import { useStore } from "vuex"; |
|
|
|
|
import { Modal } from "bootstrap/dist/js/bootstrap"; |
|
|
|
|
|
|
|
|
|
import { VAceEditor } from 'vue3-ace-editor'; |
|
|
|
|
import ace from 'ace-builds'; |
|
|
|
|
import { VAceEditor } from "vue3-ace-editor"; |
|
|
|
|
import ace from "ace-builds"; |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
components: { |
|
|
|
@ -139,39 +285,42 @@ export default { |
|
|
|
|
setup() { |
|
|
|
|
ace.config.set( |
|
|
|
|
"basePath", |
|
|
|
|
"https://cdn.jsdelivr.net/npm/ace-builds@" + require('ace-builds').version + "/src-noconflict/"); |
|
|
|
|
"https://cdn.jsdelivr.net/npm/ace-builds@" + |
|
|
|
|
require("ace-builds").version + |
|
|
|
|
"/src-noconflict/" |
|
|
|
|
); |
|
|
|
|
const store = useStore(); |
|
|
|
|
let bots = ref([]) // 定义bot列表 |
|
|
|
|
let bots = ref([]); // 定义bot列表 |
|
|
|
|
const new_bot = reactive({ |
|
|
|
|
title: "", |
|
|
|
|
description: "", |
|
|
|
|
content: "", |
|
|
|
|
error_msg: "", |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const cancel_update = (bot) => { |
|
|
|
|
Modal.getInstance("#update-bot-btn-" + bot.id).hide(); |
|
|
|
|
refresh_bots(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const cancel_add = () => { |
|
|
|
|
Modal.getInstance("#add_bot_btn").hide(); |
|
|
|
|
refresh_bots(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const refresh_bots = () => { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: "https://kob.bnblogs.cc/api/user/bot/getlist/", |
|
|
|
|
type: "GET", |
|
|
|
|
headers: { |
|
|
|
|
"Authorization": "Bearer " + store.state.user.token, // 任何需要登录才能显示的都要加这个验证 |
|
|
|
|
Authorization: "Bearer " + store.state.user.token, // 任何需要登录才能显示的都要加这个验证 |
|
|
|
|
}, |
|
|
|
|
success(resp) { |
|
|
|
|
// 将后端得到的数据传给bot |
|
|
|
|
bots.value = resp; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
refresh_bots(); |
|
|
|
|
|
|
|
|
|
// 点击创建bot按钮触发的事件 |
|
|
|
@ -186,23 +335,22 @@ export default { |
|
|
|
|
content: new_bot.content, |
|
|
|
|
}, |
|
|
|
|
headers: { |
|
|
|
|
"Authorization": "Bearer " + store.state.user.token, |
|
|
|
|
Authorization: "Bearer " + store.state.user.token, |
|
|
|
|
}, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.error_msg === "success") { // 添加bot成功 |
|
|
|
|
new_bot.title = "", |
|
|
|
|
new_bot.description="", |
|
|
|
|
new_bot.content="", |
|
|
|
|
if (resp.error_msg === "success") { |
|
|
|
|
// 添加bot成功 |
|
|
|
|
(new_bot.title = ""), |
|
|
|
|
(new_bot.description = ""), |
|
|
|
|
(new_bot.content = ""), |
|
|
|
|
Modal.getInstance("#add_bot_btn").hide(); |
|
|
|
|
refresh_bots(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
new_bot.error_msg = resp.error_msg; // 返回错误信息 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 点击更新bot按钮触发的事件 |
|
|
|
|
const update_bot = (bot) => { |
|
|
|
@ -216,39 +364,42 @@ export default { |
|
|
|
|
content: bot.content, |
|
|
|
|
}, |
|
|
|
|
headers: { |
|
|
|
|
"Authorization": "Bearer " + store.state.user.token, |
|
|
|
|
Authorization: "Bearer " + store.state.user.token, |
|
|
|
|
}, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.error_msg === "success") { // 更新bot成功 |
|
|
|
|
if (resp.error_msg === "success") { |
|
|
|
|
// 更新bot成功 |
|
|
|
|
Modal.getInstance("#update-bot-btn-" + bot.id).hide(); |
|
|
|
|
refresh_bots(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
new_bot.error_msg = resp.error_msg; // 返回错误信息 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 点击删除bot按钮触发的事件 |
|
|
|
|
const remove_bot = (bot) => { |
|
|
|
|
console.log(bot); |
|
|
|
|
$.ajax({ |
|
|
|
|
url: "https://kob.bnblogs.cc/api/user/bot/remove/", |
|
|
|
|
type: "POST", |
|
|
|
|
data: { |
|
|
|
|
bot_id: bot.id |
|
|
|
|
bot_id: bot.id, |
|
|
|
|
}, |
|
|
|
|
headers: { |
|
|
|
|
"Authorization": "Bearer " + store.state.user.token, |
|
|
|
|
Authorization: "Bearer " + store.state.user.token, |
|
|
|
|
}, |
|
|
|
|
success(resp) { |
|
|
|
|
console.log(resp) |
|
|
|
|
if (resp.error_msg === "success") { // 添加bot成功 |
|
|
|
|
console.log(resp); |
|
|
|
|
if (resp.error_msg === "success") { |
|
|
|
|
Modal.getInstance("#remove-bot-btn-" + bot.id).hide(); |
|
|
|
|
// 删除bot成功 |
|
|
|
|
refresh_bots(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
bots, |
|
|
|
@ -258,15 +409,14 @@ export default { |
|
|
|
|
update_bot, |
|
|
|
|
cancel_update, |
|
|
|
|
cancel_add, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
|
img { |
|
|
|
|
width: 100% |
|
|
|
|
width: 100%; |
|
|
|
|
} |
|
|
|
|
.error_msg { |
|
|
|
|
font-size: 20px; |
|
|
|
|