u-search.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-search",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$6],
  6. data() {
  7. return {
  8. keyword: "",
  9. showClear: false,
  10. // 是否显示右边的清除图标
  11. show: false,
  12. // 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件
  13. focused: this.focus
  14. // 绑定输入框的值
  15. // inputValue: this.value
  16. };
  17. },
  18. watch: {
  19. keyword(nVal) {
  20. this.$emit("update:modelValue", nVal);
  21. this.$emit("change", nVal);
  22. },
  23. modelValue: {
  24. immediate: true,
  25. handler(nVal) {
  26. this.keyword = nVal;
  27. }
  28. }
  29. },
  30. computed: {
  31. showActionBtn() {
  32. return !this.animation && this.showAction;
  33. }
  34. },
  35. emits: ["clear", "search", "custom", "focus", "blur", "click", "clickIcon", "update:modelValue", "change"],
  36. methods: {
  37. addStyle: common_vendor.addStyle,
  38. addUnit: common_vendor.addUnit,
  39. // 目前HX2.6.9 v-model双向绑定无效,故监听input事件获取输入框内容的变化
  40. inputChange(e) {
  41. this.keyword = e.detail.value;
  42. },
  43. // 清空输入
  44. // 也可以作为用户通过this.$refs形式调用清空输入框内容
  45. clear() {
  46. this.keyword = "";
  47. this.$nextTick(() => {
  48. this.$emit("clear");
  49. });
  50. },
  51. // 确定搜索
  52. search(e) {
  53. this.$emit("search", e.detail.value);
  54. try {
  55. common_vendor.index.hideKeyboard();
  56. } catch (e2) {
  57. }
  58. },
  59. // 点击右边自定义按钮的事件
  60. custom() {
  61. this.$emit("custom", this.keyword);
  62. try {
  63. common_vendor.index.hideKeyboard();
  64. } catch (e) {
  65. }
  66. },
  67. // 获取焦点
  68. getFocus() {
  69. this.focused = true;
  70. if (this.animation && this.showAction)
  71. this.show = true;
  72. this.$emit("focus", this.keyword);
  73. },
  74. // 失去焦点
  75. blur() {
  76. setTimeout(() => {
  77. this.focused = false;
  78. }, 100);
  79. this.show = false;
  80. this.$emit("blur", this.keyword);
  81. },
  82. // 点击搜索框,只有disabled=true时才发出事件,因为禁止了输入,意味着是想跳转真正的搜索页
  83. clickHandler() {
  84. if (this.disabled)
  85. this.$emit("click");
  86. },
  87. // 点击左边图标
  88. clickIcon(e) {
  89. this.$emit("clickIcon", this.keyword);
  90. try {
  91. common_vendor.index.hideKeyboard();
  92. } catch (e2) {
  93. }
  94. }
  95. }
  96. };
  97. if (!Array) {
  98. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  99. _easycom_u_icon2();
  100. }
  101. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  102. if (!Math) {
  103. _easycom_u_icon();
  104. }
  105. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  106. return common_vendor.e({
  107. a: _ctx.$slots.label || _ctx.label !== null
  108. }, _ctx.$slots.label || _ctx.label !== null ? {
  109. b: common_vendor.t(_ctx.label)
  110. } : {}, {
  111. c: common_vendor.o($options.clickIcon),
  112. d: common_vendor.p({
  113. size: _ctx.searchIconSize,
  114. name: _ctx.searchIcon,
  115. color: _ctx.searchIconColor ? _ctx.searchIconColor : _ctx.color
  116. }),
  117. e: common_vendor.o((...args) => $options.blur && $options.blur(...args)),
  118. f: $data.keyword,
  119. g: common_vendor.o((...args) => $options.search && $options.search(...args)),
  120. h: common_vendor.o((...args) => $options.inputChange && $options.inputChange(...args)),
  121. i: _ctx.disabled,
  122. j: common_vendor.o((...args) => $options.getFocus && $options.getFocus(...args)),
  123. k: _ctx.focus,
  124. l: _ctx.maxlength,
  125. m: _ctx.adjustPosition,
  126. n: _ctx.autoBlur,
  127. o: _ctx.placeholder,
  128. p: `color: ${_ctx.placeholderColor}`,
  129. q: common_vendor.s({
  130. textAlign: _ctx.inputAlign,
  131. color: _ctx.color,
  132. backgroundColor: _ctx.bgColor,
  133. height: $options.addUnit(_ctx.height)
  134. }),
  135. r: common_vendor.s(_ctx.inputStyle),
  136. s: $data.keyword && _ctx.clearabled && $data.focused
  137. }, $data.keyword && _ctx.clearabled && $data.focused ? {
  138. t: common_vendor.p({
  139. name: "close",
  140. size: "11",
  141. color: "#ffffff",
  142. customStyle: "line-height: 12px"
  143. }),
  144. v: common_vendor.o((...args) => $options.clear && $options.clear(...args))
  145. } : {}, {
  146. w: _ctx.bgColor,
  147. x: _ctx.shape == "round" ? "100px" : "4px",
  148. y: _ctx.borderColor,
  149. z: common_vendor.t(_ctx.actionText),
  150. A: common_vendor.s(_ctx.actionStyle),
  151. B: common_vendor.n(($options.showActionBtn || $data.show) && "u-search__action--active"),
  152. C: common_vendor.o((...args) => $options.custom && $options.custom(...args)),
  153. D: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args)),
  154. E: common_vendor.s({
  155. margin: _ctx.margin
  156. }),
  157. F: common_vendor.s($options.addStyle(_ctx.customStyle))
  158. });
  159. }
  160. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ed789780"], ["__file", "D:/project/学吧/learn_applet/node_modules/uview-plus/components/u-search/u-search.vue"]]);
  161. wx.createComponent(Component);