Login.vue 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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">30天免登陆</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' && key !== 'type') {
  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. param.append('maxage', this.checked ? 2592000 : '')
  502. let config = {
  503. headers: {'Content-Type': 'multipart/form-data'}
  504. }
  505. this.$http.post('/sso/login', param, config)
  506. .then(response => {
  507. this.isShowLoading = false
  508. if (response.data.success) {
  509. if (response.data.content.spaces) {
  510. // 弹框让用户选择企业
  511. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  512. this.dialogVisible = flag
  513. } else if (response.data.content.loginUrls) {
  514. // 遍历登录url循环让各应用登录(需要跨域)
  515. let param = response.data.content.data
  516. let a = ''
  517. for (let n in param) {
  518. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  519. }
  520. let params = a.substr(0, a.length - 1)
  521. this.isShowLoading = true
  522. if (response.data.content.currentUrl) {
  523. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  524. name: 'successCallback',
  525. timeout: 3000
  526. }, (err, data) => {
  527. if (err) {
  528. this.$message.error('登录超时,请重试')
  529. this.isShowLoading = false
  530. throw err
  531. } else {
  532. this.loginOther(response, params)
  533. }
  534. })
  535. } else {
  536. this.loginOther(response, params, 3000)
  537. }
  538. }
  539. } else {
  540. this.$message.error(response.data)
  541. var count = response.data.errorCount
  542. if (count < 3) {
  543. this.showCheckCode = false
  544. this.isLoginDisabled = false
  545. } else if (count >= 5) {
  546. this.$message.error('密码错误次数已达上限,今日无法登陆')
  547. this.isLoginDisabled = true
  548. this.showCheckCode = false
  549. } else if (count >= 3 && count < 5) {
  550. this.getCode()
  551. if (count === 3) {
  552. this.$message.error('当前已输错密码3次,若达到5次今日将无法登陆')
  553. }
  554. this.showCheckCode = true
  555. this.isLoginDisabled = false
  556. }
  557. return Promise.reject(response.data)
  558. }
  559. }).catch(err => {
  560. this.isShowLoading = false
  561. let _this = this
  562. setTimeout(function () {
  563. _this.getCode()
  564. }, 100)
  565. this.$message.error(err.errMsg)
  566. })
  567. }
  568. },
  569. // 选择账套
  570. chooseOneEnterprise (flag, spaceUU) {
  571. this.login.spaceUU = spaceUU
  572. this.dialogVisible = false
  573. if (this.$route.query.code) {
  574. this.wxEnterprise(flag)
  575. } else {
  576. if (this.activeTab === 0) {
  577. this.isLogin(flag)
  578. }
  579. if (this.activeTab === 1) {
  580. this.fastToLogin(flag)
  581. }
  582. }
  583. // 记住密码
  584. // if (this.appId === 'mall' || this.appId === 'home') {
  585. // if (this.checked) {
  586. // this.setCookie(this.login.username, this.login.password, 7)
  587. // } else {
  588. // this.clearCookie()
  589. // }
  590. // }
  591. },
  592. // 短信快捷登录
  593. fastToLogin (flag) {
  594. this.isShowLoading = true
  595. if (!this.fastLogin.mobile) {
  596. this.isShowLoading = false
  597. this.$message.error('请填写手机号')
  598. } else {
  599. let param = new FormData()
  600. param.append('mobile', this.fastLogin.mobile)
  601. param.append('code', this.fastLogin.code)
  602. param.append('appId', this.appId)
  603. param.append('token', this.token)
  604. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  605. param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
  606. param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
  607. let config = {
  608. headers: {'Content-Type': 'multipart/form-data'}
  609. }
  610. this.$http.post('/sso/login/sms', param, config)
  611. .then(response => {
  612. this.isShowLoading = false
  613. if (response.data.success) {
  614. if (response.data.content.spaces) {
  615. // 弹框让用户选择企业
  616. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  617. this.dialogVisible = flag
  618. } else if (response.data.content.loginUrls) {
  619. // 遍历登录url循环让各应用登录(需要跨域)
  620. let param = response.data.content.data
  621. let a = ''
  622. for (let n in param) {
  623. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  624. }
  625. let params = a.substr(0, a.length - 1)
  626. this.isShowLoading = true
  627. if (response.data.content.currentUrl) {
  628. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  629. name: 'successCallback',
  630. timeout: 3000
  631. }, (err, data) => {
  632. if (err) {
  633. this.$message.error('登录超时,请重试')
  634. this.isShowLoading = false
  635. throw err
  636. } else {
  637. this.loginOther(response, params)
  638. }
  639. })
  640. } else {
  641. this.loginOther(response, params, 3000)
  642. }
  643. }
  644. } else {
  645. this.$message.error(response.data)
  646. return Promise.reject(response.data)
  647. }
  648. }).catch(err => {
  649. this.isShowLoading = false
  650. let _this = this
  651. setTimeout(function () {
  652. _this.getCode()
  653. }, 100)
  654. this.$message.error(err.errMsg)
  655. })
  656. }
  657. },
  658. getJsonp: function (url, timeout = 500) {
  659. return new Promise((resolve, reject) => {
  660. this.$jsonp(url, {
  661. name: 'successCallback',
  662. timeout: timeout
  663. }, function (err, data) {
  664. if (err) {
  665. reject(err)
  666. throw err
  667. } else {
  668. resolve(data)
  669. }
  670. })
  671. })
  672. },
  673. crossAfter (url) {
  674. try {
  675. window.location.href = url
  676. } catch (err) {
  677. console.log(err)
  678. }
  679. },
  680. loginOther (response, a, timeout) {
  681. const crossAfter = this.crossAfter
  682. let promises = []
  683. for (let i in response.data.content.loginUrls) {
  684. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  685. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  686. }
  687. }
  688. Promise.all(promises).then(() => {
  689. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  690. }).catch(() => {
  691. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  692. })
  693. },
  694. // 设置cookie
  695. // setCookie (cName, cPwd, exdays) {
  696. // let exdate = new Date()
  697. // exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays)
  698. // window.document.cookie = 'userName' + '=' + cName + ';path=/;expires=' + exdate.toGMTString()
  699. // window.document.cookie = 'userPwd' + '=' + cPwd + ';path=/;expires=' + exdate.toGMTString()
  700. // },
  701. // 读取cookies
  702. // getCookie () {
  703. // if (document.cookie.length > 0) {
  704. // let arr = document.cookie.split(';')
  705. // for (var i = 0; i < arr.length; i++) {
  706. // let arr2 = arr[i].split('=')
  707. // if (arr2[0].trim() === 'userName') {
  708. // this.login.username = arr2[1]
  709. // }
  710. // if (arr2[0].trim() === 'userPwd') {
  711. // this.login.password = arr2[1]
  712. // }
  713. // if (this.login.username && this.login.username) {
  714. // this.checked = true
  715. // }
  716. // }
  717. // }
  718. // },
  719. // 清除cookie
  720. // clearCookie () {
  721. // this.setCookie('', '', -1)
  722. // },
  723. // 获取校验码
  724. getCheckCode () {
  725. this.isShowLoading = true
  726. if (!this.fastLogin.mobile) {
  727. this.isShowLoading = false
  728. this.$message.error('请先填写手机号')
  729. } else {
  730. if (this.checkMobile) {
  731. this.$http.get(`/sso/login/sendSmsCode`, {params: {mobile: this.fastLogin.mobile}})
  732. .then(response => {
  733. this.isShowLoading = false
  734. if (response.data) {
  735. if (response.data.success) {
  736. this.token = response.data.content.token
  737. this.$message({
  738. message: '验证码已经发送到您的手机,请注意查收',
  739. type: 'success'
  740. })
  741. this.sendLoginCode = false
  742. this.login_time = 60
  743. var loginTime = setInterval(() => {
  744. this.login_time--
  745. if (this.login_time <= 0) {
  746. this.sendLoginCode = true
  747. clearInterval(loginTime)
  748. }
  749. }, 1000)
  750. } else {
  751. this.$message.error(response.data.errMsg)
  752. }
  753. } else {
  754. return Promise.reject(response.data)
  755. }
  756. }).catch(err => {
  757. this.isShowLoading = false
  758. this.$message.error(err.errMsg)
  759. })
  760. } else {
  761. this.isShowLoading = false
  762. }
  763. }
  764. },
  765. // 微信判断绑定和账套选择
  766. wxEnterprise () {
  767. this.isShowLoading = true
  768. if (this.$route.query.code) {
  769. let param = new FormData()
  770. param.append('code', this.$route.query.code ? this.$route.query.code : '')
  771. param.append('type', 'wx')
  772. param.append('state', this.$route.query.state ? this.$route.query.state : '')
  773. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  774. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  775. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  776. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  777. let config = {
  778. headers: {'Content-Type': 'multipart/form-data'}
  779. }
  780. this.$http.post('/sso/login/foreignLogin', param, config)
  781. .then(response => {
  782. this.isShowLoading = false
  783. if (response.data.success) {
  784. if (!response.data.content.hasRegister && response.data.content.token) {
  785. this.loginWay = 2
  786. this.wxToken = response.data.content.token
  787. this.$http.get(`/foreign/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
  788. .then(response => {
  789. if (response.data.success) {
  790. this.wxImg = response.data.content.foreignUserImg
  791. this.wxName = response.data.content.foreignUserName
  792. } else {
  793. return Promise.reject(response.data)
  794. }
  795. }).catch(err => {
  796. this.$message.error(err.errMsg)
  797. })
  798. } else if (response.data.content.spaces) {
  799. // 弹框让用户选择企业
  800. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  801. this.dialogVisible = true
  802. } else if (response.data.content.loginUrls) {
  803. // 遍历登录url循环让各应用登录(需要跨域)
  804. let param = response.data.content.data
  805. let a = ''
  806. for (let n in param) {
  807. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  808. }
  809. let params = a.substr(0, a.length - 1)
  810. this.isShowLoading = true
  811. if (response.data.content.currentUrl) {
  812. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  813. name: 'successCallback',
  814. timeout: 3000
  815. }, (err, data) => {
  816. if (err) {
  817. this.$message.error('登录超时,请重试')
  818. this.isShowLoading = false
  819. throw err
  820. } else {
  821. this.loginOther(response, params)
  822. }
  823. })
  824. } else {
  825. this.loginOther(response, params, 3000)
  826. }
  827. }
  828. } else {
  829. this.$message.error(response.data)
  830. return Promise.reject(response.data)
  831. }
  832. }).catch(err => {
  833. this.isShowLoading = false
  834. let _this = this
  835. setTimeout(function () {
  836. _this.getCode()
  837. }, 100)
  838. this.$message.error(err.errMsg)
  839. })
  840. }
  841. },
  842. // 微信扫码登录
  843. getScan () {
  844. // this.loginWay = 1
  845. this.isShowLoading = true
  846. this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
  847. .then(response => {
  848. this.isShowLoading = false
  849. if (response.data.success) {
  850. window.location.href = response.data.content
  851. } else {
  852. return Promise.reject(response.data)
  853. }
  854. }).catch(err => {
  855. this.isShowLoading = false
  856. this.$message.error(err.errMsg)
  857. })
  858. },
  859. // 绑定企业
  860. wxBind () {
  861. this.isShowLoading = true
  862. if (!this.bindAccount.username) {
  863. this.isShowLoading = false
  864. this.$message.error('请填写账号')
  865. } else if (!this.bindAccount.password) {
  866. this.isShowLoading = false
  867. this.$message.error('请填写密码')
  868. } else {
  869. let param = new FormData()
  870. param.append('_operate', 'account')
  871. param.append('t', this.wxToken)
  872. param.append('username', this.bindAccount.username)
  873. param.append('password', this.bindAccount.password)
  874. let config = {
  875. headers: {'Content-Type': 'multipart/form-data'}
  876. }
  877. this.$http.post('/foreign/addAccount', param, config)
  878. .then(response => {
  879. this.isShowLoading = false
  880. if (response.data.success) {
  881. this.wxEnterprise()
  882. } else {
  883. return Promise.reject(response.data)
  884. }
  885. }).catch(err => {
  886. this.isShowLoading = false
  887. this.$message.error(err.errMsg)
  888. })
  889. }
  890. }
  891. }
  892. }
  893. </script>
  894. <style lang="scss" type="text/scss" scoped>
  895. @import '~assets/scss/mixins';
  896. @import '~assets/scss/variables';
  897. .x-navbar{
  898. height: 80px;
  899. line-height: 80px;
  900. margin: 0;
  901. .container{
  902. position: relative;
  903. width: 990px!important;
  904. height: 80px;
  905. .navbar-header{
  906. height: 80px;
  907. line-height: 80px;
  908. }
  909. a.navbar-brand{
  910. overflow: hidden;
  911. padding: 0px;
  912. height: inherit;
  913. line-height: inherit;
  914. font-family: "\5FAE\8F6F\96C5\9ED1";
  915. font-size: 24px;
  916. font-weight: 400;
  917. color: #888;
  918. img{
  919. margin: 28px 8px 0 0;
  920. max-width: 80px;
  921. max-height: 27px;
  922. vertical-align: middle;
  923. float: left;
  924. }
  925. span{
  926. float: left;
  927. }
  928. }
  929. .collapse{
  930. a{
  931. padding-left: 12px;
  932. margin-right: 10px;
  933. color: #666;
  934. outline: 0;
  935. border-left: 1px solid #ddd;
  936. &:first-child{
  937. border-width: 0;
  938. }
  939. }
  940. }
  941. }
  942. }
  943. .x-container{
  944. position: relative;
  945. height: 475px;
  946. div.link-go {
  947. text-align: right;
  948. margin-top: 7px;
  949. a{
  950. font-size: 12px;
  951. color: #2d8cf0;
  952. background: 0 0;
  953. text-decoration: none;
  954. outline: 0;
  955. cursor: pointer;
  956. transition: color .2s ease;
  957. }
  958. a.first{
  959. float: left;
  960. margin-top: 2px;
  961. font-size: 12px;
  962. }
  963. a.change{
  964. margin:2px 0 0 50px;
  965. float: left;
  966. font-size: 12px;
  967. }
  968. }
  969. /*微信登录*/
  970. .scavenging {
  971. margin-top:22px;
  972. div{
  973. font-size: 12px;
  974. color: #666;
  975. cursor: pointer;
  976. img{
  977. margin-right: 10px;
  978. }
  979. }
  980. }
  981. /*登录弹出框*/
  982. .x-floating {
  983. position: fixed;
  984. top: 80px;
  985. left: 50%;
  986. z-index: 100000;
  987. opacity: 1;
  988. -webkit-transition: all .5s;
  989. -moz-transition: all .5s;
  990. transition: all .5s;
  991. }
  992. .x-list {
  993. width: 60%;
  994. height:420px;
  995. margin-left: -30%;
  996. background: #fff;
  997. border-top: 1px solid #e7e7e7;
  998. cursor: pointer;
  999. .x-list-header {
  1000. padding: 10px 20px;
  1001. background: #e0e0e0;
  1002. height: 42px;
  1003. line-height: 21px;
  1004. font-size: 14px;
  1005. font-weight: 700;
  1006. color: #505050;
  1007. }
  1008. .x-list-content{
  1009. overflow-y: auto;
  1010. height:375px;
  1011. ul{
  1012. margin-bottom: 0;
  1013. li{
  1014. display:inline-block;
  1015. padding: 10px 20px;
  1016. width: 33%;
  1017. overflow: hidden;
  1018. white-space: nowrap;
  1019. text-overflow: ellipsis;
  1020. height: 42px;
  1021. line-height: 21px;
  1022. font-size: 12px;
  1023. color: #505050;
  1024. border-bottom: 1px solid #e7e7e7;
  1025. &:hover{
  1026. background: #e7e7e7;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. .x-list .x-list-header, .x-list li {
  1032. padding: 10px 20px;
  1033. border-bottom: 1px solid #e7e7e7;
  1034. }
  1035. }
  1036. .x-floating.in {
  1037. top: 80px;
  1038. opacity: 1;
  1039. }
  1040. .x-banner-wrap {
  1041. position: absolute;
  1042. left: 0;
  1043. top: 0;
  1044. width: 100%;
  1045. height: 475px;
  1046. .x-banner {
  1047. position: relative;
  1048. overflow: auto;
  1049. height: 475px;
  1050. text-align: center;
  1051. li{
  1052. width: 100%;
  1053. height: 475px;
  1054. .inner{
  1055. height: 100%;
  1056. }
  1057. }
  1058. }
  1059. }
  1060. .x-login-wrap{
  1061. position: absolute;
  1062. top: 10px;
  1063. right: 50%;
  1064. margin-right: -495px;
  1065. height: 475px;
  1066. z-index: 5;
  1067. .x-login {
  1068. position: relative;
  1069. top: 40px;
  1070. width: 346px;
  1071. background: #fff;
  1072. overflow: visible;
  1073. z-index: 4;
  1074. .x-login-form, .x-login-qrcode {
  1075. padding: 20px;
  1076. .btn{
  1077. background: #5078cb;
  1078. color: #fff;
  1079. font-weight: 700;
  1080. letter-spacing: 4px;
  1081. border-radius: 0;
  1082. }
  1083. .x-has-feedback-right {
  1084. float: right;
  1085. display: inline-block;
  1086. a{
  1087. color: #5078cb;
  1088. }
  1089. }
  1090. .x-has-feedback-left {
  1091. position: relative;
  1092. .x-input {
  1093. padding-left: 30px;
  1094. line-height: 18px;
  1095. color: #555;
  1096. border-color: #ccc;
  1097. border-radius: 0;
  1098. box-shadow: none;
  1099. }
  1100. i.fa{
  1101. position: absolute;
  1102. top: 2px;
  1103. left: 0;
  1104. z-index: 2;
  1105. display: block;
  1106. width: 30px;
  1107. height: 34px;
  1108. line-height: 34px;
  1109. text-align: center;
  1110. pointer-events: none;
  1111. color: #999;
  1112. font-size: 18px;
  1113. }
  1114. }
  1115. i.fa-keyboard-o{
  1116. position: absolute;
  1117. right: 10px;
  1118. top: 10px;
  1119. }
  1120. i.fa-arrow-circle-o-right{
  1121. margin-right: 5px;
  1122. font-size: 12px;
  1123. color: #5078cb;
  1124. }
  1125. .warn-text-area{
  1126. margin-top: 5px;
  1127. font-size: 13px;
  1128. color: #000;
  1129. }
  1130. .text-position {
  1131. overflow: hidden;
  1132. .page-part {
  1133. float: left;
  1134. margin-bottom: 0;
  1135. .el-checkbox {
  1136. margin: 0;
  1137. span.el-checkbox__inner{
  1138. width: 14px;
  1139. height: 14px;
  1140. }
  1141. }
  1142. }
  1143. .forget {
  1144. float: right;
  1145. color: #2d8cf0;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. .scan-login {
  1151. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1152. border-radius: 6px;
  1153. .x-login-form{
  1154. padding: 0;
  1155. .scan-header {
  1156. position: relative;
  1157. height: 50px;
  1158. line-height: 50px;
  1159. font-size: 18px;
  1160. font-weight: bold;
  1161. color: #666;
  1162. border: solid 1px #e5e5e5;
  1163. span{
  1164. position: absolute;
  1165. top: -3px;
  1166. padding-left: 10px;
  1167. display: inline-block;
  1168. width: 90px;
  1169. border-bottom: 2px solid #0076ff;
  1170. }
  1171. img{
  1172. position: absolute;
  1173. top: -3px;
  1174. right: -1px;
  1175. height: 50px;
  1176. cursor: pointer;
  1177. }
  1178. }
  1179. .scan-body {
  1180. margin: 22px auto 0;
  1181. padding-bottom: 38px;
  1182. text-align: center ;
  1183. div.img{
  1184. margin: 0 auto;
  1185. width: 180px;
  1186. height: 182px;
  1187. line-height: 182px;
  1188. text-align: center;
  1189. border: 1px solid #dcdcdc;
  1190. img{
  1191. width: 162px;
  1192. height: 165px;
  1193. }
  1194. }
  1195. div.content {
  1196. width: 138px;
  1197. margin: 58px auto 0;
  1198. text-align: center;
  1199. overflow: hidden;
  1200. img{
  1201. float: left;
  1202. margin-right: 25px;
  1203. width: 32px;
  1204. height: 27px;
  1205. }
  1206. div{
  1207. float: left;
  1208. width: 80px;
  1209. text-align: left;
  1210. span{
  1211. font-size: 14px;
  1212. color: #999;
  1213. b{
  1214. color: #0076ff;
  1215. }
  1216. }
  1217. div{
  1218. font-size: 14px;
  1219. color: #999;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. }
  1225. }
  1226. .bind-login {
  1227. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1228. border-radius: 6px;
  1229. .x-login-form{
  1230. padding: 0;
  1231. .bind-header {
  1232. overflow: hidden;
  1233. padding: 0 20px;
  1234. height: 50px;
  1235. line-height: 50px;
  1236. font-size: 18px;
  1237. font-weight: bold;
  1238. color: #666;
  1239. border: solid 1px #e5e5e5;
  1240. span {
  1241. &:first-child {
  1242. float: left;
  1243. border-bottom: 2px solid #5078cb;
  1244. }
  1245. &:last-child{
  1246. float: right;
  1247. font-size: 14px;
  1248. color: #5078cb;
  1249. font-weight: normal;
  1250. cursor: pointer;
  1251. }
  1252. }
  1253. }
  1254. .bind-body {
  1255. margin: 22px auto 0;
  1256. padding-bottom: 20px;
  1257. text-align: center ;
  1258. .img{
  1259. margin: 0 auto;
  1260. text-align: center;
  1261. img{
  1262. margin-bottom: 10px;
  1263. width: 60px;
  1264. height: 60px;
  1265. border-radius: 50%;
  1266. }
  1267. div{
  1268. font-size: 14px;
  1269. color: #999;
  1270. }
  1271. }
  1272. .set{
  1273. margin-top: 30px;
  1274. font-size: 12px;
  1275. color: #999;
  1276. a{
  1277. display: inline-block;
  1278. width: 90px;
  1279. line-height: 23px;
  1280. height: 24px;
  1281. text-align: center;
  1282. font-size: 14px;
  1283. color: #5078cb;
  1284. border-radius: 13px;
  1285. border: solid 1px #5078cb;
  1286. }
  1287. }
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. .footer{
  1294. padding: 50px 0;
  1295. }
  1296. </style>