login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="login" id="loginBox">
  3. <div class="logopositon">
  4. <!-- <img src="../assets/images/yunlian_logo.png" alt="">-->
  5. </div>
  6. <div class="login-con">
  7. <div class="img-box">
  8. <div class="imgline1">
  9. 一站式私域平台
  10. </div>
  11. <div class="imgline2">
  12. 助力企业打造自主客户资产池!
  13. </div>
  14. </div>
  15. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  16. <div class="title">{{vueAppTitle}}</div>
  17. <div class="title-line"></div>
  18. <el-form-item prop="tenantCode">
  19. <el-input v-model="loginForm.tenantCode" type="text" auto-complete="off" placeholder="企业编号(选填,如 test001)" class="tenantCode" >
  20. <img slot="prefix" src="../assets/images/user.png" class="input-icon "/>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="username">
  24. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" class="username" >
  25. <img slot="prefix" src="../assets/images/user.png" class="input-icon "/>
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item prop="password">
  29. <el-input
  30. v-model="loginForm.password"
  31. :type="passwordtype"
  32. auto-complete="off"
  33. placeholder="密码"
  34. @keyup.enter.native="handleLogin"
  35. class="password"
  36. >
  37. <!-- <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> -->
  38. <img slot="prefix" src="../assets/images/pass.png" class="input-icon" />
  39. <img slot="suffix" src="../assets/images/eyeoff.png" class="input-icon2" v-if="ispassword" @click.stop="changetype()"/>
  40. <img slot="suffix" src="../assets/images/eyeopen.png" class="input-icon2" v-else @click.stop="changetype()"/>
  41. </el-input>
  42. </el-form-item>
  43. <el-form-item prop="code" v-if="captchaOnOff">
  44. <el-input
  45. v-model="loginForm.code"
  46. auto-complete="off"
  47. placeholder="验证码"
  48. style="width: 63%"
  49. @keyup.enter.native="handleLogin"
  50. >
  51. <!-- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/> -->
  52. <img slot="prefix" src="../assets/images/code.png" class="input-icon" />
  53. </el-input>
  54. <div class="login-code">
  55. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  56. </div>
  57. </el-form-item>
  58. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  59. <el-form-item style="width:100%;">
  60. <el-button
  61. :loading="loading"
  62. size="medium"
  63. type="primary"
  64. style="width:100%;"
  65. @click.native.prevent="handleLogin"
  66. >
  67. <span v-if="!loading">登 录</span>
  68. <span v-else>登 录 中...</span>
  69. </el-button>
  70. </el-form-item>
  71. </el-form>
  72. </div>
  73. <!-- &lt;!&ndash; 微信扫码弹框 &ndash;&gt;-->
  74. <!-- <WechatLoginDialog-->
  75. <!-- ref="wechatDialog"-->
  76. <!-- :ticket="loginForm.username"-->
  77. <!-- :visible.sync="wechatDialogVisible"-->
  78. <!-- @loginSuccess="handleWechatLoginSuccess"-->
  79. <!-- :redirect="redirect"-->
  80. <!-- />-->
  81. <!-- 底部 -->
  82. <div class="el-login-footer">
  83. <span>{{companyName}}</span>
  84. <a :href="icpUrl" target="_bank">{{icpRecord}}</a>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import { getCodeImg } from "@/api/login";
  90. import Cookies from "js-cookie";
  91. import { encrypt, decrypt } from '@/utils/jsencrypt'
  92. import { getFirstLogin } from "@/api/login";
  93. // import WechatLoginDialog from "@/views/WechatLoginDialog";
  94. import { setToken } from "@/utils/auth";
  95. import {getConfigByKey} from "@/api/system/config";
  96. import Vue from 'vue'
  97. export default {
  98. name: "Login",
  99. // components: { WechatLoginDialog },
  100. data() {
  101. return {
  102. codeUrl: "",
  103. captchaOnOff: true,
  104. vueAppTitle: process.env.VUE_APP_TITLE,
  105. companyName: process.env.VUE_APP_COMPANY_NAME,
  106. icpRecord: process.env.VUE_APP_ICP_RECORD,
  107. icpUrl: process.env.VUE_APP_ICP_URL,
  108. cookiePassword: "",
  109. wechatDialogVisible: false,
  110. loginForm: {
  111. username: "",
  112. password: "",
  113. rememberMe: false,
  114. code: "",
  115. uuid: "",
  116. tenantCode: "",
  117. },
  118. loginRules: {
  119. tenantCode: [
  120. { required: true, trigger: "blur", message: "租户编号不能为空" }
  121. ],
  122. username: [
  123. { required: true, trigger: "blur", message: "用户名不能为空" }
  124. ],
  125. password: [
  126. { required: true, trigger: "blur", message: "密码不能为空" },
  127. { min: 5, max: 20, message: "密码长度为5-20位", trigger: ["blur", "change"] }
  128. ],
  129. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  130. },
  131. loading: false,
  132. redirect: undefined,
  133. passwordtype:'password',
  134. ispassword:true
  135. };
  136. },
  137. watch: {
  138. $route: {
  139. handler: function(route) {
  140. this.redirect = route.query && route.query.redirect;
  141. },
  142. immediate: true
  143. }
  144. },
  145. mounted () {
  146. },
  147. created() {
  148. this.getCode();
  149. this.getCookie();
  150. },
  151. methods: {
  152. // 重新加载运行时配置
  153. async reloadRuntimeConfig() {
  154. try {
  155. const res = await getConfigByKey('his.adminUi.config')
  156. const configValue = res?.data?.configValue
  157. if (!configValue) return
  158. // 后端配置 JSON
  159. const form = JSON.parse(configValue)
  160. // 直接更新全局配置
  161. const config = {
  162. VUE_APP_LIVE_WS_URL: form.liveWebSocketUrl || '',
  163. VUE_APP_COURSE_DEFAULT: form.courseDefaultType || '1',
  164. }
  165. // 更新到全局
  166. Vue.prototype.$runtimeConfig = config
  167. } catch (error) {
  168. console.error('重新加载运行时配置异常:', error)
  169. }
  170. },
  171. checkFirstLogin() {
  172. getFirstLogin().then(res => {
  173. this.loading = false;
  174. if (res.code === 200 && res.data) {
  175. localStorage.setItem('isFirstLogin', 'true');
  176. this.$router.push('/set-password');
  177. } else {
  178. localStorage.setItem('isFirstLogin', 'false');
  179. this.$router.push({ path: this.redirect || "/" });
  180. }
  181. }).catch(() => {
  182. this.loading = false;
  183. this.$router.push({ path: this.redirect || "/" });
  184. });
  185. },
  186. getCode() {
  187. getCodeImg().then(res => {
  188. this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  189. if (this.captchaOnOff) {
  190. this.codeUrl = "data:image/gif;base64," + res.img;
  191. this.loginForm.uuid = res.uuid;
  192. }
  193. });
  194. },
  195. getCookie() {
  196. const username = Cookies.get("username");
  197. const rememberMe = Cookies.get('rememberMe')
  198. const tenantCode = Cookies.get('tenantCode')
  199. this.loginForm = {
  200. username: username === undefined ? this.loginForm.username : username,
  201. password: '',
  202. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  203. tenantCode: this.loginForm.tenantCode || tenantCode || ''
  204. };
  205. },
  206. // 微信扫码成功回调
  207. handleWechatLoginSuccess(token) {
  208. this.loading = false
  209. this.$store.commit("SET_TOKEN", token);
  210. setToken(token);
  211. // 登录成功后检查是否是首次登录
  212. this.checkFirstLogin();
  213. },
  214. handleLogin() {
  215. this.$refs.loginForm.validate(valid => {
  216. if (valid) {
  217. this.loading = true;
  218. if (this.loginForm.rememberMe) {
  219. Cookies.set("username", this.loginForm.username, { expires: 30 });
  220. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  221. } else {
  222. Cookies.remove("username");
  223. Cookies.remove('rememberMe');
  224. }
  225. // 始终保存 tenantCode 用于后续 API 数据源切换
  226. if (this.loginForm.tenantCode) {
  227. Cookies.set('tenantCode', this.loginForm.tenantCode);
  228. }
  229. this.$store
  230. .dispatch("Login", {...this.loginForm, captchaOnOff: this.captchaOnOff})
  231. .then(res => {
  232. if (res.needSms) {
  233. this.loading = false;
  234. this.$message.warning('需要短信验证,但验证组件未启用,请联系管理员');
  235. } else {
  236. // 登录成功后检查是否是首次登录
  237. this.checkFirstLogin();
  238. }
  239. this.reloadRuntimeConfig()
  240. })
  241. .catch(res => {
  242. this.loading = false;
  243. this.getCode();
  244. });
  245. }
  246. });
  247. },
  248. changetype(){
  249. this.ispassword=!this.ispassword
  250. if(this.ispassword){
  251. this.passwordtype="password"
  252. }else{
  253. this.passwordtype="text"
  254. }
  255. }
  256. }
  257. };
  258. </script>
  259. <style rel="stylesheet/scss" lang="scss">
  260. .login {
  261. .logopositon{
  262. position: fixed;
  263. left: 30px;
  264. top: 30px;
  265. }
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. height: 100%;
  270. width: 100%;
  271. background-image: (url(../assets/images/login_bg.png) );
  272. background-size: 100% 100%;
  273. background-size: cover;
  274. .login-con{
  275. width: 880px;
  276. display: flex;
  277. align-items: center;
  278. justify-content: space-between;
  279. border-radius: 10px;
  280. .img-box{
  281. width: 440px;
  282. height: 500px;
  283. background-image: url(../assets/images/login_left.png);
  284. background-size: 100% 100%;
  285. color: #FFFFFF;
  286. .imgline1{
  287. font-size: 34px;
  288. font-weight:400;
  289. margin-left: 38px;
  290. margin-top: 38px;
  291. letter-spacing: 2px;
  292. }
  293. .imgline2{
  294. margin-left: 38px;
  295. font-size: 16px;
  296. margin-top: 6px;
  297. letter-spacing: 1px;
  298. }
  299. }
  300. }
  301. }
  302. .title {
  303. margin: 0px auto 15px auto;
  304. text-align: center;
  305. color: #202124;
  306. font-weight: 500;
  307. font-size: 20px;
  308. }
  309. .title-line{
  310. width: 40px;
  311. border-bottom: 2px solid #006CFF;
  312. margin: 0px auto 30px auto;
  313. }
  314. .login-form {
  315. box-sizing: border-box;
  316. background: #ffffff;
  317. width: 440px;
  318. height: 500px;
  319. padding: 40px 25px 5px 25px;
  320. box-shadow:4px -4px 10px rgba(0, 108, 255, 0.15);
  321. .el-input {
  322. height: 38px;
  323. input {
  324. height: 38px;
  325. }
  326. }
  327. .input-icon {
  328. height: 20px;
  329. width: 20px;
  330. margin-left: 2px;
  331. margin-top: 10px;
  332. }
  333. .input-icon2{
  334. height: 20px;
  335. width: 20px;
  336. margin-right: 4px;
  337. margin-top: 10px;
  338. }
  339. }
  340. .login-tip {
  341. font-size: 13px;
  342. text-align: center;
  343. color: #bfbfbf;
  344. }
  345. .login-code {
  346. width: 33%;
  347. height: 38px;
  348. float: right;
  349. img {
  350. cursor: pointer;
  351. vertical-align: middle;
  352. }
  353. }
  354. .el-login-footer {
  355. height: 40px;
  356. line-height: 40px;
  357. position: fixed;
  358. bottom: 0;
  359. width: 100%;
  360. text-align: center;
  361. color: #fff;
  362. font-family: Arial;
  363. font-size: 12px;
  364. letter-spacing: 1px;
  365. }
  366. .login-code-img {
  367. height: 38px;
  368. }
  369. </style>