Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

login.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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" class="group">
  57. <checkbox
  58. :checked="state.checked"
  59. color="#00B38B"
  60. size="30"
  61. icon-size="30"
  62. label-size="24"
  63. style="transform:scale(0.85)"
  64. >
  65. </checkbox>
  66. <label>我已阅读并同意</label>
  67. </checkbox-group>
  68. <!-- <view class="txt-grey">我已阅读并同意</view> -->
  69. <view class="txt-green" @click="toRead"
  70. >《平台用户服务隐私协议》</view
  71. >
  72. </view>
  73. <view class="btns as-layout-horizontal">
  74. <view
  75. class="as-layout-vertical as-gravity-center"
  76. @click="navTo('/login/register-step1')"
  77. >
  78. <view class="bg blue as-gravity-center">
  79. <image :src="`${$imgUrl}login/icon_register.png`" class="img" />
  80. </view>
  81. <view class="label">注册账号</view>
  82. </view>
  83. <view
  84. class="as-layout-vertical as-gravity-center"
  85. @click="
  86. state.loginType === 'pwd'
  87. ? (state.loginType = 'code')
  88. : (state.loginType = 'pwd')
  89. "
  90. >
  91. <view class="bg orange as-gravity-center">
  92. <image :src="`${$imgUrl}login/icon_code.png`" class="img" />
  93. </view>
  94. <view class="label">{{
  95. state.loginType === "pwd" ? "验证码登录" : "密码登录"
  96. }}</view>
  97. </view>
  98. <view
  99. class="as-layout-vertical as-gravity-center"
  100. @click="navTo('/login/forget-pwd-step1')"
  101. >
  102. <view class="bg purple as-gravity-center">
  103. <image :src="`${$imgUrl}login/icon_pwd.png`" class="img" />
  104. </view>
  105. <view class="label">忘记密码</view>
  106. </view>
  107. </view>
  108. </view>
  109. </template>
  110. <script setup lang="ts">
  111. import { reactive } from "vue";
  112. import { checkStr, msg, navTo } from "@/utils/utils";
  113. import { onLoad, onUnload } from "@dcloudio/uni-app";
  114. import { login, loginCode, loginTime } from "@/utils/network/api.js";
  115. import { request } from "@/utils/network/request.js";
  116. import { stringToJson } from "@/utils/network/encryption";
  117. import { useUserStore } from "@/stores/user";
  118. import { setItem } from "@/utils/storage";
  119. const userStore = useUserStore();
  120. const { fetchToken } = userStore;
  121. const state = reactive({
  122. checked: false, //是否勾选协议
  123. isPwdType: true, //是不是密码类型
  124. loginType: "pwd", //pwd-密码登录 code-验证码登录
  125. username: "", //用户名
  126. password: "", //密码
  127. code: "", //验证码
  128. });
  129. onLoad(() => {
  130. uni.$on("login", (data) => {
  131. state.username = data.phone;
  132. });
  133. });
  134. onUnload(() => {
  135. uni.$off("login");
  136. });
  137. const checkboxChange = (e) => {
  138. console.log(e);
  139. state.checked = !state.checked;
  140. };
  141. // 去协议页面
  142. const toRead=()=>{
  143. navTo("/login/agreement")
  144. }
  145. /* 登录 */
  146. const doLogin = () => {
  147. if (!state.username) {
  148. msg("请输入手机号!");
  149. return;
  150. }
  151. if (state.loginType === "pwd" && !state.password) {
  152. msg("请输入密码!");
  153. return;
  154. }
  155. if (state.loginType === "code" && !state.code) {
  156. msg("请输入验证码!");
  157. return;
  158. }
  159. if (!checkStr(state.username, "mobile")) {
  160. msg("请输入正确的手机号!");
  161. return;
  162. }
  163. if (!state.checked) {
  164. msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  165. return;
  166. }
  167. //判断是验证码登录,还是账号密码登录
  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:string, data:object) => {
  184. console.log(code,data);
  185. const options = {
  186. type: 2,
  187. data: data,
  188. method: "POST",
  189. showLoading: true,
  190. };
  191. request(code, options).then((res) => {
  192. const result = stringToJson(res.bizContent);
  193. console.log(result);
  194. console.log(typeof(result));
  195. fetchToken(result.code).then((data:any) => {
  196. console.log("登录",data);
  197. msg("登录成功!");
  198. uni.$emit("refreshOrder");
  199. uni.navigateBack();
  200. });
  201. });
  202. };
  203. </script>
  204. <style lang="scss" scoped>
  205. .login-main {
  206. border-top: 1rpx solid #dcdcdc;
  207. padding: 22rpx 30rpx 140rpx;
  208. .logo {
  209. width: 260rpx;
  210. height: 160rpx;
  211. }
  212. .group{
  213. display: flex;
  214. align-items: center;
  215. }
  216. .title {
  217. font-size: 46rpx;
  218. color: #333333;
  219. margin-top: 30rpx;
  220. font-weight: 600;
  221. }
  222. .form {
  223. width: 100%;
  224. margin-top: 100rpx;
  225. .form-input {
  226. display: flex;
  227. flex-direction: row;
  228. align-items: center;
  229. height: 90rpx;
  230. border-bottom: 1rpx solid #dcdcdc;
  231. padding: 0rpx 12rpx;
  232. color: #333333;
  233. &:last-child {
  234. margin-top: 50rpx;
  235. }
  236. .input {
  237. flex: 1;
  238. padding-right: 48rpx;
  239. font-size: 28rpx;
  240. font-family: Microsoft YaHei;
  241. }
  242. .arror {
  243. width: 28rpx;
  244. height: 25rpx;
  245. margin-left: 16rpx;
  246. margin-right: 40rpx;
  247. }
  248. .eye {
  249. width: 48rpx;
  250. height: 48rpx;
  251. }
  252. }
  253. .form-placeholder {
  254. color: #999999;
  255. }
  256. }
  257. .btn {
  258. width: 100%;
  259. margin: 120rpx 40rpx 50rpx;
  260. }
  261. .agreement {
  262. font-size: 24rpx;
  263. display: flex;
  264. align-items: center;
  265. .txt-grey {
  266. color: #666666;
  267. }
  268. .txt-green {
  269. color: #00b38b;
  270. }
  271. :deep(.u-checkbox) {
  272. margin-right: -20rpx;
  273. }
  274. }
  275. .btns {
  276. width: 100%;
  277. margin-top: 125rpx;
  278. justify-content: space-around;
  279. padding: 0px 8rpx;
  280. .bg {
  281. width: 80rpx;
  282. height: 80rpx;
  283. border-radius: 50%;
  284. .img {
  285. width: 48rpx;
  286. height: 48rpx;
  287. }
  288. }
  289. .blue {
  290. background-color: #1d9cff;
  291. }
  292. .orange {
  293. background-color: #feb654;
  294. }
  295. .purple {
  296. background-color: #8060ff;
  297. }
  298. .label {
  299. font-size: 26rpx;
  300. color: #333333;
  301. margin-top: 30rpx;
  302. }
  303. }
  304. }
  305. </style>