国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue Element UI 自定義描述列表組件

這篇具有很好參考價(jià)值的文章主要介紹了Vue Element UI 自定義描述列表組件。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

效果圖

el-descriptions-item,vue.js,ui,前端

?寫在前面

由于vue使用的版本太低,vue element UI 的描述列表不生效,但是有時(shí)候又不想換版本的可以自定義一個(gè)描述列表。

實(shí)現(xiàn)哪些功能

1、每行的高度根據(jù)改行中某一列的最大高度自動(dòng)撐開
2、列寬度自動(dòng)補(bǔ)全,避免最后一列出現(xiàn)殘缺的情況
3、支持純文本與HTML插槽
4、支持每行幾列的設(shè)置
5、支持每列寬度自定義
6、支持動(dòng)態(tài)數(shù)據(jù)重繪

組件設(shè)計(jì)

1、使用父子組件嵌套實(shí)現(xiàn),父組件為 el-descriptions, 子組件為 el-descriptions-item。
2、e-desc-item傳遞props的label 和 插槽的value
3、利用 el-row 和 el-col 來實(shí)現(xiàn)整體組件布局

封裝el-descriptions組件

<template>
    <div class="desc" :style="{margin}">
      <!-- 標(biāo)題 -->
      <h1 v-if="title" class="desc-title" v-html="title"></h1>
      <el-row class="desc-row" ref='elRow'>
        <slot/>
      </el-row>
    </div>
  </template>
  
  <script>
  export default {
    name: 'ElDescriptions',
    // 通過provide提供給子組件
    provide () {
      return {
        labelWidth: this.labelWidth,
        column: this.column,
        size: this.size
      }
    },
    props: {
      // 標(biāo)題
      title: {
        type: String,
        default: ''
      },
      // 邊距
      margin: {
        type: String,
        default: '0'
      },
      // label寬度
      labelWidth: {
        type: String,
        default: '120px',
      },
      column: {
        // 每行顯示的項(xiàng)目個(gè)數(shù)
        type: [Number, String],
        default: 4
      },
      size: {
        // 大小
        type: String,
        default: '0'
      }
    },
    data () {
      return {
        // 監(jiān)聽插槽變化
        observe: new MutationObserver(this.computedSpan)
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.computedSpan()
        this.observe.observe(this.$refs.elRow.$el, { childList: true })
      })
    },
    methods: {
      computedSpan () {
        // 篩選出子組件e-desc-item
        const dataSource = this.$slots.default
        const dataList = []
        dataSource.forEach(item => {
          if (item.componentOptions && item.componentOptions.tag === 'e-desc-item') {
            dataList.push(item.componentInstance)
          }
        })
        // 剩余span
        let leftSpan = this.column
        const len = dataList.length
        dataList.forEach((item, index) => {
          // 處理column與span之間的關(guān)系
          // 剩余的列數(shù)小于設(shè)置的span數(shù)
          const hasLeft = leftSpan <= (item.span || 1)
          // 當(dāng)前列的下一列大于了剩余span
          const nextColumnSpan = (index < (len - 1)) && (dataList[index + 1].span >= leftSpan)
          // 是最后一行的最后一列
          const isLast = index === (len - 1)
          if (hasLeft || nextColumnSpan || isLast) {
            // 滿足以上條件,需要自動(dòng)補(bǔ)全span,避免最后一列出現(xiàn)殘缺的情況
            item.selfSpan = leftSpan
            leftSpan = this.column
          } else {
            leftSpan -= item.span || 1
          }
        })
      }
    },
    beforeDestroy () {
      this.observer.disconnect()
    }
  }
  </script>
  
  <style scoped lang="scss">
    .desc{
      .desc-title {
        margin-bottom: 10px;
        color: #333;
        font-weight: 700;
        font-size: 16px;
        line-height: 1.5715;
      }
      .desc-row{
        display: flex;
        flex-wrap: wrap;
        border-radius: 2px;
        border: 1px solid #EBEEF5;
        border-bottom: 0;
        border-right: 0;
        width: 100%;
       
      }
    }
  </style>
  

