list-frame.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div id="list-frame" :style="`height:${heights}px;overflow:auto`">
  3. <!-- <el-scrollbar style="height:100%"> -->
  4. <el-card style="background-image: linear-gradient(315deg, #CCF, transparent);border-radius: 60px;" shadow="hover">
  5. <el-row>
  6. <el-col :span="21" class="title">
  7. <span v-if="returns">
  8. <el-button size="mini" plan circle @click="toReturns" style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
  9. <span class="el-icon-arrow-left" style="zoom:1.5;font-weight:700"></span>
  10. </el-button>
  11. </span>
  12. <slot name="title">
  13. {{ title }}
  14. </slot>
  15. </el-col>
  16. <el-col :span="3" class="title" v-if="needAdd">
  17. <el-button type="primary" icon="el-icon-plus" size="mini" @click="$emit('add')">新增</el-button>
  18. </el-col>
  19. </el-row>
  20. <slot name="filter" v-if="needFilter">
  21. <el-form :inline="true" style="padding:0.9rem 1.5rem ;">
  22. <el-form-item v-for="(item, index) in filter" :key="index" :label="item.label">
  23. <template v-if="item.type === `select`">
  24. <el-select v-model="searchInfo[`${item.model}`]" size="mini" clearable>
  25. <!-- <el-option v-for="(select, sIndex) in item.list" :key="sIndex" :label="select.label" :value="select.value"></el-option> -->
  26. <slot name="options" v-bind="{ item }"></slot>
  27. </el-select>
  28. </template>
  29. <template v-else>
  30. <el-input v-model="searchInfo[`${item.model}`]" size="mini" :placeholder="getField('place', item)" clearable></el-input>
  31. </template>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" size="mini" @click="toQuery()">查询</el-button>
  35. </el-form-item>
  36. </el-form>
  37. </slot>
  38. <div style="padding:0.9rem 1.25rem ;">
  39. <slot> </slot>
  40. </div>
  41. <el-row type="flex" align="middle" justify="end" v-if="needPag">
  42. <el-col :span="24" style="text-align:right;">
  43. <el-pagination
  44. background
  45. layout="total, prev, pager, next"
  46. :total="total"
  47. :page-size="limit"
  48. :current-page.sync="currentPage"
  49. @current-change="changePage"
  50. >
  51. </el-pagination>
  52. </el-col>
  53. </el-row>
  54. </el-card>
  55. <!-- </el-scrollbar> -->
  56. </div>
  57. </template>
  58. <script>
  59. import _ from 'lodash';
  60. export default {
  61. name: 'list-frame',
  62. props: {
  63. title: { type: String },
  64. filter: { type: Array, default: () => [] },
  65. total: { type: Number, default: 0 },
  66. needPag: { type: Boolean, default: true },
  67. returns: { type: null, default: null },
  68. needFilter: { type: Boolean, default: true },
  69. needAdd: { type: Boolean, default: true },
  70. },
  71. components: {},
  72. data: () => ({
  73. limit: _.get(this, `$limit`, undefined) !== undefined ? this.$limit : process.env.VUE_APP_LIMIT * 1,
  74. currentPage: 1,
  75. searchInfo: {},
  76. heights: document.documentElement.clientHeight - 80,
  77. }),
  78. created() {},
  79. computed: {},
  80. mounted() {
  81. const that = this;
  82. window.onresize = () => {
  83. return (() => {
  84. window.fullHeight = document.documentElement.clientHeight - 80;
  85. that.heights = window.fullHeight;
  86. })();
  87. };
  88. },
  89. methods: {
  90. changePage(page) {
  91. this.$emit('query', { skip: (page - 1) * this.limit, limit: this.limit, ...this.searchInfo });
  92. },
  93. toQuery() {
  94. let keys = Object.keys(this.searchInfo);
  95. for (const key of keys) if (this.searchInfo[key] === '' || !this.searchInfo[key]) delete this.searchInfo[key];
  96. this.$emit('query', this.searchInfo);
  97. },
  98. toReturns() {
  99. if (_.isString(this.returns)) this.$router.push({ path: this.returns });
  100. else if (_.isFunction(this.returns)) {
  101. let fun = _.get(this, `returns`);
  102. fun();
  103. }
  104. },
  105. // 文字描述
  106. getField(item, data) {
  107. let res = _.get(data, item, null);
  108. if (item === 'type') res = res === null ? `text` : res;
  109. if (item === 'place') res = res === null ? `请输入${data.label}` : res;
  110. if (item === 'required') res = res === null ? false : res;
  111. if (item === `error`) res = res === null ? `${data.label}错误` : res;
  112. return res;
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="less" scoped>
  118. .title {
  119. font-size: 1rem;
  120. font-weight: 700;
  121. padding: 0.8rem;
  122. }
  123. /deep/.el-scrollbar__wrap {
  124. overflow-x: auto;
  125. }
  126. </style>