Login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="wavy-line">
  3. <div id="content" style="height: 100%;">
  4. <div id="Login">
  5. <header class="L_header">
  6. <div class="w1100">
  7. <img src="../assets/image/logoImg.png" />
  8. </div>
  9. </header>
  10. <main id="LBg">
  11. <section class="w1100 clearfix">
  12. <div class="LBox">
  13. <div class="Lg_Fm_header">
  14. <img src="../assets/image/loginheader.png" />
  15. <span>欢迎登录</span>
  16. </div>
  17. <div class="Lg_Fm_Body">
  18. <el-form size="medium" :model="loginForm" :rules="fieldRules" ref="loginForm" label-position="left"
  19. label-width="80px">
  20. <el-form-item prop="account" label=" 用户名:">
  21. <el-input type="text" v-model="loginForm.account" auto-complete="off" placeholder="账号"></el-input>
  22. </el-form-item>
  23. <el-form-item prop="password" label=" 密码:">
  24. <el-input type="password" v-model="loginForm.password" auto-complete="off"
  25. placeholder="密码"></el-input>
  26. </el-form-item>
  27. <el-row>
  28. <el-col :span="14">
  29. <el-form-item prop="captcha" label=" 验证码:">
  30. <el-input type="test" v-model="loginForm.captcha" auto-complete="off" placeholder="验证码">
  31. </el-input>
  32. </el-form-item>
  33. </el-col>
  34. <el-col class="line" :span="1">&nbsp;</el-col>
  35. <el-col :span="9">
  36. <img style="width: 100%;height: 32px;margin: 2px;" class="pointer" :src="loginForm.src"
  37. @click="refreshCaptcha">
  38. </el-col>
  39. </el-row>
  40. <el-row style="width:100%;padding: 0px 20px;margin-top: 10px;">
  41. <el-button size="medium" type="primary" style="width:48%;float: left;" @click.native.prevent="reset">重
  42. 置</el-button>
  43. <el-button size="medium" type="primary" style="width:48%;float: right;" @click.native.prevent="login"
  44. :loading="loading">登 录</el-button>
  45. </el-row>
  46. </el-form>
  47. </div>
  48. </div>
  49. </section>
  50. </main>
  51. <footer class="L_footer">
  52. <div class="w1100" style="padding-top: 15px;">
  53. <p style="font-weight: bold;">版权所有©1994-2014山西掌柜科技有限公司 未经许可不得复制转载或者摘编</p>
  54. <p style="font-weight: bold;">copyright 1994-2014 ZhangGui Property Insurance Co.Lid All rights reserved</p>
  55. </div>
  56. </footer>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import { mapState } from 'vuex'
  63. import Cookies from "js-cookie"
  64. import ThemePicker from "@/components/ThemePicker"
  65. import LangSelector from "@/components/LangSelector"
  66. import { login } from '@/api/user'
  67. export default {
  68. name: 'Login',
  69. components: {
  70. ThemePicker,
  71. LangSelector
  72. },
  73. data() {
  74. return {
  75. rememberPassword: false,
  76. loading: false,
  77. loginForm: {
  78. account: '',
  79. password: '',
  80. captcha: '',
  81. src: ''
  82. },
  83. fieldRules: {
  84. account: [
  85. { required: true, message: '请输入账号', trigger: 'blur' },
  86. ],
  87. password: [
  88. { required: true, message: '请输入密码', trigger: 'blur' },
  89. ],
  90. captcha: [
  91. { required: true, message: '请输入验证码', trigger: 'blur' }
  92. ]
  93. },
  94. checked: true,
  95. }
  96. },
  97. created() {
  98. // 记住密码
  99. if (Cookies.get('accountInfo')) {
  100. const accountInfo = JSON.parse(Cookies.get('accountInfo'));
  101. this.loginForm.account = accountInfo.account
  102. this.loginForm.password = accountInfo.password
  103. this.rememberPassword = true
  104. }
  105. this.enterEvent()//初始化回车事件
  106. },
  107. methods: {
  108. enterEvent() {
  109. if (this.$route.name === '登录') {
  110. document.onkeydown = (e) => {
  111. const url = e.target.baseURI.match(/login/)
  112. if (e.keyCode==13 && url.includes('login')) {
  113. this.login();
  114. }
  115. }
  116. }
  117. },
  118. login() {
  119. this.loading = true
  120. let userInfo = {
  121. account: this.loginForm.account,
  122. password: this.loginForm.password,
  123. captcha: this.loginForm.captcha.toLowerCase()
  124. }
  125. // this.$store.dispatch('login', userInfo)
  126. // .then(() => {
  127. // if (this.rememberPassword) { //是否保存密码
  128. // Cookies.set('accountInfo', { 'account': this.loginForm.account, 'password': this.loginForm.password, })
  129. // } else {
  130. // Cookies.remove('accountInfo')
  131. // }
  132. // Cookies.set('user', userInfo.account) /
  133. // sessionStorage.setItem('user', userInfo.account) // 保存用户到本地会话
  134. // this.$store.commit('menuRouteLoaded', false) // 要求重新加载导航菜单
  135. // this.$router.push('/')
  136. // this.loading = false
  137. // })
  138. // .catch(() => {
  139. // this.loading = false
  140. // })
  141. this.$api.login.login(userInfo).then((res) => {
  142. if (res.code != 200) {
  143. this.$message({
  144. message: res.msg,
  145. type: 'error',
  146. duration: 2000
  147. })
  148. } else {
  149. if (this.rememberPassword) { //是否保存密码
  150. Cookies.set('accountInfo', { 'account': this.loginForm.account, 'password': this.loginForm.password, })
  151. } else {
  152. Cookies.remove('accountInfo')
  153. }
  154. Cookies.set('token', res.data) // 放置token到Cookie
  155. Cookies.set('user', userInfo.account) // 放置token到Cookie
  156. this.getDictItems()
  157. this.$api.user.getLoginUser().then((response) => {
  158. if(response.code==200){
  159. localStorage.setItem('user_data', JSON.stringify(response.data))
  160. }
  161. else{
  162. this.$message.error(response.msg)
  163. }
  164. })
  165. this.$api.role.findAll().then((res) => {
  166. localStorage.setItem('find_all', JSON.stringify(res.data))
  167. })
  168. localStorage.setItem('routerId', '420')
  169. sessionStorage.setItem('user', userInfo.account) /
  170. this.$store.commit('menuRouteLoaded', false) // 要求重新加载导航菜单
  171. this.$router.push('/') // 登录成功,跳转到主页
  172. }
  173. this.loading = false
  174. }).catch((res) => {
  175. this.$message({
  176. message: res.message,
  177. type: 'error',
  178. duration: 2000
  179. })
  180. });
  181. // this.$api.login.login(userInfo).then((res) => {
  182. // if (res.msg != null) {
  183. // this.$message({
  184. // message: res.msg,
  185. // type: 'error',
  186. // duration: 2000
  187. // })
  188. // } else {
  189. // if (this.rememberPassword) { //是否保存密码
  190. // Cookies.set('accountInfo', { 'account': this.loginForm.account, 'password': this.loginForm.password, })
  191. // } else {
  192. // Cookies.remove('accountInfo')
  193. // }
  194. // Cookies.set('token', res.data.token, { expires: 1, }) // 放置token到Cookie
  195. // Cookies.set('user', userInfo.account) // 放置token到Cookie
  196. // sessionStorage.setItem('user', userInfo.account) // 保存用户到本地会话
  197. // this.$store.commit('menuRouteLoaded', false) // 要求重新加载导航菜单
  198. // this.$router.push('/') // 登录成功,跳转到主页
  199. // }
  200. // this.loading = false
  201. // }).catch((res) => {
  202. // this.$message({
  203. // message: res.message,
  204. // type: 'error',
  205. // duration: 2000
  206. // })
  207. // });
  208. },
  209. getDictItems() {
  210. //--数据字典--
  211. // 性别
  212. this.$api.dict
  213. .findByLableName('sex')
  214. .then((response) => {
  215. localStorage.setItem('sexOptions', JSON.stringify(response.data)) // 保存用户到本地会话
  216. })
  217. // 状态
  218. this.$api.dict
  219. .findByLableName('user_status')
  220. .then((response) => {
  221. localStorage.setItem('user_statusoptions', JSON.stringify(response.data)) // 保存用户到本地会话
  222. })
  223. },
  224. // 用户信息
  225. getUser(){
  226. this.$api.user.getLoginUser().then((response) => {
  227. if(response.code==200){
  228. this.$store.commit("SET_USER", response.data)
  229. localStorage.setItem('user_data', JSON.stringify(response.data)) // 保存用户到本地会话
  230. }
  231. })
  232. },
  233. refreshCaptcha() {
  234. // this.loginForm.src = this.global.baseUrl + "/captcha.jpg?t=" + new Date().getTime();
  235. this.loginForm.src = process.env.BASE_URL + "/captcha.jpg?t=" + new Date().getTime();
  236. },
  237. reset() {
  238. this.$refs.loginForm.resetFields()
  239. },
  240. // 切换主题
  241. onThemeChange: function (themeColor) {
  242. this.$store.commit('setThemeColor', themeColor)
  243. }
  244. },
  245. mounted() {
  246. this.refreshCaptcha()
  247. },
  248. computed: {
  249. ...mapState({
  250. themeColor: state => state.app.themeColor
  251. })
  252. },
  253. //销毁函数
  254. destroyed() {
  255. document.onkeydown = null;
  256. }
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. .wavy-line {
  261. font: 13px/150% Arial, Verdana, "\5B8B\4F53";
  262. color: #666;
  263. background: #fff;
  264. height: 100%;
  265. }
  266. #content {
  267. overflow: auto;
  268. }
  269. #Login {
  270. width: 100%;
  271. height: 100%;
  272. background-image: url(../assets/image/bgImg5.jpg) !important;
  273. background-size: 100% 100%;
  274. background-repeat: no-repeat;
  275. background-position: 100% 100%;
  276. .L_header {
  277. width: 100%;
  278. height: 64px;
  279. background-color: #fff;
  280. img {
  281. padding-top: 11px;
  282. }
  283. }
  284. .w1100 {
  285. width: 1100px;
  286. margin: 0 auto;
  287. }
  288. #LBg {
  289. width: 100%;
  290. .LBox {
  291. width: 365px;
  292. height: 326px;
  293. border-radius: 10px;
  294. background-color: #fff;
  295. margin-top: 133px;
  296. margin-bottom: 20px;
  297. position: relative;
  298. float: right;
  299. .Lg_Fm_header {
  300. img {
  301. position: absolute;
  302. top: 11px;
  303. right: -64px;
  304. }
  305. span {
  306. color: #fff;
  307. position: absolute;
  308. display: block;
  309. top: 19px;
  310. left: 155px;
  311. font-size: 18px;
  312. }
  313. }
  314. .Lg_Fm_Body {
  315. margin-top: 20px;
  316. margin-bottom: 20px;
  317. margin-left: 10px;
  318. position: absolute;
  319. top: 60px;
  320. width: 340px;
  321. }
  322. }
  323. }
  324. .L_footer {
  325. width: 100%;
  326. height: 64px;
  327. background-color: #fff;
  328. position: fixed;
  329. bottom: 0;
  330. color: #888;
  331. font-size: 12px;
  332. p {
  333. margin: 0;
  334. }
  335. }
  336. }
  337. // // 登录背景
  338. // .loginBackground{
  339. // background: #2b4b6b;
  340. // width:100%;
  341. // height: 100%;
  342. // background-image: url(../assets/image/bgImg.jpg);
  343. // background-repeat:no-repeat ;
  344. // background-size:100% 100%;
  345. // }
  346. // // 登录Form容器
  347. // .login-container {
  348. // width: 350px;
  349. // background: #fff;
  350. // border: 1px solid #eaeaea;
  351. // -webkit-border-radius: 5px;
  352. // border-radius: 5px;
  353. // -moz-border-radius: 5px;
  354. // position: absolute;
  355. // top: 50%;
  356. // left: 50%;
  357. // transform: translate(-50%,-50%);
  358. // padding: 35px 35px 15px 35px;
  359. // // 登录标题
  360. // .title {
  361. // margin: 0px auto 30px auto;
  362. // text-align: center;
  363. // color: #505458;
  364. // }
  365. // // 记住密码
  366. // .remember {
  367. // margin: 0px 0px 35px 0px;
  368. // text-align: right;
  369. // }
  370. // }
  371. </style>