Login.vue 45 KB

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