Login.vue 45 KB

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