register.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!-- 短信注册 -->
  2. <template>
  3. <view>
  4. <!-- 表单项 -->
  5. <uni-forms ref="smsLoginRef" v-model="state.model" :rules="state.rules" validateTrigger="bind" labelWidth="140"
  6. labelAlign="center" class="loginUniForm">
  7. <uni-forms-item name="username" label="用户名" class="loginUniFormItem" :error-message="state.usernameErrorMsg">
  8. <uni-easyinput placeholder="请输入用户名" v-model="state.model.username" :inputBorder="false" :clearable="false" @blur="verifyUsername">
  9. <template v-slot:right>
  10. <view v-if="!state.verifyUsername" class="icon"><image style :src="sheep.$url.static('/static/images/shibai.png')" /></view>
  11. <view v-else class="icon"> <image :src="sheep.$url.static('/static/images/chenggong.png')" /></view>
  12. </template>
  13. </uni-easyinput>
  14. </uni-forms-item>
  15. <uni-forms-item name="password" label="密码" class="loginUniFormItem">
  16. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.password" :inputBorder="false">
  17. </uni-easyinput>
  18. </uni-forms-item>
  19. <uni-forms-item name="mobile" label="手机号" class="mobile loginUniFormItem ss-p-t-10" :error-message="state.mobileErrorMsg">
  20. <phoneInternationalInput :verify-username="state.verifyUsername" @input="mobileInput"/>
  21. </uni-forms-item>
  22. <uni-forms-item name="code" label="验证码" class="loginUniFormItem">
  23. <uni-easyinput placeholder="请输入验证码" v-model="state.model.code" :inputBorder="false" type="number"
  24. maxlength="4">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. </uni-forms>
  28. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  29. <!-- <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  30. 忘记密码
  31. </button> -->
  32. <button class="ss-reset-button login-btn-start" @tap="registerSubmit"> 注册 </button>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import {
  38. ref,
  39. reactive,
  40. unref,
  41. computed
  42. } from 'vue';
  43. import sheep from '@/sheep';
  44. import {
  45. code,
  46. mobile,
  47. username,
  48. password
  49. } from '@/sheep/validate/form';
  50. import {
  51. showAuthModal,
  52. closeAuthModal,
  53. getSmsCode,
  54. getSmsTimer
  55. } from '@/sheep/hooks/useModal';
  56. import AuthUtil from '@/sheep/api/member/auth';
  57. import phoneInternationalInput from './phone-international-input.vue';
  58. const mobileInput = (mobile,mobileError)=>{
  59. // console.log(mobile,mobileError);
  60. state.model.mobile = mobile;
  61. state.mobileErrorMsg = mobileError;
  62. }
  63. // 账号注册数据
  64. const state = reactive({
  65. verifyUsername: false , // 校验用户名是否可用
  66. codeText: '获取验证码',
  67. mobileErrorMsg:'',
  68. usernameErrorMsg:'',
  69. model: {
  70. username:'', // 用户名
  71. password:'', // 密码
  72. mobile: '', // 手机号
  73. code: '', // 验证码
  74. },
  75. rules: {
  76. username,
  77. password,
  78. code,
  79. },
  80. });
  81. const smsLoginRef = ref(null);
  82. const emits = defineEmits(['onConfirm']);
  83. const props = defineProps({
  84. agreeStatus: {
  85. type: Boolean,
  86. default: false,
  87. },
  88. });
  89. let lastUsername = ref('')
  90. async function verifyUsername(e){
  91. const username = e.detail.value;
  92. if(username == '' || username == lastUsername.value){
  93. // 为空或者没改东西,不调校验
  94. return false;
  95. }
  96. lastUsername.value = username
  97. // 提交数据
  98. const { data } = await AuthUtil.verifyUsername(username);
  99. // false就是已经有这个用户名,不可以用。true是没有,可以改
  100. if(data){
  101. state.usernameErrorMsg = ''
  102. state.verifyUsername = data
  103. }else {
  104. state.usernameErrorMsg = '已存在用户名!'
  105. state.verifyUsername = data
  106. }
  107. }
  108. // 注册
  109. async function registerSubmit() {
  110. console.log(state.model)
  111. // 参数校验
  112. const validate = await unref(smsLoginRef)
  113. .validate()
  114. .catch((error) => {
  115. console.log('error: ', error);
  116. });
  117. if (!validate) {
  118. return;
  119. }
  120. if (!props.agreeStatus) {
  121. emits('onConfirm', true)
  122. //onConfirm(true)
  123. sheep.$helper.toast('请勾选同意');
  124. return;
  125. }
  126. // 看缓存中有没有linkId 如果有的话 加入model传给后台 即为绑定
  127. const linkId = uni.getStorageSync("linkId")
  128. if (linkId) {
  129. state.model.linkId = linkId
  130. }else{
  131. sheep.$helper.toast('您只能通过分享注册');
  132. return false;
  133. }
  134. // 提交数据
  135. const {
  136. code
  137. } = await AuthUtil.register(state.model);
  138. if (code === 0) {
  139. closeAuthModal();
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. @import '../index.scss';
  145. .code-btn-start {
  146. color: #55b774;
  147. border: 1px solid #55b774;
  148. }
  149. .disabled{
  150. border: 1px solid #f7f7f7;
  151. }
  152. .icon{
  153. display:flex;
  154. align-items: center;
  155. margin-right:7rpx
  156. }
  157. .icon image{
  158. width:35rpx;
  159. height:35rpx;
  160. }
  161. .agreement-box {
  162. margin: 20rpx 0;
  163. }
  164. .login-btn-start {
  165. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  166. width: 100%;
  167. height: 80rpx;
  168. font-size: 32rpx;
  169. }
  170. .loginUniForm {
  171. border: 1rpx solid #d6d6d6;
  172. padding: 10rpx 15rpx;
  173. border-radius: 10rpx;
  174. }
  175. .loginUniFormItem {
  176. border-bottom: 1rpx solid #d6d6d6;
  177. padding-bottom: 10rpx;
  178. }
  179. .loginUniFormItem:last-child {
  180. border-bottom: none;
  181. padding-top: 10rpx;
  182. }
  183. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  184. padding-bottom: 0;
  185. }
  186. ::v-deep .loginUniFormItem .uni-error-message {
  187. bottom: -20rpx;
  188. }
  189. </style>