index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div class="login-container">
  3. <div class="login-form-main">
  4. <img src="@/assets/sheji/loginlan.png" alt="" />
  5. <div class="main-title">
  6. <h1>欢迎登录</h1>
  7. <h3>采销平台</h3>
  8. </div>
  9. <el-form
  10. ref="loginForm"
  11. :model="loginForm"
  12. :rules="loginRules"
  13. class="login-form"
  14. autocomplete="on"
  15. label-position="left"
  16. >
  17. <div class="title-container">
  18. <h3 class="title">
  19. 采销平台<span>{{ ver }}</span>
  20. </h3>
  21. </div>
  22. <el-form-item prop="username">
  23. <span class="svg-container">
  24. <i class="el-icon-user"></i>
  25. </span>
  26. <el-input
  27. ref="username"
  28. v-model="loginForm.username"
  29. placeholder="手机号"
  30. name="username"
  31. type="text"
  32. tabindex="1"
  33. maxlength="11"
  34. autocomplete="on"
  35. />
  36. </el-form-item>
  37. <el-tooltip
  38. v-model="capsTooltip"
  39. content="Caps lock is On"
  40. placement="right"
  41. manual
  42. >
  43. <el-form-item prop="password">
  44. <span class="svg-container">
  45. <i class="el-icon-unlock"></i>
  46. </span>
  47. <el-input
  48. :key="passwordType"
  49. ref="password"
  50. v-model="loginForm.password"
  51. :type="passwordType"
  52. placeholder="密码"
  53. name="password"
  54. tabindex="2"
  55. autocomplete="on"
  56. maxlength="16"
  57. @keyup.native="checkCapslock"
  58. @blur="capsTooltip = false"
  59. @keyup.enter.native="handleLogin"
  60. />
  61. <span class="show-pwd" @click="showPwd">
  62. <svg-icon
  63. :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  64. />
  65. </span>
  66. </el-form-item>
  67. </el-tooltip>
  68. <el-button
  69. :loading="loading"
  70. :disabled="loading"
  71. type="primary"
  72. style="width: 100%; margin-top: 5px"
  73. @click.native.prevent="handleLogin()"
  74. >登&nbsp;&nbsp;&nbsp;&nbsp;录</el-button
  75. >
  76. <div style="position: relative; padding: 12px 0 0 0">
  77. <div class="tips" style="float: left">
  78. <el-popover
  79. placement="top"
  80. title="初始密码:"
  81. width="200"
  82. trigger="click"
  83. content="dingding123"
  84. >
  85. <i class="el-icon-info" slot="reference"></i>
  86. </el-popover>
  87. </div>
  88. <!-- <router-link to="/forget-password">
  89. <div class="tips" style="float: right">
  90. <span>忘记密码</span>
  91. </div>
  92. </router-link> -->
  93. </div>
  94. </el-form>
  95. </div>
  96. <div class="beian">
  97. <span>万宇恒通</span>
  98. <a target="_blank" href="https://beian.miit.gov.cn/"
  99. >京ICP备2020033956号-1</a
  100. >
  101. <span> </span>
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import asyncRequest from "@/apis/service/user";
  107. import resToken from "@/mixins/resToken";
  108. import {
  109. isnumber,
  110. isAlphanumeric,
  111. validAlphabets,
  112. isMobile,
  113. } from "@/utils/validate";
  114. export default {
  115. name: "Login",
  116. mixins: [resToken],
  117. data() {
  118. const validateUsername = (rule, value, callback) => {
  119. if (value === "") {
  120. callback(new Error("手机号不能为空!"));
  121. } else {
  122. if (!isMobile(value)) {
  123. callback(new Error("请输入正确的手机号"));
  124. } else {
  125. callback();
  126. }
  127. }
  128. };
  129. const validatePassword = (rule, value, callback) => {
  130. if (value === "") {
  131. callback(new Error("密码不能为空!"));
  132. } else {
  133. if (!isAlphanumeric(value)) {
  134. callback(new Error("密码为6-18位数字字母组合!"));
  135. } else if (value.length < 6 || value.length > 18) {
  136. callback(new Error("密码为6-18位数字字母组合!"));
  137. } else if (isnumber(value)) {
  138. callback(new Error("密码不能为纯数字!"));
  139. } else if (validAlphabets(value)) {
  140. callback(new Error("密码不能为纯字母!"));
  141. } else {
  142. callback();
  143. }
  144. }
  145. };
  146. return {
  147. ver: "",
  148. show: false,
  149. loginForm: {
  150. username: "",
  151. password: "",
  152. },
  153. loginRules: {
  154. username: [
  155. { required: true, trigger: "blur", validator: validateUsername },
  156. ],
  157. password: [
  158. { required: true, trigger: "blur", validator: validatePassword },
  159. ],
  160. },
  161. passwordType: "password",
  162. capsTooltip: false,
  163. loading: false,
  164. showDialog: false,
  165. redirect: undefined,
  166. otherQuery: {},
  167. };
  168. },
  169. watch: {
  170. $route: {
  171. handler: function (route) {
  172. const query = route.query;
  173. if (query) {
  174. this.redirect = query.redirect;
  175. this.otherQuery = this.getOtherQuery(query);
  176. }
  177. },
  178. immediate: true,
  179. },
  180. },
  181. mounted() {
  182. // console.log(process.env.NODE_ENV);
  183. // if (process.env.NODE_ENV === "development") {
  184. // this.loginForm = {
  185. // username: "17744520491",
  186. // password: "mlp123",
  187. // };
  188. // }
  189. // this.getversion();
  190. if (this.loginForm.username === "") {
  191. this.$refs.username.focus();
  192. } else if (this.loginForm.password === "") {
  193. this.$refs.password.focus();
  194. }
  195. },
  196. methods: {
  197. async getversion() {
  198. let res = await asyncRequest.version({});
  199. if (res && res.code === 0) {
  200. let data = res.data;
  201. this.ver = data.version;
  202. } else if (res && res.code >= 100 && res.code <= 104) {
  203. await this.logout();
  204. } else {
  205. this.$message.warning(res.message);
  206. }
  207. },
  208. setVisible(val) {
  209. this.show = val;
  210. },
  211. handleClick() {
  212. this.show = true;
  213. },
  214. handleSuccess() {
  215. this.show = false;
  216. this.handleLogin();
  217. },
  218. checkCapslock(e) {
  219. const { key } = e;
  220. this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
  221. },
  222. showPwd() {
  223. if (this.passwordType === "password") {
  224. this.passwordType = "";
  225. } else {
  226. this.passwordType = "password";
  227. }
  228. this.$nextTick(() => {
  229. this.$refs.password.focus();
  230. });
  231. },
  232. handleLogin() {
  233. this.$refs.loginForm.validate((valid) => {
  234. if (valid) {
  235. this.loading = true;
  236. this.$store
  237. .dispatch("user/login", this.loginForm)
  238. .then((res) => {
  239. if (res.code === 0) {
  240. // this.$router.push({
  241. // path: this.redirect || "/",
  242. // query: this.otherQuery,
  243. // });
  244. this.getMenu();
  245. } else {
  246. this.$message.warning(res.message);
  247. this.loading = false;
  248. }
  249. })
  250. .catch((err) => {
  251. console.log(err);
  252. this.loading = false;
  253. });
  254. } else {
  255. console.log("error submit!!");
  256. return false;
  257. }
  258. });
  259. },
  260. getMenu() {
  261. this.$store
  262. .dispatch("user/getMenuList", this)
  263. .then((res) => {
  264. console.log(res);
  265. window.vm.$router.push({
  266. path:
  267. this.redirect || res === "success-dataV"
  268. ? "/bigScreen/datavScr"
  269. : "/welcome",
  270. query: this.otherQuery,
  271. });
  272. this.loading = false;
  273. })
  274. .catch((err) => {
  275. this.loading = false;
  276. });
  277. },
  278. getOtherQuery(query) {
  279. return Object.keys(query).reduce((acc, cur) => {
  280. if (cur !== "redirect") {
  281. acc[cur] = query[cur];
  282. }
  283. return acc;
  284. }, {});
  285. },
  286. },
  287. };
  288. </script>
  289. <style lang="scss">
  290. /* 修复input 背景不协调 和光标变色 */
  291. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  292. $bg: #283443;
  293. $light_gray: #fff;
  294. $cursor: #fff;
  295. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  296. .login-container .el-input input {
  297. color: $cursor;
  298. }
  299. }
  300. /* reset element-ui css */
  301. .login-container {
  302. .el-input {
  303. display: inline-block;
  304. height: 47px;
  305. width: 85%;
  306. input {
  307. background: transparent;
  308. border: 0px;
  309. -webkit-appearance: none;
  310. border-radius: 0px;
  311. padding: 12px 5px 12px 15px;
  312. color: #232323;
  313. height: 47px;
  314. // caret-color: $cursor;
  315. &:-webkit-autofill {
  316. // box-shadow: 0 0 0px 1000px $bg inset !important;
  317. // -webkit-text-fill-color: $cursor !important;
  318. }
  319. }
  320. }
  321. .el-form-item {
  322. border: 1px solid #e9e9e9;
  323. // background: rgba(0, 0, 0, 0.1);
  324. border-radius: 5px;
  325. color: #232323;
  326. }
  327. }
  328. </style>
  329. <style lang="scss" scoped>
  330. $bg: #2d3a4b;
  331. $dark_gray: #38c1e7;
  332. $light_gray: #f2f2f2;
  333. .login-container {
  334. position: fixed;
  335. top: 0;
  336. left: 0;
  337. width: 100%;
  338. height: 100%;
  339. min-width: 1000px;
  340. min-height: 700px;
  341. z-index: 2;
  342. zoom: 1;
  343. background-repeat: no-repeat;
  344. background-size: cover;
  345. background-position: center 0;
  346. background-image: url("~@/assets/sheji/loginbg.png");
  347. text-align: center;
  348. .login-form-main {
  349. display: inline-block;
  350. width: 600px;
  351. height: 500px;
  352. margin: 26vh auto 0 auto;
  353. position: relative;
  354. img {
  355. width: 400px;
  356. height: 350px;
  357. }
  358. .main-title {
  359. position: absolute;
  360. top: 0;
  361. left: 0;
  362. z-index: 2;
  363. left: 170px;
  364. top: 125px;
  365. text-align: left;
  366. color: #fff;
  367. h1 {
  368. padding: 0 0 13px 0;
  369. }
  370. h3 {
  371. font-size: 22px;
  372. }
  373. }
  374. .login-form {
  375. position: absolute;
  376. width: 320px;
  377. top: -20px;
  378. left: 380px;
  379. z-index: 3;
  380. max-width: 100%;
  381. padding: 60px 28px 20px 28px;
  382. margin: 0 auto;
  383. overflow: hidden;
  384. background: #fff;
  385. border-radius: 20px;
  386. .el-button--primary {
  387. background-color: #38c1e7;
  388. border-color: #38c1e7;
  389. height: 46px;
  390. font-size: 16px;
  391. text-align: center;
  392. }
  393. }
  394. }
  395. // min-height: 100%;
  396. // width: 100%;
  397. // background-color: $bg;
  398. // overflow: hidden;
  399. .beian {
  400. position: absolute;
  401. width: 100%;
  402. bottom: 60px;
  403. color: #343434;
  404. font-size: 12px;
  405. padding: 0 0 0 15%;
  406. span {
  407. padding: 0 10px;
  408. }
  409. a {
  410. display: inline-block;
  411. color: #343434;
  412. vertical-align: top;
  413. font-size: 12px;
  414. &:hover {
  415. text-decoration: underline;
  416. text-decoration-color: #343434;
  417. }
  418. }
  419. }
  420. .tips {
  421. font-size: 14px;
  422. color: #04a2ce;
  423. margin-bottom: 10px;
  424. span {
  425. &:first-of-type {
  426. margin-right: 8px;
  427. }
  428. }
  429. i {
  430. font-size: 20px;
  431. margin: 0 0 0 7px;
  432. }
  433. }
  434. .puzzle-box {
  435. position: absolute;
  436. top: 200px;
  437. }
  438. .svg-container {
  439. padding: 6px 5px 6px 6px;
  440. color: #38c1e7;
  441. vertical-align: middle;
  442. width: 30px;
  443. display: inline-block;
  444. }
  445. .title-container {
  446. position: relative;
  447. .title {
  448. font-size: 26px;
  449. color: #04a2ce;
  450. margin: 0px auto 40px auto;
  451. text-align: center;
  452. font-weight: bold;
  453. span {
  454. display: inline-block;
  455. font-size: 18px;
  456. vertical-align: top;
  457. padding: 10px 0 0 4px;
  458. }
  459. }
  460. }
  461. .show-pwd {
  462. position: absolute;
  463. right: 10px;
  464. top: 7px;
  465. font-size: 16px;
  466. color: $dark_gray;
  467. cursor: pointer;
  468. user-select: none;
  469. }
  470. .thirdparty-button {
  471. position: absolute;
  472. right: 0;
  473. bottom: 6px;
  474. }
  475. @media only screen and (max-width: 470px) {
  476. .thirdparty-button {
  477. display: none;
  478. }
  479. }
  480. }
  481. </style>