最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue前端實(shí)現(xiàn)dhtmlxgantt甘特圖代碼示例(個(gè)人需求)

 更新時(shí)間:2025年03月01日 11:53:57   作者:cat-rongye  
這篇文章主要介紹了如何使用dhtmlx-gantt和chinese-days插件在項(xiàng)目中實(shí)現(xiàn)節(jié)假日置灰顯示的功能,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下

官網(wǎng)地址: dhtmlx-gantt - npm   chinese-days - npm

安裝:npm i dhtmlx-gantt    npm i chinese-days

開發(fā)過(guò)程中需要判斷節(jié)假日并置灰顯示,使用了插件chinese-days(用于查詢中國(guó)節(jié)假日、調(diào)休日、工作日、24節(jié)氣、以及農(nóng)歷陽(yáng)歷互轉(zhuǎn))實(shí)現(xiàn)

this.task = { data:[],type: "tasks"}
//獲取甘特圖數(shù)據(jù)   
public getData(data){
    if(data.length){
        data.forEach((val:any,index:any)=>{
          this.tasks.data.push({
            id: val.OBJ_ID,
            name: val.TDSB,
            start_date: new Date(this.timestampToTime(val.STARTTIME)),
            end_date: new Date(this.timestampToTime(val.ENDTIME)),
            duration: 20,
            open: true, //默認(rèn)打開,
            toolTipsTxt:  val.TDSB,
            fxdj: val.FXDJ,
            index:index,
            editable:true,
            // progress: 0.6,
            //status: "parent",
          })
        })
      }
    }    
