index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="register-page">
  3. <!-- 状态栏占位 -->
  4. <view class="status-bar"></view>
  5. <!-- 返回按钮 -->
  6. <view class="nav-back" @click="goBack">
  7. <text class="back-icon">&#xe685;</text>
  8. </view>
  9. <!-- 页面标题 -->
  10. <view class="header">
  11. <text class="title">注册账号</text>
  12. </view>
  13. <!-- 注册表单 -->
  14. <view class="form-section">
  15. <view class="form-item">
  16. <input type="text" v-model="form.phone" placeholder="请输入手机号" />
  17. </view>
  18. <view class="form-item code-item">
  19. <input type="text" v-model="form.code" placeholder="请输入验证码" />
  20. <button class="code-btn" :disabled="counting" @tap="getCode">
  21. {{counting ? `${counter}s后重新获取` : '获取验证码'}}
  22. </button>
  23. </view>
  24. <view class="form-item">
  25. <input type="password" v-model="form.password" placeholder="请设置密码" />
  26. </view>
  27. <button class="submit-btn" @tap="handleSubmit">注册</button>
  28. <view class="agreement">
  29. <checkbox :checked="isAgree" @tap="toggleAgreement"></checkbox>
  30. <text class="agreement-text">
  31. 注册即代表您已同意
  32. <text class="link" @tap="goToPrivacy">《隐私政策》</text>
  33. <text class="link" @tap="goToService">《服务协议》</text>
  34. </text>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. form: {
  44. phone: '',
  45. code: '',
  46. password: ''
  47. },
  48. isAgree: false,
  49. counting: false,
  50. counter: 60
  51. }
  52. },
  53. methods: {
  54. // 返回上一页
  55. goBack() {
  56. uni.navigateBack();
  57. },
  58. // 获取验证码
  59. getCode() {
  60. if (!this.form.phone) {
  61. uni.showToast({
  62. title: '请输入手机号',
  63. icon: 'none'
  64. });
  65. return;
  66. }
  67. // 开始倒计时
  68. this.counting = true;
  69. this.counter = 60;
  70. const timer = setInterval(() => {
  71. this.counter--;
  72. if (this.counter <= 0) {
  73. clearInterval(timer);
  74. this.counting = false;
  75. }
  76. }, 1000);
  77. // TODO: 调用发送验证码接口
  78. uni.showToast({
  79. title: '验证码已发送',
  80. icon: 'success'
  81. });
  82. },
  83. // 切换协议同意状态
  84. toggleAgreement() {
  85. this.isAgree = !this.isAgree;
  86. },
  87. // 提交注册
  88. handleSubmit() {
  89. if (!this.isAgree) {
  90. uni.showToast({
  91. title: '请先同意用户协议和隐私政策',
  92. icon: 'none'
  93. });
  94. return;
  95. }
  96. if (!this.form.phone || !this.form.code || !this.form.password) {
  97. uni.showToast({
  98. title: '请填写完整信息',
  99. icon: 'none'
  100. });
  101. return;
  102. }
  103. // TODO: 调用注册接口
  104. uni.showLoading({
  105. title: '注册中...'
  106. });
  107. setTimeout(() => {
  108. uni.hideLoading();
  109. uni.showToast({
  110. title: '注册成功',
  111. icon: 'success'
  112. });
  113. // 注册成功后跳转到登录页
  114. setTimeout(() => {
  115. uni.navigateTo({
  116. url: '/pages/user/login'
  117. });
  118. }, 1500);
  119. }, 1000);
  120. },
  121. // 跳转到隐私政策
  122. goToPrivacy() {
  123. uni.navigateTo({
  124. url: '/packageUser/pages/article/detail?type=privacy'
  125. });
  126. },
  127. // 跳转到服务协议
  128. goToService() {
  129. uni.navigateTo({
  130. url: '/packageUser/pages/article/detail?type=service'
  131. });
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .register-page {
  138. min-height: 100vh;
  139. background: #fff;
  140. padding-bottom: env(safe-area-inset-bottom);
  141. }
  142. .status-bar {
  143. height: var(--status-bar-height);
  144. width: 100%;
  145. }
  146. .nav-back {
  147. position: fixed;
  148. left: 30rpx;
  149. top: calc(var(--status-bar-height) + 20rpx);
  150. z-index: 100;
  151. .back-icon {
  152. font-family: "iconfont";
  153. font-size: 40rpx;
  154. color: #333;
  155. }
  156. }
  157. .header {
  158. padding: 60rpx 40rpx;
  159. .title {
  160. font-size: 48rpx;
  161. font-weight: bold;
  162. color: #333;
  163. }
  164. }
  165. .form-section {
  166. padding: 0 40rpx;
  167. .form-item {
  168. border-bottom: 1px solid #eee;
  169. padding: 20rpx 0;
  170. margin-bottom: 20rpx;
  171. input {
  172. font-size: 32rpx;
  173. color: #333;
  174. }
  175. }
  176. .code-item {
  177. display: flex;
  178. align-items: center;
  179. input {
  180. flex: 1;
  181. }
  182. .code-btn {
  183. width: 200rpx;
  184. height: 60rpx;
  185. line-height: 60rpx;
  186. font-size: 24rpx;
  187. color: #fff;
  188. background: #D93025;
  189. border-radius: 30rpx;
  190. margin-left: 20rpx;
  191. &[disabled] {
  192. background: #ccc;
  193. }
  194. }
  195. }
  196. .submit-btn {
  197. width: 100%;
  198. height: 88rpx;
  199. line-height: 88rpx;
  200. background: #D93025;
  201. color: #fff;
  202. font-size: 32rpx;
  203. border-radius: 44rpx;
  204. margin-top: 60rpx;
  205. }
  206. .agreement {
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. margin-top: 40rpx;
  211. checkbox {
  212. transform: scale(0.7);
  213. }
  214. .agreement-text {
  215. font-size: 24rpx;
  216. color: #666;
  217. margin-left: 8rpx;
  218. .link {
  219. color: #D93025;
  220. }
  221. }
  222. }
  223. }
  224. </style>