index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import './by-table.scss'
  2. export default {
  3. data() {
  4. return {
  5. }
  6. },
  7. props: {
  8. //数据源
  9. data: {
  10. type: Array,
  11. default: () => []
  12. },
  13. // table配置信息
  14. columns: {
  15. type: Array,
  16. default: () => []
  17. },
  18. // 每页条数
  19. pageSize: {
  20. type: Number,
  21. default: 10
  22. },
  23. // 总条数
  24. total: {
  25. type: Number,
  26. default: 0
  27. },
  28. // 当前页码
  29. pageNum: {
  30. type: Number,
  31. default: 1
  32. },
  33. //搜索配置
  34. selectConfig: {
  35. type: Array,
  36. default: () => []
  37. },
  38. //请求参数
  39. req: {
  40. type: Object,
  41. default: () => {
  42. return {
  43. pageNum: 1,
  44. pageSize: 10,
  45. total:0,
  46. }
  47. }
  48. }
  49. },
  50. methods: {
  51. //操作按钮
  52. renderActionColumn(h, actions) {
  53. return <el-table-column
  54. label={actions.label || '操作'}
  55. width={actions.width || 200}
  56. align="right"
  57. {...{
  58. scopedSlots: {
  59. default: row => {
  60. //循环按钮,触发配置方法
  61. return actions.actions.map(item => {
  62. return <el-button
  63. type="text"
  64. disabled={item.disabled || false}
  65. onClick={
  66. () => item.fn ? item.fn(row) : console.log('请配置fn方法')
  67. }
  68. style={actions.style || 'color:#0084FF'}>
  69. {item.text}
  70. </el-button>
  71. })
  72. }
  73. }
  74. }}
  75. >
  76. </el-table-column>
  77. },
  78. //拼接table
  79. renderTable(h) {
  80. return (
  81. <elTable data={this.data}>
  82. {
  83. this.columns.map(item => {
  84. if (item.actions) {
  85. console.log(item.actions)
  86. return this.renderActionColumn(h, item)
  87. } else if (item.render) {
  88. return <el-table-column
  89. label={item.label || 'label没配置哦!'}
  90. width={item.width || null}
  91. {...{
  92. scopedSlots: {
  93. default: ({ row }) => {
  94. return item.render(h,row)
  95. }
  96. },
  97. }}
  98. >
  99. </el-table-column>
  100. }
  101. else {
  102. return <el-table-column
  103. prop={item.prop || null}
  104. label={item.label || 'label没配置哦!'}
  105. width={item.width || null}
  106. {...{
  107. scopedSlots: {
  108. default: ({ row }) => {
  109. return <div class={item.textType == 'blue' || item.textType == 'blueOrLine' ? 'cl-blue' : ''}>
  110. <span
  111. style={item.textType == 'blueOrLine' ? 'border-bottom:1px solid #0084FF;cursor: pointer;' : ''}
  112. onClick={
  113. () => item.fn ? item.fn(row) : console.log('请配置fn方法')
  114. }>
  115. {row[item.prop]}
  116. </span>
  117. </div>
  118. }
  119. },
  120. }}
  121. >
  122. </el-table-column>
  123. }
  124. })
  125. }
  126. </elTable>
  127. )
  128. },
  129. //render分页
  130. renderPage(h) {
  131. return <pagination v-show={this.total > 0} total={this.total} page={this.pageNum} limit={this.pageSize} />
  132. },
  133. renderDropDown(h,item) {
  134. const v = this
  135. return <div class='by-dropdown'>
  136. <div class='by-dropdown-title'>{item.label} <i class="el-icon-caret-bottom el-icon--right"></i></div>
  137. <ul class="by-dropdown-lists">
  138. <li onClick={() => {
  139. v.req[item.prop] = null
  140. item.label = item.labelCopy.label
  141. //item.label = item.labelCopy
  142. }}>全部</li>
  143. {
  144. item.data.map(i => {
  145. return <li key={i.value}
  146. onClick={
  147. () => {
  148. v.req[item.prop] = i.value
  149. item.label = i.label
  150. }
  151. }>{i.label}</li>
  152. })
  153. }
  154. </ul>
  155. </div>
  156. },
  157. //render搜索
  158. renderSearch(h) {
  159. if(!this.selectConfig) return <div></div>
  160. return <div class='by-search'>
  161. <div style='display: flex;'>
  162. {
  163. this.selectConfig.map( item => {
  164. return this.renderDropDown(h,item)
  165. })
  166. }
  167. <div class='more-text'>更多 <i class="el-icon-arrow-right el-icon--right"></i></div>
  168. </div>
  169. <div style='display: flex;'>
  170. <el-input
  171. placeholder="请选择日期"
  172. suffix-icon="el-icon-search"
  173. size="mini"
  174. value={this.req.keyword} onInput={$event => this.req.keyword = $event}>
  175. </el-input>
  176. <div class='more-icon'><i class="el-icon-arrow-right el-icon--right"></i></div>
  177. </div>
  178. </div>
  179. },
  180. renderSearchInit(){
  181. this.selectConfig.map(item => {
  182. item.labelCopy = JSON.parse(JSON.stringify(item))
  183. console.log(item.labelCopy)
  184. })
  185. },
  186. },
  187. created(){
  188. this.renderSearchInit()
  189. },
  190. name: 'by-table',
  191. render(h) {
  192. const search = this.renderSearch(h)
  193. const table = this.renderTable(h)
  194. const page = this.renderPage(h)
  195. return <div class='by-table'>
  196. {search}
  197. {table}
  198. {page}
  199. </div>
  200. },
  201. }