numberBox.nvue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="">
  3. <up-cell-group :border="true">
  4. <up-cell
  5. :border="true"
  6. title="基础用法"
  7. >
  8. <template v-slot:right-icon>
  9. <up-number-box
  10. v-model="value1"
  11. step="1"
  12. @change="change"
  13. >
  14. </up-number-box>
  15. </template>
  16. </up-cell>
  17. <up-cell
  18. :border="true"
  19. title="步长设置"
  20. >
  21. <template v-slot:right-icon>
  22. <up-number-box
  23. v-model="value2"
  24. :step="step1"
  25. @change="change"
  26. >
  27. </up-number-box>
  28. </template>
  29. </up-cell>
  30. <up-cell
  31. :border="true"
  32. title="限制输入范围"
  33. >
  34. <template v-slot:right-icon>
  35. <up-number-box
  36. v-model="value3"
  37. step="1"
  38. :min="min1"
  39. :max="max1"
  40. @change="change"
  41. >
  42. </up-number-box>
  43. </template>
  44. </up-cell>
  45. <up-cell
  46. :border="true"
  47. title="限制输入整数"
  48. >
  49. <template v-slot:right-icon>
  50. <up-number-box
  51. v-model="value4"
  52. step="1"
  53. integer
  54. @change="change"
  55. >
  56. </up-number-box>
  57. </template>
  58. </up-cell>
  59. <up-cell
  60. :border="true"
  61. title="禁用状态"
  62. >
  63. <template v-slot:right-icon>
  64. <up-number-box
  65. v-model="value5"
  66. step="1"
  67. :disabled="true"
  68. @change="change"
  69. >
  70. </up-number-box>
  71. </template>
  72. </up-cell>
  73. <up-cell
  74. :border="true"
  75. title="禁用输入框"
  76. >
  77. <template v-slot:right-icon>
  78. <up-number-box
  79. v-model="value6"
  80. step="1"
  81. :disabledInput="true"
  82. @change="change"
  83. >
  84. </up-number-box>
  85. </template>
  86. </up-cell>
  87. <up-cell
  88. :border="true"
  89. title="禁用长按"
  90. >
  91. <template v-slot:right-icon>
  92. <up-number-box
  93. v-model="value7"
  94. step="1"
  95. :longPress="false"
  96. @change="change"
  97. >
  98. </up-number-box>
  99. </template>
  100. </up-cell>
  101. <up-cell
  102. :border="true"
  103. title="固定小数位数"
  104. >
  105. <template v-slot:right-icon>
  106. <up-number-box
  107. v-model="value8"
  108. step="0.2"
  109. decimalLength="1"
  110. @change="change"
  111. >
  112. </up-number-box>
  113. </template>
  114. </up-cell>
  115. <up-cell
  116. :border="true"
  117. title="异步变更"
  118. >
  119. <template v-slot:right-icon>
  120. <up-number-box
  121. v-model="value9"
  122. step="1"
  123. :asyncChange="asyncChange"
  124. @change="myAsyncChange"
  125. >
  126. </up-number-box>
  127. </template>
  128. </up-cell>
  129. <up-cell
  130. :border="true"
  131. title="自定义大小颜色样式"
  132. >
  133. <template v-slot:right-icon>
  134. <up-number-box
  135. v-model="value10"
  136. step="1"
  137. :color="color"
  138. :buttonSize="buttonSize"
  139. :bgColor="bgColor"
  140. @change="change"
  141. iconStyle="color: #fff"
  142. >
  143. </up-number-box>
  144. </template>
  145. </up-cell>
  146. <up-cell
  147. :border="true"
  148. title="自定义(为0时减少按钮会消失)"
  149. >
  150. <template v-slot:right-icon>
  151. <up-number-box
  152. v-model="value11"
  153. step="1"
  154. :min="0"
  155. :showMinus="value11 > 0"
  156. >
  157. <template v-slot:minus>
  158. <view
  159. class="minus"
  160. >
  161. <up-icon
  162. name="minus"
  163. size="12"
  164. ></up-icon>
  165. </view>
  166. </template>
  167. <template v-slot:input>
  168. <text
  169. style="width: 50px;text-align: center;"
  170. class="input"
  171. >{{value11}}</text>
  172. </template>
  173. <template v-slot:plus>
  174. <view
  175. class="plus"
  176. >
  177. <up-icon
  178. name="plus"
  179. color="#FFFFFF"
  180. size="12"
  181. ></up-icon>
  182. </view>
  183. </template>
  184. </up-number-box>
  185. </template>
  186. </up-cell>
  187. </up-cell-group>
  188. </view>
  189. </template>
  190. <script>
  191. export default {
  192. data() {
  193. return {
  194. value1: 3,
  195. value2: 3,
  196. value3: 3,
  197. value4: 3,
  198. value5: 3,
  199. value6: 3,
  200. value7: 3,
  201. value8: 3.1,
  202. value9: 3,
  203. value10: 3,
  204. value11: 3,
  205. step1: 2,
  206. min1: 5,
  207. max1: 8,
  208. asyncChange: true,
  209. color: '#FFFFFF',
  210. buttonSize: 36,
  211. bgColor: '#2979ff'
  212. }
  213. },
  214. methods: {
  215. change(e) {
  216. console.log('change', e);
  217. },
  218. myAsyncChange(e) {
  219. this.asyncChange = false
  220. uni.showLoading({
  221. title: '正在加载'
  222. })
  223. setTimeout(() => {
  224. uni.hideLoading()
  225. this.value9 = e
  226. this.asyncChange = true
  227. }, 3000)
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. .minus {
  234. width: 22px;
  235. height: 22px;
  236. border-width: 1px;
  237. border-color: #E6E6E6;
  238. border-top-left-radius: 100px;
  239. border-top-right-radius: 100px;
  240. border-bottom-left-radius: 100px;
  241. border-bottom-right-radius: 100px;
  242. @include flex;
  243. justify-content: center;
  244. align-items: center;
  245. }
  246. .input {
  247. padding: 0 10px;
  248. }
  249. .plus {
  250. width: 22px;
  251. height: 22px;
  252. background-color: #FF0000;
  253. border-radius: 50%;
  254. /* #ifndef APP-NVUE */
  255. display: flex;
  256. /* #endif */
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. </style>