index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div>
  3. <el-table
  4. ref="multipleTable"
  5. v-loading="dataLoading"
  6. stripe
  7. border
  8. :header-cell-style="{background:'#F5F7FA'}"
  9. :data="tableData"
  10. :selection-data="selectionData"
  11. :height="tableMaxHeight"
  12. @selection-change="selectionChange"
  13. @row-click="rowdata"
  14. @cell-mouse-enter="cellMouseEnter"
  15. >
  16. <el-table-column fixed :type="selectType" align="center" width="50" />
  17. <el-table-column v-if="showCover" label="Cover" :align="columns[0].align">
  18. <template slot-scope="scope">
  19. <img :src="src+scope.row.cover" width="40" height="40">
  20. </template>
  21. </el-table-column>
  22. <el-table-column v-if="showFace" label="Cover" :align="columns[0].align">
  23. <template slot-scope="scope">
  24. <img :src="src+scope.row.face" width="40" height="40">
  25. </template>
  26. </el-table-column>
  27. <template v-for="(column, index) in columns">
  28. <el-table-column
  29. :key="column.label"
  30. :prop="column.prop"
  31. :label="column.label"
  32. :align="column.align"
  33. :min-width="column.minWidth"
  34. :max-width="column.maxWidth"
  35. >
  36. <template slot-scope="scope">
  37. <template v-if="!column.render">
  38. <template v-if="typeof column.formatter == 'string'">
  39. <!--<span v-html="column.formatter(scope.row, column)" />-->
  40. <span v-html="formatter(scope.row, column)" />
  41. </template>
  42. <template v-else-if="typeof column.formatter == 'function'">
  43. <span v-html="column.formatter(scope.row, column)" />
  44. </template>
  45. <template v-else>
  46. <span>{{ scope.row[column.prop] }}</span>
  47. </template>
  48. </template>
  49. <template v-else>
  50. <expand-dom :column="column" :row="scope.row" :render="column.render" :index="index" />
  51. </template>
  52. </template>
  53. </el-table-column>
  54. </template>
  55. <el-table-column
  56. v-if="operates.list.length > 0 && (operates.list.filter(_x=>_x.show === true).length > 0 || operates.dropdown.filter(_x=>_x.show === true).length > 0) "
  57. ref="fixedColumn"
  58. label="Operate"
  59. align="center"
  60. :width="operates.width"
  61. :fixed="operates.fixed"
  62. >
  63. <template slot-scope="scope">
  64. <div class="operate-group">
  65. <template v-for="btn in operates.list">
  66. <el-button
  67. v-if="btn.show"
  68. :key="btn.id"
  69. :type="btn.type"
  70. size="mini"
  71. :icon="btn.icon"
  72. :disabled="btn.disabled"
  73. :plain="btn.plain"
  74. @click.native.prevent="btn.method(scope.row)"
  75. >{{ btn.label }}</el-button>
  76. </template>
  77. <div
  78. v-if="operates.dropdown != undefined && operates.dropdown.filter(_x=>_x.show === true).length > 0"
  79. style="display: inline-block;"
  80. >
  81. <el-dropdown style="font-size: 12px" size="mini">
  82. <el-button type="primary" size="mini">More</el-button>
  83. <el-dropdown-menu slot="dropdown">
  84. <el-dropdown-item
  85. v-for="dropbtn in operates.dropdown"
  86. :key="dropbtn.id"
  87. @click.native.prevent="dropbtn.method(scope.row)"
  88. >{{ dropbtn.label }}</el-dropdown-item>
  89. </el-dropdown-menu>
  90. </el-dropdown>
  91. </div>
  92. </div>
  93. </template>
  94. </el-table-column>
  95. <!--endregion-->
  96. </el-table>
  97. <div class="clearfix" style="height: 32px;margin: 10px 24px 0 10px;">
  98. <el-pagination
  99. class="pagination-site"
  100. background
  101. :class="floatType"
  102. :current-page="dataQuery.page"
  103. :page-sizes="page.pageSizes"
  104. :page-size="dataQuery.rows"
  105. layout="total, sizes, prev, pager, next, jumper"
  106. :total="page.dataTotal"
  107. @size-change="sizeChange"
  108. @current-change="currentChange"
  109. />
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. import { scrollTo } from '@/utils/scroll-to'
  115. export default {
  116. name: 'Sheet',
  117. props: {
  118. showFace: {
  119. type: Boolean,
  120. default: false
  121. },
  122. showCover: {
  123. type: Boolean,
  124. default: false
  125. },
  126. headerName: {
  127. type: String,
  128. default: () => 'searchForm'
  129. },
  130. callBack: {
  131. type: Function,
  132. default: () => {}
  133. },
  134. api: {
  135. type: Function,
  136. default: () => {}
  137. },
  138. columns: {
  139. type: Array,
  140. default: () => []
  141. },
  142. floatType: {
  143. type: String,
  144. default: () => ''
  145. },
  146. clearSelection: {
  147. type: String,
  148. default: () => ''
  149. },
  150. selectType: {
  151. type: String,
  152. default: () => ''
  153. },
  154. dataQuery: {
  155. type: Object,
  156. default: () => {
  157. return { page: 1, rows: 10 }
  158. }
  159. },
  160. page: {
  161. type: Object,
  162. default: () => {
  163. return {
  164. pageSizes: [5, 10, 20, 50, 100],
  165. dataTotal: 0
  166. }
  167. }
  168. },
  169. operates: {
  170. type: Object,
  171. default: () => {
  172. return {
  173. list: [],
  174. width: 150
  175. }
  176. }
  177. }
  178. },
  179. data: function() {
  180. return {
  181. src: window.Domain.static_url,
  182. tableData: [],
  183. dataLoading: false,
  184. optionsets: {},
  185. selectionData: []
  186. }
  187. },
  188. computed: {
  189. tableMaxHeight() {
  190. if (
  191. this.$store === undefined ||
  192. this.$store.getters.pageTableHeaderHeight === 0
  193. ) { return null }
  194. const height = 240 + 20 + this.$store.getters.pageTableHeaderHeight
  195. return 'calc(100vh - ' + height + 'px)'
  196. }
  197. },
  198. watch: {
  199. clearSelection(newdata, olddata) {
  200. this.$refs.multipleTable.clearSelection()
  201. }
  202. },
  203. created() {
  204. this.getData()
  205. },
  206. methods: {
  207. search(obj) {
  208. this.dataQuery.page = 1
  209. Object.assign(this.dataQuery, obj)
  210. this.getData()
  211. },
  212. cellMouseEnter(row, column) {
  213. this.$emit('cell-mouse-enter', row, column)
  214. },
  215. formatter(row, column) {
  216. if (this.optionsets[column.formatter] !== undefined) {
  217. let colValue
  218. typeof row[column.prop] === 'number'
  219. ? (colValue = row[column.prop].toString())
  220. : (colValue = row[column.prop])
  221. for (var i = 0; i < this.optionsets[column.formatter].length; i++) {
  222. if (this.optionsets[column.formatter][i].value === colValue) {
  223. return this.optionsets[column.formatter][i].text
  224. }
  225. }
  226. }
  227. return ''
  228. },
  229. rowdata(row, column, event) {
  230. if (column.label !== '操作') {
  231. this.$refs.multipleTable.toggleRowSelection(row)
  232. this.$emit('getRow', row)
  233. }
  234. },
  235. toggleRowSelection(row) {
  236. this.$refs.multipleTable.toggleRowSelection(row)
  237. },
  238. selectionChange(selection) {
  239. this.selectionData = selection
  240. this.$emit('update:selectionData', selection)
  241. },
  242. async getData() {
  243. const codes = []
  244. this.columns.forEach(item => {
  245. if (
  246. item.formatter !== undefined &&
  247. typeof item.formatter === 'string'
  248. ) {
  249. codes.push(item.formatter)
  250. }
  251. })
  252. for (var i = 0; i < codes.length; i++) {
  253. this.optionsets[codes[i]] = await this.$store.dispatch(
  254. 'optionset/formatterData',
  255. codes[i]
  256. )
  257. }
  258. this.dataLoading = true
  259. this.dataQuery
  260. this.api(this.dataQuery).then(res => {
  261. if (res.code === 200) {
  262. this.page.dataTotal = res.data.totalrecords
  263. this.tableData = res.data.data
  264. this.$emit('callBack', res.data.content)
  265. } else {
  266. this.page.dataTotal = 0
  267. this.tableData = []
  268. }
  269. this.dataLoading = false
  270. })
  271. },
  272. sizeChange(val) {
  273. scrollTo(0, 600)
  274. this.dataQuery.rows = val
  275. this.dataQuery.page = 1
  276. this.getData()
  277. },
  278. currentChange(val) {
  279. scrollTo(0, 600)
  280. this.dataQuery.page = val
  281. this.getData()
  282. }
  283. }
  284. }
  285. </script>
  286. <style>
  287. .right {
  288. float: right;
  289. }
  290. .left {
  291. float: left;
  292. }
  293. .el-table--border th.gutter:last-of-type {
  294. display: block !important;
  295. width: 17px !important;
  296. }
  297. </style>