소스 검색

修改了弹出框样式 ,增加适应列宽度

ooo 1 년 전
부모
커밋
3d9f81624d
1개의 변경된 파일35개의 추가작업 그리고 0개의 파일을 삭제
  1. 35 0
      src/components/CommonTable/index.vue

+ 35 - 0
src/components/CommonTable/index.vue

@@ -80,14 +80,41 @@ const crudRef = ref(null); //crudRef.value 获取avue-crud对象
 
 const commonTableEmits = defineEmits(["selectedSure"]);
 
+const calculateColumnWidth = (column) => {
+  if (!column.label) {
+    return column.minWidth;
+  }
+  // 字宽度
+  const fontSize = 17;
+  let width = fontSize * (column.label.length + 2);
+  // 如果开启过滤
+  if (column.filters) {
+    width += 12;
+  }
+  // 如果开启排序
+  if (column.sortable) {
+    width += 24;
+  }
+  return width;
+};
+
 onMounted(() => {
   url.value = tableConfig[props.tableType].url;
   option.value = Object.assign(option.value, {
     menu: false,
     highlightCurrentRow: true,
     addBtn: false,
+    height: "500",
+    overHidden: true,
+    indexWidth: "120px",
     column: tableConfig[props.tableType].column,
   });
+  // 列处理
+  if (option.value.column) {
+    for (let col of option.value.column) {
+      col.minWidth = calculateColumnWidth(col);
+    }
+  }
   // dataList();
 });
 watch(
@@ -98,8 +125,16 @@ watch(
       menu: false,
       highlightCurrentRow: true,
       addBtn: false,
+      height: "500",
+      overHidden: true,
       column: tableConfig[props.tableType].column,
     });
+    // 列处理
+    if (option.value.column) {
+      for (let col of option.value.column) {
+        col.minWidth = calculateColumnWidth(col);
+      }
+    }
     dataList();
   }
 );