register.uvue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. onBackPress() {
  68. // 覆盖系统默认的返回行为,返回到指定页面
  69. uni.navigateTo({
  70. url: `/pages/mine/index`,
  71. // 修改动画方向为从左到右退回
  72. animationType: 'slide-in-left', // 使用从左到右滑出的动画效果
  73. animationDuration: 300 // 动画持续时间,单位ms
  74. })
  75. // 返回true表示拦截默认返回行为
  76. return true
  77. },
  78. methods: {
  79. // 用户登录
  80. handleUserLogin() {
  81. uni.navigateTo({
  82. url: '/pages/login'
  83. });
  84. },
  85. // 获取图形验证码
  86. async getCode() {
  87. getCodeImg().then((res:UTSJSONObject) => {
  88. this.captchaEnabled = res.getBoolean("captchaEnabled") as boolean | false
  89. if (this.captchaEnabled) {
  90. this.codeUrl = 'data:image/gif;base64,' + (res.getString("img") as string)
  91. this.registerForm.uuid = res.getString("uuid") as string
  92. }
  93. })
  94. },
  95. // 注册方法
  96. async handleRegister() {
  97. if (this.registerForm.username == "") {
  98. uni.showToast({
  99. title: '请输入您的账号',
  100. icon: 'error'
  101. });
  102. } else if (this.registerForm.username.length < 4 || this.registerForm.username.length > 20) {
  103. uni.showToast({
  104. title: '账号长度需在4-20位之间',
  105. icon: 'error'
  106. });
  107. } else if (!/^[a-zA-Z0-9]+$/.test(this.registerForm.username)) {
  108. uni.showToast({
  109. title: '账号只能包含字母和数字',
  110. icon: 'error'
  111. });
  112. } else if (this.registerForm.password == "") {
  113. uni.showToast({
  114. title: '请输入您的密码',
  115. icon: 'error'
  116. });
  117. } else if (this.registerForm.confirmPassword == "") {
  118. uni.showToast({
  119. title: '请再次输入您的密码',
  120. icon: 'error'
  121. });
  122. } else if (this.registerForm.password != this.registerForm.confirmPassword) {
  123. uni.showToast({
  124. title: '两次输入的密码不一致',
  125. icon: 'error'
  126. });
  127. } else if (this.registerForm.name == "") {
  128. uni.showToast({
  129. title: '请输入您的用户姓名',
  130. icon: 'error'
  131. });
  132. }
  133. else {
  134. uni.showLoading({
  135. title: '注册中,请耐心等待...'
  136. });
  137. this.register();
  138. }
  139. },
  140. // 用户注册
  141. async register() {
  142. register(this.registerForm).then(() => {
  143. uni.hideLoading()
  144. uni.showModal({
  145. title: "系统提示",
  146. content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
  147. success: function (res:UniShowModalResult) {
  148. if (res.confirm) {
  149. uni.redirectTo({ url: `/pages/mine/index` });
  150. }
  151. }
  152. })
  153. }).catch(() => {
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. .my-page {
  161. background-color: #ffffff;
  162. width: 100%;
  163. height: 100%;
  164. }
  165. .normal-login-container {
  166. width: 100%;
  167. align-items: center;
  168. justify-content: center;
  169. .logo-content {
  170. width: 100%;
  171. font-size: 21px;
  172. text-align: center;
  173. padding-top: 15%;
  174. .my-image {
  175. border-radius: 4px;
  176. }
  177. .title {
  178. margin-top: 15rpx;
  179. }
  180. }
  181. .login-form-content {
  182. /* #ifdef APP-NVUE */
  183. text-align: center;
  184. /* #endif */
  185. margin: 20rpx auto;
  186. margin-top: 15%;
  187. width: 80%;
  188. .input-item {
  189. margin: 20rpx auto;
  190. background-color: #f5f6f7;
  191. height: 45px;
  192. border-radius: 20px;
  193. .icon {
  194. /* #ifdef APP-NVUE */
  195. font-size: 38rpx;
  196. color: #999;
  197. /* #endif */
  198. margin-left: 10px;
  199. }
  200. .input {
  201. width: 100%;
  202. font-size: 14px;
  203. /* #ifdef APP-NVUE */
  204. line-height: 20px;
  205. /* #endif */
  206. padding-left: 15px;
  207. }
  208. }
  209. .register-btn {
  210. margin-top: 40px;
  211. height: 45px;
  212. }
  213. .xieyi {
  214. color: #333;
  215. margin-top: 20px;
  216. }
  217. .login-code {
  218. height: 38px;
  219. margin-left: auto;
  220. .login-code-img {
  221. height: 38px;
  222. margin-left: 10px;
  223. width: 200rpx;
  224. }
  225. }
  226. }
  227. }
  228. </style>