BaseMyTable.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <template>
  2. <div class="myTable">
  3. <!-- 科目选择以及表格备注 -->
  4. <div class="table-subject-select">
  5. <!-- <Select v-model="subjectSelectVal" style="width:150px" v-if="showSelect" @on-change="onSelectChange">
  6. <Option v-for="(item,index) in subjectList" :value="index" :key="index">{{ item }}</Option>
  7. </Select> -->
  8. <div class="myTable-title">{{ tableName }}</div>
  9. <div>
  10. <span @click="exportData(3)" class="table-export-btn"><Icon type="ios-share-alt" /> {{$t('totalAnalysis.exportTable').slice(0,2)}}</span>
  11. <span class="table-tips" v-if="tips">{{tips}}</span>
  12. <span class="table-tips" v-if="!tips"></span>
  13. </div>
  14. </div>
  15. <!-- 表格组件 -->
  16. <Table :border="isShowBorder" ref="table" :data="tableData" :columns="tableColumns" @on-sort-change="onSortChange" @on-filter-change="onFilterChange"></Table>
  17. <!-- 表格分页组件 -->
  18. <div style="margin: 10px;overflow: hidden" v-if="!noPage">
  19. <div style="float: right;margin-top: 20px;">
  20. <Page show-total
  21. size="small"
  22. :current="currentPage"
  23. :total="originData.length"
  24. :page-size="pageSize"
  25. :page-size-opts="pageSizeOpts"
  26. @on-change="pageChange"
  27. @on-page-size-change="pageSizeChange"
  28. show-sizer />
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import excel from '@/utils/excel.js'
  35. export default {
  36. props: {
  37. columns: {
  38. type: Array,
  39. default: () => []
  40. },
  41. isScroll: {
  42. type: Boolean,
  43. default: false
  44. },
  45. tableDatas: {
  46. type: Array,
  47. default: () => []
  48. },
  49. showSelect: {
  50. type: Boolean,
  51. default: false
  52. },
  53. noPage: {
  54. type: Boolean,
  55. default: false
  56. },
  57. tips: {
  58. type: String,
  59. default: null
  60. },
  61. tableTitle: {
  62. type: String,
  63. default: null
  64. },
  65. pageSize: {
  66. type: Number,
  67. default: 10
  68. },
  69. tableName: {
  70. type: String,
  71. default:'Analysis Table'
  72. },
  73. tableRef: {
  74. type: String,
  75. default:''
  76. }
  77. },
  78. data() {
  79. return {
  80. isShowBorder: true,
  81. isFirst: true,
  82. subjectSelectVal: 0,
  83. tableData: [],
  84. firstData: [],
  85. originData: [],
  86. tableColumns: [],
  87. subjectList: [],
  88. currentPage: 1,
  89. pageSizes: 10,
  90. pageSizeOpts: [5, 10, 20, 30, 40],
  91. poperData: []
  92. }
  93. },
  94. created() {
  95. this.tableColumns = this.columns
  96. this.originData = this.tableDatas
  97. this.columns.forEach(item => {
  98. item.render = typeof item.renderType === 'function' ? item.renderType : this[item.renderType]
  99. })
  100. },
  101. methods: {
  102. // 导出表格
  103. exportData (type) {
  104. if (type === 3) {
  105. const params = {
  106. title: this.columns.map(i => i.title),
  107. key: this.columns.map(i => i.key),
  108. data: this.originData,
  109. autoWidth: true,
  110. filename: this.tableName
  111. }
  112. excel.export_array_to_excel(params)
  113. } else {
  114. // 多个文件 打包下载
  115. const params = {
  116. title: this.columns.map(i => i.title),
  117. key: this.columns.map(i => i.key),
  118. data: this.originData,
  119. autoWidth: true,
  120. filename: this.tableName
  121. }
  122. this.$store.commit('updateExportParams', params)
  123. }
  124. },
  125. // 排序操作
  126. onSortChange(data) {
  127. console.log(data)
  128. let order = data.order // 当前排序方式 升序、降序、正常
  129. let key = data.key // 当前排序依据
  130. switch (order) {
  131. case 'asc':
  132. this.originData = this.tableDatas.sort((a, b) => { return Number(a[key]) - Number(b[key]) })
  133. break
  134. case 'desc':
  135. this.originData = this.tableDatas.sort((a, b) => { return Number(b[key]) - Number(a[key]) })
  136. break
  137. case 'normal':
  138. this.originData = this.firstData
  139. break
  140. default:
  141. break
  142. }
  143. this.pageChange(1)
  144. },
  145. // 筛选操作
  146. onFilterChange(val) {
  147. let filterValue = val._filterChecked[0]
  148. const ipoint = this.$store.state.totalAnalysis.analysisJson.ipoint
  149. const touchScore = this.$store.state.totalAnalysis.analysisJson.touchScore
  150. switch (filterValue) {
  151. case 1:
  152. this.originData = this.tableDatas.filter(item => item.score > ipoint)
  153. break
  154. case 2:
  155. this.originData = this.tableDatas.filter(item => item.score > ipoint && item.score < (ipoint + touchScore))
  156. break
  157. case 3:
  158. console.log('进步班级')
  159. break
  160. case 4:
  161. console.log('退步班级')
  162. break
  163. case 5:
  164. console.log('稳定班级')
  165. break
  166. default:
  167. this.originData = this.firstData
  168. break
  169. }
  170. this.pageChange(1)
  171. },
  172. // 分页操作
  173. pageChange(page) {
  174. let start = this.pageSizes * (page - 1)
  175. let end = this.pageSizes * page
  176. this.currentPage = page
  177. this.tableData = this.originData.slice(start, end)
  178. },
  179. // 页码操作
  180. pageSizeChange(val) {
  181. this.pageSizes = val
  182. this.pageChange(1)
  183. },
  184. // 下拉选择
  185. onSelectChange(val) {
  186. this.$emit('onSelectChange', val)
  187. },
  188. // 渲染班级标题以及相应点击事件
  189. renderClassName(h, params) {
  190. let that = this
  191. let row = params.row
  192. return h('span', {
  193. }, [
  194. h('span', {
  195. domProps: {
  196. className: 'table-rank-value'
  197. }
  198. }, params.row.classId),
  199. ])
  200. },
  201. renderEventIndex(h, params) {
  202. let that = this
  203. return h('span', {
  204. on: {
  205. click: function() {
  206. that.$parent.$parent.$parent.isShowQuestions = true
  207. that.$router.push({ path: '/total/questionList', query: { QIndex: params.row.id } })
  208. }
  209. },
  210. style: {
  211. cursor: 'pointer',
  212. color: '#00ffd2',
  213. fontWeight: 'bold'
  214. }
  215. }, params.row.id)
  216. },
  217. // 总分排名Render
  218. renderRank(h, params) {
  219. const row = params.row
  220. return h('span', {
  221. domProps: {
  222. className: 'badge-wrap'
  223. }
  224. }, [
  225. h('span', {
  226. domProps: {
  227. className: 'table-rank-badge'
  228. },
  229. style: {
  230. color: row.changesStatus === 1 ? '#0ccb0c' : '#ff5d5d'
  231. }
  232. }, (row.changesStatus === 1 && row.changesVal !== 0) ? '+' + row.changesVal : (row.changesStatus === -1 && row.changesVal !== 0) ? '-' + row.changesVal : ''),
  233. h('span', {
  234. domProps: {
  235. className: 'table-rank-value'
  236. }
  237. }, row.gradeRank)
  238. ]
  239. )
  240. },
  241. // 折线图趋势变化
  242. renderLineChange(h, params) {
  243. const row = params.row
  244. return h('Poptip', {
  245. props: {
  246. trigger: 'hover',
  247. placement: 'right',
  248. transfer: true
  249. },
  250. on: {
  251. // 鼠标触发气泡事件
  252. 'on-popper-show': () => {
  253. console.log(row.poperData)
  254. // this.poperData = row.poperData
  255. }
  256. }
  257. }, [
  258. h('Icon', {
  259. props: {
  260. type: row.classRank === 1 ? 'md-trending-up' : row.classRank === 2 ? 'md-trending-down' : 'md-git-commit',
  261. color: row.classRank === 1 ? '#13ff13' : row.classRank === 2 ? '#fd4e4e' : 'yellow',
  262. size: '22'
  263. },
  264. style: {
  265. cursor: 'pointer'
  266. }
  267. }),
  268. h('div', {
  269. slot: 'content'
  270. }, [h('BaseChangeLine', {
  271. props: {
  272. poperData: row.poperData,
  273. isLoad: true,
  274. lineColor: row.classRank === 1 ? 'green' : row.classRank === 2 ? '#fd4e4e' : '#ffcc33'
  275. }
  276. })
  277. ])
  278. ])
  279. },
  280. // 排名变化
  281. renderRankChange(h, params) {
  282. const row = params.row
  283. return h('span', [
  284. h('Icon', {
  285. props: {
  286. type: (row.changesStatus === 1 && row.changesVal !== 0) ? 'md-arrow-up' : (row.changesStatus === -1 && row.changesVal !== 0) ? 'md-arrow-down' : 'md-git-commit',
  287. color: (row.changesStatus === 1 && row.changesVal !== 0) ? '#13ff13' : (row.changesStatus === -1 && row.changesVal !== 0) ? '#fd4e4e' : 'yellow',
  288. size: '22'
  289. },
  290. style: {
  291. cursor: 'pointer'
  292. }
  293. }),
  294. h('span', {
  295. domProps: {
  296. className: 'table-rank-value'
  297. }
  298. }, row.changesStatus === 0 ? '' : row.changesVal)
  299. ])
  300. },
  301. // 是否进线
  302. renderEntry(h, params) {
  303. let that = this
  304. const row = params.row
  305. const ipoint = this.$store.state.totalAnalysis.analysisJson.ipoint
  306. const touchScore = this.$store.state.totalAnalysis.analysisJson.touchScore
  307. return h('span', [
  308. h('span', {
  309. domProps: {
  310. className: 'table-entry-status'
  311. },
  312. style: {
  313. cursor: 'pointer',
  314. background: row.score > (ipoint + touchScore) ? '#209a31' : row.score > ipoint ? '#00767d' : 'transparent'
  315. }
  316. }, row.score > (ipoint + touchScore) ? that.$t('totalAnalysis.myTable.inner') : row.score > ipoint ? that.$t('totalAnalysis.myTable.outer') : ''),
  317. h('span', {
  318. domProps: {
  319. className: 'table-rank-value'
  320. }
  321. }, row.score)
  322. ])
  323. },
  324. // 变化状态
  325. renderStauts(h, params) {
  326. const row = params.row
  327. return h('span', [
  328. h('Icon', {
  329. props: {
  330. type: row.classRank === 1 ? 'md-arrow-up' : row.classRank === 2 ? 'md-arrow-down' : 'md-git-commit',
  331. color: row.classRank === 1 ? '#13ff13' : row.classRank === 2 ? '#fd4e4e' : 'yellow',
  332. size: '22'
  333. },
  334. style: {
  335. cursor: 'pointer'
  336. }
  337. })
  338. ])
  339. },
  340. // 渲染应努力题号
  341. renderHard(h, params) {
  342. let that = this
  343. const list = params.row.hardList ? params.row.hardList.split(',') : params.row.itemNO.split(',')
  344. return h('span', { style: {
  345. textAlign:'left'
  346. }},list.map(function(item, index) {
  347. return h('span', {
  348. style: {
  349. fontSize: '16px',
  350. fontWeight: '600',
  351. color: '#03efdb',
  352. cursor: 'pointer',
  353. display: 'inline-block',
  354. float: 'left'
  355. },
  356. on: {
  357. 'click': function() {
  358. that.$parent.$parent.$parent.isShowQuestions = true
  359. that.$router.push({ path: '/total/questionList', query: { QIndex: isNaN(item) ? 1 : item } })
  360. }
  361. }
  362. }, item + (index === list.length - 1 ? '' : ' , '))
  363. }))
  364. },
  365. // 渲染应小心题号
  366. renderCareful(h, params) {
  367. let that = this
  368. const row = params.row
  369. const list = params.row.carefulList ? params.row.carefulList.split(',') : []
  370. return h('span', list.map(function(item, index) {
  371. return h('span', {
  372. style: {
  373. fontSize: '16px',
  374. fontWeight: '600',
  375. color: '#03efdb',
  376. cursor: 'pointer',
  377. display: 'inline-block',
  378. float: 'left'
  379. // textDecoration: "underline"
  380. },
  381. on: {
  382. 'click': function() {
  383. that.$parent.$parent.$parent.isShowQuestions = true
  384. that.$router.push({ path: '/total/questionList', query: { QIndex: isNaN(item) ? 1 : item } })
  385. }
  386. }
  387. }, item + (index === list.length - 1 ? '' : ' , '))
  388. }))
  389. },
  390. // 渲染百分比数据
  391. renderPercent(h, params) {
  392. return h('span', params.row.scoreRate + '%')
  393. }
  394. },
  395. mounted() {
  396. if(this.noPage){
  397. this.pageSizes = 999999
  398. this.pageChange(1)
  399. this.currentPage = 1
  400. }
  401. },
  402. computed: {
  403. exportTableRefs() {
  404. return this.$store.state.totalAnalysis.exportTableRefs
  405. }
  406. },
  407. watch: {
  408. tableDatas: function(data) {
  409. this.originData = JSON.parse(JSON.stringify(data))
  410. if (this.isFirst) this.firstData = JSON.parse(JSON.stringify(data))
  411. // 获取当前测评班级数据
  412. this.subjectList = this.$store.state.totalAnalysis.subjectList
  413. // this.subjectList = ['全部'].concat(this.$store.state.totalAnalysis.subjectList)
  414. this.pageChange(1)
  415. this.isFirst = false
  416. },
  417. exportTableRefs: {
  418. handler(n) {
  419. // 如果导出的表格包含当前表格 则直接运行下载
  420. if (n.length && n.indexOf(this.tableRef) > -1) {
  421. // 如果选择下载的表格数量大于1 则进行打包下载
  422. if(n.length > 1){
  423. this.exportData(4)
  424. }else{
  425. this.exportData(3)
  426. }
  427. }
  428. },
  429. deep:true
  430. }
  431. }
  432. }
  433. </script>
  434. <style>
  435. .myTable {
  436. width: 100%;
  437. /*height: 400px;*/
  438. /*padding: 20px 0;*/
  439. padding-right: 20px;
  440. margin-top: 20px;
  441. margin: 0 auto;
  442. display: block;
  443. user-select: none !important;
  444. }
  445. .myTable .ivu-table td, .myTable .ivu-table th {
  446. /*border: none;*/
  447. color: #e4eadb;
  448. border-color: #595959;
  449. }
  450. .myTable .ivu-table-wrapper {
  451. /*border:none;*/
  452. border-color: #595959;
  453. border-right: 1px solid #595959;
  454. }
  455. .myTable .ivu-table::before, .myTable .ivu-table::after {
  456. height: 1px;
  457. background: #595959;
  458. }
  459. .myTable .ivu-table {
  460. box-sizing: border-box;
  461. /*border:1px solid #595959;*/
  462. }
  463. .myTable .ivu-table, .myTable .ivu-table td {
  464. background: #343434;
  465. text-align: center;
  466. position: relative;
  467. }
  468. .myTable .ivu-table th {
  469. background: rgba(107, 107, 107, 0.19);
  470. text-align: center;
  471. position: relative;
  472. }
  473. .myTable .ivu-table-sort {
  474. margin-left: -6px;
  475. }
  476. .myTable .ivu-table-sort i {
  477. color: #fff;
  478. margin-left: 1px;
  479. }
  480. .myTable .ivu-table-sort i.on{
  481. color: #4cf8da;
  482. }
  483. .myTable .ivu-table-header .ivu-table-cell {
  484. font-size: 14px;
  485. font-weight: bold;
  486. }
  487. .myTable .ivu-table-header {
  488. background: rgba(228, 234, 219, 0.08);
  489. }
  490. .myTable .table-rank-value {
  491. margin-left: 10px;
  492. vertical-align: middle;
  493. font-size: 14px;
  494. }
  495. .myTable .table-rank-badge {
  496. position: absolute;
  497. right: 10px;
  498. top: 12px;
  499. font-size: 14px;
  500. padding: 2px 14px;
  501. color: #e4eadb;
  502. }
  503. .myTable .badge-wrap .ivu-icon, .myTable .badge-wrap img {
  504. position: absolute;
  505. left: 7px;
  506. top: 12px;
  507. }
  508. .myTable .ivu-page-item {
  509. background: rgba(40,40,40,.5);
  510. }
  511. .myTable .ivu-page-item:hover {
  512. border-color: #e4eadb;
  513. }
  514. .myTable .ivu-page-item-active {
  515. background: #bfbfb9;
  516. }
  517. .myTable .ivu-page-item a {
  518. color: #f1f1f1;
  519. }
  520. .myTable .ivu-page-next, .myTable .ivu-page-prev {
  521. background: rgba(0,0,0,0);
  522. }
  523. .myTable .ivu-page-next a, .myTable .ivu-page-prev a {
  524. color: #e4eadb;
  525. }
  526. .myTable .ivu-page-next:hover, .myTable .ivu-page-prev:hover {
  527. border-color: #e4eadb;
  528. }
  529. .myTable .ivu-page-item-active, .myTable .ivu-page-item:hover a {
  530. border-color: #e4eadb;
  531. }
  532. .myTable .ivu-page-item-active a {
  533. color: #595959;
  534. }
  535. .myTable .ivu-table-fixed {
  536. /*padding-top:3px;*/
  537. background: #282828;
  538. }
  539. .myTable .ivu-table-fixed-right::before, .ivu-table-fixed::before {
  540. height: 0;
  541. }
  542. .table-subject-select {
  543. position: relative;
  544. display: flex;
  545. justify-content: space-between;
  546. padding-right: 5px;
  547. height: 40px;
  548. margin-bottom: 10px;
  549. }
  550. .table-subject-select .table-tips {
  551. font-size: 14px;
  552. color: #4cf8da;
  553. font-weight: bold;
  554. position: absolute;
  555. right: 65px;
  556. top: 10px;
  557. }
  558. .table-subject-select .ivu-select {
  559. margin: 5px 20px 15px 0;
  560. height: 30px;
  561. }
  562. .table-subject-select .ivu-select-single .ivu-select-selection {
  563. height: 30px;
  564. background: transparent;
  565. border: 1px solid #595959;
  566. box-shadow: none;
  567. color: #cecece;
  568. }
  569. .table-subject-select .ivu-select-single .ivu-select-arrow {
  570. /*top:76%;*/
  571. }
  572. .table-subject-select .ivu-select-single .ivu-select-placeholder {
  573. height: 30px;
  574. line-height: 30px;
  575. font-size: 16px;
  576. }
  577. .table-subject-select .table-export-btn {
  578. font-size: 14px;
  579. font-weight: bold;
  580. width:50px;
  581. position: absolute;
  582. right: 5px;
  583. top: 10px;
  584. cursor:pointer;
  585. }
  586. .myTable .table-entry-status {
  587. position: absolute;
  588. right: 20px;
  589. top: 15px;
  590. background: #209a31;
  591. width: 15px;
  592. height: 15px;
  593. display: flex;
  594. justify-content: center;
  595. align-items: center;
  596. padding: 10px;
  597. }
  598. .ivu-table-overflowX::-webkit-scrollbar {
  599. height: 12px !important;
  600. }
  601. .ivu-table-overflowX::-webkit-scrollbar-track {
  602. border-radius: 0px;
  603. display: none;
  604. }
  605. .ivu-table-overflowX::-webkit-scrollbar-thumb {
  606. border-radius: 0px;
  607. background: #949494;
  608. }
  609. .myTable .ivu-select-small.ivu-select-single .ivu-select-selection .ivu-select-selected-value {
  610. height: 27px;
  611. line-height: 27px;
  612. font-size: 12px;
  613. }
  614. .myTable .myTable-title{
  615. font-size: 16px;
  616. }
  617. </style>