login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="login">
  3. <!-- <div>
  4. <img style="width: 500px; position: relative;top:0; left:0;" src="../assets/images/pic_dl_srkbg.png" alt="">
  5. </div> -->
  6. <!-- <img src="../assets/images/pic_htdl_bt.png" alt="" style="margin-bottom: 10px;"> -->
  7. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  8. <h3 class="title">园区安防监控数据管理平台</h3>
  9. <el-form-item prop="username" v-if='!xgmemberMe'>
  10. <el-input
  11. v-model="loginForm.username"
  12. type="text"
  13. auto-complete="off"
  14. placeholder="账号"
  15. >
  16. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item prop="password" v-if='!xgmemberMe'>
  20. <el-input
  21. v-model="loginForm.password"
  22. type="password"
  23. auto-complete="off"
  24. placeholder="密码"
  25. @keyup.enter.native="handleLogin"
  26. >
  27. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  28. </el-input>
  29. </el-form-item>
  30. <!-- v-if='!xgmemberMe' -->
  31. <el-form-item prop="code" v-if="captchaEnabled" >
  32. <el-input
  33. v-model="loginForm.code"
  34. auto-complete="off"
  35. placeholder="验证码"
  36. style="width: 63%"
  37. @keyup.enter.native="handleLogin"
  38. >
  39. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  40. </el-input>
  41. <div class="login-code">
  42. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  43. </div>
  44. </el-form-item>
  45. <el-form-item prop="oldPassword" v-if='xgmemberMe'>
  46. <el-input v-model="loginForm.oldPassword" type="password"
  47. auto-complete="off"
  48. placeholder="学校名称"
  49. @keyup.enter.native="handleLogins" >
  50. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  51. </el-input>
  52. </el-form-item>
  53. <el-form-item prop="newPassword" v-if='xgmemberMe'>
  54. <el-input v-model="loginForm.newPassword" placeholder="联系方式" type="password" >
  55. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  56. </el-input>
  57. </el-form-item>
  58. <!-- v-if='xgmemberMe' -->
  59. <el-form-item prop="confirmPassword" class="njhyter" v-if="xgmemberMe">
  60. <fileUpload :limit="5" />
  61. </el-form-item>
  62. <div class="njuyehaf">
  63. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  64. <!-- <p v-if="!xgmemberMe">还没有账号?去 <span @click="zhuc">注册</span></p>
  65. <p v-if="xgmemberMe">已有账号?去 <span @click="zhucs" >登录</span></p> -->
  66. </div>
  67. <!-- <el-checkbox v-model="xgmemberMe" @change=" xgmes " style="margin:0px 0px 25px 25px;">修改密码</el-checkbox> -->
  68. <el-form-item style="width:100%;margin-bottom: 0;" v-if='!xgmemberMe' >
  69. <el-button
  70. :loading="loading"
  71. size="medium"
  72. type="primary"
  73. style="width: 100%;background: linear-gradient(180deg, #68BEFF 0%, #0391FD 100%);height: 45px; border-color: #0391FD ;color: #fff; border-radius: 30px;"
  74. @click.native.prevent="handleLogin"
  75. >
  76. <span v-if="!loading">登 录</span>
  77. <span v-else>登 录 中...</span>
  78. </el-button>
  79. <!-- <p class="div_p">
  80. * 使用快捷登录,请先绑定第三方账号
  81. </p> -->
  82. </el-form-item>
  83. <el-form-item style="width:100%;margin-bottom: 0;" v-if='xgmemberMe'>
  84. <el-button
  85. :loading="loading"
  86. size="medium"
  87. type="primary"
  88. style="width: 100%;background-color: #A6A1EB;height: 45px; border-color: #A6A1EB;"
  89. @click.native.prevent="handleLogins"
  90. >
  91. <span v-if="!loading">确认修改</span>
  92. <span v-else>修 改 中...</span>
  93. </el-button>
  94. <!-- <p class="div_p">
  95. * 使用快捷登录,请先绑定第三方账号
  96. </p> -->
  97. </el-form-item>
  98. </el-form>
  99. <!-- 底部 -->
  100. <div class="el-login-footer">
  101. <!-- <span>版本号:ZXY_tj_1.2</span> -->
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import { getCodeImg } from "@/api/login";
  107. import Cookies from "js-cookie";
  108. import { encrypt, decrypt } from '@/utils/jsencrypt'
  109. import {setToken} from '@/utils/auth'
  110. import resetPwd from "./system/user/profile/resetPwd.vue";
  111. import { updateUserPwds } from "@/api/system/user";
  112. export default {
  113. name: "Login",
  114. data() {
  115. return {
  116. codeUrl: "",
  117. loginForm: {
  118. username: "",
  119. password: "",
  120. rememberMe: false,
  121. code: "",
  122. uuid: ""
  123. },
  124. loginRules: {
  125. username: [
  126. { required: true, trigger: "blur", message: "请输入您的账号" }
  127. ],
  128. password: [
  129. { required: true, trigger: "blur", message: "请输入您的密码" }
  130. ],
  131. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  132. },
  133. loading: false,
  134. // 验证码开关
  135. captchaEnabled: false,
  136. // 注册开关
  137. register: false,
  138. redirect: undefined,
  139. xgmemberMe:false //修改密码
  140. };
  141. },
  142. watch: {
  143. $route: {
  144. handler: function(route) {
  145. this.redirect = route.query && route.query.redirect;
  146. },
  147. immediate: true
  148. }
  149. },
  150. created() {
  151. this.getCode();
  152. this.getCookie();
  153. },
  154. methods: {
  155. getCode() {
  156. getCodeImg().then(res => {
  157. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  158. if (this.captchaEnabled) {
  159. this.codeUrl = "data:image/gif;base64," + res.img;
  160. this.loginForm.uuid = res.uuid;
  161. }
  162. });
  163. },
  164. getCookie() {
  165. const username = Cookies.get("username");
  166. const password = Cookies.get("password");
  167. const rememberMe = Cookies.get('rememberMe')
  168. this.loginForm = {
  169. username: username === undefined ? this.loginForm.username : username,
  170. password: password === undefined ? this.loginForm.password : decrypt(password),
  171. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  172. };
  173. },
  174. handleLogin() {
  175. this.$refs.loginForm.validate(valid => {
  176. if (valid) {
  177. this.loading = true;
  178. if (this.loginForm.rememberMe) {
  179. Cookies.set("username", this.loginForm.username, { expires: 30 });
  180. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  181. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  182. } else {
  183. Cookies.remove("username");
  184. Cookies.remove("password");
  185. Cookies.remove('rememberMe');
  186. }
  187. this.$store.dispatch("Login", this.loginForm).then(() => {
  188. this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  189. }).catch(() => {
  190. this.loading = false;
  191. if (this.captchaEnabled) {
  192. this.getCode();
  193. }
  194. });
  195. }
  196. });
  197. },
  198. // 修改密码
  199. handleLogins(){
  200. if(this.loginForm.username == ""){
  201. this.$message.error('请输入账号');
  202. return
  203. }
  204. if(this.loginForm.oldPassword == undefined){
  205. this.$message.error('请输入旧密码');
  206. return
  207. }
  208. if(this.loginForm.newPassword == undefined){
  209. this.$message.error('请输入新密码');
  210. return
  211. }
  212. if(this.loginForm.confirmPassword == undefined){
  213. this.$message.error('请输入确认密码');
  214. return
  215. }
  216. this.loading = true;
  217. let nhse={
  218. userName:''
  219. }
  220. nhse.userName = this.loginForm.username
  221. updateUserPwds(this.loginForm.oldPassword, this.loginForm.newPassword,this.loginForm.username).then(
  222. response => {
  223. console.log(response.msg,36)
  224. if(response.msg == '操作成功'){
  225. this.$modal.msgSuccess(response.msg);
  226. this.xgmemberMe = false
  227. this.getCode();
  228. this.$set(this.loginForm,'password','')
  229. this.$set(this.loginForm,'uuid','')
  230. this.$set(this.loginForm,'rememberMe',false)
  231. this.$set(this.loginForm,'code','')
  232. this.$set(this.loginForm,'confirmPassword',undefined)
  233. this.$set(this.loginForm,'oldPassword',undefined)
  234. this.$set(this.loginForm,'newPassword',undefined)
  235. // this.$set(this.loginForm,'username','')
  236. }else{
  237. this.$message.error(response.msg);
  238. }
  239. this.loading = false;
  240. }
  241. );
  242. },
  243. // 确认密码失去焦点
  244. cpass(){
  245. if(this.loginForm.confirmPassword !== this.loginForm.newPassword){
  246. this.$message.error('两次密码不一致');
  247. }
  248. },
  249. // 复选框选择修改密码
  250. xgmes(){
  251. if(this.xgmemberMe == false){
  252. this.$set(this.loginForm,'confirmPassword',undefined)
  253. this.$set(this.loginForm,'oldPassword',undefined)
  254. this.$set(this.loginForm,'newPassword',undefined)
  255. this.$set(this.loginForm,'username','')
  256. }else{
  257. this.$set(this.loginForm,'username','')
  258. this.$set(this.loginForm,'password','')
  259. this.$set(this.loginForm,'uuid','')
  260. this.$set(this.loginForm,'rememberMe',false)
  261. this.$set(this.loginForm,'code','')
  262. }
  263. },
  264. zhuc(){
  265. this.xgmemberMe = true
  266. },
  267. zhucs(){
  268. this.xgmemberMe = false
  269. }
  270. }
  271. };
  272. </script>
  273. <style rel="stylesheet/scss" lang="scss">
  274. .login {
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. flex-direction: column;
  279. height: 100%;
  280. background-image: url("../assets/images/login-background.jpg");
  281. background-size: cover;
  282. .el-input__prefix{
  283. color: #5974E0;
  284. top:2px;
  285. }
  286. // margin-left: 300px;
  287. }
  288. .title {
  289. margin: 0 auto 20px auto;
  290. text-align: center;
  291. font-size: 23px;
  292. font-family: PingFang SC;
  293. font-weight: 800;
  294. color: #343434;
  295. }
  296. .login-form {
  297. border-radius: 6px;
  298. background: #000a48;
  299. background-color:#fff;
  300. width: 400px;
  301. // margin-left: -3.2%;
  302. // margin-right: 50%;
  303. // margin-left: 10px;
  304. padding: 25px 35px 5px 35px;
  305. .el-input {
  306. height: 45px;
  307. input {
  308. height: 45px;
  309. border: 1px solid #0391FD;
  310. border-radius: 21px;
  311. background-color: #0391FD;
  312. // border-color: #F7F6FC;s
  313. background-color:#fff
  314. }
  315. }
  316. .el-checkbox__inner{
  317. background-color: #2174f3;
  318. border-color: rgba(1, 152, 221,0.2);
  319. background-color:rgba(0,0,0,0.3)
  320. }
  321. .input-icon {
  322. height: 39px;
  323. width: 14px;
  324. margin-left: 2px;
  325. }
  326. .el-button--primary{
  327. margin-bottom: 20px;
  328. // background-color: #A6A1EB !important;
  329. }
  330. .el-form-item{
  331. margin-bottom: 25px;
  332. }
  333. }
  334. .login-tip {
  335. font-size: 13px;
  336. text-align: center;
  337. color: #bfbfbf;
  338. }
  339. .login-code {
  340. width: 33%;
  341. height: 38px;
  342. float: right;
  343. img {
  344. cursor: pointer;
  345. vertical-align: middle;
  346. }
  347. }
  348. .el-login-footer {
  349. height: 40px;
  350. line-height: 40px;
  351. position: fixed;
  352. bottom: 0;
  353. width: 100%;
  354. text-align: center;
  355. color: #fff;
  356. font-family: Arial;
  357. font-size: 12px;
  358. letter-spacing: 1px;
  359. }
  360. .login-code-img {
  361. height: 38px;
  362. }
  363. .nli{
  364. .el-button--primary{
  365. background-color: #A6A1EB;
  366. border-color: #A6A1EB !important;
  367. }
  368. }
  369. .njuyehaf{
  370. display: flex;
  371. p{
  372. flex: 1;
  373. font-size: 14px;
  374. font-family: PingFang SC;
  375. font-weight: 400;
  376. color: #C8C8C8;
  377. margin: 0;
  378. text-align: right;
  379. span{
  380. color: #FFB339;
  381. font-weight: 700;
  382. cursor:pointer;
  383. }
  384. }
  385. }
  386. .njhyter{
  387. .el-upload{
  388. width: 100%;
  389. }
  390. .el-button--mini{
  391. width: 100% !important;
  392. padding: 11px 15px;
  393. // text-align: left;
  394. margin: 0;
  395. }
  396. .el-button--primary{
  397. background-color: #F7F6FC;
  398. border-color: #F7F6FC;
  399. color: #A6A1EB;
  400. }
  401. .el-upload__tip{
  402. font-size: 12px;
  403. }
  404. }
  405. </style>