欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Avue實(shí)現(xiàn)動(dòng)態(tài)查詢與數(shù)據(jù)展示的示例代碼

 更新時(shí)間:2024年08月20日 11:22:38   作者:碼農(nóng)研究僧  
Avue是一個(gè)基于Vue.js的前端框架,它是由阿里云開發(fā)的一款企業(yè)級(jí)UI組件庫(kù),旨在提供一套全面、易用且高性能的界面解決方案本文介紹了Avue實(shí)現(xiàn)動(dòng)態(tài)查詢與數(shù)據(jù)展示的示例,需要的朋友可以參考下

下面是一個(gè)前端查詢頁面的總結(jié),包括Demo示例和注釋

1. 基本知識(shí)

數(shù)據(jù)展示配置 (optiontotal, datatotal, totalPage)

<avue-crud
  :option="optiontotal"
  :data="datatotal"
  :page="totalPage"
  @on-load="loadPage">
  <!-- 插槽模板 -->
  <template slot-scope="scope" slot="menu">
    <el-button style="margin-left:10px;" size="small" type="text" @click.native="showDetail(scope.row)">查看</el-button>
  </template>
  <template slot-scope="scope" slot="remainCapacity" class="el-progress-bar__innerText">
    <el-progress :text-inside="true" :stroke-width="24" :color="percentageStyle(scope.row.remainCapacity)" :percentage="scope.row.remainCapacity"></el-progress>
  </template>
</avue-crud>
  • :option="optiontotal":配置avue-crud組件的顯示選項(xiàng),如表格列的定義、是否顯示刪除、編輯、添加按鈕等
  • :data="datatotal": 綁定要顯示的數(shù)據(jù),通常是從API獲取的結(jié)果數(shù)組
  • :page="totalPage":配置分頁信息,包括當(dāng)前頁碼、每頁大小、總記錄數(shù)等
  • @on-load="loadPage": 當(dāng)數(shù)據(jù)需要加載時(shí)調(diào)用loadPage方法,通常用于處理分頁和數(shù)據(jù)加載

基本的注意事項(xiàng)如下:

  • 分頁參數(shù):
    確保分頁參數(shù)(currentPage和pageSize)正確傳遞,并與后端API的分頁要求一致
    在分頁變化時(shí)(如頁碼變動(dòng)),需要重新加載數(shù)據(jù)以反映當(dāng)前頁的數(shù)據(jù)

  • 數(shù)據(jù)綁定:
    :data="datatotal"綁定的數(shù)據(jù)應(yīng)確保格式正確,并與表格列定義中的prop屬性一致
    數(shù)據(jù)中每一項(xiàng)的字段名稱應(yīng)與optiontotal中定義的列字段一致,以確保數(shù)據(jù)能正確顯示

  • 插槽使用:
    slot="menu"用于自定義行操作按鈕,如“查看”按鈕
    slot="remainCapacity"用于自定義進(jìn)度條顯示,動(dòng)態(tài)設(shè)置顏色和百分比,提供直觀的設(shè)備狀態(tài)反饋

2. Demo

以下為充電樁的實(shí)時(shí)動(dòng)態(tài)數(shù)據(jù),通過PLC實(shí)時(shí)傳輸?shù)綌?shù)據(jù)庫(kù)中,對(duì)應(yīng)這個(gè)頁面動(dòng)態(tài)查詢數(shù)據(jù)即可

整體界面邏輯如下:

  1. 組件初始化:在組件掛載時(shí),啟動(dòng)定時(shí)器每30秒自動(dòng)刷新數(shù)據(jù)
  2. 查詢功能
    -搜索:根據(jù)輸入的條件(如車輛名稱)查詢數(shù)據(jù)并更新展示
    -重置:重置表單字段和查詢條件,重新加載數(shù)據(jù)
  3. 數(shù)據(jù)顯示:通過avue-crud組件展示車輛信息,包括車輛名稱、狀態(tài)、充電槍狀態(tài)、電池溫度、剩余電量和更新時(shí)間等
  4. 詳情查看:點(diǎn)擊“查看”按鈕時(shí),跳轉(zhuǎn)到設(shè)備詳情頁面,并將設(shè)備名稱作為查詢參數(shù)傳遞
  5. 設(shè)備詳情對(duì)話框:顯示設(shè)備詳細(xì)信息的對(duì)話框(在此例中為空)
