e-select.vue 4.0 KB

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