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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <!-- 密码登录 -->
  2. <template>
  3. <view class="login-main as-gravity-center as-layout-vertical">
  4. <image :src="`${$imgUrl}login/logo.png`" class="logo" mode="aspectFill"></image>
  5. <view class="title">九州ETC</view>
  6. <view class="form">
  7. <view class="form-input">
  8. <view> +86</view>
  9. <image :src="`${$imgUrl}common/arror_down_black.png`" class="arror" mode="aspectFill" />
  10. <input class="input" v-model="state.username" focus placeholder="请输入手机号"
  11. placeholder-class="form-placeholder" type="number" maxlength="11" />
  12. </view>
  13. <view class="form-input" v-if="state.loginType === 'pwd'">
  14. <input class="input" v-model="state.password" type="text" placeholder="请输入密码"
  15. placeholder-class="form-placeholder" :password="state.isPwdType ? true : false" />
  16. <image :src="`${$imgUrl}login/${
  17. state.isPwdType ? 'icon_eye_close' : 'icon_eye_open'
  18. }.png`" class="eye" @click="state.isPwdType = !state.isPwdType" mode="aspectFill"></image>
  19. </view>
  20. <view class="form-input" v-if="state.loginType === 'code'">
  21. <input class="input" v-model="state.code" placeholder="请输入验证码" placeholder-class="form-placeholder"
  22. maxlength="6" type="number" />
  23. <verification-code :bg="false" :mobile="state.username"></verification-code>
  24. </view>
  25. </view>
  26. <view class="btn">
  27. <submit-button title="登录" @submit="doLogin"></submit-button>
  28. <button size="default" type="primary" class="ui-btn" open-type="getPhoneNumber" @getphonenumber="doLogin"
  29. >登录</button>
  30. </view>
  31. <view class="agreement">
  32. <checkbox-group @change="checkboxChange" class="group">
  33. <checkbox :checked="state.checked" color="#00B38B" size="30" icon-size="30" label-size="24"
  34. style="transform:scale(0.85)">
  35. </checkbox>
  36. <label>我已阅读并同意</label>
  37. </checkbox-group>
  38. <view class="txt-green" @click="toRead">《平台用户服务隐私协议》</view>
  39. </view>
  40. <view class="btns as-layout-horizontal">
  41. <view class="as-layout-vertical as-gravity-center" @click="navTo('/login/register-step1')">
  42. <view class="bg blue as-gravity-center">
  43. <image :src="`${$imgUrl}login/icon_register.png`" class="img" mode="aspectFill" />
  44. </view>
  45. <view class="label">注册账号</view>
  46. </view>
  47. <view class="as-layout-vertical as-gravity-center" @click="
  48. state.loginType === 'pwd'
  49. ? (state.loginType = 'code')
  50. : (state.loginType = 'pwd')
  51. ">
  52. <view class="bg orange as-gravity-center">
  53. <image :src="`${$imgUrl}login/icon_code.png`" class="img" mode="aspectFill" />
  54. </view>
  55. <view class="label">{{
  56. state.loginType === "pwd" ? "验证码登录" : "密码登录"
  57. }}</view>
  58. </view>
  59. <view class="as-layout-vertical as-gravity-center" @click="navTo('/login/forget-pwd-step1')">
  60. <view class="bg purple as-gravity-center">
  61. <image :src="`${$imgUrl}login/icon_pwd.png`" class="img" mode="aspectFill" />
  62. </view>
  63. <view class="label">忘记密码</view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script setup lang="ts">
  69. import { reactive } from "vue";
  70. import { checkStr, msg, navTo, subscribeMessages } from "@/utils/utils";
  71. import { onLoad, onUnload } from "@dcloudio/uni-app";
  72. import { login, loginCode, loginTime, wechatAppID,userBasicGetOpenId,userBasicGetPhoneNumber } from "@/utils/network/api.js";
  73. import { requestNew} from "@/utils/network/request.js";
  74. import { stringToJson } from "@/utils/network/encryption";
  75. import { useUserStore } from "@/stores/user";
  76. import { setItem } from "@/utils/storage";
  77. const userStore = useUserStore();
  78. const { fetchToken } = userStore;
  79. const state = reactive({
  80. checked: false, //是否勾选协议
  81. isPwdType: true, //是不是密码类型
  82. loginType: "code", //pwd-密码登录 code-验证码登录
  83. username: "", //用户名
  84. password: "", //密码
  85. code: "", //验证码
  86. back: 0, //从app扫码看协议过来 登录了 还需要回到手机号验证页面 0 是原本的登录 1 要回去的登录(从哪来回哪去) 2运维跳转过来得中转页
  87. params:{}
  88. });
  89. onLoad((option) => {
  90. if (option.back == 1) {
  91. state.back = option.back
  92. }
  93. if (option.back == 2) {
  94. state.back = option.back
  95. state.params = JSON.parse(decodeURIComponent(option.params))
  96. }
  97. uni.$on("login", (data) => {
  98. state.username = data.phone;
  99. });
  100. });
  101. onUnload(() => {
  102. uni.$off("login");
  103. });
  104. const checkboxChange = (e) => {
  105. console.log(e);
  106. state.checked = !state.checked;
  107. };
  108. // 去协议页面
  109. const toRead = () => {
  110. navTo("/login/agreement")
  111. }
  112. /* 登录 */
  113. const doLogin = (e) => {
  114. // if (!state.username) {
  115. // msg("请输入手机号!");
  116. // return;
  117. // }
  118. // if (state.loginType === "pwd" && !state.password) {
  119. // msg("请输入密码!");
  120. // return;
  121. // }
  122. // if (state.loginType === "code" && !state.code) {
  123. // msg("请输入验证码!");
  124. // return;
  125. // }
  126. // if (!checkStr(state.username, "mobile")) {
  127. // msg("请输入正确的手机号!");
  128. // return;
  129. // }
  130. // if (!state.checked) {
  131. // msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  132. // return;
  133. // }
  134. console.log("e",e)
  135. //判断是验证码登录,还是账号密码登录
  136. // if (state.loginType === "code") {
  137. // reqLogin(loginCode, {
  138. // mobile: state.username,
  139. // code: state.code,
  140. // loginTime: loginTime,
  141. // });
  142. // } else {
  143. // reqLogin(login, {
  144. // mobile: state.username,
  145. // password: state.password,
  146. // loginTime: loginTime,
  147. // });
  148. // }
  149. reqLogin(userBasicGetPhoneNumber, {
  150. jsCode: e.detail.code,
  151. iv: e.detail.iv,
  152. encryptedData: e.detail.encryptedData,
  153. });
  154. };
  155. /* 执行登录 */
  156. const reqLogin = (code : string, data : object) => {
  157. console.log(code, data);
  158. const options = {
  159. type: 2,
  160. data: data,
  161. method: "POST",
  162. showLoading: true,
  163. };
  164. requestNew(code, options).then((res) => {
  165. const result = res;
  166. console.log(result);
  167. console.log(typeof (result));
  168. fetchToken(result.code).then((data : any) => {
  169. console.log("登录", data);
  170. setItem('mobile', state.username)
  171. subscribeMessages();
  172. msg("登录成功!");
  173. uni.$emit("refreshOrder");
  174. if (state.back == 1) {
  175. uni.navigateBack({
  176. delta: 1
  177. })
  178. } else if (state.back == 2) {
  179. const params = encodeURIComponent(JSON.stringify(state.params))
  180. uni.redirectTo({
  181. url:`/subpackage/after-sale/transfer-page?params=${params}`
  182. })
  183. } else{
  184. uni.switchTab({
  185. url: '/pages/index/index'
  186. })
  187. }
  188. });
  189. });
  190. };
  191. const decryptPhoneNumber=(e)=>{
  192. console.log("e",e)
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. .login-main {
  197. border-top: 1rpx solid #dcdcdc;
  198. padding: 22rpx 30rpx 140rpx;
  199. .logo {
  200. width: 260rpx;
  201. height: 160rpx;
  202. }
  203. .group {
  204. display: flex;
  205. align-items: center;
  206. }
  207. .title {
  208. font-size: 46rpx;
  209. color: #333333;
  210. margin-top: 30rpx;
  211. font-weight: 600;
  212. }
  213. .form {
  214. width: 100%;
  215. margin-top: 100rpx;
  216. .form-input {
  217. display: flex;
  218. flex-direction: row;
  219. align-items: center;
  220. height: 90rpx;
  221. border-bottom: 1rpx solid #dcdcdc;
  222. padding: 0rpx 12rpx;
  223. color: #333333;
  224. &:last-child {
  225. margin-top: 50rpx;
  226. }
  227. .input {
  228. flex: 1;
  229. padding-right: 48rpx;
  230. font-size: 28rpx;
  231. font-family: Microsoft YaHei;
  232. background-color: transparent;
  233. }
  234. .arror {
  235. width: 28rpx;
  236. height: 25rpx;
  237. margin-left: 16rpx;
  238. margin-right: 40rpx;
  239. }
  240. .eye {
  241. width: 48rpx;
  242. height: 48rpx;
  243. }
  244. }
  245. .form-placeholder {
  246. color: #999999;
  247. }
  248. }
  249. .btn {
  250. width: 100%;
  251. margin: 120rpx 40rpx 50rpx;
  252. }
  253. .agreement {
  254. font-size: 24rpx;
  255. display: flex;
  256. align-items: center;
  257. .txt-grey {
  258. color: #666666;
  259. }
  260. .txt-green {
  261. color: #00b38b;
  262. }
  263. :deep(.u-checkbox) {
  264. margin-right: -20rpx;
  265. }
  266. }
  267. .btns {
  268. width: 100%;
  269. margin-top: 125rpx;
  270. justify-content: space-around;
  271. padding: 0px 8rpx;
  272. .bg {
  273. width: 80rpx;
  274. height: 80rpx;
  275. border-radius: 50%;
  276. .img {
  277. width: 48rpx;
  278. height: 48rpx;
  279. }
  280. }
  281. .blue {
  282. background-color: #1d9cff;
  283. }
  284. .orange {
  285. background-color: #feb654;
  286. }
  287. .purple {
  288. background-color: #8060ff;
  289. }
  290. .label {
  291. font-size: 26rpx;
  292. color: #333333;
  293. margin-top: 30rpx;
  294. }
  295. }
  296. }
  297. </style>