register.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="register">
  3. <!-- 主要内容区域 -->
  4. <view class="content">
  5. <!-- Logo和标题区域 -->
  6. <view class="header" @longpress.prevent="onLongPressHeader()">
  7. <view class="title"> 用户注册 </view>
  8. <view class="subtitle">创建您的账号,开始精彩旅程</view>
  9. </view>
  10. <!-- 表单区域 -->
  11. <view class="form-container">
  12. <view class="form">
  13. <!-- 用户名输入 -->
  14. <view class="form-item" :class="{'focused': userNameFocused}">
  15. <view class="icon-wrapper">
  16. <view class="icon iconfont icon-username"></view>
  17. </view>
  18. <input class="input" type="text" v-model="dataForm.userName" placeholder="请填写用户名"
  19. @focus="userNameFocused = true" @blur="userNameFocused = false" />
  20. </view>
  21. <!-- 用户名输入 -->
  22. <view class="form-item" :class="{'focused': nickNameFocused}">
  23. <view class="icon-wrapper">
  24. <view class="icon iconfont icon-username"></view>
  25. </view>
  26. <input class="input" type="text" v-model="dataForm.nickName" placeholder="请填写昵称"
  27. @focus="nickNameFocused = true" @blur="nickNameFocused = false" />
  28. </view>
  29. <!-- 密码输入 -->
  30. <view class="form-item" :class="{'focused': passwordFocused}">
  31. <view class="icon-wrapper">
  32. <view class="icon iconfont icon-pwd"></view>
  33. </view>
  34. <input class="input" :type="isShowPwd?'text':'password'" v-model="dataForm.password"
  35. placeholder="请设置密码" @focus="passwordFocused = true" @blur="passwordFocused = false" />
  36. <view class="icon-suffix iconfont" :class="isShowPwd?'icon-pwd-show':'icon-pwd-hide'"
  37. @click="onSwitchShowPwd"></view>
  38. </view>
  39. <!-- 确认密码输入 -->
  40. <view class="form-item" :class="{'focused': confirmPasswordFocused}">
  41. <view class="icon-wrapper">
  42. <view class="icon iconfont icon-pwd"></view>
  43. </view>
  44. <input class="input" :type="isShowConfirmPwd?'text':'password'"
  45. v-model="dataForm.confirmPassword" placeholder="确认密码" @focus="confirmPasswordFocused = true"
  46. @blur="confirmPasswordFocused = false" />
  47. <view class="icon-suffix iconfont" :class="isShowConfirmPwd?'icon-pwd-show':'icon-pwd-hide'"
  48. @click="onSwitchShowConfirmPwd"></view>
  49. </view>
  50. <!-- 注册按钮 -->
  51. <button class="submit-btn" @click="submit" type="primary">
  52. <view class="btn-content">
  53. <text class="btn-text">注册并登录</text>
  54. </view>
  55. </button>
  56. <!-- 底部导航 -->
  57. <view class="nav-tool-bar">
  58. <view class="nav-login">
  59. <navigator url="/pages/login/login" class="login-link">
  60. <text class="login-text">已有账号?</text>
  61. <text class="login-highlight">立即登录</text>
  62. </navigator>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import UNI_APP from '@/.env.js';
  72. export default {
  73. data() {
  74. return {
  75. isShowPwd: false,
  76. isShowConfirmPwd: false,
  77. userNameFocused: false,
  78. nickNameFocused: false,
  79. passwordFocused: false,
  80. confirmPasswordFocused: false,
  81. dataForm: {
  82. userName: '',
  83. nickName: '',
  84. password: '',
  85. confirmPassword: ''
  86. }
  87. }
  88. },
  89. methods: {
  90. onSwitchShowPwd() {
  91. this.isShowPwd = !this.isShowPwd;
  92. },
  93. onSwitchShowConfirmPwd() {
  94. this.isShowConfirmPwd = !this.isShowConfirmPwd;
  95. },
  96. submit() {
  97. if (!this.dataForm.userName) {
  98. return uni.showToast({
  99. title: '请输入用户名',
  100. icon: 'none'
  101. });
  102. }
  103. if (!this.dataForm.password) {
  104. return uni.showToast({
  105. title: '请输入密码',
  106. icon: 'none'
  107. });
  108. }
  109. if (!this.dataForm.confirmPassword) {
  110. return uni.showToast({
  111. title: '请输入确认密码',
  112. icon: 'none'
  113. });
  114. }
  115. if (this.dataForm.confirmPassword != this.dataForm.password) {
  116. return uni.showToast({
  117. title: '两次密码输入不一致',
  118. icon: 'none'
  119. });
  120. }
  121. this.$http({
  122. url: '/register',
  123. data: this.dataForm,
  124. method: 'POST'
  125. }).then(() => {
  126. let appName = uni.getSystemInfoSync().appName
  127. uni.showToast({
  128. title: `注册成功,您已成为${appName}的用户`,
  129. icon: 'none'
  130. })
  131. this.login();
  132. })
  133. },
  134. login() {
  135. const loginForm = {
  136. terminal: this.$enums.TERMINAL_TYPE.APP,
  137. userName: this.dataForm.userName,
  138. password: this.dataForm.password
  139. }
  140. this.$http({
  141. url: '/login',
  142. data: loginForm,
  143. method: 'POST'
  144. }).then((loginInfo) => {
  145. console.log("登录成功,自动跳转到聊天页面...")
  146. uni.setStorageSync("userName", loginForm.userName);
  147. uni.setStorageSync("password", loginForm.password);
  148. uni.setStorageSync("loginInfo", loginInfo);
  149. // 调用App.vue的初始化方法
  150. getApp().init()
  151. // 跳转到聊天页面
  152. uni.switchTab({
  153. url: "/pages/chat/chat"
  154. })
  155. })
  156. // 清理数据,防止缓存未失效
  157. getApp().$vm.unloadStore();
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .register {
  164. display: flex;
  165. flex-direction: column;
  166. position: relative;
  167. overflow: hidden;
  168. // 主要内容区域
  169. .content {
  170. flex: 1;
  171. position: relative;
  172. display: flex;
  173. flex-direction: column;
  174. margin-top: 120rpx;
  175. // #ifdef APP-PLUS
  176. margin-top: calc(120rpx + var(--status-bar-height));
  177. // #endif
  178. padding: 0 60rpx;
  179. }
  180. // 头部区域
  181. .header {
  182. text-align: center;
  183. padding: 80rpx 0;
  184. .title {
  185. color: $im-color-primary;
  186. font-size: 48rpx;
  187. font-weight: 700;
  188. margin-bottom: 20rpx;
  189. letter-spacing: 2rpx;
  190. }
  191. .subtitle {
  192. color: $im-text-color-light;
  193. font-size: 28rpx;
  194. opacity: 0.8;
  195. }
  196. }
  197. // 表单容器
  198. .form-container {
  199. display: flex;
  200. flex-direction: column;
  201. }
  202. // 表单样式
  203. .form {
  204. height: 830rpx;
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: center;
  208. .form-item {
  209. position: relative;
  210. display: flex;
  211. align-items: center;
  212. padding: 0 30rpx;
  213. height: 100rpx;
  214. margin: 14rpx 0;
  215. border-radius: 25rpx;
  216. background: rgba(255, 255, 255, 0.9);
  217. border: 2rpx solid transparent;
  218. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  219. transition: all 0.3s ease;
  220. &.focused {
  221. border-color: $im-color-primary;
  222. box-shadow: 0 8rpx 32rpx rgba($im-color-primary, 0.15);
  223. transform: translateY(-2rpx);
  224. }
  225. .icon-wrapper {
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. width: 60rpx;
  230. height: 60rpx;
  231. margin-right: 30rpx;
  232. border-radius: 50%;
  233. background: $im-bg-active;
  234. transition: all 0.3s ease;
  235. .icon {
  236. font-size: 32rpx;
  237. color: $im-color-primary;
  238. font-weight: bold;
  239. }
  240. }
  241. &.focused .icon-wrapper {
  242. transform: scale(1.1);
  243. }
  244. .input {
  245. flex: 1;
  246. font-size: 32rpx;
  247. color: #333;
  248. background: transparent;
  249. border: none;
  250. outline: none;
  251. &::placeholder {
  252. color: $im-text-color-light;
  253. font-size: 30rpx;
  254. }
  255. }
  256. .icon-suffix {
  257. font-size: 36rpx;
  258. padding: 10rpx;
  259. }
  260. }
  261. }
  262. // 注册按钮
  263. .submit-btn {
  264. height: 100rpx;
  265. border-radius: 50rpx;
  266. border: none;
  267. transition: all 0.3s ease;
  268. overflow: hidden;
  269. position: relative;
  270. width: 100%;
  271. margin-top: 50rpx;
  272. &:active {
  273. transform: translateY(2rpx);
  274. }
  275. .btn-content {
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. height: 100%;
  280. color: white;
  281. font-size: $im-font-size-large;
  282. font-weight: 600;
  283. .btn-text {
  284. margin-right: 10rpx;
  285. }
  286. }
  287. }
  288. // 底部导航
  289. .nav-tool-bar {
  290. padding: 40rpx 0 60rpx;
  291. display: flex;
  292. align-items: center;
  293. justify-content: center;
  294. .nav-login {
  295. .login-link {
  296. display: flex;
  297. align-items: center;
  298. text-decoration: none;
  299. .login-text {
  300. color: $im-text-color-light;
  301. font-size: $im-font-size-small;
  302. margin-right: 8rpx;
  303. }
  304. .login-highlight {
  305. color: $im-color-primary;
  306. font-size: $im-font-size-small;
  307. font-weight: 600;
  308. transition: all 0.3s ease;
  309. &:active {
  310. opacity: 0.7;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. </style>