¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div> |
| | | <!-- è¡¨æ ¼ --> |
| | | <el-table |
| | | ref="multipleTable" |
| | | v-loading="tableLoading" |
| | | :border="border" |
| | | :data="tableData" |
| | | :header-cell-style="{ background: '#0e3372', color: '#cccccc' }" |
| | | :height="height" |
| | | :highlight-current-row="highlightCurrentRow" |
| | | :row-class-name="rowClassName" |
| | | :row-style="rowStyle" |
| | | :row-key="rowKey" |
| | | stripe |
| | | style="width: 100%; " |
| | | tooltip-effect="dark" |
| | | @row-click="rowClick" |
| | | @current-change="currentChange" |
| | | @selection-change="handleSelectionChange" |
| | | > |
| | | <template v-if="isSelection"> |
| | | <el-table-column type="selection" width="55" /> |
| | | </template> |
| | | <template> |
| | | <el-table-column align="center" label="åºå·" type="index" width="60" /> |
| | | </template> |
| | | |
| | | <template v-for="(item, index) in column"> |
| | | <el-table-column :column-key="item.columnKey" :filter-method="item.filterHandler" |
| | | :filter-multiple="item.filterMultiple" :filtered-value="item.filteredValue" |
| | | :filters="item.filters" :fixed="item.fixed" :label="item.label" |
| | | :min-width="item.minWidth" :prop="item.prop" |
| | | :show-overflow-tooltip="item.showOverflowTooltip" |
| | | :sortable="item.sortable ? true : false" :type="item.type" :width="item.width" |
| | | align="center"> |
| | | <!-- <div class="123" v-if="item.type == ''"> --> |
| | | <template v-if="item.hasOwnProperty('colunmTemplate')" :slot="item.colunmTemplate" |
| | | slot-scope="scope"> |
| | | <slot v-if="item.theadSlot" :index="index" :name="item.theadSlot" :row="scope.row" /> |
| | | </template> |
| | | |
| | | <template slot-scope="scope"> |
| | | <!-- ææ§½ --> |
| | | <div v-if="item.dataType == 'slot'"> |
| | | <slot v-if="item.slot" :index="scope.$index" :name="item.slot" :row="scope.row" /> |
| | | </div> |
| | | <!-- è¿åº¦æ¡ --> |
| | | <div v-else-if="item.dataType == 'progress'"> |
| | | <el-progress :percentage="Number(scope.row[item.prop])" /> |
| | | </div> |
| | | |
| | | <!-- tag --> |
| | | <div v-else-if="item.dataType == 'tag'"> |
| | | <el-tag v-if="typeof dataTypeFn(scope.row[item.prop], item.formatData) == 'string'" |
| | | :title="scope.row[item.prop] | formatters(item.formatData)" |
| | | :type="formatType(scope.row[item.prop], item.formatType)">{{ scope.row[item.prop] | formatters(item.formatData) }}</el-tag> |
| | | <el-tag v-for="(tag, index) in dataTypeFn(scope.row[item.prop], item.formatData)" |
| | | v-else-if="typeof dataTypeFn(scope.row[item.prop], item.formatData) == 'object'" |
| | | :key="index" :title="scope.row[item.prop] | formatters(item.formatData)" |
| | | :type="formatType(tag, item.formatType)">{{ item.tagGroup ? tag[item.tagGroup.label] ? tag[item.tagGroup.label] : tag : tag }}</el-tag> |
| | | <el-tag v-else :title="scope.row[item.prop] | formatters(item.formatData)" |
| | | :type="formatType(scope.row[item.prop], item.formatType)">{{ scope.row[item.prop] | formatters(item.formatData) }}</el-tag> |
| | | </div> |
| | | |
| | | <!-- æé® --> |
| | | <div v-else-if="item.dataType == 'action'"> |
| | | <template v-for="(o, key) in item.operation"> |
| | | <el-button |
| | | v-if="o.type!='upload'" |
| | | v-show="o.showHide ? o.showHide(scope.row) : true" |
| | | :disabled="o.disabled ? o.disabled(scope.row) : false" |
| | | :icon="o.icon | iconFn(scope.row)" |
| | | :plain="o.plain" :size="o.size" |
| | | :style="{ 'color': o.color }" |
| | | :type="o.type | typeFn(scope.row)" |
| | | @click="o.clickFun(scope.row)"> |
| | | {{ o.name }} |
| | | </el-button> |
| | | <el-upload |
| | | action="#" |
| | | :on-change="(file, fileList)=>o.clickFun(scope.row,file, fileList)" |
| | | :multiple="o.multiple?o.multiple:false" |
| | | :limit="o.limit?o.limit:1" |
| | | :disabled="o.disabled ? o.disabled(scope.row) : false" |
| | | :accept="o.accept?o.accept:'.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'" |
| | | v-if="o.type=='upload'" style="display: inline-block;width: 50px;" |
| | | v-show="o.showHide ? o.showHide(scope.row) : true" |
| | | :auto-upload="false" |
| | | :on-exceed="onExceed" |
| | | :show-file-list="false"> |
| | | <el-button :size="o.size?o.size:'small'" type="text" :disabled="o.disabled ? o.disabled(scope.row) : false">{{o.name}}</el-button> |
| | | </el-upload> |
| | | </template> |
| | | </div> |
| | | <!-- é»è®¤çº¯å±ç¤ºæ°æ® --> |
| | | <div v-else> |
| | | <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span> |
| | | <span v-else>{{ scope.row[item.prop] | formatters(item.formatData) }}</span> |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | </template> |
| | | </el-table> |
| | | <pagination |
| | | v-show="page.total>0" |
| | | :total="page.total" |
| | | :page.sync="page.pageNum" |
| | | :limit.sync="page.pageSize" |
| | | @pagination="pagination" |
| | | /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | // 注ï¼ä»¥ä¸æ¯ææé
置项ï¼å
¶ä¸æå¸¸ä½¿ç¨çå°±æ¯labelãwidthãpropãdataTypeãslot |
| | | // label ï¼ååï¼å°±æ¯è¡¨å¤´ä¸çæ ç¾å«ä»ä¹äºä»ä¹ï¼ç±»å string |
| | | // widthï¼è¯¥åå®½åº¦ï¼ string |
| | | // propï¼ tableç»å®æ°æ®å段 string,è¿ä¸åè¦å±ç¤ºåªä¸ªtableDataéé¢çåæ®µå°±ååªä¸ªå段 |
| | | // dataTypeï¼ å
ç½®å¤ä¸ªåºæ¬çelementç»ä»¶å¯ä¾ç´æ¥ä½¿ç¨ string |
| | | // slot å½`dataType`为`slot`æ¶å¿
另忰ï¼åæ°å¼ä¸ºææ§½ç `slot` å¼ stringï¼å
·ä½ä½¿ç¨æ¹æ³è¯·çä¸é¢ç第4ç¹slotææ§½çä½¿ç¨ |
| | | // fixedï¼åæ¯å¦åºå®å¨å·¦ä¾§æè
å³ä¾§ï¼true 表示åºå®å¨å·¦ä¾§ string, boolean |
| | | // sortable 对åºåæ¯å¦å¯ä»¥æåº boolean, string |
| | | // filters æ°æ®è¿æ»¤çéé¡¹ï¼æ°ç»æ ¼å¼ï¼æ°ç»ä¸çå
ç´ éè¦æ text å value 屿§ãArray |
| | | // columnKey ï¼column ç keyï¼å¦æéè¦ä½¿ç¨ filter-change äºä»¶ï¼åéè¦æ¤å±æ§æ è¯æ¯åªä¸ª column çç鿡件 |
| | | // filteredValue éä¸çæ°æ®è¿æ»¤é¡¹ï¼å¦æéè¦èªå®ä¹è¡¨å¤´è¿æ»¤çæ¸²ææ¹å¼ï¼å¯è½ä¼éè¦æ¤å±æ§ã |
| | | // filterMultiple æ°æ®è¿æ»¤çé项æ¯å¦å¤é |
| | | // minWidth 对åºåçæå°å®½åº¦ï¼ä¸ width çåºå«æ¯ width æ¯åºå®çï¼min-width 伿å©ä½å®½åº¦ææ¯ä¾åé
ç»è®¾ç½®äº min-width çå string |
| | | // formatData å¯¹æ°æ®è¿è¡æ°æ®å¤çï¼æ¥åä¸ä¸ªåè°å½æ° (params?: {prop}) => {} |
| | | // formatType å½ `dataType`为 `tag`æ¶ï¼å¯¹æ ç¾é¢è²è®¾ç½® (params?: {prop}) => { return 'danger'| 'success'... }` |
| | | // operation å½ `dataType` 为 `option`æ¶ï¼å¯¹æé®ç é
ç½®ï¼å
·ä½é
置项以ä¸å¾ä¸ºåobject |
| | | // tagGroup å½ `dataType`为 `tag`æ¶ï¼ç»å®æ°æ®éåæ®µæ¾ç¤ºåç§° object |
| | | /** |
| | | * ææ§½çä½¿ç¨æ¹æ³: |
| | | */ |
| | | /* <div |
| | | slot="protocolSlot" |
| | | slot-scope="scope" |
| | | > |
| | | <span>{{ scope.row.protocol }}</span> |
| | | </div> |
| | | */ |
| | | /** |
| | | * 使ç¨formatDataè¿è¡æ°æ®å¤ç |
| | | */ |
| | | // { |
| | | // type: '', |
| | | // label: 'å¯ç¨ç¶æ', |
| | | // prop: 'is_active', |
| | | // formatData: (item) => { |
| | | // const str = item == true ? 'å·²å¯ç¨' : 'æªå¯ç¨' |
| | | // return str |
| | | // } |
| | | // }, |
| | | /** |
| | | * operationé
ç½® |
| | | */ |
| | | // operationé
ç½®ä¸»è¦æ¯æ¥ç¨äºè¡¨æ ¼éé¢çæä½é£ä¸åï¼é叏就伿å¾å¤æé®ï¼æä»¥ä¸åæ°ï¼ |
| | | // nameï¼æé®åç§°ï¼string |
| | | // typeï¼æé®ç±»åï¼`string` | `danger | success`ï¼ä»¥elementUi åæ°ä¸ºå |
| | | // sizeï¼æé®å¤§å°ï¼ä»¥elementUi åæ°ä¸ºå |
| | | // iconï¼æé®ä¸çiconï¼ä»¥elementUi åæ°ä¸ºå |
| | | // plainï¼æelementUi ææ¡£ä¸ºå |
| | | // clickFunï¼æé®çåè°å½æ° |
| | | export default { |
| | | name: 'ZTTable', |
| | | filters: { |
| | | iconFn(val, row) { |
| | | if (typeof (val) === 'function') { |
| | | return val(row); |
| | | } else return val; |
| | | }, |
| | | typeFn(val, row) { |
| | | // console.log(val, row, '11111111'); |
| | | if (typeof (val) === 'function') { |
| | | return val(row); |
| | | } else return val; |
| | | }, |
| | | describeConts(val, describeCont) { |
| | | if (typeof (describeCont) === 'function') { |
| | | return describeCont(val); |
| | | } else return val; |
| | | }, |
| | | formatters(val, format) { |
| | | if (typeof (format) === 'function') { |
| | | return format(val); |
| | | } else return val; |
| | | } |
| | | }, |
| | | props: { |
| | | isSelection: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | height: { |
| | | type: String, |
| | | default: null |
| | | }, |
| | | tableLoading: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | handleSelectionChange: { |
| | | type: Function, |
| | | default: () => { |
| | | return () => { |
| | | }; |
| | | } |
| | | }, |
| | | rowClick: { |
| | | type: Function, |
| | | default: () => { |
| | | return () => { |
| | | }; |
| | | } |
| | | }, |
| | | currentChange: { |
| | | type: Function, |
| | | default: () => { |
| | | return () => { |
| | | }; |
| | | } |
| | | }, |
| | | border: { |
| | | type: Boolean, |
| | | default: true |
| | | }, |
| | | highlightCurrentRow: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | headerCellStyle: { |
| | | type: Object, |
| | | default: () => { |
| | | return {}; |
| | | } |
| | | }, |
| | | column: { |
| | | type: Array, |
| | | default() { |
| | | return []; |
| | | } |
| | | }, |
| | | rowClassName: { |
| | | type: Function, |
| | | default: () => { |
| | | |
| | | } |
| | | }, |
| | | rowStyle: { |
| | | type: Object || Function, |
| | | default: () => { |
| | | } |
| | | }, |
| | | tableData: { |
| | | type: Array, |
| | | default() { |
| | | return []; |
| | | } |
| | | }, |
| | | rowKey: { |
| | | type: String, |
| | | default: undefined |
| | | }, |
| | | page:{ |
| | | type:object, |
| | | default() { |
| | | return { |
| | | total:0, |
| | | pageNum:0, |
| | | pageSize:10 |
| | | }; |
| | | } |
| | | } |
| | | }, |
| | | |
| | | methods: { |
| | | formatType(val, format) { |
| | | if (typeof (format) === 'function') { |
| | | return format(val); |
| | | } else return ''; |
| | | }, |
| | | dataTypeFn(val, format) { |
| | | if (typeof (format) === 'function') { |
| | | return format(val); |
| | | } else return val; |
| | | }, |
| | | setCurrent(row) { |
| | | this.$refs.multipleTable.setCurrentRow(); |
| | | }, |
| | | onExceed(){ |
| | | this.$message.warning('è¶
åºæä»¶ä¸ªæ°'); |
| | | }, |
| | | pagination(page,limit){ |
| | | this.$emit('pagination',{pageNum: page, pageSize: limit}); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .el-table >>> .el-table__empty-text { |
| | | text-align: center |
| | | } |
| | | </style> |
| | | |