input.uvue 3.0 KB

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