1fbd8155 by lihua

标准代码表支持自适应列宽

1 parent 0317718a
...@@ -10,6 +10,7 @@ import Table from '@/components/Table/index.vue' ...@@ -10,6 +10,7 @@ import Table from '@/components/Table/index.vue'
10 // import Dialog from '@/components/Dialog/index.vue' 10 // import Dialog from '@/components/Dialog/index.vue'
11 import useCatchStore from "@/store/modules/catch"; 11 import useCatchStore from "@/store/modules/catch";
12 import { chunk } from '@/utils/common' 12 import { chunk } from '@/utils/common'
13 import { calcColumnWidth } from "@/utils/index";
13 import { getStandardCodeDataList, getStandardCodeFields, 14 import { getStandardCodeDataList, getStandardCodeFields,
14 saveStandardCodeFieldsData, deleteStandardCodeFieldsData, 15 saveStandardCodeFieldsData, deleteStandardCodeFieldsData,
15 exportStandardCodeData 16 exportStandardCodeData
...@@ -120,6 +121,49 @@ const dialogInfo = ref({ ...@@ -120,6 +121,49 @@ const dialogInfo = ref({
120 }, 121 },
121 }) 122 })
122 123
124 /** otherWidth表示使用标题宽度时添加标题排序图标等宽度 */
125 const calcTableColumnWidth = (data: any[], prop, title, otherWidth = 0) => {
126 let d: any[] = [];
127 data.forEach((dt) => d.push(dt[prop]));
128 return calcColumnWidth(
129 d,
130 title,
131 {
132 fontSize: 14,
133 fontFamily: "SimSun",
134 },
135 {
136 fontSize: 14,
137 fontFamily: "SimSun",
138 },
139 otherWidth
140 );
141 };
142
143 /** 每列字段对应的列宽计算结果。 */
144 const originTableFieldColumn = ref({});
145
146 watch(
147 () => tableData.value,
148 (val: any[], oldVal) => {
149 if (!tableFields.value?.length) {
150 // originTableFieldColumn.value = {};
151 return;
152 }
153 //originTableFieldColumn.value = {};
154 tableFields.value.forEach((field, index) => {
155 field.width = calcTableColumnWidth(
156 val?.slice(0, 30) || [],
157 field.field,
158 field.label,
159 24
160 );
161 });
162 },
163 {
164 deep: true,
165 }
166 );
123 167
124 const getFirstPageData = () => { 168 const getFirstPageData = () => {
125 page.value.curr = 1; 169 page.value.curr = 1;
...@@ -476,16 +520,6 @@ const setUploadDataInfo = async (info, setField = false) => { ...@@ -476,16 +520,6 @@ const setUploadDataInfo = async (info, setField = false) => {
476 // chunkData() 520 // chunkData()
477 } 521 }
478 522
479 const chunkData = () => {
480 const data = orginData.value
481 tableChunkData.value = chunk(data, page.value.limit)
482 tableData.value = tableChunkData.value[page.value.curr - 1]
483 tableInfo.value.data = tableData.value
484 tableInfo.value.page.limit = page.value.limit
485 tableInfo.value.page.curr = page.value.curr
486 tableInfo.value.page.rows = orginData.value.length
487 }
488
489 const batching = (type) => { 523 const batching = (type) => {
490 if (type == 'delete') { 524 if (type == 'delete') {
491 if (selectRowData.value.length == 0) { 525 if (selectRowData.value.length == 0) {
......
...@@ -100,16 +100,16 @@ const tableInfo: any = ref({ ...@@ -100,16 +100,16 @@ const tableInfo: any = ref({
100 fixedSelection: true, 100 fixedSelection: true,
101 fields: [ 101 fields: [
102 { label: "序号", type: "index", width: 56, align: "center" }, 102 { label: "序号", type: "index", width: 56, align: "center" },
103 { label: '代码名称', field: 'codeName', width: 140 }, 103 { label: '代码名称', field: 'codeName', width: 160 },
104 // { label: '代码编码', field: 'code', width: 140 }, 104 // { label: '代码编码', field: 'code', width: 140 },
105 { label: '标准号', field: 'standard', width: 140 }, 105 { label: '标准号', field: 'standard', width: 140 },
106 { label: '标准名称', field: 'standardName', width: 140 }, 106 { label: '标准名称', field: 'standardName', width: 160 },
107 // { label: '启用状态', field: 'bizState', type: 'switch', activeText: '启用', inactiveText: '停用', activeValue: 1, inactiveValue: 0, switchWidth: 56, width: 100, align: 'center' }, 107 // { label: '启用状态', field: 'bizState', type: 'switch', activeText: '启用', inactiveText: '停用', activeValue: 1, inactiveValue: 0, switchWidth: 56, width: 100, align: 'center' },
108 { label: '启用状态', field: 'bizState', type: 'tag', width: 100, align: 'center',getName: (scope) => { 108 { label: '启用状态', field: 'bizState', type: 'tag', width: 100, align: 'center',getName: (scope) => {
109 let status = scope.row.bizState; 109 let status = scope.row.bizState;
110 return status == 'Y' ? '启用' : '停用'; 110 return status == 'Y' ? '启用' : '停用';
111 } }, 111 } },
112 { label: '创建时间', field: 'createTime', width: TableColumnWidth } 112 { label: '创建时间', field: 'createTime', width: TableColumnWidth.DATETIME }
113 ], 113 ],
114 data: [], 114 data: [],
115 page: { 115 page: {
......
...@@ -243,6 +243,18 @@ function getTableFields () { ...@@ -243,6 +243,18 @@ function getTableFields () {
243 const data = res.data 243 const data = res.data
244 standardFields.value = data 244 standardFields.value = data
245 let orderFieldIndex = null; 245 let orderFieldIndex = null;
246 let columnWidths = {
247 'order_num': 80,
248 'data_type': 100,
249 'length': 100,
250 // 'inside_identifier': 100,
251 'indicate_format': 110,
252 'other_data_relationship': 150,
253 'unit': 100,
254 'meta_data_type': 150,
255 'definition': 300,
256 'explanation': 300
257 }
246 const fields = data.map((item, index) => { 258 const fields = data.map((item, index) => {
247 if (currentObj.orderField && currentObj.orderField == item.fileNameCode) { 259 if (currentObj.orderField && currentObj.orderField == item.fileNameCode) {
248 orderFieldIndex = index; 260 orderFieldIndex = index;
...@@ -250,7 +262,7 @@ function getTableFields () { ...@@ -250,7 +262,7 @@ function getTableFields () {
250 return { 262 return {
251 label: item.fileNameCodeName, 263 label: item.fileNameCodeName,
252 field: item.fileNameCode, 264 field: item.fileNameCode,
253 width: 140 265 width: columnWidths[item.fileNameCode] || 140
254 } 266 }
255 }) 267 })
256 if (currentObj.orderField && currentObj.isDisplay == 'N') { 268 if (currentObj.orderField && currentObj.isDisplay == 'N') {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!