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 9.0KB

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