u-message-input.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-message-input",
  5. props: {
  6. // 最大输入长度
  7. maxlength: {
  8. type: [Number, String],
  9. default: 4
  10. },
  11. // 是否用圆点填充
  12. dotFill: {
  13. type: Boolean,
  14. default: false
  15. },
  16. // 显示模式,box-盒子模式,bottomLine-横线在底部模式,middleLine-横线在中部模式
  17. mode: {
  18. type: String,
  19. default: "box"
  20. },
  21. // 预置值
  22. modelValue: {
  23. type: [String, Number],
  24. default: ""
  25. },
  26. // 当前激活输入item,是否带有呼吸效果
  27. breathe: {
  28. type: Boolean,
  29. default: true
  30. },
  31. // 是否自动获取焦点
  32. focus: {
  33. type: Boolean,
  34. default: false
  35. },
  36. // 字体是否加粗
  37. bold: {
  38. type: Boolean,
  39. default: false
  40. },
  41. // 字体大小
  42. fontSize: {
  43. type: [String, Number],
  44. default: 60
  45. },
  46. // 激活样式
  47. activeColor: {
  48. type: String,
  49. default: "#2979ff"
  50. },
  51. // 未激活的样式
  52. inactiveColor: {
  53. type: String,
  54. default: "#606266"
  55. },
  56. // 输入框的大小,单位rpx,宽等于高
  57. width: {
  58. type: [Number, String],
  59. default: "80"
  60. },
  61. // 是否隐藏原生键盘,如果想用自定义键盘的话,需设置此参数为true
  62. disabledKeyboard: {
  63. type: Boolean,
  64. default: false
  65. }
  66. },
  67. watch: {
  68. // maxlength: {
  69. // // 此值设置为true,会在组件加载后无需maxlength变化就会执行一次本监听函数,无需再created生命周期中处理
  70. // immediate: true,
  71. // handler(val) {
  72. // this.maxlength = Number(val);
  73. // }
  74. // },
  75. modelValue: {
  76. immediate: true,
  77. handler(val) {
  78. val = String(val);
  79. this.valueModel = val.substring(0, this.maxlength);
  80. }
  81. }
  82. },
  83. data() {
  84. return {
  85. valueModel: ""
  86. };
  87. },
  88. emits: ["change", "finish"],
  89. computed: {
  90. // 是否显示呼吸灯效果
  91. animationClass() {
  92. return (index) => {
  93. if (this.breathe && this.charArr.length == index)
  94. return "u-breathe";
  95. else
  96. return "";
  97. };
  98. },
  99. // 用于显示字符
  100. charArr() {
  101. return this.valueModel.split("");
  102. },
  103. charArrLength() {
  104. return this.charArr.length;
  105. },
  106. // 根据长度,循环输入框的个数,因为头条小程序数值不能用于v-for
  107. loopCharArr() {
  108. return new Array(this.maxlength);
  109. }
  110. },
  111. methods: {
  112. getVal(e) {
  113. let {
  114. value
  115. } = e.detail;
  116. this.valueModel = value;
  117. if (String(value).length > this.maxlength)
  118. return;
  119. this.$emit("change", value);
  120. if (String(value).length == this.maxlength) {
  121. this.$emit("finish", value);
  122. }
  123. }
  124. }
  125. };
  126. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  127. return {
  128. a: $props.disabledKeyboard,
  129. b: $data.valueModel,
  130. c: $props.focus,
  131. d: $props.maxlength,
  132. e: common_vendor.o((...args) => $options.getVal && $options.getVal(...args)),
  133. f: common_vendor.f($options.loopCharArr, (item, index, i0) => {
  134. return common_vendor.e($props.mode !== "middleLine" ? {
  135. a: $options.charArrLength === index ? "block" : "none",
  136. b: $props.width * 0.5 + "rpx"
  137. } : {}, {
  138. c: $props.mode === "middleLine" && $options.charArrLength <= index
  139. }, $props.mode === "middleLine" && $options.charArrLength <= index ? {
  140. d: common_vendor.n($props.breathe && $options.charArrLength == index ? "u-breathe" : ""),
  141. e: common_vendor.n($options.charArrLength === index ? "u-middle-line-active" : ""),
  142. f: $props.bold ? "4px" : "2px",
  143. g: $options.charArrLength === index ? $props.activeColor : $props.inactiveColor
  144. } : {}, $props.mode === "bottomLine" ? {
  145. h: common_vendor.n($props.breathe && $options.charArrLength == index ? "u-breathe" : ""),
  146. i: common_vendor.n($options.charArrLength === index ? "u-bottom-line-active" : ""),
  147. j: $props.bold ? "4px" : "2px",
  148. k: $options.charArrLength === index ? $props.activeColor : $props.inactiveColor
  149. } : {}, !$props.dotFill ? {
  150. l: common_vendor.t($options.charArr[index] ? $options.charArr[index] : "")
  151. } : {
  152. m: common_vendor.t($options.charArr[index] ? "●" : "")
  153. }, {
  154. n: common_vendor.n($props.breathe && $options.charArrLength == index ? "u-breathe" : ""),
  155. o: common_vendor.n($options.charArrLength === index && $props.mode == "box" ? "u-box-active" : ""),
  156. p: $options.charArrLength === index && $props.mode == "box" ? $props.activeColor : $props.inactiveColor,
  157. q: index
  158. });
  159. }),
  160. g: $props.mode !== "middleLine",
  161. h: $props.mode === "bottomLine",
  162. i: !$props.dotFill,
  163. j: common_vendor.n($props.mode === "box" ? "u-box" : ""),
  164. k: $props.bold ? "bold" : "normal",
  165. l: $props.fontSize + "rpx",
  166. m: $props.width + "rpx",
  167. n: $props.width + "rpx",
  168. o: $props.inactiveColor
  169. };
  170. }
  171. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-30b8b720"], ["__file", "C:/Users/Administrator/Desktop/srcaaa/node_modules/uview-plus/components/u-message-input/u-message-input.vue"]]);
  172. wx.createComponent(Component);