index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="f-form">
  8. <div class="page-part">
  9. <mt-field :state="state.vipName"
  10. placeholder="会员名"
  11. :attr="{ maxlength: 20 }"
  12. v-model="vipName"></mt-field>
  13. </div>
  14. <div class="page-part">
  15. <mt-field :state="state.password"
  16. placeholder="密码"
  17. :attr="{ maxlength: 20 }"
  18. v-model="password"
  19. @input.native="codePwd"
  20. type="password"></mt-field>
  21. <template v-if="password">
  22. <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>
  23. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  24. </template>
  25. </div>
  26. <div class="page-part">
  27. <mt-field :state="state.confirm"
  28. placeholder="确认密码"
  29. v-model="confirm"
  30. type="password"></mt-field>
  31. </div>
  32. <div class="page-part">
  33. <mt-field :state="state.mobile"
  34. placeholder="手机号码"
  35. v-model="mobile"
  36. type="tel"></mt-field>
  37. </div>
  38. <div class="page-part">
  39. <mt-field placeholder="验证码" v-model="code">
  40. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  41. </mt-field>
  42. </div>
  43. <div class="page-part">
  44. <mt-field :state="state.token"
  45. placeholder="短信验证码"
  46. v-model="token"
  47. auto-complete="off">
  48. <span class="token" v-text="tokenText" @click="getCheckCode">获取验证码</span>
  49. </mt-field>
  50. </div>
  51. </div>
  52. <div class="form-btn">
  53. <div class="page-part">
  54. <el-checkbox v-model="checked">我已阅读并同意 <a class="rgba" href="/common/agreement">《优软云服务条款》</a></el-checkbox>
  55. </div>
  56. <mt-button type="primary" size="large" @click.native="submit">完成注册</mt-button>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. name: 'registerPerson',
  63. data () {
  64. return {
  65. imgSrc: '',
  66. code: '',
  67. step: 1,
  68. state: {
  69. vipName: 'error',
  70. password: 'error',
  71. confirm: 'error',
  72. mobile: 'error',
  73. token: 'error',
  74. code: 'error'
  75. },
  76. vipName: '',
  77. password: '',
  78. confirm: '',
  79. mobile: '',
  80. token: '',
  81. tokenCode: '',
  82. tokenText: '获取验证码',
  83. tokenTime: '60',
  84. checked: true
  85. }
  86. },
  87. mounted () {
  88. this.$nextTick(() => {
  89. this.getCode()
  90. })
  91. },
  92. watch: {
  93. 'token': {
  94. handler (newVal) {
  95. if (newVal.length === 6) {
  96. this.codeToken()
  97. }
  98. },
  99. immediate: true
  100. }
  101. },
  102. methods: {
  103. getCode () {
  104. this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
  105. },
  106. // 注册
  107. goRegister () {
  108. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  109. },
  110. // 验证弹窗
  111. downToast (type) {
  112. this.$toast({
  113. message: type,
  114. iconClass: 'el-icon-warning'
  115. })
  116. },
  117. // 验证会员名
  118. codeVipName () {
  119. let count = this.vipName.length
  120. if (count === 0) {
  121. this.downToast('会员名不能为空')
  122. this.state.vipName = 'error'
  123. } else if (count < 2 || count > 20) {
  124. this.downToast('请填写合适的会员名称,2~20个字符')
  125. this.state.vipName = 'warning'
  126. } else {
  127. this.state.vipName = 'success'
  128. }
  129. },
  130. // 验证密码强度
  131. codePwd () {
  132. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  133. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  134. if (reg1.test(this.password)) {
  135. this.step = '强'
  136. } else if (reg2.test(this.password)) {
  137. this.step = '中'
  138. } else {
  139. this.step = '弱'
  140. }
  141. },
  142. // 验证密码格式
  143. codePwdBlur () {
  144. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  145. if (!this.password) {
  146. this.downToast('请输入密码')
  147. this.state.password = 'error'
  148. } else if (!reg2.test(this.password)) {
  149. this.downToast('密码须为8-20字符的英文、数字混合')
  150. this.state.password = 'warning'
  151. } else {
  152. this.state.password = 'success'
  153. if (this.confirm) {
  154. this.codePassword()
  155. }
  156. }
  157. },
  158. // 验证密码的确认信息
  159. codePassword () {
  160. if (!this.confirm) {
  161. this.downToast('请再次输入密码')
  162. this.state.confirm = 'error'
  163. } else if (this.confirm !== this.password) {
  164. this.downToast('两次输入密码不一致!')
  165. this.state.confirm = 'warning'
  166. } else {
  167. this.state.confirm = 'success'
  168. }
  169. },
  170. // 验证手机号
  171. codeMobile () {
  172. let reg = /^1([0-9]{10})$/
  173. if (!this.mobile) {
  174. this.downToast('请输入手机号')
  175. this.state.mobile = 'error'
  176. } else if (!reg.test(this.mobile)) {
  177. this.downToast('请填写正确的手机号码')
  178. this.state.mobile = 'warning'
  179. } else {
  180. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.mobile, mobileArea: ''}})
  181. .then(response => {
  182. if (response.data.hasRegister) {
  183. this.downToast('该手机号已被注册,可直接登录')
  184. this.state.mobile = 'warning'
  185. } else {
  186. this.state.mobile = 'success'
  187. }
  188. }).catch((err) => {
  189. this.downToast(err.errMsg)
  190. })
  191. }
  192. },
  193. // 验证-验证码信息
  194. codeToken () {
  195. if (!this.token) {
  196. this.downToast('请先填写验证码')
  197. this.state.token = 'error'
  198. } else {
  199. if (!this.mobile) {
  200. this.downToast('请先填写正确的手机号码')
  201. this.state.token = 'warning'
  202. } else {
  203. if (this.tokenCode) {
  204. let param = new FormData()
  205. param.append('mobile', this.mobile)
  206. param.append('token', this.tokenCode)
  207. param.append('code', this.token)
  208. let config = {
  209. headers: {'Content-Type': 'multipart/form-data'}
  210. }
  211. this.$http.post('/sso/personal/register/checkCode', param, config)
  212. .then(response => {
  213. if (response.data.success) {
  214. this.state.token = 'success'
  215. } else {
  216. this.$toast({
  217. message: response.data.errMsg,
  218. iconClass: 'el-icon-error'
  219. })
  220. }
  221. }).catch((err) => {
  222. this.downToast(err.errMsg)
  223. })
  224. } else {
  225. this.downToast('请点击先获取验证码信息')
  226. this.state.token = 'warning'
  227. }
  228. }
  229. }
  230. },
  231. // 获取验证码
  232. loadCheckCode () {
  233. if (this.state.mobile !== 'success') {
  234. this.codeMobile()
  235. } else if (this.code === '') {
  236. this.downToast('请输入验证码后获取!')
  237. } else {
  238. this.$indicator.open('获取中...')
  239. let _this = this
  240. this.$http.get('/sso/personal/register/checkCode', {params: {code: this.code, mobile: this.mobile, timestamp: new Date().getTime() + ''}})
  241. .then(response => {
  242. this.$indicator.close()
  243. if (response.data.errMsg) {
  244. this.$toast({
  245. message: response.data.errMsg,
  246. iconClass: 'el-icon-error'
  247. })
  248. this.code = ''
  249. this.getCode()
  250. return
  251. }
  252. if (response.data) {
  253. this.tokenCode = response.data.token
  254. this.$toast({
  255. message: '验证码已经发送到您的手机,请注意查收',
  256. iconClass: 'el-icon-success'
  257. })
  258. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  259. let setTime = setInterval(() => {
  260. _this.tokenTime--
  261. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  262. if (this.tokenTime <= 0) {
  263. clearInterval(setTime)
  264. _this.tokenText = '获取验证码'
  265. _this.tokenTime = 60
  266. }
  267. }, 1000)
  268. }
  269. }).catch((err) => {
  270. this.$indicator.close()
  271. this.downToast(err.errMsg)
  272. })
  273. }
  274. },
  275. // 验证码发送请求
  276. getCheckCode () {
  277. if (this.tokenTime > 0 && this.tokenTime < 60) {
  278. this.downToast('请稍后再点击,我在倒计时')
  279. } else {
  280. this.loadCheckCode()
  281. }
  282. },
  283. // 表单提交
  284. submit () {
  285. if (this.state.vipName !== 'success') {
  286. this.codeVipName()
  287. } else if (this.state.password !== 'success') {
  288. this.codePwdBlur()
  289. } else if (this.state.confirm !== 'success') {
  290. this.codePassword()
  291. } else if (this.state.mobile !== 'success') {
  292. this.codeMobile()
  293. } else if (this.state.token !== 'success') {
  294. this.codeToken()
  295. } else if (this.checked === false) {
  296. this.downToast('您对阅读条款未做勾选')
  297. } else {
  298. this.$indicator.open('注册中...')
  299. let param = new FormData()
  300. param.append('vipName', this.vipName)
  301. param.append('password', this.password)
  302. param.append('mobile', this.mobile)
  303. // param.append('mobileArea', '')
  304. param.append('appId', this.$store.state.option.appId)
  305. param.append('code', this.token)
  306. param.append('token', this.tokenCode)
  307. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  308. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  309. let config = {
  310. header: {'Content-Type': 'multipart/form-data'}
  311. }
  312. this.$http.post('/sso/personal/register', param, config)
  313. .then(response => {
  314. this.$indicator.close()
  315. if (response.data.success) {
  316. if (response.data.content.data) {
  317. let param = response.data.content.data
  318. let a = ''
  319. for (let n in param) {
  320. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  321. }
  322. let params = a.substr(0, a.length - 1)
  323. this.isShowLoading = true
  324. if (response.data.content.currentUrl) {
  325. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  326. name: 'successCallback',
  327. timeout: 3000
  328. }, (err, data) => {
  329. if (err) {
  330. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  331. this.isShowLoading = false
  332. throw err
  333. } else {
  334. this.loginOther(response, params)
  335. }
  336. })
  337. } else {
  338. this.loginOther(response, params, 3000)
  339. }
  340. } else {
  341. let userUU = response.data.content.userUU
  342. window.location.href = `/overRegister/${userUU}`
  343. }
  344. } else if (response.data.error) {
  345. this.$toast({
  346. message: response.data.errMsg,
  347. iconClass: 'el-icon-error'
  348. })
  349. }
  350. }).catch((err) => {
  351. this.$indicator.close()
  352. this.downToast(err.errMsg)
  353. })
  354. }
  355. },
  356. getJsonp: function (url, timeout = 500) {
  357. return new Promise((resolve, reject) => {
  358. this.$jsonp(url, {
  359. name: 'successCallback',
  360. timeout: timeout
  361. }, function (err, data) {
  362. if (err) {
  363. reject(err)
  364. throw err
  365. } else {
  366. resolve(data)
  367. }
  368. })
  369. })
  370. },
  371. crossAfter (url) {
  372. try {
  373. window.location.href = url
  374. } catch (err) {
  375. console.log(err)
  376. }
  377. },
  378. loginOther (response, a, timeout) {
  379. const crossAfter = this.crossAfter
  380. let promises = []
  381. for (let i in response.data.content.loginUrls) {
  382. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  383. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  384. }
  385. }
  386. let returnUrl = decodeURIComponent(this.$route.query.returnURL)
  387. Promise.all(promises).then(() => {
  388. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  389. }).catch(() => {
  390. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  391. })
  392. }
  393. }
  394. }
  395. </script>