123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <!--
- 基础通用表格
- @Author: linqian
- @Date: 2021-07-07 17:11
- -->
- <template>
- <div>
- <!-- 列表 -->
- <dg-table
- border
- ref="baseTable"
- :auto-page="h=>h*0.6"
- :url="tableUrl"
- :condition="condition"
- :data="data"
- highlight-current-row
- :row-key="rowKey"
- :lazyLoad="lazyLoad"
- :load="load"
- :before-quest="handleBeforeQuest"
- :before-search="handleBeforeSearch"
- @selection-change="handleSelectionChange"
- @select="handleSelect"
- @select-all="handleCheckAll"
- @row-click="handleRowClick"
- >
- <dg-table-column v-if="selection" type="selection" reserve-selection width="55" align="center" />
- <dg-table-column type="index" label="序号" width="75" align="center" />
- <template v-for="item in tableHeader">
- <dg-table-column :key="item[rowKey]" v-bind="item" align="center">
- <template slot-scope="{ row }">
- <span v-if="item.dateFormat">{{ row[item.prop] | dateFormatter(item.dateFormat) }}</span>
- <slot v-if="item.custom" v-bind:row="row" :name="item.prop"></slot>
- </template>
- </dg-table-column>
- </template>
- <slot></slot>
- <!--操作栏-->
- <dg-table-column label="操作" align="center" v-if="tableOptList.length" :width="optColumnWidth">
- <template slot-scope="{ row }">
- <div class="u-table__operation">
- <el-tooltip
- v-for="(item, index) in tableOptList"
- :key="index"
- :content="item"
- effect="dark"
- placement="top-end"
- >
- <i :class="item | optIcon" @click="handleEvent(item, row)"></i>
- </el-tooltip>
- </div>
- </template>
- </dg-table-column>
- </dg-table>
- </div>
- </template>
- <script>
- import _ from 'lodash';
- import DgTable from '@srcPath/components/jz-base/table';
- export default {
- mixins: [DgTable],
- props: {
- tableUrl: String,
- tableHeader: Array,
- condition: {
- type: Object,
- default: () => {}
- },
- lazyLoad: {
- type: Boolean,
- default: false
- },
- load: {
- type: Function,
- default: (conditions) => conditions
- },
- rowKey: {
- type: String,
- default: 'id'
- },
- selection: {
- type: Boolean,
- default: false
- },
- // 列表操作
- tableOptList: {
- type: Array,
- default: () => []
- },
- // 操作列宽度
- optColumnWidth: {
- type: [String, Number],
- default: "120"
- }
- },
- components: {},
- data() {
- return {
- newChooseArr: []
- };
- },
- computed: {},
- methods: {
- /**
- * 查询
- */
- handleSearch() {
- this.$refs.baseTable.searchForm();
- },
- /**
- * 清除复选框选中的数据
- */
- handleClearSelection() {
- this.$refs.baseTable.clearAll();
- this.newChooseArr = [];
- },
- handleSelectionChange(data) {
- this.$emit('handleSelectionChange', data);
- },
- // getReqSearchCondition() {
- // return this.$refs.baseTable.getReqSearchCondition();
- // },
- handleBeforeSearch(conditions) {
- let searchConditionObj = JSON.parse(conditions.searchCondition);
- let result = [];
- for (let i = 0; i < searchConditionObj.length; i++) {
- const { op, value } = searchConditionObj[i];
- if (op == 'between' && value[0]) {
- result.push({ ...searchConditionObj[i], op: '>=', value: value[0] });
- result.push({ ...searchConditionObj[i], op: '<=', value: value[1] });
- } else {
- result.push(searchConditionObj[i]);
- }
- }
- conditions.searchCondition = JSON.stringify(result);
- conditions.sort = JSON.stringify(this.sortProps);
- return conditions;
- },
- /**
- * 进入页面默认选中设置
- */
- handleBeforeQuest(res) {
- const { content, totalElements } = res.data;
- this.currentPageContent = content;
- if (this.newChooseArr.length > 0) {
- let rowKeys = [];
- for (let j = 0; j < content.length; j++) {
- const cItem = content[j];
- const index = this.newChooseArr.findIndex((item) => (item[this.rowKey] || item) == cItem[this.rowKey]);
- if (index > -1) {
- rowKeys.push(this.newChooseArr[index][this.rowKey] || this.newChooseArr[index]);
- }
- }
- setTimeout(() => {
- this.$refs.baseTable.setCheck(rowKeys);
- }, 500);
- }
- const result = {
- data: {
- content,
- totalElements
- }
- };
- return result;
- },
- /**
- * 选中某条数据
- */
- handleSelect(selection, row) {
- let copyAttr = _.cloneDeep(this.newChooseArr);
- const index = this.newChooseArr.findIndex((item) => (item[this.rowKey] || item) == row[this.rowKey]);
- if (index > -1) {
- copyAttr.splice(index, 1);
- } else {
- copyAttr.push(row);
- }
- this.newChooseArr = copyAttr;
- console.log(this.newChooseArr);
- },
- /**
- * 选中/取消选中
- */
- handleCheckAll(selection) {
- const checked = selection.length == 0 ? false : true;
- this.currentPageContent.forEach((row) => {
- // this.handleSelect([], element);
- let copyAttr = _.cloneDeep(this.newChooseArr);
- const index = this.newChooseArr.findIndex((item) => (item[this.rowKey] || item) == row[this.rowKey]);
- if (checked) {
- if (index < 0) {
- copyAttr.push(row);
- }
- } else {
- if (index > -1) {
- copyAttr.splice(index, 1);
- }
- }
- this.newChooseArr = copyAttr;
- });
- console.log(this.newChooseArr);
- },
- // 发送操作事件类型
- handleEvent(type, row) {
- this.$emit('submitTableOpt', type, row);
- },
- /**
- * 表格某行被点击
- * */
- handleRowClick(row) {
- this.$refs.baseTable.setCurrentRow(row);
- this.$emit('handleRowClick', row);
- }
- },
- created() {},
- mounted() {}
- };
- </script>
- <style lang='scss'>
- </style>
|