You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get-code.vue 5.4KB

1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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, subscribeMessages } from "@/utils/utils";
  25. import { onLoad, onUnload } from "@dcloudio/uni-app";
  26. import { checkCode, loginCode, loginTime } 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. // 直接去登录
  85. reqLogin(loginCode, {
  86. mobile: state.mobile,
  87. code: state.code,
  88. loginTime: loginTime,
  89. });
  90. };
  91. /* 执行登录 */
  92. const reqLogin = (code : string, data : object) => {
  93. console.log(code, data);
  94. const options = {
  95. type: 2,
  96. data: data,
  97. method: "POST",
  98. showLoading: true,
  99. };
  100. request(code, options).then((res) => {
  101. const result = stringToJson(res.bizContent);
  102. console.log(result);
  103. console.log(typeof (result));
  104. fetchToken(result.code).then((data : any) => {
  105. console.log("登录", data);
  106. setItem('mobile', state.mobile)
  107. subscribeMessages();
  108. if (state.json.type == 1) {
  109. uni.navigateTo({
  110. url: `/subpackage/orders/order_payment?orderId=${state.json.orderId}`,
  111. });
  112. } else if (state.json.type == 2) {
  113. uni.navigateTo({
  114. url: `/subpackage/orders/product-detail?orderId=${state.json.orderId}&url=${state.json.url}&typeScanCode=${state.json.type}`,
  115. });
  116. }
  117. });
  118. });
  119. };
  120. //解析URL获取参数
  121. const getRequest = (urlStr) => {
  122. if (typeof urlStr == "undefined") {
  123. // 获取url中"?"符后的字符串
  124. var url = decodeURI(location.search);
  125. } else {
  126. var url = "?" + urlStr.split("?")[1];
  127. }
  128. var theRequest = new Object();
  129. if (url.indexOf("?") != -1) {
  130. var str = url.substr(1);
  131. var strs = str.split("&");
  132. for (var i = 0; i < strs.length; i++) {
  133. theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
  134. }
  135. }
  136. return theRequest;
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. .login-main {
  141. border-top: 1rpx solid #dcdcdc;
  142. padding: 22rpx 30rpx 140rpx;
  143. .title {
  144. font-size: 46rpx;
  145. color: #333333;
  146. margin-top: 30rpx;
  147. font-weight: 600;
  148. }
  149. .form {
  150. width: 100%;
  151. margin-top: 100rpx;
  152. .form-input {
  153. display: flex;
  154. flex-direction: row;
  155. align-items: center;
  156. height: 90rpx;
  157. border-bottom: 1rpx solid #dcdcdc;
  158. padding: 0rpx 12rpx;
  159. color: #333333;
  160. &:last-child {
  161. margin-top: 50rpx;
  162. }
  163. .input {
  164. flex: 1;
  165. padding-right: 48rpx;
  166. font-size: 28rpx;
  167. font-family: Microsoft YaHei;
  168. background-color: transparent;
  169. }
  170. .arror {
  171. width: 28rpx;
  172. height: 25rpx;
  173. margin-left: 16rpx;
  174. margin-right: 40rpx;
  175. }
  176. .eye {
  177. width: 48rpx;
  178. height: 48rpx;
  179. }
  180. }
  181. .form-placeholder {
  182. color: #999999;
  183. }
  184. }
  185. .btn {
  186. width: 100%;
  187. margin: 120rpx 40rpx 50rpx;
  188. }
  189. }
  190. </style>