打开/关闭菜单
切换首选项菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:BusDepot:修订间差异

来自珠海交通维基
无编辑摘要
无编辑摘要
标签已被回退
第2行: 第2行:
local p = {}
local p = {}


-- 全局状态(模拟变量)
function p.display(frame)
local state = {
    -- 初始化
    depot = '',
     local route = frame.args.route or '22'
    depot1 = 1,
    local html = mw.html.create('table'):addClass('wikitable')
    num = 0,
    depotlen = 1
}
 
function p.count(frame)
     local depot = frame.args.depot or ''
      
      
     -- 重置或更新状态
     -- 添加表头
     if state.depot == '' then
     html:node(frame:expandTemplate{ title = '线路配车表格头' })
         state.depot1 = 1
   
        state.num = 0
    -- 假设dt2-showtable提供数据库接口(需确认扩展API)
    elseif state.depot == depot then
    local db = mw.ext.data.getDB()
        state.depot1 = state.depot1 + 1
    local rows = db:query{
    else
        table = 'bustable',
        state.num = state.num + 1
        where = {
         state.depot1 = 1
            ['route1'] = route,
            ['route2'] = route,
            status = '营运'
        },
        where_operator = 'OR', -- route1 OR route2
        order_by = 'depot'
    }
   
    -- 计数逻辑
    local depot_counts = {}
    local current_depot = ''
    local depot1 = 0
    local num = 0
   
    for _, row in ipairs(rows) do
         local depot = row.depot or ''
       
        -- 计数
        if current_depot == '' then
            depot1 = 1
            num = 0
        elseif current_depot == depot then
            depot1 = depot1 + 1
        else
            num = num + 1
            depot1 = 1
        end
        current_depot = depot
        depot_counts[depot] = depot1
       
         -- 渲染行
        html:node(frame:expandTemplate{
            title = '线路配车',
            args = {
                number = row.number,
                depot = depot,
                model = row.model,
                batch = row.batch,
                faci = row.faci,
                color = row.color,
                shift = row.shift,
                attr = row.attr,
                depotlen = depot_counts[depot]
            }
        })
     end
     end
      
      
    -- 更新当前depot和depotlen
     return tostring(html)
    state.depot = depot
    state.depotlen = state.depot1
   
     return ''
end
 
function p.getDepotLen(frame)
    return state.depotlen
end
end


return p
return p

2025年4月15日 (二) 11:02的版本

此模块的文档可以在模块:BusDepot/doc创建

-- Module:BusDepot
local p = {}

function p.display(frame)
    -- 初始化
    local route = frame.args.route or '22'
    local html = mw.html.create('table'):addClass('wikitable')
    
    -- 添加表头
    html:node(frame:expandTemplate{ title = '线路配车表格头' })
    
    -- 假设dt2-showtable提供数据库接口(需确认扩展API)
    local db = mw.ext.data.getDB()
    local rows = db:query{
        table = 'bustable',
        where = { 
            ['route1'] = route,
            ['route2'] = route,
            status = '营运'
        },
        where_operator = 'OR', -- route1 OR route2
        order_by = 'depot'
    }
    
    -- 计数逻辑
    local depot_counts = {}
    local current_depot = ''
    local depot1 = 0
    local num = 0
    
    for _, row in ipairs(rows) do
        local depot = row.depot or ''
        
        -- 计数
        if current_depot == '' then
            depot1 = 1
            num = 0
        elseif current_depot == depot then
            depot1 = depot1 + 1
        else
            num = num + 1
            depot1 = 1
        end
        current_depot = depot
        depot_counts[depot] = depot1
        
        -- 渲染行
        html:node(frame:expandTemplate{
            title = '线路配车',
            args = {
                number = row.number,
                depot = depot,
                model = row.model,
                batch = row.batch,
                faci = row.faci,
                color = row.color,
                shift = row.shift,
                attr = row.attr,
                depotlen = depot_counts[depot]
            }
        })
    end
    
    return tostring(html)
end

return p