模块:Db:修订间差异
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
MJ Hamster(留言 | 贡献) 小无编辑摘要 |
||
| 第15行: | 第15行: | ||
-- [[------------------------------------------------------------------]] | -- [[------------------------------------------------------------------]] | ||
-- [[ 2. 表格标题映射 | -- [[ 2. 表格标题映射 ]] | ||
-- [[------------------------------------------------------------------]] | -- [[------------------------------------------------------------------]] | ||
local displayNames = { | local displayNames = { | ||
-- | -- 核心字段 | ||
['title'] = '歌曲标题', | ['title'] = '歌曲标题', | ||
['composer'] = '艺术家', | ['composer'] = '艺术家', | ||
| 第30行: | 第30行: | ||
-- 保留常用字段 | -- 保留常用字段 | ||
['duration'] = '时长', | ['duration'] = '时长', | ||
-- 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 | ||
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), | ||
[' | ['composer'] = autoLink, | ||
['singer'] = autoLink, | |||
['bga'] = autoLink, | |||
} | } | ||
| 第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%, 居中, 内容居中 | ||
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) | ||
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, '|-') | ||
-- | -- 数据字段 | ||
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, '|}') | ||