login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 { loadRuntimeConfig } from '@/utils/runtimeConfig'
  96. export default {
  97. name: "Login",
  98. // components: { WechatLoginDialog },
  99. data() {
  100. return {
  101. codeUrl: "",
  102. captchaOnOff: true,
  103. vueAppTitle: process.env.VUE_APP_TITLE,
  104. companyName: process.env.VUE_APP_COMPANY_NAME,
  105. icpRecord: process.env.VUE_APP_ICP_RECORD,
  106. icpUrl: process.env.VUE_APP_ICP_URL,
  107. cookiePassword: "",
  108. wechatDialogVisible: false,
  109. loginForm: {
  110. username: "",
  111. password: "",
  112. rememberMe: false,
  113. code: "",
  114. uuid: "",
  115. tenantCode: "",
  116. },
  117. loginRules: {
  118. tenantCode: [
  119. { required: true, trigger: "blur", message: "租户编号不能为空" }
  120. ],
  121. username: [
  122. { required: true, trigger: "blur", message: "用户名不能为空" }
  123. ],
  124. password: [
  125. { required: true, trigger: "blur", message: "密码不能为空" },
  126. { min: 5, max: 20, message: "密码长度为5-20位", trigger: ["blur", "change"] }
  127. ],
  128. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  129. },
  130. loading: false,
  131. redirect: undefined,
  132. passwordtype:'password',
  133. ispassword:true
  134. };
  135. },
  136. watch: {
  137. $route: {
  138. handler: function(route) {
  139. this.redirect = route.query && route.query.redirect;
  140. },
  141. immediate: true
  142. }
  143. },
  144. mounted () {
  145. },
  146. created() {
  147. this.getCode();
  148. this.getCookie();
  149. },
  150. methods: {
  151. reloadRuntimeConfig() {
  152. return loadRuntimeConfig()
  153. },
  154. checkFirstLogin() {
  155. getFirstLogin().then(res => {
  156. this.loading = false;
  157. if (res.code === 200 && res.data) {
  158. localStorage.setItem('isFirstLogin', 'true');
  159. this.$router.push('/set-password');
  160. } else {
  161. localStorage.setItem('isFirstLogin', 'false');
  162. this.$router.push({ path: this.redirect || "/" });
  163. }
  164. }).catch(() => {
  165. this.loading = false;
  166. this.$router.push({ path: this.redirect || "/" });
  167. });
  168. },
  169. getCode() {
  170. getCodeImg().then(res => {
  171. this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  172. if (this.captchaOnOff) {
  173. this.codeUrl = "data:image/gif;base64," + res.img;
  174. this.loginForm.uuid = res.uuid;
  175. }
  176. });
  177. },
  178. getCookie() {
  179. const username = Cookies.get("username");
  180. const rememberMe = Cookies.get('rememberMe')
  181. const tenantCode = Cookies.get('tenantCode')
  182. this.loginForm = {
  183. username: username === undefined ? this.loginForm.username : username,
  184. password: '',
  185. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  186. tenantCode: this.loginForm.tenantCode || tenantCode || ''
  187. };
  188. },
  189. // 微信扫码成功回调
  190. handleWechatLoginSuccess(token) {
  191. this.loading = false
  192. this.$store.commit("SET_TOKEN", token);
  193. setToken(token);
  194. // 登录成功后检查是否是首次登录
  195. this.checkFirstLogin();
  196. },
  197. handleLogin() {
  198. this.$refs.loginForm.validate(valid => {
  199. if (valid) {
  200. this.loading = true;
  201. if (this.loginForm.rememberMe) {
  202. Cookies.set("username", this.loginForm.username, { expires: 30 });
  203. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  204. } else {
  205. Cookies.remove("username");
  206. Cookies.remove('rememberMe');
  207. }
  208. // 始终保存 tenantCode 用于后续 API 数据源切换
  209. if (this.loginForm.tenantCode) {
  210. Cookies.set('tenantCode', this.loginForm.tenantCode);
  211. }
  212. this.$store
  213. .dispatch("Login", {...this.loginForm, captchaOnOff: this.captchaOnOff})
  214. .then(res => {
  215. if (res.needSms) {
  216. this.loading = false;
  217. this.$message.warning('需要短信验证,但验证组件未启用,请联系管理员');
  218. } else {
  219. // 登录成功后检查是否是首次登录
  220. this.checkFirstLogin();
  221. }
  222. this.reloadRuntimeConfig()
  223. })
  224. .catch(res => {
  225. this.loading = false;
  226. this.getCode();
  227. });
  228. }
  229. });
  230. },
  231. changetype(){
  232. this.ispassword=!this.ispassword
  233. if(this.ispassword){
  234. this.passwordtype="password"
  235. }else{
  236. this.passwordtype="text"
  237. }
  238. }
  239. }
  240. };
  241. </script>
  242. <style rel="stylesheet/scss" lang="scss">
  243. .login {
  244. .logopositon{
  245. position: fixed;
  246. left: 30px;
  247. top: 30px;
  248. }
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. height: 100%;
  253. width: 100%;
  254. background-image: (url(../assets/images/login_bg.png) );
  255. background-size: 100% 100%;
  256. background-size: cover;
  257. .login-con{
  258. width: 880px;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. border-radius: 10px;
  263. .img-box{
  264. width: 440px;
  265. height: 500px;
  266. background-image: url(../assets/images/login_left.png);
  267. background-size: 100% 100%;
  268. color: #FFFFFF;
  269. .imgline1{
  270. font-size: 34px;
  271. font-weight:400;
  272. margin-left: 38px;
  273. margin-top: 38px;
  274. letter-spacing: 2px;
  275. }
  276. .imgline2{
  277. margin-left: 38px;
  278. font-size: 16px;
  279. margin-top: 6px;
  280. letter-spacing: 1px;
  281. }
  282. }
  283. }
  284. }
  285. .title {
  286. margin: 0px auto 15px auto;
  287. text-align: center;
  288. color: #202124;
  289. font-weight: 500;
  290. font-size: 20px;
  291. }
  292. .title-line{
  293. width: 40px;
  294. border-bottom: 2px solid #006CFF;
  295. margin: 0px auto 30px auto;
  296. }
  297. .login-form {
  298. box-sizing: border-box;
  299. background: #ffffff;
  300. width: 440px;
  301. height: 500px;
  302. padding: 40px 25px 5px 25px;
  303. box-shadow:4px -4px 10px rgba(0, 108, 255, 0.15);
  304. .el-input {
  305. height: 38px;
  306. input {
  307. height: 38px;
  308. }
  309. }
  310. .input-icon {
  311. height: 20px;
  312. width: 20px;
  313. margin-left: 2px;
  314. margin-top: 10px;
  315. }
  316. .input-icon2{
  317. height: 20px;
  318. width: 20px;
  319. margin-right: 4px;
  320. margin-top: 10px;
  321. }
  322. }
  323. .login-tip {
  324. font-size: 13px;
  325. text-align: center;
  326. color: #bfbfbf;
  327. }
  328. .login-code {
  329. width: 33%;
  330. height: 38px;
  331. float: right;
  332. img {
  333. cursor: pointer;
  334. vertical-align: middle;
  335. }
  336. }
  337. .el-login-footer {
  338. height: 40px;
  339. line-height: 40px;
  340. position: fixed;
  341. bottom: 0;
  342. width: 100%;
  343. text-align: center;
  344. color: #fff;
  345. font-family: Arial;
  346. font-size: 12px;
  347. letter-spacing: 1px;
  348. }
  349. .login-code-img {
  350. height: 38px;
  351. }
  352. </style>