PinCodeModal.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <!-- 遮罩层 -->
  3. <view
  4. class="pin-modal-overlay"
  5. v-if="visible"
  6. :class="{ 'fade-in': visible, 'fade-out': !visible }"
  7. >
  8. <!-- 弹框内容 -->
  9. <view class="pin-modal-container">
  10. <!-- 取消按钮 -->
  11. <view class="cancel-btn" @click="handleCancel">{{ t("取消") }}</view>
  12. <!-- 锁图标 -->
  13. <view class="lock-icon-wrapper">
  14. <view class="lock-icon-bg">
  15. <up-icon name="lock" color="#7B61FF" size="36"></up-icon>
  16. </view>
  17. </view>
  18. <!-- 标题 -->
  19. <view class="title">{{ t(title) }}</view>
  20. <!-- PIN 码输入指示器 -->
  21. <view class="pin-indicators">
  22. <view
  23. v-for="(dot, index) in 4"
  24. :key="index"
  25. class="pin-dot"
  26. :class="{ filled: pinCode.length > index }"
  27. ></view>
  28. </view>
  29. <!-- 数字键盘 -->
  30. <view class="number-pad">
  31. <view class="number-row" v-for="row in numberRows" :key="row.id">
  32. <view
  33. class="number-btn"
  34. v-for="num in row.numbers"
  35. :key="num"
  36. @click="handleNumberClick(num)"
  37. >
  38. <text class="number-text">{{ num }}</text>
  39. </view>
  40. </view>
  41. <view class="last-row">
  42. <view class="empty-cell"></view>
  43. <view class="number-btn zero-btn" @click="handleNumberClick(0)">
  44. <text class="number-text">0</text>
  45. </view>
  46. <view class="delete-btn" @click="handleDelete">
  47. <up-icon name="backspace" color="#FFFFFF" size="24"></up-icon>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script setup>
  55. import { ref, watch } from "vue";
  56. import { useTabbarStore } from "@/store";
  57. import { t } from "@/locale";
  58. const props = defineProps({
  59. title: {
  60. type: String,
  61. default: "输入PIN码进行验证",
  62. },
  63. visible: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. isHome: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. });
  72. const useTabbar = useTabbarStore();
  73. // 定义组件事件
  74. const emit = defineEmits(["close", "complete"]);
  75. // PIN 码数据
  76. const pinCode = ref("");
  77. // 数字键盘布局
  78. const numberRows = [
  79. { id: 1, numbers: [1, 2, 3] },
  80. { id: 2, numbers: [4, 5, 6] },
  81. { id: 3, numbers: [7, 8, 9] },
  82. ];
  83. watch(
  84. () => pinCode.value.length,
  85. (length) => {
  86. if (length === 4) {
  87. emit("complete", pinCode.value);
  88. pinCode.value = "";
  89. }
  90. }
  91. );
  92. const handleNumberClick = (number) => {
  93. if (pinCode.value.length < 4) {
  94. pinCode.value += number.toString();
  95. }
  96. };
  97. const handleDelete = () => {
  98. pinCode.value = pinCode.value.slice(0, -1);
  99. };
  100. const handleCancel = () => {
  101. pinCode.value = "";
  102. if (props.isHome) {
  103. uni.switchTab({ url: "/pages/index/index" });
  104. useTabbar.getPageCur("index");
  105. }
  106. // 触发关闭事件
  107. emit("close");
  108. };
  109. watch(
  110. () => props.visible,
  111. (newVal) => {
  112. if (!newVal) {
  113. pinCode.value = "";
  114. }
  115. }
  116. );
  117. </script>
  118. <style lang="scss" scoped>
  119. .fade-in {
  120. animation: fadeIn 0.3s ease-out forwards;
  121. }
  122. .fade-out {
  123. animation: fadeOut 0.3s ease-in forwards;
  124. }
  125. @keyframes fadeIn {
  126. from {
  127. opacity: 0;
  128. }
  129. to {
  130. opacity: 1;
  131. }
  132. }
  133. @keyframes fadeOut {
  134. from {
  135. opacity: 1;
  136. }
  137. to {
  138. opacity: 0;
  139. }
  140. }
  141. // 遮罩层
  142. .pin-modal-overlay {
  143. position: fixed;
  144. top: 0;
  145. left: 0;
  146. right: 0;
  147. bottom: 0;
  148. background-color: #7b61ff;
  149. z-index: 9999;
  150. display: flex;
  151. justify-content: center;
  152. align-items: center;
  153. }
  154. // 弹框容器
  155. .pin-modal-container {
  156. width: 100%;
  157. height: 100%;
  158. display: flex;
  159. flex-direction: column;
  160. padding: 60rpx 20rpx 20rpx;
  161. box-sizing: border-box;
  162. }
  163. // 取消按钮
  164. .cancel-btn {
  165. align-self: flex-start;
  166. color: #ffffff;
  167. font-size: 28rpx;
  168. margin: 30rpx 0 60rpx 30rpx;
  169. }
  170. // 锁图标
  171. .lock-icon-wrapper {
  172. display: flex;
  173. justify-content: center;
  174. margin-bottom: 60rpx;
  175. }
  176. .lock-icon-bg {
  177. width: 160rpx;
  178. height: 160rpx;
  179. border-radius: 50%;
  180. background-color: #ffffff;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. }
  185. // 标题
  186. .title {
  187. color: #ffffff;
  188. font-size: 36rpx;
  189. text-align: center;
  190. margin-bottom: 80rpx;
  191. }
  192. // PIN码指示器
  193. .pin-indicators {
  194. display: flex;
  195. justify-content: center;
  196. gap: 30rpx;
  197. margin-bottom: 120rpx;
  198. }
  199. .pin-dot {
  200. width: 24rpx;
  201. height: 24rpx;
  202. border-radius: 50%;
  203. border: 2rpx solid #ffffff;
  204. transition: all 0.2s ease;
  205. }
  206. .pin-dot.filled {
  207. background-color: #ffffff;
  208. transform: scale(1.2);
  209. }
  210. // 数字键盘
  211. .number-pad {
  212. flex: 1;
  213. display: flex;
  214. flex-direction: column;
  215. justify-content: center;
  216. align-items: center;
  217. gap: 30rpx;
  218. margin-top: auto;
  219. padding-bottom: 80rpx;
  220. }
  221. .number-row {
  222. display: flex;
  223. gap: 30rpx;
  224. }
  225. .number-btn {
  226. width: 140rpx;
  227. height: 140rpx;
  228. border-radius: 50%;
  229. border: 2rpx solid #ffffff;
  230. display: flex;
  231. justify-content: center;
  232. align-items: center;
  233. color: #ffffff;
  234. font-size: 48rpx;
  235. font-weight: 500;
  236. transition: all 0.1s ease;
  237. }
  238. .number-btn:active {
  239. background-color: rgba(255, 255, 255, 0.2);
  240. }
  241. .number-text {
  242. user-select: none;
  243. }
  244. // 最后一行
  245. .last-row {
  246. display: flex;
  247. gap: 30rpx;
  248. margin-top: 30rpx;
  249. }
  250. .empty-cell {
  251. width: 140rpx;
  252. }
  253. .zero-btn {
  254. width: 140rpx;
  255. height: 140rpx;
  256. }
  257. .delete-btn {
  258. width: 140rpx;
  259. height: 140rpx;
  260. border-radius: 50%;
  261. border: 2rpx solid #ffffff;
  262. display: flex;
  263. justify-content: center;
  264. align-items: center;
  265. transition: all 0.1s ease;
  266. }
  267. .delete-btn:active {
  268. background-color: rgba(255, 255, 255, 0.2);
  269. }
  270. </style>