Login.vue 44 KB

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