iview库table组件中标头render函数使用方法

发布时间 2023-08-31 11:38:10作者: 李云蹊
columns: [
        {
          title: "序号",
          align: "center",
          width: 80,
          key: "id",
          fixed: "left",
        },
        {
          title: "标题",
          key: "task_name",
          width: 300,
          tree: true,
          renderHeader: (h, params) => {
            // Render 函数,自定义列头显示内容
            return h("div", [
              h("span", "标题"),
              h("Icon", {
                attrs: {
                  type: "ios-add-circle-outline",
                  color: "#3D7EFF",
                  size: 22,
                },
                style:{marginLeft:'212px',fontWeight:'800'},
                on: {
                  click: () => {
                    this.modal = true;
                    // this._handleCreate();
                  },
                },
              }),
            ]);
          },
          render: (h, { row }) =>
            h(
              "a",
              {
                style: { color: "#606266" },
                on: {
                  click: () => {
                    this.toEdtail(row);
                  },
                },
              },
              row.task_name
            ),
        },
        {
          title: "任务状态",
          align: "center",
          width: 100,
          key: "task_status",
          // slot: 'status'
          render: (h, { row }) =>
            h(
              "p",
              {
                style: {
                  backgroundColor: ['', '#F2F2F2', '#E7F5FE', '#E7F7EA'][row.task_status],
                  borderRadius: "4px",
                  color: ['', '#606266', '#3D7EFF', '#1a9538'][row.task_status],
                },
              },
              row.task_status_text
            ),
        },
        {
          title: "优先级",
          align: "center",
          width: 110,
          key: "priority",
          render: (h, { row }) =>
            h(
              "p",
              {
                style: {
                  backgroundColor: this.priorityList[row.priority],
                  color: "#FFFFFF",
                  borderRadius: "4px",
                  // opacity: row.task_status == 3 ? 0.3 : 1,
                },
              },
              row.priority_text
            ),
        },
        {
          title: "任务列表",
          width: 150,
          key: "task_list_name",
        },
        {
          title: "开始时间",
          align: "center",
          width: 140,
          key: "start_date",
          // slot: 'start_date'
          render: (h, { row }) =>
            h(
              "div",
              {
                style: { display: "flex" },
              },
              [
                h("span", row.start_date),
                //重复任务图标
                // h('Icon', {
                //     style: {
                //         display: row.id==1? 'block': 'none',
                //     },
                //     attrs: {
                //         type: 'md-refresh',
                //         size: 20
                //     }
                // }),
              ]
            ),
        },
        {
          title: "结束时间",
          align: "center",
          width: 200,
          slot: "end_date",
        },
        {
          title: "执行者",
          align: "center",
          width: 200,
          key: "performer",
          render: (h, { row }) =>
            h(
              "div",
              {
                style: {
                  display: row.performer ? "flex" : "none",
                  justifyContent: "center",
                },
              },
              [
                h(
                  "p",
                  {
                    style: {
                      backgroundColor: "#F8BF84",
                      color: "#FFFFFF",
                      width: "20px",
                      height: "20px",
                      borderRadius: "50%",
                    },
                  },
                  row.performer.charAt(0)
                ),
                h(
                  "span",
                  {
                    style: {
                      paddingLeft: "5px",
                    },
                  },
                  row.performer
                ),
              ]
            ),
        },
        {
          title: "参与者",
          align: "center",
          width: 300,
          render: (h, { row }) =>
            h(
              "div",
              {
                style: {
                  display: "flex",
                  justifyContent: "center",
                },
              },
              row.participants.map((v) => {
                // 遍历
                return h(
                  "p",
                  {
                    style: {
                      backgroundColor: v.type == 1 ? "#F8BF84" : "#75B0E9",
                      color: "#FFFFFF",
                      width: "20px",
                      height: "20px",
                      borderRadius: "50%",
                    },
                  },
                  v.name.charAt(0)
                );
              })
            ),
        },
        {
          title: "完成时间",
          align: "center",
          width: 120,
          key: "finish_date",
        },
        {
          title: "创建时间",
          align: "center",
          width: 120,
          key: "create_date",
        },
      ],