Login.vue 44 KB

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