verification.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <template>
  2. <view>
  3. <view v-if="!hid" class="flex-row-center" :style="{ top: scHight }" style="width: 750rpx; position: fixed; z-index: 100; left: 0">
  4. <view class="flex-column-center" style="background-color: #fcfcfc; padding: 30rpx; border-radius: 10rpx">
  5. <movable-area class="flex" style="width: 100%" animation="false" :style="{ height: originalHeight }">
  6. <movable-view scale-value="1" animation="false" damping="5000" :x="moveX" :style="{
  7. height: sliderHeight,
  8. width: sliderWidth,
  9. 'z-index': 101,
  10. }" direction="horizontal">
  11. <image :src="imgbk" class="image" mode="aspectFit" :style="{
  12. height: sliderHeight,
  13. width: sliderWidth,
  14. 'margin-top': imgbKH,
  15. }"></image>
  16. </movable-view>
  17. <image :src="img" mode="aspectFit" :style="{ height: originalHeight, width: originalWidth }" style="border-radius: 10rpx"></image>
  18. </movable-area>
  19. <movable-area class="flex-row-start" style="
  20. width: 100%;
  21. background-color: #efefef;
  22. height: 80rpx;
  23. border-radius: 40rpx;
  24. margin-top: 30rpx;
  25. ">
  26. <movable-view scale-value="1" animation="false" damping="50" :x="movePv" class="flex-row-center" style="
  27. border-radius: 50%;
  28. height: 100rpx;
  29. width: 100rpx;
  30. background-color: #ffffff;
  31. border: 2rpx solid #e3e3e3;
  32. margin-top: -13rpx;
  33. " direction="horizontal" @change="moveChange" @touchend="end">
  34. <view :class="endLoad ? 'cuIcon-right' : 'cuIcon-loading turn-load'" class="loadIcon" style="">
  35. </view>
  36. </movable-view>
  37. <text style="padding-left: 140rpx" :style="{ color: col }">{{
  38. hasImg
  39. }}</text>
  40. </movable-area>
  41. <view class="flex-row-around padding-top" style="width: 100%">
  42. <view @click="hide" class="cuIcon-close" style="font-size: 50rpx; color: #e25915">
  43. </view>
  44. <text class="cu-tag bg-cyan round" @click="getCode">刷新拼图</text>
  45. <text class="my-neirong-sm cuIcon-safe" style="color: #c1c1c1">Lili-FRAMEWORK</text>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- <view
  50. @click="hide"
  51. v-show="flage"
  52. class="flex-row-around"
  53. style="border-radius: 10rpx; background-color: #ebebeb"
  54. :style="{
  55. width: width,
  56. height: height,
  57. 'margin-left': left,
  58. 'margin-top': top,
  59. }"
  60. :class="vsr ? 'border-index' : ''"
  61. >
  62. <view class="flex-row-center" style="width: 45rpx; height: 45rpx">
  63. <view v-show="!vsr" class="dh-wt"> </view>
  64. <view
  65. v-show="vsr"
  66. class="cuIcon-roundcheck"
  67. style="font-size: 45rpx; color: #07c160"
  68. >
  69. </view>
  70. </view>
  71. <text :class="vsr ? 'ttcl' : ''" style="color: #5a5a5a">{{ vsrtx }}</text>
  72. <view class="cuIcon-safe text-gray"> </view>
  73. </view> -->
  74. </view>
  75. </template>
  76. <script>
  77. import api from "@/config/api.js";
  78. import storage from "@/utils/storage.js";
  79. const phone = uni.getSystemInfoSync();
  80. const l = phone.screenWidth / 750;
  81. export default {
  82. name: "verification",
  83. created() {
  84. // 可自行调整
  85. this.scHight = phone.screenHeight / 2 - 200 + "px";
  86. this.getCode();
  87. // 监听是否要重新验证
  88. uni.$on("vert", (data) => {
  89. this.vsr = data;
  90. this.vsrtx = "点击进行验证";
  91. this.getCode();
  92. });
  93. },
  94. props: {
  95. height: {
  96. type: String,
  97. default: "80rpx",
  98. },
  99. width: {
  100. type: String,
  101. default: "350rpx",
  102. },
  103. left: {
  104. type: String,
  105. default: "180rpx",
  106. },
  107. top: {
  108. type: String,
  109. default: "30rpx",
  110. },
  111. business: {
  112. type: String,
  113. default: "LOGIN",
  114. },
  115. },
  116. data() {
  117. return {
  118. flage: false,
  119. key: "", //key
  120. vsrtx: "点击进行验证", //按钮提示语
  121. vsr: false, //
  122. hid: true,
  123. col: "#838383",
  124. movePv: 0,
  125. hasImg: "拖动滑块已完成拼图",
  126. spcode: "",
  127. tl: 0,
  128. moveCode: 0,
  129. //X轴移动距离
  130. moveX: 0,
  131. //模版高度
  132. originalHeight: "",
  133. //模版宽度
  134. originalWidth: "",
  135. //拼图高度
  136. sliderHeight: "",
  137. //平涂宽度
  138. sliderWidth: "",
  139. scHight: 0,
  140. //原图
  141. img: "",
  142. //拼图
  143. imgbk: "",
  144. endLoad: true,
  145. imgbKH: "",
  146. };
  147. },
  148. methods: {
  149. show() {
  150. this.hid = false;
  151. },
  152. hide() {
  153. if (!this.vsr) {
  154. // vsr判断是否验证成功,成功隐藏验证框
  155. this.hid = !this.hid;
  156. }
  157. },
  158. // 获取验证图片
  159. getCode() {
  160. this.col = "#b3afae";
  161. this.hasImg = "图片加载中...";
  162. uni.request({
  163. url: api.common + "/slider/" + this.business,
  164. header: {
  165. uuid: storage.getUuid(),
  166. },
  167. success: (res) => {
  168. this.col = "#838383";
  169. this.hasImg = "拖动滑块以完成拼图";
  170. var data = res.data.result;
  171. // base64的图片
  172. this.img = data.backImage;
  173. this.imgbk = data.slidingImage;
  174. // 根据参数动态适应验证图片的高宽
  175. this.imgbKH = data.randomY * 1.8 + "rpx";
  176. this.originalHeight = data.originalHeight * 1.8 + "rpx";
  177. this.originalWidth = data.originalWidth * 1.8 + "rpx";
  178. this.sliderHeight = data.sliderHeight * 1.8 + "rpx";
  179. this.sliderWidth = data.sliderWidth * 1.8 + "rpx";
  180. // 适应比率,用来适应滑动距离
  181. this.tl = 1 / (1.8 * l);
  182. // 无用信息
  183. this.spcode = data.capcode;
  184. // 验证令牌
  185. this.key = data.key;
  186. this.$store.state.verificationKey = data.key;
  187. },
  188. });
  189. },
  190. end(e) {
  191. this.endLoad = false;
  192. // 验证拼图位置是否正确
  193. uni.request({
  194. method: "POST",
  195. url:
  196. api.common +
  197. "/slider/" +
  198. this.business +
  199. "?xPos=" +
  200. parseInt(this.moveCode * this.tl),
  201. header: {
  202. uuid: storage.getUuid(),
  203. },
  204. success: (res) => {
  205. this.endLoad = true;
  206. res.data.result == false
  207. ? (res.data.result = false)
  208. : (res.data.result = true);
  209. if (res.data && res.data.result) {
  210. // // 验证成功后把key发送出去,后端会把验证信息存在缓存里
  211. this.$emit("send", this.key);
  212. this.hide();
  213. this.vsr = true;
  214. this.vsrtx = "已通过验证";
  215. } else {
  216. this.getCode(); // 让滑块回到起始位置
  217. if (this.movePv == 1) {
  218. this.movePv = 0;
  219. } else {
  220. this.movePv = 1;
  221. }
  222. }
  223. },
  224. fail: (res) => {
  225. this.$msg("连接服务器失败");
  226. },
  227. });
  228. },
  229. // 绑定拼图位置
  230. moveChange(e) {
  231. this.moveX = e.detail.x;
  232. this.moveCode = e.detail.x;
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. @import "./animation.css";
  239. @import "./icon.css";
  240. // @import './main.css';
  241. .dh-wt {
  242. animation: at 1.1s ease;
  243. animation-iteration-count: infinite;
  244. animation-direction: alternate;
  245. background-color: $main-color;
  246. border-radius: 50%;
  247. }
  248. @keyframes at {
  249. from {
  250. width: 27rpx;
  251. height: 27rpx;
  252. }
  253. to {
  254. width: 45rpx;
  255. height: 45rpx;
  256. }
  257. }
  258. .ttcl {
  259. color: $main-color;
  260. }
  261. .border-index {
  262. border: 1rpx solid $main-color;
  263. }
  264. .loadIcon {
  265. color: $main-color;
  266. font-size: 40rpx;
  267. }
  268. .status_bar {
  269. height: var(--status-bar-height);
  270. background-color: #f1f1f1;
  271. width: 100%;
  272. }
  273. .status_bar-nobg {
  274. height: var(--status-bar-height);
  275. width: 100%;
  276. }
  277. /* 转圈动画 */
  278. .turn-load {
  279. animation: turnmy 1s linear infinite;
  280. }
  281. @keyframes turnmy {
  282. 0% {
  283. -webkit-transform: rotate(0deg);
  284. }
  285. 25% {
  286. -webkit-transform: rotate(90deg);
  287. }
  288. 50% {
  289. -webkit-transform: rotate(180deg);
  290. }
  291. 75% {
  292. -webkit-transform: rotate(270deg);
  293. }
  294. 100% {
  295. -webkit-transform: rotate(360deg);
  296. }
  297. }
  298. .status_bar-fixed {
  299. height: var(--status-bar-height);
  300. width: 100%;
  301. position: fixed;
  302. background-color: #f1f1f1;
  303. z-index: 20;
  304. }
  305. .head-dh-my {
  306. display: flex;
  307. position: fixed;
  308. justify-content: space-around;
  309. align-items: flex-end;
  310. padding-bottom: 10rpx;
  311. z-index: 15;
  312. background-color: #e3e3e3;
  313. width: 750rpx;
  314. }
  315. .border-bom {
  316. border-bottom: 0.5rpx solid #dddddd;
  317. }
  318. .border-red {
  319. border-bottom: 1rpx solid #d33e18;
  320. }
  321. .border-bom-big {
  322. border-bottom: 8rpx solid #dddddd;
  323. }
  324. .border-bom-white {
  325. border-bottom: 2rpx solid #ffffff;
  326. }
  327. .border-bom-green {
  328. border-bottom: 4rpx solid #f8f9bd;
  329. }
  330. .border-bom-index {
  331. border-bottom: 4rpx solid #27d9b3;
  332. }
  333. .padding-left {
  334. padding-left: 20rpx;
  335. }
  336. .padding-left-top {
  337. padding-left: 20rpx;
  338. padding-top: 20rpx;
  339. }
  340. .padding-right {
  341. padding-right: 20rpx;
  342. }
  343. .input-my {
  344. padding-left: 20rpx;
  345. border-radius: 40rpx;
  346. height: 50rpx;
  347. margin: 10rpx;
  348. }
  349. .tb-tag-absolute {
  350. position: absolute;
  351. z-index: 5;
  352. border-radius: 25rpx;
  353. font-size: 16rpx;
  354. margin-left: 25rpx;
  355. margin-top: -35rpx;
  356. }
  357. .lk-tag {
  358. height: 50rpx;
  359. padding: 0 10rpx;
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. border: 2rpx solid #24bd9f;
  364. border-radius: 6rpx;
  365. color: #1c947a;
  366. font-weight: 500;
  367. }
  368. .tb-tag-my {
  369. border-radius: 15rpx;
  370. font-size: 16rpx;
  371. margin-left: 5rpx;
  372. }
  373. .my-green {
  374. color: #29c7a5;
  375. }
  376. .my-hui {
  377. color: #585858;
  378. font-size: 22rpx;
  379. }
  380. .flex-column-center {
  381. display: flex;
  382. flex-direction: column;
  383. justify-content: center;
  384. align-items: center;
  385. }
  386. .flex-column-between {
  387. display: flex;
  388. flex-direction: column;
  389. justify-content: space-between;
  390. align-items: center;
  391. }
  392. .flex-column-start {
  393. display: flex;
  394. flex-direction: column;
  395. justify-content: center;
  396. }
  397. .flex-column-around {
  398. display: flex;
  399. flex-direction: column;
  400. justify-content: space-around;
  401. align-items: center;
  402. }
  403. .flex-row-start {
  404. display: flex;
  405. flex-direction: row;
  406. align-items: center;
  407. }
  408. .flex-row-around {
  409. display: flex;
  410. flex-direction: row;
  411. justify-content: space-around;
  412. align-items: center;
  413. }
  414. .flex-row-center {
  415. display: flex;
  416. flex-direction: row;
  417. justify-content: center;
  418. align-items: center;
  419. }
  420. .flex-row-between {
  421. display: flex;
  422. flex-direction: row;
  423. justify-content: space-between;
  424. align-items: center;
  425. }
  426. .my-title {
  427. font-size: 35rpx;
  428. font-weight: bold;
  429. }
  430. .my-neirong {
  431. font-size: 26rpx;
  432. color: #6d6d6d;
  433. }
  434. .my-neirong-sm {
  435. font-size: 23rpx;
  436. color: #616161;
  437. }
  438. .my-tag-text {
  439. font-size: 22rpx;
  440. padding-top: 20rpx;
  441. color: #bababa;
  442. }
  443. .padding-top {
  444. padding-top: 35rpx;
  445. }
  446. .padding-top-sm {
  447. padding-top: 20rpx;
  448. }
  449. .bottom-dh {
  450. background-color: #f1f1f1;
  451. position: fixed;
  452. z-index: 10;
  453. bottom: 0;
  454. width: 750rpx;
  455. height: 110rpx;
  456. }
  457. .tb-text {
  458. display: flex;
  459. flex-direction: column;
  460. justify-content: center;
  461. align-items: center;
  462. }
  463. .bottom-text {
  464. width: 750rpx;
  465. position: fixed;
  466. text-align: center;
  467. font-size: 26rpx;
  468. color: #9d9d9d;
  469. bottom: 70rpx;
  470. }
  471. .white-box {
  472. padding: 0 20rpx;
  473. margin-bottom: 15rpx;
  474. margin-top: 5rpx;
  475. width: 715rpx;
  476. background-color: #ffffff;
  477. border-radius: 30rpx;
  478. }
  479. .green-box {
  480. padding: 0 20rpx;
  481. margin-bottom: 15rpx;
  482. margin-top: 5rpx;
  483. width: 715rpx;
  484. background-color: #ffffff;
  485. border-radius: 30rpx;
  486. background-image: linear-gradient(#1faf97, #29c7a5);
  487. }
  488. .yuan-sm {
  489. width: 13rpx;
  490. height: 13rpx;
  491. border-radius: 50%;
  492. background-color: #1fc189;
  493. margin-left: 10rpx;
  494. }
  495. .yuan-normal {
  496. width: 14rpx;
  497. height: 14rpx;
  498. border-radius: 50%;
  499. background-color: #159f3c;
  500. margin-left: 10rpx;
  501. }
  502. .yuan-normal-red {
  503. width: 14rpx;
  504. height: 14rpx;
  505. border-radius: 50%;
  506. background-color: #bc3c11;
  507. margin-left: 10rpx;
  508. }
  509. .yuan-sm-red {
  510. width: 13rpx;
  511. height: 13rpx;
  512. border-radius: 50%;
  513. background-color: #de410d;
  514. margin-left: 10rpx;
  515. }
  516. .white-box-all {
  517. margin-top: 5rpx;
  518. width: 750rpx;
  519. background-color: #ffffff;
  520. border-radius: 13px;
  521. }
  522. .moneycolor {
  523. color: #ea5002;
  524. }
  525. .text-bold-sm {
  526. font-weight: 425;
  527. }
  528. .sm-moneycolor {
  529. color: #e3793b;
  530. }
  531. .margin-top {
  532. margin-top: 20rpx;
  533. }
  534. .margin-top-sm {
  535. margin-top: 12rpx;
  536. }
  537. .margin {
  538. margin: 20rpx;
  539. }
  540. .margin-left {
  541. margin-left: 20rpx;
  542. }
  543. .margin-left-top {
  544. margin-left: 20rpx;
  545. margin-top: 20rpx;
  546. }
  547. .margin-right {
  548. margin-right: 20rpx;
  549. }
  550. .my-absolute {
  551. position: absolute;
  552. }
  553. .my-fixed {
  554. position: fixed;
  555. }
  556. .my-seach {
  557. width: 450rpx;
  558. height: 55rpx;
  559. background-color: #f8f8f8;
  560. border-radius: 30rpx;
  561. padding-left: 20rpx;
  562. }
  563. .move-view {
  564. width: 48rpx;
  565. height: 10rpx;
  566. background-color: #28ba91;
  567. border-radius: 4rpx;
  568. margin-left: 100rpx;
  569. }
  570. .move-view-p {
  571. width: 45rpx;
  572. height: 10rpx;
  573. background-color: #28ba91;
  574. border-radius: 4rpx;
  575. }
  576. .header-dh {
  577. position: fixed;
  578. padding-top: 20rpx;
  579. padding-bottom: 15rpx;
  580. height: 70rpx;
  581. width: 750rpx;
  582. background-color: #f1f1f1;
  583. z-index: 20;
  584. }
  585. .tp-normal {
  586. width: 60rpx;
  587. height: 60rpx;
  588. }
  589. .tp-sm {
  590. width: 45rpx;
  591. height: 45rpx;
  592. }
  593. .tp-big {
  594. width: 70rpx;
  595. height: 70rpx;
  596. border-radius: 50%;
  597. }
  598. .main-color {
  599. color: #07d188;
  600. }
  601. </style>