封裝e-desc-item組件

<template>
    <el-col :span="computedSpan" class="desc-item">
      <div class="desc-item-content" :class="size">
        <label class="desc-item-label" :style="{width: labelWidth}" v-html="label"></label>
        <div class="desc-item-value" v-if="$slots">
          <slot/>
        </div>
      </div>
    </el-col>
  </template>
  
  <script>
  export default {
    name: 'ElDescriptionsItem',
    inject: ['labelWidth', 'column', 'size'],
    props: {
      span: {
        type: [Number, String],
        required: false,
        default: 0
      },
      label: {
        type: String,
        required: false,
        default: ''
      }
    },
    data () {
      return {
        // 子組件自己的span
        selfSpan: 0
      }
    },
    computed: {
      computedSpan () {
        // 子組件自己的span,用于父組件計(jì)算修改span
        if (this.selfSpan) {
          return 24 / this.column * this.selfSpan
        } else if (this.span) {
        // props傳遞的span
          return 24 / this.column * this.span
        } else {
        // 未傳遞span時(shí),取column
          return 24 / this.column
        }
      }
    }
  }
  </script>
  
  <style scoped lang="scss">
    .desc-item {
      border-right: 1px solid #EBEEF5;
      border-bottom: 1px solid #EBEEF5;
      .desc-item-content {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        color: rgba(0,0,0,.65);
        font-size: 14px;
        line-height: 1.5;
        width: 100%;
        background-color: #fafafa;
        height: 100%;
        .desc-item-label{
          border-right: 1px solid #EBEEF5;
          display: inline-block;
          padding: 12px 16px;
          flex-grow: 0;
          flex-shrink: 0;
          color: rgba(0, 0, 0, 0.6);
          font-weight: 400;
          font-size: 14px;
          line-height: 1.5;
          height: 100%;
          display: flex;
          align-items: center;
        }
        .desc-item-value{
          background: #fff;
          padding: 12px 16px;
          flex-grow: 1;
          overflow: hidden;
          word-break: break-all;
          height: 100%;
          display: flex;
          align-items: center;
          color: #444;
          span{
            color: #aaa;
          }
          // 空數(shù)據(jù)時(shí)展示的內(nèi)容
          &:empty::after {
            content: '--';
          }
        }
        &.small {
          .desc-item-label,
          .desc-item-value {
            padding: 10px 14px;
          }
        }
      }
    }
  </style>
  

使用方式

