index.vue 21 KB

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