Home.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="home">
  3. <div class="top"></div>
  4. <div class="flex-center flex-column login-body">
  5. <h2>中医智能辅助诊疗系统</h2>
  6. <div class="login-form" v-if="!useToken">
  7. <!-- <div class="flex-center">
  8. <img src="../assets/logo.png" alt="" class="logo" />
  9. </div>-->
  10. <div class="input-body flex-vertical-center-l">
  11. <img src="../assets/log-user.png" />
  12. <input type="text" placeholder="请输入用户名" v-model="name" @keydown.enter="login" />
  13. </div>
  14. <div class="input-body flex-vertical-center-l">
  15. <img src="../assets/log-pas.png" />
  16. <input type="password" placeholder="请输入密码" v-model="pas" @keydown.enter="login" />
  17. </div>
  18. <div class="flex-vertical-center-l">
  19. <div class="input-body flex-vertical-center-l">
  20. <!-- <img src='../assets/log-code.png' /> -->
  21. <input type="text" placeholder="请输入验证码" v-model="code" @keydown.enter="login" />
  22. </div>
  23. <img :src="src" alt class="code" @click="changeImg()" />
  24. </div>
  25. <div class="login-btn flex-center" @click="login()">登录</div>
  26. <div>
  27. <el-checkbox v-model="checked">记住我</el-checkbox>
  28. </div>
  29. </div>
  30. <div v-else-if="useTokenError" style="max-width: 50vw;background-color: rgba(255,255,255,0.4);">
  31. <el-result icon="error" title="登录错误" :subTitle="useTokenError"></el-result>
  32. </div>
  33. </div>
  34. <div class="bottom">
  35. <!-- <span>杭州寻脉科技有限公司</span> -->
  36. <!-- <a href="https://beian.miit.gov.cn/#/Integrated/index">网站备案号 浙icp备2021018580号-1</a> -->
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import {login, getCode, getCodeimg, loginBySSO} from '@/api/user.js';
  42. function getURLSearchParams(value) {
  43. value ??= `${ location.search }&${ location.hash.split('?')[ 1 ] || '' }`;
  44. return new URLSearchParams(value);
  45. }
  46. export default {
  47. name: "Home",
  48. components: {},
  49. data() {
  50. return {
  51. name: "",
  52. pas: "",
  53. code: "",
  54. useToken: true,
  55. useTokenError: '',
  56. checked: false,
  57. src: process.env.VUE_APP_BASE_API + "captchaImage"
  58. };
  59. },
  60. created() {
  61. const sso = getURLSearchParams()
  62. const keys = ['accessToken', 'token'];
  63. this.useToken = keys.find(key => sso.has(key));
  64. if (this.useToken) {
  65. localStorage.setItem("sso-token", keys.find(key => sso.get(key)));
  66. this.loginBySSO(sso.toString())
  67. return;
  68. }
  69. localStorage.removeItem("sso-token");
  70. // this.getCodeimg()
  71. this.changeImg();
  72. setTimeout(() => {
  73. sessionStorage.setItem("isAllow", "true");
  74. }, 1000);
  75. },
  76. methods: {
  77. async getCodeimg() {
  78. let res = await getCodeimg();
  79. let time = new Date().getTime();
  80. this.src = process.env.VUE_APP_BASE_API + "captchaImage?time=" + time;
  81. },
  82. async login() {
  83. localStorage.removeItem("token");
  84. if (this.name == "") {
  85. this.$message.warning("请输入用户名");
  86. return;
  87. }
  88. if (this.pas == "") {
  89. this.$message.warning("请输入密码");
  90. return;
  91. }
  92. if (this.code == "") {
  93. this.$message.warning("请输入验证码");
  94. return;
  95. }
  96. const loading = this.$loading({
  97. lock: true,
  98. text: "正在登录",
  99. spinner: "el-icon-loading",
  100. background: "rgba(0, 0, 0, 0.7)"
  101. });
  102. let params = {
  103. password: this.pas,
  104. username: this.name,
  105. vercode: this.code
  106. };
  107. let res = await login(params).catch(err => {
  108. loading.close();
  109. this.changeImg();
  110. });
  111. if (res.ResultCode == 0) {
  112. loading.close();
  113. this.$message.success("登陆成功");
  114. localStorage.setItem("token", res.Data.token);
  115. setTimeout(() => {
  116. this.$router.push({
  117. path: "/index/todaypatients"
  118. });
  119. }, 1500);
  120. }
  121. },
  122. async loginBySSO(value) {
  123. this.useTokenError = '';
  124. let loading;
  125. const timer = setTimeout(() => {
  126. loading = this.$loading({
  127. lock: true,
  128. text: '正在登录',
  129. spinner: 'el-icon-loading',
  130. background: 'rgba(0, 0, 0, 0.7)',
  131. });
  132. }, 2000);
  133. try {
  134. const token = await loginBySSO(value);
  135. localStorage.setItem('token', token);
  136. this.$nextTick(() => {
  137. this.$router.push({path: '/index/todaypatients'});
  138. });
  139. } catch (e) {
  140. this.useTokenError = e.message;
  141. }
  142. clearTimeout(timer);
  143. if (loading) loading.close();
  144. },
  145. // 修改验证码
  146. changeImg() {
  147. // let time = new Date().getTime()
  148. // this.src = this.src + '?time=' + time
  149. this.getCodeimg();
  150. }
  151. }
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. @import "../style/common.scss";
  156. .home {
  157. width: 100%;
  158. height: 100%;
  159. background: #fff;
  160. background: url("../assets/log-bg.png") no-repeat;
  161. background-size: 100% 100%;
  162. background-position: center;
  163. .top {
  164. width: 100%;
  165. height: 50%;
  166. // background: url('../assets/login-bg.png') no-repeat;
  167. background-position: center;
  168. background-size: 100% 100%;
  169. }
  170. .login-body {
  171. position: absolute;
  172. top: 0;
  173. bottom: 0;
  174. left: 0;
  175. right: 0;
  176. // background: red;
  177. h2 {
  178. font-size: 58px;
  179. font-family: Source Han Sans CN;
  180. font-weight: bold;
  181. color: #ffffff;
  182. margin-bottom: 83px;
  183. }
  184. .logo {
  185. width: 92px;
  186. margin: 0 auto 20px;
  187. }
  188. .login-btn {
  189. height: 56px;
  190. // background: #9f643a;
  191. background: #9F643A;
  192. opacity: 0.91;
  193. border-radius: 8px;
  194. font-size: 18px;
  195. font-family: Microsoft YaHei;
  196. font-weight: 400;
  197. color: #ffffff;
  198. cursor: pointer;
  199. margin-bottom: 20px;
  200. }
  201. .login-form {
  202. width: 509px;
  203. // height: 377px;
  204. box-sizing: border-box;
  205. padding: 23px 47px 23px;
  206. // background: rgba($color: #fff, $alpha: 0.35);
  207. background: #fff;
  208. box-shadow: 0px 3px 8px 0px rgba(30, 72, 111, 0.35);
  209. // opacity: 0.35;
  210. border-radius: 10px;
  211. .code {
  212. width: 170px;
  213. height: 44px;
  214. border-radius: 8px;
  215. margin-left: 20px;
  216. margin-bottom: 20px;
  217. }
  218. .input-body {
  219. box-sizing: border-box;
  220. flex: 1;
  221. padding: 14px 27px;
  222. background: #ffffff;
  223. border: 1px solid #e5e5e5;
  224. // box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.3);
  225. border-radius: 8px;
  226. margin-bottom: 20px;
  227. img {
  228. width: 14px;
  229. }
  230. input {
  231. flex: 1;
  232. border: 0;
  233. outline: none;
  234. font-size: 14px;
  235. font-family: Microsoft YaHei;
  236. font-weight: 400;
  237. line-height: 20px;
  238. margin-left: 20px;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. .bottom {
  245. position: fixed;
  246. left: 0;
  247. right: 0;
  248. bottom: 42px;
  249. text-align: center;
  250. font-size: 20px;
  251. font-family: PingFang SC;
  252. font-weight: bold;
  253. color: #ffffff;
  254. a {
  255. color: #fff;
  256. text-decoration: none;
  257. margin-left: 30px;
  258. }
  259. }
  260. </style>