reg.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="page-box">
  3. <uni-forms :modelValue="postForm" ref="postForm" :rules="rules" :label-width="100">
  4. <uni-forms-item name="realName" label="真实姓名" required>
  5. <uni-easyinput type="text" v-model="postForm.realName" placeholder="用户姓名" />
  6. </uni-forms-item>
  7. <uni-forms-item name="userName" label="登录账号" required>
  8. <uni-easyinput type="text" v-model="postForm.userName" placeholder="登录账号" />
  9. </uni-forms-item>
  10. <uni-forms-item name="password" label="登录密码" required>
  11. <uni-easyinput type="password" v-model="postForm.password" placeholder="登录密码" />
  12. </uni-forms-item>
  13. <uni-forms-item name="deptCode" label="所在部门" required>
  14. <uni-data-picker placeholder="请选择所在部门" popup-title="选择部门" :localdata="treeData" :step-searh="true"
  15. @nodeclick="deptClick">
  16. </uni-data-picker>
  17. </uni-forms-item>
  18. </uni-forms>
  19. <view style="margin-top: 10px;">
  20. <button type="primary" @tap="handleLogin">注册并登录</button>
  21. </view>
  22. <view class="login-opt">
  23. <a @tap="$navs.toForgot">忘记密码</a>
  24. <a @tap="$navs.toLogin">已有账号?</a>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { userReg } from '@/api/user.js'
  30. import { fetchTreeSelect } from '@/api/sys/depart/depart.js'
  31. export default {
  32. data() {
  33. return {
  34. treeData: [],
  35. rules: {
  36. realName: {
  37. rules: [{
  38. required: true,
  39. errorMessage: '姓名不能为空!'
  40. }]
  41. },
  42. userName: {
  43. rules: [{
  44. required: true,
  45. errorMessage: '登录账号不能为空!'
  46. }]
  47. },
  48. deptCode: {
  49. rules: [{
  50. required: true,
  51. errorMessage: '所属部门不能为空!'
  52. }]
  53. },
  54. password: {
  55. rules: [{
  56. required: true,
  57. errorMessage: '密码不能为空!'
  58. }]
  59. }
  60. },
  61. postForm: {
  62. userName: '',
  63. realName: '',
  64. deptCode: '',
  65. password: ''
  66. }
  67. }
  68. },
  69. created() {
  70. fetchTreeSelect({flag: '2'}).then(data => {
  71. this.treeData = data
  72. })
  73. },
  74. methods: {
  75. deptClick(e) {
  76. const value = e.value
  77. this.postForm.deptCode = value
  78. },
  79. async handleLogin() {
  80. // 对整个表单进行校验,返回一个 Promise
  81. this.$refs.postForm.validate().then((res) => {
  82. uni.showLoading({
  83. title: '加载中...'
  84. });
  85. this.loginLoading = true
  86. // 快速注册后开始考试
  87. userReg(this.postForm).then(data => {
  88. // 关闭加载
  89. uni.hideLoading()
  90. // 保存本地token
  91. uni.setStorageSync('token', data.token);
  92. // 以下需要判断身份证信息是否填写完整 不完整 -> redirectTo /pages/user/info/info (设置tempToken,用于完成信息后保存token) 完整则 进入首页
  93. if(!data.idCard){
  94. //打印请求返回的数据
  95. uni.redirectTo({
  96. url: '/pages/user/info/info'
  97. });
  98. }else{
  99. uni.setStorageSync('idCard', data.idCard);
  100. //打印请求返回的数据
  101. uni.switchTab({
  102. url: '/pages/index/index'
  103. });
  104. }
  105. });
  106. }).catch((err) => {
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style scoped>
  113. /deep/ .uni-data-tree-input .input-value {
  114. line-height: 34px !important;
  115. height: 34px !important;
  116. }
  117. </style>