<template>
  <div class="mod-contracts">
    <el-descriptions
      margin="0 12px"
      label-width="100px"
      v-loading="dataListLoading"
      v-model="userInfo"
      v-if="userInfo"
    >
      <el-descriptions-item label="合同編號(hào)" :span="2">{{
        userInfo.num
      }}</el-descriptions-item>
      <el-descriptions-item label="合同名稱" :span="2">
        {{ userInfo.title }}</el-descriptions-item
      >
      <el-descriptions-item label="姓名" :span="2">
        {{ userInfo.userName }}</el-descriptions-item
      >
      <el-descriptions-item label="公司名稱" :span="2">
        {{ userInfo.companyName }}</el-descriptions-item
      >
      <el-descriptions-item label="合同類型" :span="2">
        <span v-if="userInfo.type == 0">試用期合同</span>
        <span v-if="userInfo.type == 1">正式員工合同</span>
        <span v-if="userInfo.type == 2">外包合同</span>
      </el-descriptions-item>

      <el-descriptions-item label="薪資" :span="2">{{
        userInfo.salary
      }}</el-descriptions-item>
      <el-descriptions-item label="崗位" :span="2">{{
        userInfo.post
      }}</el-descriptions-item>
      <el-descriptions-item label="合同狀態(tài)" :span="2">
        <template>
          <el-tag
            v-if="userInfo.state === 0 && !isCurrentTimeLater"
            size="small"
            type="info"
            >未確認(rèn)</el-tag
          >
          <el-tag v-if="userInfo.state === 1" size="small">生效</el-tag>
          <el-tag
            v-if="userInfo.state === 2 || isCurrentTimeLater"
            size="small"
            type="danger"
            >作廢</el-tag
          >
        </template>
      </el-descriptions-item>
      <el-descriptions-item label="身份證號(hào)碼" :span="2">{{
        userInfo.idNum
      }}</el-descriptions-item>
      <el-descriptions-item label="家庭住址" :span="2">{{
        userInfo.address
      }}</el-descriptions-item>
      <el-descriptions-item label="聯(lián)系電話" :span="2">{{
        userInfo.mobile
      }}</el-descriptions-item>

      <el-descriptions-item label="合同生效時(shí)間" :span="2">{{
        userInfo.effectTime
      }}</el-descriptions-item>
      <el-descriptions-item label="合同失效時(shí)間" :span="2">{{
        userInfo.lostEffectTime
      }}</el-descriptions-item>
      <el-descriptions-item label="合同人所屬部門" :span="2">
        <el-row v-for="item in deptList" :key="item.id">
          <span v-if="item.id == userInfo.deptId">{{ item.label }}</span>
        </el-row>
      </el-descriptions-item>
      <el-descriptions-item label="合同結(jié)束時(shí)間" :span="4">{{
        userInfo.endTime
      }}</el-descriptions-item>
      <el-descriptions-item label="詳情" :span="4" style="height: auto">
        甲乙雙方經(jīng)平等協(xié)商。共同決定建立勞務(wù)關(guān)系。本服務(wù)協(xié)議屬于勞務(wù)協(xié)議,不在《中華人民共和國芳動(dòng)法》調(diào)整范圍內(nèi),而在《中華人民共和國民法通則》、
        《中華人民共和國合同法》的調(diào)整之中。甲乙雙方在充分明確這一法律關(guān)系的基礎(chǔ)上,根據(jù)《民法通則》、《合同法》和其他相關(guān)法律、法規(guī),自愿簽訂本協(xié)議,共同道守協(xié)議所列條款。
      </el-descriptions-item>
      <el-descriptions-item
        label="操作"
        :span="4"
        v-if="userInfo.state == 0 && !isCurrentTimeLater"
      >
        <template>
          <el-button size="small" type="primary" @click="update(userInfo.id)"
            >確認(rèn)合同</el-button
          >
        </template>
      </el-descriptions-item>
    </el-descriptions>
<el-descriptions v-else>
  <template>暫無合同,請(qǐng)聯(lián)系管理員</template>
</el-descriptions>
    <el-button v-if="userInfo"  style="margin-top: 10px;margin-left: 10px;" type="danger" @click="downloadExcel(userInfo.id)">導(dǎo)出合同</el-button>
    <update
      v-if="UpdateVisible"
      ref="updateView"
      @refreshData="getContractsInfo"
    ></update>
  </div>
</template>

