input.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <cl-input></cl-input>
  6. </demo-item>
  7. <demo-item :label="t('数字输入')">
  8. <cl-input type="number"></cl-input>
  9. </demo-item>
  10. <demo-item :label="t('密码输入')">
  11. <cl-input password></cl-input>
  12. </demo-item>
  13. <demo-item :label="t('可清除')">
  14. <cl-input clearable :pt="{ className: 'mb-2' }"></cl-input>
  15. <demo-tips>设置 hold-keyboard 属性后,清除内容时输入框将保持聚焦状态</demo-tips>
  16. <cl-input clearable hold-keyboard></cl-input>
  17. </demo-item>
  18. <demo-item :label="t('左右插槽')">
  19. <cl-input
  20. :pt="{
  21. className: '!pr-1 mb-2'
  22. }"
  23. >
  24. <template #append>
  25. <cl-button
  26. type="primary"
  27. size="small"
  28. icon="send-plane-fill"
  29. :pt="{
  30. className: 'ml-2'
  31. }"
  32. @tap="toAlert"
  33. ></cl-button>
  34. </template>
  35. </cl-input>
  36. <cl-input
  37. :pt="{
  38. className: '!pl-1'
  39. }"
  40. >
  41. <template #prepend>
  42. <cl-button
  43. type="primary"
  44. size="small"
  45. icon="search-line"
  46. :pt="{
  47. className: 'mr-2'
  48. }"
  49. @tap="toAlert"
  50. ></cl-button>
  51. </template>
  52. </cl-input>
  53. </demo-item>
  54. <demo-item :label="t('保留精度')">
  55. <demo-tips>当 type 为 digit 时,可设置 precision 属性来保留精度</demo-tips>
  56. <cl-input type="digit" :precision="precision"></cl-input>
  57. <cl-list border :pt="{ className: 'mt-5' }">
  58. <cl-list-item :label="t('精度')">
  59. <cl-input-number v-model="precision"></cl-input-number>
  60. </cl-list-item>
  61. </cl-list>
  62. </demo-item>
  63. <demo-item :label="t('自定义')">
  64. <cl-input
  65. v-model="content"
  66. :border="isBorder"
  67. :suffix-icon="isRightIcon ? 'text' : ''"
  68. :prefix-icon="isLeftIcon ? 'search-line' : ''"
  69. :disabled="isDisabled"
  70. :pt="{
  71. className: parseClass({
  72. '!bg-sky-100': isColor,
  73. '!border-sky-700': isColor
  74. }),
  75. inner: {
  76. className: parseClass({
  77. '!text-sky-700': isColor
  78. })
  79. },
  80. prefixIcon: {
  81. className: parseClass({
  82. '!text-sky-700': isColor
  83. })
  84. }
  85. }"
  86. ></cl-input>
  87. <cl-list border :pt="{ className: 'mt-5' }">
  88. <cl-list-item :label="t('边框')">
  89. <cl-switch v-model="isBorder"></cl-switch>
  90. </cl-list-item>
  91. <cl-list-item :label="t('左图标')">
  92. <cl-switch v-model="isLeftIcon"></cl-switch>
  93. </cl-list-item>
  94. <cl-list-item :label="t('右图标')">
  95. <cl-switch v-model="isRightIcon"></cl-switch>
  96. </cl-list-item>
  97. <cl-list-item :label="t('禁用')">
  98. <cl-switch v-model="isDisabled"></cl-switch>
  99. </cl-list-item>
  100. <cl-list-item :label="t('其他颜色')">
  101. <cl-switch v-model="isColor"></cl-switch>
  102. </cl-list-item>
  103. </cl-list>
  104. </demo-item>
  105. </view>
  106. </cl-page>
  107. </template>
  108. <script lang="ts" setup>
  109. import { ref } from "vue";
  110. import DemoItem from "../components/item.uvue";
  111. import DemoTips from "../components/tips.uvue";
  112. import { parseClass } from "@/cool";
  113. import { useUi } from "@/uni_modules/cool-ui";
  114. import { t } from "@/locale";
  115. const ui = useUi();
  116. const content = ref("Cool Unix");
  117. const isBorder = ref(true);
  118. const isLeftIcon = ref(true);
  119. const isRightIcon = ref(false);
  120. const isDisabled = ref(false);
  121. const isColor = ref(false);
  122. const precision = ref<number>(2);
  123. function toAlert() {
  124. ui.showToast({
  125. message: "Hello"
  126. });
  127. }
  128. </script>