選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

get-code.vue 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!-- 密码登录 -->
  2. <template>
  3. <view class="login-main as-gravity-center as-layout-vertical">
  4. <view class="form">
  5. <view class="form-input">
  6. <view> +86</view>
  7. <image :src="`${$imgUrl}common/arror_down_black.png`" class="arror" mode="aspectFill" />
  8. <input class="input" v-model="state.mobile" focus placeholder="请输入手机号"
  9. placeholder-class="form-placeholder" type="number" maxlength="11" disabled />
  10. </view>
  11. <view class="form-input" v-if="state.loginType === 'code'">
  12. <input class="input" v-model="state.code" placeholder="请输入验证码" placeholder-class="form-placeholder"
  13. maxlength="6" type="number" />
  14. <verification-code :bg="false" :mobile="state.mobile"></verification-code>
  15. </view>
  16. </view>
  17. <view class="btn">
  18. <submit-button title="下一步" @submit="toNext"></submit-button>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup lang="ts">
  23. import { reactive } from "vue";
  24. import { checkStr, msg, navTo } from "@/utils/utils";
  25. import { onLoad, onUnload } from "@dcloudio/uni-app";
  26. import { checkCode } from "@/utils/network/api.js";
  27. import { request } from "@/utils/network/request.js";
  28. import { stringToJson } from "@/utils/network/encryption";
  29. import { useUserStore } from "@/stores/user";
  30. import { getItem, setItem } from "@/utils/storage";
  31. const userStore = useUserStore();
  32. const { fetchToken } = userStore;
  33. const state = reactive({
  34. loginType: "code", //pwd-密码登录 code-验证码登录
  35. mobile: "", //用户名
  36. password: "", //密码
  37. code: "", //验证码
  38. json: {}
  39. });
  40. onLoad((option) => {
  41. // https://qtzl.etcjz.cn/default-bucket/20231204/scanPay.html?orderId=20231016180507480853307&phone=18786896573&type=1
  42. // https://qtzl.etcjz.cn/default-bucket/20231204/protocol.html?orderId=20231012114651162505354&phone=18786896573&type=2&url=default-bucket/20231024/fcae5e580ecc4cacaaa75138_ETC用户协议20230805(法审终版).docx
  43. console.log("option", option)
  44. if (option.q) {
  45. const q = decodeURIComponent(option.q); // 获取到二维码原始链接内容
  46. console.log(q);
  47. state.json = getRequest(q)
  48. console.log("state.json", state.json, getItem("mobile"), getItem("mobile") == state.json.phone)
  49. setItem('scanCode', state.json)
  50. if (!getItem("mobile")) {
  51. uni.showModal({
  52. title: '提示',
  53. content: '您还未登录小程序,请先登录小程序',
  54. showCancel: false,
  55. success: function (res) {
  56. if (res.confirm) {
  57. navTo('/login/login')
  58. }
  59. }
  60. });
  61. }
  62. // 直接用传过来的手机号(不让他修改)
  63. state.mobile = state.json.phone
  64. } else {
  65. state.json = getItem("scanCode")
  66. state.mobile = state.json.phone
  67. }
  68. });
  69. onUnload(() => {
  70. });
  71. const toNext = () => {
  72. if (!state.mobile) {
  73. msg("请输入手机号!");
  74. return;
  75. }
  76. if (state.loginType === "code" && !state.code) {
  77. msg("请输入验证码!");
  78. return;
  79. }
  80. if (!checkStr(state.mobile, "mobile")) {
  81. msg("请输入正确的手机号!");
  82. return;
  83. }
  84. const options = {
  85. type: 2,
  86. data: {
  87. mobile: state.mobile,
  88. code: state.code
  89. },
  90. method: "POST",
  91. showLoading: true,
  92. };
  93. request(checkCode, options).then((res) => {
  94. console.log("过来了", res)
  95. if (state.json.type == 1) {
  96. uni.navigateTo({
  97. url: `/subpackage/orders/order_payment?orderId=${state.json.orderId}`,
  98. });
  99. } else if (state.json.type == 2) {
  100. uni.navigateTo({
  101. url: `/subpackage/orders/product-detail?orderId=${state.json.orderId}&url=${state.json.url}&typeScanCode=${state.json.type}`,
  102. });
  103. }
  104. })
  105. .catch((err) => {
  106. // msg("验证码错误");
  107. });
  108. };
  109. //解析URL获取参数
  110. const getRequest = (urlStr) => {
  111. if (typeof urlStr == "undefined") {
  112. // 获取url中"?"符后的字符串
  113. var url = decodeURI(location.search);
  114. } else {
  115. var url = "?" + urlStr.split("?")[1];
  116. }
  117. var theRequest = new Object();
  118. if (url.indexOf("?") != -1) {
  119. var str = url.substr(1);
  120. var strs = str.split("&");
  121. for (var i = 0; i < strs.length; i++) {
  122. theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
  123. }
  124. }
  125. return theRequest;
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .login-main {
  130. border-top: 1rpx solid #dcdcdc;
  131. padding: 22rpx 30rpx 140rpx;
  132. .title {
  133. font-size: 46rpx;
  134. color: #333333;
  135. margin-top: 30rpx;
  136. font-weight: 600;
  137. }
  138. .form {
  139. width: 100%;
  140. margin-top: 100rpx;
  141. .form-input {
  142. display: flex;
  143. flex-direction: row;
  144. align-items: center;
  145. height: 90rpx;
  146. border-bottom: 1rpx solid #dcdcdc;
  147. padding: 0rpx 12rpx;
  148. color: #333333;
  149. &:last-child {
  150. margin-top: 50rpx;
  151. }
  152. .input {
  153. flex: 1;
  154. padding-right: 48rpx;
  155. font-size: 28rpx;
  156. font-family: Microsoft YaHei;
  157. background-color: transparent;
  158. }
  159. .arror {
  160. width: 28rpx;
  161. height: 25rpx;
  162. margin-left: 16rpx;
  163. margin-right: 40rpx;
  164. }
  165. .eye {
  166. width: 48rpx;
  167. height: 48rpx;
  168. }
  169. }
  170. .form-placeholder {
  171. color: #999999;
  172. }
  173. }
  174. .btn {
  175. width: 100%;
  176. margin: 120rpx 40rpx 50rpx;
  177. }
  178. }
  179. </style>