Login.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div id="bg">
  3. <el-container>
  4. <el-header></el-header>
  5. <el-main>
  6. <h5 class="title">SignalDigger</h5>
  7. <span class="subtitle">专用场所无线信号安全监控系统</span>
  8. <el-card class="box-card">
  9. <div class="center">
  10. <el-form ref="form" :model="form" label-width="0px">
  11. <el-form-item label="">
  12. <el-input v-model="form.name" placeholder="用户名"></el-input>
  13. </el-form-item>
  14. <el-form-item label="">
  15. <el-input type="password" v-model="form.pwd" placeholder="密码"></el-input>
  16. </el-form-item>
  17. <el-form-item label="" v-loading="validImgState" element-loading-text="拼命加载中"
  18. element-loading-spinner="el-icon-loading"
  19. element-loading-background="rgba(0, 0, 0, 0.4)">
  20. <el-input v-model="form.valid" placeholder="验证码"
  21. @keyup.enter.native="pwdLoginBtn"></el-input>
  22. <img id="validImg" :src="valImgSrc" alt="" width="100px" height="30px"
  23. title="看不清?刷一下试试!" @click="changeValImg">
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" class="primaryBtn" @click="onSubmit">确认</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. </el-card>
  31. </el-main>
  32. <el-footer>
  33. <p>Copyright © 2020-{{thisYear}} 专用场所无线信号安全监控系统 版权所有</p>
  34. </el-footer>
  35. </el-container>
  36. </div>
  37. </template>
  38. <script>
  39. import {SignIn, GenVerifyPic} from '../api/getApiRes.js'
  40. let qs = require('qs');
  41. import Global from '../Global.js'
  42. export default {
  43. data() {
  44. return {
  45. thisYear: new Date().getFullYear(),
  46. form: {
  47. name: '',
  48. pwd: '',
  49. valid: '',
  50. picId: '',
  51. },
  52. overtime: '',
  53. validImgState: true,
  54. valImgSrc: '',
  55. }
  56. },
  57. mounted() {
  58. // 读取验证码
  59. this.CurentGenVerifyPic();
  60. this.overtime = new Date();
  61. // 如果是手动退出用户
  62. if (this.$route.query.status == 1) {
  63. // 刷新验证图
  64. this.changeValImg();
  65. // 重置倒计时
  66. this.overtime = new Date();
  67. }
  68. },
  69. methods: {
  70. CurentGenVerifyPic() {
  71. let that = this;
  72. let postdata;
  73. GenVerifyPic(postdata).then(res => {
  74. let json = res;
  75. if (json.Id) {
  76. that.valImgSrc = json.Pic;
  77. that.form.picId = json.Id;
  78. this.validImgState = false;
  79. } else {
  80. that.$message.error(json.Memo);
  81. }
  82. })
  83. },
  84. // 点击验证码切换
  85. changeValImg: function () {
  86. this.validImgState = true;
  87. this.CurentGenVerifyPic();
  88. },
  89. // 登陆
  90. onSubmit() {
  91. this.pwdLoginBtn()
  92. },
  93. // 清除登陆
  94. clearForm() {
  95. this.form.name = '';
  96. this.form.pwd = '';
  97. this.form.valid = '';
  98. this.changeValImg();
  99. },
  100. // 密码登陆
  101. pwdLoginBtn() {
  102. let that = this;
  103. let username = this.form.name;
  104. let userpwd = this.form.pwd;
  105. let uservalid = this.form.valid;
  106. // 重置验证码超时
  107. that.overtime = new Date();
  108. if (!globalValid(username, 2, 17, '用户名', that)) return;
  109. if (!globalValid(userpwd, 5, 17, '密码', that)) return;
  110. if (!globalValid(uservalid, 3, 5, '验证码', that)) return;
  111. this.loginInfo();
  112. },
  113. // pwd登陆
  114. loginInfo: function () {
  115. const that = this;
  116. let url = headapi + '?ctl=ajax&mod=index&act=login';
  117. let username = this.form.name;
  118. let userpwd = this.form.pwd;
  119. let uservalid = this.form.valid;
  120. let picId = this.form.picId;
  121. let current = new Date();
  122. let betweenTime = current - that.overtime;
  123. let s = 120;
  124. if (betweenTime > s * 1000) {
  125. that.changeValImg();
  126. that.$message.error('验证码已超时,请重新输入');
  127. return false
  128. }
  129. let param = {
  130. 'verifyName': username,
  131. 'verifyCode': userpwd,
  132. 'src': 'pc',
  133. 'picId': picId,
  134. 'picCode': uservalid,
  135. };
  136. let postdata = qs.stringify(param);
  137. SignIn(postdata).then(res => {
  138. if (res.Code == 0) {
  139. that.res = res.Rs;
  140. that.userName = res.Rs.userName;
  141. localStorage.userName = res.Rs.username;
  142. localStorage.token = res.Rs.token;
  143. that.$router.push({path: '/'});
  144. } else {
  145. if (res.Code == 10005) {
  146. that.$refs.userpwd.value = '';
  147. that.$notify({
  148. title: '警告',
  149. message: '密码错误,请重新输入',
  150. type: 'warning'
  151. });
  152. } else {
  153. that.$notify({
  154. title: '警告',
  155. message: res.Memo,
  156. type: 'warning'
  157. });
  158. that.form.valid = '';
  159. that.changeValImg();
  160. }
  161. }
  162. })
  163. }
  164. }
  165. }
  166. </script>
  167. <style scoped>
  168. #bg {
  169. width: 100%;
  170. height: 100%;
  171. overflow: hidden;
  172. display: block;
  173. margin: 0 auto;
  174. background-image: url("../assets/img/login.png");
  175. background-repeat: no-repeat;
  176. background-position: top center;
  177. background-size: 100% 100%;
  178. }
  179. .title {
  180. font-size: 43px;
  181. font-weight: 600;
  182. text-align: center;
  183. color: #fff;
  184. margin-top: 2%;
  185. margin-bottom: 5px;
  186. }
  187. .subtitle {
  188. width: 100%;
  189. overflow: hidden;
  190. display: block;
  191. margin: 0 auto;
  192. text-align: center;
  193. color: #fff;
  194. margin-bottom: 40px;
  195. font-size: 14px;
  196. }
  197. .box-card {
  198. width: 626px;
  199. height: 389px;
  200. overflow: hidden;
  201. display: block;
  202. margin: 0 auto;
  203. background: rgba(255, 255, 255, 0.18) !important;
  204. /*background: url("../assets/img/goss.png");*/
  205. /*background-image: url("../assets/img/goss.png");*/
  206. border: 1px solid rgba(255, 255, 255, 0.41);
  207. background-repeat: no-repeat;
  208. background-position: top center;
  209. background-size: 100% 100%;
  210. }
  211. .box-card .boxTitle {
  212. font-size: 30px;
  213. margin-bottom: 15px;
  214. }
  215. #validImg {
  216. position: relative;
  217. float: right;
  218. bottom: 35px;
  219. }
  220. .center {
  221. width: 300px;
  222. overflow: hidden;
  223. display: block;
  224. margin: 0 auto;
  225. background: rgba(255, 255, 255, 0.25);
  226. border-radius: 12px;
  227. margin-top: 27px;
  228. margin-bottom: 27px;
  229. padding: 31px 133px;
  230. }
  231. .primaryBtn {
  232. width: 100%;
  233. overflow: hidden;
  234. display: block;
  235. margin: 0 auto;
  236. height: 44px;
  237. line-height: 24px;
  238. font-size: 16px;
  239. }
  240. .el-card {
  241. background: none;
  242. }
  243. /deep/ .el-input__inner {
  244. background: none;
  245. border: 1px solid #70C2FF;
  246. color: #BEE3FF;
  247. }
  248. /deep/ .el-input__inner::placeholder {
  249. color: #BEE3FF;
  250. }
  251. /deep/ .el-footer {
  252. position: absolute;
  253. bottom: 0;
  254. width: 100%;
  255. text-align: center;
  256. color: #6DC1FF;
  257. }
  258. </style>