use json::{JsonValue, object}; use br_fields::Field; use crate::plugin::{{plugin}}::{{model_a}}::{{model}}; use br_plugin::Response; use br_plugin::action::Action; use br_plugin::model::Model; pub struct {{action}} { pub model: {{model}}, } impl Action for {{action}} { fn author(&mut self) -> &'static str { return ""; } fn title(&mut self) -> &'static str { "{{title}}" } fn api(&mut self) -> &'static str { "{{api}}" } fn mode(&mut self) -> Vec<&'static str> { vec![] } fn interface_type(&mut self) -> InterfaceType { InterfaceType::Btn } fn params(&mut self) -> JsonValue { let mut params = object! {}; params[self.model.primary_key()] = br_fields::str::Key::new(true, self.model.primary_key(), "ID", 20).field(); return params; } fn index(&mut self, _header: JsonValue, request: JsonValue) -> Response { let id = request["id"].clone(); let update = self.tools().db.table(self.model.table()).where_and("id", "=", id.clone()).update(request); if update.as_i32().unwrap() == 0 { return self.fail("{{title}}失败"); } return self.success(update, "{{title}}成功"); } }