<script>
import ElDescriptions from "../../common/e-desc.vue";
import ElDescriptionsItem from "../../common/e-desc-item.vue";
import Update from "./contracts-update.vue";
export default {
  components: {
    ElDescriptions,
    ElDescriptionsItem,
    Update,
  },
  data() {
    return {
      userInfo: {
        id: 0,
        userId: 0,
        roleName: "",
        username: "",
        deptId: "",
        lostEffectTime: "",
      },
      currentTime: new Date(),
      deptList: [],
      dataList:[],
      dataListLoading: false,
      UpdateVisible: false,
    };
  },

  mounted() {
    this.getDeptDataList();
    this.getContractsInfo();
    setInterval(() => {
      this.currentTime = new Date();
    }, 1000);
  },

  computed: {
    isCurrentTimeLater() {
      this.currentTime.setHours(0, 0, 0, 0);
      this.lostEffectTime = new Date(this.userInfo.lostEffectTime);
      return this.currentTime > this.lostEffectTime;
    },
  },

  methods: {
    getContractsInfo() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(`/contracts/info`),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.userInfo = data.contracts;
          this.dataList.push(data.contracts);
        } else {
          this.userInfo = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },

    // 獲取部門數(shù)據(jù)列表
    getDeptDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/sys/dept/tree"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        this.deptList = data;
      });
    },

    //完善合同
    update(id) {
      this.UpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.updateView.init(id);
      });
    },

    //導(dǎo)出全部
    downloadExcel(id) {
      var ids=this.dataList.map(item => item.id);
      this.$confirm(`確定對(duì)[id=${ids.join(",")}]進(jìn)行導(dǎo)出操作?`, "提示", {
        confirmButtonText: "確定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        // 發(fā)送 HTTP 請(qǐng)求以下載 Excel 文件
        this.$http({
          url: this.$http.adornUrl("/contracts/download"),
          method: "post",
          data: this.$http.adornData(ids, false),
          responseType: "blob", // 設(shè)置響應(yīng)類型為二進(jìn)制流
        })
          .then((response) => {
            // 創(chuàng)建一個(gè) URL 對(duì)象,指向返回的二進(jìn)制數(shù)據(jù)
            const url = window.URL.createObjectURL(new Blob([response.data])); // 創(chuàng)建一個(gè) <a> 元素,設(shè)置其屬性,模擬點(diǎn)擊下載

            const link = document.createElement("a");
            link.href = url;
            link.setAttribute("download", "data.xlsx"); // 設(shè)置下載文件的默認(rèn)名稱
            document.body.appendChild(link);
            link.click(); // 清理創(chuàng)建的 URL 對(duì)象

            window.URL.revokeObjectURL(url);
          })
          .catch((error) => {
            console.error("下載失敗", error);
          });
      });
    },
  },
};
</script>

參數(shù)說明

el-descriptions-item,vue.js,ui,前端

?el-descriptions-item,vue.js,ui,前端

?至此,代碼就寫完啦,描述列表不生效的問題應(yīng)該就解決了文章來源地址http://www.zghlxwxcb.cn/news/detail-777728.html

