Login.vue 45 KB

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