u-number-keyboard.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-number-keyboard",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props$28],
  6. data() {
  7. return {
  8. backspace: "backspace",
  9. // 退格键内容
  10. dot: ".",
  11. // 点
  12. timer: null,
  13. // 长按多次删除的事件监听
  14. cardX: "X"
  15. // 身份证的X符号
  16. };
  17. },
  18. computed: {
  19. // 键盘需要显示的内容
  20. numList() {
  21. if (this.dotDisabled && this.mode == "number") {
  22. if (!this.random) {
  23. return [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  24. } else {
  25. return common_vendor.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
  26. }
  27. } else if (!this.dotDisabled && this.mode == "number") {
  28. if (!this.random) {
  29. return [1, 2, 3, 4, 5, 6, 7, 8, 9, this.dot, 0];
  30. } else {
  31. return common_vendor.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, this.dot, 0]);
  32. }
  33. } else if (this.mode == "card") {
  34. if (!this.random) {
  35. return [1, 2, 3, 4, 5, 6, 7, 8, 9, this.cardX, 0];
  36. } else {
  37. return common_vendor.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, this.cardX, 0]);
  38. }
  39. }
  40. },
  41. // 按键的样式,在非乱序&&数字键盘&&不显示点按钮时,index为9时,按键占位两个空间
  42. itemStyle() {
  43. return (index) => {
  44. let style = {};
  45. if (this.mode == "number" && this.dotDisabled && index == 9)
  46. style.width = "464rpx";
  47. return style;
  48. };
  49. },
  50. // 是否让按键显示灰色,只在非乱序&&数字键盘&&且允许点按键的时候
  51. btnBgGray() {
  52. return (index) => {
  53. if (!this.random && index == 9 && (this.mode != "number" || this.mode == "number" && !this.dotDisabled))
  54. return true;
  55. else
  56. return false;
  57. };
  58. }
  59. },
  60. created() {
  61. },
  62. emits: ["backspace", "change"],
  63. methods: {
  64. // 点击退格键
  65. backspaceClick() {
  66. this.$emit("backspace");
  67. clearInterval(this.timer);
  68. this.timer = null;
  69. this.timer = setInterval(() => {
  70. this.$emit("backspace");
  71. }, 250);
  72. },
  73. clearTimer() {
  74. clearInterval(this.timer);
  75. this.timer = null;
  76. },
  77. // 获取键盘显示的内容
  78. keyboardClick(val) {
  79. if (!this.dotDisabled && val != this.dot && val != this.cardX)
  80. val = Number(val);
  81. this.$emit("change", val);
  82. }
  83. }
  84. };
  85. if (!Array) {
  86. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  87. _easycom_u_icon2();
  88. }
  89. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  90. if (!Math) {
  91. _easycom_u_icon();
  92. }
  93. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  94. return {
  95. a: common_vendor.f($options.numList, (item, index, i0) => {
  96. return {
  97. a: common_vendor.t(item),
  98. b: common_vendor.s($options.itemStyle(index)),
  99. c: common_vendor.o(($event) => $options.keyboardClick(item), index),
  100. d: index
  101. };
  102. }),
  103. b: common_vendor.p({
  104. name: "backspace",
  105. color: "#303133",
  106. size: "28"
  107. }),
  108. c: common_vendor.o((...args) => $options.backspaceClick && $options.backspaceClick(...args)),
  109. d: common_vendor.o((...args) => $options.clearTimer && $options.clearTimer(...args)),
  110. e: common_vendor.o((...args) => _ctx.noop && _ctx.noop(...args))
  111. };
  112. }
  113. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-172328e1"], ["__file", "C:/Users/Administrator/Desktop/srcaaa/node_modules/uview-plus/components/u-number-keyboard/u-number-keyboard.vue"]]);
  114. wx.createComponent(Component);