到了這里,關(guān)于Vue Element UI 自定義描述列表組件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue中element ui 中tree組件怎么自定義前綴圖標(biāo)呢?

    vue中element ui 中tree組件怎么自定義前綴圖標(biāo)呢?

    一 問題 ?餓了么ui 默認(rèn)的圖標(biāo)樣式是: 1. 一個(gè)箭頭, 展開自動(dòng)順時(shí)針旋轉(zhuǎn)90°, 以上的條件是該節(jié)點(diǎn)有子節(jié)點(diǎn), 2. 如果是沒有子節(jié)點(diǎn)的節(jié)點(diǎn), 是默認(rèn)空白圖標(biāo)的(這里我認(rèn)為他不是沒有, 而是有占位但是空白的) 按照官網(wǎng)文檔, 設(shè)置icon-class設(shè)置自定義圖標(biāo)代替默認(rèn)箭頭, 但是展開和收

    2024年02月13日
    瀏覽(21)
  • vue + element UI 表單中內(nèi)嵌自定義組件的表單校驗(yàn)觸發(fā)方案

    vue + element UI 表單中內(nèi)嵌自定義組件的表單校驗(yàn)觸發(fā)方案

    在表單中,可能部分表單項(xiàng)需封裝成自定義組件,如何在表單提交時(shí),能同步觸發(fā)自定義組件的表單校驗(yàn)? 將表單綁定的變量傳入自定義組件中,在自定義組件中定義表單校驗(yàn)規(guī)則 內(nèi)嵌自定義組件 srctestindex.vue srctestsearch_job.vue

    2024年02月14日
    瀏覽(23)
  • vue3 + vite自定義封裝vue + element-ui 表格組件,發(fā)布到npm包的全過程。

    vue3 + vite自定義封裝vue + element-ui 表格組件,發(fā)布到npm包的全過程。

    當(dāng)我們項(xiàng)目中用到的表格太多的話,就會(huì)導(dǎo)致我們的代碼量一直增加,所以我們要封裝一個(gè)公共得組件,通過傳參引入來使用,下面這篇文章主要給大家介紹了關(guān)于vue3+vite自定義封裝vue組件發(fā)布到npm包的相關(guān)資料,需要的朋友可以參考下。 提示我們要安裝 create-vite@4.1.0 得依賴

    2024年02月02日
    瀏覽(26)
  • 基于vue和element-ui的表格組件,主推數(shù)據(jù)渲染,支持內(nèi)容和方法靈活綁定,提供動(dòng)態(tài)具名插槽自定義內(nèi)容

    基于vue和element-ui的表格組件,主推數(shù)據(jù)渲染,支持內(nèi)容和方法靈活綁定,提供動(dòng)態(tài)具名插槽自定義內(nèi)容

    ? ? ? ? 組件名為commonTable,主要是基于element-ui中的表格組件進(jìn)行二次封裝的組件,集成了常用的表格功能,除默認(rèn)內(nèi)容的顯示外,還包括以下幾點(diǎn): ? ? ? ? 1. 狀態(tài)的篩選和顯示; ? ? ? ? 2. 操作按鈕的顯示和方法綁定; ? ? ? ? 3. 自定義具名插槽內(nèi)容的封裝; ? ? ?

    2024年02月07日
    瀏覽(31)
  • Element UI 日期封裝自定義組件

    日常工作中我們會(huì)遇到要封裝日期組件的情況,例如:element組件日期選擇開始時(shí)間,結(jié)束時(shí)間組件不能直接使用時(shí),重復(fù)使用到日期選擇,我們就不得不去封裝。 其實(shí)很簡答,我不做過多講解,直接上代碼,急拿急用。 代碼如下(示例): 代碼如下(示例): 這樣就可以

    2024年02月15日
    瀏覽(18)
  • Element-UI技巧分享:自定義拖拽列表的制作方法

    部分?jǐn)?shù)據(jù)來源: ChatGPT 引言 ????????當(dāng)我們使用 Element-UI 的自定義拖拽列表時(shí),有時(shí)候需要根據(jù)拖拽的字段位置,將數(shù)據(jù)組成不同的列表進(jìn)行顯示。這種情況下,我們可以通過一些簡單的操作,來實(shí)現(xiàn)自定義拖拽列表中的分類展示。 在本文中,我們將介紹如何使用 Eleme

    2024年02月08日
    瀏覽(22)
  • Element Ui 樹形組件自定義樣式與功能

    Element Ui 樹形組件自定義樣式與功能

    一、功能描述:可實(shí)現(xiàn)樹節(jié)點(diǎn)內(nèi)容修改、增加節(jié)點(diǎn)、刪除節(jié)點(diǎn)等,根據(jù)層級(jí)不同顯示不同的圖標(biāo)等,已封裝成組件。 二、調(diào)用組件示例: 三、效果圖如下:

    2024年02月15日
    瀏覽(20)
  • Element UI 自定義省市區(qū)三級(jí)聯(lián)動(dòng)選擇組件

    Element UI 自定義省市區(qū)三級(jí)聯(lián)動(dòng)選擇組件

    https://blog.csdn.net/qq_42690194/article/details/125669141

    2024年02月11日
    瀏覽(42)
  • element ui組件的自定義類名樣式不生效

    element ui組件的自定義類名樣式不生效

    element ui中,類似描述列表這種組件? 會(huì)提供自定義類名屬性? ? 需要注意,樣式不能寫在style scoped標(biāo)簽中,會(huì)被vue自動(dòng)加上data-v屬性,導(dǎo)致樣式失效。 必須寫在style標(biāo)簽里 ? ? ?

    2024年02月13日
    瀏覽(19)
  • Vue.js 中使用 Element UI 實(shí)現(xiàn)異步加載分頁列表

    Vue.js 中使用 Element UI 實(shí)現(xiàn)異步加載分頁列表

    在前端開發(fā)中,我們常常需要展示大量數(shù)據(jù),并提供分頁瀏覽的功能。本篇博客將介紹如何使用 Vue.js 和 Element UI 組件庫創(chuàng)建一個(gè)簡單的異步加載分頁列表。 Vue.js Element UI JavaScript 我們將創(chuàng)建一個(gè)包含表格和分頁組件的 Vue 單文件組件。以下是組件的基本結(jié)構(gòu): 引入 Element U

    2024年02月04日
    瀏覽(33)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包