index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>个人注册</p>
  5. <a class="go" @click="goRegister"><i class="fa fa-long-arrow-right"></i>企业注册</a>
  6. </div>
  7. <div class="content-tab">
  8. <span :class="{speed: speediness === false}" @click="clickWay(false)">用户名注册</span>
  9. <span :class="{speed: speediness === true}" @click="clickWay(true)">手机号注册</span>
  10. </div>
  11. <div class="f-form">
  12. <div class="page-part" v-if="!speediness">
  13. <mt-field :state="state.vipName"
  14. placeholder="会员名"
  15. :attr="{ maxlength: 20 }"
  16. v-model="vipName"></mt-field>
  17. </div>
  18. <div class="page-part" v-if="!speediness">
  19. <mt-field :state="state.password"
  20. placeholder="密码"
  21. :attr="{ maxlength: 20 }"
  22. v-model="password"
  23. @input.native="codePwd"
  24. type="password"></mt-field>
  25. <template v-if="password">
  26. <p class="pwd">密码强度 <em :class="{sm:step === '弱', md: step === '中', ld:step === '强'}"></em> <em :class="{md: step === '中', ld:step === '强'}"></em> <em :class="{ld:step === '强'}"></em> <span :class="{smstep:step === '弱', mdstep: step === '中', ldstep:step === '强'}" v-text="step">强</span></p>
  27. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  28. </template>
  29. </div>
  30. <div class="page-part" v-if="!speediness">
  31. <mt-field :state="state.confirm"
  32. placeholder="确认密码"
  33. v-model="confirm"
  34. type="password"></mt-field>
  35. </div>
  36. <div class="page-part">
  37. <mt-field :state="state.mobile"
  38. placeholder="手机号码"
  39. v-model="mobile"
  40. type="tel"></mt-field>
  41. </div>
  42. <div class="page-part">
  43. <mt-field placeholder="验证码" v-model="code">
  44. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  45. </mt-field>
  46. </div>
  47. <div class="page-part">
  48. <mt-field :state="state.token"
  49. placeholder="短信验证码"
  50. v-model="token"
  51. auto-complete="off">
  52. <span class="token" v-text="tokenText" @click="getCheckCode">获取验证码</span>
  53. </mt-field>
  54. </div>
  55. </div>
  56. <div class="form-btn">
  57. <div class="page-part">
  58. <el-checkbox v-model="checked">我已阅读并同意 <a class="rgba" href="/common/agreement">《优软云服务条款》</a></el-checkbox>
  59. </div>
  60. <mt-button type="primary" size="large" @click.native="allSubmit">完成注册</mt-button>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import md5 from 'js-md5'
  66. export default {
  67. name: 'registerPerson',
  68. data () {
  69. return {
  70. speediness: false,
  71. imgSrc: '',
  72. code: '',
  73. step: 1,
  74. state: {
  75. vipName: 'error',
  76. password: 'error',
  77. confirm: 'error',
  78. mobile: 'error',
  79. token: 'error',
  80. code: 'error'
  81. },
  82. vipName: '',
  83. password: '',
  84. confirm: '',
  85. mobile: '',
  86. token: '',
  87. tokenCode: '',
  88. tokenText: '获取验证码',
  89. tokenTime: '60',
  90. checked: true
  91. }
  92. },
  93. mounted () {
  94. this.$nextTick(() => {
  95. this.getCode()
  96. })
  97. },
  98. watch: {
  99. 'token': {
  100. handler (newVal) {
  101. if (newVal.length === 6) {
  102. this.codeToken()
  103. }
  104. },
  105. immediate: true
  106. }
  107. },
  108. methods: {
  109. // 切换注册方式
  110. clickWay (type) {
  111. if (this.speediness !== type) {
  112. this.speediness = type
  113. this.imgSrc = ''
  114. this.getCode()
  115. }
  116. },
  117. getCode () {
  118. this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
  119. },
  120. // 注册
  121. goRegister () {
  122. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  123. },
  124. // 验证弹窗
  125. downToast (type) {
  126. this.$toast({
  127. message: type,
  128. iconClass: 'el-icon-warning'
  129. })
  130. },
  131. // 验证会员名
  132. codeVipName () {
  133. let count = this.vipName.length
  134. if (count === 0) {
  135. this.downToast('会员名不能为空')
  136. this.state.vipName = 'error'
  137. } else if (count < 2 || count > 20) {
  138. this.downToast('请填写合适的会员名称,2~20个字符')
  139. this.state.vipName = 'warning'
  140. } else {
  141. this.state.vipName = 'success'
  142. }
  143. },
  144. // 验证密码强度
  145. codePwd () {
  146. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  147. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  148. if (reg1.test(this.password)) {
  149. this.step = '强'
  150. } else if (reg2.test(this.password)) {
  151. this.step = '中'
  152. } else {
  153. this.step = '弱'
  154. }
  155. },
  156. // 验证密码格式
  157. codePwdBlur () {
  158. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  159. if (!this.password) {
  160. this.downToast('请输入密码')
  161. this.state.password = 'error'
  162. } else if (!reg2.test(this.password)) {
  163. this.downToast('密码须为8-20字符的英文、数字混合')
  164. this.state.password = 'warning'
  165. } else {
  166. this.state.password = 'success'
  167. if (this.confirm) {
  168. this.codePassword()
  169. }
  170. }
  171. },
  172. // 验证密码的确认信息
  173. codePassword () {
  174. if (!this.confirm) {
  175. this.downToast('请再次输入密码')
  176. this.state.confirm = 'error'
  177. } else if (this.confirm !== this.password) {
  178. this.downToast('两次输入密码不一致!')
  179. this.state.confirm = 'warning'
  180. } else {
  181. this.state.confirm = 'success'
  182. }
  183. },
  184. // 验证手机号
  185. codeMobile () {
  186. let reg = /^1([0-9]{10})$/
  187. if (!this.mobile) {
  188. this.downToast('请输入手机号')
  189. this.state.mobile = 'error'
  190. } else if (!reg.test(this.mobile)) {
  191. this.downToast('请填写正确的手机号码')
  192. this.state.mobile = 'warning'
  193. } else {
  194. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.mobile, mobileArea: ''}})
  195. .then(response => {
  196. if (response.data.hasRegister) {
  197. this.downToast('该手机号已被注册,可直接登录')
  198. this.state.mobile = 'warning'
  199. } else {
  200. this.state.mobile = 'success'
  201. }
  202. }).catch((err) => {
  203. this.downToast(err.errMsg)
  204. })
  205. }
  206. },
  207. // 验证-验证码信息
  208. codeToken () {
  209. if (!this.token) {
  210. this.downToast('请先填写验证码')
  211. this.state.token = 'error'
  212. } else {
  213. if (!this.mobile) {
  214. this.downToast('请先填写正确的手机号码')
  215. this.state.token = 'warning'
  216. } else {
  217. if (this.tokenCode) {
  218. let param = new FormData()
  219. param.append('mobile', this.mobile)
  220. param.append('token', this.tokenCode)
  221. param.append('code', this.token)
  222. let config = {
  223. headers: {'Content-Type': 'multipart/form-data'}
  224. }
  225. this.$http.post('/sso/personal/register/checkCode', param, config)
  226. .then(response => {
  227. if (response.data.success) {
  228. this.state.token = 'success'
  229. } else {
  230. this.$toast({
  231. message: response.data.errMsg,
  232. iconClass: 'el-icon-error'
  233. })
  234. }
  235. }).catch((err) => {
  236. this.downToast(err.errMsg)
  237. })
  238. } else {
  239. this.downToast('请点击先获取验证码信息')
  240. this.state.token = 'warning'
  241. }
  242. }
  243. }
  244. },
  245. // 获取验证码
  246. loadCheckCode () {
  247. let md5Code = md5(`{mobile=${this.mobile},code=${this.code},salt=sso}`)
  248. if (this.state.mobile !== 'success') {
  249. this.codeMobile()
  250. } else if (this.code === '') {
  251. this.downToast('请输入验证码后获取!')
  252. } else {
  253. this.$indicator.open('获取中...')
  254. let _this = this
  255. this.$http.get('/sso/personal/register/checkCode', {params: {sign: md5Code, code: this.code, mobile: this.mobile, timestamp: new Date().getTime() + ''}})
  256. .then(response => {
  257. this.$indicator.close()
  258. if (response.data.errMsg) {
  259. this.$toast({
  260. message: response.data.errMsg,
  261. iconClass: 'el-icon-error'
  262. })
  263. this.code = ''
  264. this.getCode()
  265. return
  266. }
  267. if (response.data) {
  268. this.tokenCode = response.data.token
  269. this.$toast({
  270. message: '验证码已经发送到您的手机,请注意查收',
  271. iconClass: 'el-icon-success'
  272. })
  273. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  274. let setTime = setInterval(() => {
  275. _this.tokenTime--
  276. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  277. if (this.tokenTime <= 0) {
  278. clearInterval(setTime)
  279. _this.tokenText = '获取验证码'
  280. _this.tokenTime = 60
  281. }
  282. }, 1000)
  283. }
  284. }).catch((err) => {
  285. this.$indicator.close()
  286. this.downToast(err.errMsg)
  287. })
  288. }
  289. },
  290. // 验证码发送请求
  291. getCheckCode () {
  292. if (this.tokenTime > 0 && this.tokenTime < 60) {
  293. this.downToast('请稍后再点击,我在倒计时')
  294. } else {
  295. this.loadCheckCode()
  296. }
  297. },
  298. // 表单提交
  299. submit () {
  300. if (this.state.vipName !== 'success') {
  301. this.codeVipName()
  302. } else if (this.state.password !== 'success') {
  303. this.codePwdBlur()
  304. } else if (this.state.confirm !== 'success') {
  305. this.codePassword()
  306. } else if (this.state.mobile !== 'success') {
  307. this.codeMobile()
  308. } else if (this.state.token !== 'success') {
  309. this.codeToken()
  310. } else if (this.checked === false) {
  311. this.downToast('您对阅读条款未做勾选')
  312. } else {
  313. this.$indicator.open('注册中...')
  314. let param = new FormData()
  315. param.append('vipName', this.vipName)
  316. param.append('password', this.password)
  317. param.append('mobile', this.mobile)
  318. // param.append('mobileArea', '')
  319. param.append('appId', this.$store.state.option.appId)
  320. param.append('code', this.token)
  321. param.append('token', this.tokenCode)
  322. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  323. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  324. let config = {
  325. header: {'Content-Type': 'multipart/form-data'}
  326. }
  327. this.$http.post('/sso/personal/register', param, config)
  328. .then(response => {
  329. this.$indicator.close()
  330. if (response.data.success) {
  331. if (response.data.content.data) {
  332. let param = response.data.content.data
  333. let a = ''
  334. for (let n in param) {
  335. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  336. }
  337. let params = a.substr(0, a.length - 1)
  338. this.isShowLoading = true
  339. if (response.data.content.currentUrl) {
  340. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  341. name: 'successCallback',
  342. timeout: 3000
  343. }, (err, data) => {
  344. if (err) {
  345. this.$toast({
  346. message: '注册成功,请返回应用登录',
  347. iconClass: 'el-icon-success'
  348. })
  349. this.isShowLoading = false
  350. throw err
  351. } else {
  352. this.loginOther(response, params)
  353. }
  354. })
  355. } else {
  356. this.loginOther(response, params, 3000)
  357. }
  358. } else {
  359. let userUU = response.data.content.data.userUU
  360. if (userUU) {
  361. window.location.href = `/overRegister/${userUU}`
  362. } else {
  363. window.location.href = `/`
  364. }
  365. }
  366. } else if (response.data.error) {
  367. this.$toast({
  368. message: response.data.errMsg,
  369. iconClass: 'el-icon-error'
  370. })
  371. }
  372. }).catch((err) => {
  373. this.$indicator.close()
  374. this.downToast(err.errMsg)
  375. })
  376. }
  377. },
  378. // 快速登录
  379. waySubmit () {
  380. if (this.state.mobile !== 'success') {
  381. this.codeMobile()
  382. } else if (this.state.token !== 'success') {
  383. this.codeToken()
  384. } else if (this.checked === false) {
  385. this.downToast('您对阅读条款未做勾选')
  386. } else {
  387. this.$indicator.open('注册中...')
  388. let param = new FormData()
  389. param.append('mobile', this.mobile)
  390. // param.append('mobileArea', '')
  391. param.append('appId', this.$store.state.option.appId)
  392. param.append('code', this.token)
  393. param.append('token', this.tokenCode)
  394. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  395. if (this.$route.query.baseUrl) {
  396. param.append('baseUrl', this.$route.query.baseUrl)
  397. }
  398. if (this.$route.query.returnURL) {
  399. param.append('returnUrl', this.$route.query.returnURL)
  400. }
  401. let config = {
  402. header: {'Content-Type': 'multipart/form-data'}
  403. }
  404. this.$http.post('/sso/personal/register/sms', param, config)
  405. .then(response => {
  406. this.$indicator.close()
  407. if (response.data.success) {
  408. this.$toast({
  409. message: '注册成功。登陆密码已发送至您的手机,请妥善保管!',
  410. iconClass: 'el-icon-success'
  411. })
  412. if (response.data.content.data) {
  413. let param = response.data.content.data
  414. let a = ''
  415. for (let n in param) {
  416. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  417. }
  418. let params = a.substr(0, a.length - 1)
  419. this.isShowLoading = true
  420. if (response.data.content.currentUrl) {
  421. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  422. name: 'successCallback',
  423. timeout: 3000
  424. }, (err, data) => {
  425. if (err) {
  426. this.$toast({
  427. message: '注册成功,请返回应用登录',
  428. iconClass: 'el-icon-success'
  429. })
  430. this.isShowLoading = false
  431. throw err
  432. } else {
  433. this.loginOther(response, params)
  434. }
  435. })
  436. } else {
  437. this.loginOther(response, params, 5000)
  438. }
  439. } else {
  440. let userUU = response.data.content.data.userUU
  441. if (userUU) {
  442. window.location.href = `/overRegister/${userUU}`
  443. } else {
  444. window.location.href = `/`
  445. }
  446. }
  447. } else if (response.data.error) {
  448. this.$toast({
  449. message: response.data.errMsg,
  450. iconClass: 'el-icon-error'
  451. })
  452. }
  453. }).catch((err) => {
  454. this.$indicator.close()
  455. this.downToast(err.errMsg)
  456. })
  457. }
  458. },
  459. // 提交注册流程
  460. allSubmit () {
  461. if (this.speediness) {
  462. this.waySubmit()
  463. } else {
  464. this.submit()
  465. }
  466. },
  467. getJsonp: function (url, timeout = 500) {
  468. return new Promise((resolve, reject) => {
  469. this.$jsonp(url, {
  470. name: 'successCallback',
  471. timeout: timeout
  472. }, function (err, data) {
  473. if (err) {
  474. reject(err)
  475. throw err
  476. } else {
  477. resolve(data)
  478. }
  479. })
  480. })
  481. },
  482. crossAfter (url, time) {
  483. try {
  484. if (time) {
  485. setTimeout(function () {
  486. window.location.href = url
  487. }, time)
  488. } else {
  489. window.location.href = url
  490. }
  491. } catch (err) {
  492. console.log(err)
  493. }
  494. },
  495. loginOther (response, a, timeout) {
  496. const crossAfter = this.crossAfter
  497. let promises = []
  498. for (let i in response.data.content.loginUrls) {
  499. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  500. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  501. }
  502. }
  503. let returnUrl = this.$route.query.returnURL ? decodeURIComponent(this.$route.query.returnURL) : 'https://www.usoftchina.com/'
  504. Promise.all(promises).then(() => {
  505. crossAfter(returnUrl, timeout)
  506. }).catch(() => {
  507. crossAfter(returnUrl, timeout)
  508. })
  509. }
  510. }
  511. }
  512. </script>
  513. <style type="text/scss" scoped lang="scss">
  514. .content-tab{
  515. width: 70%;
  516. margin: 0 auto;
  517. margin-top:.3rem;
  518. span{
  519. display:inline-block;
  520. width:49%;
  521. vertical-align:top;
  522. text-align: center;
  523. line-height:.6rem;
  524. height:.6rem;
  525. font-size:16px;
  526. border:1px solid #E7E7E7;
  527. background: #E7E7E7;
  528. color:#999;
  529. &.speed{
  530. color:#3F84F6;
  531. border:1px solid #3F84F6;
  532. background: #fff;
  533. }
  534. }
  535. }
  536. </style>