index.vue 20 KB

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