<template>
  <div>
    <basic-container>
      <!-- 查詢表單 -->
      <el-form :inline="true" ref="formInline" :model="formInline" label-width="150px">
        <el-form-item label="車輛名稱">
          <el-input v-model="formInline.deviceName" placeholder="請(qǐng)輸入車輛名稱"></el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" size="small" @click="onSearch">查詢</el-button>
          <el-button size="small" @click="resetForm('formInline')">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 數(shù)據(jù)展示卡片 -->
      <el-card class="box-card">
        <div class="clearfix">
          <span>總數(shù)為:{{totalPage.total}}輛</span>
          <avue-crud
            :option="optiontotal"
            :data="datatotal"
            :page="totalPage"
            @on-load="loadPage">
            <!-- 查看按鈕模板 -->
            <template slot-scope="scope" slot="menu">
              <el-button style="margin-left:10px;" size="small" type="text" @click.native="showDetail(scope.row)">查看</el-button>
            </template>
            <!-- 剩余電量進(jìn)度條模板 -->
            <template slot-scope="scope" slot="remainCapacity" class="el-progress-bar__innerText">
              <el-progress :text-inside="true" :stroke-width="24" :color="percentageStyle(scope.row.remainCapacity)" :percentage="scope.row.remainCapacity"></el-progress>
            </template>
          </avue-crud>
        </div>
      </el-card>
    </basic-container>

    <!-- 設(shè)備詳情對(duì)話框 -->
    <el-dialog title="設(shè)備詳情" :append-to-body='true' :visible="detailVisible" @close="closeDetialDialog"></el-dialog>
  </div>
</template>

<script>
import { getDeviceRealList } from "@/api/equipment/chargingSchedule/devicereal";

export default {
  data() {
    return {
      timer: null,
      detailVisible: false,
      query: {},
      totalPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      formInline: {
        deviceName: ''
      },
      datatotal: [],
      optiontotal: {
        height: 'auto',
        calcHeight: 95,
        fit: true,
        border: true,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menuWidth: 100,
        highlightCurrentRow: true,
        column: [
          {
            label: '車輛名稱',
            prop: 'deviceName'
          },
          {
            label: '車輛狀態(tài)',
            prop: 'vehicleStatus',
            dicData: [
              { label: '啟動(dòng)', value: '01' },
              { label: '熄火', value: '02' },
              { label: '充電', value: '03' },
              { label: '離線', value: '99' }
            ]
          },
          {
            label: '充電槍狀態(tài)',
            prop: 'chargeGun',
            dicData: [
              { label: '未連接', value: '00' },
              { label: '已連接', value: '11' }
            ]
          },
          {
            label: '電池系統(tǒng)溫度(℃)',
            prop: 'batteryTemp'
          },
          {
            label: '剩余電量(%)',
            prop: 'remainCapacity',
            slot: true
          },
          {
            label: '更新時(shí)間',
            prop: 'infoUpdateTime',
            width: '150'
          },
          {
            label: '時(shí)間差值(天)',
            prop: 'timeDifferenceDay',
            width: '70',
            formatter: (row) => this.calculateTimeDifference(row.infoUpdateTime)
          }
        ]
      }
    };
  },
  computed: {
    currentTime() {
      return new Date();
    }
  },
  mounted() {
    // 定時(shí)刷新頁面
    this.timer = setInterval(() => {
      setTimeout(() => this.loadPage(this.totalPage, this.query), 0);
    }, 1000 * 30);
  },
  methods: {
    calculateTimeDifference(updateTime) {
      const updateTimeObj = new Date(updateTime);
      const timeDifference = this.currentTime - updateTimeObj; // 時(shí)間差值,單位為毫秒
      const dayDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
      return dayDifference;
    },
    onSearch() {
      let searchInfo = {
        deviceName: this.formInline.deviceName === '' ? null : this.formInline.deviceName
      };
      this.totalPage.currentPage = 1;
      this.loadPage(this.totalPage, searchInfo);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.formInline.deviceName = null;
      this.onSearch();
    },
    showDetail(row) {
      this.$router.push({ path: '/equipment/chargingSchedule/deviceInfoVisual', query: { deviceName: row.deviceName } });
    },
    loadPage(page, params = {}) {
      getDeviceRealList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.totalPage.total = data.total;
        this.datatotal = data.records;
      });
    },
    percentageStyle(percentage) {
      if (percentage <= 20) return '#CD0000';
      if (percentage > 20 && percentage <= 40) return '#FF0000';
      if (percentage > 80) return '#32CD32';
      if (percentage > 60 && percentage <= 80) return '#EEEE00';
      if (percentage <= 60 && percentage > 40) return '#EEC900';
    },
    closeDetialDialog() {
      this.detailVisible = false;
    }
  }
}
</script>

