register.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <div class="go-register register">
  3. <div class="container">
  4. <div class="content" v-if="isSuccess">
  5. <div class="content-top">
  6. <h3>注册</h3>
  7. </div>
  8. <div>
  9. <el-form :model="item" :rules="rules2" ref="item" label-width="100px" class="demo-ruleForm">
  10. <div>
  11. </div>
  12. <el-form-item prop="mobile" class="mobile">
  13. <el-input v-model="item.mobile"
  14. v-bind:class="{active: mobileRegister}"
  15. placeholder="手机号码"></el-input>
  16. <span class="err-tip-msg tip" v-show="showMsgTip">单个手机号只能注册一个用户</span>
  17. <span class="err-tip-msg tip tip-mobile" v-show="mobileRegister">该手机号已被注册</span>
  18. </el-form-item>
  19. <el-form-item prop="captcha" class="captcha" style="overflow: hidden">
  20. <el-input type="text"
  21. v-model="ImgCode"
  22. auto-complete="off"
  23. class="code-input"
  24. @keyup.enter.native="getCheckCode"></el-input>
  25. <img id="captchaImage2" class="code-img" src="/sso/login/checkCode"/>
  26. <a class="code-click" @click="getCode">看不清换一张</a>
  27. </el-form-item>
  28. <el-form-item prop="code">
  29. <el-input type="text" v-model="item.code"
  30. v-bind:class="{ active: codeErrorChecked }" auto-complete="off" class="msg" placeholder="短信验证码"></el-input>
  31. <el-button type="primary" class="code"
  32. v-show="sendPersonalCode"
  33. @click="getCheckCode"
  34. :disabled="this.checkMobile">获取验证码</el-button>
  35. <el-button type="primary" v-show="!sendPersonalCode" class="code code-send">已发送({{personal_time}}s)</el-button>
  36. <span v-show="codeErrorChecked" class="codeError-tip">{{codeErrorMsg}}</span>
  37. </el-form-item>
  38. <el-form-item class="agree">
  39. <el-checkbox name="type" v-model="checked" @click="checkboxChecked"></el-checkbox>
  40. <span class="agree" v-if="!agreementUrl || (agreementUrl && (JSON.parse(agreementUrl.terms).isUrl))">我已阅读并同意 <a href="/common/agreement" target="_blank">《优软云服务条款》</a></span>
  41. <span class="agree" v-else>我已阅读并同意<a :href="`/common/cityAgreement/?appId=${this.$route.query.appId}`" target="_blank">《{{JSON.parse(agreementUrl.terms).name || ''}}》</a></span>
  42. </el-form-item>
  43. <el-form-item>
  44. <a class="btn finish" @click="waySubmit">确认注册</a>
  45. </el-form-item>
  46. </el-form>
  47. </div>
  48. </div>
  49. <div class="content" v-else>
  50. <div class="register-success">
  51. <i class="iconfont icon-zhucechenggong1"></i>
  52. <p>注册成功!</p>
  53. <span>您的账号密码已发送至手机,请注意查收</span>
  54. </div>
  55. </div>
  56. <div class="login">已有账号?<a :href="returnLogin">立即登录</a></div>
  57. <loading v-show="isShowLoading"/>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import md5 from 'js-md5'
  63. import Loading from '~components/common/loading/Loading.vue'
  64. export default {
  65. name: 'PersonalRegistration',
  66. layout: 'sass',
  67. components: {
  68. Loading
  69. },
  70. data () {
  71. var validateMobile = (rule, value, callback) => {
  72. if (value === '') {
  73. callback(new Error('请填写正确的手机号'))
  74. this.showMsgTip = false
  75. this.checkMobile = true
  76. this.mobileRegister = false
  77. this.mobileChecked = false
  78. } else {
  79. if (this.item.mobile !== '') {
  80. var reg = /^1([0-9]{10})$/
  81. if (!reg.test(value)) {
  82. callback(new Error('请填写正确的手机号'))
  83. this.showMsgTip = false
  84. this.checkMobile = true
  85. this.mobileRegister = false
  86. this.mobileChecked = false
  87. } else {
  88. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.item.mobile, mobileArea: ''}})
  89. .then(response => {
  90. if (response.data.hasRegister) {
  91. this.mobileRegister = true
  92. this.showMsgTip = false
  93. this.checkMobile = true
  94. this.mobileChecked = false
  95. } else {
  96. this.showMsgTip = false
  97. this.checkMobile = false
  98. this.mobileRegister = false
  99. this.mobileChecked = true
  100. }
  101. })
  102. }
  103. }
  104. callback()
  105. }
  106. }
  107. var validateCode = (rule, value, callback) => {
  108. if (value === '') {
  109. callback(new Error('请填写正确的验证码'))
  110. this.codeErrorChecked = false
  111. this.codeChecked = false
  112. } else {
  113. if (this.item.mobile === '') {
  114. callback(new Error('请先填写正确的手机号'))
  115. } else {
  116. if (this.token) {
  117. if (this.item.code.length === 6) {
  118. let param = new FormData()
  119. param.append('mobile', this.item.mobile)
  120. param.append('code', this.item.code)
  121. param.append('token', this.token)
  122. let config = {
  123. headers: {'Content-Type': 'multipart/form-data'}
  124. }
  125. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  126. .then(response => {
  127. if (response.data.success) {
  128. this.codeChecked = true
  129. this.codeErrorChecked = false
  130. } else {
  131. this.codeErrorChecked = true
  132. this.codeChecked = false
  133. return Promise.reject(response.data)
  134. }
  135. }).catch(err => {
  136. <<<<<<< HEAD
  137. this.$message.error(err.errMsg)
  138. // this.codeErrorMsg = err.errMsg
  139. =======
  140. // this.codeErrorMsg = err.errMsg
  141. this.$message.error(err.errMsg)
  142. >>>>>>> hotfix-nuxt2.0.0
  143. })
  144. } else {
  145. callback(new Error('请输入正确的验证码'))
  146. this.codeChecked = false
  147. this.codeErrorChecked = false
  148. }
  149. } else {
  150. callback(new Error('请先获取验证码'))
  151. this.codeChecked = false
  152. this.codeErrorChecked = false
  153. }
  154. }
  155. callback()
  156. }
  157. }
  158. var validateCodeIsEmpty = (rule, value, callback) => {
  159. if (value === '') {
  160. callback(new Error('请填写正确的验证码'))
  161. this.codeErrorChecked = false
  162. this.codeChecked = false
  163. } else {
  164. if (this.item.mobile === '') {
  165. callback(new Error('请先填写正确的手机号'))
  166. } else {
  167. if (this.token) {
  168. if (this.item.code.length === 6) {
  169. let param = new FormData()
  170. param.append('mobile', this.item.mobile)
  171. param.append('code', this.item.code)
  172. param.append('token', this.token)
  173. let config = {
  174. headers: {'Content-Type': 'multipart/form-data'}
  175. }
  176. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  177. .then(response => {
  178. if (response.data.success) {
  179. this.codeChecked = true
  180. this.codeErrorChecked = false
  181. } else {
  182. this.codeErrorChecked = true
  183. this.codeChecked = false
  184. return Promise.reject(response.data)
  185. }
  186. }).catch(err => {
  187. this.$message.error(err.errMsg)
  188. // this.codeErrorMsg = err.errMsg
  189. })
  190. } else {
  191. callback(new Error('请输入正确的验证码'))
  192. this.codeChecked = false
  193. this.codeErrorChecked = false
  194. }
  195. } else {
  196. callback(new Error('请先获取验证码'))
  197. this.codeChecked = false
  198. this.codeErrorChecked = false
  199. }
  200. }
  201. callback()
  202. }
  203. }
  204. return {
  205. isSuccess: true,
  206. speediness: false,
  207. ImgCode: '',
  208. item: {
  209. mobile: '',
  210. code: ''
  211. },
  212. isShowLoading: false,
  213. showPasswordError: false,
  214. mobileChecked: false,
  215. codeChecked: false,
  216. codeErrorChecked: false,
  217. showMsgTip: true,
  218. checkMobile: true,
  219. checked: true,
  220. token: '',
  221. mobileRegister: false,
  222. sendPersonalCode: true,
  223. codeErrorMsg: '',
  224. personal_time: 0,
  225. queryLink: '',
  226. appId: '',
  227. returnLogin: '',
  228. rules2: {
  229. mobile: [
  230. { validator: validateMobile, trigger: 'blur' }
  231. ],
  232. code: [
  233. { validator: validateCode, trigger: 'blur' },
  234. { validator: validateCodeIsEmpty, trigger: 'blur' }
  235. ]
  236. }
  237. }
  238. },
  239. mounted () {
  240. // 获取链接
  241. this.$nextTick(() => {
  242. this.getUrl()
  243. this.getCode()
  244. })
  245. },
  246. computed: {
  247. loginStyle () {
  248. return this.$store.state.login.loginStyle.data.content
  249. },
  250. agreementUrl () {
  251. return this.$store.state.login.agreementUrl.data.content
  252. }
  253. },
  254. methods: {
  255. // 获取链接
  256. getUrl () {
  257. var url = window.location.search
  258. var request = {}
  259. var origin = window.location.origin
  260. this.returnLogin = origin + '/sassLogin' + url
  261. if (url.indexOf('?' !== -1)) {
  262. var str = url.substr(1)
  263. var strs = str.split('&')
  264. this.queryLink = str
  265. for (var i = 0; i < strs.length; i++) {
  266. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  267. }
  268. }
  269. this.appId = request['appId'] || ''
  270. },
  271. // 注册
  272. goRegister () {
  273. window.location.href = `/register/enterpriseRegistration${this.queryLink ? '?' + this.queryLink : ''}`
  274. },
  275. // 我同意是否被选中
  276. checkboxChecked () {
  277. this.checked = !this.checked
  278. },
  279. // 快速注册
  280. waySubmit () {
  281. console.log(this.$route.params.baseUrl)
  282. if (this.mobileChecked && this.codeChecked && this.checked) {
  283. this.isShowLoading = true
  284. let param = new FormData()
  285. param.append('mobile', this.item.mobile)
  286. param.append('appId', this.appId)
  287. param.append('code', this.item.code)
  288. param.append('token', this.token)
  289. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  290. if (this.$route.query.baseUrl) {
  291. param.append('baseUrl', this.$route.query.baseUrl)
  292. }
  293. if (this.$route.query.returnURL) {
  294. param.append('returnUrl', this.$route.query.returnURL)
  295. }
  296. let config = {
  297. headers: {'Content-Type': 'multipart/form-data'}
  298. }
  299. this.$http.post('/sso/personal/register/sms', param, config)
  300. .then(response => {
  301. this.isShowLoading = false
  302. if (response.data.success) {
  303. this.isSuccess = false
  304. this.isShowLoading = false
  305. this.getJsonp(decodeURIComponent(this.$route.query.baseUrl))
  306. } else {
  307. return Promise.reject(response.data)
  308. }
  309. }).catch(err => {
  310. this.$message.error(err.errMsg)
  311. this.isShowLoading = false
  312. this.personal_time = 0
  313. })
  314. } else {
  315. if (!this.item.mobile) {
  316. this.$message.error('手机号不能为空')
  317. } else if (!this.mobileChecked) {
  318. this.$message.error('手机号输入有误,请按提示重新输入')
  319. } else if (!this.token) {
  320. this.$message.error('请先获取验证码')
  321. } else if (!this.item.code) {
  322. this.$message.error('验证码不能为空')
  323. } else if (!this.codeChecked) {
  324. this.$message.error('验证码输入有误,请按提示重新输入')
  325. } else if (!this.checked) {
  326. this.$message.error('您对阅读条款未做勾选')
  327. }
  328. }
  329. },
  330. // 获取验证码
  331. getCode () {
  332. let imgSrc = document.getElementById('captchaImage2')
  333. imgSrc.setAttribute('src', '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf())
  334. },
  335. getCheckCode () {
  336. let md5Code = md5(`{mobile=${this.item.mobile},code=${this.ImgCode},salt=sso}`)
  337. this.isShowLoading = true
  338. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile, timestamp: new Date().getTime() + '', code: this.ImgCode, sign: md5Code}})
  339. .then(response => {
  340. this.isShowLoading = false
  341. if (response.data) {
  342. this.token = response.data.token
  343. if (response.data.errMsg) {
  344. this.$message({
  345. message: response.data.errMsg,
  346. type: 'error'
  347. })
  348. this.ImgCode = ''
  349. this.getCode()
  350. return
  351. }
  352. if (this.token !== '') {
  353. this.$message({
  354. message: '验证码已经发送到您的手机,请注意查收',
  355. type: 'success'
  356. })
  357. this.sendPersonalCode = false
  358. this.personal_time = 60
  359. var personalTime = setInterval(() => {
  360. this.personal_time--
  361. if (this.personal_time <= 0) {
  362. this.sendPersonalCode = true
  363. clearInterval(personalTime)
  364. }
  365. }, 1000)
  366. }
  367. } else {
  368. return Promise.reject(response.data)
  369. }
  370. }).catch(err => {
  371. this.isShowLoading = false
  372. this.$message.error(err.errMsg)
  373. })
  374. },
  375. getJsonp: function (url, timeout = 500) {
  376. return new Promise((resolve, reject) => {
  377. this.$jsonp(url, {
  378. name: 'successCallback',
  379. timeout: timeout
  380. }, function (err, data) {
  381. if (err) {
  382. reject(err)
  383. throw err
  384. } else {
  385. resolve(data)
  386. }
  387. })
  388. })
  389. }
  390. }
  391. }
  392. </script>
  393. <style lang="scss" scoped>
  394. .go-register.register {
  395. position: relative;
  396. bottom: -18px;
  397. margin: 0 auto;
  398. width: 100%;
  399. background: #eee;
  400. .container{
  401. padding-top: 38px!important;
  402. margin: 0 auto;
  403. width: 980px;
  404. text-align: center;
  405. background: #fff;
  406. box-shadow: none!important;
  407. .content{
  408. padding: 0 50px;
  409. margin: 50px auto 0;
  410. width: 100%;
  411. text-align: center;
  412. .register-success {
  413. padding-top: 40px;
  414. width: 100%;
  415. height: 380px;
  416. i.icon-zhucechenggong1{
  417. font-size: 148px;
  418. color: #00BB00;
  419. }
  420. p{
  421. margin-top: 20px;
  422. font-size: 28px;
  423. color: #333;
  424. }
  425. span{
  426. font-size: 16px;
  427. color: #666;
  428. }
  429. }
  430. .content-top{
  431. position: relative;
  432. height: 80px;
  433. line-height: 80px;
  434. border-bottom: 1px solid #dcdcdc;
  435. h3{
  436. font-family: 'SimHei';
  437. font-size: 24px;
  438. color: #000;
  439. }
  440. a.go{
  441. position: absolute;
  442. top: 0;
  443. right: 0;
  444. font-size: 14px;
  445. i{
  446. margin-right: 3px;
  447. }
  448. }
  449. }
  450. .content-tab{
  451. width: 360px;
  452. margin: 0 auto;
  453. height: 50px;
  454. margin-top: 15px;
  455. color: #999;
  456. span{
  457. display:inline-block;
  458. width:50%;
  459. vertical-align:top;
  460. font-size:20px;
  461. text-align: center;
  462. line-height:40px;
  463. height:40px;
  464. border-bottom:2px solid #fff;
  465. cursor:pointer;
  466. &.speed{
  467. color:#3375a7;
  468. border-bottom:2px solid #3375a7;
  469. }
  470. }
  471. }
  472. form {
  473. padding-bottom: 44px;
  474. margin-top: 15px;
  475. input{
  476. padding: 0 0 0 18px;
  477. width: 360px;
  478. height: 44px;
  479. line-height: 44px;
  480. font-size: 14px;
  481. color: #000;
  482. border-radius: 0;
  483. }
  484. span.help{
  485. position: absolute;
  486. right: -230px;
  487. top:0;
  488. font-size: 12px;
  489. color: #f00;
  490. }
  491. i.fa{
  492. position: absolute;
  493. top: 10px;
  494. right: 18px;
  495. font-size: 24px;
  496. color: #a0a0a0;
  497. cursor: pointer;
  498. }
  499. span.tip{
  500. position: absolute;
  501. top: 40px;
  502. left: 0;
  503. font-size: 12px;
  504. color: #8c8c8c;
  505. &.tip-mobile{
  506. color: #ff4949;
  507. }
  508. }
  509. .el-form-item__error {
  510. position: static;
  511. margin: 0 auto;
  512. text-align: left;
  513. }
  514. span.codeError-tip{
  515. position: absolute;
  516. top: 3px;
  517. left: 378px;
  518. width: 200px;
  519. text-align: left;
  520. color: #ff4949;
  521. font-size: 12px;
  522. }
  523. span.tip.passwordError{
  524. position: absolute;
  525. top: 3px;
  526. left: 380px;
  527. width: 200px;
  528. text-align: left;
  529. color: #ff4949;
  530. font-size: 12px;
  531. }
  532. input.msg{
  533. float: left;
  534. width: 210px;
  535. }
  536. button.msg{
  537. float: right;
  538. width: 130px;
  539. height: 44px;
  540. font-size: 14px;
  541. color: #5a5a5a;
  542. background: #f4f4f4;
  543. border: 1px solid #dcdcdc;
  544. cursor: pointer;
  545. &:disabled{
  546. cursor: not-allowed ;
  547. opacity: .7;
  548. }
  549. }
  550. span.msg.send{
  551. float: right;
  552. width: 130px;
  553. height: 44px;
  554. line-height: 44px;
  555. font-size: 14px;
  556. background: #d2d2d2;
  557. color: #fff;
  558. border: 1px solid #dcdcdc;
  559. }
  560. input[type='checkbox']{
  561. margin: 0 14px 0 55px;
  562. float: left;
  563. width: 16px;
  564. height: 16px;
  565. }
  566. span.agree{
  567. float: left;
  568. margin: 1px 0 0 10px;
  569. font-size: 14px;
  570. color: #8b8b8b;
  571. a{
  572. color: #0076ad;
  573. }
  574. }
  575. .form-group.agree{
  576. margin: 20px auto 0 !important;
  577. }
  578. .submitBtn {
  579. display: inline-block;
  580. width: 360px;
  581. height: 44px;
  582. line-height: 44px;
  583. font-size: 16px;
  584. color: #fff;
  585. background: #0076AD;
  586. border-radius: 3px;
  587. border: none;
  588. &:disabled{
  589. cursor: not-allowed ;
  590. opacity: .7;
  591. }
  592. }
  593. }
  594. }
  595. .login{
  596. margin-top: 20px;
  597. font-size: 14px;
  598. color: #8c8c8c;
  599. a{
  600. font-size: 14px;
  601. color: #0076ad;
  602. }
  603. }
  604. }
  605. }
  606. .footer{
  607. padding: 50px 0;
  608. }
  609. </style>