login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="login-box">
  3. <a-spin :spinning="loading">
  4. <div class="login-body">
  5. <div class="login-title-row">
  6. <img class="login-title-logo" :src="logoImg" />
  7. <span class="login-title-txt">{{ loginTitle }}</span>
  8. </div>
  9. <div class="login-description-row">
  10. <div class="login-description-none"></div>
  11. <div class="login-description-txt">后端管理平台</div>
  12. </div>
  13. <a-form
  14. :form="loginForm"
  15. @submit="handleLoginFun"
  16. style="width: 350px;"
  17. >
  18. <a-form-item>
  19. <a-input
  20. placeholder="账户"
  21. :maxLength="10"
  22. v-decorator="[
  23. 'loginUserName',
  24. {
  25. rules: [{ required: true, message: '请输入您的账户!' }],
  26. },
  27. ]"
  28. >
  29. <icon-font
  30. slot="addonBefore"
  31. class="iconFont"
  32. type="ali-icon-yonghu"
  33. />
  34. </a-input>
  35. </a-form-item>
  36. <a-form-item>
  37. <a-input-password
  38. placeholder="密码"
  39. :maxLength="10"
  40. v-decorator="[
  41. 'loginPassword',
  42. {
  43. rules: [{ required: true, message: '请输入您的密码!' }],
  44. },
  45. ]"
  46. >
  47. <icon-font
  48. slot="addonBefore"
  49. class="iconFont"
  50. type="ali-icon-mima"
  51. />
  52. </a-input-password>
  53. </a-form-item>
  54. <a-form-item>
  55. <a-button
  56. type="primary"
  57. html-type="submit"
  58. style="width: 100%;margin-top: 40px;"
  59. >登录</a-button
  60. >
  61. </a-form-item>
  62. </a-form>
  63. <div class="login-enterprise">
  64. <span>copyright © 浮游科技有限公司出品</span>
  65. </div>
  66. </div>
  67. </a-spin>
  68. </div>
  69. </template>
  70. <script>
  71. import { PROGRAM_Title, AUTH_TOKEN_FRONT } from '@/common/Constant';
  72. export default {
  73. name: 'login',
  74. props: {},
  75. components: {},
  76. data() {
  77. return {
  78. loading: false, // 是否显示加载动画
  79. logoImg: require('@/assets/image/logo.png'), // logo图
  80. loginTitle: PROGRAM_Title, // 系统标题
  81. loginForm: this.$form.createForm(this, { name: 'login' }),
  82. };
  83. },
  84. created() {
  85. // this.setUserInfo({ name: '111', token: 'WFFFF' });
  86. this.initDataFun(); // 初始化数据
  87. },
  88. mounted() {},
  89. beforeDestroy() {},
  90. watch: {},
  91. computed: {},
  92. methods: {
  93. // 初始化数据
  94. initDataFun() {},
  95. // 操作:登录
  96. handleLoginFun(e) {
  97. e.preventDefault();
  98. this.loginForm.validateFields((err, values) => {
  99. if (!err) {
  100. this.loading = true;
  101. let params = {
  102. userName: values.loginUserName,
  103. password: values.loginPassword,
  104. token: AUTH_TOKEN_FRONT,
  105. };
  106. this.$_http
  107. .get(this.$_API.INTERFACE_GET_USER_LOGIN, {
  108. auth: {
  109. username: params.userName,
  110. password: params.password,
  111. },
  112. })
  113. .then((res) => {
  114. console.log(res);
  115. this.loading = false;
  116. if (res.data) {
  117. this.getEngineeringWorkList(res.data); // 获取工种,并存到vuex
  118. } else {
  119. this.loginForm.setFields({
  120. password: {
  121. value: values.loginUserName,
  122. errors: [new Error('账号密码不正确')],
  123. },
  124. passwordSecond: {
  125. value: values.loginPassword,
  126. errors: [new Error('账号密码不正确')],
  127. },
  128. });
  129. }
  130. })
  131. .catch(() => {
  132. this.loading = false;
  133. });
  134. }
  135. });
  136. },
  137. // 获取工种,并存到vuex
  138. getEngineeringWorkList(userInfo) {
  139. this.loading = true;
  140. this.$_http
  141. .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
  142. .then((res) => {
  143. this.$store.commit('common/SET_ENGINEERING_WORK_LIST', res.data);
  144. sessionStorage.setItem(
  145. 'ENGINEERING_WORK_LIST',
  146. JSON.stringify(res.data)
  147. );
  148. this.getExamQuestionTypeConditionParentList(userInfo); // 获取试题类型-父类信息,并存到vuex
  149. })
  150. .catch(() => {
  151. this.loading = false;
  152. this.setUserInfo(userInfo); // 设置用户信息,跳转到首页
  153. });
  154. },
  155. // 获取试题类型-父类信息,并存到vuex
  156. getExamQuestionTypeConditionParentList(userInfo) {
  157. this.$_http
  158. .get(this.$_API.INTERFACE_GET_EXAMS_QUESTION_TYPE_CONDITION_PARENT)
  159. .then((res) => {
  160. this.$store.commit(
  161. 'common/SET_EXAM_QUESTION_TYPE_CONDITION_PARENT',
  162. res.data
  163. );
  164. sessionStorage.setItem(
  165. 'EXAM_QUESTION_TYPE_CONDITION_PARENT',
  166. JSON.stringify(res.data)
  167. );
  168. this.setUserInfo(userInfo); // 设置用户信息,跳转到首页
  169. })
  170. .catch(() => {
  171. this.loading = false;
  172. });
  173. },
  174. // 设置用户信息,跳转到首页
  175. setUserInfo(userInfo) {
  176. this.$store.commit('user/SET_LOGIN', userInfo); // // 存用户信息
  177. this.$store.commit('user/SET_MENU', []); // 赋值菜单
  178. this.loading = false;
  179. this.$router.push({ name: 'home' });
  180. },
  181. },
  182. };
  183. </script>
  184. <style lang="less">
  185. .login-box {
  186. .ant-input,
  187. .ant-btn {
  188. height: 40px;
  189. }
  190. }
  191. </style>
  192. <style lang="less" scoped>
  193. @import '~@/styles/common/variable.less';
  194. .login-box {
  195. .login-body {
  196. width: 100vw;
  197. height: 100vh;
  198. background-image: url('../../assets/image/login/background.png');
  199. background-repeat: no-repeat;
  200. background-size: cover;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. position: relative;
  205. .login-title-row {
  206. margin-top: 10%;
  207. padding-right: 50px;
  208. display: flex;
  209. align-items: center;
  210. .login-title-logo {
  211. width: 45px;
  212. height: 45px;
  213. }
  214. .login-title-txt {
  215. margin-left: 30px;
  216. font-size: 33px;
  217. font-weight: bold;
  218. color: @mainColorBlack;
  219. }
  220. }
  221. .login-description-row {
  222. margin-top: 10px;
  223. margin-bottom: 5%;
  224. padding-right: 50px;
  225. display: flex;
  226. color: @mainColorBlack45;
  227. .login-description-none {
  228. width: 45px;
  229. }
  230. .login-description-txt {
  231. margin-left: 45px;
  232. width: 132px;
  233. font-size: 14px;
  234. text-align: center;
  235. }
  236. }
  237. .login-enterprise {
  238. position: absolute;
  239. bottom: 5%;
  240. span {
  241. font-size: 12px;
  242. color: @mainColorBlack45;
  243. white-space: nowrap;
  244. flex-wrap: nowrap;
  245. }
  246. }
  247. }
  248. }
  249. </style>