register.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. qrCodeInvalid:false,//二维码是否无效标识
  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. {
  103. type: 'string',
  104. required: true,
  105. min:2,
  106. message: '请输入姓名',
  107. trigger: ['blur']
  108. }
  109. ] ,
  110. 'idCard': [
  111. {
  112. type: 'string',
  113. required: true,
  114. min:18,
  115. max: 18,
  116. pattern:this.$idCardPattern,
  117. message: '请输入身份证号',
  118. trigger: ['blur']
  119. },
  120. {
  121. asyncValidator: async (a,b,callback) => {
  122. this.$refs.uForm.validateField('name');
  123. let res = await this.idCardAndName()
  124. if(res.data.data.respCode !== '0000') {
  125. callback(new Error(res.data.data.respMessage));
  126. } else {
  127. // 如果校验通过,也要执行callback()回调
  128. callback();
  129. }
  130. },
  131. // 触发器可以同时用blur和change
  132. trigger: ['blur']
  133. }
  134. ],
  135. 'phone': {
  136. type: 'string',
  137. required: true,
  138. min:11,
  139. max: 11,
  140. pattern:this.$phonePattern,
  141. message: '请输入正确的电话号码',
  142. trigger: ['blur', 'change']
  143. },
  144. 'code': {
  145. type: 'string',
  146. required: true,
  147. min:4,
  148. max: 6,
  149. message: '请输入验证码',
  150. trigger: ['blur', 'change']
  151. },
  152. 'newPassword': {
  153. type: 'string',
  154. min:6,
  155. max: 16,
  156. required: true,
  157. message: '请输入6-18位密码',
  158. trigger: ['blur', 'change']
  159. },
  160. 'againPassword': {
  161. type: 'string',
  162. min:6,
  163. max: 16,
  164. required: true,
  165. message: '请输入6-18位密码',
  166. trigger: ['blur', 'change']
  167. }
  168. },
  169. }
  170. },
  171. onLoad(e){
  172. if (e.roleId){
  173. this.form.roleId = e.roleId
  174. console.log('获取到的id',e.roleId)
  175. }
  176. if (e.parentId){
  177. this.form.parentId = e.parentId
  178. console.log('获取到的name',e.parentId)
  179. }
  180. if (e.timestamp){
  181. console.log('获取到的时间戳',e.timestamp,new Date().getTime() > e.timestamp)
  182. if (new Date().getTime() > e.timestamp){
  183. this.qrCodeInvalid = true
  184. uni.showModal({
  185. title: '温馨提示',
  186. content: ' 当前二维码已过期,请重新扫码',
  187. showCancel:false,
  188. success: function (res) {
  189. if (res.confirm) {
  190. console.log('用户点击确定');
  191. } else if (res.cancel) {
  192. console.log('用户点击取消');
  193. }
  194. }
  195. });
  196. }
  197. }
  198. },
  199. methods: {
  200. idCardAndName(){
  201. return this.$api.service.idCardAndName({
  202. name:this.form.name,
  203. idCard:this.form.idCard,
  204. }).then(res=>{
  205. return res
  206. })
  207. },
  208. gologin(){
  209. uni.redirectTo({
  210. url:'/pages/login/login'
  211. })
  212. },
  213. updateAvatar(){
  214. let that = this
  215. uni.chooseImage({
  216. count: 1, //默认9
  217. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  218. sourceType: ['album'], //从相册选择
  219. success: function (res) {
  220. let tempUrl = res.tempFiles[0].path
  221. uni.uploadFile({
  222. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  223. filePath:tempUrl,
  224. name: 'file',
  225. header: {
  226. // "Content-Type": "multipart/form-data",
  227. // 'X-Access-Token': uni.getStorageSync('token'),
  228. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  229. },
  230. success: (uploadFileRes) => {
  231. let res = JSON.parse(uploadFileRes.data)
  232. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++',uploadFileRes.data)
  233. that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
  234. that.form.img = res.data.ossId
  235. }
  236. });
  237. }
  238. })
  239. },
  240. birthdayClose() {
  241. this.showBirthday = false
  242. // this.$refs.form1.validateField('userInfo.birthday')
  243. },
  244. birthdayConfirm(e) {
  245. console.log(e)
  246. this.showBirthday = false
  247. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  248. // this.$refs.form1.validateField('userInfo.birthday')
  249. },
  250. sexSelect(e) {
  251. console.log(e)
  252. },
  253. expandRegister(){
  254. if (this.qrCodeInvalid){
  255. uni.showModal({
  256. title: '温馨提示',
  257. content: ' 当前二维码已过期,请重新扫码',
  258. success: function (res) {
  259. if (res.confirm) {
  260. console.log('用户点击确定');
  261. } else if (res.cancel) {
  262. console.log('用户点击取消');
  263. }
  264. }
  265. });
  266. return;
  267. }
  268. console.log(this.form)
  269. if (this.requestStatus){
  270. return
  271. }
  272. this.requestStatus=true
  273. this.$refs.uForm.validate().then(res => {
  274. uni.showLoading({
  275. title: '正在注册...'
  276. });
  277. this.$api.login.expandRegister(this.form).then(res=>{
  278. uni.hideLoading();
  279. this.requestStatus=false
  280. uni.showToast({
  281. icon: 'success',
  282. duration: 2000,
  283. title: '注册成功,即将跳转登录页'
  284. });
  285. setTimeout(()=>{
  286. this.gologin()
  287. },2000)
  288. }).catch(err=>{
  289. this.requestStatus=false
  290. })
  291. }).catch(err=>{
  292. this.requestStatus=false
  293. })
  294. },
  295. logout(){
  296. this.$api.login.logout().then(res=>{
  297. uni.clearStorageSync();
  298. uni.navigateTo({
  299. url:'/pages/login/login'
  300. })
  301. })
  302. },
  303. back(){
  304. uni.navigateBack({
  305. delta: 1
  306. });
  307. },
  308. codeChange(text) {
  309. this.tips = text;
  310. },
  311. getCode() {
  312. let regExp=new RegExp(this.$phonePattern);
  313. let b= regExp.test(this.form.phone)
  314. if (!b){
  315. uni.$u.toast('请输入正确的手机号')
  316. return
  317. }
  318. if (this.$refs.uCode.canGetCode) {
  319. // 模拟向后端请求验证码
  320. uni.showLoading({
  321. title: '正在获取验证码'
  322. })
  323. this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res=>{
  324. uni.hideLoading();
  325. // 这里此提示会被this.start()方法中的提示覆盖
  326. uni.$u.toast('验证码已发送');
  327. // 通知验证码组件内部开始倒计时
  328. this.$refs.uCode.start();
  329. })
  330. } else {
  331. uni.$u.toast('倒计时结束后再发送');
  332. }
  333. },
  334. }
  335. }
  336. </script>
  337. <style lang="scss" scoped>
  338. @import './index.rpx.css';
  339. </style>