register.uvue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class=" normal-login-container my-page">
  3. <view class=" logo-content align-center justify-center flex">
  4. <image class="my-image" style="width: 150rpx;height: 150rpx;" :src="(globalConfig['appInfo'] as UTSJSONObject)['logo'] as string" mode="widthFix">
  5. </image>
  6. <text class="title">用户注册</text>
  7. </view>
  8. <view class=" login-form-content">
  9. <view class=" input-item flex align-center uni-row">
  10. <view class=" iconfont icon-user icon"></view>
  11. <input v-model="registerForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  12. </view>
  13. <view class=" input-item flex align-center uni-row">
  14. <view class=" iconfont icon-user icon"></view>
  15. <input v-model="registerForm.name" class="input" type="text" placeholder="请输入用户姓名" maxlength="30" />
  16. </view>
  17. <view class=" input-item flex align-center uni-row">
  18. <view class=" iconfont icon-password icon"></view>
  19. <input v-model="registerForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  20. </view>
  21. <view class=" input-item flex align-center uni-row">
  22. <view class=" iconfont icon-password icon"></view>
  23. <input v-model="registerForm.confirmPassword" type="password" class="input" placeholder="请输入重复密码" maxlength="20" />
  24. </view>
  25. <!--
  26. <view class=" input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  27. <view class=" iconfont icon-code icon"></view>
  28. <input v-model="registerForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  29. <view class=" login-code">
  30. <image :src="codeUrl" @click="getCode" class="login-code-img my-image"></image>
  31. </view>
  32. </view> -->
  33. <view class=" action-btn">
  34. <button @click="handleRegister()" class="register-btn block bg-blue lg round">注册</button>
  35. </view>
  36. </view>
  37. <view class=" xieyi text-center" v-if="login">
  38. <text @click="handleUserLogin" class="text-blue">使用已有账号登录</text>
  39. </view>
  40. </view>
  41. </template>
  42. <script lang="uts">
  43. import { GlobalConfig } from '../config'
  44. import { getCodeImg, register, RegForm} from '@/api/login'
  45. import {GetInfo} from '@/store'
  46. export default {
  47. data() {
  48. return {
  49. codeUrl: "" as string,
  50. captchaEnabled: false as boolean,
  51. login: false as boolean,
  52. globalConfig: getApp().globalData.config as UTSJSONObject,
  53. registerForm: {
  54. username: "",
  55. name: "",
  56. password: "",
  57. token: "",
  58. confirmPassword: "",
  59. code: "",
  60. uuid: ''
  61. } as RegForm
  62. }
  63. },
  64. created() {
  65. //this.getCode()
  66. },
  67. methods: {
  68. // 用户登录
  69. handleUserLogin() {
  70. uni.navigateTo({
  71. url: '/pages/login'
  72. });
  73. },
  74. // 获取图形验证码
  75. async getCode() {
  76. getCodeImg().then((res:UTSJSONObject) => {
  77. this.captchaEnabled = res.getBoolean("captchaEnabled") as boolean | false
  78. if (this.captchaEnabled) {
  79. this.codeUrl = 'data:image/gif;base64,' + (res.getString("img") as string)
  80. this.registerForm.uuid = res.getString("uuid") as string
  81. }
  82. })
  83. },
  84. // 注册方法
  85. async handleRegister() {
  86. if (this.registerForm.username == "") {
  87. uni.showToast({
  88. title: '请输入您的账号',
  89. icon: 'error'
  90. });
  91. } else if (this.registerForm.password == "") {
  92. uni.showToast({
  93. title: '请输入您的密码',
  94. icon: 'error'
  95. });
  96. } else if (this.registerForm.confirmPassword == "") {
  97. uni.showToast({
  98. title: '请再次输入您的密码',
  99. icon: 'error'
  100. });
  101. } else if (this.registerForm.password != this.registerForm.confirmPassword) {
  102. uni.showToast({
  103. title: '两次输入的密码不一致',
  104. icon: 'error'
  105. });
  106. } else if (this.registerForm.name == "") {
  107. uni.showToast({
  108. title: '请输入您的用户姓名',
  109. icon: 'error'
  110. });
  111. }
  112. /*else if (this.registerForm.code == "" && this.captchaEnabled) {
  113. uni.showToast({
  114. title: '请输入验证码',
  115. icon: 'error'
  116. });
  117. } */
  118. else {
  119. uni.showLoading({
  120. title: '注册中,请耐心等待...'
  121. });
  122. this.register();
  123. }
  124. },
  125. // 用户注册
  126. async register() {
  127. register(this.registerForm).then(() => {
  128. uni.hideLoading()
  129. uni.showModal({
  130. title: "系统提示",
  131. content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
  132. success: function (res:UniShowModalResult) {
  133. if (res.confirm) {
  134. uni.redirectTo({ url: `/pages/login` });
  135. }
  136. }
  137. })
  138. }).catch(() => {
  139. if (this.captchaEnabled) {
  140. this.getCode()
  141. }
  142. })
  143. },
  144. // 注册成功后,处理函数
  145. registerSuccess() {
  146. // 设置用户信息
  147. GetInfo().then(() => {
  148. uni.reLaunch({
  149. url: '/pages/index'
  150. });
  151. })
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss">
  157. .my-page {
  158. background-color: #ffffff;
  159. width: 100%;
  160. height: 100%;
  161. }
  162. .normal-login-container {
  163. width: 100%;
  164. align-items: center;
  165. justify-content: center;
  166. .logo-content {
  167. width: 100%;
  168. font-size: 21px;
  169. text-align: center;
  170. padding-top: 15%;
  171. .my-image {
  172. border-radius: 4px;
  173. }
  174. .title {
  175. margin-top: 15rpx;
  176. }
  177. }
  178. .login-form-content {
  179. /* #ifdef APP-NVUE */
  180. text-align: center;
  181. /* #endif */
  182. margin: 20px auto;
  183. margin-top: 15%;
  184. width: 80%;
  185. .input-item {
  186. margin: 20px auto;
  187. background-color: #f5f6f7;
  188. height: 45px;
  189. border-radius: 20px;
  190. .icon {
  191. /* #ifdef APP-NVUE */
  192. font-size: 38rpx;
  193. color: #999;
  194. /* #endif */
  195. margin-left: 10px;
  196. }
  197. .input {
  198. width: 100%;
  199. font-size: 14px;
  200. /* #ifdef APP-NVUE */
  201. line-height: 20px;
  202. /* #endif */
  203. padding-left: 15px;
  204. }
  205. }
  206. .register-btn {
  207. margin-top: 40px;
  208. height: 45px;
  209. }
  210. .xieyi {
  211. color: #333;
  212. margin-top: 20px;
  213. }
  214. .login-code {
  215. height: 38px;
  216. margin-left: auto;
  217. .login-code-img {
  218. height: 38px;
  219. margin-left: 10px;
  220. width: 200rpx;
  221. }
  222. }
  223. }
  224. }
  225. </style>