• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

gantt/甘特图完整代码带注释,可以复制

武飞扬头像
zheshihuahua
帮助1

 官网地址:Gantt : Samples

效果图:

学新通

代码: 

  1.  
    <!DOCTYPE html>
  2.  
    <html>
  3.  
     
  4.  
    <head>
  5.  
    <meta charset="utf-8">
  6.  
    <title></title>
  7.  
    <meta name="renderer" content="webkit">
  8.  
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  9.  
    <meta name="viewport"
  10.  
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  11.  
    <link rel="stylesheet" href="../../component/layui/css/layui.css" media="all">
  12.  
    <link rel="stylesheet" href="../../component/style/admin.css" media="all">
  13.  
    <link rel="stylesheet" href="../../component/dhtmlxgantt.css" type="text/css">
  14.  
    <script src="../../component/dhtmlxgantt.js"></script>
  15.  
    <!--[if lt IE 9]>
  16.  
    <script src="../../component/html5.min.js"></script>
  17.  
    <script src="../../component/respond.min.js"></script>
  18.  
    <![endif]-->
  19.  
    <style>
  20.  
    html,
  21.  
    body {
  22.  
    height: 100%;
  23.  
    padding: 0px;
  24.  
    margin: 0px;
  25.  
    overflow: hidden;
  26.  
    }
  27.  
     
  28.  
    .weekend {
  29.  
    background: #f4f7f4 !important;
  30.  
    }
  31.  
     
  32.  
    .gantt_grid_head_cell {
  33.  
    font-size: 14px;
  34.  
    font-weight: 600;
  35.  
    color: #000 !important;
  36.  
    }
  37.  
     
  38.  
    .gantt_scale_cell {
  39.  
    font-size: 14px;
  40.  
    font-weight: 600;
  41.  
    color: #000 !important;
  42.  
     
  43.  
    }
  44.  
    </style>
  45.  
    </head>
  46.  
     
  47.  
    <body>
  48.  
    <div class="layui-fluid">
  49.  
    <div class="layui-card">
  50.  
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
  51.  
    <div class="layui-row">
  52.  
    <div class="layui-col-md3">
  53.  
    <div class="layui-form-item">
  54.  
    <label class="layui-form-label">订单名称</label>
  55.  
    <div class="layui-input-block">
  56.  
    <select id="orderId" name="orderId" autocomplete="off" lay-search>
  57.  
    <option value="">请选择订单</option>
  58.  
    </select>
  59.  
    </div>
  60.  
    </div>
  61.  
    </div>
  62.  
    <div class="layui-col-md3">
  63.  
    <div class="layui-form-item">
  64.  
    <label class="layui-form-label">设备编码</label>
  65.  
    <div class="layui-input-block">
  66.  
    <input id="deviceCode" type="text" name="deviceCode" placeholder="请选择设备编码"
  67.  
    autocomplete="off" class="layui-input start">
  68.  
    </div>
  69.  
    </div>
  70.  
    </div>
  71.  
    <div class="layui-col-md3">
  72.  
    <div class="layui-form-item">
  73.  
    <div class="layui-inline">
  74.  
    <button style="margin-left: 50px;"
  75.  
    class="layui-btn layui-btn-vat layuiadmin-btn-useradmin layui-bg-blue" lay-submit
  76.  
    lay-filter="spmrp-search">
  77.  
    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  78.  
    查询
  79.  
    </button>
  80.  
    </div>
  81.  
    </div>
  82.  
    </div>
  83.  
    </div>
  84.  
    </div>
  85.  
    <div class="layui-card-body">
  86.  
    <div class="layui-btn-container">
  87.  
    <button type="button" id="reset" class="layui-btn layui-btn-danger">重排
  88.  
    </button>
  89.  
    </div>
  90.  
    <div id="device_load" style='width:100%;'></div>
  91.  
    </div>
  92.  
    </div>
  93.  
    </div>
  94.  
    <script src="../../component/layui/layui.js"></script>
  95.  
    <script>
  96.  
    layui.config({
  97.  
    base: '../../component/'
  98.  
    }).extend({
  99.  
    index: 'lib/index'
  100.  
    }).use(['index', 'view', 'form', 'laydate'], function () {
  101.  
    var $ = layui.$,
  102.  
    form = layui.form,
  103.  
    view = layui.view,
  104.  
    layer = layui.layer,
  105.  
    laydate = layui.laydate;
  106.  
     
  107.  
    view.req({
  108.  
    method: 'POST',
  109.  
    data: JSON.stringify({ orderComplete: 0, page: 1, limit: 99999 }),
  110.  
    url: layui.setter.api 'biz/order/produce/page',
  111.  
    success: function (res) {
  112.  
    data = res["data"]["list"] || [];
  113.  
    if (data.length > 0) {
  114.  
    var element = document.getElementById("orderId");
  115.  
    for (var i = 0; i < data.length; i ) {
  116.  
    var option = document.createElement("option");
  117.  
    option.setAttribute("value", data[i]["ordNo"]);
  118.  
    option.innerText = data[i]["project"];
  119.  
    element.appendChild(option);
  120.  
    }
  121.  
    form.render("select");
  122.  
    }
  123.  
    }
  124.  
    });
  125.  
     
  126.  
    // 颜色
  127.  
    function randomColor1() {
  128.  
    var r = Math.floor(Math.random() * 256);
  129.  
    var g = Math.floor(Math.random() * 256);
  130.  
    var b = Math.floor(Math.random() * 256);
  131.  
    if (r < 16) {
  132.  
    r = "0" r.toString(16);
  133.  
    } else {
  134.  
    r = r.toString(16);
  135.  
    }
  136.  
    if (g < 16) {
  137.  
    g = "0" g.toString(16);
  138.  
    } else {
  139.  
    g = g.toString(16);
  140.  
    }
  141.  
    if (b < 16) {
  142.  
    b = "0" b.toString(16);
  143.  
    } else {
  144.  
    b = b.toString(16);
  145.  
    }
  146.  
    return "#" r g b;
  147.  
    }
  148.  
     
  149.  
    function renderPanel() {
  150.  
    document.getElementById('device_load').style.cssText = 'height:' ($(window).height() - 140) 'px';
  151.  
    }
  152.  
     
  153.  
    $(window).resize(function () {
  154.  
    renderPanel();
  155.  
    });
  156.  
    renderPanel();
  157.  
     
  158.  
    // gantt.templates.tooltip_text = function (start, end, task) {
  159.  
    // var div = '<table class="layui-table"><thead><tr><th>订单</th><th>产品</th><th>数量</th><th>占用产能</th></tr></thead><tbody>';
  160.  
    // for (var i = 0; i < task.orders.length; i ) {
  161.  
    // div = '<tr>';
  162.  
    // div = '<td>' task.orders[i].order '</td>'
  163.  
    // '<td>' task.orders[i].product '</td>'
  164.  
    // '<td>' task.orders[i].qty '</td>'
  165.  
    // '<td>' percenToString(task.orders[i].progress) '</td>';
  166.  
    // div = '</tr>';
  167.  
    // }
  168.  
    // div = '</tbody></table>';
  169.  
    // return div;
  170.  
    // };
  171.  
    // 尺寸比例
  172.  
    function percenToString(num) {
  173.  
    return Math.floor(num * 100) '%';
  174.  
    }
  175.  
     
  176.  
    function renderLabel(progress, type, sum) {
  177.  
    var relWidth = progress * 100;
  178.  
     
  179.  
    switch (type) {
  180.  
    case 1:
  181.  
    return "<div class='custom_progress idle' style='width:" relWidth "%'>"
  182.  
    percenToString(progress) "</div>";
  183.  
    break;
  184.  
    case 2:
  185.  
    return "<div class='custom_progress in_progress' style='width:" relWidth "%'>" percenToString(progress) "</div>";
  186.  
    break;
  187.  
    case 3:
  188.  
    return "<div class='custom_progress ' style='width:" relWidth "%;background-color:" randomColor1() "'>" percenToString(progress) "</div>";
  189.  
    break;
  190.  
    default:
  191.  
    return "<div class='custom_progress ' style='width:" relWidth "%;background-color:" randomColor1() "''>" percenToString(progress) "</div>";
  192.  
    break;
  193.  
     
  194.  
    }
  195.  
    }
  196.  
     
  197.  
    // gantt.templates.task_text = function (start, end, task) {
  198.  
    // var div = '';
  199.  
    // var relWidth=0;
  200.  
    //
  201.  
    // for (var i = 0; i < task.orders.length; i ) {
  202.  
    // div = renderLabel(task.orders[i].progress, 1 i, task.storage);
  203.  
    // relWidth =task.orders[i].progress * 100;
  204.  
    //
  205.  
    // }
  206.  
    //
  207.  
    // //剩余宽度--------------------------------------------
  208.  
    // var RWidth=100-relWidth;
  209.  
    // if(RWidth>0)
  210.  
    // {
  211.  
    // div = "<div class='custom_progress nearly_done' style='width:" RWidth "%'></div>";
  212.  
    // }
  213.  
    //
  214.  
    // //--------------------------------------------
  215.  
    // return div;
  216.  
    // };
  217.  
    // 时间格式
  218.  
    gantt.config.date_format = "%Y-%m-%d";
  219.  
    gantt.config.scales = [
  220.  
    { unit: "year", step: 1, format: "%Y" },
  221.  
    { unit: "day", step: 1, date: "%m-%d" },
  222.  
    { unit: "hour", step: 1, format: "%H:%i" }
  223.  
    ];
  224.  
     
  225.  
     
  226.  
    gantt.config.reorder_grid_columns = true;
  227.  
    gantt.config.columns = [{
  228.  
    name: "text",
  229.  
    label: "任务名",
  230.  
    width: 200,
  231.  
    align: "center",
  232.  
    tree: true,
  233.  
    resize: true
  234.  
    }, {
  235.  
    name: "start_date",
  236.  
    label: "开始日期",
  237.  
    width: 100,
  238.  
    align: "center",
  239.  
    resize: true
  240.  
    }, {
  241.  
    name: "duration",
  242.  
    label: "持续时间",
  243.  
    width: 100,
  244.  
    align: "center",
  245.  
    resize: true
  246.  
     
  247.  
    }];
  248.  
     
  249.  
     
  250.  
    gantt.config.row_height = 40;
  251.  
    gantt.config.scale_height = 50;
  252.  
    gantt.config.drag_move = false;
  253.  
    gantt.config.drag_resize = false;
  254.  
    gantt.config.sort = true;
  255.  
    gantt.config.show_quick_info = false;
  256.  
    // 关闭点击事件
  257.  
    gantt.attachEvent("onTaskDblClick", function (id, e) {
  258.  
    return false;
  259.  
    });
  260.  
     
  261.  
    gantt.config.show_tasks_outside_timescale = true;
  262.  
    gantt.plugins({
  263.  
    auto_scheduling: true, //自动排程
  264.  
    tooltip: true //提示信息
  265.  
    });
  266.  
     
  267.  
    gantt.config.start_date = new Date("2022-11-03 00:00:00");
  268.  
    gantt.config.end_date = new Date("2022-11-03 23:59:59");
  269.  
    // 样式
  270.  
    gantt.config.layout = {
  271.  
    css: "gantt_container",
  272.  
    cols: [{
  273.  
    width: 400,
  274.  
    min_width: 300,
  275.  
    rows: [
  276.  
    {
  277.  
    view: "grid",
  278.  
    scrollX: "gridScroll",
  279.  
    scrollable: true,
  280.  
    scrollY: "scrollVer"
  281.  
    },
  282.  
    { view: "scrollbar", id: "gridScroll", group: "horizontal" }
  283.  
    ]
  284.  
    },
  285.  
    { resizer: true, width: 1 },
  286.  
    {
  287.  
    rows: [
  288.  
    {
  289.  
    view: "timeline",
  290.  
    scrollX: "scrollHor",
  291.  
    scrollY: "scrollVer"
  292.  
    },
  293.  
    {
  294.  
    view: "scrollbar",
  295.  
    id: "scrollHor",
  296.  
    group: "horizontal"
  297.  
    }
  298.  
    ]
  299.  
    },
  300.  
    { view: "scrollbar", id: "scrollVer" }]
  301.  
    };
  302.  
     
  303.  
    gantt.init("device_load");
  304.  
     
  305.  
    gantt.i18n.setLocale("cn"); //使用中文
  306.  
    function render() {
  307.  
    var index = layer.load(); //后面会使用这赋值来关闭这个页面
  308.  
    view.req({
  309.  
    method: 'POST',
  310.  
    data: JSON.stringify({
  311.  
    orderId: $('#orderId').val(),
  312.  
    deviceCode: $('#deviceCode').val()
  313.  
    }),
  314.  
    url: layui.setter.api "biz/plan/device/load",
  315.  
    success: function (res) {
  316.  
     
  317.  
    gantt.clearAll(); //清空缓存
  318.  
    console.info("gantt", gantt.config.end_date);
  319.  
    var data = [
  320.  
    { id: "10cz1t", text: "P220901-044", type: "project", progress: 0.88, open: true, parent: 0 },
  321.  
    { id: "11cz1t", text: "L3660", type: "project", progress: 0, open: true, parent: "10cz1t" },
  322.  
     
  323.  
     
  324.  
    { id: "12cz1t", text: "备膜", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },
  325.  
     
  326.  
    { id: "121cz1t", text: "Stage #1", start_date: "2022-11-03 01:00", end_date: "2022-11-03 05:00", parent: "12cz1t", progress: 0, open: true },
  327.  
     
  328.  
    { id: "13cz1t", text: "挤压加工", type: "project", render: "split", parent: "11cz1t", progress: 0.5, open: false },
  329.  
    { id: "131cz1t", text: "Stage #1", start_date: "2022-11-03 01:00", end_date: "2022-11-03 02:00", parent: "13cz1t", progress: 0, open: true },
  330.  
    { id: "132cz1t", text: "Stage #2", start_date: "2022-11-03 04:00", end_date: "2022-11-03 05:00", parent: "13cz1t", progress: 0, open: true },
  331.  
    { id: "133cz1t", text: "Stage #3", start_date: "2022-11-03 07:00", end_date: "2022-11-03 08:00", parent: "13cz1t", progress: 0, open: true },
  332.  
    { id: "134cz1t", text: "Stage #4", start_date: "2022-11-03 10:00", end_date: "2022-11-03 11:00", parent: "13cz1t", progress: 0, open: true },
  333.  
    { id: "135cz1t", text: "Stage #5", start_date: "2022-11-03 13:00", end_date: "2022-11-03 14:00", parent: "13cz1t", progress: 0, open: true },
  334.  
    { id: "136cz1t", text: "Stage #6", start_date: "2022-11-03 16:00", end_date: "2022-11-03 17:00", parent: "13cz1t", progress: 0, open: true },
  335.  
    { id: "137cz1t", text: "Stage #7", start_date: "2022-11-03 19:00", end_date: "2022-11-03 20:00", parent: "13cz1t", progress: 0, open: true },
  336.  
     
  337.  
    { id: "24cz1t", text: "时效加工", type: "project", render: "split", parent: "11cz1t", progress: 0.5, open: false },
  338.  
    { id: "241cz1t", text: "Stage #1", start_date: "2022-11-03 05:00", end_date: "2022-11-03 06:00", parent: "24cz1t", progress: 0, open: true },
  339.  
    { id: "242cz1t", text: "Stage #2", start_date: "2022-11-03 11:00", end_date: "2022-11-03 12:00", parent: "24cz1t", progress: 0, open: true },
  340.  
    { id: "243cz1t", text: "Stage #3", start_date: "2022-11-03 17:00", end_date: "2022-11-03 18:00", parent: "24cz1t", progress: 0, open: true },
  341.  
    { id: "244cz1t", text: "Stage #4", start_date: "2022-11-03 20:00", end_date: "2022-11-03 21:00", parent: "24cz1t", progress: 0, open: true },
  342.  
     
  343.  
     
  344.  
    { id: "25cz1t", text: "氧化包装", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },
  345.  
    { id: "251cz1t", text: "Stage #1", start_date: "2022-11-03 06:00", end_date: "2022-11-03 07:00", parent: "25cz1t", progress: 0, open: true },
  346.  
    { id: "252cz1t", text: "Stage #2", start_date: "2022-11-03 08:00", end_date: "2022-11-03 09:00", parent: "25cz1t", progress: 0, open: true },
  347.  
    { id: "253cz1t", text: "Stage #3", start_date: "2022-11-03 12:00", end_date: "2022-11-03 13:00", parent: "25cz1t", progress: 0, open: true },
  348.  
    { id: "254cz1t", text: "Stage #4", start_date: "2022-11-03 14:00", end_date: "2022-11-03 15:00", parent: "25cz1t", progress: 0, open: true },
  349.  
    { id: "255cz1t", text: "Stage #5", start_date: "2022-11-03 18:00", end_date: "2022-11-03 19:00", parent: "25cz1t", progress: 0, open: true },
  350.  
    { id: "256cz1t", text: "Stage #6", start_date: "2022-11-03 20:00", end_date: "2022-11-03 21:00", parent: "25cz1t", progress: 0, open: true },
  351.  
    { id: "257cz1t", text: "Stage #7", start_date: "2022-11-03 22:00", end_date: "2022-11-03 23:30", parent: "25cz1t", progress: 0, open: true },
  352.  
     
  353.  
     
  354.  
    { id: "29cz1t", text: "测试包装", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },
  355.  
    { id: "291cz1t", text: "Stage #5", start_date: "2022-11-03 15:00", end_date: "2022-11-03 16:00", parent: "29cz1t", progress: 0, open: true },
  356.  
    { id: "292cz1t", text: "Stage #6", start_date: "2022-11-03 17:00", end_date: "2022-11-03 18:00", parent: "29cz1t", progress: 0, open: true },
  357.  
     
  358.  
     
  359.  
    { id: "28cz1t", text: "L3660", type: "project", progress: 0, open: true, parent: "10cz1t" },
  360.  
    // ,start_date: "2022-11-03 01:00",end_date: "2022-11-03 03:00"
  361.  
    { id: "281cz1t", text: "备膜", start_date: "2022-11-03 01:00", end_date: "2022-11-03 03:00", parent: "28cz1t", progress: 0, open: true },
  362.  
    { id: "281cz1t1", text: "备膜1", start_date: "2022-11-03 02:30", end_date: "2022-11-03 05:30", parent: "28cz1t", progress: 0, open: true },
  363.  
    { id: "281cz1t2", text: "备膜2", start_date: "2022-11-03 06:50", end_date: "2022-11-03 07:50", parent: "28cz1t", progress: 0, open: true },
  364.  
     
  365.  
    { id: "282cz1t", text: "挤压加工", start_date: "2022-11-03 08:00", end_date: "2022-11-03 09:00", parent: "28cz1t", progress: 0.5, open: true },
  366.  
    { id: "283cz1t", text: "时效加工", start_date: "2022-11-03 010:00", end_date: "2022-11-03 11:00", parent: "28cz1t", progress: 0, open: true },
  367.  
    { id: "284cz1t", text: "氧化包装", start_date: "2022-11-03 11:00", end_date: "2022-11-03 12:00", parent: "28cz1t", progress: 0, open: true },
  368.  
     
  369.  
     
  370.  
    ];
  371.  
    var datalist = new Array();
  372.  
    $.each(data, function (i, item) {
  373.  
     
  374.  
    var model = new Object();
  375.  
    model.id = item.id;
  376.  
    model.text = item.text;
  377.  
    if (item.type != null) {
  378.  
    model.type = item.type;
  379.  
    }
  380.  
     
  381.  
    model.progress = item.progress;
  382.  
    model.open = item.open;
  383.  
    model.start_date = new Date(item.start_date);
  384.  
    model.end_date = new Date(item.end_date);
  385.  
    model.parent = item.parent;
  386.  
    if (item.render != null) {
  387.  
    model.render = item.render;
  388.  
    }
  389.  
     
  390.  
    datalist.push(model);
  391.  
     
  392.  
    });
  393.  
     
  394.  
    // 数据之间的关系
  395.  
    var links = [
  396.  
    // {id: "1", source: "10", target: "11", type: "1"},
  397.  
    // {id: "2", source: "11", target: "12", type: "1"},
  398.  
    // {id: "3", source: "10", target: "28", type: "1"},
  399.  
    //
  400.  
    // {id: "4", source: "12", target: "131", type: "1"},
  401.  
    // source:连接谁 ; target:和谁连 ; (里面写data里面的id)
  402.  
     
  403.  
    { id: "5c", source: "131cz1t", target: "241cz1t", type: "0" },
  404.  
    { id: "6c", source: "132cz1t", target: "241cz1t", type: "0" },
  405.  
     
  406.  
     
  407.  
    { id: "7c", source: "133cz1t", target: "242cz1t", type: "0" },
  408.  
    { id: "8c", source: "134cz1t", target: "242cz1t", type: "0" },
  409.  
     
  410.  
     
  411.  
    { id: "9c", source: "135cz1t", target: "243cz1t", type: "0" },
  412.  
    { id: "10c", source: "136cz1t", target: "243cz1t", type: "0" },
  413.  
    { id: "11c", source: "137cz1t", target: "244cz1t", type: "0" },
  414.  
     
  415.  
     
  416.  
     
  417.  
    { id: "14c", source: "241cz1t", target: "253cz1t", type: "0", color: "green" },
  418.  
    { id: "13c", source: "241cz1t", target: "252cz1t", type: "0", color: "green" },
  419.  
    { id: "12c", source: "241cz1t", target: "251cz1t", type: "0", color: "green" },
  420.  
     
  421.  
    { id: "16c", source: "242cz1t", target: "254cz1t", type: "0", color: "green" },
  422.  
    { id: "15c", source: "242cz1t", target: "253cz1t", type: "0", color: "green" },
  423.  
     
  424.  
     
  425.  
    { id: "19c", source: "243cz1t", target: "257cz1t", type: "0", color: "green" },
  426.  
    { id: "18c", source: "243cz1t", target: "256cz1t", type: "0", color: "green" },
  427.  
    { id: "17c", source: "243cz1t", target: "255cz1t", type: "0", color: "green" },
  428.  
     
  429.  
     
  430.  
    { id: "21c", source: "254cz1t", target: "292cz1t", type: "0", color: "blue" },
  431.  
    { id: "20c", source: "254cz1t", target: "291cz1t", type: "0", color: "blue" },
  432.  
     
  433.  
     
  434.  
    { id: "22c", source: "28cz1t", target: "281cz1t", type: "0", color: "red" },
  435.  
    { id: "23c", source: "281cz1t", target: "281cz1t1", type: "0", color: "red" },
  436.  
    { id: "24c", source: "281cz1t", target: "281cz1t2", type: "0", color: "red" },
  437.  
     
  438.  
     
  439.  
    { id: "25c", source: "281cz1t", target: "282cz1t", type: "0", color: "hotpink" },
  440.  
    { id: "26c", source: "281cz1t", target: "284cz1t", type: "0", color: "hotpink" },
  441.  
    { id: "27c", source: "281cz1t", target: "283cz1t", type: "0", color: "hotpink" },
  442.  
    { id: "28c", source: "281cz1t", target: "284cz1t", type: "0", color: "hotpink" },
  443.  
     
  444.  
     
  445.  
     
  446.  
     
  447.  
    ]
  448.  
    //解析
  449.  
    gantt.parse({
  450.  
    data: datalist,
  451.  
    links: links
  452.  
    });
  453.  
    console.info("gantt", gantt);
  454.  
     
  455.  
    layer.close(index); //关闭页面
  456.  
    }
  457.  
    });
  458.  
    }
  459.  
     
  460.  
    render();
  461.  
    $('#reset').click(function () {
  462.  
    view.req({
  463.  
    method: 'get',
  464.  
    url: layui.setter.api "biz/plan/device/init",
  465.  
    success: function (res) {
  466.  
    render();
  467.  
    }
  468.  
    });
  469.  
    });
  470.  
    form.on('submit(spmrp-search)', function (data) {
  471.  
    render();
  472.  
    });
  473.  
     
  474.  
     
  475.  
     
  476.  
     
  477.  
    });
  478.  
    </script>
  479.  
    </body>
  480.  
     
  481.  
    </html>