<style>
.el-progress-bar__innerText {
  color: #0b0a0a;
  font-size: 12px;
  margin: 0px 5px;
}
</style>

最終界面如下所示:

到此這篇關(guān)于Avue實(shí)現(xiàn)動(dòng)態(tài)查詢與數(shù)據(jù)展示的示例代碼的文章就介紹到這了,更多相關(guān)Avue動(dòng)態(tài)查詢與數(shù)據(jù)展示內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue.js中關(guān)于“{{}}”的用法

    Vue.js中關(guān)于“{{}}”的用法

    這篇文章主要介紹了Vue.js中關(guān)于“{{}}”的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue便簽的簡(jiǎn)單實(shí)現(xiàn)

    Vue便簽的簡(jiǎn)單實(shí)現(xiàn)

    本文主要介紹了Vue便簽的簡(jiǎn)單實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • Vue數(shù)據(jù)驅(qū)動(dòng)表單渲染,輕松搞定form表單

    Vue數(shù)據(jù)驅(qū)動(dòng)表單渲染,輕松搞定form表單

    這篇文章主要介紹了Vue數(shù)據(jù)驅(qū)動(dòng)表單渲染,輕松搞定form表單,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • vue使用echarts畫組織結(jié)構(gòu)圖

    vue使用echarts畫組織結(jié)構(gòu)圖

    這篇文章主要介紹了vue使用echarts畫組織結(jié)構(gòu)圖的示例,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-02-02
  • vue利用better-scroll實(shí)現(xiàn)輪播圖與頁面滾動(dòng)詳解

    vue利用better-scroll實(shí)現(xiàn)輪播圖與頁面滾動(dòng)詳解

    在我們?nèi)粘5捻?xiàng)目開發(fā)中,處理滾動(dòng)和輪播圖是再常見不過的需求了,下面這篇文章主要給大家介紹了關(guān)于vue利用better-scroll實(shí)現(xiàn)輪播圖與頁面滾動(dòng)的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。
    2017-10-10
  • Vue?package-lock.json的作用及說明

    Vue?package-lock.json的作用及說明

    這篇文章主要介紹了Vue?package-lock.json的作用及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue-cli4 配置 element-ui 按需引入操作

    Vue-cli4 配置 element-ui 按需引入操作

    這篇文章主要介紹了Vue-cli4 配置 element-ui 按需引入操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue項(xiàng)目打包之后生成一個(gè)可修改IP地址的文件(具體操作)

    vue項(xiàng)目打包之后生成一個(gè)可修改IP地址的文件(具體操作)

    這篇文章主要介紹了vue項(xiàng)目打包之后生成一個(gè)可修改IP地址的文件(具體操作),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • Vue項(xiàng)目引入translate.js國(guó)際化自動(dòng)翻譯組件的方法

    Vue項(xiàng)目引入translate.js國(guó)際化自動(dòng)翻譯組件的方法

    這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目引入translate.js國(guó)際化自動(dòng)翻譯組件的相關(guān)資料,除了基本的文本翻譯功能之外,jstranslate還提供了一些高級(jí)功能,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • vue語法自動(dòng)轉(zhuǎn)typescript(解放雙手)

    vue語法自動(dòng)轉(zhuǎn)typescript(解放雙手)

    這篇文章主要介紹了vue語法自動(dòng)轉(zhuǎn)typescript,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論