Login.vue 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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. <el-form-item prop="username">
  53. <el-input type="text" v-model="login.username" auto-complete="new-password" placeholder="手机号/邮箱"></el-input>
  54. <i class="fa fa-user"></i>
  55. </el-form-item>
  56. <el-form-item prop="password">
  57. <input autocomplete="new-password"
  58. type="password" style="display: none;width:0;height:0;">
  59. <el-input type="password"
  60. v-model="login.password"
  61. auto-complete="new-password"
  62. placeholder="密码"
  63. @keyup.enter.native="isLogin(true)"></el-input>
  64. <i class="fa fa-lock"></i>
  65. </el-form-item>
  66. <el-form-item prop="captcha" class="captcha" v-show="showCheckCode">
  67. <el-input type="text"
  68. v-model="login.captcha"
  69. auto-complete="off"
  70. class="code-input"
  71. @keyup.enter.native="isLogin(true)"></el-input>
  72. <img id="captchaImage" class="code-img" src="/sso/login/checkCode"/>
  73. <a class="code-click" @click="getCode">看不清换一张</a>
  74. </el-form-item>
  75. <el-form-item class="text-position">
  76. <div class="page-part" v-if="loginStyle.needRememberPwd">
  77. <el-checkbox v-model="checked">记住密码</el-checkbox>
  78. </div>
  79. <a class="forget" id='forget' @click="goForgetPassword">忘记密码?</a>
  80. </el-form-item>
  81. <el-form-item>
  82. <a class="btn login"
  83. @click="isLogin(true)"
  84. :disabled="isLoginDisabled">登录</a>
  85. </el-form-item>
  86. </el-form>
  87. </div>
  88. <!--短信快捷登录-->
  89. <div v-show="activeTab === 1">
  90. <el-form :model="fastLogin" :rules="rules3" ref="fastLogin" class="demo-ruleForm login-form loginForm">
  91. <el-form-item prop="mobile">
  92. <el-input type="text" v-model="fastLogin.mobile" auto-complete="off" placeholder="请输入手机号"></el-input>
  93. </el-form-item>
  94. <el-form-item prop="code" class="fastMsg">
  95. <el-input type="text" v-model="fastLogin.code"
  96. auto-complete="off" placeholder="验证码"></el-input>
  97. <el-button type="primary" class="fastCode"
  98. v-show="sendLoginCode"
  99. @click="getCheckCode">获取验证码</el-button>
  100. <el-button type="primary" v-show="!sendLoginCode" class="fastCode code-send">已发送({{login_time}}s)</el-button>
  101. </el-form-item>
  102. <el-form-item>
  103. <a class="btn login"
  104. @click="fastToLogin(true)">登录</a>
  105. </el-form-item>
  106. </el-form>
  107. </div>
  108. <div class="warn-text-area">
  109. 为确保您账户的安全及正常使用,依《网络安全法》相关要求,6月1日起会员账户需绑定手机、设置密码保护。感谢您的理解和支持!
  110. </div>
  111. <div class="link-go">
  112. <a @click="changeManage" class="first">更换管理员</a>
  113. <a class='change' @click="activeTab = 1" v-show="activeTab === 0">短信快捷登录</a>
  114. <a class='change' @click="activeTab = 0" v-show="activeTab === 1">用户密码登录</a>
  115. <a id="register" @click="goRegister" class="second">
  116. <i class="fa fa-arrow-circle-o-right"></i>免费注册</a>
  117. </div>
  118. <!--微信-->
  119. <div class="scavenging">
  120. <div @click="getScan"><img src="/images/logo/weixin.png" alt=""/>微信</div>
  121. </div>
  122. </div>
  123. </div>
  124. <!--微信扫码登录-->
  125. <div>
  126. <!--<div class="x-login scan-login" v-if="loginWay === 1">-->
  127. <!--<div class="x-login-form">-->
  128. <!--<div class="scan-header">-->
  129. <!--<span>微信登录</span>-->
  130. <!--<img src="images/logo/saoma.png" alt="" @click="loginWay = 0"/>-->
  131. <!--</div>-->
  132. <!--<div class="scan-body">-->
  133. <!--<div class="img">-->
  134. <!--<img src="/images/logo/sao.png" alt=""/>-->
  135. <!--</div>-->
  136. <!--<div class="content">-->
  137. <!--<img src="/images/logo/saosao.png" alt="">-->
  138. <!--<div>-->
  139. <!--<span>打开 <b>微信</b></span>-->
  140. <!--<div>扫一扫登录</div>-->
  141. <!--</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. <input autocomplete="new-password"
  166. type="password" style="display: none;width:0;height:0;">
  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. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  683. }
  684. Promise.all(promises).then(() => {
  685. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  686. }).catch(() => {
  687. crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
  688. })
  689. },
  690. // 设置cookie
  691. setCookie (cName, cPwd, exdays) {
  692. let exdate = new Date()
  693. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays)
  694. window.document.cookie = 'userName' + '=' + cName + ';path=/;expires=' + exdate.toGMTString()
  695. window.document.cookie = 'userPwd' + '=' + cPwd + ';path=/;expires=' + exdate.toGMTString()
  696. },
  697. // 读取cookies
  698. getCookie () {
  699. if (document.cookie.length > 0) {
  700. let arr = document.cookie.split(';')
  701. for (var i = 0; i < arr.length; i++) {
  702. let arr2 = arr[i].split('=')
  703. if (arr2[0].trim() === 'userName') {
  704. this.login.username = arr2[1]
  705. }
  706. if (arr2[0].trim() === 'userPwd') {
  707. this.login.password = arr2[1]
  708. }
  709. if (this.login.username && this.login.username) {
  710. this.checked = true
  711. }
  712. }
  713. }
  714. },
  715. // 清除cookie
  716. clearCookie () {
  717. this.setCookie('', '', -1)
  718. },
  719. // 获取校验码
  720. getCheckCode () {
  721. this.isShowLoading = true
  722. if (!this.fastLogin.mobile) {
  723. this.isShowLoading = false
  724. this.$message.error('请先填写手机号')
  725. } else {
  726. if (this.checkMobile) {
  727. this.$http.get(`/sso/login/sendSmsCode`, {params: {mobile: this.fastLogin.mobile}})
  728. .then(response => {
  729. this.isShowLoading = false
  730. if (response.data) {
  731. if (response.data.success) {
  732. this.token = response.data.content.token
  733. this.$message({
  734. message: '验证码已经发送到您的手机,请注意查收',
  735. type: 'success'
  736. })
  737. this.sendLoginCode = false
  738. this.login_time = 60
  739. var loginTime = setInterval(() => {
  740. this.login_time--
  741. if (this.login_time <= 0) {
  742. this.sendLoginCode = true
  743. clearInterval(loginTime)
  744. }
  745. }, 1000)
  746. } else {
  747. this.$message.error(response.data.errMsg)
  748. }
  749. } else {
  750. return Promise.reject(response.data)
  751. }
  752. }).catch(err => {
  753. this.isShowLoading = false
  754. this.$message.error(err.errMsg)
  755. })
  756. } else {
  757. this.isShowLoading = false
  758. }
  759. }
  760. },
  761. // 微信判断绑定和账套选择
  762. wxEnterprise () {
  763. this.isShowLoading = true
  764. if (this.$route.query.code) {
  765. let param = new FormData()
  766. param.append('code', this.$route.query.code ? this.$route.query.code : '')
  767. param.append('state', this.$route.query.state ? this.$route.query.state : '')
  768. param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
  769. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  770. param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
  771. param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
  772. let config = {
  773. headers: {'Content-Type': 'multipart/form-data'}
  774. }
  775. this.$http.post('/sso/login/wxqrLogin', param, config)
  776. .then(response => {
  777. this.isShowLoading = false
  778. if (response.data.success) {
  779. if (!response.data.content.hasRegister && response.data.content.token) {
  780. this.loginWay = 2
  781. this.wxToken = response.data.content.token
  782. this.$http.get(`/weChat/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
  783. .then(response => {
  784. if (response.data.success) {
  785. this.wxImg = response.data.content.headimgurl
  786. this.wxName = response.data.content.nickname
  787. } else {
  788. return Promise.reject(response.data)
  789. }
  790. }).catch(err => {
  791. this.$message.error(err.errMsg)
  792. })
  793. } else if (response.data.content.spaces) {
  794. // 弹框让用户选择企业
  795. this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
  796. this.dialogVisible = true
  797. } else if (response.data.content.loginUrls) {
  798. // 遍历登录url循环让各应用登录(需要跨域)
  799. let param = response.data.content.data
  800. let a = ''
  801. for (let n in param) {
  802. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  803. }
  804. let params = a.substr(0, a.length - 1)
  805. this.isShowLoading = true
  806. if (response.data.content.currentUrl) {
  807. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  808. name: 'successCallback',
  809. timeout: 3000
  810. }, (err, data) => {
  811. if (err) {
  812. this.$message.error('登录超时,请重试')
  813. this.isShowLoading = false
  814. throw err
  815. } else {
  816. this.loginOther(response, params)
  817. }
  818. })
  819. } else {
  820. this.loginOther(response, params, 3000)
  821. }
  822. }
  823. } else {
  824. this.$message.error(response.data)
  825. return Promise.reject(response.data)
  826. }
  827. }).catch(err => {
  828. this.isShowLoading = false
  829. let _this = this
  830. setTimeout(function () {
  831. _this.getCode()
  832. }, 100)
  833. this.$message.error(err.errMsg)
  834. })
  835. }
  836. },
  837. // 微信扫码登录
  838. getScan () {
  839. // this.loginWay = 1
  840. this.isShowLoading = true
  841. this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
  842. .then(response => {
  843. this.isShowLoading = false
  844. if (response.data.success) {
  845. window.location.href = response.data.content
  846. } else {
  847. return Promise.reject(response.data)
  848. }
  849. }).catch(err => {
  850. this.isShowLoading = false
  851. this.$message.error(err.errMsg)
  852. })
  853. },
  854. // 绑定企业
  855. wxBind () {
  856. this.isShowLoading = true
  857. if (!this.bindAccount.username) {
  858. this.isShowLoading = false
  859. this.$message.error('请填写账号')
  860. } else if (!this.bindAccount.password) {
  861. this.isShowLoading = false
  862. this.$message.error('请填写密码')
  863. } else {
  864. let param = new FormData()
  865. param.append('t', this.wxToken)
  866. param.append('username', this.bindAccount.username)
  867. param.append('password', this.bindAccount.password)
  868. let config = {
  869. headers: {'Content-Type': 'multipart/form-data'}
  870. }
  871. this.$http.post('/weChat/addAccount', param, config)
  872. .then(response => {
  873. this.isShowLoading = false
  874. if (response.data.success) {
  875. this.wxEnterprise()
  876. } else {
  877. return Promise.reject(response.data)
  878. }
  879. }).catch(err => {
  880. this.isShowLoading = false
  881. this.$message.error(err.errMsg)
  882. })
  883. }
  884. }
  885. }
  886. }
  887. </script>
  888. <style lang="scss" type="text/scss" scoped>
  889. @import '~assets/scss/mixins';
  890. @import '~assets/scss/variables';
  891. .x-navbar{
  892. height: 80px;
  893. line-height: 80px;
  894. margin: 0;
  895. .container{
  896. position: relative;
  897. width: 990px!important;
  898. height: 80px;
  899. .navbar-header{
  900. height: 80px;
  901. line-height: 80px;
  902. }
  903. a.navbar-brand{
  904. overflow: hidden;
  905. padding: 0px;
  906. height: inherit;
  907. line-height: inherit;
  908. font-family: "\5FAE\8F6F\96C5\9ED1";
  909. font-size: 24px;
  910. font-weight: 400;
  911. color: #888;
  912. img{
  913. margin: 28px 8px 0 0;
  914. max-width: 80px;
  915. max-height: 27px;
  916. vertical-align: middle;
  917. float: left;
  918. }
  919. span{
  920. float: left;
  921. }
  922. }
  923. .collapse{
  924. a{
  925. padding-left: 12px;
  926. margin-right: 10px;
  927. color: #666;
  928. outline: 0;
  929. border-left: 1px solid #ddd;
  930. &:first-child{
  931. border-width: 0;
  932. }
  933. }
  934. }
  935. }
  936. }
  937. .x-container{
  938. position: relative;
  939. height: 475px;
  940. div.link-go {
  941. text-align: right;
  942. margin-top: 7px;
  943. a{
  944. font-size: 12px;
  945. color: #2d8cf0;
  946. background: 0 0;
  947. text-decoration: none;
  948. outline: 0;
  949. cursor: pointer;
  950. transition: color .2s ease;
  951. }
  952. a.first{
  953. float: left;
  954. margin-top: 2px;
  955. font-size: 12px;
  956. }
  957. a.change{
  958. margin:2px 0 0 50px;
  959. float: left;
  960. font-size: 12px;
  961. }
  962. }
  963. /*微信登录*/
  964. .scavenging {
  965. margin-top:22px;
  966. div{
  967. font-size: 12px;
  968. color: #666;
  969. cursor: pointer;
  970. img{
  971. margin-right: 10px;
  972. }
  973. }
  974. }
  975. /*登录弹出框*/
  976. .x-floating {
  977. position: fixed;
  978. top: 80px;
  979. left: 50%;
  980. z-index: 100000;
  981. opacity: 1;
  982. -webkit-transition: all .5s;
  983. -moz-transition: all .5s;
  984. transition: all .5s;
  985. }
  986. .x-list {
  987. width: 60%;
  988. height:420px;
  989. margin-left: -30%;
  990. background: #fff;
  991. border-top: 1px solid #e7e7e7;
  992. cursor: pointer;
  993. .x-list-header {
  994. padding: 10px 20px;
  995. background: #e0e0e0;
  996. height: 42px;
  997. line-height: 21px;
  998. font-size: 14px;
  999. font-weight: 700;
  1000. color: #505050;
  1001. }
  1002. .x-list-content{
  1003. overflow-y: auto;
  1004. height:375px;
  1005. ul{
  1006. margin-bottom: 0;
  1007. li{
  1008. display:inline-block;
  1009. padding: 10px 20px;
  1010. width: 33%;
  1011. overflow: hidden;
  1012. white-space: nowrap;
  1013. text-overflow: ellipsis;
  1014. height: 42px;
  1015. line-height: 21px;
  1016. font-size: 12px;
  1017. color: #505050;
  1018. border-bottom: 1px solid #e7e7e7;
  1019. &:hover{
  1020. background: #e7e7e7;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. .x-list .x-list-header, .x-list li {
  1026. padding: 10px 20px;
  1027. border-bottom: 1px solid #e7e7e7;
  1028. }
  1029. }
  1030. .x-floating.in {
  1031. top: 80px;
  1032. opacity: 1;
  1033. }
  1034. .x-banner-wrap {
  1035. position: absolute;
  1036. left: 0;
  1037. top: 0;
  1038. width: 100%;
  1039. height: 475px;
  1040. .x-banner {
  1041. position: relative;
  1042. overflow: auto;
  1043. height: 475px;
  1044. text-align: center;
  1045. li{
  1046. width: 100%;
  1047. height: 475px;
  1048. .inner{
  1049. height: 100%;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. .x-login-wrap{
  1055. position: absolute;
  1056. top: 10px;
  1057. right: 50%;
  1058. margin-right: -495px;
  1059. height: 475px;
  1060. z-index: 5;
  1061. .x-login {
  1062. position: relative;
  1063. top: 40px;
  1064. width: 346px;
  1065. background: #fff;
  1066. overflow: visible;
  1067. z-index: 4;
  1068. .x-login-form, .x-login-qrcode {
  1069. padding: 20px;
  1070. .btn{
  1071. background: #5078cb;
  1072. color: #fff;
  1073. font-weight: 700;
  1074. letter-spacing: 4px;
  1075. border-radius: 0;
  1076. }
  1077. .x-has-feedback-right {
  1078. float: right;
  1079. display: inline-block;
  1080. a{
  1081. color: #5078cb;
  1082. }
  1083. }
  1084. .x-has-feedback-left {
  1085. position: relative;
  1086. .x-input {
  1087. padding-left: 30px;
  1088. line-height: 18px;
  1089. color: #555;
  1090. border-color: #ccc;
  1091. border-radius: 0;
  1092. box-shadow: none;
  1093. }
  1094. i.fa{
  1095. position: absolute;
  1096. top: 2px;
  1097. left: 0;
  1098. z-index: 2;
  1099. display: block;
  1100. width: 30px;
  1101. height: 34px;
  1102. line-height: 34px;
  1103. text-align: center;
  1104. pointer-events: none;
  1105. color: #999;
  1106. font-size: 18px;
  1107. }
  1108. }
  1109. i.fa-keyboard-o{
  1110. position: absolute;
  1111. right: 10px;
  1112. top: 10px;
  1113. }
  1114. i.fa-arrow-circle-o-right{
  1115. margin-right: 5px;
  1116. font-size: 12px;
  1117. color: #5078cb;
  1118. }
  1119. .warn-text-area{
  1120. margin-top: 5px;
  1121. font-size: 13px;
  1122. color: #000;
  1123. }
  1124. .text-position {
  1125. overflow: hidden;
  1126. .page-part {
  1127. float: left;
  1128. margin-bottom: 0;
  1129. .el-checkbox {
  1130. margin: 0;
  1131. span.el-checkbox__inner{
  1132. width: 14px;
  1133. height: 14px;
  1134. }
  1135. }
  1136. }
  1137. .forget {
  1138. float: right;
  1139. color: #2d8cf0;
  1140. }
  1141. }
  1142. }
  1143. }
  1144. .scan-login {
  1145. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1146. border-radius: 6px;
  1147. .x-login-form{
  1148. padding: 0;
  1149. .scan-header {
  1150. position: relative;
  1151. height: 50px;
  1152. line-height: 50px;
  1153. font-size: 18px;
  1154. font-weight: bold;
  1155. color: #666;
  1156. border: solid 1px #e5e5e5;
  1157. span{
  1158. position: absolute;
  1159. top: -3px;
  1160. padding-left: 10px;
  1161. display: inline-block;
  1162. width: 90px;
  1163. border-bottom: 2px solid #0076ff;
  1164. }
  1165. img{
  1166. position: absolute;
  1167. top: -3px;
  1168. right: -1px;
  1169. height: 50px;
  1170. cursor: pointer;
  1171. }
  1172. }
  1173. .scan-body {
  1174. margin: 22px auto 0;
  1175. padding-bottom: 38px;
  1176. text-align: center ;
  1177. div.img{
  1178. margin: 0 auto;
  1179. width: 180px;
  1180. height: 182px;
  1181. line-height: 182px;
  1182. text-align: center;
  1183. border: 1px solid #dcdcdc;
  1184. img{
  1185. width: 162px;
  1186. height: 165px;
  1187. }
  1188. }
  1189. div.content {
  1190. width: 138px;
  1191. margin: 58px auto 0;
  1192. text-align: center;
  1193. overflow: hidden;
  1194. img{
  1195. float: left;
  1196. margin-right: 25px;
  1197. width: 32px;
  1198. height: 27px;
  1199. }
  1200. div{
  1201. float: left;
  1202. width: 80px;
  1203. text-align: left;
  1204. span{
  1205. font-size: 14px;
  1206. color: #999;
  1207. b{
  1208. color: #0076ff;
  1209. }
  1210. }
  1211. div{
  1212. font-size: 14px;
  1213. color: #999;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220. .bind-login {
  1221. box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
  1222. border-radius: 6px;
  1223. .x-login-form{
  1224. padding: 0;
  1225. .bind-header {
  1226. overflow: hidden;
  1227. padding: 0 20px;
  1228. height: 50px;
  1229. line-height: 50px;
  1230. font-size: 18px;
  1231. font-weight: bold;
  1232. color: #666;
  1233. border: solid 1px #e5e5e5;
  1234. span {
  1235. &:first-child {
  1236. float: left;
  1237. border-bottom: 2px solid #5078cb;
  1238. }
  1239. &:last-child{
  1240. float: right;
  1241. font-size: 14px;
  1242. color: #5078cb;
  1243. font-weight: normal;
  1244. cursor: pointer;
  1245. }
  1246. }
  1247. }
  1248. .bind-body {
  1249. margin: 22px auto 0;
  1250. padding-bottom: 20px;
  1251. text-align: center ;
  1252. .img{
  1253. margin: 0 auto;
  1254. text-align: center;
  1255. img{
  1256. margin-bottom: 10px;
  1257. width: 60px;
  1258. height: 60px;
  1259. border-radius: 50%;
  1260. }
  1261. div{
  1262. font-size: 14px;
  1263. color: #999;
  1264. }
  1265. }
  1266. .set{
  1267. margin-top: 40px;
  1268. font-size: 12px;
  1269. color: #999;
  1270. a{
  1271. display: inline-block;
  1272. width: 90px;
  1273. line-height: 23px;
  1274. height: 24px;
  1275. text-align: center;
  1276. font-size: 14px;
  1277. color: #5078cb;
  1278. border-radius: 13px;
  1279. border: solid 1px #5078cb;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. .footer{
  1288. padding: 50px 0;
  1289. }
  1290. </style>