index.vue 14 KB

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