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.8KB

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