from PDAPI import * import TempLateAPI.GERP.API.FormAPI.FormData as FormData __metadata__ = { "route": "{DEFAULT_ROUTE}/", "methods": ["GET"], "blueprint": "GERP", "permission": 1.0, "attributes": [], "limit": "1 per second" } def HandleRequest(_CleanedData): Table = FormData.GetTable(_CleanedData["params"]["TableName"]) if not Table: return {"code": 1, "msg": "找不到表格"}, 404 TableName = _CleanedData["params"]["TableName"] columns = [] for item in Table.row: field_name = item["Name"] field_type = item.get("Type", "str") groups = item.get("Groups", []) title = FormData.get_field_display_name(TableName, field_name) column_def = { "field": field_name, "title": title, "width": "120px" } if "PrimaryKey" in groups: column_def["primaryKey"] = True column_def["hideInForm"] = True column_def["editable"] = False hide_key = f"{TableName}.{field_name}" if hide_key in FormData.TABLE_HIDE_IN_FORM: column_def["hideInForm"] = True if "MechanicalItem" in groups: column_def["hideInForm"] = True column_def["editable"] = False if field_type == "int": column_def["type"] = "number" elif field_type == "float": column_def["type"] = "number" elif field_type == "bool": column_def["type"] = "switch" elif field_type == "timestampstr": column_def["sortable"] = True column_def["width"] = "160px" timestamp_format = item.get("TimestampFormat", "%Y-%m-%d %H:%M:%S") if "HH:mm" in timestamp_format: column_def["type"] = "datetime" elif "HH:mm" not in timestamp_format and "%H" not in timestamp_format: column_def["type"] = "date" else: column_def["type"] = "datetime" elif field_type == "json": column_def["type"] = "textarea" elif field_type == "str": textarea_key = f"{TableName}.{field_name}" if textarea_key in FormData.TABLE_TEXTAREA_FIELDS: column_def["type"] = "textarea" elif field_type == "UUID": fk_key = f"{TableName}.{field_name}" fk_config = FormData.TABLE_FK_PICKER.get(fk_key) if fk_config: column_def["type"] = "entityPicker" column_def["width"] = "320px" column_def["codeTable"] = f"{TableName}.{field_name}" column_def["entityPicker"] = { "api": fk_config.get("api", ""), "method": fk_config.get("method", "GET"), "labelField": fk_config.get("labelField", "name"), "valueField": fk_config.get("valueField", "id"), "secondaryField": fk_config.get("secondaryField"), "searchParam": fk_config.get("searchParam", "keyword"), "resultPath": fk_config.get("resultPath", "data"), "placeholder": f"输入{title}搜索...", "codeTable": f"{TableName}.{field_name}", } else: column_def["type"] = "uuid" column_def["width"] = "280px" column_def["editable"] = False if item.get("Required", False): column_def["required"] = True if item.get("Unique", False): column_def["unique"] = True if item.get("PassEmpty", False): column_def["passEmpty"] = True if item.get("AllowList"): column_def["type"] = "select" allow_list = item["AllowList"] translated_options = [] for opt in allow_list: value = opt.get("value") if isinstance(opt, dict) else opt label = FormData.get_code_display(TableName, field_name, value) translated_options.append({ "value": value, "label": label }) column_def["options"] = translated_options column_def["codeTable"] = f"{TableName}.{field_name}" if item.get("Length"): column_def["length"] = item["Length"] if item.get("MinLen") is not None: column_def["minLength"] = item["MinLen"] if item.get("MaxLen") is not None: column_def["maxLength"] = item["MaxLen"] if item.get("Default") is not None: column_def["defaultValue"] = item["Default"] if field_name in ["create_time", "update_time", "created_at", "updated_at"]: column_def["sortable"] = True if item.get("Regex"): column_def["pattern"] = item["Regex"] placeholder_key = f"{TableName}.{field_name}" custom_placeholder = FormData.TABLE_FIELD_PLACEHOLDER.get(placeholder_key) if custom_placeholder: column_def["placeholder"] = custom_placeholder columns.append(column_def) return {"code": 0, "columns": columns}, 200