iView Table组件自定义

 效果展示

 代码如下

resourcesColumn: [
        {
          title: "文件名",
          key: "FileName",
          align: "left",
          width: 200,
          render: (h, params) => {
            var me = params.row;
            var showName = (me.FileName.length>17) ? me.FileName.substr(0,10) + "···" : me.FileName;
            var imgUrl;
            var fileType = me.FileName.split(".");
            fileType = fileType[fileType.length - 1].toLowerCase();
            switch (fileType) {
              case "pdf":
              case "pptx":
                imgUrl = "ppt_icn.png";
                break;
              case "docx":
                imgUrl = "word_icn.png";
                break;
              case "xlsx":
                imgUrl = "xlsx_icn.png";
                break;
              case "png":
              case "jpg":
              case "jpeg":
              case "gif":
                imgUrl = "img_icn.png";
                break;
              case "mp4":
              case "mpeg":
              case "mpg":
              case "avi":
              case "mov":
              case "wmv":
              case "mkv":
              case "flv":
                imgUrl = "video_icn.png";
                break;
              case "mp3":
              case "wave":
              case "wma":
                imgUrl = "voice_icn.png";
                break;
              default:
                break;
            }
            return h("div", [
              h(
                "img",
                {
                  props: {
                    to: me.Url
                  },
                  attrs: {
                    src: "/static/images/" + imgUrl
                  },
                  style: {
                    width: "14px",
                    height: "16px",
                    marginRight: "6px"
                  },
                  on: {
                    click: () => {}
                  }
                },
                ""
              ),
                h(
                  "span",
                  {
                    class: [],
                    style: {
                      marginRight: "10px",
                      display: me.disSpan
                    },
                    attrs: {
                      title: me.FileName
                    },
                    on: {
                      click: () => {}
                    }
                  },
                  showName
                ),
                h(
                  "Input",
                  {
                    class: ["editInput"],
                    props: {
                      //将单元格的值给Input
                      value: me.newName.substr(0,me.newName.lastIndexOf('.'))
                    },
                    style: {
                      display: me.disInput
                    },
                    on: {
                      "on-change": event => {
                        //值改变时
                        //将渲染后的值重新赋值给单元格值
                        me.newName = event.target.value;
                      }
                    }
                  }
                ),
                h(
                  "div",
                  {
                    class: ["edit"],
                    attrs: {
                      title: "重命名"
                    },
                    style: {
                      display: me.disSpan
                    },
                    on: {
                      click: () => {
                        me.disSpan = "none";
                        me.disInput = "inline-block";
                      }
                    }
                  },
                  ""
                ),
                h(
                  "div",
                  {
                    class: ["confirmed"],
                    attrs: {
                      title: "完成"
                    },
                    style: {
                      display: me.disInput
                    },
                    on: {
                      click: () => {
                        me.disSpan = "inline-block";
                        me.disInput = "none";
                        var params = {
                          Id: me.Id, // 文件id !!required!!
                          AlterName: me.newName // 文件原名称 !!required!!
                        };
                        if (me.newName != me.FileName) {
                          this.AlterFileName(params);
                          me.FileName = me.newName + "." + fileType;
                        }
                      }
                    }
                  },
                  ""
                )
            ]);
          }
        },
        {
          title: "来源",
          key: "SourseName",
          align: "left"
        },
        {
          title: "添加日期",
          key: "CreateTime",
          align: "left"
        },
        {
          title: "操作",
          key: "action",
          width: 250,
          render: (h, params) => {
            var me = params.row;
            var type;
            var fileType = me.FileName.split(".");
            fileType = fileType[fileType.length - 1].toLowerCase();
            switch (fileType) {
              case "pdf":
              case "pptx":
              case "docx":
              case "xlsx":
                type = "File";
                break;
              case "png":
              case "jpg":
              case "jpeg":
              case "gif":
                type = "Img";
                break;
              case "mp4":
              case "mpeg":
              case "mpg":
              case "avi":
              case "mov":
              case "wmv":
              case "mkv":
              case "flv":
                type = "Video";
                break;
              case "mp3":
              case "wave":
              case "wma":
                type = "Voice";
                break;
              default:
                break;
            }
            return h("div", [
              h(
                "div",
                {
                  class: ["examine"],
                  attrs: {
                    title: "查看"
                  },
                  on: {
                    click: () => {
                      this.PreviewFile(me.Id, me.FileName, type);
                    }
                  }
                },
                ""
              ),
              h(
                "div",
                {
                  class: ["cut-off-rule"]
                },
                ""
              ),
              h(
                "Poptip",
                {
                  props: {
                    confirm: true,
                    transfer: true,
                    placement: "bottom-end",
                    title: "确认删除此文件吗?",
                    size: "small",
                    width: "160"
                  },
                  on: {
                    "on-ok": () => {
                      this.RemoveFile(params.index, me.Id);
                    },
                    "on-cancel": () => {}
                  }
                },
                [
                  h(
                    "div",
                    {
                      class: ["delete"],
                      attrs: {
                        title: "删除"
                      },
                      on: {
                        click: () => {}
                      }
                    },
                    ""
                  )
                ]
              )
            ]);
          }
        }
      ]

 

 

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值