index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="visit-box" v-if="show">
  3. <image class="visit-bg" src="./bg.png" mode="scaleToFill"></image>
  4. <!-- <view class="forget-pass" @tap="forgetpass">忘记密码</view> -->
  5. <image class="visit-close" src="./close1.png" @click="close"></image>
  6. <text class="visit-text">请输入密码</text>
  7. <view class="visit-list">
  8. <view class="visit-list-box" v-for="(item, index) in passselect" :key="index"
  9. :class="{ 'visit-list-box-last': index === passselect.length - 1 }" :style="{
  10. backgroundColor: index < selectIndex ? '#FFFFFF' : 'rgba(0,0,0,0)',
  11. }"></view>
  12. </view>
  13. <view class="visit-Nine-palaces">
  14. <view class="nine-row" v-for="(row, ri) in keyRows" :key="'row-' + ri"
  15. :class="{ 'nine-row-last': ri === keyRows.length - 1 }">
  16. <view class="visit-Nine-palaces-list" v-for="(item, ci) in row" :key="'cell-' + ri + '-' + ci"
  17. :class="{ 'visit-Nine-palaces-list-row-end': ci === 2 }" :style="{
  18. borderColor: styleClass(item.key),
  19. backgroundColor: keytype(item.key, ri * 3 + ci),
  20. }" @click="selectkey(item, ri * 3 + ci)">
  21. <text v-if="item.key !== 'backspace'" class="nine-key-text">{{
  22. item.key
  23. }}</text>
  24. <view class="qingchu-box" v-else>
  25. <image class="qingchu-img" src="./qingchu1.png" mode="aspectFit"></image>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import sys from "@/plugins/device/sys.plugins.js";
  34. export default {
  35. name: "visit-box",
  36. props: {
  37. show: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. selectColor: {
  42. type: String,
  43. default: "",
  44. },
  45. },
  46. data() {
  47. return {
  48. passselect: new Array(6),
  49. Keylist: [
  50. { key: 1 },
  51. { key: 2 },
  52. { key: 3 },
  53. { key: 4 },
  54. { key: 5 },
  55. { key: 6 },
  56. { key: 7 },
  57. { key: 8 },
  58. { key: 9 },
  59. { key: "#" },
  60. { key: 0 },
  61. { key: "backspace" },
  62. ],
  63. key_index: null,
  64. select: [], //选择的时候,
  65. selectIndex: null,
  66. KeylistIndex: null,
  67. };
  68. },
  69. computed: {
  70. /** 一行三个键,避免 nvue 下 flex-wrap 表现不一致 */
  71. keyRows() {
  72. const list = this.Keylist;
  73. const rows = [];
  74. for (let i = 0; i < list.length; i += 3) {
  75. rows.push(list.slice(i, i + 3));
  76. }
  77. return rows;
  78. },
  79. },
  80. methods: {
  81. styleClass(type) {
  82. // return typeof type !== "number" ? "transparent" : "#ffffff";
  83. return "#ffffff";
  84. },
  85. keytype(type, index) {
  86. if (this.key_index === index && typeof type === "number") {
  87. type = this.selectColor;
  88. } else {
  89. type = "rgba(0,0,0,0)";
  90. }
  91. return type;
  92. },
  93. //选择事件
  94. selectkey(even, index) {
  95. sys.playClickSound();
  96. this.key_index = index;
  97. if (even.key !== "backspace" && this.selectIndex < 6) {
  98. this.select.push(even.key);
  99. this.selectIndex++;
  100. this.$forceUpdate();
  101. } else if (even.key === "backspace") {
  102. //点击清除的时候
  103. if (this.selectIndex > 0) {
  104. this.selectIndex--;
  105. }
  106. this.select.splice(this.selectIndex, 1);
  107. this.$forceUpdate();
  108. }
  109. if (this.selectIndex === 6) {
  110. // 延迟提交,避免弹层立刻关闭截断最后一声嘟
  111. setTimeout(() => {
  112. this.$emit("change", this.select.join(""));
  113. }, 150);
  114. }
  115. },
  116. forgetpass() {
  117. this.$emit("forgetpass");
  118. },
  119. //关闭按钮事件
  120. close() {
  121. sys.playClickSound();
  122. this.$emit("close", false);
  123. },
  124. },
  125. watch: {
  126. select: {
  127. handler(newName, oldName) {
  128. if (newName.length === 6) {
  129. this.$emit("select", newName.join(""));
  130. }
  131. },
  132. immediate: true,
  133. },
  134. },
  135. };
  136. </script>
  137. <style scoped>
  138. .qingchu-box {
  139. position: absolute;
  140. left: 0;
  141. top: 0;
  142. right: 0;
  143. bottom: 0;
  144. flex-direction: row;
  145. justify-content: center;
  146. align-items: center;
  147. }
  148. .qingchu-img {
  149. width: 46px;
  150. height: 46px;
  151. }
  152. .visit-bg {
  153. position: absolute;
  154. left: 0;
  155. top: 0;
  156. right: 0;
  157. bottom: 0;
  158. }
  159. .visit-box {
  160. position: absolute;
  161. left: 0;
  162. top: 0;
  163. right: 0;
  164. bottom: 0;
  165. overflow: hidden;
  166. flex-direction: column;
  167. align-items: center;
  168. }
  169. /* 预留:忘记密码 */
  170. .visit-box .forget-pass {
  171. width: 72px;
  172. height: 28px;
  173. background-color: rgba(0, 0, 0, 0.3);
  174. border-radius: 14px 0px 0px 14px;
  175. font-size: 13px;
  176. font-weight: 400;
  177. line-height: 28px;
  178. color: #ffffff;
  179. opacity: 1;
  180. text-align: center;
  181. position: absolute;
  182. top: 10px;
  183. right: 0px;
  184. }
  185. .visit-close {
  186. position: absolute;
  187. top: 25rpx;
  188. right: 25rpx;
  189. width: 40px;
  190. height: 40px;
  191. }
  192. .visit-text {
  193. /* 不用百分比:直接用左右贴边铺满 */
  194. position: relative;
  195. left: 0px;
  196. right: 0px;
  197. font-size: 30px;
  198. font-weight: bold;
  199. color: #ffffff;
  200. text-align: center;
  201. margin-top: 110rpx;
  202. }
  203. .visit-list {
  204. width: 200px;
  205. height: 25px;
  206. flex-direction: row;
  207. flex-wrap: nowrap;
  208. margin-top: 18px;
  209. margin-bottom: 50px;
  210. justify-content: center;
  211. align-items: center;
  212. }
  213. .visit-list-box {
  214. width: 25px;
  215. height: 25px;
  216. border-radius: 15px;
  217. border-width: 2px;
  218. border-style: solid;
  219. border-color: #ffffff;
  220. margin-right: 10px;
  221. }
  222. .visit-list-box-last {
  223. margin-right: 0px;
  224. }
  225. .visit-Nine-palaces {
  226. width: 340px;
  227. flex-direction: column;
  228. }
  229. .nine-row {
  230. width: 340px;
  231. flex-direction: row;
  232. justify-content: flex-start;
  233. align-items: center;
  234. margin-bottom: 18px;
  235. }
  236. .nine-row-last {
  237. margin-bottom: 0px;
  238. }
  239. .visit-Nine-palaces-list {
  240. position: relative;
  241. width: 90px;
  242. height: 90px;
  243. border-radius: 45px;
  244. border-width: 3px;
  245. border-style: solid;
  246. border-color: #ffffff;
  247. opacity: 1;
  248. flex-direction: row;
  249. justify-content: center;
  250. align-items: center;
  251. margin-right: 35px;
  252. }
  253. .visit-Nine-palaces-list-row-end {
  254. margin-right: 0px;
  255. }
  256. .nine-key-text {
  257. font-size: 36px;
  258. font-weight: bold;
  259. line-height: 86px;
  260. color: #ffffff;
  261. text-align: center;
  262. }
  263. </style>