pay-pop.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="szjp">
  3. <!-- -->
  4. <view v-if="show">
  5. <view class="mask" @tap="Close"></view>
  6. <view
  7. class="box"
  8. style="z-index: 10000"
  9. :class="AlertObj[AlertClass][AlertClassUp]"
  10. >
  11. <view class="bottom">
  12. <view class="bg">
  13. <image
  14. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/bg.png"
  15. mode="widthFix"
  16. ></image>
  17. </view>
  18. <view class="tle">
  19. <view class="tle_lft">
  20. <image
  21. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/pwd.png"
  22. mode="widthFix"
  23. ></image>
  24. <view class="tle_1">{{ txt }}</view>
  25. <view class="tle_2">(长度{{ pwdlength }}位)</view>
  26. </view>
  27. <view class="tle_rgt" @tap.stop="is_vis = !is_vis">
  28. <!-- <block> -->
  29. <image
  30. v-show="is_vis"
  31. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/yj2.png"
  32. mode="widthFix"
  33. :width="20"
  34. :height="20"
  35. ></image>
  36. <image
  37. v-show="!is_vis"
  38. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/yj1.png"
  39. mode="widthFix"
  40. :width="20"
  41. :height="20"
  42. ></image>
  43. <!-- </block> -->
  44. <!-- <block v-show="!is_vis">
  45. <image src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/yj1.png" mode="widthFix"></image>
  46. </block> -->
  47. </view>
  48. </view>
  49. <view class="pwd_box" @click.stop>
  50. <view
  51. v-for="(v, k) in pwdlength"
  52. :key="k"
  53. class="pwd-text"
  54. :class="{ active: idx === k }"
  55. >
  56. {{ star_lis[k] === undefined ? "" : star_lis[k] }}
  57. <!-- {{is_vis?star_lis[k]:res_pwd[k]}} -->
  58. </view>
  59. </view>
  60. <view class="pwd_info">
  61. <!-- <view>可以放些提示信息</view> -->
  62. </view>
  63. <view class="solt" @click.stop>
  64. <view class="s_lft">
  65. <button
  66. v-for="(v, k) in 9"
  67. :key="k"
  68. class="s_li"
  69. type="primary"
  70. plain="true"
  71. @tap="click(k + 1)"
  72. >
  73. {{ k + 1 }}
  74. </button>
  75. <button
  76. class="s_li s_o"
  77. type="primary"
  78. plain="true"
  79. @tap="click(0)"
  80. >
  81. 0
  82. </button>
  83. <button
  84. class="s_li s_sq"
  85. type="primary"
  86. plain="true"
  87. @tap="Close"
  88. >
  89. <image
  90. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/sq.png"
  91. mode="widthFix"
  92. ></image>
  93. </button>
  94. </view>
  95. <view class="s_rgt">
  96. <view class="s_cx">
  97. <button class="s_li s_x" type="primary" plain="true" @tap="del">
  98. <image
  99. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/payPop/ht.png"
  100. mode="widthFix"
  101. ></image>
  102. </button>
  103. </view>
  104. <view class="s_qd">
  105. <button
  106. class="s_li s_s"
  107. type="primary"
  108. plain="true"
  109. @tap="submit"
  110. >
  111. 确定
  112. </button>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>
  121. <script setup>
  122. import { ref, computed } from "vue";
  123. // 定义组件属性
  124. const props = defineProps({
  125. txt: {
  126. type: String,
  127. default: "支付密码",
  128. },
  129. pwdlength: {
  130. type: [Number, String],
  131. default: 1,
  132. },
  133. });
  134. // 定义事件
  135. const emit = defineEmits(["pwd_e", "close"]);
  136. // 响应式数据
  137. const Repeat = ref(true);
  138. const show = ref(false);
  139. const AlertObj = ref([["a-bounceinB", "a-bounceoutB"]]);
  140. const AlertClass = ref(0);
  141. const AlertClassUp = ref(0);
  142. const res_pwd = ref([]);
  143. const fa_par = ref("");
  144. const is_vis = ref(true); // 密码是否可见
  145. // 计算属性
  146. const idx = computed(() => {
  147. return res_pwd.value.length;
  148. });
  149. const star_lis = computed(() => {
  150. if (is_vis.value) {
  151. return res_pwd.value;
  152. } else {
  153. const arr = [];
  154. res_pwd.value.forEach(() => {
  155. arr.push("*");
  156. });
  157. return arr;
  158. }
  159. });
  160. // 方法定义
  161. const click = (e) => {
  162. if (res_pwd.value.length <= props.pwdlength - 1) {
  163. res_pwd.value.push(e);
  164. // #ifdef APP-PLUS
  165. plus.device.vibrate(50); // 震动
  166. // #endif
  167. } else {
  168. toast(`最大长度${props.pwdlength}位`);
  169. }
  170. };
  171. const del = () => {
  172. res_pwd.value.pop();
  173. // #ifdef APP-PLUS
  174. plus.device.vibrate(50); // 震动
  175. // #endif
  176. };
  177. const submit = () => {
  178. // #ifdef APP-PLUS
  179. plus.device.vibrate(50); // 震动
  180. // #endif
  181. if (res_pwd.value.length === props.pwdlength) {
  182. const res = res_pwd.value.join("");
  183. emit("pwd_e", res, fa_par.value); // 调用父组件方法
  184. Close();
  185. } else {
  186. toast(`长度未满足`);
  187. }
  188. };
  189. // 打开
  190. const Open = (par) => {
  191. if (par) {
  192. console.log("父元素传参", par);
  193. fa_par.value = par; // 保存父元素传参
  194. }
  195. if (!Repeat.value) {
  196. return false;
  197. }
  198. res_pwd.value = [];
  199. Repeat.value = false;
  200. AlertClassUp.value = 0;
  201. show.value = true;
  202. setTimeout(() => {
  203. Repeat.value = true;
  204. }, 300);
  205. };
  206. // 关闭
  207. const Close = () => {
  208. if (!Repeat.value) {
  209. return false;
  210. }
  211. Repeat.value = false;
  212. AlertClassUp.value = 1;
  213. setTimeout(() => {
  214. show.value = false;
  215. Repeat.value = true;
  216. // 触发关闭事件
  217. emit("close");
  218. }, 300);
  219. };
  220. const toast = (val) => {
  221. uni.showToast({
  222. title: val,
  223. icon: "error",
  224. });
  225. };
  226. // 暴露方法给父组件调用
  227. defineExpose({
  228. Open,
  229. Close,
  230. submit,
  231. });
  232. </script>
  233. <style lang="scss" scoped>
  234. /*引入css文件*/
  235. @import "./szjp.scss";
  236. </style>