diff --git a/web/src/store/bot.js b/web/src/store/bot.js new file mode 100644 index 0000000..70a3d43 --- /dev/null +++ b/web/src/store/bot.js @@ -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: {}, +}; diff --git a/web/src/store/index.js b/web/src/store/index.js index 56bbab3..4c3044f 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -1,5 +1,6 @@ import { createStore } from "vuex"; import ModuleUser from "./user"; +import ModuleBot from './bot'; export default createStore({ state: {}, @@ -8,5 +9,6 @@ export default createStore({ actions: {}, modules: { user: ModuleUser, + bot: ModuleBot, }, });