-

bugfix250729.1
全站通知:

模块:编年史

来自无尽的拉格朗日-星际猎人WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:编年史/doc创建

local p = {}

function p.main(frame)
    local parentArgs = frame:getParent().args
    local params = parentArgs
    
    -- 获取章节参数(如91010)
    local chapter = params['章节'] or ''
    
    local output = {}
    
    -- 顶部英文名
    table.insert(output, '<div style="width: 100%;height: 1px;border-top: solid #ACC0D8 1px;"></div>')
    table.insert(output, '<div style="font-size:16px;height: 26px">' .. (params['英文名'] or '') .. '</div>')
    table.insert(output, '<div style="width: 100%;height: 1px;border-top: solid #ACC0D8 1px;"></div>')
    
    -- 开始表格
    table.insert(output, [[
<div class="tab_con">
<div class="poke-bg" style="color: #16769c">
<p style="font-size: small">点击<span style="color: #cc4040">对应档案</span>展开详细内容</p>
<table class="wikitable" style="width: 100%; margin: 0">]])
    
    local hasAnyEntry = false
    
    -- 检查前200个条目(根据编号参数判断条目是否存在)
    for i = 1, 200 do
        local numberParam = params['编号' .. i]
        
        -- 如果编号参数存在且非空,则显示该条目
        if numberParam and numberParam ~= '' then
            local content = params['内容' .. i] or ''
            local title = params['标题' .. i] or ''
            
            -- 1. 确定最终编号(两种模式)
            local finalNumber = ''
            
            -- 自定义编号模式
            local customNumber = params['自定义编号' .. i]
            if customNumber and customNumber ~= '' then
                finalNumber = customNumber
            -- 默认编号模式
            else
                finalNumber = '编号' .. chapter .. numberParam
            end
            
            -- 2. 确定最终标题(两种模式)
            local finalTitle = ''
            
            -- 自定义标题模式
            local customTitle = params['自定义标题' .. i]
            if customTitle and customTitle ~= '' then
                finalTitle = customTitle
            -- 默认标题模式
            else
				finalTitle = frame:preprocess(
				    '【大事件】{{橙色|' .. title .. '}}年'
				)

            end
            
            -- 生成唯一ID
            local toggleId = 'entry_' .. chapter .. '_' .. i
            local collapsibleId = 'mw-customcollapsible-' .. toggleId
            
            -- 输出表头行
            table.insert(output, string.format(
                '<tr><th class="mw-customtoggle-%s" style="text-align:left">%s&nbsp;<small>%s</small></th></tr>',
                toggleId, finalNumber, finalTitle
            ))
            
            -- 输出内容行
            table.insert(output, string.format(
                '<tr><td class="mw-collapsible mw-collapsed" id="%s" style="display:none;">%s</td></tr>',
                collapsibleId, content
            ))
            
            hasAnyEntry = true
        end
    end
    
    -- 如果没有条目
    if not hasAnyEntry then
        table.insert(output, '<tr><td style="text-align:center; color:#999;">暂无档案数据</td></tr>')
    end
    
    -- 结束表格
    table.insert(output, '</table>')
    table.insert(output, '<div style="clear: both; margin-bottom: .4em"></div>')
    table.insert(output, '</div></div>')
    
    return table.concat(output, '\n')
end

return p