uni-search-bar.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const uni_modules_uniSearchBar_components_uniSearchBar_i18n_index = require("./i18n/index.js");
  4. const {
  5. t
  6. } = common_vendor.initVueI18n(uni_modules_uniSearchBar_components_uniSearchBar_i18n_index.messages);
  7. const _sfc_main = {
  8. name: "UniSearchBar",
  9. emits: ["input", "update:modelValue", "clear", "cancel", "confirm", "blur", "focus"],
  10. props: {
  11. placeholder: {
  12. type: String,
  13. default: ""
  14. },
  15. radius: {
  16. type: [Number, String],
  17. default: 5
  18. },
  19. clearButton: {
  20. type: String,
  21. default: "auto"
  22. },
  23. cancelButton: {
  24. type: String,
  25. default: "auto"
  26. },
  27. cancelText: {
  28. type: String,
  29. default: "取消"
  30. },
  31. bgColor: {
  32. type: String,
  33. default: "#F8F8F8"
  34. },
  35. maxlength: {
  36. type: [Number, String],
  37. default: 100
  38. },
  39. value: {
  40. type: [Number, String],
  41. default: ""
  42. },
  43. modelValue: {
  44. type: [Number, String],
  45. default: ""
  46. },
  47. focus: {
  48. type: Boolean,
  49. default: false
  50. },
  51. readonly: {
  52. type: Boolean,
  53. default: false
  54. }
  55. },
  56. data() {
  57. return {
  58. show: false,
  59. showSync: false,
  60. searchVal: ""
  61. };
  62. },
  63. computed: {
  64. cancelTextI18n() {
  65. return this.cancelText || t("uni-search-bar.cancel");
  66. },
  67. placeholderText() {
  68. return this.placeholder || t("uni-search-bar.placeholder");
  69. }
  70. },
  71. watch: {
  72. modelValue: {
  73. immediate: true,
  74. handler(newVal) {
  75. this.searchVal = newVal;
  76. if (newVal) {
  77. this.show = true;
  78. }
  79. }
  80. },
  81. focus: {
  82. immediate: true,
  83. handler(newVal) {
  84. if (newVal) {
  85. if (this.readonly)
  86. return;
  87. this.show = true;
  88. this.$nextTick(() => {
  89. this.showSync = true;
  90. });
  91. }
  92. }
  93. },
  94. searchVal(newVal, oldVal) {
  95. this.$emit("input", newVal);
  96. this.$emit("update:modelValue", newVal);
  97. }
  98. },
  99. methods: {
  100. searchClick() {
  101. if (this.readonly)
  102. return;
  103. if (this.show) {
  104. return;
  105. }
  106. this.show = true;
  107. this.$nextTick(() => {
  108. this.showSync = true;
  109. });
  110. },
  111. clear() {
  112. this.$emit("clear", {
  113. value: this.searchVal
  114. });
  115. this.searchVal = "";
  116. },
  117. cancel() {
  118. if (this.readonly)
  119. return;
  120. this.$emit("cancel", {
  121. value: this.searchVal
  122. });
  123. this.searchVal = "";
  124. this.show = false;
  125. this.showSync = false;
  126. common_vendor.index.hideKeyboard();
  127. },
  128. confirm() {
  129. common_vendor.index.hideKeyboard();
  130. this.$emit("confirm", {
  131. value: this.searchVal
  132. });
  133. },
  134. blur() {
  135. common_vendor.index.hideKeyboard();
  136. this.$emit("blur", {
  137. value: this.searchVal
  138. });
  139. },
  140. emitFocus(e) {
  141. this.$emit("focus", e.detail);
  142. }
  143. }
  144. };
  145. if (!Array) {
  146. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  147. _easycom_uni_icons2();
  148. }
  149. const _easycom_uni_icons = () => "../../../uni-icons/components/uni-icons/uni-icons.js";
  150. if (!Math) {
  151. _easycom_uni_icons();
  152. }
  153. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  154. return common_vendor.e({
  155. a: common_vendor.p({
  156. color: "#c0c4cc",
  157. size: "18",
  158. type: "search"
  159. }),
  160. b: $data.show || $data.searchVal
  161. }, $data.show || $data.searchVal ? {
  162. c: $data.showSync,
  163. d: $props.readonly,
  164. e: $options.placeholderText,
  165. f: $props.maxlength,
  166. g: common_vendor.o((...args) => $options.confirm && $options.confirm(...args)),
  167. h: common_vendor.o((...args) => $options.blur && $options.blur(...args)),
  168. i: common_vendor.o((...args) => $options.emitFocus && $options.emitFocus(...args)),
  169. j: $data.searchVal,
  170. k: common_vendor.o(($event) => $data.searchVal = $event.detail.value)
  171. } : {
  172. l: common_vendor.t($props.placeholder)
  173. }, {
  174. m: $data.show && ($props.clearButton === "always" || $props.clearButton === "auto" && $data.searchVal !== "") && !$props.readonly
  175. }, $data.show && ($props.clearButton === "always" || $props.clearButton === "auto" && $data.searchVal !== "") && !$props.readonly ? {
  176. n: common_vendor.p({
  177. color: "#c0c4cc",
  178. size: "20",
  179. type: "clear"
  180. }),
  181. o: common_vendor.o((...args) => $options.clear && $options.clear(...args))
  182. } : {}, {
  183. p: $props.radius + "px",
  184. q: $props.bgColor,
  185. r: common_vendor.o((...args) => $options.searchClick && $options.searchClick(...args)),
  186. s: $props.cancelButton === "always" || $data.show && $props.cancelButton === "auto"
  187. }, $props.cancelButton === "always" || $data.show && $props.cancelButton === "auto" ? {
  188. t: common_vendor.t($options.cancelTextI18n),
  189. v: common_vendor.o((...args) => $options.cancel && $options.cancel(...args))
  190. } : {});
  191. }
  192. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/uni_modules/uni-search-bar/components/uni-search-bar/uni-search-bar.vue"]]);
  193. wx.createComponent(Component);