login.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="container">
  3. <div class="newLogin">
  4. <div class="login">
  5. <div>
  6. <img src="../../assets/login/newImg.png" alt style="width: 100%;" />
  7. </div>
  8. <div class="logo">
  9. <img src="../../assets/login/newLogo.png" alt />
  10. </div>
  11. <div class="reg">
  12. <div class="form">
  13. <ul>
  14. <li>
  15. <span class="iconfont">&#xe78b;</span>
  16. <input
  17. placeholder="请输入手机号"
  18. type="tel"
  19. class="tel"
  20. v-model="form.mobile"
  21. />
  22. </li>
  23. <li>
  24. <span class="iconfont">&#xe6c0;</span>
  25. <input
  26. placeholder="请输入密码"
  27. type="password"
  28. class="tel"
  29. v-model="form.pwd"
  30. />
  31. </li>
  32. </ul>
  33. </div>
  34. <!-- <router-link to="/product"> -->
  35. <div class="remember">
  36. <el-checkbox v-model="checked">记住密码</el-checkbox>
  37. </div>
  38. <!-- <button
  39. class="loginBtn"
  40. @click="loginAction"
  41. :class="loginDisable ? 'disableLoginBtn' : ''"
  42. :disabled="loginDisable"
  43. >
  44. 登录
  45. </button>-->
  46. <button
  47. class="loginBtn"
  48. @click="submitForm"
  49. :class="loginDisable ? 'disableLoginBtn' : ''"
  50. :disabled="loginDisable"
  51. >
  52. 登录
  53. </button>
  54. <!-- <router-link to="/forgetPassword">
  55. <div class="newForget">忘记密码</div>
  56. </router-link>-->
  57. <!-- </router-link> -->
  58. <!-- <div class="forget">
  59. <a href="">免密码登录</a>
  60. <a href="">忘记密码?</a>
  61. </div>-->
  62. </div>
  63. <div class="agree">
  64. <el-checkbox v-model="agreement">我已阅读并同意</el-checkbox>
  65. <span class="agreeText" @click="agree()">《隐私服务协议》</span>
  66. <span class="agreeText" @click="agree1()">《用户协议》</span>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import { loginByPwd } from "@/api/login";
  74. import { hex_md5 } from "@/utils/md5";
  75. import { getLoginInfoCache, cacheLoginInfo } from "@/utils/admin_info_cache";
  76. import { Toast } from "vant";
  77. export default {
  78. name: "Home",
  79. data() {
  80. return {
  81. form: {
  82. mobile: "",
  83. pwd: ""
  84. },
  85. checked: false,
  86. agreement: true
  87. };
  88. },
  89. computed: {
  90. loginDisable() {
  91. // return false
  92. return this.form.mobile.length == 0 || this.form.pwd.length == 0;
  93. }
  94. },
  95. created() {
  96. var loginInfo = getLoginInfoCache();
  97. this.form.mobile = loginInfo.mobile;
  98. this.form.pwd = loginInfo.password;
  99. },
  100. mounted() {
  101. this.getCookie();
  102. },
  103. methods: {
  104. loginAction: function() {
  105. loginByPwd(this.form.mobile, hex_md5(this.form.pwd)).then(rs => {
  106. var resp = rs.data;
  107. if (resp.state == 1) {
  108. cacheLoginInfo(this.form.mobile, this.form.pwd);
  109. console.log(resp);
  110. var user = resp.data.user;
  111. var org = resp.data.org;
  112. var subscibe = resp.data.subscibe;
  113. var config_list = resp.data.config_list;
  114. var template_info = resp.data.template_info;
  115. var filed_list = resp.data.filed_list;
  116. console.log(resp.data.filed_list);
  117. console.log(filed_list);
  118. this.$store.dispatch("InitUserInfo", {
  119. user: user,
  120. org: org,
  121. subscibe: subscibe,
  122. template_info: template_info,
  123. filed_list: filed_list
  124. });
  125. this.$store.dispatch("SetConfigList", config_list);
  126. // this.$router.push({path: "/product"})
  127. this.$router.push({ path: "/main" });
  128. } else {
  129. this.$toast({
  130. message: resp.msg
  131. });
  132. }
  133. });
  134. },
  135. to: function() {
  136. this.$router.push({ path: "/privacy" });
  137. },
  138. submitForm() {
  139. this.$router.push({ path: "/homeIndex" });
  140. },
  141. // submitForm() {
  142. // const self = this;
  143. // //判断复选框是否被勾选 勾选则调用配置cookie方法
  144. // if (self.checked == true) {
  145. // console.log("checked == true");
  146. // //传入账号名,密码,和保存天数3个参数
  147. // self.setCookie(self.form.mobile, self.form.pwd, 7);
  148. // } else {
  149. // console.log("清空Cookie");
  150. // //清空Cookie
  151. // self.clearCookie();
  152. // }
  153. //
  154. // //与后端请求代码,本功能不需要与后台交互所以省略
  155. //
  156. // loginByPwd(this.form.mobile, hex_md5(this.form.pwd)).then(rs => {
  157. // var resp = rs.data;
  158. // if (this.agreement != true) {
  159. // Toast("请同意隐私服务协议");
  160. // }
  161. //
  162. // if (resp.state == 1 && this.agreement == true) {
  163. // cacheLoginInfo(this.form.mobile, this.form.pwd);
  164. // console.log(resp);
  165. //
  166. // var user = resp.data.user;
  167. // var org = resp.data.org;
  168. // var subscibe = resp.data.subscibe;
  169. // var config_list = resp.data.config_list;
  170. // var template_info = resp.data.template_info;
  171. // var filed_list = resp.data.filed_list;
  172. // console.log(resp.data.filed_list);
  173. // console.log(filed_list);
  174. //
  175. // this.$store.dispatch("InitUserInfo", {
  176. // user: user,
  177. // org: org,
  178. // subscibe: subscibe,
  179. // template_info: template_info,
  180. // filed_list: filed_list
  181. // });
  182. // this.$store.dispatch("SetConfigList", config_list);
  183. //
  184. // // this.$router.push({path: "/product"})
  185. // this.$router.push({ path: "/main" });
  186. // } else {
  187. // this.$toast({
  188. // message: resp.msg
  189. // });
  190. // }
  191. // });
  192. // console.log("登陆成功");
  193. // },
  194. // 设置cookie
  195. setCookie(c_name, c_pwd, exdays) {
  196. var exdate = new Date(); // 获取时间
  197. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); // 保存的天数
  198. // 字符串拼接cookie
  199. window.document.cookie =
  200. "userName" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
  201. window.document.cookie =
  202. "userPwd" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
  203. },
  204. getCookie: function() {
  205. this.$nextTick(() => {
  206. if (this.form.pwd != "") {
  207. this.checked = true;
  208. }
  209. });
  210. if (document.cookie.length > 0) {
  211. var arr = document.cookie.split("; "); // 这里显示的格式需要切割一下自己可输出看下
  212. for (var i = 0; i < arr.length; i++) {
  213. var arr2 = arr[i].split("="); // 再次切割
  214. // 判断查找相对应的值
  215. if (arr2[0] == "userName") {
  216. this.form.mobile = arr2[1]; // 保存到保存数据的地方
  217. } else if (arr2[0] == "userPwd") {
  218. this.form.pwd = arr2[1];
  219. }
  220. }
  221. }
  222. },
  223. // 清除cookie
  224. clearCookie: function() {
  225. this.setCookie("", "", -1); // 修改2值都为空,天数为负1天就好了
  226. },
  227. agree() {
  228. this.$router.push({ path: "/privacy" });
  229. },
  230. agree1() {
  231. this.$router.push({ path: "/userAgreement" });
  232. }
  233. }
  234. };
  235. </script>
  236. <style rel="stylesheet/scss" lang="scss" scoped>
  237. .container {
  238. // background: $white-bg;
  239. background: #fff;
  240. @include box-sizing;
  241. position: fixed;
  242. width: 100%;
  243. height: 100%;
  244. display: flex;
  245. justify-content: space-between;
  246. .newLogin {
  247. width: 100%;
  248. height: 100%;
  249. margin: auto;
  250. // box-shadow: 0px 2px 25px 0px rgba(37, 143, 252, 0.1);
  251. background: #fff;
  252. }
  253. .login {
  254. // @include box-shadow;
  255. @include text-align;
  256. @include display-flex;
  257. @include align-items-center;
  258. // @include justify-content-center;
  259. @include flex-direction;
  260. height: 100%;
  261. overflow-y: auto;
  262. .logo {
  263. // padding: 3rem 0 2.5rem;
  264. padding: 0 0 0.5rem;
  265. img {
  266. width: 44%;
  267. height: auto;
  268. display: inline-block;
  269. }
  270. }
  271. .reg {
  272. width: 9.3rem;
  273. .welcome {
  274. text-align: left;
  275. font-size: 0.55rem;
  276. font-weight: 400;
  277. color: rgba(37, 143, 252, 1);
  278. margin-bottom: 0.5rem;
  279. // line-height: 14px;
  280. }
  281. .newForget {
  282. text-align: right;
  283. font-size: 0.45rem;
  284. font-weight: 400;
  285. color: rgba(37, 143, 252, 1);
  286. margin-top: 0.3rem;
  287. }
  288. .form {
  289. border: 1px $border-color solid;
  290. border-radius: 4px;
  291. li {
  292. border-bottom: 1px $border-color solid;
  293. @include align-items-center;
  294. @include text-align;
  295. @include display-flex;
  296. @include box-sizing;
  297. .tel {
  298. padding: 0.4rem 0;
  299. width: 90%;
  300. border: none;
  301. outline: none;
  302. font-size: 0.6rem;
  303. }
  304. .mint-cell {
  305. width: 100%;
  306. }
  307. &:last-child {
  308. border: none;
  309. }
  310. .iconfont {
  311. color: $main-color;
  312. font-size: 0.6rem;
  313. margin: 0 0.46rem;
  314. }
  315. }
  316. }
  317. .forget {
  318. text-align: left;
  319. padding: 0.45rem 1rem;
  320. a {
  321. float: left;
  322. font-size: 0.28rem;
  323. color: $main-color;
  324. &:nth-child(2) {
  325. color: #999999;
  326. float: right;
  327. }
  328. &:active {
  329. background: $white-bg;
  330. }
  331. }
  332. }
  333. .loginBtn {
  334. width: 100%;
  335. height: 1.4rem;
  336. line-height: 1.4rem;
  337. background: $main-color;
  338. color: #fff;
  339. font-size: 0.6rem;
  340. @include text-align;
  341. border-radius: 4px;
  342. margin: 1rem 0 0 0;
  343. }
  344. .disableLoginBtn {
  345. background: lightgray;
  346. }
  347. }
  348. }
  349. .remember {
  350. float: left;
  351. }
  352. .agreeText {
  353. color: #409eff;
  354. font-size: 14px;
  355. }
  356. }
  357. </style>
  358. <style lang="scss">
  359. .remember {
  360. .el-checkbox__inner {
  361. @media only screen and (min-width: 415px) and (max-width: 767px) {
  362. width: 20px;
  363. height: 20px;
  364. }
  365. @media only screen and (min-width: 768px) {
  366. width: 20px;
  367. height: 20px;
  368. }
  369. }
  370. .el-checkbox__inner::after {
  371. @media only screen and (min-width: 415px) and (max-width: 767px) {
  372. left: 7px;
  373. height: 12px;
  374. width: 4px;
  375. }
  376. @media only screen and (min-width: 768px) {
  377. left: 7px;
  378. height: 12px;
  379. width: 4px;
  380. }
  381. }
  382. .el-checkbox__label {
  383. @media only screen and (min-width: 415px) and (max-width: 767px) {
  384. font-size: 0.45rem;
  385. }
  386. @media only screen and (min-width: 768px) {
  387. font-size: 0.45rem;
  388. }
  389. }
  390. }
  391. .agree {
  392. .el-checkbox__inner {
  393. @media only screen and (min-width: 415px) and (max-width: 767px) {
  394. width: 20px;
  395. height: 20px;
  396. }
  397. @media only screen and (min-width: 768px) {
  398. width: 20px;
  399. height: 20px;
  400. }
  401. }
  402. .el-checkbox__inner::after {
  403. @media only screen and (min-width: 415px) and (max-width: 767px) {
  404. left: 7px;
  405. height: 12px;
  406. width: 4px;
  407. }
  408. @media only screen and (min-width: 768px) {
  409. left: 7px;
  410. height: 12px;
  411. width: 4px;
  412. }
  413. }
  414. .el-checkbox__label {
  415. @media only screen and (min-width: 415px) and (max-width: 767px) {
  416. font-size: 0.45rem;
  417. }
  418. @media only screen and (min-width: 768px) {
  419. font-size: 0.45rem;
  420. }
  421. }
  422. .agreeText {
  423. @media only screen and (min-width: 415px) and (max-width: 767px) {
  424. font-size: 0.45rem;
  425. }
  426. @media only screen and (min-width: 768px) {
  427. font-size: 0.45rem;
  428. }
  429. }
  430. }
  431. </style>