From 72c64062a9bf4b6dd9c4f802564f061cd6fe1a59 Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 22 Feb 2023 22:38:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20store->bot=20=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/store/bot.js | 98 ++++++++++++++++++++++++++++++++++++++++++ web/src/store/index.js | 2 + 2 files changed, 100 insertions(+) create mode 100644 web/src/store/bot.js 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, }, });