| | |
| | | let day = String(date.getDate()).padStart(2, '0'); // 获取日期并补零 |
| | | return `${year}-${month}-${day}`; // 返回格式化后的字符串 |
| | | }, |
| | | selectionChange(e) { |
| | | // 只允许选中一条 |
| | | if (Array.isArray(e.detail) && e.detail.length > 1) { |
| | | // 只保留最后一条 |
| | | const last = e.detail[e.detail.length - 1]; |
| | | this.selectedIndexs = [this.tableData.indexOf(last)]; |
| | | |
| | | // 只选中最后一条 |
| | | this.$nextTick(() => { |
| | | const table = this.$refs.table; |
| | | if (table && table.toggleRowSelection) { |
| | | // 先取消前面的 |
| | | e.detail.slice(0, -1).forEach(row => { |
| | | table.toggleRowSelection(row, false); |
| | | }); |
| | | // 保证最后一条是选中的 |
| | | table.toggleRowSelection(last, true); |
| | | } |
| | | }); |
| | | } else if (Array.isArray(e.detail) && e.detail.length === 1) { |
| | | this.selectedIndexs = [this.tableData.indexOf(e.detail[0])]; |
| | | } else { |
| | | this.selectedIndexs = []; |
| | | } |
| | | }, |
| | | selectionChange(e) { |
| | | // 单选直接赋值 |
| | | this.selectedIndexs = [e.detail.index]; |
| | | }, |
| | | |
| | | selectedItems() { |
| | | return this.selectedIndexs.map(i => this.tableData[i]) |