您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

login.vue 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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, data) => {
  182. const options = {
  183. type: 2,
  184. data: data,
  185. method: "POST",
  186. showLoading: true,
  187. };
  188. request(code, options).then((res) => {
  189. fetchToken(stringToJson(res.bizContent).code).then((data) => {
  190. setItem("phone", data.mobile);
  191. msg("登录成功!");
  192. uni.$emit("refreshOrder");
  193. uni.navigateBack();
  194. });
  195. });
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .login-main {
  200. border-top: 1rpx solid #dcdcdc;
  201. padding: 22rpx 30rpx 140rpx;
  202. .logo {
  203. width: 260rpx;
  204. height: 160rpx;
  205. }
  206. .title {
  207. font-size: 46rpx;
  208. color: #333333;
  209. margin-top: 30rpx;
  210. font-weight: 600;
  211. }
  212. .form {
  213. width: 100%;
  214. margin-top: 100rpx;
  215. .form-input {
  216. display: flex;
  217. flex-direction: row;
  218. align-items: center;
  219. height: 90rpx;
  220. border-bottom: 1rpx solid #dcdcdc;
  221. padding: 0rpx 12rpx;
  222. color: #333333;
  223. &:last-child {
  224. margin-top: 50rpx;
  225. }
  226. .input {
  227. flex: 1;
  228. padding-right: 48rpx;
  229. font-size: 28rpx;
  230. font-family: Microsoft YaHei;
  231. }
  232. .arror {
  233. width: 28rpx;
  234. height: 25rpx;
  235. margin-left: 16rpx;
  236. margin-right: 40rpx;
  237. }
  238. .eye {
  239. width: 48rpx;
  240. height: 48rpx;
  241. }
  242. }
  243. .form-placeholder {
  244. color: #999999;
  245. }
  246. }
  247. .btn {
  248. width: 100%;
  249. margin: 120rpx 40rpx 50rpx;
  250. }
  251. .agreement {
  252. font-size: 24rpx;
  253. display: flex;
  254. align-items: center;
  255. .txt-grey {
  256. color: #666666;
  257. }
  258. .txt-green {
  259. color: #00b38b;
  260. }
  261. :deep(.u-checkbox) {
  262. margin-right: -20rpx;
  263. }
  264. }
  265. .btns {
  266. width: 100%;
  267. margin-top: 125rpx;
  268. justify-content: space-around;
  269. padding: 0px 8rpx;
  270. .bg {
  271. width: 80rpx;
  272. height: 80rpx;
  273. border-radius: 50%;
  274. .img {
  275. width: 48rpx;
  276. height: 48rpx;
  277. }
  278. }
  279. .blue {
  280. background-color: #1d9cff;
  281. }
  282. .orange {
  283. background-color: #feb654;
  284. }
  285. .purple {
  286. background-color: #8060ff;
  287. }
  288. .label {
  289. font-size: 26rpx;
  290. color: #333333;
  291. margin-top: 30rpx;
  292. }
  293. }
  294. }
  295. </style>