Login.vue 46 KB

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