register.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view>
  3. <u-navbar title="" autoBack placeholder></u-navbar>
  4. <view class="card_login">
  5. <view class="card_head_logo">
  6. <image class="mine_image" src="../static/logo.png" mode=""></image>
  7. <view class="welcome_title">欢迎注册宝智达气瓶</view>
  8. </view>
  9. <u-form labelPosition="left" :model="formList" :rules="rules" ref="uForm">
  10. <u-form-item label="类型" prop="type" labelWidth="80" borderBottom ref="item1">
  11. <u-radio-group v-model="formList.type" placement="row">
  12. <u-radio shape="circle" :customStyle="{marginRight: '20px'}" v-for="(item, index) in radiolist"
  13. :key="index" :label="item.name" :name="item.value"></u-radio>
  14. </u-radio-group>
  15. </u-form-item>
  16. <u-form-item label="手机号" prop="phone" labelWidth="80" borderBottom ref="item1">
  17. <u-input v-model="formList.phone" border="none" placeholder="请填写手机号"></u-input>
  18. </u-form-item>
  19. <u-form-item label="验证码" prop="verifyCode" labelWidth="80" borderBottom>
  20. <u-input v-model="formList.verifyCode" border="none" placeholder="请填写验证码"></u-input>
  21. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini"
  22. :disabled="disabled1"></u-button>
  23. </u-form-item>
  24. <u-form-item label="密码" prop="password" labelWidth="80" borderBottom ref="item1">
  25. <u-input v-show="isText === true" placeholder="请填写密码" border="none" v-model="formList.password"
  26. class="input_class_pwd" :password="true">
  27. <template slot="suffix" v-if="formList.password">
  28. <u-icon name="eye-off" @click="isText = false" size="20"></u-icon>
  29. </template>
  30. </u-input>
  31. <u-input v-show="isText === false" placeholder="请填写密码" border="none" v-model="formList.password"
  32. class="input_class_pwd" :password="false">
  33. <template slot="suffix" v-if="formList.password">
  34. <u-icon name="eye-fill" @click="isText = true" size="20"></u-icon>
  35. </template>
  36. </u-input>
  37. </u-form-item>
  38. </u-form>
  39. <u-code ref="uCode" @change="codeChange" seconds="90" @start="disabled1 = true"
  40. @end="disabled1 = false"></u-code>
  41. <view class="title_register" @click="goLogin">去登录</view>
  42. <view class="card_btn">
  43. <u-button type="primary" :disabled="disabled" text="注册" @click="getRegister"></u-button>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. radiolist: [{
  53. name: '私人',
  54. value: 1,
  55. }, {
  56. name: '商户',
  57. value: 0,
  58. }],
  59. formList: {
  60. type: 1,
  61. phone: '',
  62. verifyCode: '',
  63. password: '',
  64. },
  65. tips: '',
  66. disabled1: false,
  67. rules: {
  68. phone: {
  69. type: 'string',
  70. required: true,
  71. message: '请填写手机号',
  72. trigger: ['blur']
  73. },
  74. verifyCode: {
  75. type: 'string',
  76. required: true,
  77. message: '请填写验证码',
  78. trigger: ['blur']
  79. },
  80. password: {
  81. type: 'string',
  82. required: true,
  83. message: '请填写密码',
  84. trigger: ['blur']
  85. },
  86. },
  87. isText: true,
  88. }
  89. },
  90. computed: {
  91. disabled() {
  92. if (this.formList.phone == '' || this.formList.verifyCode == '' || this.formList.password == '') {
  93. return true;
  94. } else {
  95. return false;
  96. }
  97. },
  98. },
  99. methods: {
  100. // 注册
  101. getRegister() {
  102. this.$refs.uForm.validate().then(res => {
  103. uni.showLoading();
  104. this.$api.post('/api/applet/register', {
  105. phone: this.formList.phone,
  106. password: this.formList.password,
  107. verifyCode: this.formList.verifyCode
  108. }).then((res) => {
  109. if (res.code == 200) {
  110. uni.showToast({
  111. title: res.msg,
  112. icon: 'none',
  113. duration: 2000
  114. });
  115. this.formList.phone = ''
  116. this.formList.password = ''
  117. this.formList.verifyCode = ''
  118. } else {
  119. this.formList.phone = ''
  120. this.formList.password = ''
  121. this.formList.verifyCode = ''
  122. uni.showToast({
  123. title: res.data.msg,
  124. icon: 'none',
  125. duration: 2000
  126. });
  127. }
  128. uni.hideLoading();
  129. })
  130. }).catch(errors => {
  131. // uni.$u.toast('校验失败')
  132. })
  133. },
  134. getCode() {
  135. if (this.$refs.uCode.canGetCode) {
  136. // 模拟向后端请求验证码
  137. if (this.formList.phone) {
  138. uni.showLoading({
  139. title: '正在获取验证码'
  140. })
  141. // 通知验证码组件内部开始倒计时
  142. this.$refs.uCode.start();
  143. this.$api.get('/api/verify-code', {
  144. phone: this.formList.phone,
  145. }).then(res => {
  146. if (res.code == 200) {
  147. // 这里此提示会被this.start()方法中的提示覆盖
  148. uni.$u.toast('验证码已发送');
  149. }
  150. uni.hideLoading();
  151. })
  152. } else {
  153. uni.$u.toast('请先输入手机号');
  154. }
  155. } else {
  156. uni.$u.toast('倒计时结束后再发送');
  157. }
  158. },
  159. codeChange(text) {
  160. this.tips = text;
  161. },
  162. // 登录
  163. goLogin() {
  164. // uni.redirectTo({
  165. // url: '/pages/login'
  166. // })
  167. uni.navigateBack({
  168. delta: 1
  169. });
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="scss">
  175. .welcome_title {
  176. font-size: 46rpx;
  177. font-weight: 600;
  178. margin-bottom: 60rpx;
  179. margin-top: 10rpx;
  180. }
  181. .card_head_logo {
  182. margin-top: 50rpx;
  183. display: flex;
  184. flex-direction: column;
  185. justify-content: center;
  186. align-items: center;
  187. }
  188. .card_login {
  189. padding: 20rpx 40rpx;
  190. }
  191. .mine_image {
  192. width: 100rpx;
  193. height: 100rpx;
  194. }
  195. .title_register {
  196. margin-top: 20rpx;
  197. display: flex;
  198. justify-content: flex-end;
  199. font-size: 28rpx;
  200. color: #494949;
  201. }
  202. .card_hint {
  203. margin-top: 60rpx;
  204. display: flex;
  205. align-items: flex-start;
  206. }
  207. .agreement_title {
  208. font-size: 30rpx;
  209. color: #333;
  210. }
  211. .protocol_title {
  212. color: #1177ff;
  213. }
  214. .card_btn {
  215. margin-top: 50rpx;
  216. }
  217. .card_checkbox {
  218. margin-top: 5rpx;
  219. position: relative;
  220. cursor: pointer;
  221. }
  222. .message {
  223. display: none;
  224. position: absolute;
  225. padding: 5px 8px;
  226. border: 1px solid #494949;
  227. border-radius: 9px;
  228. top: -36px;
  229. font-size: 12px;
  230. width: 110px;
  231. background: #494949;
  232. color: #fff;
  233. left: -6px;
  234. }
  235. .message::after {
  236. content: '';
  237. position: absolute;
  238. left: 8px;
  239. top: 100%;
  240. border: 8px solid transparent;
  241. border-top: 6px solid #494949;
  242. margin-left: -2px;
  243. }
  244. </style>