register.vue 9.6 KB

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