Login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <div class="login">
  3. <div id="udb_login">
  4. <div class="title">
  5. 登录
  6. <Back />
  7. </div>
  8. <div class="login_input" @keyup.enter="login">
  9. <!-- 手机号/账号 -->
  10. <div class="login_username">
  11. <!-- <i class="iconfont icon-ziyuan"></i> -->
  12. <input
  13. class="login_input_username"
  14. placeholder="请输入手机号/账号登录"
  15. compositionstart="compositionnstartInput"
  16. @input="passportKeyup"
  17. @focus="onAccountFocus"
  18. v-model="account"
  19. />
  20. <!-- 记住密码的所有账密列表 -->
  21. <ul
  22. class="account_list"
  23. v-show="isShowAccount && !account && accountList.length > 0"
  24. >
  25. <li v-for="(item, index) in accountList" :key="index">
  26. <span @click="selectAccount(item.account, item.pwd)">
  27. {{ item.account }}
  28. </span>
  29. <i
  30. class="iconfont icon-baseline-close-px"
  31. @click="deleteAccount(index)"
  32. ></i>
  33. </li>
  34. </ul>
  35. </div>
  36. <!-- 密码 -->
  37. <div class="login_password">
  38. <!-- <i class="iconfont icon-mima"></i> -->
  39. <input
  40. class="login_input_password"
  41. type="password"
  42. password="true"
  43. maxlength="20"
  44. oninput="value=value.replace(/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]|\s+|[^\w\u4e00-\u9fa5\/\-]|[/|]/ig,'');"
  45. placeholder="请输入密码"
  46. v-model="password"
  47. />
  48. </div>
  49. </div>
  50. <!-- 记住密码 -->
  51. <div class="login_other">
  52. <p class="login_remember">
  53. <input
  54. id="is_remember"
  55. class="login_input_remember"
  56. type="checkbox"
  57. v-model="isChecked"
  58. value="true"
  59. />
  60. <label for="is_remember">记住密码</label>
  61. </p>
  62. <!-- <div @click="onForgetClick" class="login_forget">忘记密码</div> -->
  63. </div>
  64. <!-- 登录按钮 -->
  65. <div v-if="canLogin" class="login_true" @click="login">登录</div>
  66. <div v-else class="login_true gray">正在登录</div>
  67. <!-- 联系客服 -->
  68. <span class="service" @click="onService">遇到问题? 联系客服</span>
  69. <!-- 其他 -->
  70. <div class="other">
  71. <span class="left" @click="onVisitor">快速登录</span>
  72. <span class="right" @click="onReg">没有账号?去注册</span>
  73. </div>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import { mapActions, mapState } from "vuex";
  79. import Back from "@/components/Inner/Back"; // 返回
  80. export default {
  81. name: "Login",
  82. components: {
  83. Back,
  84. },
  85. inject: [
  86. "checkCode",
  87. "getFinance",
  88. "routeLink",
  89. "onQuickHandler",
  90. "loginUtil",
  91. ],
  92. data() {
  93. return {
  94. isChecked: true, //记住密码是否选中
  95. account: "", //获取用户名的值
  96. password: "", //获取密码的值
  97. isShowAccount: false, // 是否显示账密列表
  98. accountList: [], // 账密列表
  99. accountLocal: [], // 本地存储的账密
  100. canLogin: true, // 登录按钮防抖
  101. };
  102. },
  103. computed: {
  104. ...mapState(["query", "appid", "platform"]),
  105. },
  106. watch: {},
  107. created() {},
  108. mounted() {
  109. // 初始化操作
  110. this.init();
  111. },
  112. methods: {
  113. ...mapActions(["userInfoAction"]),
  114. // 初始化操作
  115. init() {
  116. // 初始化账密列表内容
  117. this.initAccountList();
  118. },
  119. // ios中文输入
  120. compositionstartInput() {
  121. this.account = "";
  122. },
  123. // 账号 输入
  124. passportKeyup() {
  125. this.account = this.account.replace(
  126. /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]|\s+|[^\w\u4e00-\u9fa5\/\-]|[/|]/gi,
  127. ""
  128. );
  129. },
  130. // 初始化账密列表
  131. initAccountList() {
  132. // const accountLocal = JSON.parse(localStorage.getItem("jhremember"));
  133. let accountLocal = this.$utils.readStorage("", "jhremember");
  134. accountLocal = accountLocal && JSON.parse(accountLocal);
  135. accountLocal &&
  136. accountLocal.length &&
  137. accountLocal.map((ele) => {
  138. const _account = ele.split("&&")[0];
  139. const _pwd = ele.split("&&")[1];
  140. const account = this.$utils.decrypt(_account);
  141. const pwd = this.$utils.decrypt(_pwd);
  142. this.accountList.push({
  143. account,
  144. pwd,
  145. });
  146. });
  147. // 填充账号密码
  148. if (accountLocal && accountLocal.length) {
  149. this.account = this.accountList[0].account;
  150. this.password = this.accountList[0].pwd;
  151. }
  152. },
  153. //登录
  154. login() {
  155. const { account, password } = this;
  156. // 1. 账号校验
  157. if (!account) {
  158. this.$toast.text("账号不能为空");
  159. return;
  160. }
  161. // 2. 密码是否为空
  162. if (!password) {
  163. this.$toast.text("密码不能为空");
  164. return;
  165. }
  166. // 3. 登录接口
  167. this.onLogin();
  168. },
  169. // 忘记密码
  170. onForgetClick() {
  171. this.routeLink("Forget");
  172. },
  173. // 账密格式正确, 进行登录
  174. onLogin() {
  175. // 登录接口
  176. const { account, password, isChecked } = this;
  177. if (!this.canLogin) {
  178. return;
  179. }
  180. this.canLogin = false;
  181. this.$api
  182. .login({
  183. passport: account,
  184. password,
  185. })
  186. .then((res) => {
  187. this.checkCode(res);
  188. this.canLogin = true;
  189. const { data, code } = res.data;
  190. // 错误
  191. if (code) {
  192. return;
  193. }
  194. // 成功
  195. // 存储信息
  196. this.$utils.writeStorage("", "userInfo", JSON.stringify(data));
  197. this.userInfoAction(data);
  198. // 1. 记住密码
  199. if (isChecked) {
  200. this.rememberFun(account, password);
  201. }
  202. // 根据当前环境去做不同事情的登录工具函数
  203. this.loginUtil(data);
  204. });
  205. },
  206. // 账号/手机号 聚焦
  207. onAccountFocus() {
  208. this.isShowAccount = true;
  209. },
  210. // 选择登录账号
  211. selectAccount(account, pwd) {
  212. this.account = account;
  213. this.password = pwd;
  214. },
  215. // 删除账号密码
  216. deleteAccount(accountIndex) {
  217. this.accountList.splice(accountIndex, 1);
  218. // const accountLocal = JSON.parse(localStorage.getItem("jhremember"));
  219. let accountLocal = this.$utils.readStorage("", "jhremember");
  220. accountLocal = JSON.parse(accountLocal);
  221. accountLocal.splice(accountIndex, 1);
  222. // localStorage.setItem("jhremember", JSON.stringify(accountLocal));
  223. this.$utils.writeStorage("", "jhremember", JSON.stringify(accountLocal));
  224. },
  225. // 快速登录
  226. onVisitor() {
  227. this.onQuickHandler();
  228. },
  229. // 注册
  230. onReg() {
  231. this.routeLink("Reg");
  232. },
  233. // 登录成功
  234. toHome() {
  235. this.routeLink("Home");
  236. },
  237. // 记住密码
  238. rememberFun(account, password) {
  239. this.accountList = this.$utils.rememberFun(account, password);
  240. },
  241. // 联系客服
  242. onService() {
  243. this.$emit("showInnerControl", "service");
  244. },
  245. },
  246. };
  247. </script>
  248. <style lang="less">
  249. .login {
  250. position: absolute;
  251. top: 0;
  252. left: 0;
  253. right: 0;
  254. bottom: 0;
  255. background-color: rgba(0, 0, 0, 0.6);
  256. }
  257. #udb_login {
  258. width: 700 / @rem;
  259. height: 600 / @rem;
  260. position: absolute;
  261. top: 50%;
  262. left: 50%;
  263. margin-left: -350 / @rem;
  264. margin-top: -300 / @rem;
  265. font-size: 32 / @rem;
  266. background-color: #fff;
  267. box-sizing: border-box;
  268. border-radius: 5px;
  269. overflow: hidden;
  270. input {
  271. outline: none;
  272. }
  273. .title {
  274. height: 100 / @rem;
  275. line-height: 100 / @rem;
  276. background-color: #3faeed;
  277. color: #fff;
  278. font-size: 36 / @rem;
  279. }
  280. .login_input,
  281. .login_other,
  282. .login_true,
  283. .other {
  284. padding: 0 / @rem 30 / @rem;
  285. box-sizing: border-box;
  286. }
  287. .login_input {
  288. width: 100%;
  289. margin-top: 20 / @rem;
  290. }
  291. .login_username,
  292. .login_password {
  293. width: 100%;
  294. height: 90 / @rem;
  295. position: relative;
  296. }
  297. .login_username {
  298. .account_list {
  299. width: 100%;
  300. max-height: 305 / @rem;
  301. position: absolute;
  302. top: 100%;
  303. z-index: 5;
  304. margin-top: -1px;
  305. background-color: #e4e4e4;
  306. border: 1px solid #cecece;
  307. box-sizing: border-box;
  308. overflow-y: auto;
  309. li {
  310. height: 60 / @rem;
  311. line-height: 60 / @rem;
  312. padding: 0 20 / @rem;
  313. border-bottom: 1px solid #dadada;
  314. &:last-child {
  315. border-bottom: 0;
  316. }
  317. span {
  318. float: left;
  319. width: 80%;
  320. }
  321. i {
  322. float: right;
  323. }
  324. }
  325. }
  326. }
  327. .icon-ziyuan,
  328. .icon-mima {
  329. width: 50 / @rem;
  330. height: 90 / @rem;
  331. line-height: 90 / @rem;
  332. position: absolute;
  333. left: 5 / @rem;
  334. z-index: 5;
  335. }
  336. .login_password {
  337. margin-top: 20 / @rem;
  338. }
  339. .login_input_username,
  340. .login_input_password {
  341. width: 100%;
  342. height: 100%;
  343. border: 1 / @rem solid #d6d6d6;
  344. box-sizing: border-box;
  345. position: absolute;
  346. left: 0;
  347. z-index: 4;
  348. font-size: 32 / @rem;
  349. padding-left: 20 / @rem;
  350. }
  351. input::-webkit-input-placeholder {
  352. color: #888;
  353. }
  354. .login_other {
  355. width: 100%;
  356. height: 50 / @rem;
  357. margin-top: 20 / @rem;
  358. }
  359. .login_remember,
  360. .login_forget {
  361. color: #3faeed;
  362. font-size: 30 / @rem;
  363. width: 290 / @rem;
  364. height: 40 / @rem;
  365. line-height: 40 / @rem;
  366. display: inline-block;
  367. }
  368. .login_input_remember {
  369. position: relative;
  370. top: 4 / @rem;
  371. -webkit-appearance: checkbox;
  372. }
  373. .login_true {
  374. width: 80%;
  375. height: 80 / @rem;
  376. line-height: 80 / @rem;
  377. margin: auto;
  378. margin-top: 5 / @rem;
  379. border-radius: 20 / @rem;
  380. background-color: #3faeed;
  381. color: #ffffff;
  382. }
  383. .login_username_check,
  384. .login_password_check {
  385. font-size: 28 / @rem;
  386. color: #e43633;
  387. position: absolute;
  388. }
  389. .is_hide_username,
  390. .is_hide_password {
  391. display: none;
  392. }
  393. .service {
  394. margin-top: 15 / @rem;
  395. font-size: 28 / @rem;
  396. color: #3faeed;
  397. display: inline-block;
  398. border-bottom: 1px solid #3faeed;
  399. }
  400. .other {
  401. margin-top: 10 / @rem;
  402. color: #3faeed;
  403. font-size: 34 / @rem;
  404. .left {
  405. float: left;
  406. }
  407. .right {
  408. float: right;
  409. }
  410. }
  411. }
  412. // 横屏
  413. @media screen and (orientation: landscape),
  414. /**竖屏 */ all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px),
  415. /**ipad */ all and (min-device-aspect-ratio: 3/4) and (max-device-aspect-ratio: 4/3),
  416. all and (device-aspect-ratio: 4/3) {
  417. #udb_login {
  418. width: 350 / @rem;
  419. height: 300 / @rem;
  420. margin-left: -175 / @rem;
  421. margin-top: -150 / @rem;
  422. font-size: 16 / @rem;
  423. overflow-y: auto;
  424. .title {
  425. height: 50 / @rem;
  426. line-height: 50 / @rem;
  427. font-size: 18 / @rem;
  428. }
  429. .login_input,
  430. .login_other,
  431. .login_true,
  432. .other {
  433. padding: 0 / @rem 15 / @rem;
  434. }
  435. .login_input {
  436. margin-top: 10 / @rem;
  437. }
  438. .login_username,
  439. .login_password {
  440. height: 45 / @rem;
  441. }
  442. .login_username {
  443. .account_list {
  444. max-height: 152.5 / @rem;
  445. li {
  446. height: 30 / @rem;
  447. line-height: 30 / @rem;
  448. padding: 0 10 / @rem;
  449. }
  450. }
  451. }
  452. .login_password {
  453. margin-top: 10 / @rem;
  454. }
  455. .login_input_username,
  456. .login_input_password {
  457. border: 1 / @rem solid #d6d6d6;
  458. font-size: 16 / @rem;
  459. padding-left: 10 / @rem;
  460. }
  461. .login_other {
  462. height: 25 / @rem;
  463. margin-top: 10 / @rem;
  464. }
  465. .login_remember,
  466. .login_forget {
  467. width: 145 / @rem;
  468. height: 20 / @rem;
  469. line-height: 20 / @rem;
  470. font-size: 15 / @rem;
  471. }
  472. .login_input_remember {
  473. top: 2 / @rem;
  474. }
  475. .login_true {
  476. height: 40 / @rem;
  477. line-height: 40 / @rem;
  478. margin-top: 5 / @rem;
  479. border-radius: 10 / @rem;
  480. }
  481. .login_username_check,
  482. .login_password_check {
  483. font-size: 14 / @rem;
  484. }
  485. .service {
  486. margin-top: 5 / @rem;
  487. font-size: 14 / @rem;
  488. }
  489. .other {
  490. margin-top: 5 / @rem;
  491. font-size: 16 / @rem;
  492. }
  493. }
  494. }
  495. </style>