input.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 为 number 时,可设置 precision 属性来保留精度</demo-tips>
  56. <cl-list-item :label="t('精度')">
  57. <cl-input-number v-model="precision"></cl-input-number>
  58. </cl-list-item>
  59. <cl-input type="number" :precision="precision"></cl-input>
  60. </demo-item>
  61. <demo-item :label="t('自定义')">
  62. <cl-input
  63. v-model="content"
  64. :border="isBorder"
  65. :suffix-icon="isRightIcon ? 'text' : ''"
  66. :prefix-icon="isLeftIcon ? 'search-line' : ''"
  67. :disabled="isDisabled"
  68. :pt="{
  69. className: parseClass({
  70. '!bg-sky-100': isColor,
  71. '!border-sky-700': isColor
  72. }),
  73. inner: {
  74. className: parseClass({
  75. '!text-sky-700': isColor
  76. })
  77. },
  78. prefixIcon: {
  79. className: parseClass({
  80. '!text-sky-700': isColor
  81. })
  82. }
  83. }"
  84. ></cl-input>
  85. <cl-list border :pt="{ className: 'mt-5' }">
  86. <cl-list-item :label="t('边框')">
  87. <cl-switch v-model="isBorder"></cl-switch>
  88. </cl-list-item>
  89. <cl-list-item :label="t('左图标')">
  90. <cl-switch v-model="isLeftIcon"></cl-switch>
  91. </cl-list-item>
  92. <cl-list-item :label="t('右图标')">
  93. <cl-switch v-model="isRightIcon"></cl-switch>
  94. </cl-list-item>
  95. <cl-list-item :label="t('禁用')">
  96. <cl-switch v-model="isDisabled"></cl-switch>
  97. </cl-list-item>
  98. <cl-list-item :label="t('其他颜色')">
  99. <cl-switch v-model="isColor"></cl-switch>
  100. </cl-list-item>
  101. </cl-list>
  102. </demo-item>
  103. </view>
  104. </cl-page>
  105. </template>
  106. <script lang="ts" setup>
  107. import { ref } from "vue";
  108. import DemoItem from "../components/item.uvue";
  109. import DemoTips from "../components/tips.uvue";
  110. import { parseClass } from "@/cool";
  111. import { useUi } from "@/uni_modules/cool-ui";
  112. import { t } from "@/locale";
  113. const ui = useUi();
  114. const content = ref("Cool Unix");
  115. const isBorder = ref(true);
  116. const isLeftIcon = ref(true);
  117. const isRightIcon = ref(false);
  118. const isDisabled = ref(false);
  119. const isColor = ref(false);
  120. const precision = ref<number>(2);
  121. function toAlert() {
  122. ui.showToast({
  123. message: "Hello"
  124. });
  125. }
  126. </script>