Login.vue 45 KB

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