学新通

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="https://blog.csdn.net/zheshihuahua/component/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="https://blog.csdn.net/zheshihuahua/component/style/admin.css" media="all">
    <link rel="stylesheet" href="https://blog.csdn.net/zheshihuahua/component/dhtmlxgantt.css" type="text/css">
    <script src="https://blog.csdn.net/zheshihuahua/component/dhtmlxgantt.js"></script>
    <!--[if lt IE 9]>
    <script src="https://blog.csdn.net/zheshihuahua/component/html5.min.js"></script>
    <script src="https://blog.csdn.net/zheshihuahua/component/respond.min.js"></script>
    <![endif]-->
    <style>
        html,
        body {
            height: 100%;
            padding: 0px;
            margin: 0px;
            overflow: hidden;
        }

        .weekend {
            background: #f4f7f4 !important;
        }

        .gantt_grid_head_cell {
            font-size: 14px;
            font-weight: 600;
            color: #000 !important;
        }

        .gantt_scale_cell {
            font-size: 14px;
            font-weight: 600;
            color: #000 !important;

        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单名称</label>
                            <div class="layui-input-block">
                                <select id="orderId" name="orderId" autocomplete="off" lay-search>
                                    <option value="">请选择订单</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item">
                            <label class="layui-form-label">设备编码</label>
                            <div class="layui-input-block">
                                <input id="deviceCode" type="text" name="deviceCode" placeholder="请选择设备编码"
                                    autocomplete="off" class="layui-input start">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button style="margin-left: 50px;"
                                    class="layui-btn layui-btn-vat layuiadmin-btn-useradmin layui-bg-blue" lay-submit
                                    lay-filter="spmrp-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                    查询
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <div class="layui-btn-container">
                    <button type="button" id="reset" class="layui-btn layui-btn-danger">重排
                    </button>
                </div>
                <div id="device_load" style='width:100%;'></div>
            </div>
        </div>
    </div>
    <script src="https://blog.csdn.net/zheshihuahua/component/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../component/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'view', 'form', 'laydate'], function () {
            var $ = layui.$,
                form = layui.form,
                view = layui.view,
                layer = layui.layer,
                laydate = layui.laydate;

            view.req({
                method: 'POST',
                data: JSON.stringify({ orderComplete: 0, page: 1, limit: 99999 }),
                url: layui.setter.api 'biz/order/produce/page',
                success: function (res) {
                    data = res["data"]["list"] || [];
                    if (data.length > 0) {
                        var element = document.getElementById("orderId");
                        for (var i = 0; i < data.length; i ) {
                            var option = document.createElement("option");
                            option.setAttribute("value", data[i]["ordNo"]);
                            option.innerText = data[i]["project"];
                            element.appendChild(option);
                        }
                        form.render("select");
                    }
                }
            });

            //  颜色
            function randomColor1() {
                var r = Math.floor(Math.random() * 256);
                var g = Math.floor(Math.random() * 256);
                var b = Math.floor(Math.random() * 256);
                if (r < 16) {
                    r = "0" r.toString(16);
                } else {
                    r = r.toString(16);
                }
                if (g < 16) {
                    g = "0" g.toString(16);
                } else {
                    g = g.toString(16);
                }
                if (b < 16) {
                    b = "0" b.toString(16);
                } else {
                    b = b.toString(16);
                }
                return "#" r g b;
            }

            function renderPanel() {
                document.getElementById('device_load').style.cssText = 'height:' ($(window).height() - 140) 'px';
            }

            $(window).resize(function () {
                renderPanel();
            });
            renderPanel();

            // gantt.templates.tooltip_text = function (start, end, task) {
            //     var div = '<table class="layui-table"><thead><tr><th>订单</th><th>产品</th><th>数量</th><th>占用产能</th></tr></thead><tbody>';
            //     for (var i = 0; i < task.orders.length; i ) {
            //         div = '<tr>';
            //         div = '<td>' task.orders[i].order '</td>'
            //             '<td>' task.orders[i].product '</td>'
            //             '<td>' task.orders[i].qty '</td>'
            //             '<td>' percenToString(task.orders[i].progress) '</td>';
            //         div = '</tr>';
            //     }
            //     div = '</tbody></table>';
            //     return div;
            // };
            // 尺寸比例
            function percenToString(num) {
                return Math.floor(num * 100) '%';
            }

            function renderLabel(progress, type, sum) {
                var relWidth = progress * 100;

                switch (type) {
                    case 1:
                        return "<div class='custom_progress idle' style='width:" relWidth "%'>"
                            percenToString(progress) "</div>";
                        break;
                    case 2:
                        return "<div class='custom_progress in_progress' style='width:" relWidth "%'>" percenToString(progress) "</div>";
                        break;
                    case 3:
                        return "<div class='custom_progress ' style='width:" relWidth "%;background-color:" randomColor1() "'>" percenToString(progress) "</div>";
                        break;
                    default:
                        return "<div class='custom_progress ' style='width:" relWidth "%;background-color:" randomColor1() "''>" percenToString(progress) "</div>";
                        break;

                }
            }

            // gantt.templates.task_text = function (start, end, task) {
            //     var div = '';
            //     var relWidth=0;
            //
            //     for (var i = 0; i < task.orders.length; i ) {
            //         div = renderLabel(task.orders[i].progress, 1 i, task.storage);
            //         relWidth =task.orders[i].progress  * 100;
            //
            //     }
            //
            //     //剩余宽度--------------------------------------------
            //     var RWidth=100-relWidth;
            //     if(RWidth>0)
            //     {
            //         div = "<div class='custom_progress nearly_done' style='width:" RWidth "%'></div>";
            //     }
            //
            //     //--------------------------------------------
            //     return div;
            // };
            // 时间格式
            gantt.config.date_format = "%Y-%m-%d";
            gantt.config.scales = [
                { unit: "year", step: 1, format: "%Y" },
                { unit: "day", step: 1, date: "%m-%d" },
                { unit: "hour", step: 1, format: "%H:%i" }
            ];


            gantt.config.reorder_grid_columns = true;
            gantt.config.columns = [{
                name: "text",
                label: "任务名",
                width: 200,
                align: "center",
                tree: true,
                resize: true
            }, {
                name: "start_date",
                label: "开始日期",
                width: 100,
                align: "center",
                resize: true
            }, {
                name: "duration",
                label: "持续时间",
                width: 100,
                align: "center",
                resize: true

            }];


            gantt.config.row_height = 40;
            gantt.config.scale_height = 50;
            gantt.config.drag_move = false;
            gantt.config.drag_resize = false;
            gantt.config.sort = true;
            gantt.config.show_quick_info = false;
            //  关闭点击事件
            gantt.attachEvent("onTaskDblClick", function (id, e) {
                return false;
            });

            gantt.config.show_tasks_outside_timescale = true;
            gantt.plugins({
                auto_scheduling: true,  //自动排程
                tooltip: true     //提示信息
            });

            gantt.config.start_date = new Date("2022-11-03 00:00:00");
            gantt.config.end_date = new Date("2022-11-03 23:59:59");
            // 样式
            gantt.config.layout = {
                css: "gantt_container",
                cols: [{
                    width: 400,
                    min_width: 300,
                    rows: [
                        {
                            view: "grid",
                            scrollX: "gridScroll",
                            scrollable: true,
                            scrollY: "scrollVer"
                        },
                        { view: "scrollbar", id: "gridScroll", group: "horizontal" }
                    ]
                },
                { resizer: true, width: 1 },
                {
                    rows: [
                        {
                            view: "timeline",
                            scrollX: "scrollHor",
                            scrollY: "scrollVer"
                        },
                        {
                            view: "scrollbar",
                            id: "scrollHor",
                            group: "horizontal"
                        }
                    ]
                },
                { view: "scrollbar", id: "scrollVer" }]
            };

            gantt.init("device_load");

            gantt.i18n.setLocale("cn");  //使用中文
            function render() {
                var index = layer.load();  //后面会使用这赋值来关闭这个页面
                view.req({
                    method: 'POST',
                    data: JSON.stringify({
                        orderId: $('#orderId').val(),
                        deviceCode: $('#deviceCode').val()
                    }),
                    url: layui.setter.api "biz/plan/device/load",
                    success: function (res) {

                        gantt.clearAll();  //清空缓存
                        console.info("gantt", gantt.config.end_date);
                        var data = [
                            { id: "10cz1t", text: "P220901-044", type: "project", progress: 0.88, open: true, parent: 0 },
                            { id: "11cz1t", text: "L3660", type: "project", progress: 0, open: true, parent: "10cz1t" },


                            { id: "12cz1t", text: "备膜", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },

                            { id: "121cz1t", text: "Stage #1", start_date: "2022-11-03 01:00", end_date: "2022-11-03 05:00", parent: "12cz1t", progress: 0, open: true },

                            { id: "13cz1t", text: "挤压加工", type: "project", render: "split", parent: "11cz1t", progress: 0.5, open: false },
                            { id: "131cz1t", text: "Stage #1", start_date: "2022-11-03 01:00", end_date: "2022-11-03 02:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "132cz1t", text: "Stage #2", start_date: "2022-11-03 04:00", end_date: "2022-11-03 05:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "133cz1t", text: "Stage #3", start_date: "2022-11-03 07:00", end_date: "2022-11-03 08:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "134cz1t", text: "Stage #4", start_date: "2022-11-03 10:00", end_date: "2022-11-03 11:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "135cz1t", text: "Stage #5", start_date: "2022-11-03 13:00", end_date: "2022-11-03 14:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "136cz1t", text: "Stage #6", start_date: "2022-11-03 16:00", end_date: "2022-11-03 17:00", parent: "13cz1t", progress: 0, open: true },
                            { id: "137cz1t", text: "Stage #7", start_date: "2022-11-03 19:00", end_date: "2022-11-03 20:00", parent: "13cz1t", progress: 0, open: true },

                            { id: "24cz1t", text: "时效加工", type: "project", render: "split", parent: "11cz1t", progress: 0.5, open: false },
                            { id: "241cz1t", text: "Stage #1", start_date: "2022-11-03 05:00", end_date: "2022-11-03 06:00", parent: "24cz1t", progress: 0, open: true },
                            { id: "242cz1t", text: "Stage #2", start_date: "2022-11-03 11:00", end_date: "2022-11-03 12:00", parent: "24cz1t", progress: 0, open: true },
                            { id: "243cz1t", text: "Stage #3", start_date: "2022-11-03 17:00", end_date: "2022-11-03 18:00", parent: "24cz1t", progress: 0, open: true },
                            { id: "244cz1t", text: "Stage #4", start_date: "2022-11-03 20:00", end_date: "2022-11-03 21:00", parent: "24cz1t", progress: 0, open: true },


                            { id: "25cz1t", text: "氧化包装", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },
                            { id: "251cz1t", text: "Stage #1", start_date: "2022-11-03 06:00", end_date: "2022-11-03 07:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "252cz1t", text: "Stage #2", start_date: "2022-11-03 08:00", end_date: "2022-11-03 09:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "253cz1t", text: "Stage #3", start_date: "2022-11-03 12:00", end_date: "2022-11-03 13:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "254cz1t", text: "Stage #4", start_date: "2022-11-03 14:00", end_date: "2022-11-03 15:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "255cz1t", text: "Stage #5", start_date: "2022-11-03 18:00", end_date: "2022-11-03 19:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "256cz1t", text: "Stage #6", start_date: "2022-11-03 20:00", end_date: "2022-11-03 21:00", parent: "25cz1t", progress: 0, open: true },
                            { id: "257cz1t", text: "Stage #7", start_date: "2022-11-03 22:00", end_date: "2022-11-03 23:30", parent: "25cz1t", progress: 0, open: true },


                            { id: "29cz1t", text: "测试包装", type: "project", render: "split", parent: "11cz1t", progress: 0, open: true },
                            { id: "291cz1t", text: "Stage #5", start_date: "2022-11-03 15:00", end_date: "2022-11-03 16:00", parent: "29cz1t", progress: 0, open: true },
                            { id: "292cz1t", text: "Stage #6", start_date: "2022-11-03 17:00", end_date: "2022-11-03 18:00", parent: "29cz1t", progress: 0, open: true },


                            { id: "28cz1t", text: "L3660", type: "project", progress: 0, open: true, parent: "10cz1t" },
                            // ,start_date: "2022-11-03 01:00",end_date: "2022-11-03 03:00"
                            { id: "281cz1t", text: "备膜", start_date: "2022-11-03 01:00", end_date: "2022-11-03 03:00", parent: "28cz1t", progress: 0, open: true },
                            { id: "281cz1t1", text: "备膜1", start_date: "2022-11-03 02:30", end_date: "2022-11-03 05:30", parent: "28cz1t", progress: 0, open: true },
                            { id: "281cz1t2", text: "备膜2", start_date: "2022-11-03 06:50", end_date: "2022-11-03 07:50", parent: "28cz1t", progress: 0, open: true },

                            { id: "282cz1t", text: "挤压加工", start_date: "2022-11-03 08:00", end_date: "2022-11-03 09:00", parent: "28cz1t", progress: 0.5, open: true },
                            { id: "283cz1t", text: "时效加工", start_date: "2022-11-03 010:00", end_date: "2022-11-03 11:00", parent: "28cz1t", progress: 0, open: true },
                            { id: "284cz1t", text: "氧化包装", start_date: "2022-11-03 11:00", end_date: "2022-11-03 12:00", parent: "28cz1t", progress: 0, open: true },


                        ];
                        var datalist = new Array();
                        $.each(data, function (i, item) {

                            var model = new Object();
                            model.id = item.id;
                            model.text = item.text;
                            if (item.type != null) {
                                model.type = item.type;
                            }

                            model.progress = item.progress;
                            model.open = item.open;
                            model.start_date = new Date(item.start_date);
                            model.end_date = new Date(item.end_date);
                            model.parent = item.parent;
                            if (item.render != null) {
                                model.render = item.render;
                            }

                            datalist.push(model);
                         
                        });

                        // 数据之间的关系
                        var links = [
                            //  {id: "1", source: "10", target: "11", type: "1"},
                            //  {id: "2", source: "11", target: "12", type: "1"},
                            //  {id: "3", source: "10", target: "28", type: "1"},
                            //
                            // {id: "4", source: "12", target: "131", type: "1"},
                            // source:连接谁 ; target:和谁连 ; (里面写data里面的id)

                            { id: "5c", source: "131cz1t", target: "241cz1t", type: "0" },
                            { id: "6c", source: "132cz1t", target: "241cz1t", type: "0" },


                            { id: "7c", source: "133cz1t", target: "242cz1t", type: "0" },
                            { id: "8c", source: "134cz1t", target: "242cz1t", type: "0" },


                            { id: "9c", source: "135cz1t", target: "243cz1t", type: "0" },
                            { id: "10c", source: "136cz1t", target: "243cz1t", type: "0" },
                            { id: "11c", source: "137cz1t", target: "244cz1t", type: "0" },

                            { id: "14c", source: "241cz1t", target: "253cz1t", type: "0", color: "green" },
                            { id: "13c", source: "241cz1t", target: "252cz1t", type: "0", color: "green" },
                            { id: "12c", source: "241cz1t", target: "251cz1t", type: "0", color: "green" },

                            { id: "16c", source: "242cz1t", target: "254cz1t", type: "0", color: "green" },
                            { id: "15c", source: "242cz1t", target: "253cz1t", type: "0", color: "green" },


                            { id: "19c", source: "243cz1t", target: "257cz1t", type: "0", color: "green" },
                            { id: "18c", source: "243cz1t", target: "256cz1t", type: "0", color: "green" },
                            { id: "17c", source: "243cz1t", target: "255cz1t", type: "0", color: "green" },


                            { id: "21c", source: "254cz1t", target: "292cz1t", type: "0", color: "blue" },
                            { id: "20c", source: "254cz1t", target: "291cz1t", type: "0", color: "blue" },

                                
                            { id: "22c", source: "28cz1t", target: "281cz1t", type: "0", color: "red" },
                            { id: "23c", source: "281cz1t", target: "281cz1t1", type: "0", color: "red" },
                            { id: "24c", source: "281cz1t", target: "281cz1t2", type: "0", color: "red" },
                         

                            { id: "25c", source: "281cz1t", target: "282cz1t", type: "0", color: "hotpink" },
                            { id: "26c", source: "281cz1t", target: "284cz1t", type: "0", color: "hotpink" },
                            { id: "27c", source: "281cz1t", target: "283cz1t", type: "0", color: "hotpink" },
                            { id: "28c", source: "281cz1t", target: "284cz1t", type: "0", color: "hotpink" },

                        


                        ]
                            //解析  
                        gantt.parse({
                            data: datalist,
                            links: links
                        });
                        console.info("gantt", gantt);

                        layer.close(index);    //关闭页面
                    }
                });
            }

            render();
            $('#reset').click(function () {
                view.req({
                    method: 'get',
                    url: layui.setter.api "biz/plan/device/init",
                    success: function (res) {
                        render();
                    }
                });
            });
            form.on('submit(spmrp-search)', function (data) {
                render();
            });

          
          
            
        });
    </script>
</body>

</html>

觉得香点个赞,让更多的小伙伴一起快乐!

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhhabkfe
系列文章
更多 icon
同类精品
更多 icon
继续加载