register.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. pattern:this.$idCardPattern,
  113. message: '请输入身份证号',
  114. trigger: ['blur', 'change']
  115. },
  116. 'phone': {
  117. type: 'string',
  118. required: true,
  119. min:11,
  120. max: 11,
  121. pattern:this.$phonePattern,
  122. message: '请输入正确的电话号码',
  123. trigger: ['blur', 'change']
  124. },
  125. 'code': {
  126. type: 'string',
  127. required: true,
  128. min:4,
  129. max: 6,
  130. message: '请输入验证码',
  131. trigger: ['blur', 'change']
  132. },
  133. 'newPassword': {
  134. type: 'string',
  135. min:6,
  136. max: 16,
  137. required: true,
  138. message: '请输入6-18位密码',
  139. trigger: ['blur', 'change']
  140. },
  141. 'againPassword': {
  142. type: 'string',
  143. min:6,
  144. max: 16,
  145. required: true,
  146. message: '请输入6-18位密码',
  147. trigger: ['blur', 'change']
  148. }
  149. },
  150. }
  151. },
  152. onLoad(e){
  153. if (e.roleId){
  154. this.form.roleId = e.roleId
  155. console.log('获取到的id',e.roleId)
  156. }
  157. if (e.parentId){
  158. this.form.parentId = e.parentId
  159. console.log('获取到的name',e.parentId)
  160. }
  161. },
  162. methods: {
  163. gologin(){
  164. uni.redirectTo({
  165. url:'/pages/login/login'
  166. })
  167. },
  168. updateAvatar(){
  169. let that = this
  170. uni.chooseImage({
  171. count: 1, //默认9
  172. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  173. sourceType: ['album'], //从相册选择
  174. success: function (res) {
  175. let tempUrl = res.tempFiles[0].path
  176. uni.uploadFile({
  177. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  178. filePath:tempUrl,
  179. name: 'file',
  180. header: {
  181. // "Content-Type": "multipart/form-data",
  182. // 'X-Access-Token': uni.getStorageSync('token'),
  183. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  184. },
  185. success: (uploadFileRes) => {
  186. let res = JSON.parse(uploadFileRes.data)
  187. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++',uploadFileRes.data)
  188. that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
  189. that.form.img = res.data.ossId
  190. }
  191. });
  192. }
  193. })
  194. },
  195. birthdayClose() {
  196. this.showBirthday = false
  197. // this.$refs.form1.validateField('userInfo.birthday')
  198. },
  199. birthdayConfirm(e) {
  200. console.log(e)
  201. this.showBirthday = false
  202. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  203. // this.$refs.form1.validateField('userInfo.birthday')
  204. },
  205. sexSelect(e) {
  206. console.log(e)
  207. },
  208. expandRegister(){
  209. console.log(this.form)
  210. this.$refs.uForm.validate().then(res => {
  211. this.$api.login.expandRegister(this.form).then(res=>{
  212. uni.showToast({
  213. icon: 'success',
  214. duration: 2000,
  215. title: '注册成功,即将跳转登录页'
  216. });
  217. setTimeout(()=>{
  218. this.gologin()
  219. },2000)
  220. })
  221. })
  222. },
  223. logout(){
  224. this.$api.login.logout().then(res=>{
  225. uni.clearStorageSync();
  226. uni.navigateTo({
  227. url:'/pages/login/login'
  228. })
  229. })
  230. },
  231. back(){
  232. uni.navigateBack({
  233. delta: 1
  234. });
  235. },
  236. codeChange(text) {
  237. this.tips = text;
  238. },
  239. getCode() {
  240. let regExp=new RegExp(this.$phonePattern);
  241. let b= regExp.test(this.form.phone)
  242. if (!b){
  243. uni.$u.toast('请输入正确的手机号')
  244. return
  245. }
  246. if (this.$refs.uCode.canGetCode) {
  247. // 模拟向后端请求验证码
  248. uni.showLoading({
  249. title: '正在获取验证码'
  250. })
  251. this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res=>{
  252. uni.hideLoading();
  253. // 这里此提示会被this.start()方法中的提示覆盖
  254. uni.$u.toast('验证码已发送');
  255. // 通知验证码组件内部开始倒计时
  256. this.$refs.uCode.start();
  257. })
  258. } else {
  259. uni.$u.toast('倒计时结束后再发送');
  260. }
  261. },
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. @import './index.rpx.css';
  267. </style>