import $ from "jquery"; import store from "."; export default { state: {}, getters: {}, // 同步事件 mutations: {}, // 异步事件 actions: { add(context, data) { // 新建 bot $.ajax({ url: "http://localhost:3001/api/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:3001/api/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:3001/api/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:3001/api/user/bot/getlist/", type: "GET", headers: { Authorization: "Bearer " + store.state.user.token, }, success(resp) { data.success(resp); }, error(resp) { data.error(resp); }, }); }, }, modules: {}, };