添加 store->bot 信息

This commit is contained in:
flykhan 2023-02-22 22:38:58 +08:00
parent c77e6216aa
commit 72c64062a9
2 changed files with 100 additions and 0 deletions

98
web/src/store/bot.js Normal file
View File

@ -0,0 +1,98 @@
import $ from "jquery";
import store from ".";
export default {
state: {},
getters: {},
// 同步事件
mutations: {},
// 异步事件
actions: {
add(context, data) {
// 新建 bot
$.ajax({
url: "http://localhost:3000/user/bot/add/",
type: "POST",
data: {
title: data.title,
description: data.description,
content: data.content,
},
headers: {
Authorization: "Bearer " + store.state.user.token,
},
success(resp) {
data.success(resp);
},
error(resp) {
data.error(resp);
},
});
},
remove(context, data) {
// 移除 bot
$.ajax({
url: "http://localhost:3000/user/bot/remove/",
type: "POST",
data: {
bot_id: data.bot_id,
},
headers: {
Authorization: "Bearer " + store.state.user.token,
},
success(resp) {
if (resp.error_message === "success") {
data.success(resp);
} else {
data.error(resp);
}
},
error(resp) {
data.error(resp);
},
});
},
update(context, data) {
// 更新 bot
$.ajax({
url: "http://localhost:3000/user/bot/update/",
type: "POST",
data: {
bot_id: data.bot_id,
title: data.title,
description: data.description,
content: data.content,
},
headers: {
Authorization: "Bearer " + store.state.user.token,
},
success(resp) {
data.success(resp);
},
error(resp) {
data.error(resp);
},
});
},
getList(context, data) {
// 获取 Bot 列表
$.ajax({
url: "http://localhost:3000/user/bot/getlist/",
type: "GET",
headers: {
Authorization: "Bearer " + store.state.user.token,
},
success(resp) {
data.success(resp);
},
error(resp) {
data.error(resp);
},
});
},
},
modules: {},
};

View File

@ -1,5 +1,6 @@
import { createStore } from "vuex"; import { createStore } from "vuex";
import ModuleUser from "./user"; import ModuleUser from "./user";
import ModuleBot from './bot';
export default createStore({ export default createStore({
state: {}, state: {},
@ -8,5 +9,6 @@ export default createStore({
actions: {}, actions: {},
modules: { modules: {
user: ModuleUser, user: ModuleUser,
bot: ModuleBot,
}, },
}); });