画廊添加

This commit is contained in:
2026-08-08 11:57:08 +08:00
parent 0ba5c56b6e
commit c8b82f640e
14 changed files with 282 additions and 23 deletions
+77
View File
@@ -1,4 +1,5 @@
#include "example_descriptors.hpp"
#include "gallery.hpp"
#include <cassert>
#include <string>
#include <string_view>
@@ -25,6 +26,47 @@ const Json* find_named_node(const Json& value, std::string_view name) {
}
return nullptr;
}
void assert_flex_items_renderable(const Json& value) {
if(value.is_object()) {
if(value.contains("type") && value.at("type") == "flex") {
assert(value.contains("items"));
for(const auto& item : value.at("items")) {
assert(item.is_object());
assert(item.contains("type"));
}
}
for(const auto& [key, child] : value.items()) {
static_cast<void>(key);
assert_flex_items_renderable(child);
}
return;
}
if(value.is_array()) {
for(const auto& child : value) {
assert_flex_items_renderable(child);
}
}
}
const Json* find_labeled_node(const Json& value, std::string_view label) {
if(value.is_object()) {
if(value.contains("label") && value.at("label").is_string() && value.at("label").get<std::string>() == label) {
return &value;
}
for(const auto& [key, child] : value.items()) {
static_cast<void>(key);
if(const Json* result = find_labeled_node(child, label)) {
return result;
}
}
} else if(value.is_array()) {
for(const auto& child : value) {
if(const Json* result = find_labeled_node(child, label)) {
return result;
}
}
}
return nullptr;
}
const Json* find_titled_node(const Json& value, std::string_view title) {
if(value.is_object()) {
if(value.contains("title") && value.at("title").is_string() && value.at("title").get<std::string>() == title) {
@@ -217,6 +259,41 @@ int main() {
assert(resource_form.at("api").at("method") == "post");
assert(resource_form.at("api").at("url") == "/admin/config/radio/data");
assert(resource_form.at("actions").at(1).at("label") == "确认修改");
adminive::example::Component_Gallery gallery;
const auto gallery_schema = gallery.amis_schema();
assert(gallery_schema.at("type") == "panel");
assert_flex_items_renderable(gallery_schema);
const Json* automatic_control = find_named_node(gallery_schema, "automatic_text");
const Json* text_control = find_named_node(gallery_schema, "text_value");
const Json* multiline_control = find_named_node(gallery_schema, "multiline_value");
const Json* number_control = find_named_node(gallery_schema, "number_value");
const Json* even_control = find_named_node(gallery_schema, "even_number");
const Json* boolean_control = find_named_node(gallery_schema, "boolean_value");
const Json* select_control = find_named_node(gallery_schema, "select_value");
const Json* date_gallery_control = find_named_node(gallery_schema, "date_value");
const Json* color_gallery_control = find_named_node(gallery_schema, "color_value");
const Json* optional_control = find_named_node(gallery_schema, "optional_text");
const Json* readonly_control = find_named_node(gallery_schema, "read_only_text");
assert(automatic_control && automatic_control->at("type") == "input-text");
assert(text_control && text_control->at("type") == "input-text");
assert(multiline_control && multiline_control->at("type") == "textarea");
assert(number_control && number_control->at("type") == "input-number");
assert(number_control->at("min") == 0 && number_control->at("max") == 100);
assert(even_control && even_control->at("type") == "input-number" && even_control->at("step") == 2);
assert(boolean_control && boolean_control->at("type") == "switch");
assert(select_control && select_control->at("type") == "select");
assert(date_gallery_control && date_gallery_control->at("type") == "input-date");
assert(color_gallery_control && color_gallery_control->at("type") == "input-color");
assert(optional_control && optional_control->at("clearable") == true);
assert(readonly_control && readonly_control->at("type") == "static");
const Json* save_gallery_button = find_labeled_node(gallery_schema, "保存画廊数据");
const Json* create_gallery_button = find_labeled_node(gallery_schema, "新增一行");
const Json* edit_gallery_button = find_labeled_node(gallery_schema, "编辑");
const Json* delete_gallery_button = find_labeled_node(gallery_schema, "删除");
assert(save_gallery_button && save_gallery_button->at("type") == "submit");
assert(create_gallery_button && create_gallery_button->at("type") == "button");
assert(edit_gallery_button && edit_gallery_button->at("actionType") == "dialog");
assert(delete_gallery_button && delete_gallery_button->at("actionType") == "ajax");
adminive::example::Server_Status server_status;
server_status.server_time = "2026-08-06T00:00:00Z";
server_status.poll_sequence = 7;