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

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