模块:收纳表
外观
此模块的文档可以在模块:收纳表/doc创建
--各个可在模版中使用的的参数的用途,如
--(参数名)(=某值,代表预设值,nil代表空的值): (用途)
--大小写有区别!
--[[
selectHeight = nil: 选择栏的高度,如100px。若有设置而内容太长挤不进去,则右方会多一个滚动条
textHeight = nil: 内容框的高度,如10em。同上。
selectWidth = nil: 选择栏的宽度,如50%。若有设置而内容太长挤不进去,则下方会多一个滚动条
textWidth = nil: 内容框的宽度,如75ch。同上。
splitCount = 5: 决定每行有几个物件
textDisplay = top: 内容相对于选择栏的位置,可输入
top(内容在选择栏上)
down(内容在选择栏下)
left(内容在选择栏左,此时selectWidth会被设置成20%、textWidth被设成60%、textHeight, selectHeight皆被设成400px)
right(内容在选择栏右,同上)
--]]
local p = {}
--处理可选择人名
local function renderSelect(tabIndices, args)
local splitCount = tonumber(args['splitCount'])
local tabs_pages = mw.html.create('div')
:addClass('tabs_pages')
:css('display', 'grid')
:css('margin', '2.5%')
:css('gap', '6px')
:css('grid-template-columns', string.rep('1fr ', splitCount))
if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then
tabs_pages
:css('display', 'inline-grid')
:css('height', '400px')
:css('width', '20%')
end
if args['selectHeight'] ~= nil then
tabs_pages
:css('height', args['selectHeight'])
:css('overflow-y', 'auto')
end
if args['selectWidth'] ~= nil then
tabs_pages
:css('width', args['selectWidth'])
:css('overflow-x', 'auto')
end
for _, tabIndex in ipairs(tabIndices) do
tabs_pages:tag('div')
:addClass('tab')
:css('margin', '0')
:css('font-weight', '700')
:wikitext(args['tab' .. tabIndex])
end
return tostring(tabs_pages)
end
--处理感言内容
local function renderContent(tabIndices, args)
local tabs_contents = mw.html.create('div')
:addClass('tabs-contents')
if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then
tabs_contents
:css('display', 'inline-grid')
:css('height', '400px')
:css('width', '60%')
end
if args['textHeight'] ~= nil then
tabs_contents
:css('height', args['textHeight'])
:css('overflow-y', 'auto')
end
if args['textWidth'] ~= nil then
tabs_contents
:css('width', args['textWidth'])
:css('overflow-x', 'auto')
end
for _, tabIndex in ipairs(tabIndices) do
tabs_contents:tag('div')
:addClass('tab-c')
:wikitext(args['content' .. tabIndex])
end
return tostring(tabs_contents)
end
function p.selectTable(frame)
local args = {splitCount=5}
local tabIndices = {}
--获取页面传来的参数,而非模板本身的参数
local parent_args = frame:getParent().args;
--将获取的参数传给args
for k, v in pairs(parent_args) do
if v ~= 'nil' then args[k] = v end --避免空的参数
end
--|tab(x) 的数字可能非123...,可能是012...、037...等
--用于处理上述情况
for k, _ in pairs(args) do
local tabIndex = ('' .. k):match('^tab(%d+)$')
if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end
end
table.sort(tabIndices)
--处理勋章
local mainDiv = mw.html.create('div')
:addClass('tabs-container')
if args['textDisplay'] == 'down' or args['textDisplay'] == 'left' then
mainDiv:node(renderContent(tabIndices, args))
mainDiv:node(renderSelect(tabIndices, args))
else
mainDiv:node(renderSelect(tabIndices, args))
mainDiv:node(renderContent(tabIndices, args))
end
return tostring(mainDiv)
end
return p