Преглед изворни кода

四性检测动态加入、排序等

ZaiZai пре 2 година
родитељ
комит
6e70c11a83
3 измењених фајлова са 99 додато и 24 уклоњено
  1. 49 3
      src/global/components/hc-table/index.vue
  2. 45 20
      src/views/custody/testing.vue
  3. 5 1
      src/views/file/collection.vue

+ 49 - 3
src/global/components/hc-table/index.vue

@@ -4,7 +4,21 @@
                   @row-click="tableRowClick" @row-dblclick="tableRowDblClick" @row-contextmenu="tableRowContextmenu" @cell-click="tableCellClick" @cell-dblclick="tableCellDblClick"
                   @cell-contextmenu="tableCellContextmenu" style="width: 100%;">
             <el-table-column type="selection" width="50" v-if="isCheck"/>
-            <el-table-column type="index" prop="num" label="序号" width="80" v-if="isIndex && !isSlotNum"/>
+            <el-table-column type="index" prop="num" label="序号" width="80" v-if="isIndex && !isSlotNum">
+                <template #default="scope">
+                    <div class="table-column-sort">
+                        <span class="mr-3">{{scope.$index + 1}}</span>
+                        <template v-if="isDataSort">
+                            <span class="text-link text-lg">
+                                <HcIcon name="arrow-up" @click="upSortClick(scope.$index)"/>
+                            </span>
+                            <span class="text-link text-lg">
+                                <HcIcon name="arrow-down" @click="downSortClick(scope.$index)"/>
+                            </span>
+                        </template>
+                    </div>
+                </template>
+            </el-table-column>
             <el-table-column type="index" prop="num" width="100" v-if="isIndex && isSlotNum">
                 <template #header>
                     <div class="table-column-header-num">
@@ -72,6 +86,10 @@ const props = defineProps({
         type: String,
         default: '100%'
     },
+    isSort: {
+        type: Boolean,
+        default: false
+    },
 })
 
 //初始变量
@@ -80,16 +98,19 @@ const columns = ref(props.column)
 const tableData = ref(props.datas)
 const isLoading = ref(props.loading)
 const isBorder = ref(props.border)
+const isDataSort = ref(props.isSort)
 
 //监听
 watch(() => [
     props.datas,
     props.loading,
     props.border,
-], ([datas, loading, border]) => {
+    props.isSort,
+], ([datas, loading, border, isSort]) => {
     tableData.value = datas;
     isLoading.value = loading;
     isBorder.value = border;
+    isDataSort.value = isSort;
 })
 
 //监听表头
