Login.vue 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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: 35px;
  985. padding-bottom: 10px;
  986. a{
  987. margin-left: 20px;
  988. font-size: 14px;
  989. color: #999;
  990. background: 0 0;
  991. text-decoration: none;
  992. outline: 0;
  993. cursor: pointer;
  994. transition: color .2s ease;
  995. }
  996. a.change{
  997. margin:2px 0 0 50px;
  998. font-size: 12px;
  999. }
  1000. span.line {
  1001. position: absolute;
  1002. top: 1px;
  1003. display: inline-block;
  1004. margin: 0 10px;
  1005. width: 2px;
  1006. height: 15px;
  1007. background-color: #dddddd;
  1008. }
  1009. }
  1010. /*微信登录*/
  1011. .scavenging {
  1012. margin-top:22px;
  1013. div{
  1014. font-size: 12px;
  1015. color: #666;
  1016. cursor: pointer;
  1017. img{
  1018. margin-right: 10px;
  1019. }
  1020. }
  1021. }
  1022. /*登录弹出框*/
  1023. .x-floating {
  1024. position: fixed;
  1025. top: 80px;
  1026. left: 50%;
  1027. z-index: 100000;
  1028. opacity: 1;
  1029. -webkit-transition: all .5s;
  1030. -moz-transition: all .5s;
  1031. transition: all .5s;
  1032. }
  1033. .x-list {
  1034. width: 60%;
  1035. height:420px;
  1036. margin-left: -30%;
  1037. background: #fff;
  1038. border-top: 1px solid #e7e7e7;
  1039. cursor: pointer;
  1040. .x-list-header {
  1041. padding: 10px 20px;
  1042. background: #e0e0e0;
  1043. height: 42px;
  1044. line-height: 21px;
  1045. font-size: 14px;
  1046. font-weight: 700;
  1047. color: #505050;
  1048. }
  1049. .x-list-content{
  1050. overflow-y: auto;
  1051. height:375px;
  1052. ul{
  1053. margin-bottom: 0;
  1054. li{
  1055. display:inline-block;
  1056. padding: 10px 20px;
  1057. width: 33%;
  1058. overflow: hidden;
  1059. white-space: nowrap;
  1060. text-overflow: ellipsis;
  1061. height: 42px;
  1062. line-height: 21px;
  1063. font-size: 12px;
  1064. color: #505050;
  1065. border-bottom: 1px solid #e7e7e7;
  1066. &:hover{
  1067. background: #e7e7e7;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. .x-list .x-list-header, .x-list li {
  1073. padding: 10px 20px;
  1074. border-bottom: 1px solid #e7e7e7;
  1075. }
  1076. }
  1077. .x-floating.in {
  1078. top: 80px;
  1079. opacity: 1;
  1080. }
  1081. .x-banner-wrap {
  1082. position: absolute;
  1083. left: 0;
  1084. top: 0;
  1085. width: 100%;
  1086. height: 475px;
  1087. .x-banner {
  1088. position: relative;
  1089. overflow: auto;
  1090. height: 475px;
  1091. text-align: center;
  1092. li{
  1093. width: 100%;
  1094. height: 475px;
  1095. .inner{
  1096. height: 100%;
  1097. }
  1098. }
  1099. }
  1100. }
  1101. .x-login-wrap{
  1102. position: absolute;
  1103. top: 0;
  1104. right: 50%;
  1105. margin-right: -495px;
  1106. height: 475px;
  1107. z-index: 5;
  1108. .login-tab {
  1109. padding: 0 30px;
  1110. position: relative;
  1111. top: 40px;
  1112. margin: 0 auto;
  1113. width: 346px;
  1114. height: 55px;
  1115. line-height: 55px;
  1116. font-size: 16px;
  1117. color: #999;
  1118. text-align: center;
  1119. background: #fff;
  1120. border-bottom: 1px solid #dcdcdc;
  1121. span{
  1122. margin-right: 42px;
  1123. width: 64px;
  1124. cursor: pointer;
  1125. &:hover, &.active{
  1126. padding-bottom: 15px;
  1127. color: #333;
  1128. border-bottom: 2px solid #282828;
  1129. }
  1130. }
  1131. span:last-child {
  1132. margin-right: 0;
  1133. }
  1134. }
  1135. .x-login {
  1136. position: relative;
  1137. top: 40px;
  1138. width: 346px;
  1139. background: #fff;
  1140. overflow: visible;
  1141. z-index: 4;
  1142. .x-login-form, .x-login-qrcode {
  1143. padding: 20px 20px 10px;
  1144. .btn{
  1145. background: #5078cb;
  1146. color: #fff;
  1147. font-weight: 700;
  1148. letter-spacing: 4px;
  1149. border-radius: 0;
  1150. }
  1151. .x-has-feedback-right {
  1152. float: right;
  1153. display: inline-block;
  1154. a{
  1155. color: #5078cb;
  1156. }
  1157. }
  1158. .x-has-feedback-left {
  1159. position: relative;
  1160. .x-input {
  1161. padding-left: 30px;
  1162. line-height: 18px;
  1163. color: #555;
  1164. border-color: #ccc;
  1165. border-radius: 0;
  1166. box-shadow: none;
  1167. }
  1168. i.fa{
  1169. position: absolute;
  1170. top: 2px;
  1171. left: 0;
  1172. z-index: 2;
  1173. display: block;
  1174. width: 30px;
  1175. height: 34px;
  1176. line-height: 34px;
  1177. text-align: center;
  1178. pointer-events: none;
  1179. color: #999;
  1180. font-size: 18px;
  1181. }
  1182. }
  1183. i.fa-keyboard-o{
  1184. position: absolute;
  1185. right: 10px;
  1186. top: 10px;
  1187. }
  1188. i.fa-arrow-circle-o-right{
  1189. margin-right: 5px;
  1190. font-size: 12px;
  1191. color: #5078cb;
  1192. }
  1193. .warn-text-area{
  1194. margin-top: 5px;
  1195. font-size: 13px;
  1196. color: #000;
  1197. }
  1198. .text-position {
  1199. overflow: hidden;
  1200. .page-part {
  1201. float: left;
  1202. margin-bottom: 0;
  1203. .el-checkbox {
  1204. margin: 0;
  1205. span.el-checkbox__inner{
  1206. width: 14px;
  1207. height: 14px;
  1208. }
  1209. }
  1210. }
  1211. .forget {
  1212. float: right;
  1213. color: #2d8cf0;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. .scan-login {
  1219. .x-login-form{
  1220. padding: 0;
  1221. .scan-header {
  1222. position: relative;
  1223. height: 50px;
  1224. line-height: 50px;
  1225. font-size: 18px;
  1226. font-weight: bold;
  1227. color: #666;
  1228. border: solid 1px #e5e5e5;
  1229. span{
  1230. position: absolute;
  1231. top: -3px;
  1232. padding-left: 10px;
  1233. display: inline-block;
  1234. width: 90px;
  1235. border-bottom: 2px solid #0076ff;
  1236. }
  1237. img{
  1238. position: absolute;
  1239. top: -3px;
  1240. right: -1px;
  1241. height: 50px;
  1242. cursor: pointer;
  1243. }
  1244. }
  1245. .scan-body {
  1246. margin: 0 auto;
  1247. padding: 22px 0 25px;
  1248. text-align: center ;
  1249. div.img{
  1250. position: relative;
  1251. margin: 0 auto;
  1252. width: 180px;
  1253. height: 182px;
  1254. line-height: 182px;
  1255. text-align: center;
  1256. /*border: 1px solid #dcdcdc;*/
  1257. img{
  1258. width: 162px;
  1259. height: 165px;
  1260. }
  1261. }
  1262. #login_container{ position: absolute;left: -60px;top: -12px; z-index: 10;}
  1263. div.content {
  1264. width: 138px;
  1265. margin: 38px auto 0;
  1266. text-align: center;
  1267. overflow: hidden;
  1268. img{
  1269. float: left;
  1270. margin-right: 25px;
  1271. width: 32px;
  1272. height: 27px;
  1273. }
  1274. div{
  1275. float: left;
  1276. width: 80px;
  1277. text-align: left;
  1278. span{
  1279. font-size: 14px;
  1280. color: #999;
  1281. b{
  1282. color: #0076ff;
  1283. }
  1284. }
  1285. div{
  1286. font-size: 14px;
  1287. color: #999;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. .bind-login {
  1295. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1296. border-radius: 6px;
  1297. .x-login-form{
  1298. padding: 0;
  1299. .bind-header {
  1300. overflow: hidden;
  1301. padding: 0 20px;
  1302. height: 50px;
  1303. line-height: 50px;
  1304. font-size: 18px;
  1305. font-weight: bold;
  1306. color: #666;
  1307. border: solid 1px #e5e5e5;
  1308. span {
  1309. &:first-child {
  1310. float: left;
  1311. border-bottom: 2px solid #5078cb;
  1312. }
  1313. &:last-child{
  1314. float: right;
  1315. font-size: 14px;
  1316. color: #5078cb;
  1317. font-weight: normal;
  1318. cursor: pointer;
  1319. }
  1320. }
  1321. }
  1322. .bind-body {
  1323. margin: 22px auto 0;
  1324. padding-bottom: 20px;
  1325. text-align: center ;
  1326. .img{
  1327. margin: 0 auto;
  1328. text-align: center;
  1329. img{
  1330. margin-bottom: 10px;
  1331. width: 60px;
  1332. height: 60px;
  1333. border-radius: 50%;
  1334. }
  1335. div{
  1336. font-size: 14px;
  1337. color: #999;
  1338. }
  1339. }
  1340. .set{
  1341. margin-top: 30px;
  1342. font-size: 12px;
  1343. color: #999;
  1344. a{
  1345. display: inline-block;
  1346. width: 90px;
  1347. line-height: 23px;
  1348. height: 24px;
  1349. text-align: center;
  1350. font-size: 14px;
  1351. color: #5078cb;
  1352. border-radius: 13px;
  1353. border: solid 1px #5078cb;
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. }
  1361. .footer{
  1362. padding: 50px 0;
  1363. }
  1364. </style>