register.uvue 6.7 KB

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