@@ -122,7 +143,7 @@ const setIsSlots = () => {
 
 //事件
 const emit = defineEmits([
-    'selection-change', 'row-drop',
+    'selection-change', 'row-drop', 'row-sort',
     'row-click', 'row-dblclick', 'row-contextmenu',
     'cell-click', 'cell-dblclick', 'cell-contextmenu'
 ])
@@ -194,6 +215,31 @@ const tableCellContextmenu = (row, column, cell, event) => {
     emit('cell-contextmenu', {row, column, cell, event})
 }
 
+//向上排序
+const upSortClick = (index) => {
+    const data = tableData.value
+    if(index !== 0) {
+        const tmp = data.splice(index - 1,1);
+        tableData.value.splice(index, 0, tmp[0]);
+        emit('row-sort', tableData.value)
+    } else {
+        window?.$message?.warning('已经处于置顶,无法上移')
+    }
+}
+
+//向下排序
+const downSortClick = (index) => {
+    const indexs = index + 1
+    const data = tableData.value
+    if(indexs !== data.length) {
+        const tmp = data.splice(indexs, 1);
+        tableData.value.splice(index, 0, tmp[0]);
+        emit('row-sort', tableData.value)
+    } else {
+        window?.$message?.warning('已经处于置底,无法下移')
+    }
+}
+
 // 暴露出去
 defineExpose({
     clearSelection,

+ 45 - 20
src/views/custody/testing.vue

@@ -272,7 +272,7 @@ import testBgsamll  from '~src/assets/view/testBgsamll.png';
 import HcCard1 from './components/hc-card1.vue'
 import HcTable1 from './components/hc-table1.vue'
 import reportApi from "~api/custody/testing.js";
-import {getArrValue, toParse, getObjValue, isArrIndex} from "js-fast-way"
+import {getArrValue, toParse, getObjValue, isArrIndex, deepClone} from "js-fast-way"
 import truePng from '~src/assets/testphoto/true.png';
 import fullPng from '~src/assets/testphoto/full.png';
 import usePng from '~src/assets/testphoto/use.png';
@@ -305,7 +305,7 @@ const tableLoading = ref(false)
 //一键检测
 const reportId=ref(0)
 const detectionLoad=ref(false)
-const detection=async()=>{
+const detection = async()=>{
     detectionLoad.value=true
     const { error, code, data } = await reportApi.getExamining({
         projectId: projectId.value,
@@ -328,7 +328,7 @@ const detection=async()=>{
 onMounted(() => {
     getReportData()
     getReportStatusdata()
- 
+
 })
 //获取检测报告状态
 const getReportStatusdata=async()=>{
@@ -361,18 +361,46 @@ const props = defineProps(
     }
 )
 //检测百分比
-const statusPercent=ref('25%')
-const finalUrl=ref('')
-const pushTable = (item) => {
-    setTimeout(() => {
-        tableData.value.unshift(item)
+const statusPercent = ref('25%')
+const finalUrl = ref('')
 
-    }, 1000);
+const newTabledata = ref([])
 
-   
+const pushTable = async () => {
+    const arr = reTabledata.value
+    for (let i = 0; i < arr.length; i++) {
+        if (!isArrIndex(newTabledata.value, 'id', arr[i].id)) {
+            console.log(arr[i].id, 'id')
+            newTabledata.value.push(arr[i])
+        }
+    }
+    setTimeoutData().then()
 }
 
-const reTabledata=ref([])
+
+const isTimeout = ref(false)
+const setTimeoutData = async () => {
+    const arr = newTabledata.value
+    console.log(arr, 'arr');
+    if (!isTimeout.value && arr.length > 0) {
+        isTimeout.value = true
+        for (let i = 0; i < arr.length; i++) {
+            const item = await getTimeoutData(arr[i])
+            tableData.value.unshift(item)
+        }
+    }
+}
+
+const getTimeoutData = (item) => {
+  return new Promise((resolve) => {
+    setTimeout(() => {
+        resolve(item)
+    }, 1000)
+  })
+}
+
+const reTabledata = ref([])
+
 //监听
 watch(() => [
         props.msgCount,
@@ -380,17 +408,15 @@ watch(() => [
         props.msgChange,
     ], ([val,index,msgChange]) => {
         const res = toParse(val)
-        if(res===true&&msgChange>0) {
+        if(res === true && msgChange > 0) {
             reportApi.getCurrentExaminingInfo({ reportId: reportId.value}).then((res)=>{
-                console.log(res.data,'res');
-                let resdata=res.data
+                let resdata = res.data
                 activeIndex.value = resdata.status;
-                tableData.value=resdata.detailList;
-                reTabledata.value=resdata.detailList
-                finalUrl.value=resdata.pdfUrl||''
+                reTabledata.value = resdata.detailList
+                finalUrl.value = resdata.pdfUrl||''
+                pushTable()
             })
         }
-      
         if(index.value===1){
             statusPercent.value='25%'
         }else if(index.value===2){
@@ -400,7 +426,7 @@ watch(() => [
         }else if(index.value===4){
             statusPercent.value='100%'
         }
-       
+
     }
 )
 //监听
@@ -427,7 +453,6 @@ const getReportData = async () => {
     reportLoading.value = true
     const { error, code, data } = await reportApi.getReportList({
         projectId: projectId.value,
-
     })
     reportLoading.value = false
     if (!error && code === 200) {

+ 5 - 1
src/views/file/collection.vue

@@ -255,7 +255,7 @@
 
         <!--新增编辑文件-->
         <el-dialog v-model="showUploadModal" title="上传工程文件" width="80vw" class="hc-modal-border hc-modal-table">
-            <HcTable ui="hc-form-table" :column="tableUploadColumn" :datas="tableUploadData" :loading="uploadSaveLoading">
+            <HcTable ui="hc-form-table" isSort :column="tableUploadColumn" :datas="tableUploadData" :loading="uploadSaveLoading" @row-sort="tableUploadRowSort">
                 <template #fileNumber="{row}">
                     <!-- <el-input v-model="row.fileNumber" :class="row['isFileNumber'] ? 'is-error' : ''" @input="tableIsInput($event, row, 'isFileNumber')"/> -->
                     <el-input v-model="row.fileNumber"/>
@@ -1130,6 +1130,10 @@ const whetherData = ref([
     {label: "需要", value: 1}
 ])
 
+//表格数据排序
+const tableUploadRowSort = (arr) => {
+    tableUploadData.value = arr
+}
 
 //删除
 const delUploadData = async (row,index) => {