register.vue 7.8 KB

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