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.

login.vue 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 { reactive } from "vue";
  110. import { checkStr, msg, navTo } from "@/utils/utils";
  111. import { onLoad, onUnload } from "@dcloudio/uni-app";
  112. import { login, loginCode, loginTime } from "@/utils/network/api.js";
  113. import { request } from "@/utils/network/request.js";
  114. import { stringToJson } from "@/utils/network/encryption";
  115. import { useUserStore } from "@/stores/user";
  116. import { setItem } from "@/utils/storage";
  117. const userStore = useUserStore();
  118. const { fetchToken } = userStore;
  119. const state = reactive({
  120. checked: false, //是否勾选协议
  121. isPwdType: true, //是不是密码类型
  122. loginType: "pwd", //pwd-密码登录 code-验证码登录
  123. username: "", //用户名
  124. password: "", //密码
  125. code: "", //验证码
  126. });
  127. onLoad(() => {
  128. uni.$on("login", (data) => {
  129. state.username = data.phone;
  130. });
  131. });
  132. onUnload(() => {
  133. uni.$off("login");
  134. });
  135. const checkboxChange = (e) => {
  136. console.log(e);
  137. state.checked = !state.checked;
  138. };
  139. // 去协议页面
  140. const toRead=()=>{
  141. navTo("/login/agreement")
  142. }
  143. /* 登录 */
  144. const doLogin = () => {
  145. if (!state.username) {
  146. msg("请输入手机号!");
  147. return;
  148. }
  149. if (state.loginType === "pwd" && !state.password) {
  150. msg("请输入密码!");
  151. return;
  152. }
  153. if (state.loginType === "code" && !state.code) {
  154. msg("请输入验证码!");
  155. return;
  156. }
  157. if (!checkStr(state.username, "mobile")) {
  158. msg("请输入正确的手机号!");
  159. return;
  160. }
  161. if (!state.checked) {
  162. msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  163. return;
  164. }
  165. //判断是验证码登录,还是账号密码登录
  166. if (state.loginType === "code") {
  167. reqLogin(loginCode, {
  168. mobile: state.username,
  169. code: state.code,
  170. loginTime: loginTime,
  171. });
  172. } else {
  173. reqLogin(login, {
  174. mobile: state.username,
  175. password: state.password,
  176. loginTime: loginTime,
  177. });
  178. }
  179. };
  180. /* 执行登录 */
  181. const reqLogin = (code:string, data:object) => {
  182. console.log(code,data);
  183. const options = {
  184. type: 2,
  185. data: data,
  186. method: "POST",
  187. showLoading: true,
  188. };
  189. request(code, options).then((res) => {
  190. const result = stringToJson(res.bizContent);
  191. console.log(result);
  192. console.log(typeof(result));
  193. fetchToken(result.code).then((data:any) => {
  194. console.log(data);
  195. msg("登录成功!");
  196. uni.$emit("refreshOrder");
  197. uni.navigateBack();
  198. });
  199. });
  200. };
  201. </script>
  202. <style lang="scss" scoped>
  203. .login-main {
  204. border-top: 1rpx solid #dcdcdc;
  205. padding: 22rpx 30rpx 140rpx;
  206. .logo {
  207. width: 260rpx;
  208. height: 160rpx;
  209. }
  210. .title {
  211. font-size: 46rpx;
  212. color: #333333;
  213. margin-top: 30rpx;
  214. font-weight: 600;
  215. }
  216. .form {
  217. width: 100%;
  218. margin-top: 100rpx;
  219. .form-input {
  220. display: flex;
  221. flex-direction: row;
  222. align-items: center;
  223. height: 90rpx;
  224. border-bottom: 1rpx solid #dcdcdc;
  225. padding: 0rpx 12rpx;
  226. color: #333333;
  227. &:last-child {
  228. margin-top: 50rpx;
  229. }
  230. .input {
  231. flex: 1;
  232. padding-right: 48rpx;
  233. font-size: 28rpx;
  234. font-family: Microsoft YaHei;
  235. }
  236. .arror {
  237. width: 28rpx;
  238. height: 25rpx;
  239. margin-left: 16rpx;
  240. margin-right: 40rpx;
  241. }
  242. .eye {
  243. width: 48rpx;
  244. height: 48rpx;
  245. }
  246. }
  247. .form-placeholder {
  248. color: #999999;
  249. }
  250. }
  251. .btn {
  252. width: 100%;
  253. margin: 120rpx 40rpx 50rpx;
  254. }
  255. .agreement {
  256. font-size: 24rpx;
  257. display: flex;
  258. align-items: center;
  259. .txt-grey {
  260. color: #666666;
  261. }
  262. .txt-green {
  263. color: #00b38b;
  264. }
  265. :deep(.u-checkbox) {
  266. margin-right: -20rpx;
  267. }
  268. }
  269. .btns {
  270. width: 100%;
  271. margin-top: 125rpx;
  272. justify-content: space-around;
  273. padding: 0px 8rpx;
  274. .bg {
  275. width: 80rpx;
  276. height: 80rpx;
  277. border-radius: 50%;
  278. .img {
  279. width: 48rpx;
  280. height: 48rpx;
  281. }
  282. }
  283. .blue {
  284. background-color: #1d9cff;
  285. }
  286. .orange {
  287. background-color: #feb654;
  288. }
  289. .purple {
  290. background-color: #8060ff;
  291. }
  292. .label {
  293. font-size: 26rpx;
  294. color: #333333;
  295. margin-top: 30rpx;
  296. }
  297. }
  298. }
  299. </style>