index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <div class="container-component">
  3. <div ref="ibpsCrud" class="ibps-container-crud">
  4. <!-- 工具栏 -->
  5. <!-- 标题栏-->
  6. <div v-if="displayField && displayField!='N'&& displayField!='true'&& displayField!='Y'" class="jbd-title-cont">
  7. {{displayField}}
  8. </div>
  9. <div
  10. v-if="toolbars || $slots.header"
  11. ref="ibpsCrudHeader"
  12. class="ibps-container-crud__header"
  13. >
  14. <div
  15. v-if="toolbars"
  16. :class="['ibps-toolbar--' +$ELEMENT.size]"
  17. class="ibps-toolbar"
  18. >
  19. <div class="header"
  20. style="overflow:scroll;
  21. height: 100%;
  22. background-color: #F9FFFF;
  23. border-bottom: 0px;
  24. border-top: 0px;
  25. overflow: hidden"
  26. >
  27. <!-- 换了位置 -->
  28. <div
  29. v-show="$utils.isNotEmpty(searchForm) && showToolbar"
  30. ref="toolbarBox"
  31. class="toolbar-box clear"
  32. style="padding: 0px; border: 0px;"
  33. >
  34. <template v-if="$slots.searchForm" ref="searchForm">
  35. <slot :loading="loading" name="searchForm" />
  36. </template>
  37. <template v-else>
  38. <search-form
  39. v-if="searchForm"
  40. ref="searchForm"
  41. :forms="searchForm.forms||[]"
  42. size="mini"
  43. :fuzzy="searchForm.fuzzy"
  44. :inline="searchForm.inline"
  45. :label-width="searchForm.labelWidth"
  46. :item-width="searchForm.itemWidth"
  47. @search="handleActionEvent({key:'search'}, 'toolbar')"
  48. >
  49. <template v-for="item in searchFormSlot" :slot="item.slotName">
  50. <slot :name="item.slotName" :item="item" />
  51. </template>
  52. <template slot="jbd-buttons" v-if="searchFormSlot.length>0">
  53. <ibps-toolbar
  54. :actions="toolbars"
  55. :socpe="thatSocpe"
  56. @action-event="handleActionEvent"
  57. />
  58. </template>
  59. </search-form>
  60. </template>
  61. </div>
  62. <div class="buttons" v-if="$slots.searchForm">
  63. <ibps-toolbar
  64. :actions="toolbars"
  65. :socpe="thatSocpe"
  66. @action-event="handleActionEvent"
  67. />
  68. </div>
  69. <div class="buttons" v-else-if="searchFormSlot.length<1">
  70. <ibps-toolbar
  71. :actions="toolbars"
  72. :socpe="thatSocpe"
  73. @action-event="handleActionEvent"
  74. />
  75. </div>
  76. </div>
  77. <!-- 下拉隐藏-->
  78. <!-- <div class="tools">
  79. <slot name="rightTools" />
  80. <el-button v-if="displayField" icon="ibps-icon-cog" class="ibps-crud__display-field" :underline="false" @click="displayFieldVisible=true">{{ $t('components.crud.displayField') }}</el-button>
  81. <el-tooltip
  82. v-if="$utils.isNotEmpty(searchForm)"
  83. :content="showToolbar?$t('components.crud.collapse'):$t('components.crud.expand')"
  84. >
  85. <a class="expand" @click="handleCollapseExpandToolbar">
  86. <i :class="showToolbar?'el-icon-caret-top':'el-icon-caret-bottom'" />
  87. </a>
  88. </el-tooltip>
  89. </div> -->
  90. <slot name="header" />
  91. </div>
  92. </div>
  93. <!--列表--><!-- @header-dragend="handleHeaderDragend" 拖拽事件取消 -->
  94. <el-table
  95. ref="elTable"
  96. v-loading="loading"
  97. v-bind="options"
  98. :row-key="pkKey"
  99. :data="ibpsData"
  100. :height="tableHeight"
  101. :header-cell-style="{color:'#000','font-size':'14px',padding:'6px 6px'}"
  102. :stripe="false"
  103. :row-class-name="tableRowClassName"
  104. @current-change="handleCurrentChange"
  105. @select="handleSelect"
  106. @select-all="handleSelectAll"
  107. @selection-change="handleSelectionChange"
  108. @sort-change="handleSortChange"
  109. @cell-mouse-enter="handleCellMouseEnter"
  110. @cell-mouse-leave="handleCellMouseLeave"
  111. @cell-click="handleCellClick"
  112. @cell-dblclick="handleCellDblclick"
  113. @row-click="handleRowClick"
  114. @row-contextmenu="handleRowContextmenu"
  115. @row-dblclick="handleRowDblclick"
  116. @header-click="handleHeaderClick"
  117. @header-contextmenu="handleHeaderContextmenu"
  118. >
  119. <template slot="empty">
  120. <slot v-if="$slots.empty" name="empty" />
  121. <ibps-empty v-else />
  122. </template>
  123. <!--选择列 多选-->
  124. <el-table-column
  125. v-if="(selectionRow || selectionRow === '') && selectionType === 'checkbox'"
  126. v-bind="typeof selectionRow === 'Object'?selectionRow:null"
  127. :label="handleAttribute(selectionRow.label, '')"
  128. :reserve-selection="selectionRow.reserveSelectione||false"
  129. type="selection"
  130. show-overflow-tooltip
  131. />
  132. <!--选择列 单选-->
  133. <el-table-column
  134. v-if="(selectionRow || selectionRow === '') && selectionType === 'radio'"
  135. :label="selectionRow.label||''"
  136. :width="selectionRow.width||55"
  137. show-overflow-tooltip
  138. >
  139. <template slot-scope="scope">
  140. <el-radio v-model="selectionRadio" :label="getPkValue(scope.row)"><span>&nbsp;</span></el-radio>
  141. </template>
  142. </el-table-column>
  143. <!-- 自定义表单名称-->
  144. <el-table-column :width="150"
  145. show-overflow-tooltip
  146. label="表单名称"
  147. v-if="formName">
  148. <template slot-scope="scope">
  149. {{formName}}
  150. </template>
  151. </el-table-column>
  152. <!--索引列-->
  153. <el-table-column
  154. v-if="indexRow || indexRow === ''"
  155. v-bind="typeof indexRow === 'Object'?indexRow:null"
  156. :label="handleAttribute(indexRow.label, $t('components.crud.index'))"
  157. :width="60"
  158. type="index"
  159. />
  160. <slot name="prepend-column" />
  161. <template v-for="(column, index) in tableColumns">
  162. <el-table-column
  163. v-if="showColumn(column)"
  164. :key="index"
  165. :prop="handleAttribute(column.prop, null)"
  166. :label="handleAttribute(column.label, '')"
  167. :width="handleAttribute(column.width,null)"
  168. v-bind="column"
  169. show-overflow-tooltip
  170. >
  171. <template slot="header">
  172. <slot :name="column.headerName" :column="column" />
  173. </template>
  174. <template slot-scope="scope">
  175. <!--时间格式-->
  176. <span v-if="column.dateFormat" class="ibps-table-column">
  177. {{ scope.row[column.prop] | dateFormat(column.dateFormat,column.origDateFormat) }}
  178. </span>
  179. <!--通用过滤器-->
  180. <span v-else-if="column.filter" class="ibps-table-column">
  181. {{ handleColumnFilter(column.filter,scope.row[column.prop]) }}as
  182. </span>
  183. <!-- 下拉组件-->
  184. <span v-else-if="column.options" class="ibps-table-column">
  185. <!--stringArray 字符串类型的数组,逗号分隔-->
  186. <template v-if="column.dataType==='stringArray'">
  187. <span
  188. v-for="(value,i) in handleColumnDataConvert(scope.row[column.prop],column.separator)"
  189. :key="i"
  190. >
  191. {{ handleColumnOptions('label',column.options,value,column) }}<template v-if="handleColumnDataConvert(scope.row[column.prop],column.separator).length-1 !==i">,</template>
  192. </span>
  193. </template>
  194. <!--stringArray 字符串类型的数组-->
  195. <template v-else-if="column.dataType==='objectList'">
  196. <span v-for="(value,j) in scope.row[column.prop]" :key="j">
  197. {{ value[column.tagLabel] }}
  198. </span>
  199. </template>
  200. <span v-else>{{ handleColumnOptions('label',column.options,scope.row[column.prop]) }}</span>
  201. </span>
  202. <!-- tags组件-->
  203. <span v-else-if="column.tags" class="ibps-table-column">
  204. <span v-if="$utils.isEmpty(scope.row[column.prop]) ">{{ column.defaultLabel||'' }}</span>
  205. <!--stringArray 字符串类型的数组-->
  206. <template v-else-if="column.dataType==='stringArray'">
  207. <el-tag
  208. v-for="(value,i) in handleColumnDataConvert(scope.row[column.prop],column.separator)"
  209. :key="i"
  210. :type="handleColumnOptions('type',column.tags,value,column)"
  211. >
  212. {{ handleColumnOptions('label',column.tags,value,column) }}
  213. </el-tag>
  214. </template>
  215. <!--stringArray 字符串类型的数组-->
  216. <template v-else-if="column.dataType==='objectList'">
  217. <el-tag v-for="(value,j) in scope.row[column.prop]" :key="j">
  218. {{ value[column.tagLabel] }}
  219. </el-tag>
  220. </template>
  221. <template v-else>
  222. <el-tag :type="handleColumnOptions('type',column.tags,scope.row[column.prop],column)">{{ handleColumnOptions('label',column.tags,scope.row[column.prop],column) }}</el-tag>
  223. </template>
  224. </span>
  225. <!-- link组件-->
  226. <span v-else-if="column.link" class="ibps-table-column">
  227. <el-link :type="column.type||'primary'" :underline="column.underline||false" @click="handleColumnLink(column,scope.row)">
  228. {{ scope.row[column.prop] |removeHtmlTag }}
  229. </el-link>
  230. </span>
  231. <!-- 自定义slot组件############################################-->
  232. <span v-else-if="column.slotName" class="ibps-table-column">
  233. <slot :name="column.slotName" :row="scope.row" :value="scope.row[column.prop]" :column="column" :$index="scope.$index" />
  234. </span>
  235. <!--自定义组件-->
  236. <render-custom-component
  237. v-else-if="column.component && column.component.name"
  238. v-model="scope.row[column.prop]"
  239. :component-name="column.component.name"
  240. />
  241. <!--渲染组件-->
  242. <render-component
  243. v-else-if="column.component && column.component.render"
  244. :render-function="column.component.render"
  245. :scope="scope"
  246. />
  247. <template v-else>
  248. {{ column.formatter ? column.formatter(scope.row, scope.column, _get(scope.row, column.prop), scope.$index) : _get(scope.row, column.prop) }}
  249. </template>
  250. </template>
  251. <!--子列 -->
  252. <template v-if="column.children">
  253. <el-table-column
  254. show-overflow-tooltip
  255. v-for="(column2, index2) in column.children"
  256. :key="index2"
  257. :label="handleAttribute(column2.title, '')"
  258. :prop="handleAttribute(column2.key, null)"
  259. v-bind="column2"
  260. >
  261. <template slot-scope="scope">
  262. <!--过滤器-->
  263. <span v-if="column2.filter">
  264. {{ handleColumnFilter(column2.filter,scope.row[column2.prop]) }}
  265. </span>
  266. <!-- 下拉组件-->
  267. <span v-else-if="column2.options" class="table-column-options">
  268. <span>{{ handleColumnOptions('label',column2.options,scope.row[column2.prop]) }}</span>
  269. </span>
  270. <!-- tags组件-->
  271. <span v-else-if="column2.tags" class="table-column-tags">
  272. <el-tag :type="handleTags('type',column2.tags,scope.row[column2.prop])">{{ handleTags('label',column2.tags,scope.row[column2.prop]) }}</el-tag>
  273. </span>
  274. <!-- link组件-->
  275. <span v-else-if="column2.link">
  276. <a href="javascript:void(0)" class="table-column-link" @click="handleColumnLink(column2,scope.row)">{{ scope.row[column2.prop] }}</a>
  277. </span>
  278. <span v-else-if="column2.slotName">
  279. <slot :name="column2.slotName" :row="scope.row" :$index="scope.$index" />
  280. </span>
  281. <!--自定义组件-->
  282. <render-custom-component
  283. v-else-if="column2.component && column2.component.name"
  284. v-model="scope.row[column2.prop]"
  285. :component-name="column2.component.name"
  286. />
  287. <!--渲染组件-->
  288. <render-component
  289. v-else-if="column2.component && column2.component.render"
  290. :render-function="column2.component.render"
  291. :scope="scope"
  292. />
  293. <span v-if="contorlLength">
  294. <el-tooltip class="item" effect="dark" :content="column.formatter ? column.formatter(scope.row, scope.column, _get(scope.row, column.prop), scope.$index) : _get(scope.row, column.prop)" placement="bottom">
  295. <span>
  296. {{ column2.formatter ? column2.formatter(scope.row, scope.column2, _get(scope.row, column2.prop), scope.$index) : _get(scope.row, column2.prop)| ellipsis }}
  297. </span>
  298. </el-tooltip>
  299. </span>
  300. <template v-else>{{ column2.formatter ? column2.formatter(scope.row, scope.column2, _get(scope.row, column2.prop), scope.$index) : _get(scope.row, column2.prop) }}</template>
  301. </template>
  302. </el-table-column>
  303. <!-- end 子列-->
  304. </template>
  305. </el-table-column>
  306. </template>
  307. <!--操作列begin-->
  308. <!-- $t('components.crud.manage') handleAttribute(rowHandle.width, rowHandleDefaultWidth) -->
  309. <el-table-column
  310. v-if="rowHandle"
  311. v-bind="rowHandle"
  312. :label=" handleAttribute(rowHandle.columnHeader,'操作') "
  313. :width="handleAttribute(rowHandle.width, rowHandleDefaultWidth) <80 ? '80' : this.rowHandle.actions.length !=0 && this.rowHandle.actions.length<3 ? 110 * this.rowHandle.actions.length : handleAttribute(rowHandle.width, rowHandleDefaultWidth)"
  314. :fixed="handleAttribute(rowHandle.fixed, 'right')"
  315. :align="handleAttribute(rowHandle.align, 'center')"
  316. >
  317. <template v-slot:default="scope">
  318. <slot name="selectCont" :row="scope.row" />
  319. <template v-if="hasRowHandleActions(scope.row)">
  320. <template v-if="rowHandle.effect ==='display'">
  321. <ibps-toolbar
  322. v-if="!rowHandleMoreActions || rowHandleMoreActions.length <=1"
  323. :actions="rowHandleActions"
  324. :socpe="thatSocpe"
  325. :data="scope.row"
  326. position="manage"
  327. type="link"
  328. @action-event="handleActionEvent"
  329. />
  330. <template v-if="rowHandleMoreActions && rowHandleMoreActions.length <=1">
  331. <div class="el-divider el-divider--vertical"/>
  332. <ibps-toolbar
  333. :actions="rowHandleMoreActions"
  334. :socpe="thatSocpe"
  335. :data="scope.row"
  336. position="manage"
  337. type="link"
  338. @action-event="handleActionEvent"
  339. />
  340. </template>
  341. <template v-if="rowHandleMoreActions && rowHandleMoreActions.length >1" >
  342. <el-dropdown>
  343. <i class="el-icon-caret-bottom el-dropdown-link" style="font-size:14px;">更多</i>
  344. <el-dropdown-menu slot="dropdown" class="ibps-table-dropdown-menu">
  345. <ibps-toolbar
  346. :actions="rowHandleMoreActions.concat(rowHandleActions)"
  347. :socpe="thatSocpe"
  348. :data="scope.row"
  349. position="manage"
  350. type="linkHide"
  351. @action-event="handleActionEvent"
  352. />
  353. </el-dropdown-menu>
  354. </el-dropdown>
  355. </template>
  356. </template>
  357. <!-- 下拉-->
  358. <template v-else>
  359. <el-dropdown>
  360. <i class="ibps-icon ibps-icon-chevron-circle-down" style="font-size:24px;" />
  361. <el-dropdown-menu slot="dropdown" class="ibps-table-dropdown-menu">
  362. <ibps-toolbar
  363. :actions="rowHandleActions"
  364. :socpe="thatSocpe"
  365. :data="scope.row"
  366. position="manage"
  367. @action-event="handleActionEvent"
  368. />
  369. </el-dropdown-menu>
  370. </el-dropdown>
  371. <span>&nbsp;</span>
  372. </template>
  373. </template>
  374. </template>
  375. </el-table-column>
  376. <!--操作列end-->
  377. </el-table>
  378. <!--分页 或底部 自定义底部-->
  379. <div
  380. v-if="isShowPagination"
  381. ref="ibpsCrudFooter"
  382. class="ibps-container-crud__footer"
  383. >
  384. <template v-if="$slots.footer">
  385. <slot name="footer" />
  386. </template>
  387. <el-pagination
  388. v-else
  389. :current-page="currentPage"
  390. :page-size="pageSize"
  391. :page-count="pagination[pageCountKey]"
  392. :total="pagination[totalKey]"
  393. v-bind="paginationOptions"
  394. @size-change="handlePaginationSizeChange"
  395. @current-change="handlePaginationCurrentChange"
  396. @prev-click="handlePaginationPrevClick"
  397. @next-click="handlePaginationNextClick"
  398. >
  399. <template>
  400. <span class="el-pagination__total">{{ pageInfo }}</span>
  401. </template>
  402. </el-pagination>
  403. </div>
  404. </div>
  405. <!--显示字段-->
  406. <display-field-dialog
  407. :visible="displayFieldVisible"
  408. :fields="columns"
  409. :data="displayFields"
  410. @callback="handleDisplayField"
  411. @close="visible => displayFieldVisible = visible"
  412. />
  413. </div>
  414. </template>
  415. <script>
  416. import base from './mixin/base'
  417. import handleRow from './mixin/handleRow'
  418. import data from './mixin/data'
  419. import search from './mixin/search'
  420. import column from './mixin/column'
  421. import pagination from './mixin/pagination'
  422. import displayField from './mixin/displayField'
  423. import utils from './mixin/utils'
  424. import RenderComponent from './components/render-component.vue'
  425. import RenderCustomComponent from './components/render-custom-component.vue'
  426. import SearchForm from './components/search-form'
  427. import DisplayFieldDialog from './components/display-field'
  428. export default {
  429. props:['contorlLength'],
  430. name: 'ibps-crud',
  431. filters: { //定义过滤器
  432. ellipsis(value) {
  433. if (!value) return ''
  434. if (value.length > 7) {
  435. return value.slice(0,7) + '..'
  436. }
  437. return value
  438. }
  439. },
  440. components: {
  441. RenderComponent,
  442. RenderCustomComponent,
  443. SearchForm,
  444. DisplayFieldDialog
  445. },
  446. mixins: [
  447. base,
  448. data,
  449. search,
  450. column,
  451. handleRow,
  452. pagination,
  453. displayField,
  454. utils
  455. ]
  456. }
  457. </script>
  458. <style >
  459. .el-table th{
  460. background-color: #A7D6F8 !important;
  461. font-size: 12px !important;
  462. color: #000000;
  463. border: 0px;
  464. }
  465. .jbd-title-cont{
  466. text-align: center;
  467. font-weight: bold;
  468. background-color: rgb(249, 255, 255);
  469. width: 100%;
  470. font-size: 18px;
  471. }
  472. .el-table .caret-wrapper{
  473. top: -5px;
  474. position: absolute;
  475. }
  476. .el-table td{
  477. padding: 4px 0 !important;
  478. color: #000000;
  479. font-size: 12px !important;
  480. }
  481. .el-table .warning-row {
  482. background: #D9EEFD;
  483. color: #000000;
  484. }
  485. .el-table .success-row {
  486. background: #F9FFFF;
  487. color: #000000;
  488. }
  489. </style>
  490. <style lang="less" scoped>
  491. /deep/ .el-tag--mini{
  492. height: 0px;
  493. padding: 0px;
  494. line-height: 15px;
  495. }
  496. /deep/ .el-tag{
  497. background-color: #ecf5ff;
  498. border-color: #d9ecff;
  499. height: 0px;
  500. padding: 0px;
  501. line-height: 15px;
  502. font-size: 12px;
  503. color: #409EFF;
  504. border-width: 1px;
  505. border-style: solid;
  506. border-radius: 4px;
  507. -webkit-box-sizing: border-box;
  508. box-sizing: border-box;
  509. // white-space: nowrap;
  510. white-space:break-spaces;
  511. }
  512. /deep/.cell{
  513. overflow: visible;
  514. }
  515. /deep/ .el-table .cell.el-tooltip {
  516. white-space:break-spaces;
  517. // min-width: 50px;
  518. }
  519. </style>