login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div class="login">
  3. <div class="login-content">
  4. <!-- 公告栏 -->
  5. <div class="announcement">
  6. <div class="announcement-header">
  7. <div class="announcement-bg">
  8. 公示公告 <img src="../assets/img/装饰.png" alt="" />
  9. </div>
  10. <!-- <el-button type="primary" round size="mini">进入公告</el-button> -->
  11. </div>
  12. <div class="announcement-list">
  13. <div v-for="item in announcements" :key="item.noticeId" class="announcement-item"
  14. :class="{ highlighted: item.show === true }">
  15. <div class="announcement-item-header" @click="announcementChange(item)">
  16. <el-tooltip class="item" effect="dark" :content="item.noticeTitle" placement="left-start">
  17. <div class="announcement-title" :class="{ highlighted: item.show === true }">
  18. {{ item.noticeTitle }}
  19. </div>
  20. </el-tooltip>
  21. <div class="announcement-date">{{ item.updateTime }}</div>
  22. </div>
  23. <div class="announcement-qs" v-if="item.show">
  24. <div v-html="item.noticeContent"></div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  30. <h3 class="title">用户登录</h3>
  31. <el-form-item prop="username">
  32. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  33. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  34. </el-input>
  35. </el-form-item>
  36. <el-form-item prop="password">
  37. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
  38. @keyup.enter.native="handleLogin">
  39. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  40. </el-input>
  41. </el-form-item>
  42. <el-form-item prop="code" v-if="captchaEnabled">
  43. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"
  44. @keyup.enter.native="handleLogin">
  45. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  46. </el-input>
  47. <div class="login-code">
  48. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  49. </div>
  50. </el-form-item>
  51. <el-checkbox v-model="loginForm.rememberMe" style="margin: 0px 0px 25px 0px">记住密码</el-checkbox>
  52. <el-form-item style="width: 100%">
  53. <el-button round :loading="loading" size="medium" type="primary" style="width: 100%"
  54. @click.native.prevent="handleLogin">
  55. <span v-if="!loading">登 录</span>
  56. <span v-else>登 录 中...</span>
  57. </el-button>
  58. <div style="float: right" v-if="register">
  59. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  60. </div>
  61. </el-form-item>
  62. <el-form-item prop="">
  63. <div>
  64. <el-button type="text">数字登录证书</el-button><el-button type="text">短信验证码登录</el-button><el-button
  65. type="text">邮件验证码登录</el-button><el-button type="text">微信登录</el-button>
  66. </div>
  67. </el-form-item>
  68. </el-form>
  69. </div>
  70. <!-- 底部 -->
  71. <div class="el-login-footer">
  72. <p>版权所有 上海市疾病预防控制中心</p>
  73. <p>地址:上海市中申虹路1509号</p>
  74. <p>电话:021-62758710 邮编:200336</p>
  75. <p>提醒:本系统建议采用IE11或 Google chrome(谷歌)或火狐或奇安信的测览雅</p>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. // 公示公告
  81. import { listNotice } from "@/api/system/notice";
  82. import { getCodeImg } from "@/api/login";
  83. import Cookies from "js-cookie";
  84. import { encrypt, decrypt } from "@/utils/jsencrypt";
  85. export default {
  86. name: "Login",
  87. data() {
  88. return {
  89. codeUrl: "",
  90. loginForm: {
  91. username: "admin",
  92. password: "admin123",
  93. rememberMe: false,
  94. code: "",
  95. uuid: "",
  96. },
  97. loginRules: {
  98. username: [
  99. { required: true, trigger: "blur", message: "请输入您的账号" },
  100. ],
  101. password: [
  102. { required: true, trigger: "blur", message: "请输入您的密码" },
  103. ],
  104. code: [{ required: true, trigger: "change", message: "请输入验证码" }],
  105. },
  106. loading: false,
  107. // 验证码开关
  108. captchaEnabled: true,
  109. // 注册开关
  110. register: false,
  111. redirect: undefined,
  112. announcements: [
  113. // {
  114. // title: "系统平台已接入,客户端软件登录后下载;",
  115. // qs: "2024-12-18系统平台已接入,客户端软件登录后下载:系统平台已接入,客户端系统平台已接入客",
  116. // date: "2024-01-25",
  117. // show: false,
  118. // },
  119. // {
  120. // title: "资源管理系统",
  121. // qs: "2024-12-18系统平台已接入,客户端软件登录后下载:系统平台已接入,客户端系统平台已接入客",
  122. // date: "2024-01-25",
  123. // show: false,
  124. // },
  125. // {
  126. // title: "邮件系统",
  127. // qs: "2024-12-18系统平台已接入,客户端软件登录后下载:系统平台已接入,客户端系统平台已接入客",
  128. // date: "2024-01-25",
  129. // show: false,
  130. // },
  131. ],
  132. };
  133. },
  134. watch: {
  135. $route: {
  136. handler: function (route) {
  137. this.redirect = route.query && route.query.redirect;
  138. },
  139. immediate: true,
  140. },
  141. },
  142. created() {
  143. this.getCode();
  144. this.getCookie();
  145. this.getListNotice()
  146. },
  147. methods: {
  148. getListNotice () {
  149. listNotice({ noticeType: 2 }).then(response => {
  150. response.rows.forEach(item => {
  151. item.show = false
  152. })
  153. this.announcements = response.rows;
  154. });
  155. },
  156. announcementChange(item) {
  157. this.announcements.forEach((element) => {
  158. if (element.noticeId === item.noticeId) {
  159. element.show = !element.show;
  160. }
  161. });
  162. },
  163. getCode() {
  164. getCodeImg().then((res) => {
  165. this.captchaEnabled =
  166. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  167. if (this.captchaEnabled) {
  168. this.codeUrl = "data:image/gif;base64," + res.img;
  169. this.loginForm.uuid = res.uuid;
  170. }
  171. });
  172. },
  173. getCookie() {
  174. const username = Cookies.get("username");
  175. const password = Cookies.get("password");
  176. const rememberMe = Cookies.get("rememberMe");
  177. this.loginForm = {
  178. username: username === undefined ? this.loginForm.username : username,
  179. password:
  180. password === undefined ? this.loginForm.password : decrypt(password),
  181. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  182. };
  183. },
  184. handleLogin() {
  185. this.$refs.loginForm.validate((valid) => {
  186. if (valid) {
  187. this.loading = true;
  188. if (this.loginForm.rememberMe) {
  189. Cookies.set("username", this.loginForm.username, { expires: 30 });
  190. Cookies.set("password", encrypt(this.loginForm.password), {
  191. expires: 30,
  192. });
  193. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  194. expires: 30,
  195. });
  196. } else {
  197. Cookies.remove("username");
  198. Cookies.remove("password");
  199. Cookies.remove("rememberMe");
  200. }
  201. this.$store
  202. .dispatch("Login", this.loginForm)
  203. .then(() => {
  204. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  205. })
  206. .catch(() => {
  207. this.loading = false;
  208. if (this.captchaEnabled) {
  209. this.getCode();
  210. }
  211. });
  212. }
  213. });
  214. },
  215. },
  216. };
  217. </script>
  218. <style rel="stylesheet/scss" lang="scss" scoped>
  219. .login {
  220. display: flex;
  221. justify-content: center;
  222. align-items: center;
  223. height: 100%;
  224. background-image: url("../assets/img/互联网门户登录页.jpg");
  225. background-size: cover;
  226. }
  227. .title {
  228. margin: 0px auto 30px auto;
  229. text-align: center;
  230. color: #707070;
  231. font-weight: 700;
  232. }
  233. .login-form {
  234. border-radius: 6px;
  235. background: rgba(255, 255, 255, 0.7);
  236. width: 440px;
  237. padding: 25px 25px 5px 25px;
  238. .el-input__inner{
  239. border-radius: 19px;
  240. border: 1px solid #2692ff;
  241. }
  242. .el-input {
  243. height: 38px;
  244. input {
  245. height: 38px;
  246. }
  247. }
  248. .input-icon {
  249. height: 39px;
  250. width: 14px;
  251. margin-left: 2px;
  252. }
  253. }
  254. .login-tip {
  255. font-size: 13px;
  256. text-align: center;
  257. color: #bfbfbf;
  258. }
  259. .login-code {
  260. width: 33%;
  261. height: 38px;
  262. float: right;
  263. img {
  264. cursor: pointer;
  265. vertical-align: middle;
  266. }
  267. }
  268. .el-login-footer {
  269. // height: 40px;
  270. // line-height: 40px;
  271. position: fixed;
  272. bottom: 0;
  273. width: 100%;
  274. text-align: center;
  275. color: #fff;
  276. font-family: Arial;
  277. font-size: 12px;
  278. letter-spacing: 1px;
  279. }
  280. .login-code-img {
  281. height: 38px;
  282. }
  283. .login-content {
  284. width: 100%;
  285. display: flex;
  286. justify-content: space-evenly;
  287. }
  288. .announcement {
  289. height: 400px;
  290. width: 440px;
  291. background: rgba(255, 255, 255, 0.7);
  292. border-radius: 10px;
  293. padding: 15px;
  294. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  295. }
  296. .announcement-header {
  297. font-size: 16px;
  298. height: 30px;
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. .announcement-bg {
  303. font-weight: 700;
  304. color: #1a8ff9;
  305. img {
  306. margin-left: 5px;
  307. }
  308. }
  309. }
  310. .announcement-list {
  311. margin-top: 10px;
  312. padding-right: 20px;
  313. height: 320px;
  314. overflow-y: auto;
  315. // overflow: hidden;
  316. }
  317. .announcement-item {
  318. margin-bottom: 10px;
  319. padding: 10px;
  320. border-bottom: 1px dashed #f2f1f3;
  321. // margin-bottom: 10px;
  322. .announcement-item-header {
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-between;
  326. }
  327. .announcement-qs {
  328. font-size: 12px;
  329. color: #a3acb3;
  330. }
  331. &.highlighted {
  332. background-color: rgba(#dbe7f5, 0.3); /* 淡蓝色背景 */
  333. }
  334. }
  335. .announcement-title {
  336. cursor: pointer;
  337. max-width: 260px;
  338. font-size: 14px;
  339. color: #828282;
  340. white-space: nowrap; // 防止文本换行
  341. overflow: hidden; // 超出部分隐藏
  342. text-overflow: ellipsis; // 如果超出部分隐藏,则使用省略号显示
  343. &.highlighted {
  344. font-weight: 700;
  345. color: #3981db; /* 深蓝色标题 */
  346. }
  347. }
  348. .announcement-date {
  349. font-size: 12px;
  350. color: #888;
  351. }
  352. </style>