Login.vue 46 KB

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