reg.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="login-form">
  3. <u-form>
  4. <view class="form-header">
  5. <text>{{lang.register}}</text>
  6. </view>
  7. <u-form-item :label-position="labelPosition" :label="lang.account" label-width="120">
  8. <u-input :password-icon="true" v-model="username" :border="border" type="text"
  9. :placeholder="lang.input_account">
  10. </u-input>
  11. </u-form-item>
  12. <u-form-item :label-position="labelPosition" :label="lang.pwd" label-width="120">
  13. <u-input :border="border" v-model="upwd" type="password" :placeholder="lang.password"></u-input>
  14. </u-form-item>
  15. <u-form-item :label-position="labelPosition" :label="lang.pwd" label-width="120">
  16. <u-input :border="border" v-model="upwd2" type="password" :placeholder="lang.input_confirm_password">
  17. </u-input>
  18. </u-form-item>
  19. <u-form-item :label-position="labelPosition" :label="lang.verify_code" prop="code" label-width="120">
  20. <u-input :border="border" v-model="code" :placeholder="lang.verify_code" type="text"></u-input>
  21. <u-toast ref="uToast"></u-toast>
  22. <u-verification-code :keep-running="true" :seconds="seconds" @end="end" @start="start" ref="uCode"
  23. @change="codeChange" :startText="startText" :changeText="changeText" :endText="endText">
  24. </u-verification-code>
  25. <u-button slot="right" class="send-code" type="success" size="mini" @click="getCode">{{tips}}</u-button>
  26. </u-form-item>
  27. <!-- <u-form-item :label-position="labelPosition" right-icon="scan" label="邀请码" label-width="120">
  28. <u-input :border="border" v-model="oid" type="text" placeholder="请输入邀请码"></u-input>
  29. </u-form-item> -->
  30. <view class="form-btn" @click="reg()">
  31. {{lang.go_reg}}
  32. </view>
  33. <view class="agreement">
  34. <u-checkbox v-model="check" @change="checkboxChange"></u-checkbox>
  35. <view class="agreement-text">
  36. {{lang.protocl}}<text @click="gotoPage('/pages/agreement/register')"
  37. class="agree">{{lang.service_agree}}</text>
  38. </view>
  39. </view>
  40. </u-form>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. check: false,
  48. labelPosition: 'left',
  49. border: false,
  50. codeTips: '',
  51. tips: '',
  52. seconds: 60,
  53. refCode: null,
  54. startText: '获取',
  55. changeText: 'X秒获取',
  56. endText: '重新获取',
  57. username: '',
  58. upwd: '',
  59. upwd2: '',
  60. code: '',
  61. oid: ''
  62. };
  63. },
  64. methods: {
  65. // 获取验证码
  66. codeChange(text) {
  67. this.tips = text;
  68. },
  69. checkboxChange() {
  70. },
  71. start() {
  72. console.log('开始')
  73. },
  74. end() {
  75. console.log('结束')
  76. },
  77. // 发送验证码
  78. getCode() {
  79. if (this.$refs.uCode.canGetCode) {
  80. // 模拟向后端请求验证码
  81. uni.showLoading({
  82. title: '正在获取验证码'
  83. })
  84. setTimeout(() => {
  85. uni.hideLoading();
  86. // 通知验证码组件内部开始倒计时
  87. this.$refs.uCode.start();
  88. this.$request.send('/api/sendmsm', {
  89. username: this.username,
  90. }, 'POST').then(res => {
  91. // 打印调用成功回调
  92. console.log(res)
  93. //提示是否发送成功
  94. this.$u.toast(res.msg);
  95. })
  96. }, 2000);
  97. } else {
  98. this.$u.toast('请不要频繁发送');
  99. }
  100. },
  101. secondsChange(index) {
  102. this.seconds = index == 0 ? 60 : index == 1 ? 10 : 5;
  103. },
  104. textChange(index) {
  105. if (index == 0) {
  106. this.startText = '点一下获取',
  107. this.changeText = '重新获取Xs',
  108. this.endText = '再次获取'
  109. } else {
  110. this.startText = '获取',
  111. this.changeText = 'X秒获取',
  112. this.endText = '重新获取'
  113. }
  114. },
  115. // 注册账户
  116. reg() {
  117. var _this = this;
  118. if (_this.username == '') {
  119. this.$u.toast('请填写邮箱或手机号');
  120. return false;
  121. }
  122. if (_this.upwd == '') {
  123. this.$u.toast('请填写登录密码');
  124. return false;
  125. }
  126. if (_this.upwd1 == '') {
  127. this.$u.toast('请确认登录密码');
  128. return false;
  129. }
  130. if (_this.code == '') {
  131. this.$u.toast('请填写验证码');
  132. return false;
  133. }
  134. if (_this.upwd != _this.upwd2) {
  135. this.$u.toast('确认密码不正确');
  136. return false;
  137. }
  138. if (!_this.check) {
  139. this.$u.toast('请先勾选平台服务条款');
  140. return false;
  141. }
  142. // 调用注册
  143. this.$request.send('/api/register', {
  144. username: _this.username,
  145. password: _this.upwd,
  146. oid: _this.oid,
  147. code: _this.code,
  148. }, 'POST').then(res => {
  149. // 打印调用成功回调
  150. if (res.success == true) {
  151. this.$u.toast(res.msg);
  152. setTimeout(function() {
  153. uni.reLaunch({
  154. url: '/pages/login/login'
  155. });
  156. }, 2000)
  157. } else {
  158. this.$u.toast(res.msg);
  159. }
  160. })
  161. },
  162. //返回登录页面
  163. back() {
  164. uni.reLaunch({
  165. url: '/pages/login/login'
  166. });
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss">
  172. .login-form {
  173. .u-form {
  174. padding: 100upx;
  175. .form-header {
  176. color: #FFFFFF;
  177. font-size: 50upx;
  178. font-weight: bold;
  179. margin-bottom: 120upx;
  180. text-align: center;
  181. text {
  182. padding: 10upx 30upx;
  183. }
  184. }
  185. .u-form-item {
  186. background-color: #FFFFFF;
  187. padding: 10upx 50upx;
  188. border-radius: 50upx;
  189. border-width: 0;
  190. margin-bottom: 40upx;
  191. }
  192. .u-border-bottom::after {
  193. border-width: 0;
  194. }
  195. .u-form-item--left__content__label {
  196. color: #060518;
  197. }
  198. .send-code {
  199. background: linear-gradient(90deg, #F0D8A6 0%, #EBC181 100%);
  200. color: #060518;
  201. border-radius: 30upx;
  202. padding: 10upx 30upx;
  203. }
  204. .form-btn {
  205. background: linear-gradient(90deg, #F0D8A6 0%, #EBC181 100%);
  206. text-align: center;
  207. padding: 25upx 30upx;
  208. border-radius: 50upx;
  209. margin-top: 60rpx;
  210. }
  211. .agreement {
  212. display: flex;
  213. align-items: center;
  214. margin: 40rpx 20rpx;
  215. .agreement-text {
  216. padding-left: 8rpx;
  217. color: $u-tips-color;
  218. }
  219. .agree {
  220. color: #EBC181;
  221. }
  222. }
  223. .u-checkbox__icon-wrap--checked {
  224. background-color: #EECF98;
  225. border-color: #EECF98;
  226. }
  227. .u-checkbox {
  228. display: inline-block;
  229. }
  230. }
  231. }
  232. </style>