PersonalRegistration.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <div class="register">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>个人注册</h3>
  7. </div>
  8. <div>
  9. <el-form :model="item" :rules="rules2" ref="item" label-width="100px" class="demo-ruleForm">
  10. <el-form-item prop="vipName">
  11. <el-input type="text" v-model="item.vipName" auto-complete="off" placeholder="会员名"></el-input>
  12. </el-form-item>
  13. <el-form-item prop="password">
  14. <el-input type="password" v-model="item.password" auto-complete="off" placeholder="登录密码"></el-input>
  15. <div class="pwd sm" v-show="showMsgTip1">密码强度 <em></em><em></em><em></em><span>弱</span></div>
  16. <div class="pwd md" v-show="showMsgTip2">密码强度 <em></em><em></em><em></em><span>中</span></div>
  17. <div class="pwd lar" v-show="showMsgTip3">密码强度 <em></em><em></em><em></em><span>强</span></div>
  18. <div class="pwd low" v-show="showMsgTip4">密码强度 <em></em><em></em><em></em></div>
  19. </el-form-item>
  20. <el-form-item prop="confirm">
  21. <el-input type="password" v-model="item.confirm" auto-complete="off" placeholder="密码确认"></el-input>
  22. </el-form-item>
  23. <el-form-item prop="mobile">
  24. <el-input v-model="item.mobile"
  25. v-bind:class="{active: mobileRegister}"
  26. placeholder="手机号码"></el-input>
  27. <span class="tip" v-show="showMsgTip">单个手机号只能注册一个用户</span>
  28. <span class="tip tip-mobile" v-show="mobileRegister">该手机号已被注册</span>
  29. </el-form-item>
  30. <el-form-item prop="code">
  31. <el-input type="text" v-model="item.code"
  32. v-bind:class="{ active: this.codeErrorChecked }" auto-complete="off" class="msg" placeholder="短信验证码"></el-input>
  33. <el-button type="primary" class="code"
  34. v-show="sendPersonalCode"
  35. @click="getCheckCode"
  36. :disabled="this.checkMobile">获取验证码</el-button>
  37. <el-button type="primary" v-show="!sendPersonalCode" class="code code-send">已发送({{personal_time}}s)</el-button>
  38. <!--<span v-show="codeErrorChecked" class="codeError-tip">验证码输入错误</span>-->
  39. </el-form-item>
  40. <el-form-item>
  41. <!--<el-button type="primary" @click="submitForm('item')" :disabled="!this.item.vipName || !this.item.password || !this.item.confirm || !this.item.code || !this.checked" class="finish">完成注册</el-button>-->
  42. <a class="btn finish" @click="submit"
  43. :disabled="!this.vipNameChecked || !this.passwordChecked || !this.confirmChecked || !this.mobileChecked || !this.codeChecked || !this.checked">完成注册</a>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-checkbox name="type" v-model="checked" @click="checkboxChecked"></el-checkbox>
  47. <span class="agree">我已阅读并同意 <a href="/common/agreement">《优软云服务条款》</a></span>
  48. </el-form-item>
  49. </el-form>
  50. </div>
  51. </div>
  52. <div class="login">已有账号?<a href="/">立即登录</a></div>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. name: 'PersonalRegistration',
  59. data () {
  60. var validateName = (rule, value, callback) => {
  61. if (value === '') {
  62. callback(new Error('会员名不能为空'))
  63. this.vipNameChecked = false
  64. } else {
  65. if (this.item.vipName !== '') {
  66. if (value.length < 2 || value.length > 20) {
  67. callback(new Error('请填写合适的会员名称,2~20个字符'))
  68. this.vipNameChecked = false
  69. } else {
  70. this.vipNameChecked = true
  71. }
  72. }
  73. }
  74. callback()
  75. }
  76. var validatePass = (rule, value, callback) => {
  77. if (this.item.password !== '') {
  78. if (value.length <= 20 && value.length >= 8) {
  79. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  80. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  81. if (reg1.test(value)) {
  82. // callback(new Error('密码强度强'))
  83. this.showMsgTip3 = true
  84. this.showMsgTip2 = false
  85. this.showMsgTip1 = false
  86. this.showMsgTip4 = false
  87. this.passwordChecked = true
  88. } else if (reg2.test(value)) {
  89. // callback(new Error('密码强度中'))
  90. this.showMsgTip2 = true
  91. this.showMsgTip3 = false
  92. this.showMsgTip1 = false
  93. this.showMsgTip4 = false
  94. this.passwordChecked = true
  95. } else {
  96. this.showMsgTip1 = true
  97. this.showMsgTip3 = false
  98. this.showMsgTip2 = false
  99. this.showMsgTip4 = false
  100. this.passwordChecked = false
  101. }
  102. } else {
  103. this.showMsgTip3 = false
  104. this.showMsgTip2 = false
  105. this.showMsgTip1 = false
  106. this.showMsgTip4 = true
  107. this.passwordChecked = false
  108. }
  109. }
  110. callback()
  111. }
  112. var validatePassTip = (rule, value, callback) => {
  113. if (value === '') {
  114. callback(new Error('请输入密码'))
  115. this.passwordChecked = false
  116. } else {
  117. if (this.item.password !== '') {
  118. if (value.length <= 20 && value.length >= 8) {
  119. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  120. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  121. if (reg1.test(value)) {
  122. this.passwordChecked = true
  123. } else if (reg2.test(value)) {
  124. this.passwordChecked = true
  125. } else {
  126. callback(new Error('密码须为8-20字符的英文、数字混合'))
  127. this.passwordChecked = false
  128. }
  129. } else {
  130. callback(new Error('密码须为8-20字符的英文、数字混合'))
  131. this.passwordChecked = false
  132. }
  133. }
  134. callback()
  135. }
  136. }
  137. var validatePass2 = (rule, value, callback) => {
  138. if (value === '') {
  139. callback(new Error('请再次输入密码'))
  140. this.confirmChecked = false
  141. } else if (value !== this.item.password) {
  142. callback(new Error('两次输入密码不一致!'))
  143. this.confirmChecked = false
  144. } else {
  145. this.confirmChecked = true
  146. callback()
  147. }
  148. }
  149. var validateMobile = (rule, value, callback) => {
  150. if (value === '') {
  151. callback(new Error('请填写正确的手机号'))
  152. this.showMsgTip = false
  153. this.checkMobile = true
  154. this.mobileRegister = false
  155. this.mobileChecked = false
  156. } else {
  157. if (this.item.mobile !== '') {
  158. var reg = /^1([0-9]{10})$/
  159. if (!reg.test(value)) {
  160. callback(new Error('请填写正确的手机号'))
  161. this.showMsgTip = false
  162. this.checkMobile = true
  163. this.mobileRegister = false
  164. this.mobileChecked = false
  165. } else {
  166. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.item.mobile, mobileArea: ''}})
  167. .then(response => {
  168. if (response.data.hasRegister) {
  169. this.mobileRegister = true
  170. this.showMsgTip = false
  171. this.checkMobile = true
  172. this.mobileChecked = false
  173. } else {
  174. this.showMsgTip = false
  175. this.checkMobile = false
  176. this.mobileRegister = false
  177. this.mobileChecked = true
  178. }
  179. })
  180. }
  181. }
  182. callback()
  183. }
  184. }
  185. var validateCode = (rule, value, callback) => {
  186. if (value === '') {
  187. callback(new Error('请填写正确的验证码'))
  188. this.codeErrorChecked = false
  189. this.codeChecked = false
  190. } else {
  191. if (this.token !== '') {
  192. if (this.item.code !== '' && this.item.mobile !== '') {
  193. let param = new FormData()
  194. param.append('mobile', this.item.mobile)
  195. param.append('code', this.item.code)
  196. param.append('token', this.token)
  197. let config = {
  198. headers: {'Content-Type': 'multipart/form-data'}
  199. }
  200. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  201. .then(response => {
  202. if (response.data.success) {
  203. this.codeChecked = true
  204. this.codeErrorChecked = false
  205. } else {
  206. this.codeErrorChecked = true
  207. this.codeChecked = false
  208. // callback(new Error('验证码输入错误'))
  209. return Promise.reject(response.data)
  210. }
  211. }).catch(err => {
  212. this.$message.error(err.errMsg)
  213. })
  214. }
  215. } else {}
  216. callback()
  217. }
  218. }
  219. return {
  220. item: {
  221. vipName: '',
  222. password: '',
  223. confirm: '',
  224. mobile: '',
  225. code: ''
  226. },
  227. vipNameChecked: false,
  228. passwordChecked: false,
  229. confirmChecked: false,
  230. mobileChecked: false,
  231. codeChecked: false,
  232. codeErrorChecked: false,
  233. showMsgTip: true,
  234. showMsgTip1: false,
  235. showMsgTip2: false,
  236. showMsgTip3: false,
  237. showMsgTip4: false,
  238. checkMobile: true,
  239. checked: true,
  240. token: '',
  241. mobileRegister: false,
  242. sendPersonalCode: true,
  243. personal_time: 0,
  244. rules2: {
  245. vipName: [
  246. { validator: validateName, trigger: 'blur' }
  247. ],
  248. password: [
  249. { validator: validatePassTip, trigger: 'blur' },
  250. { validator: validatePass, trigger: 'change' }
  251. ],
  252. confirm: [
  253. { required: true, validator: validatePass2, trigger: 'blur' }
  254. ],
  255. mobile: [
  256. { validator: validateMobile, trigger: 'blur' }
  257. ],
  258. code: [
  259. { validator: validateCode, trigger: 'blur' }
  260. ]
  261. }
  262. }
  263. },
  264. methods: {
  265. // 我同意是否被选中
  266. checkboxChecked () {
  267. this.checked = !this.checked
  268. },
  269. // 表单提交
  270. submit () {
  271. if (this.vipNameChecked && this.passwordChecked && this.confirmChecked && this.mobileChecked && this.codeChecked && this.checked) {
  272. var url = window.location.search
  273. var request = {}
  274. if (url.indexOf('?' !== -1)) {
  275. var str = url.substr(1)
  276. var strs = str.split('&')
  277. for (var i = 0; i < strs.length; i++) {
  278. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  279. }
  280. }
  281. var appId = request['appId'] || ''
  282. let param = new FormData()
  283. param.append('vipName', this.item.vipName)
  284. param.append('password', this.item.password)
  285. param.append('mobile', this.item.mobile)
  286. // param.append('mobileArea', '')
  287. param.append('appId', appId)
  288. param.append('code', this.item.code)
  289. param.append('token', this.token)
  290. let config = {
  291. headers: {'Content-Type': 'multipart/form-data'}
  292. }
  293. this.$http.post('/sso/personal/register', param, config)
  294. .then(response => {
  295. if (response.data.success) {
  296. // window.loaction.href = '/'
  297. } else {
  298. return Promise.reject(response.data)
  299. }
  300. }).catch(err => {
  301. this.$message.error(err.errMsg)
  302. })
  303. }
  304. },
  305. // 获取验证码
  306. // async getCode () {
  307. // let { data } = await this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  308. // this.token = data.token
  309. // },
  310. getCheckCode () {
  311. // this.getCode()
  312. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  313. .then(response => {
  314. this.token = response.data.token
  315. if (this.token !== '') {
  316. this.$message({
  317. message: '验证码已经发送到您的手机,请注意查收',
  318. type: 'success'
  319. })
  320. this.sendPersonalCode = false
  321. this.personal_time = 60
  322. var personalTime = setInterval(() => {
  323. this.personal_time--
  324. if (this.personal_time <= 0) {
  325. this.sendPersonalCode = true
  326. clearInterval(personalTime)
  327. }
  328. }, 1000)
  329. } else {}
  330. }).catch(err => {
  331. this.$message.error(err.errMsg)
  332. })
  333. }
  334. }
  335. }
  336. </script>
  337. <style lang="scss" scoped>
  338. .register {
  339. padding-bottom: 145px;
  340. margin: 0 auto;
  341. width: 100%;
  342. background: #eee;
  343. .container{
  344. padding-top: 50px;
  345. margin: 0 auto;
  346. width: 980px;
  347. text-align: center;
  348. .content{
  349. padding: 0 50px;
  350. margin: 50px auto 0;
  351. width: 100%;
  352. text-align: center;
  353. background: #fff;
  354. .content-top{
  355. height: 80px;
  356. line-height: 80px;
  357. border-bottom: 1px solid #dcdcdc;
  358. h3{
  359. font-family: 'SimHei';
  360. font-size: 24px;
  361. color: #000;
  362. }
  363. }
  364. form {
  365. padding-bottom: 44px;
  366. margin-top: 35px;
  367. input{
  368. padding: 0 0 0 18px;
  369. width: 360px;
  370. height: 44px;
  371. line-height: 44px;
  372. font-size: 14px;
  373. color: #000;
  374. border-radius: 0;
  375. }
  376. span.help{
  377. position: absolute;
  378. right: -230px;
  379. top:0;
  380. font-size: 12px;
  381. color: #f00;
  382. }
  383. i.fa{
  384. position: absolute;
  385. top: 10px;
  386. right: 18px;
  387. font-size: 24px;
  388. color: #a0a0a0;
  389. cursor: pointer;
  390. }
  391. .pwd {
  392. margin: 6px 0 -15px 0;
  393. text-align: left;
  394. font-size: 13px;
  395. em{
  396. display: inline-block;
  397. margin: 0 8px 2px 0;
  398. width: 24px;
  399. height: 6px;
  400. &:first-child{
  401. margin-left: 10px;
  402. }
  403. }
  404. span{
  405. margin-left: 10px;
  406. font-size: 13px;
  407. }
  408. }
  409. .pwd.sm{
  410. color: #8c8c8c;
  411. em {
  412. background: #bfbfbf;
  413. &:first-child{
  414. background: #ff4e00;
  415. }
  416. }
  417. span{
  418. color: #ff4e00;
  419. }
  420. }
  421. .pwd.md{
  422. color: #8c8c8c;
  423. em {
  424. background: #22ac38;
  425. &:nth-child(3){
  426. background: #bfbfbf;
  427. }
  428. }
  429. span{
  430. color: #22ac38;
  431. }
  432. }
  433. .pwd.lar{
  434. color: #8c8c8c;
  435. em {
  436. background: #00a0e9;
  437. }
  438. span{
  439. color: #00a0e9;
  440. }
  441. }
  442. .pwd.low{
  443. color: #8c8c8c;
  444. em{
  445. background: #bfbfbf;
  446. }
  447. }
  448. span.tip{
  449. position: absolute;
  450. top: 3px;
  451. right: -190px;
  452. font-size: 13px;
  453. color: #8c8c8c;
  454. }
  455. span.tip.tip-mobile{
  456. top: 3px;
  457. right: -118px;
  458. color: #ff4949;
  459. font-size: 12px;
  460. }
  461. span.codeError-tip{
  462. position: absolute;
  463. top: 3px;
  464. right: -105px;
  465. color: #ff4949;
  466. font-size: 12px;
  467. }
  468. input.msg{
  469. float: left;
  470. width: 210px;
  471. }
  472. button.msg{
  473. float: right;
  474. width: 130px;
  475. height: 44px;
  476. font-size: 14px;
  477. color: #5a5a5a;
  478. background: #f4f4f4;
  479. border: 1px solid #dcdcdc;
  480. cursor: pointer;
  481. &:disabled{
  482. cursor: not-allowed ;
  483. opacity: .7;
  484. }
  485. }
  486. span.msg.send{
  487. float: right;
  488. width: 130px;
  489. height: 44px;
  490. line-height: 44px;
  491. font-size: 14px;
  492. background: #d2d2d2;
  493. color: #fff;
  494. border: 1px solid #dcdcdc;
  495. }
  496. input[type='checkbox']{
  497. margin: 0 14px 0 55px;
  498. float: left;
  499. width: 16px;
  500. height: 16px;
  501. }
  502. span.agree{
  503. float: left;
  504. margin: 1px 0 0 10px;
  505. font-size: 14px;
  506. color: #8b8b8b;
  507. a{
  508. color: #0076ad;
  509. }
  510. }
  511. .form-group.agree{
  512. margin: 20px auto 0 !important;
  513. }
  514. .submitBtn {
  515. display: inline-block;
  516. margin-top: 34px;
  517. width: 360px;
  518. height: 44px;
  519. line-height: 44px;
  520. font-size: 16px;
  521. color: #fff;
  522. background: #0076AD;
  523. border-radius: 3px;
  524. border: none;
  525. &:disabled{
  526. cursor: not-allowed ;
  527. opacity: .7;
  528. }
  529. }
  530. }
  531. }
  532. .login{
  533. margin-top: 20px;
  534. font-size: 14px;
  535. color: #8c8c8c;
  536. a{
  537. font-size: 14px;
  538. color: #0076ad;
  539. }
  540. }
  541. }
  542. }
  543. </style>