register.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="page">
  3. <uni-nav-bar :fixed="true" background-color="#FFE05C" :border="false" :statusBar="true" title="注册" />
  4. <view :style="{'marginTop':'10rpx'}">
  5. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  6. <view class="flex-row bordBot" >
  7. <view class="key flex-col justify-center ">
  8. <text>头像</text>
  9. </view>
  10. <view class="photoView" @click="updateAvatar">
  11. <image class="photoImage" :src="userInfo.img || '/static/ud4.png'"></image>
  12. </view>
  13. </view>
  14. <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
  15. <u--input v-model="form.username" placeholder="请输入姓名" border="none"></u--input>
  16. </u-form-item>
  17. <u-form-item :labelWidth="80" label="身份证号:" borderBottom prop="name" ref="item1">
  18. <u--input v-model="form.username" placeholder="请输入姓名" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
  21. <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
  22. </u-form-item>
  23. <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
  24. <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password" border="none"></u--input>
  25. </u-form-item>
  26. <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="username" ref="item1">
  27. <u--input v-model="form.username" placeholder="请输入手机号" border="none"></u--input>
  28. </u-form-item>
  29. <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
  30. <view class="inputCode">
  31. <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
  32. </view>
  33. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small" :disabled="disabled1"></u-button>
  34. </u-form-item>
  35. </u--form>
  36. <view :style="{'marginTop':'100rpx'}">
  37. <button class="customStyle" @click="retrievePassword">提交</button>
  38. </view>
  39. <view class="flex-row justify-center register">
  40. <text>已有账号!</text>
  41. <text @click="gologin" :style="{color:'#FFE05C'}">切换登录</text>
  42. </view>
  43. </view>
  44. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code>
  45. <u-action-sheet
  46. :show="showSex"
  47. :actions="actions"
  48. title="请选择性别"
  49. @close="showSex = false"
  50. @select="sexSelect">
  51. </u-action-sheet>
  52. <u-datetime-picker
  53. :show="showBirthday"
  54. :value="birthday"
  55. mode="date"
  56. closeOnClickOverlay
  57. @confirm="birthdayConfirm"
  58. @cancel="birthdayClose"
  59. @close="birthdayClose"
  60. ></u-datetime-picker>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. showBirthday:false,
  68. showSex:false,
  69. birthday: Number(new Date()),
  70. actions: [{
  71. name: '男',
  72. value:'1'
  73. },
  74. {
  75. name: '女',
  76. value:'0'
  77. },{
  78. name: '保密',
  79. value:'2'
  80. }
  81. ],
  82. tips:'',
  83. form:{
  84. username:'',
  85. code:'',
  86. newPassword:'',
  87. againPassword:''
  88. },
  89. rules: {
  90. 'username': {
  91. type: 'string',
  92. required: true,
  93. min:11,
  94. max: 11,
  95. pattern:this.$phonePattern,
  96. message: '请输入正确的电话号码',
  97. trigger: ['blur', 'change']
  98. },
  99. 'code': {
  100. type: 'string',
  101. required: true,
  102. min:4,
  103. max: 6,
  104. message: '请输入验证码',
  105. trigger: ['blur', 'change']
  106. },
  107. 'newPassword': {
  108. type: 'string',
  109. min:6,
  110. max: 16,
  111. required: true,
  112. message: '请输入6-18位密码',
  113. trigger: ['blur', 'change']
  114. },
  115. 'againPassword': {
  116. type: 'string',
  117. min:6,
  118. max: 16,
  119. required: true,
  120. message: '请输入6-18位密码',
  121. trigger: ['blur', 'change']
  122. }
  123. },
  124. }
  125. },
  126. methods: {
  127. gologin(){
  128. uni.redirectTo({
  129. url:'/pages/login/login'
  130. })
  131. },
  132. updateAvatar(){
  133. let that = this
  134. uni.chooseImage({
  135. count: 1, //默认9
  136. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  137. sourceType: ['album'], //从相册选择
  138. success: function (res) {
  139. let tempUrl = res.tempFiles[0].path
  140. uni.uploadFile({
  141. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  142. filePath:tempUrl,
  143. name: 'file',
  144. header: {
  145. // "Content-Type": "multipart/form-data",
  146. // 'X-Access-Token': uni.getStorageSync('token'),
  147. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  148. },
  149. success: (uploadFileRes) => {
  150. let res = JSON.parse(uploadFileRes.data)
  151. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++',uploadFileRes.data)
  152. that.userInfo.img = res.data.url.replace(/^http:/, "https:")
  153. //todo 更新头像的接口
  154. uni.setStorageSync('spreadUserInfo', that.userInfo)
  155. }
  156. });
  157. }
  158. })
  159. },
  160. birthdayClose() {
  161. this.showBirthday = false
  162. // this.$refs.form1.validateField('userInfo.birthday')
  163. },
  164. birthdayConfirm(e) {
  165. console.log(e)
  166. this.showBirthday = false
  167. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  168. // this.$refs.form1.validateField('userInfo.birthday')
  169. },
  170. sexSelect(e) {
  171. console.log(e)
  172. },
  173. retrievePassword(){
  174. this.$refs.uForm.validate().then(res => {
  175. this.$api.login.retrievePassword(this.form).then(res=>{
  176. uni.showToast({
  177. icon: 'success',
  178. duration: 2000,
  179. title: '修改成功,即将跳转登录页'
  180. });
  181. setTimeout(()=>{
  182. this.logout()
  183. },2000)
  184. })
  185. })
  186. },
  187. logout(){
  188. this.$api.login.logout().then(res=>{
  189. uni.clearStorageSync();
  190. uni.navigateTo({
  191. url:'/pages/login/login'
  192. })
  193. })
  194. },
  195. back(){
  196. uni.navigateBack({
  197. delta: 1
  198. });
  199. },
  200. codeChange(text) {
  201. this.tips = text;
  202. },
  203. getCode() {
  204. if (this.$refs.uCode.canGetCode) {
  205. // 模拟向后端请求验证码
  206. uni.showLoading({
  207. title: '正在获取验证码'
  208. })
  209. this.$api.service.getSmsCode({phonenumber: this.form.username}).then(res=>{
  210. uni.hideLoading();
  211. // 这里此提示会被this.start()方法中的提示覆盖
  212. uni.$u.toast('验证码已发送');
  213. // 通知验证码组件内部开始倒计时
  214. this.$refs.uCode.start();
  215. })
  216. } else {
  217. uni.$u.toast('倒计时结束后再发送');
  218. }
  219. },
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. @import './index.rpx.css';
  225. </style>