register.vue 8.3 KB

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