index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <uni-shadow-root class="weapp-lib-search-index"><view :class="(utils.bem('search', { withaction: showAction || useActionSlot }))+' custom-class'" :style="'background: '+(background)">
  3. <view :class="utils.bem('search__content', [shape])">
  4. <view class="van-search__label" v-if="label">{{ label }}</view>
  5. <slot v-else name="label"></slot>
  6. <van-field type="search" :left-icon="(!useLeftIconSlot ? leftIcon : '')" :right-icon="(!useRightIconSlot ? rightIcon : '')" :focus="focus" :error="error" :border="false" confirm-type="search" class="van-search__field field-class" :value="value" :disabled="disabled" :readonly="readonly" :clearable="clearable" :clear-trigger="clearTrigger" :clear-icon="clearIcon" :maxlength="maxlength" :input-align="inputAlign" input-class="input-class" :placeholder="placeholder" :placeholder-style="placeholderStyle" custom-style="padding: 5px 10px 5px 0; background-color: transparent;" @blur="onBlur" @focus="onFocus" @change="onChange" @confirm="onSearch" @clear="onClear" @click-input="onClickInput">
  7. <slot v-if="useLeftIconSlot" name="left-icon" slot="left-icon"></slot>
  8. <slot v-if="useRightIconSlot" name="right-icon" slot="right-icon"></slot>
  9. </van-field>
  10. </view>
  11. <view v-if="showAction || useActionSlot" class="van-search__action" hover-class="van-search__action--hover" hover-stay-time="70">
  12. <slot v-if="useActionSlot" name="action"></slot>
  13. <view v-else @click="onCancel" class="van-search__action-button cancel-class">{{ actionText }}</view>
  14. </view>
  15. </view></uni-shadow-root>
  16. </template>
  17. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  18. <script>
  19. import VanField from '../field/index.vue'
  20. global['__wxVueOptions'] = {components:{'van-field': VanField}}
  21. global['__wxRoute'] = 'weapp/lib/search/index'
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", { value: true });
  24. var component_1 = require("../common/component");
  25. var version_1 = require("../common/version");
  26. (0, component_1.VantComponent)({
  27. field: true,
  28. classes: ['field-class', 'input-class', 'cancel-class'],
  29. props: {
  30. value: {
  31. type: String,
  32. value: '',
  33. },
  34. label: String,
  35. focus: Boolean,
  36. error: Boolean,
  37. disabled: Boolean,
  38. readonly: Boolean,
  39. inputAlign: String,
  40. showAction: Boolean,
  41. useActionSlot: Boolean,
  42. useLeftIconSlot: Boolean,
  43. useRightIconSlot: Boolean,
  44. leftIcon: {
  45. type: String,
  46. value: 'search',
  47. },
  48. rightIcon: String,
  49. placeholder: String,
  50. placeholderStyle: String,
  51. actionText: {
  52. type: String,
  53. value: '取消',
  54. },
  55. background: {
  56. type: String,
  57. value: '#ffffff',
  58. },
  59. maxlength: {
  60. type: Number,
  61. value: -1,
  62. },
  63. shape: {
  64. type: String,
  65. value: 'square',
  66. },
  67. clearable: {
  68. type: Boolean,
  69. value: true,
  70. },
  71. clearTrigger: {
  72. type: String,
  73. value: 'focus',
  74. },
  75. clearIcon: {
  76. type: String,
  77. value: 'clear',
  78. },
  79. },
  80. methods: {
  81. onChange: function (event) {
  82. if ((0, version_1.canIUseModel)()) {
  83. this.setData({ value: event.detail });
  84. }
  85. this.$emit('change', event.detail);
  86. },
  87. onCancel: function () {
  88. var _this = this;
  89. /**
  90. * 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
  91. * https://github.com/youzan/vant-weapp/issues/1768
  92. */
  93. setTimeout(function () {
  94. if ((0, version_1.canIUseModel)()) {
  95. _this.setData({ value: '' });
  96. }
  97. _this.$emit('cancel');
  98. _this.$emit('change', '');
  99. }, 200);
  100. },
  101. onSearch: function (event) {
  102. this.$emit('search', event.detail);
  103. },
  104. onFocus: function (event) {
  105. this.$emit('focus', event.detail);
  106. },
  107. onBlur: function (event) {
  108. this.$emit('blur', event.detail);
  109. },
  110. onClear: function (event) {
  111. this.$emit('clear', event.detail);
  112. },
  113. onClickInput: function (event) {
  114. this.$emit('click-input', event.detail);
  115. },
  116. },
  117. });
  118. export default global['__wxComponents']['weapp/lib/search/index']
  119. </script>
  120. <style platform="mp-weixin">
  121. @import '../common/index.css';.van-search{align-items:center;box-sizing:border-box;display:flex;padding:var(--search-padding,10px 12px)}.van-search__content{background-color:var(--search-background-color,#f7f8fa);border-radius:2px;display:flex;flex:1;padding-left:var(--padding-sm,12px)}.van-search__content--round{border-radius:999px}.van-search__label{color:var(--search-label-color,#323233);font-size:var(--search-label-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-label-padding,0 5px)}.van-search__field{flex:1}.van-search__field__left-icon{color:var(--search-left-icon-color,#969799)}.van-search--withaction{padding-right:0}.van-search__action{color:var(--search-action-text-color,#323233);font-size:var(--search-action-font-size,14px);line-height:var(--search-input-height,34px)}.van-search__action--hover{background-color:#f2f3f5}.van-search__action-button{padding:var(--search-action-padding,0 8px)}
  122. </style>