Login.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="login">
  3. <div class="login-box">
  4. <div class="login-card">
  5. <img class="login-logo" src="../../../assets/images/login-logo.png" />
  6. <div class="middle-text">
  7. <h1>欢迎登录</h1>
  8. <h1>题库管理系统</h1>
  9. </div>
  10. <div class="bottom-text">
  11. <p>Copyright &copy; 2021</p>
  12. <p>
  13. <a href="https://www.qmth.com.cn" target="_block">启明泰和</a>.<a
  14. href="https://beian.miit.gov.cn/"
  15. target="_blank"
  16. >鄂ICP备12000033号-13</a
  17. >
  18. <span v-if="version" class="margin-left-10">v{{ version }}</span>
  19. </p>
  20. </div>
  21. </div>
  22. <div class="login-form-box">
  23. <div class="login-title">输入信息</div>
  24. <div class="login-sub-title">请输入账号与密码</div>
  25. <el-form
  26. ref="loginForm"
  27. :model="loginInfo"
  28. :rules="loginRules"
  29. size="large"
  30. >
  31. <el-form-item prop="accountValue">
  32. <el-input
  33. v-model.trim="loginInfo.accountValue"
  34. placeholder="请输入账号"
  35. clearable
  36. @keydown.enter.native="submit"
  37. >
  38. <!-- <i slot="prefix" class="icon icon-username"></i> -->
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item prop="password">
  42. <el-input
  43. v-model.trim="loginInfo.password"
  44. type="password"
  45. placeholder="请输入密码"
  46. show-password
  47. @keydown.enter.native="submit"
  48. >
  49. <!-- <i slot="prefix" class="icon icon-password"></i> -->
  50. </el-input>
  51. </el-form-item>
  52. <el-form-item v-if="dialogVisible" prop="smsCode">
  53. <el-input
  54. v-model.trim="loginInfo.smsCode"
  55. placeholder="请输入短信验证码"
  56. clearable=""
  57. >
  58. <i slot="prefix" class="icon icon-code"></i>
  59. </el-input>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button
  63. type="primary"
  64. :disabled="isSubmit"
  65. @click="submit"
  66. style="width: 100%"
  67. >登录</el-button
  68. >
  69. </el-form-item>
  70. </el-form>
  71. </div>
  72. </div>
  73. <!-- <main class="login-main">
  74. <div class="login-title">
  75. <p>欢迎登录</p>
  76. <p>题库管理系统</p>
  77. </div>
  78. <div class="login-footer">
  79. Copyright &copy; 2021
  80. <a href="https://www.qmth.com.cn" target="_block">启明泰和</a>.<a
  81. href="https://beian.miit.gov.cn/"
  82. target="_blank"
  83. >鄂ICP备12000033号-13</a
  84. >
  85. <span v-if="version" class="margin-left-10">v{{ version }}</span>
  86. </div>
  87. <div class="login-body" @keyup.enter="submit">
  88. <h1 class="login-body-title">题库管理系统</h1>
  89. <el-form ref="loginForm" :model="loginInfo" :rules="loginRules">
  90. <el-form-item prop="accountValue">
  91. <el-input
  92. v-model.trim="loginInfo.accountValue"
  93. placeholder="请输入账号"
  94. clearable
  95. >
  96. <i slot="prefix" class="icon icon-username"></i>
  97. </el-input>
  98. </el-form-item>
  99. <el-form-item prop="password">
  100. <el-input
  101. v-model.trim="loginInfo.password"
  102. type="password"
  103. placeholder="请输入密码"
  104. clearable
  105. >
  106. <i slot="prefix" class="icon icon-password"></i>
  107. </el-input>
  108. </el-form-item>
  109. <el-form-item v-if="dialogVisible" prop="smsCode">
  110. <el-input
  111. v-model.trim="loginInfo.smsCode"
  112. placeholder="请输入短信验证码"
  113. clearable=""
  114. >
  115. <i slot="prefix" class="icon icon-code"></i>
  116. </el-input>
  117. </el-form-item>
  118. <el-form-item>
  119. <el-button
  120. class="login-submit-btn"
  121. type="danger"
  122. :disabled="isSubmit"
  123. @click="submit"
  124. >登录</el-button
  125. >
  126. </el-form-item>
  127. </el-form>
  128. </div>
  129. </main> -->
  130. </div>
  131. </template>
  132. <script>
  133. import { mapActions, mapState } from "vuex";
  134. import { USER_SIGNIN } from "../store/user";
  135. import { QUESTION_API } from "@/constants/constants";
  136. export default {
  137. name: "Login",
  138. data() {
  139. return {
  140. isSubmit: false,
  141. dialogVisible: false,
  142. loginInfo: {
  143. rootOrgId: "",
  144. domain: "",
  145. code: "",
  146. accountType: "COMMON_LOGIN_NAME",
  147. accountValue: "",
  148. password: "",
  149. smsCode: null,
  150. },
  151. loginRules: {
  152. accountValue: [
  153. {
  154. required: true,
  155. message: "请输入用户名",
  156. trigger: "change",
  157. },
  158. ],
  159. password: [
  160. {
  161. validator: (rule, value, callback) => {
  162. if (
  163. value &&
  164. (/^([0-9]+|[a-z]+|[A-Z]+)$/.test(value) ||
  165. !/^[a-zA-Z0-9_]+$/.test(value))
  166. ) {
  167. callback(
  168. new Error("密码只能大写字母、小写字母、数字至少两种组成")
  169. );
  170. } else {
  171. callback();
  172. }
  173. },
  174. trigger: "change",
  175. },
  176. {
  177. required: true,
  178. min: 8,
  179. max: 16,
  180. message: "密码只能8-16个字符",
  181. trigger: "change",
  182. },
  183. ],
  184. // password: [
  185. // {
  186. // required: true,
  187. // pattern: /^[a-zA-Z0-9_]{1,20}$/,
  188. // message: "密码只能由数字、字母和下划线组成,长度1-20个字符",
  189. // trigger: "change",
  190. // },
  191. // ],
  192. smsCode: [
  193. {
  194. required: true,
  195. message: "请输入短信验证码",
  196. trigger: "change",
  197. },
  198. ],
  199. },
  200. };
  201. },
  202. computed: {
  203. ...mapState(["version"]),
  204. },
  205. watch: {
  206. $route(to) {
  207. this.loginInfo.code = to.query.code;
  208. },
  209. },
  210. created() {
  211. if (this.$route.hash && this.$route.hash.startsWith("#/access?")) {
  212. this.$router.push(this.$route.hash.slice(1));
  213. return;
  214. }
  215. this.loginInfo.domain = window.location.hostname.split(".")[0];
  216. sessionStorage.clear();
  217. var params = this.$route.query;
  218. this.loginInfo.code = params.code;
  219. },
  220. methods: {
  221. ...mapActions([USER_SIGNIN]),
  222. async submit() {
  223. const valid = await this.$refs.loginForm.validate().catch(() => {});
  224. if (!valid) return;
  225. var url = QUESTION_API + "/auth/login";
  226. this.$httpWithMsg
  227. .post(url, this.loginInfo)
  228. .then((response) => {
  229. var user = response.data;
  230. user.questionUnlock = false;
  231. this.USER_SIGNIN(user);
  232. this.$router.replace({ path: "/questions/tips" });
  233. this.$notify({
  234. message: "登录成功",
  235. type: "success",
  236. duration: 1000,
  237. });
  238. })
  239. .catch((error) => {
  240. if (error.response.data.code === "UQ-003100") {
  241. this.dialogVisible = true;
  242. }
  243. });
  244. },
  245. loginWithSms() {
  246. this.dialogVisible = false;
  247. this.submit();
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .login {
  254. width: 100vw;
  255. height: 100vh;
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. background: url("../../../assets/images/login-bg.png") 0 0 no-repeat;
  260. background-size: 100% 100%;
  261. .login-box {
  262. width: 800px;
  263. height: 500px;
  264. display: flex;
  265. border-radius: 30px;
  266. overflow: hidden;
  267. .login-card {
  268. width: 400px;
  269. height: 100%;
  270. background: url("../../../assets/images/login-card.png") 0 0 no-repeat;
  271. background-size: 100% 100%;
  272. padding: 48px;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: space-between;
  276. .login-logo {
  277. width: 78px;
  278. }
  279. .middle-text {
  280. font-size: 42px;
  281. font-weight: bold;
  282. color: #fff;
  283. line-height: 56px;
  284. }
  285. .bottom-text {
  286. p {
  287. color: #e5e5e5;
  288. line-height: 22px;
  289. font-size: 14px;
  290. }
  291. }
  292. }
  293. .login-form-box {
  294. flex: 1;
  295. background-color: #fff;
  296. padding: 40px;
  297. .login-title {
  298. font-size: 24px;
  299. color: #262626;
  300. font-weight: bold;
  301. margin-top: 66px;
  302. }
  303. .login-sub-title {
  304. font-size: 16px;
  305. color: #8c8c8c;
  306. margin-top: 10px;
  307. margin-bottom: 25px;
  308. }
  309. }
  310. }
  311. }
  312. </style>