// 判斷節(jié)假日并設(shè)置特殊樣式,這里是給節(jié)假日設(shè)置了特殊的css類名,具體樣式具需求自行添加  
//  chineseDays.isHoliday -- 使用插件 判斷這一日期是否為周末節(jié)假日
   
    public daysStyle(date: any){
        if (chineseDays.isHoliday(date)) return "weekend";
      };

    // 根據(jù)傳入數(shù)據(jù)判斷甘特圖渲染的顏色
    public setDataColor = () => {
        this.tasks.data.forEach((item: any) => {
          // if (item.fxdj) {
            //存在type字段 說(shuō)明非一級(jí)菜單,判斷階段的具體類型 設(shè)置不同顏色
            if (item.fxdj == 1) {
              item.color = "rgba(255, 0, 0,.75)";
              item.fxdjmc = "一級(jí)(+)";
            } else if (item.fxdj == 2) {
              item.fxdjmc = "一級(jí)";
              item.color = "rgb(255, 136, 20,.75)";
            } else if (item.fxdj == 3) {
              item.fxdjmc = "二級(jí)";
              item.color = "rgba(86, 146, 240,.75)";
            } else if (item.fxdj == 0) {
              item.fxdjmc = "無(wú)";
              item.color = "rgba(0, 176, 80,.75)";
            }
          // }
        });
      };
    // 初始化渲染甘特圖
    public initData(){
        //自適應(yīng)甘特圖的尺寸大小, 使得在不出現(xiàn)滾動(dòng)條的情況下, 顯示全部任務(wù)
        // gantt.config.autosize = "xy";
        // gantt.config.open_tree_initially = true;
        //   gantt.config.scale_unit = "day";
        gantt.config.min_column_width = 60;
        gantt.config.scale_height = 30 * 3;
        gantt.config.row_height = 30;
        gantt.config.drag_links = false;
        gantt.config.drag_move = false;
        gantt.config.drag_resize = false;
        gantt.config.drag_progress = false;
        gantt.config.correct_work_time = false;
        gantt.config.editable = true; // 允許編輯(內(nèi)聯(lián)編輯)
        //   是否有新增彈窗
        gantt.config.details_on_create = false;
        //   點(diǎn)擊進(jìn)度
        gantt.config.details_on_dblclick = false;
        gantt.config.order_branch = false;
        gantt.config.scroll_size = 15;
        // 不同字段對(duì)應(yīng)的編輯配置
        var textEditor = {type: "text", map_to: "name"};
        var dateEditorS = {type: "date", map_to: "start_date"};
        var dateEditorE = {type: "date", map_to: "start_date"};
        var durationEditor = {type: "select", map_to: "fxdjmc",options: [
          {label:"無(wú)",value:'0'},
          {label:"一級(jí)風(fēng)險(xiǎn)(+)",value:'1'},
          {label:"一級(jí)風(fēng)險(xiǎn)",value:'2'},
          {label:"二級(jí)風(fēng)險(xiǎn)",value:'3'},
      ]};
        //   左側(cè)目錄菜單展示內(nèi)容
        gantt.config.columns = [
          { name: "check", label: "", width: 40,
            template: function(task) {
                // 創(chuàng)建一個(gè)復(fù)選框,并為其添加一個(gè)唯一的ID,以便后續(xù)操作
                var checkboxId = "checkbox_" + task.id;
                return "<input type='checkbox' id='" + checkboxId + "' class='gantt_checkbox' />";
            },
            align: "center" },
          { name: "index", label: "序號(hào)", align: "center", width: 40 },
          { name: "name", label: "停電設(shè)備", align: "left", width: 230, },
          { name: "start_date", label: "開始時(shí)間", align: "center", width: 180 },
          { name: "end_date", label: "結(jié)束時(shí)間", align: "center", width: 180  },
          { name: "fxdjmc", label: "風(fēng)險(xiǎn)等級(jí)", align: "center"  },
          { name: "add",label: "", onrender: (item: any) => {return " ";},},
        ];
        // 指向展示詳情 -- 鼠標(biāo)懸浮是否顯示
        gantt.plugins({
          tooltip: true,
        });
        // 鼠標(biāo)懸浮內(nèi)容
        gantt.templates.tooltip_text = function (start, end, task) {
          return (
            "<b>設(shè)備名稱:</b> " +
            task.name +
            "<br/><b>開始時(shí)間:</b> " +
            gantt.templates.tooltip_date_format(start) +
            "<br/><b>結(jié)束時(shí)間:</b> " +
            gantt.templates.tooltip_date_format(end)
          );
        };
        gantt.config.auto_types = true;
        gantt.config.xml_date = "%Y-%m-%d";
        gantt.config.step = 1;
        gantt.config.start_on_monday = true;
        gantt.config.autoscroll = false;
        gantt.config.scroll_on_click = true;
        gantt.config.calendar_property = "start_date";
        gantt.config.calendar_property = "end_date";
        // 左側(cè)表格寬度
        gantt.config.autofit = true;
        gantt.config.grid_width = 500;
        //   右側(cè)表頭
        gantt.config.scales = [
          { unit: "month", step: 1, format: "%F, %Y" },
          { unit: "week", step: 1, template: this.weekScaleTemplate },
          { unit: "day", step: 1, format: "%d", css: this.daysStyle },
        ];
  
        //   表單判斷假期
        gantt.templates.timeline_cell_class = (task, date): any => {
          if (chineseDays.isHoliday(date)) {
            return "holiday";
          }
        };
        //   設(shè)置任務(wù)條進(jìn)度內(nèi)容 -- 功能不需要
        // gantt.templates.progress_text = (start, end, task: any) => {
        //   return (
        //     "<div style='text-align:left;color:#fff;padding-left:20px'>" +
        //     Math.round(task.progress * 100) +
        //     "% </div>"
        //   );
        // };
  
        //任務(wù)條顯示內(nèi)容
        gantt.templates.task_text = function (start, end, task) {
          // return task.name + '(' + task.duration + '天)';
          return "";
        };
        gantt.i18n.setLocale("cn");
        //   設(shè)置進(jìn)度顏色
        this.setDataColor();
         // 清除緩存
         gantt.clearAll(); 
        //   初始化  gantt_here 為dom的Id
        gantt.init("gantt_here");
        //   數(shù)據(jù)解析
        gantt.parse(this.tasks);
        // 監(jiān)聽(tīng)新增事件
        let _this = this;
        gantt.attachEvent("onTaskCreated", function (task) {
          //console.log(task, "task");
          _this.flag = true;
          return false;
        });
        // 為每個(gè)復(fù)選框添加事件監(jiān)聽(tīng)器
        gantt.eachTask(function(task:any) {
          var checkboxId = "checkbox_" + task.id;
          var checkbox = document.getElementById(checkboxId);
          if (checkbox) {
              // 添加change事件監(jiān)聽(tīng)器
              checkbox.addEventListener('change', function() {
                  // 這里可以執(zhí)行一些操作,比如更新任務(wù)狀態(tài)或發(fā)送Ajax請(qǐng)求
                  console.log('Task ' + task.id + ' is ' + (_this.checked ? 'checked' : 'unchecked'));
              });
          }
        });
    }

總結(jié)

到此這篇關(guān)于vue前端實(shí)現(xiàn)dhtmlxgantt甘特圖的文章就介紹到這了,更多相關(guān)vue前端dhtmlxgantt甘特圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

喀喇沁旗| 澄江县| 方正县| 宝坻区| 临江市| 鄂托克旗| 临海市| 乐清市| 郎溪县| 大冶市| 巢湖市| 庆阳市| 建阳市| 修文县| 泾源县| 岳阳县| 区。| 思南县| 长丰县| 墨玉县| 岳阳市| 德令哈市| 南雄市| 文安县| 陆川县| 砚山县| 山东| 鹿邑县| 昌宁县| 江孜县| 中西区| 清流县| 临泉县| 洪江市| 高安市| 左云县| 左贡县| 九江县| 于田县| 宁明县| 连平县|