u-search.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 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. // 目前HX2.6.9 v-model双向绑定无效,故监听input事件获取输入框内容的变化
  38. inputChange(e) {
  39. this.keyword = e.detail.value;
  40. },
  41. // 清空输入
  42. // 也可以作为用户通过this.$refs形式调用清空输入框内容
  43. clear() {
  44. this.keyword = "";
  45. this.$nextTick(() => {
  46. this.$emit("clear");
  47. });
  48. },
  49. // 确定搜索
  50. search(e) {
  51. this.$emit("search", e.detail.value);
  52. try {
  53. common_vendor.index.hideKeyboard();
  54. } catch (e2) {
  55. }
  56. },
  57. // 点击右边自定义按钮的事件
  58. custom() {
  59. this.$emit("custom", this.keyword);
  60. try {
  61. common_vendor.index.hideKeyboard();
  62. } catch (e) {
  63. }
  64. },
  65. // 获取焦点
  66. getFocus() {
  67. this.focused = true;
  68. if (this.animation && this.showAction)
  69. this.show = true;
  70. this.$emit("focus", this.keyword);
  71. },
  72. // 失去焦点
  73. blur() {
  74. setTimeout(() => {
  75. this.focused = false;
  76. }, 100);
  77. this.show = false;
  78. this.$emit("blur", this.keyword);
  79. },
  80. // 点击搜索框,只有disabled=true时才发出事件,因为禁止了输入,意味着是想跳转真正的搜索页
  81. clickHandler() {
  82. if (this.disabled)
  83. this.$emit("click");
  84. },
  85. // 点击左边图标
  86. clickIcon(e) {
  87. this.$emit("clickIcon", this.keyword);
  88. try {
  89. common_vendor.index.hideKeyboard();
  90. } catch (e2) {
  91. }
  92. }
  93. }
  94. };
  95. if (!Array) {
  96. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  97. _easycom_u_icon2();
  98. }
  99. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  100. if (!Math) {
  101. _easycom_u_icon();
  102. }
  103. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  104. return common_vendor.e({
  105. a: _ctx.$slots.label || _ctx.label !== null
  106. }, _ctx.$slots.label || _ctx.label !== null ? {
  107. b: common_vendor.t(_ctx.label)
  108. } : {}, {
  109. c: common_vendor.o($options.clickIcon),
  110. d: common_vendor.p({
  111. size: _ctx.searchIconSize,
  112. name: _ctx.searchIcon,
  113. color: _ctx.searchIconColor ? _ctx.searchIconColor : _ctx.color
  114. }),
  115. e: common_vendor.o((...args) => $options.blur && $options.blur(...args)),
  116. f: $data.keyword,
  117. g: common_vendor.o((...args) => $options.search && $options.search(...args)),
  118. h: common_vendor.o((...args) => $options.inputChange && $options.inputChange(...args)),
  119. i: _ctx.disabled,
  120. j: common_vendor.o((...args) => $options.getFocus && $options.getFocus(...args)),
  121. k: _ctx.focus,
  122. l: _ctx.maxlength,
  123. m: _ctx.placeholder,
  124. n: `color: ${_ctx.placeholderColor}`,
  125. o: common_vendor.s({
  126. textAlign: _ctx.inputAlign,
  127. color: _ctx.color,
  128. backgroundColor: _ctx.bgColor,
  129. height: _ctx.$u.addUnit(_ctx.height)
  130. }),
  131. p: common_vendor.s(_ctx.inputStyle),
  132. q: $data.keyword && _ctx.clearabled && $data.focused
  133. }, $data.keyword && _ctx.clearabled && $data.focused ? {
  134. r: common_vendor.p({
  135. name: "close",
  136. size: "11",
  137. color: "#ffffff",
  138. customStyle: "line-height: 12px"
  139. }),
  140. s: common_vendor.o((...args) => $options.clear && $options.clear(...args))
  141. } : {}, {
  142. t: _ctx.bgColor,
  143. v: _ctx.shape == "round" ? "100px" : "4px",
  144. w: _ctx.borderColor,
  145. x: common_vendor.t(_ctx.actionText),
  146. y: common_vendor.s(_ctx.actionStyle),
  147. z: common_vendor.n(($options.showActionBtn || $data.show) && "u-search__action--active"),
  148. A: common_vendor.o((...args) => $options.custom && $options.custom(...args)),
  149. B: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args)),
  150. C: common_vendor.s({
  151. margin: _ctx.margin
  152. }),
  153. D: common_vendor.s(_ctx.$u.addStyle(_ctx.customStyle))
  154. });
  155. }
  156. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ed789780"], ["__file", "D:/project/赋强公证/notarization_applet/node_modules/uview-plus/components/u-search/u-search.vue"]]);
  157. wx.createComponent(Component);