Login.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div id="bg">
  3. <el-container>
  4. <el-header></el-header>
  5. <el-main>
  6. <div class="bg">
  7. <el-card class="box-card">
  8. <h5 class="title">
  9. <img src="../assets/img/login/logo.png" alt="">
  10. </h5>
  11. <span class="subtitle">小飞龙场馆管理系统</span>
  12. <el-form ref="form" :model="form" label-width="0px">
  13. <el-form-item label="">
  14. <el-input v-model="form.name" placeholder="用户名"></el-input>
  15. </el-form-item>
  16. <el-form-item label="">
  17. <el-input v-model="form.pwd" placeholder="密码" type="password"></el-input>
  18. </el-form-item>
  19. <el-form-item label="">
  20. <el-input v-model="form.valid" placeholder="验证码"
  21. @keyup.enter.native="onSubmit"></el-input>
  22. <img id="validImg" :src="valImgSrc" alt="" width="100px" height="42px"
  23. title="看不清?刷一下试试!" @click="getGenVerifyPic">
  24. </el-form-item>
  25. <br>
  26. <br>
  27. <el-form-item>
  28. <el-button type="primary" @click="onSubmit">登陆</el-button>
  29. </el-form-item>
  30. </el-form>
  31. </el-card>
  32. </div>
  33. </el-main>
  34. <el-footer></el-footer>
  35. </el-container>
  36. </div>
  37. </template>
  38. <script>
  39. import {
  40. SignIn,
  41. GenVerifyPic,
  42. ManagerSelfQuery
  43. } from "../api/getApiRes";
  44. let qs = require('qs');
  45. import Global from '../Global.js'
  46. export default {
  47. data() {
  48. return {
  49. form: {
  50. name: '',
  51. pwd: '',
  52. valid: '',
  53. picId: '',
  54. },
  55. valImgSrc: '',
  56. valImgId: '',
  57. overtime: '',
  58. userLevel: '',
  59. userLevelText: '',
  60. }
  61. },
  62. mounted() {
  63. this.overtime = new Date();
  64. this.getGenVerifyPic();
  65. // 如果是手动退出用户
  66. if (this.$route.query.status == 1) {
  67. // 刷新验证图
  68. this.changeValImg();
  69. // 重置倒计时
  70. this.overtime = new Date();
  71. }
  72. // checkScreen
  73. if (document.body.clientWidth < 1024) {
  74. this.$message.warning('请横屏使用本系统');
  75. }
  76. },
  77. methods: {
  78. getGenVerifyPic() {
  79. let that = this;
  80. let param = {
  81. token: localStorage.token,
  82. width: 100,
  83. height: 42,
  84. noiseCount: 10,
  85. length: 4,
  86. source: 123456789,
  87. };
  88. let postdata = qs.stringify(param);
  89. GenVerifyPic(postdata).then(res => {
  90. let json = res;
  91. that.valImgSrc = json.Pic;
  92. that.valImgId = json.Id;
  93. that.form.picId = json.Id;
  94. })
  95. },
  96. // 点击验证码切换
  97. changeValImg: function () {
  98. // 刷新验证图
  99. this.getGenVerifyPic();
  100. },
  101. // 登陆
  102. onSubmit() {
  103. this.pwdLoginBtn()
  104. },
  105. // 密码登陆
  106. pwdLoginBtn() {
  107. let that = this;
  108. let username = this.form.name;
  109. let userpwd = this.form.pwd;
  110. let uservalid = this.form.valid;
  111. // 重置验证码超时
  112. that.overtime = new Date();
  113. if (!globalValid(username, 2, 17, '用户名', that)) return;
  114. if (!globalValid(userpwd, 5, 17, '密码', that)) return;
  115. if (!globalValid(uservalid, 3, 5, '验证码', that)) return;
  116. this.loginInfo();
  117. },
  118. getManagerSelfQuery() {
  119. let that = this;
  120. let param = {
  121. token: localStorage.token,
  122. };
  123. let postdata = qs.stringify(param);
  124. ManagerSelfQuery(postdata).then(res => {
  125. let json = res;
  126. if (json.Code == 0) {
  127. that.userLevelText = json.Rs.Role.Name;
  128. // 1 会员 2 系统 3 店铺 4 教练
  129. that.userLevel = json.Rs.Role.Id;
  130. localStorage.shopId = json.Rs.ShopId;
  131. localStorage.ShopId = json.Rs.ShopId;
  132. switch (parseInt(that.userLevel)) {
  133. case 1:
  134. that.$router.push({path: '/'});
  135. break;
  136. case 2:
  137. that.$router.push({path: '/shopManage'});
  138. break;
  139. case 3:
  140. that.$router.push({path: '/'});
  141. break;
  142. case 4:
  143. that.$router.push({path: '/'});
  144. break;
  145. }
  146. } else {
  147. if (json.Code == 1010) {
  148. that.$message.error(json.Memo + '错误码:' + json.Code);
  149. that.$router.push({path: '/login', query: {status: 1}});
  150. return false
  151. }
  152. that.$message.error(json.Memo + '错误码:' + json.Code);
  153. }
  154. })
  155. },
  156. // pwd登陆
  157. loginInfo: function () {
  158. const that = this;
  159. let url = headapi + '?ctl=ajax&mod=index&act=login';
  160. let username = this.form.name;
  161. let userpwd = this.form.pwd;
  162. let uservalid = this.form.valid;
  163. let current = new Date();
  164. let betweenTime = current - that.overtime;
  165. let s = 120;
  166. if (betweenTime > s * 1000) {
  167. that.changeValImg();
  168. that.$message.error('验证码已超时,请重新输入');
  169. return false
  170. }
  171. let param = {
  172. verifyName: username,
  173. verifyCode: userpwd,
  174. picCode: uservalid,
  175. picId: this.form.picId,
  176. channel: 2
  177. };
  178. let postdata = qs.stringify(param);
  179. SignIn(postdata).then(res => {
  180. if (res.Code == 0) {
  181. that.res = res.Rs;
  182. localStorage.userName = username;
  183. localStorage.token = res.Rs.token;
  184. this.getManagerSelfQuery();
  185. } else {
  186. if (res.Code == 10005) {
  187. that.$refs.userpwd.value = '';
  188. that.$notify({
  189. title: '警告',
  190. message: '密码错误,请重新输入',
  191. type: 'warning'
  192. });
  193. } else {
  194. that.$notify({
  195. title: '警告',
  196. message: res.Memo + ',错误代码:' + res.Code,
  197. type: 'warning'
  198. });
  199. that.form.valid = '';
  200. that.changeValImg();
  201. }
  202. }
  203. })
  204. }
  205. },
  206. }
  207. </script>
  208. <style scoped>
  209. #bg {
  210. width: 100%;
  211. height: 100%;
  212. overflow: hidden;
  213. display: block;
  214. margin: 0 auto;
  215. background-color: #F0F2F5;
  216. background: url("../assets/img/login/bg.png") top center no-repeat;
  217. background-size: 100% 100%;
  218. }
  219. .title {
  220. font-size: 60px;
  221. text-align: center;
  222. color: #fff;
  223. margin-top: 3%;
  224. margin-bottom: 5px;
  225. }
  226. .title img {
  227. width: 362px;
  228. overflow: hidden;
  229. display: block;
  230. margin: 0 auto;
  231. }
  232. .subtitle {
  233. width: 100%;
  234. overflow: hidden;
  235. display: block;
  236. margin: 0 auto;
  237. text-align: center;
  238. color: #414141;
  239. margin-bottom: 79px;
  240. font-size: 41px;
  241. }
  242. .box-card {
  243. width: 577px;
  244. height: 733px;
  245. overflow: hidden;
  246. float: right;
  247. margin-top: 40px;
  248. margin-right: 10%;
  249. }
  250. .box-card .boxTitle {
  251. font-size: 30px;
  252. margin-bottom: 15px;
  253. }
  254. #validImg {
  255. position: relative;
  256. float: right;
  257. bottom: 52px;
  258. }
  259. /deep/ .el-form {
  260. width: 422px;
  261. overflow: hidden;
  262. display: block;
  263. margin: 0 auto;
  264. }
  265. /deep/ .el-input__inner {
  266. height: 44px;
  267. background: #F0F2F5;
  268. border-radius: 0;
  269. margin-bottom: 10px;
  270. }
  271. /deep/ .el-button--primary {
  272. width: 100%;
  273. height: 52px;
  274. /*line-height: 32px;*/
  275. overflow: hidden;
  276. display: block;
  277. margin: 0 auto;
  278. font-size: 18px;
  279. }
  280. /*ipad only*/
  281. @media only screen and (max-width: 1366px) {
  282. #bg {
  283. background-size: 100%;
  284. background-color: #F2F2F2;
  285. }
  286. .box-card {
  287. width: 500px;
  288. height: 550px;
  289. margin-top: 0;
  290. margin-right: 1%;
  291. }
  292. .subtitle {
  293. margin-bottom: 10px;
  294. }
  295. .el-form-item {
  296. margin-bottom: 12px;
  297. }
  298. }
  299. </style>