无编辑摘要
无编辑摘要
第15行: 第15行:


-- [[------------------------------------------------------------------]]
-- [[------------------------------------------------------------------]]
-- [[ 2. 表格标题映射 (已更新) ]]
-- [[ 2. 表格标题映射 ]]
-- [[------------------------------------------------------------------]]
-- [[------------------------------------------------------------------]]
local displayNames = {
local displayNames = {
     -- 用户提供的核心字段
     -- 核心字段
     ['title'] = '歌曲标题',
     ['title'] = '歌曲标题',
     ['composer'] = '艺术家',
     ['composer'] = '艺术家',
第30行: 第30行:
     -- 保留常用字段
     -- 保留常用字段
     ['duration'] = '时长',
     ['duration'] = '时长',
    ['is_featured'] = '精选',


     -- 4B 字段
     -- 4B 字段
第70行: 第69行:
}
}


-- [[------------------------------------------------------------------]]
-- [[ 3. 本地辅助函数定义 (已修复语法) ]]
-- [[------------------------------------------------------------------]]
local function GetValuesTable()
local function GetValuesTable()
     return mw.loadData('Module:db_song')
     return mw.loadData('Module:db_song')
end
end -- **FIXED**


local function ValueFromValuesByKey(values, key)
local function ValueFromValuesByKey(values, key)
第79行: 第81行:
end
end
return nil
return nil
end
end -- **FIXED**


-- 格式化单个值的私有函数
local function formatSingleValue(value, fieldType)
local function formatSingleValue(value, fieldType)
     if value == nil then
     if value == nil then
第89行: 第92行:
         return p.valueMappingMethod[fieldType](value)
         return p.valueMappingMethod[fieldType](value)
     else
     else
         return tostring(value)
         local strValue = tostring(value)
       
        -- BPM 颜色逻辑
        if fieldType == 'bpm' and string.find(strValue, '-') then
            return '<span style="color:red;">' .. strValue .. '</span>'
        end
       
        return strValue
     end
     end
end
end -- **FIXED**


-- 判断是否为节奏游戏字段
-- 判断是否为节奏游戏字段
第99行: 第109行:
     end
     end
     return false
     return false
end
end -- **FIXED**




-- 4. 值格式化方法 (valueMappingMethod)
-- 4. 值格式化方法 (valueMappingMethod)
local function autoLink(value)
    if type(value) == 'string' and value ~= '' then
        return '[[' .. value .. ']]'
    end
    return value
end
p.valueMappingMethod = {
p.valueMappingMethod = {
     ['duration'] = (function (value)
     ['duration'] = (function (value)
第112行: 第129行:
         return value
         return value
     end),
     end),
     ['artist'] = (function (value)
     ['composer'] = autoLink,
        if type(value) == 'string' and value ~= '' then
    ['singer'] = autoLink,
            return '[[' .. value .. ']]'
    ['bga'] = autoLink,
        end
        return value
    end),
}
}


第198行: 第212行:
     return table.concat(matchingKeys, ', ')
     return table.concat(matchingKeys, ', ')
end
end


function p.generateListTable(f)
function p.generateListTable(f)
第206行: 第221行:
     local displayFieldsString = mw.text.trim(args.columns or '')  
     local displayFieldsString = mw.text.trim(args.columns or '')  
      
      
     -- 预处理 conditionValue 的类型 (代码保持不变)
     -- 预处理 conditionValue 的类型
     if type(conditionValue) == 'string' then
     if type(conditionValue) == 'string' then
         local trimmedValue = mw.text.trim(conditionValue)
         local trimmedValue = mw.text.trim(conditionValue)
第248行: 第263行:
     local output = {}
     local output = {}
      
      
     -- **核心修改:表格样式**
     -- 表格样式: 宽度 90%, 居中, 内容居中
    -- width: 90%; 满足 80%-100% 范围
    -- margin: 0 auto; 实现页面居中
    -- text-align: center; 实现内容居中
     table.insert(output, '{| class="wikitable sortable" style="width: 90%; margin: 0 auto; text-align: center;"')
     table.insert(output, '{| class="wikitable sortable" style="width: 90%; margin: 0 auto; text-align: center;"')
     table.insert(output, '|-')
     table.insert(output, '|-')
      
      
     -- **移除 ID 列表头**
     -- 构造表格头部 (不包含 ID)
    -- table.insert(output, '! ' .. (displayNames['id'] or 'ID'))  
   
     for _, field in ipairs(displayFields) do
     for _, field in ipairs(displayFields) do
         field = mw.text.trim(field)
         field = mw.text.trim(field)
第268行: 第278行:
         table.insert(output, '|-')
         table.insert(output, '|-')
          
          
         -- **移除 ID 列单元格**
         -- 数据字段
        -- table.insert(output, '| ' .. songId)
       
        -- 后续列: 数据字段
         for _, field in ipairs(displayFields) do
         for _, field in ipairs(displayFields) do
             field = mw.text.trim(field)
             field = mw.text.trim(field)
第286行: 第293行:
     end
     end
      
      
    -- 闭合表格
     table.insert(output, '|}')
     table.insert(output, '|}')