Login.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. <template>
  2. <div>
  3. <!--头部-->
  4. <nav class="x-navbar">
  5. <div class="container">
  6. <div class="navbar-header">
  7. <input type="hidden" name="iconUrl" value="">
  8. <a class="navbar-brand" :href="!loginStyle || (loginStyle && (JSON.parse(loginStyle.returnHomeUrl).url)) || ''">
  9. <img :src="loginStyle.logoUrl" alt="">
  10. <span>{{loginStyle.title || ''}}</span>
  11. </a>
  12. </div>
  13. <div class="collapse navbar-collapse navbar-right">
  14. <a :href="loginStyle ? JSON.parse(loginStyle.returnHomeUrl).url : ''">{{loginStyle ? JSON.parse(loginStyle.returnHomeUrl).name : ''}}</a>
  15. <a href="http://uas.ubtob.com/serve#/" v-if="!loginStyle || (loginStyle && (JSON.parse(loginStyle.returnHomeUrl).needHelp))">帮助</a>
  16. </div>
  17. <div class="login-tip">
  18. 为确保您账户的安全及正常使用,依《网络安全法》相关要求,6月1日起会员账户需绑定手机、设置密码保护。感谢您的理解和支持!
  19. </div>
  20. </div>
  21. </nav>
  22. <div class="x-container">
  23. <!-- background slider -->
  24. <div class="x-banner-wrap">
  25. <div class="x-banner">
  26. <ul class="list-unstyled">
  27. <li id="bgStyle" v-bind:style="{ background: `url(${loginStyle.bgUrl}) center center/auto 100% no-repeat ${loginStyle.bgColor}` }">
  28. <a :href="loginStyle.bgLink" v-if="loginStyle.bgLink">
  29. <div class="inner">
  30. <div class="x-title x-text-0"></div>
  31. <div class="x-subtitle x-text-0"></div>
  32. <div class="x-btn-group">
  33. </div>
  34. </div>
  35. </a>
  36. <a v-else style="cursor: default">
  37. <div class="inner">
  38. <div class="x-title x-text-0"></div>
  39. <div class="x-subtitle x-text-0"></div>
  40. <div class="x-btn-group">
  41. </div>
  42. </div>
  43. </a>
  44. </li>
  45. </ul>
  46. </div>
  47. </div>
  48. <div class="x-login-wrap">
  49. <div class="login-tab" v-show="loginWay != 2">
  50. <span @click="toggleTab(0)" v-bind:class="{'active': loginWay === 0 }">密码登录</span>
  51. <span @click="toggleTab(3)" v-bind:class="{'active': loginWay === 3 }">短信登录</span>
  52. <span @click="ShowWechatCoe(1)" v-bind:class="{'active': loginWay === 1 }" id="weChatBtn">微信登录</span>
  53. </div>
  54. <!--账号密码登录-->
  55. <div class="x-login" v-show="loginWay === 0">
  56. <div id="form-wrap" class="x-login-form">
  57. <el-form :model="login" :rules="rules2" ref="login" class="demo-ruleForm login-form">
  58. <div style="opacity: 0; height: 0; overflow: hidden">
  59. <input type="text" name="hideUserName" id="hideUserName">
  60. <input type="password" name="hidePassword" id="hidePassword">
  61. </div>
  62. <el-form-item prop="username">
  63. <el-input type="text" v-model="login.username" auto-complete="off" placeholder="手机号/邮箱"></el-input>
  64. <i class="fa fa-user"></i>
  65. </el-form-item>
  66. <el-form-item prop="password">
  67. <el-input type="password"
  68. v-model="login.password"
  69. placeholder="密码"
  70. auto-complete="off"
  71. @keyup.enter.native="isLogin(true)"></el-input>
  72. <i class="fa fa-lock"></i>
  73. </el-form-item>
  74. <el-form-item prop="captcha" class="captcha" v-show="showCheckCode">
  75. <el-input type="text"
  76. v-model="login.captcha"
  77. auto-complete="off"
  78. class="code-input"
  79. @keyup.enter.native="isLogin(true)"></el-input>
  80. <img id="captchaImage" class="code-img" src="/sso/login/checkCode"/>
  81. <a class="code-click" @click="getCode">看不清换一张</a>
  82. </el-form-item>
  83. <el-form-item>
  84. <a class="btn login"
  85. @click="isLogin(true)"
  86. :disabled="isLoginDisabled">登录</a>
  87. </el-form-item>
  88. <el-form-item class="text-position">
  89. <div class="page-part" v-if="loginStyle.needRememberPwd">
  90. <el-checkbox v-model="checked">30天免登录</el-checkbox>
  91. </div>
  92. </el-form-item>
  93. </el-form>
  94. <div class="link-go">
  95. <a @click="changeManage" class="first">更换管理员</a>
  96. <span class="line"></span>
  97. <a class="forget" id='forget' @click="goForgetPassword">忘记密码?</a>
  98. <span class="line"></span>
  99. <a id="register" @click="goRegister" class="second">免费注册</a>
  100. </div>
  101. </div>
  102. </div>
  103. <!--短信快捷登录-->
  104. <div class="x-login" v-show="loginWay === 3">
  105. <div id="form-wrap1" class="x-login-form">
  106. <el-form :model="fastLogin" :rules="rules3" ref="fastLogin" class="demo-ruleForm login-form loginForm">
  107. <el-form-item prop="mobile">
  108. <el-input type="text" v-model="fastLogin.mobile" auto-complete="off" placeholder="请输入手机号"></el-input>
  109. </el-form-item>
  110. <el-form-item prop="code" class="fastMsg">
  111. <el-input type="text" v-model="fastLogin.code"
  112. auto-complete="off" placeholder="验证码"></el-input>
  113. <el-button type="primary" class="fastCode"
  114. v-show="sendLoginCode"
  115. @click="getCheckCode">获取验证码</el-button>
  116. <el-button type="primary" v-show="!sendLoginCode" class="fastCode code-send">已发送({{login_time}}s)</el-button>
  117. </el-form-item>
  118. <el-form-item>
  119. <a class="btn login"
  120. @click="fastToLogin(true)">登录</a>
  121. </el-form-item>
  122. </el-form>
  123. <div class="link-go">
  124. <a @click="changeManage" class="first">更换管理员</a>
  125. <span class="line"></span>
  126. <a id="register" @click="goRegister" class="second">免费注册</a>
  127. </div>
  128. </div>
  129. </div>
  130. <!--微信扫码登录-->
  131. <div class="x-login scan-login" v-show="loginWay === 1">
  132. <div class="x-login-form">
  133. <div class="scan-body">
  134. <div class="img">
  135. <div id="login_container"></div>
  136. </div>
  137. <div class="content">
  138. <img src="/images/logo/saosao.png" alt="">
  139. <div>
  140. <span>打开 <b>微信</b></span>
  141. <div>扫一扫登录</div>
  142. </div>
  143. </div>
  144. </div>
  145. <div class="link-go" style="padding: 0 18px 12px 0; margin-top: 0;">
  146. <a @click="changeManage" class="first">更换管理员</a>
  147. <span class="line"></span>
  148. <a id="register" @click="goRegister" class="second">免费注册</a>
  149. </div>
  150. </div>
  151. </div>
  152. <!--绑定账号-->
  153. <div class="x-login bind-login" v-show="loginWay === 2">
  154. <div class="x-login-form">
  155. <div class="bind-header">
  156. <span>绑定已有账号</span>
  157. <span @click="loginWay = 0">返回</span>
  158. </div>
  159. <div class="bind-body">
  160. <div class="img"><img :src="wxImg" alt=""/><div>{{wxName}}</div></div>
  161. <div>
  162. <el-form :model="bindAccount" :rules="rules4" ref="bindAccount" class="demo-ruleForm login-form">
  163. <el-form-item prop="username" style="margin: 0 auto 10px !important;">
  164. <el-input type="text"
  165. v-model="bindAccount.username"
  166. auto-complete="off"
  167. placeholder="请输入用户名、手机号或邮箱"></el-input>
  168. </el-form-item>
  169. <el-form-item prop="password" style="margin: 0 auto 10px !important;">
  170. <el-input type="password"
  171. v-model="bindAccount.password"
  172. auto-complete="new-password"
  173. placeholder="密码"
  174. @keyup.enter.native="wxBind"></el-input>
  175. </el-form-item>
  176. <el-form-item style="margin: 0 auto!important;">
  177. <a class="btn login"
  178. @click="wxBind">确定绑定已有账号</a>
  179. </el-form-item>
  180. </el-form>
  181. </div>
  182. <div class="set">还没有优软账号,直接 <a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${wxToken}`">创建新账号</a></div>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. <!--选择企业弹出框-->
  188. <div>
  189. <el-dialog class="dialog"
  190. :visible.sync="dialogVisible"
  191. size="tiny">
  192. <div class="x-floating x-list" v-show="dialogVisible">
  193. <div class="x-list-header">您要登录的公司是:</div>
  194. <div class="x-list-content">
  195. <ul class="list-unstyled" >
  196. <template v-for="space in this.enterprise">
  197. <li v-text="space.name" @click="chooseOneEnterprise(false, space.id)">华商龙科技有限公司</li>
  198. </template>
  199. </ul>
  200. </div>
  201. </div>
  202. </el-dialog>
  203. </div>
  204. <loading v-show="isShowLoading"/>
  205. </div>
  206. <!--尾部-->
  207. <div v-html="loginStyle.footUrl || ''" class="footer"></div>
  208. </div>
  209. </template>
  210. <script>
  211. import Loading from '~components/common/loading/Loading.vue'
  212. var wxLogin = function () {}
  213. export default {
  214. name: 'login',
  215. components: {
  216. Loading
  217. },
  218. data () {
  219. // 用户名密码登录
  220. var validateUsername = (rule, value, callback) => {
  221. if (value === '') {
  222. this.checkUsername = false
  223. this.showCheckCode = false
  224. } else {
  225. if (this.login.username !== '') {
  226. // 获取密码输错次数
  227. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  228. .then(response => {
  229. if (response.data.success) {
  230. this.showCheckCode = false
  231. let getPasswordErrorCount = response.data.content || ''
  232. if (getPasswordErrorCount >= 5) {
  233. this.$message.error('密码错误次数已达上限,今日无法登录')
  234. this.isLoginDisabled = true
  235. this.showCheckCode = false
  236. } else if (getPasswordErrorCount < 3) {
  237. this.isLoginDisabled = false
  238. this.checkUsername = true
  239. this.showCheckCode = false
  240. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  241. if (getPasswordErrorCount === 3) {
  242. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  243. }
  244. if (getPasswordErrorCount === 4) {
  245. this.$message.error('当前已输错密码4次,若达到5次今日将无法登录')
  246. }
  247. this.isLoginDisabled = false
  248. this.checkUsername = true
  249. this.showCheckCode = true
  250. } else {
  251. this.checkUsername = false
  252. this.showCheckCode = false
  253. }
  254. } else {
  255. return Promise.reject(response.data)
  256. }
  257. }).catch(err => {
  258. this.isShowLoading = false
  259. this.$message.error(err.errMsg)
  260. })
  261. }
  262. callback()
  263. }
  264. }
  265. var validatePassword = (rule, value, callback) => {
  266. if (value === '') {
  267. this.checkPassword = false
  268. } else {
  269. if (this.login.password !== '') {
  270. this.checkPassword = true
  271. }
  272. callback()
  273. }
  274. }
  275. // 短信便捷登录
  276. var validateMobile = (rule, value, callback) => {
  277. if (value === '') {
  278. this.checkMobile = false
  279. } else {
  280. if (this.fastLogin.mobile) {
  281. this.checkMobile = true
  282. }
  283. callback()
  284. }
  285. }
  286. var validateCode = (rule, value, callback) => {
  287. if (value === '') {
  288. this.checkCode = false
  289. } else {
  290. if (this.fastLogin.code !== '') {
  291. this.checkCode = true
  292. }
  293. callback()
  294. }
  295. }
  296. // 微信扫码登录
  297. var validateWeiUsername = (rule, value, callback) => {
  298. if (value === '') {
  299. this.checkWeiUsername = false
  300. } else {
  301. if (this.bindAccount.username !== '') {
  302. this.checkWeiUsername = true
  303. }
  304. callback()
  305. }
  306. }
  307. var validateWeiPassword = (rule, value, callback) => {
  308. if (value === '') {
  309. this.checkWeiPassword = false
  310. } else {
  311. if (this.bindAccount.password !== '') {
  312. this.checkWeiPassword = true
  313. }
  314. callback()
  315. }
  316. }
  317. return {
  318. login: {
  319. username: '',
  320. password: '',
  321. captcha: '',
  322. spaceUU: ''
  323. },
  324. fastLogin: {
  325. mobile: '',
  326. code: ''
  327. },
  328. bindAccount: {
  329. username: '',
  330. password: ''
  331. },
  332. loginWay: 0,
  333. checked: true,
  334. isShowLoading: false,
  335. checkUsername: false,
  336. checkPassword: false,
  337. showCheckCode: false,
  338. isLoginDisabled: false,
  339. dialogVisible: false,
  340. queryLink: '',
  341. checkMobile: false,
  342. getCodeBtnIsDisabled: true,
  343. sendLoginCode: true,
  344. login_time: 0,
  345. token: '',
  346. checkCode: false,
  347. checkWeiUsername: false,
  348. checkWeiPassword: false,
  349. wxToken: '',
  350. wxImg: '',
  351. wxName: '',
  352. wxUrl: '',
  353. // 用户名密码登录
  354. rules2: {
  355. username: [
  356. {validator: validateUsername, trigger: 'blur'}
  357. ],
  358. password: [
  359. {validator: validatePassword, trigger: 'blur'}
  360. ]
  361. },
  362. // 短信快捷登录
  363. rules3: {
  364. mobile: [
  365. {validator: validateMobile, trigger: 'blur'}
  366. ],
  367. code: [
  368. {validator: validateCode, trigger: 'blur'}
  369. ]
  370. },
  371. // 微信扫码登录
  372. rules4: {
  373. username: [
  374. {validator: validateWeiUsername, trigger: 'blur'}
  375. ],
  376. password: [
  377. {validator: validateWeiPassword, trigger: 'blur'}
  378. ]
  379. }
  380. }
  381. },
  382. mounted () {
  383. this.$nextTick(() => {
  384. this.getUrl()
  385. // if (this.appId === 'mall' || this.appId === 'home') {
  386. // this.getCookie()
  387. // }
  388. this.validUserName()
  389. if (this.$route.query.code) {
  390. this.wxEnterprise()
  391. }
  392. })
  393. },
  394. computed: {
  395. enterprise () {
  396. let chooseEnterprise = this.$store.state.login.chooseRegisterEnterprise.choose.data
  397. return chooseEnterprise
  398. },
  399. loginStyle () {
  400. return this.$store.state.login.loginStyle.data.content ? this.$store.state.login.loginStyle.data.content : ''
  401. }
  402. },
  403. methods: {
  404. // resetForm (formName) {
  405. // if (this.$refs[formName] === undefined) {
  406. // this.$refs[formName].resetFields()
  407. // }
  408. // },
  409. toggleTab (type) {
  410. this.loginWay = type
  411. this.login.username = ''
  412. this.login.password = ''
  413. this.fastLogin.mobile = ''
  414. this.fastLogin.code = ''
  415. // this.resetForm(whichForm)
  416. },
  417. ShowWechatCoe () {
  418. wxLogin()
  419. this.loginWay = 1
  420. },
  421. // 获取用户错误次数
  422. validUserName () {
  423. if (this.login.username) {
  424. // 获取密码输错次数
  425. this.$http.get(`/sso/login/getPwdErrorCount`, {params: {username: this.login.username}})
  426. .then(response => {
  427. if (response.data.success) {
  428. let getPasswordErrorCount = response.data.content || ''
  429. if (getPasswordErrorCount >= 5) {
  430. this.$message.error('密码错误次数已达上限,今日无法登录')
  431. this.isLoginDisabled = true
  432. this.showCheckCode = false
  433. } else if (getPasswordErrorCount < 3) {
  434. this.isLoginDisabled = false
  435. this.checkUsername = true
  436. this.showCheckCode = false
  437. } else if (getPasswordErrorCount >= 3 && getPasswordErrorCount < 5) {
  438. if (getPasswordErrorCount === 3) {
  439. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  440. }
  441. if (getPasswordErrorCount === 4) {
  442. this.$message.error('当前已输错密码4次,若达到5次今日将无法登录')
  443. }
  444. this.isLoginDisabled = false
  445. this.checkUsername = true
  446. this.showCheckCode = true
  447. } else {
  448. this.checkUsername = false
  449. this.showCheckCode = false
  450. }
  451. } else {
  452. return Promise.reject(response.data)
  453. }
  454. }).catch(err => {
  455. this.$message.error(err.errMsg)
  456. })
  457. }
  458. },
  459. // 更换管理员
  460. changeManage () {
  461. window.location.href = `appeals/changeManagerAppeal${this.$store.state.option.fullPath}`
  462. },
  463. // 获取url参数
  464. getUrl () {
  465. let wUrl = ''
  466. if (this.$route.query) {
  467. for (var key in this.$route.query) {
  468. if (key !== 'code' && key !== 'state' && key !== 'type') {
  469. wUrl += `${key}=${encodeURIComponent(this.$route.query[key])}&`
  470. }
  471. }
  472. }
  473. if (this.$route.query) {
  474. this.wxUrl = `${window.location.origin}?${wUrl.substr(0, wUrl.length - 1)}`
  475. } else {
  476. this.wxUrl = `${window.location.origin}`
  477. }
  478. var url = window.location.search
  479. var request = {}
  480. if (url.indexOf('?' !== -1)) {
  481. var str = url.substr(1)
  482. var strs = str.split('&')
  483. this.queryLink = str
  484. for (var i = 0; i < strs.length; i++) {
  485. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  486. }
  487. }
  488. this.appId = request['appId'] || ''
  489. this.returnUrl = request['returnURL'] || ''
  490. this.baseUrl = request['baseUrl'] || ''
  491. },
  492. goForgetPassword () {
  493. let url = `/reset/forgetPasswordValidationAccount?${this.queryLink}`
  494. document.getElementById('forget').href = url
  495. },
  496. // 去注册
  497. goRegister () {
  498. document.getElementById('register').href = `/register/enterpriseRegistration?${this.queryLink}`
  499. },
  500. // 获取验证码
  501. getCode () {
  502. var imgSrc = document.getElementById('captchaImage')
  503. imgSrc.setAttribute('src', '/sso/login/checkCode?timestamp=' + (new Date()).valueOf())
  504. },
  505. // 登录
  506. isLogin (flag) {
  507. this.isShowLoading = true
  508. if (!this.login.username) {
  509. this.isShowLoading = false
  510. this.$message.error('请填写账号')
  511. } else if (!this.login.password) {
  512. this.isShowLoading = false
  513. this.$message.error('请填写密码')
  514. } else {
  515. let param = new FormData()
  516. param.append('username', this.login.username)
  517. param.append('password', this.login.password)
  518. param.append('captcha', this.login.captcha)
  519. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  520. param.append('appId', this.appId ? this.appId : '')
  521. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  522. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  523. param.append('maxage', this.checked ? 2592000 : '')
  524. let config = {
  525. headers: {'Content-Type': 'multipart/form-data'}
  526. }
  527. this.$http.post('/sso/login', param, config)
  528. .then(response => {
  529. this.isShowLoading = false
  530. if (response.data.success) {
  531. if (response.data.content.spaces) {
  532. // 弹框让用户选择企业
  533. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  534. this.dialogVisible = flag
  535. } else if (response.data.content.loginUrls) {
  536. // 遍历登录url循环让各应用登录(需要跨域)
  537. let param = response.data.content.data
  538. let a = ''
  539. for (let n in param) {
  540. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  541. }
  542. let params = a.substr(0, a.length - 1)
  543. this.isShowLoading = true
  544. if (response.data.content.currentUrl) {
  545. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  546. name: 'successCallback',
  547. timeout: 3000
  548. }, (err, data) => {
  549. if (err) {
  550. this.$message.error('登录超时,请重试')
  551. this.isShowLoading = false
  552. throw err
  553. } else {
  554. this.loginOther(response, params)
  555. }
  556. })
  557. } else {
  558. this.loginOther(response, params, 3000)
  559. }
  560. }
  561. } else {
  562. this.$message.error(response.data)
  563. var count = response.data.errorCount
  564. if (count < 3) {
  565. this.showCheckCode = false
  566. this.isLoginDisabled = false
  567. } else if (count >= 5) {
  568. this.$message.error('密码错误次数已达上限,今日无法登录')
  569. this.isLoginDisabled = true
  570. this.showCheckCode = false
  571. } else if (count >= 3 && count < 5) {
  572. this.getCode()
  573. if (count === 3) {
  574. this.$message.error('当前已输错密码3次,若达到5次今日将无法登录')
  575. }
  576. this.showCheckCode = true
  577. this.isLoginDisabled = false
  578. }
  579. return Promise.reject(response.data)
  580. }
  581. }).catch(err => {
  582. this.isShowLoading = false
  583. let _this = this
  584. setTimeout(function () {
  585. _this.getCode()
  586. }, 100)
  587. this.$message.error(err.errMsg)
  588. })
  589. }
  590. },
  591. // 选择账套
  592. chooseOneEnterprise (flag, spaceUU) {
  593. this.login.spaceUU = spaceUU
  594. this.dialogVisible = false
  595. if (this.$route.query.code) {
  596. this.wxEnterprise(flag)
  597. } else {
  598. if (this.loginWay === 0) {
  599. this.isLogin(flag)
  600. }
  601. if (this.loginWay === 3) {
  602. this.fastToLogin(flag)
  603. }
  604. }
  605. // 记住密码
  606. // if (this.appId === 'mall' || this.appId === 'home') {
  607. // if (this.checked) {
  608. // this.setCookie(this.login.username, this.login.password, 7)
  609. // } else {
  610. // this.clearCookie()
  611. // }
  612. // }
  613. },
  614. // 短信快捷登录
  615. fastToLogin (flag) {
  616. this.isShowLoading = true
  617. if (!this.fastLogin.mobile) {
  618. this.isShowLoading = false
  619. this.$message.error('请填写手机号')
  620. } else {
  621. let param = new FormData()
  622. param.append('mobile', this.fastLogin.mobile)
  623. param.append('code', this.fastLogin.code)
  624. param.append('appId', this.appId)
  625. param.append('token', this.token)
  626. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  627. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  628. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  629. let config = {
  630. headers: {'Content-Type': 'multipart/form-data'}
  631. }
  632. this.$http.post('/sso/login/sms', param, config)
  633. .then(response => {
  634. this.isShowLoading = false
  635. if (response.data.success) {
  636. if (response.data.content.spaces) {
  637. // 弹框让用户选择企业
  638. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  639. this.dialogVisible = flag
  640. } else if (response.data.content.loginUrls) {
  641. // 遍历登录url循环让各应用登录(需要跨域)
  642. let param = response.data.content.data
  643. let a = ''
  644. for (let n in param) {
  645. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  646. }
  647. let params = a.substr(0, a.length - 1)
  648. this.isShowLoading = true
  649. if (response.data.content.currentUrl) {
  650. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  651. name: 'successCallback',
  652. timeout: 3000
  653. }, (err, data) => {
  654. if (err) {
  655. this.$message.error('登录超时,请重试')
  656. this.isShowLoading = false
  657. throw err
  658. } else {
  659. this.loginOther(response, params)
  660. }
  661. })
  662. } else {
  663. this.loginOther(response, params, 3000)
  664. }
  665. }
  666. } else {
  667. this.$message.error(response.data)
  668. return Promise.reject(response.data)
  669. }
  670. }).catch(err => {
  671. this.isShowLoading = false
  672. let _this = this
  673. setTimeout(function () {
  674. _this.getCode()
  675. }, 100)
  676. this.$message.error(err.errMsg)
  677. })
  678. }
  679. },
  680. getJsonp: function (url, timeout = 500) {
  681. return new Promise((resolve, reject) => {
  682. this.$jsonp(url, {
  683. name: 'successCallback',
  684. timeout: timeout
  685. }, function (err, data) {
  686. if (err) {
  687. reject(err)
  688. throw err
  689. } else {
  690. resolve(data)
  691. }
  692. })
  693. })
  694. },
  695. crossAfter (url) {
  696. try {
  697. window.location.href = url
  698. } catch (err) {
  699. console.log(err)
  700. }
  701. },
  702. loginOther (response, a, timeout) {
  703. const crossAfter = this.crossAfter
  704. let promises = []
  705. for (let i in response.data.content.loginUrls) {
  706. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  707. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  708. }
  709. }
  710. Promise.all(promises).then(() => {
  711. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  712. }).catch(() => {
  713. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  714. })
  715. },
  716. // 设置cookie
  717. // setCookie (cName, cPwd, exdays) {
  718. // let exdate = new Date()
  719. // exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays)
  720. // window.document.cookie = 'userName' + '=' + cName + ';path=/;expires=' + exdate.toGMTString()
  721. // window.document.cookie = 'userPwd' + '=' + cPwd + ';path=/;expires=' + exdate.toGMTString()
  722. // },
  723. // 读取cookies
  724. // getCookie () {
  725. // if (document.cookie.length > 0) {
  726. // let arr = document.cookie.split(';')
  727. // for (var i = 0; i < arr.length; i++) {
  728. // let arr2 = arr[i].split('=')
  729. // if (arr2[0].trim() === 'userName') {
  730. // this.login.username = arr2[1]
  731. // }
  732. // if (arr2[0].trim() === 'userPwd') {
  733. // this.login.password = arr2[1]
  734. // }
  735. // if (this.login.username && this.login.username) {
  736. // this.checked = true
  737. // }
  738. // }
  739. // }
  740. // },
  741. // 清除cookie
  742. // clearCookie () {
  743. // this.setCookie('', '', -1)
  744. // },
  745. // 获取校验码
  746. getCheckCode () {
  747. this.isShowLoading = true
  748. if (!this.fastLogin.mobile) {
  749. this.isShowLoading = false
  750. this.$message.error('请先填写手机号')
  751. } else {
  752. if (this.checkMobile) {
  753. this.$http.get(`/sso/login/sendSmsCode`, {params: {mobile: this.fastLogin.mobile}})
  754. .then(response => {
  755. this.isShowLoading = false
  756. if (response.data) {
  757. if (response.data.success) {
  758. this.token = response.data.content.token
  759. this.$message({
  760. message: '验证码已经发送到您的手机,请注意查收',
  761. type: 'success'
  762. })
  763. this.sendLoginCode = false
  764. this.login_time = 60
  765. var loginTime = setInterval(() => {
  766. this.login_time--
  767. if (this.login_time <= 0) {
  768. this.sendLoginCode = true
  769. clearInterval(loginTime)
  770. }
  771. }, 1000)
  772. } else {
  773. this.$message.error(response.data.errMsg)
  774. }
  775. } else {
  776. return Promise.reject(response.data)
  777. }
  778. }).catch(err => {
  779. this.isShowLoading = false
  780. this.$message.error(err.errMsg)
  781. })
  782. } else {
  783. this.isShowLoading = false
  784. }
  785. }
  786. },
  787. // 微信判断绑定和账套选择
  788. wxEnterprise () {
  789. this.isShowLoading = true
  790. if (this.$route.query.code) {
  791. let param = new FormData()
  792. param.append('code', this.$route.query.code ? this.$route.query.code : '')
  793. param.append('type', 'wx')
  794. param.append('state', this.$route.query.state ? this.$route.query.state : '')
  795. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  796. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  797. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  798. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  799. let config = {
  800. headers: {'Content-Type': 'multipart/form-data'}
  801. }
  802. this.$http.post('/sso/login/foreignLogin', param, config)
  803. .then(response => {
  804. this.isShowLoading = false
  805. if (response.data.success) {
  806. if (!response.data.content.hasRegister && response.data.content.token) {
  807. this.loginWay = 2
  808. this.wxToken = response.data.content.token
  809. this.$http.get(`/foreign/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
  810. .then(response => {
  811. if (response.data.success) {
  812. this.wxImg = response.data.content.foreignUserImg
  813. this.wxName = response.data.content.foreignUserName
  814. } else {
  815. return Promise.reject(response.data)
  816. }
  817. }).catch(err => {
  818. this.$message.error(err.errMsg)
  819. })
  820. } else if (response.data.content.spaces) {
  821. // 弹框让用户选择企业
  822. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  823. this.dialogVisible = true
  824. } else if (response.data.content.loginUrls) {
  825. // 遍历登录url循环让各应用登录(需要跨域)
  826. let param = response.data.content.data
  827. let a = ''
  828. for (let n in param) {
  829. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  830. }
  831. let params = a.substr(0, a.length - 1)
  832. this.isShowLoading = true
  833. if (response.data.content.currentUrl) {
  834. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  835. name: 'successCallback',
  836. timeout: 3000
  837. }, (err, data) => {
  838. if (err) {
  839. this.$message.error('登录超时,请重试')
  840. this.isShowLoading = false
  841. throw err
  842. } else {
  843. this.loginOther(response, params)
  844. }
  845. })
  846. } else {
  847. this.loginOther(response, params, 3000)
  848. }
  849. }
  850. } else {
  851. this.$message.error(response.data)
  852. return Promise.reject(response.data)
  853. }
  854. }).catch(err => {
  855. this.isShowLoading = false
  856. let _this = this
  857. setTimeout(function () {
  858. _this.getCode()
  859. }, 100)
  860. this.$message.error(err.errMsg)
  861. })
  862. }
  863. },
  864. // 微信扫码登录
  865. getScan () {
  866. // this.loginWay = 1
  867. this.isShowLoading = true
  868. this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
  869. .then(response => {
  870. this.isShowLoading = false
  871. if (response.data.success) {
  872. window.location.href = response.data.content
  873. } else {
  874. return Promise.reject(response.data)
  875. }
  876. }).catch(err => {
  877. this.isShowLoading = false
  878. this.$message.error(err.errMsg)
  879. })
  880. },
  881. // 绑定企业
  882. wxBind () {
  883. this.isShowLoading = true
  884. if (!this.bindAccount.username) {
  885. this.isShowLoading = false
  886. this.$message.error('请填写账号')
  887. } else if (!this.bindAccount.password) {
  888. this.isShowLoading = false
  889. this.$message.error('请填写密码')
  890. } else {
  891. let param = new FormData()
  892. param.append('_operate', 'account')
  893. param.append('t', this.wxToken)
  894. param.append('username', this.bindAccount.username)
  895. param.append('password', this.bindAccount.password)
  896. let config = {
  897. headers: {'Content-Type': 'multipart/form-data'}
  898. }
  899. this.$http.post('/foreign/addAccount', param, config)
  900. .then(response => {
  901. this.isShowLoading = false
  902. if (response.data.success) {
  903. this.wxEnterprise()
  904. } else {
  905. return Promise.reject(response.data)
  906. }
  907. }).catch(err => {
  908. this.isShowLoading = false
  909. this.$message.error(err.errMsg)
  910. })
  911. }
  912. }
  913. }
  914. }
  915. </script>
  916. <style lang="scss" type="text/scss">
  917. @import '~assets/scss/mixins';
  918. @import '~assets/scss/variables';
  919. .x-navbar{
  920. height: 80px;
  921. line-height: 80px;
  922. margin: 0;
  923. .container{
  924. position: relative;
  925. width: 990px!important;
  926. height: 80px;
  927. .login-tip{
  928. padding: 0 20px;
  929. position: absolute;
  930. top: 57px;
  931. left: 145px;
  932. font-size: 12px;
  933. height: 22px;
  934. line-height: 22px;
  935. color: #999;
  936. background-color: #fef2f2;
  937. border: solid 1px #ffb4a8;
  938. border-radius: 5px;
  939. }
  940. .navbar-header{
  941. height: 80px;
  942. line-height: 80px;
  943. }
  944. a.navbar-brand{
  945. overflow: hidden;
  946. padding: 0px;
  947. height: inherit;
  948. line-height: inherit;
  949. font-family: "\5FAE\8F6F\96C5\9ED1";
  950. font-size: 24px;
  951. font-weight: 400;
  952. color: #888;
  953. img{
  954. margin: 28px 8px 0 0;
  955. max-width: 80px;
  956. max-height: 27px;
  957. vertical-align: middle;
  958. float: left;
  959. }
  960. span{
  961. float: left;
  962. }
  963. }
  964. .collapse{
  965. a{
  966. padding-left: 12px;
  967. margin-right: 10px;
  968. color: #666;
  969. outline: 0;
  970. border-left: 1px solid #ddd;
  971. &:first-child{
  972. border-width: 0;
  973. }
  974. }
  975. }
  976. }
  977. }
  978. .x-container{
  979. position: relative;
  980. height: 475px;
  981. div.link-go {
  982. position: relative;
  983. text-align: right;
  984. margin-top: 55px;
  985. a{
  986. margin-left: 20px;
  987. font-size: 14px;
  988. color: #999;
  989. background: 0 0;
  990. text-decoration: none;
  991. outline: 0;
  992. cursor: pointer;
  993. transition: color .2s ease;
  994. }
  995. a.change{
  996. margin:2px 0 0 50px;
  997. font-size: 12px;
  998. }
  999. span.line {
  1000. position: absolute;
  1001. top: 1px;
  1002. display: inline-block;
  1003. margin: 0 10px;
  1004. width: 2px;
  1005. height: 15px;
  1006. background-color: #dddddd;
  1007. }
  1008. }
  1009. /*微信登录*/
  1010. .scavenging {
  1011. margin-top:22px;
  1012. div{
  1013. font-size: 12px;
  1014. color: #666;
  1015. cursor: pointer;
  1016. img{
  1017. margin-right: 10px;
  1018. }
  1019. }
  1020. }
  1021. /*登录弹出框*/
  1022. .x-floating {
  1023. position: fixed;
  1024. top: 80px;
  1025. left: 50%;
  1026. z-index: 100000;
  1027. opacity: 1;
  1028. -webkit-transition: all .5s;
  1029. -moz-transition: all .5s;
  1030. transition: all .5s;
  1031. }
  1032. .x-list {
  1033. width: 60%;
  1034. height:420px;
  1035. margin-left: -30%;
  1036. background: #fff;
  1037. border-top: 1px solid #e7e7e7;
  1038. cursor: pointer;
  1039. .x-list-header {
  1040. padding: 10px 20px;
  1041. background: #e0e0e0;
  1042. height: 42px;
  1043. line-height: 21px;
  1044. font-size: 14px;
  1045. font-weight: 700;
  1046. color: #505050;
  1047. }
  1048. .x-list-content{
  1049. overflow-y: auto;
  1050. height:375px;
  1051. ul{
  1052. margin-bottom: 0;
  1053. li{
  1054. display:inline-block;
  1055. padding: 10px 20px;
  1056. width: 33%;
  1057. overflow: hidden;
  1058. white-space: nowrap;
  1059. text-overflow: ellipsis;
  1060. height: 42px;
  1061. line-height: 21px;
  1062. font-size: 12px;
  1063. color: #505050;
  1064. border-bottom: 1px solid #e7e7e7;
  1065. &:hover{
  1066. background: #e7e7e7;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. .x-list .x-list-header, .x-list li {
  1072. padding: 10px 20px;
  1073. border-bottom: 1px solid #e7e7e7;
  1074. }
  1075. }
  1076. .x-floating.in {
  1077. top: 80px;
  1078. opacity: 1;
  1079. }
  1080. .x-banner-wrap {
  1081. position: absolute;
  1082. left: 0;
  1083. top: 0;
  1084. width: 100%;
  1085. height: 475px;
  1086. .x-banner {
  1087. position: relative;
  1088. overflow: auto;
  1089. height: 475px;
  1090. text-align: center;
  1091. li{
  1092. width: 100%;
  1093. height: 475px;
  1094. .inner{
  1095. height: 100%;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. .x-login-wrap{
  1101. position: absolute;
  1102. top: 30px;
  1103. right: 50%;
  1104. margin-right: -495px;
  1105. height: 475px;
  1106. z-index: 5;
  1107. .login-tab {
  1108. padding: 0 30px;
  1109. position: relative;
  1110. top: 40px;
  1111. margin: 0 auto;
  1112. width: 346px;
  1113. height: 55px;
  1114. line-height: 55px;
  1115. font-size: 16px;
  1116. color: #999;
  1117. text-align: center;
  1118. background: #fff;
  1119. border-bottom: 1px solid #dcdcdc;
  1120. span{
  1121. margin-right: 42px;
  1122. width: 64px;
  1123. cursor: pointer;
  1124. &:hover, &.active{
  1125. padding-bottom: 15px;
  1126. color: #333;
  1127. border-bottom: 2px solid #282828;
  1128. }
  1129. }
  1130. span:last-child {
  1131. margin-right: 0;
  1132. }
  1133. }
  1134. .x-login {
  1135. position: relative;
  1136. top: 40px;
  1137. width: 346px;
  1138. background: #fff;
  1139. overflow: visible;
  1140. z-index: 4;
  1141. .x-login-form, .x-login-qrcode {
  1142. padding: 20px 20px 10px;
  1143. .btn{
  1144. background: #5078cb;
  1145. color: #fff;
  1146. font-weight: 700;
  1147. letter-spacing: 4px;
  1148. border-radius: 0;
  1149. }
  1150. .x-has-feedback-right {
  1151. float: right;
  1152. display: inline-block;
  1153. a{
  1154. color: #5078cb;
  1155. }
  1156. }
  1157. .x-has-feedback-left {
  1158. position: relative;
  1159. .x-input {
  1160. padding-left: 30px;
  1161. line-height: 18px;
  1162. color: #555;
  1163. border-color: #ccc;
  1164. border-radius: 0;
  1165. box-shadow: none;
  1166. }
  1167. i.fa{
  1168. position: absolute;
  1169. top: 2px;
  1170. left: 0;
  1171. z-index: 2;
  1172. display: block;
  1173. width: 30px;
  1174. height: 34px;
  1175. line-height: 34px;
  1176. text-align: center;
  1177. pointer-events: none;
  1178. color: #999;
  1179. font-size: 18px;
  1180. }
  1181. }
  1182. i.fa-keyboard-o{
  1183. position: absolute;
  1184. right: 10px;
  1185. top: 10px;
  1186. }
  1187. i.fa-arrow-circle-o-right{
  1188. margin-right: 5px;
  1189. font-size: 12px;
  1190. color: #5078cb;
  1191. }
  1192. .warn-text-area{
  1193. margin-top: 5px;
  1194. font-size: 13px;
  1195. color: #000;
  1196. }
  1197. .text-position {
  1198. overflow: hidden;
  1199. .page-part {
  1200. float: left;
  1201. margin-bottom: 0;
  1202. .el-checkbox {
  1203. margin: 0;
  1204. span.el-checkbox__inner{
  1205. width: 14px;
  1206. height: 14px;
  1207. }
  1208. }
  1209. }
  1210. .forget {
  1211. float: right;
  1212. color: #2d8cf0;
  1213. }
  1214. }
  1215. }
  1216. }
  1217. .scan-login {
  1218. .x-login-form{
  1219. padding: 0;
  1220. .scan-header {
  1221. position: relative;
  1222. height: 50px;
  1223. line-height: 50px;
  1224. font-size: 18px;
  1225. font-weight: bold;
  1226. color: #666;
  1227. border: solid 1px #e5e5e5;
  1228. span{
  1229. position: absolute;
  1230. top: -3px;
  1231. padding-left: 10px;
  1232. display: inline-block;
  1233. width: 90px;
  1234. border-bottom: 2px solid #0076ff;
  1235. }
  1236. img{
  1237. position: absolute;
  1238. top: -3px;
  1239. right: -1px;
  1240. height: 50px;
  1241. cursor: pointer;
  1242. }
  1243. }
  1244. .scan-body {
  1245. margin: 0 auto;
  1246. padding: 22px 0 25px;
  1247. text-align: center ;
  1248. div.img{
  1249. position: relative;
  1250. margin: 0 auto;
  1251. width: 180px;
  1252. height: 182px;
  1253. line-height: 182px;
  1254. text-align: center;
  1255. /*border: 1px solid #dcdcdc;*/
  1256. img{
  1257. width: 162px;
  1258. height: 165px;
  1259. }
  1260. }
  1261. #login_container{ position: absolute;left: -60px;top: -12px; z-index: 10;}
  1262. div.content {
  1263. width: 138px;
  1264. margin: 38px auto 0;
  1265. text-align: center;
  1266. overflow: hidden;
  1267. img{
  1268. float: left;
  1269. margin-right: 25px;
  1270. width: 32px;
  1271. height: 27px;
  1272. }
  1273. div{
  1274. float: left;
  1275. width: 80px;
  1276. text-align: left;
  1277. span{
  1278. font-size: 14px;
  1279. color: #999;
  1280. b{
  1281. color: #0076ff;
  1282. }
  1283. }
  1284. div{
  1285. font-size: 14px;
  1286. color: #999;
  1287. }
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. .bind-login {
  1294. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1295. border-radius: 6px;
  1296. .x-login-form{
  1297. padding: 0;
  1298. .bind-header {
  1299. overflow: hidden;
  1300. padding: 0 20px;
  1301. height: 50px;
  1302. line-height: 50px;
  1303. font-size: 18px;
  1304. font-weight: bold;
  1305. color: #666;
  1306. border: solid 1px #e5e5e5;
  1307. span {
  1308. &:first-child {
  1309. float: left;
  1310. border-bottom: 2px solid #5078cb;
  1311. }
  1312. &:last-child{
  1313. float: right;
  1314. font-size: 14px;
  1315. color: #5078cb;
  1316. font-weight: normal;
  1317. cursor: pointer;
  1318. }
  1319. }
  1320. }
  1321. .bind-body {
  1322. margin: 22px auto 0;
  1323. padding-bottom: 20px;
  1324. text-align: center ;
  1325. .img{
  1326. margin: 0 auto;
  1327. text-align: center;
  1328. img{
  1329. margin-bottom: 10px;
  1330. width: 60px;
  1331. height: 60px;
  1332. border-radius: 50%;
  1333. }
  1334. div{
  1335. font-size: 14px;
  1336. color: #999;
  1337. }
  1338. }
  1339. .set{
  1340. margin-top: 30px;
  1341. font-size: 12px;
  1342. color: #999;
  1343. a{
  1344. display: inline-block;
  1345. width: 90px;
  1346. line-height: 23px;
  1347. height: 24px;
  1348. text-align: center;
  1349. font-size: 14px;
  1350. color: #5078cb;
  1351. border-radius: 13px;
  1352. border: solid 1px #5078cb;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. .footer{
  1361. padding: 50px 0;
  1362. }
  1363. </style>