register.vue 7.4 KB

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