Login.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div class="login-container">
  3. <div class="login-form">
  4. <h3 style="display:flex;justify-content: center;flex-direction:row;align-items: center;">
  5. <img src="../assets/rccslogo.png" height="60"/>
  6. <span style="margin-left:5px;font-size: 28px;color:rgb(64,158,255);">荆州人才超市保险服务平台</span>
  7. </h3>
  8. <el-card class="box-card">
  9. <h3 class="title">荆州人才超市保险服务平台-管理端</h3>
  10. <el-form
  11. class="card-box"
  12. autocomplete="on"
  13. :model="loginForm"
  14. :rules="loginRules"
  15. ref="loginForm"
  16. label-position="left"
  17. >
  18. <el-form-item prop="userName">
  19. <i class="el-icon-user-solid"></i>
  20. <el-input
  21. name="userName"
  22. type="text"
  23. v-model="loginForm.userName"
  24. autocomplete="on"
  25. placeholder="请输入用户名"
  26. />
  27. </el-form-item>
  28. <el-form-item prop="password">
  29. <i class="el-icon-lock"></i>
  30. <el-input
  31. name="password"
  32. :type="pwdType"
  33. @keyup.enter.native="handleLogin"
  34. v-model="loginForm.password"
  35. autocomplete="on"
  36. placeholder="请输入密码"
  37. />
  38. <i class="el-icon-view" @click="showPwd"></i>
  39. </el-form-item>
  40. <el-row>
  41. <el-col :span="3">
  42. <a style="cursor:pointer;">
  43. <img src="../assets/wx.png" width="32" @click="wxLogin"/>
  44. </a>
  45. </el-col>
  46. <el-col :span="21">
  47. <el-button
  48. type="primary"
  49. style="width:100%;margin-bottom:30px;"
  50. :loading="loading"
  51. @click.native.prevent="handleLogin"
  52. >登录</el-button>
  53. </el-col>
  54. </el-row>
  55. </el-form>
  56. </el-card>
  57. </div>
  58. <el-dialog
  59. title="微信扫码登录"
  60. :modal-append-to-body="false"
  61. width="30%"
  62. :visible.sync="wxDialogVisible">
  63. <div v-loading="wxLoading">
  64. <img :src="wxLoginQrcode" width="100%" height="auto"/>
  65. </div>
  66. </el-dialog>
  67. </div>
  68. </template>
  69. <script>
  70. import Constant from "@/constant";
  71. import { Message } from "element-ui";
  72. import userApi from '@/api/sys/user';
  73. import {setToken} from '@/utils/auth'
  74. export default {
  75. name: "login",
  76. data() {
  77. return {
  78. loginForm: {
  79. userName: "",
  80. password: "",
  81. openId: ""
  82. },
  83. loginRules: {
  84. userName: [
  85. { required: true, message: "请填写用户名", trigger: "blur" }
  86. ],
  87. password: [
  88. { required: true, message: "请填写密码", trigger: "blur" },
  89. {
  90. type: "string",
  91. min: 2,
  92. message: "密码长度不能小于2位",
  93. trigger: "blur"
  94. }
  95. ]
  96. },
  97. pwdType: "password",
  98. loading: false,
  99. redirect: undefined,
  100. wxDialogVisible: false,
  101. wxLoading: false,
  102. wxLoginQrcode: '',
  103. wxQueryHandler: 0,
  104. loginCode: parseInt(Math.random().toFixed(6)*1000000)
  105. };
  106. },
  107. watch: {
  108. $route: {
  109. handler: function(route) {
  110. const query = route.query;
  111. if (query) {
  112. this.redirect = query.redirect;
  113. }
  114. },
  115. immediate: true
  116. }
  117. },
  118. methods: {
  119. showPwd() {
  120. if (this.pwdType === "password") {
  121. this.pwdType = "";
  122. } else {
  123. this.pwdType = "password";
  124. }
  125. },
  126. handleLogin() {
  127. var self = this;
  128. this.$refs.loginForm.validate(valid => {
  129. if (valid) {
  130. this.loading = true;
  131. self.$store
  132. .dispatch("user/login", self.loginForm)
  133. .then((result) => {
  134. self.loading = false;
  135. if(result){
  136. self.$router.push({ path: this.redirect || "/home" });
  137. }
  138. })
  139. .catch(error => {
  140. self.loading = false;
  141. self.$message.error(error);
  142. });
  143. }
  144. });
  145. },
  146. wxLogin() {
  147. var self = this;
  148. self.wxDialogVisible = true;
  149. self.wxLoading = true;
  150. userApi.getLoginQrcode(self.loginCode).then((resp)=>{
  151. var jsonData = resp.data;
  152. self.wxLoading = false;
  153. if(jsonData!=null){
  154. if(jsonData.result) {
  155. self.wxLoginQrcode = jsonData.data;
  156. clearTimeout(self.wxQueryHandler);
  157. self.queryWXLoginStatus();
  158. }
  159. }
  160. else{
  161. self.$message.error("获取二维码失败!");
  162. }
  163. });
  164. },
  165. queryWXLoginStatus() {
  166. var self = this;
  167. userApi.queryWXLoginStatus(self.loginCode).then((resp)=>{
  168. var jsonData = resp.data;
  169. console.log(jsonData);
  170. if(jsonData.data!=null && jsonData.data.length>0) {
  171. var openId = jsonData.data;
  172. self.loginForm.openId = openId;
  173. self.loading = true;
  174. self.scanQrcodeLogin();
  175. }
  176. else {
  177. self.wxQueryHandler = setTimeout(self.queryWXLoginStatus,3000);
  178. }
  179. });
  180. },
  181. scanQrcodeLogin() {
  182. var self = this;
  183. self.loading = true;
  184. console.log(self.loginForm.openId);
  185. userApi.scanQrcodeLogin({
  186. openId : self.loginForm.openId
  187. }).then(resp => {
  188. self.loading = false;
  189. var jsonData = resp.data;
  190. if(jsonData.result){
  191. self.$message.success("登录成功!");
  192. self.$store.commit('SET_TOKEN', jsonData.data);
  193. setToken(jsonData.data);
  194. self.$router.push({ path: self.redirect || "/home" });
  195. }
  196. else{
  197. Message.error(jsonData.message || 'Has Error')
  198. }
  199. })
  200. }
  201. },
  202. created() {
  203. // window.addEventListener('hashchange', this.afterQRScan)
  204. },
  205. destroyed() {
  206. // window.removeEventListener('hashchange', this.afterQRScan)
  207. },
  208. mounted() {}
  209. };
  210. </script>
  211. <style rel="stylesheet/scss" lang="scss">
  212. @import "src/styles/mixin.scss";
  213. $bg:rgba(242, 247, 253, 1);
  214. $icon_color: rgba(207,134,146,1);
  215. $text_color: black;
  216. .login-container {
  217. @include relative;
  218. height: 100vh;
  219. background-color: $bg;
  220. background-image:url('../assets/login_bg_element.png');
  221. background-size:615px 258px;
  222. background-position: bottom right;
  223. background-repeat: no-repeat;
  224. h3{
  225. text-align:center;
  226. }
  227. input:-webkit-autofill {
  228. -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
  229. -webkit-text-fill-color: #fff !important;
  230. }
  231. input {
  232. background: transparent;
  233. border: 0px;
  234. -webkit-appearance: none;
  235. border-radius: 0px;
  236. padding: 12px 5px 12px 15px;
  237. color: $text_color;
  238. height: 47px;
  239. }
  240. .el-input {
  241. display: inline-block;
  242. height: 47px;
  243. width: 85%;
  244. }
  245. .tips {
  246. font-size: 14px;
  247. color: #fff;
  248. margin-bottom: 10px;
  249. }
  250. .title {
  251. font-size: 18px;
  252. font-weight:normal;
  253. color: $text_color;
  254. margin: 0px auto 20px auto;
  255. text-align: center;
  256. }
  257. .login-form {
  258. position: absolute;
  259. left: 0;
  260. right: 0;
  261. width: 400px;
  262. padding: 35px 35px 15px 35px;
  263. margin: 60px auto;
  264. }
  265. .box-card{
  266. }
  267. .login-form i {
  268. color: $icon_color;
  269. font-size: 14px;
  270. }
  271. @media only screen and (max-width: 768px) {
  272. .login-form {
  273. position: absolute;
  274. left: 0;
  275. right: 0;
  276. width: 320px;
  277. padding: 15px 15px 15px 15px;
  278. margin: 120px auto;
  279. }
  280. }
  281. .el-form-item {
  282. border: 1px solid rgba(228, 228, 228, 1);
  283. background: rgba(242, 242, 242, 1);
  284. border-radius: 5px;
  285. padding-left:5px;
  286. }
  287. .show-pwd {
  288. position: absolute;
  289. right: 10px;
  290. top: 7px;
  291. font-size: 16px;
  292. cursor: pointer;
  293. }
  294. .thirdparty-button {
  295. position: absolute;
  296. right: 35px;
  297. bottom: 28px;
  298. }
  299. }
  300. </style>