Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

login.vue 7.5KB

2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <!-- 密码登录 -->
  2. <template>
  3. <view class="login-main as-gravity-center as-layout-vertical">
  4. <image :src="`${$imgUrl}login/logo.png`" class="logo"></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" />
  10. <input
  11. class="input"
  12. v-model="state.username"
  13. focus
  14. placeholder="请输入手机号"
  15. placeholder-class="form-placeholder"
  16. type="number"
  17. maxlength="11"
  18. />
  19. </view>
  20. <view class="form-input" v-if="state.loginType === 'pwd'">
  21. <input
  22. class="input"
  23. v-model="state.password"
  24. type="text"
  25. placeholder="请输入密码"
  26. placeholder-class="form-placeholder"
  27. :password="state.isPwdType ? true : false"
  28. />
  29. <image
  30. :src="`${$imgUrl}login/${
  31. state.isPwdType ? 'icon_eye_close' : 'icon_eye_open'
  32. }.png`"
  33. class="eye"
  34. @click="state.isPwdType = !state.isPwdType"
  35. ></image>
  36. </view>
  37. <view class="form-input" v-if="state.loginType === 'code'">
  38. <input
  39. class="input"
  40. v-model="state.code"
  41. placeholder="请输入验证码"
  42. placeholder-class="form-placeholder"
  43. maxlength="6"
  44. type="number"
  45. />
  46. <verification-code
  47. :bg="false"
  48. :mobile="state.username"
  49. ></verification-code>
  50. </view>
  51. </view>
  52. <view class="btn">
  53. <submit-button title="登录" @submit="doLogin"></submit-button>
  54. </view>
  55. <view class="agreement">
  56. <checkbox-group @change="checkboxChange">
  57. <checkbox
  58. :checked="state.checked"
  59. activeColor="#00B38B"
  60. size="30"
  61. icon-size="30"
  62. label-size="24"
  63. >我已阅读并同意
  64. </checkbox>
  65. </checkbox-group>
  66. <!-- <view class="txt-grey">我已阅读并同意</view> -->
  67. <view class="txt-green" @click="toRead"
  68. >《平台用户服务隐私协议》</view
  69. >
  70. </view>
  71. <view class="btns as-layout-horizontal">
  72. <view
  73. class="as-layout-vertical as-gravity-center"
  74. @click="navTo('/login/register-step1')"
  75. >
  76. <view class="bg blue as-gravity-center">
  77. <image :src="`${$imgUrl}login/icon_register.png`" class="img" />
  78. </view>
  79. <view class="label">注册账号</view>
  80. </view>
  81. <view
  82. class="as-layout-vertical as-gravity-center"
  83. @click="
  84. state.loginType === 'pwd'
  85. ? (state.loginType = 'code')
  86. : (state.loginType = 'pwd')
  87. "
  88. >
  89. <view class="bg orange as-gravity-center">
  90. <image :src="`${$imgUrl}login/icon_code.png`" class="img" />
  91. </view>
  92. <view class="label">{{
  93. state.loginType === "pwd" ? "验证码登录" : "密码登录"
  94. }}</view>
  95. </view>
  96. <view
  97. class="as-layout-vertical as-gravity-center"
  98. @click="navTo('/login/forget-pwd-step1')"
  99. >
  100. <view class="bg purple as-gravity-center">
  101. <image :src="`${$imgUrl}login/icon_pwd.png`" class="img" />
  102. </view>
  103. <view class="label">忘记密码</view>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script setup lang="ts">
  109. import uCheckBox from "@/uni_modules/vk-uview-ui/components/u-checkbox/u-checkbox.vue";
  110. import { reactive } from "vue";
  111. import { checkStr, msg, navTo } from "@/utils/utils";
  112. import { onLoad, onUnload } from "@dcloudio/uni-app";
  113. import { login, loginCode, loginTime } from "@/utils/network/api.js";
  114. import { request } from "@/utils/network/request.js";
  115. import { stringToJson } from "@/utils/network/encryption";
  116. import { useUserStore } from "@/stores/user";
  117. import { setItem } from "@/utils/storage";
  118. const userStore = useUserStore();
  119. const { fetchToken } = userStore;
  120. const state = reactive({
  121. checked: false, //是否勾选协议
  122. isPwdType: true, //是不是密码类型
  123. loginType: "pwd", //pwd-密码登录 code-验证码登录
  124. username: "", //用户名
  125. password: "", //密码
  126. code: "", //验证码
  127. });
  128. onLoad(() => {
  129. uni.$on("login", (data) => {
  130. state.username = data.phone;
  131. });
  132. });
  133. onUnload(() => {
  134. uni.$off("login");
  135. });
  136. const checkboxChange = (e) => {
  137. console.log(e);
  138. state.checked = !state.checked;
  139. };
  140. // 去协议页面
  141. const toRead=()=>{
  142. navTo("/login/agreement")
  143. }
  144. /* 登录 */
  145. const doLogin = () => {
  146. if (!state.username) {
  147. msg("请输入手机号!");
  148. return;
  149. }
  150. if (state.loginType === "pwd" && !state.password) {
  151. msg("请输入密码!");
  152. return;
  153. }
  154. if (state.loginType === "code" && !state.code) {
  155. msg("请输入验证码!");
  156. return;
  157. }
  158. if (!checkStr(state.username, "mobile")) {
  159. msg("请输入正确的手机号!");
  160. return;
  161. }
  162. if (!state.checked) {
  163. msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  164. return;
  165. }
  166. //TODO 目前后端规定验证码只能是123456,所以目前写死
  167. state.code = "123456";
  168. if (state.loginType === "code") {
  169. reqLogin(loginCode, {
  170. mobile: state.username,
  171. code: state.code,
  172. loginTime: loginTime,
  173. });
  174. } else {
  175. reqLogin(login, {
  176. mobile: state.username,
  177. password: state.password,
  178. loginTime: loginTime,
  179. });
  180. }
  181. };
  182. /* 执行登录 */
  183. const reqLogin = (code, data) => {
  184. const options = {
  185. type: 2,
  186. data: data,
  187. method: "POST",
  188. showLoading: true,
  189. };
  190. request(code, options).then((res) => {
  191. fetchToken(stringToJson(res.bizContent).code).then((data) => {
  192. setItem("phone", data.mobile);
  193. msg("登录成功!");
  194. uni.$emit("refreshOrder");
  195. uni.navigateBack();
  196. });
  197. });
  198. };
  199. </script>
  200. <style lang="scss" scoped>
  201. .login-main {
  202. border-top: 1rpx solid #dcdcdc;
  203. padding: 22rpx 30rpx 140rpx;
  204. .logo {
  205. width: 260rpx;
  206. height: 160rpx;
  207. }
  208. .title {
  209. font-size: 46rpx;
  210. color: #333333;
  211. margin-top: 30rpx;
  212. font-weight: 600;
  213. }
  214. .form {
  215. width: 100%;
  216. margin-top: 100rpx;
  217. .form-input {
  218. display: flex;
  219. flex-direction: row;
  220. align-items: center;
  221. height: 90rpx;
  222. border-bottom: 1rpx solid #dcdcdc;
  223. padding: 0rpx 12rpx;
  224. color: #333333;
  225. &:last-child {
  226. margin-top: 50rpx;
  227. }
  228. .input {
  229. flex: 1;
  230. padding-right: 48rpx;
  231. font-size: 28rpx;
  232. font-family: Microsoft YaHei;
  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>