e-select.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <e-select-built-in v-model="selectData" :options="options" :props="props" :placeholder="placeholder" :width="width"
  3. :minWidth="minWidth" :maxHeight="maxHeight" :emptyTips="emptyTips" :clearable="clearable" :disabled="disabled"
  4. :search="search" :animation="animation" :position="position" :pageSize="pageSize" :pageIndex="pageIndex"
  5. @update:pageIndex="updatePageIndex" @update:total="updateTotal" @change="changeSelect">
  6. <uni-pagination-built-in v-if="pageSize" show-icon="true" :total="total" :pageSize="pageSize"
  7. :current="pageIndex" @change="changePage"></uni-pagination-built-in>
  8. </e-select-built-in>
  9. </template>
  10. <script>
  11. import eSelectBuiltIn from './e-select-built-in.vue';
  12. import uniPaginationBuiltIn from './uni-pagination-built-in/uni-pagination-built-in.vue';
  13. export default {
  14. components: {
  15. eSelectBuiltIn,
  16. uniPaginationBuiltIn,
  17. },
  18. props: {
  19. // vue2 v-model传值方式
  20. value: {
  21. type: [String, Number],
  22. default: '',
  23. },
  24. // vue3 v-model传值方式
  25. modelValue: {
  26. type: [String, Number],
  27. default: '',
  28. },
  29. // 选项列表
  30. options: {
  31. type: Array,
  32. default () {
  33. return [];
  34. },
  35. },
  36. // 选项列表自定义数据格式
  37. props: {
  38. type: Object,
  39. default: () => {
  40. return {
  41. text: 'text',
  42. value: 'value',
  43. disabled: 'disabled',
  44. };
  45. },
  46. },
  47. // 占位文本
  48. placeholder: {
  49. type: String,
  50. default: '请选择',
  51. },
  52. // 输入框宽度
  53. width: {
  54. type: String,
  55. default: '100%',
  56. },
  57. // 输入框最小宽度
  58. minWidth: {
  59. type: String,
  60. default: '120rpx',
  61. },
  62. // 选项列表悬浮框最大高度
  63. maxHeight: {
  64. type: String,
  65. default: '160px',
  66. },
  67. // 选项列表空值占位空值占位
  68. emptyTips: {
  69. type: String,
  70. default: '暂无选项',
  71. },
  72. // 是否可清空
  73. clearable: {
  74. type: Boolean,
  75. default: false,
  76. },
  77. // 是否禁用
  78. disabled: {
  79. type: Boolean,
  80. default: false,
  81. },
  82. // 是否开启搜索
  83. search: {
  84. type: Boolean,
  85. default: true,
  86. },
  87. // 是否开启搜索的滚动动画
  88. animation: {
  89. type: Boolean,
  90. default: true,
  91. },
  92. // 悬浮框位置top/bottom
  93. position: {
  94. type: String,
  95. default: 'bottom',
  96. },
  97. // 分页每页条数
  98. pageSize: {
  99. type: Number,
  100. default: 0,
  101. },
  102. },
  103. data() {
  104. return {
  105. // 前端分页,总数就是下拉列表总数,不应由用户来控制,放在组件内部
  106. total: 0,
  107. // 前端分页,当前分页不应由用户来控制,放在组件内部
  108. pageIndex: 1,
  109. selectData: '',
  110. };
  111. },
  112. watch: {
  113. options: {
  114. handler(val) {
  115. this.total = val.length;
  116. },
  117. immediate: true,
  118. deep: true,
  119. },
  120. modelValue: {
  121. handler() {
  122. this.initData();
  123. },
  124. immediate: true,
  125. },
  126. value: {
  127. handler() {
  128. this.initData();
  129. },
  130. immediate: true,
  131. },
  132. selectData: {
  133. handler(val) {
  134. this.$emit('input', val);
  135. this.$emit('update:modelValue', val);
  136. },
  137. },
  138. },
  139. methods: {
  140. /** 处理数据,此函数用于兼容vue2 vue3 */
  141. initData() {
  142. // vue2
  143. if (this.value || this.value === 0) {
  144. this.selectData = this.value;
  145. }
  146. // vue3
  147. else if (this.modelValue || this.modelValue === 0) {
  148. this.selectData = this.modelValue;
  149. }
  150. },
  151. updatePageIndex(pageIndex) {
  152. this.pageIndex = pageIndex;
  153. },
  154. updateTotal(total) {
  155. this.total = total;
  156. },
  157. changePage(data) {
  158. this.pageIndex = data.current;
  159. this.$emit('changePage', data);
  160. },
  161. changeSelect(data) {
  162. // del by wzx 不屏蔽会重复发送 change事件
  163. // this.$emit('change', data);
  164. },
  165. },
  166. };
  167. </script>