register.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <view class="login-page">
  3. <nav-bar title="注册" bgColor="transparent" color="#fff" :showBack="false"></nav-bar>
  4. <!-- 顶部渐变装饰区 -->
  5. <view class="hero-bg">
  6. <view class="deco-circle c1"></view>
  7. <view class="deco-circle c2"></view>
  8. <view class="deco-circle c3"></view>
  9. <!-- 返回按钮 -->
  10. <view class="back-btn" @click="onClickLeft">
  11. <uni-icons type="left" size="22" color="#fff"></uni-icons>
  12. </view>
  13. <!-- Logo 区域 -->
  14. <view class="hero-content">
  15. <text class="brand-desc">开启您的好萌友服务之旅</text>
  16. </view>
  17. </view>
  18. <!-- 表单白色卡片区 -->
  19. <view class="form-card">
  20. <!-- 头像上传 -->
  21. <view class="avatar-upload-wrap" @click="onChooseAvatar">
  22. <image v-if="avatar" :src="avatar" class="avatar-image" mode="aspectFill"></image>
  23. <view v-else class="avatar-placeholder">
  24. <uni-icons type="camera-filled" size="32" color="#ccc"></uni-icons>
  25. <text class="avatar-text">上传头像</text>
  26. </view>
  27. </view>
  28. <!-- 商户名称 -->
  29. <view class="input-group">
  30. <view class="input-icon-wrap">
  31. <uni-icons type="shop" size="18" color="#ffc837"></uni-icons>
  32. </view>
  33. <input class="custom-input" v-model="companyName" placeholder="请输入商户名称"
  34. placeholder-class="input-placeholder" />
  35. </view>
  36. <!-- 用户账号 -->
  37. <view class="input-group">
  38. <view class="input-icon-wrap">
  39. <uni-icons type="person" size="18" color="#ffc837"></uni-icons>
  40. </view>
  41. <input class="custom-input" v-model="username" placeholder="请输入用户账号"
  42. placeholder-class="input-placeholder" />
  43. </view>
  44. <!-- 姓名 -->
  45. <view class="input-group">
  46. <view class="input-icon-wrap">
  47. <uni-icons type="staff" size="18" color="#ffc837"></uni-icons>
  48. </view>
  49. <input class="custom-input" v-model="name" placeholder="请输入姓名" placeholder-class="input-placeholder" />
  50. </view>
  51. <!-- 邮箱 -->
  52. <view class="input-group">
  53. <view class="input-icon-wrap">
  54. <uni-icons type="email" size="18" color="#ffc837"></uni-icons>
  55. </view>
  56. <input class="custom-input" v-model="email" placeholder="请输入邮箱" placeholder-class="input-placeholder" />
  57. </view>
  58. <!-- 密码 -->
  59. <view class="input-group">
  60. <view class="input-icon-wrap">
  61. <uni-icons type="locked" size="18" color="#ffc837"></uni-icons>
  62. </view>
  63. <input class="custom-input" v-model="password" type="password" placeholder="请输入密码"
  64. placeholder-class="input-placeholder" />
  65. </view>
  66. <!-- 确认密码 -->
  67. <view class="input-group">
  68. <view class="input-icon-wrap">
  69. <uni-icons type="locked" size="18" color="#ffc837"></uni-icons>
  70. </view>
  71. <input class="custom-input" v-model="confirmPassword" type="password" placeholder="请再次输入密码"
  72. placeholder-class="input-placeholder" />
  73. </view>
  74. <!-- 协议勾选 -->
  75. <view class="agreement-row">
  76. <checkbox-group @change="onCheckChange">
  77. <label class="agree-label">
  78. <checkbox :checked="checked" color="#ffc837" style="transform: scale(0.7);" />
  79. <text class="agree-text">我已阅读并同意</text>
  80. <text class="text-link" @click.stop="showAgreement(2)">《隐私政策》</text>
  81. <text class="agree-text">和</text>
  82. <text class="text-link" @click.stop="showAgreement(1)">《用户服务协议》</text>
  83. </label>
  84. </checkbox-group>
  85. </view>
  86. <!-- 提交注册按钮 -->
  87. <button class="login-btn" @click="onSubmit">提交注册申请</button>
  88. <!-- 返回登录 -->
  89. <view class="register-redirect-row">
  90. <text class="redirect-hint">已有账号?</text>
  91. <text class="redirect-action" @click="goToLogin">立即登录</text>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script setup>
  97. import { ref } from 'vue'
  98. import navBar from '@/components/nav-bar/index.vue'
  99. import { register } from '@/api/auth'
  100. const avatar = ref('')
  101. const companyName = ref('')
  102. const username = ref('')
  103. const name = ref('')
  104. const email = ref('')
  105. const password = ref('')
  106. const confirmPassword = ref('')
  107. const checked = ref(false)
  108. const onChooseAvatar = () => {
  109. uni.chooseImage({
  110. count: 1,
  111. success: (res) => {
  112. avatar.value = res.tempFilePaths[0]
  113. }
  114. })
  115. }
  116. const onCheckChange = () => {
  117. checked.value = !checked.value
  118. }
  119. const goToLogin = () => {
  120. uni.reLaunch({
  121. url: '/pages/login/index'
  122. })
  123. }
  124. const onClickLeft = () => {
  125. uni.navigateBack({
  126. fail: () => {
  127. goToLogin()
  128. }
  129. })
  130. }
  131. const showAgreement = (agreementId) => {
  132. const title = agreementId === 1 ? '用户服务协议' : '隐私政策'
  133. uni.navigateTo({
  134. url: `/pages/my/agreement/detail/index?id=${agreementId}&title=${encodeURIComponent(title)}`
  135. })
  136. }
  137. const onSubmit = async () => {
  138. // 1. 商户名称验证
  139. if (!companyName.value) {
  140. uni.showToast({ title: '请输入商户名称', icon: 'none' })
  141. return
  142. }
  143. if (companyName.value.length < 2 || companyName.value.length > 50) {
  144. uni.showToast({ title: '商户名称长度需在 2 到 50 个字符之间', icon: 'none' })
  145. return
  146. }
  147. // 2. 用户账号验证
  148. if (!username.value) {
  149. uni.showToast({ title: '请输入用户账号', icon: 'none' })
  150. return
  151. }
  152. const usernameRegex = /^[a-zA-Z0-9_-]{4,20}$/
  153. if (!usernameRegex.test(username.value)) {
  154. uni.showToast({ title: '账号必须为 4 到 20 位字母、数字、下划线或减号', icon: 'none' })
  155. return
  156. }
  157. // 3. 姓名验证
  158. if (!name.value) {
  159. uni.showToast({ title: '请输入姓名', icon: 'none' })
  160. return
  161. }
  162. if (name.value.length < 2 || name.value.length > 20) {
  163. uni.showToast({ title: '姓名长度需在 2 到 20 个字符之间', icon: 'none' })
  164. return
  165. }
  166. // 4. 邮箱验证
  167. if (!email.value) {
  168. uni.showToast({ title: '请输入邮箱', icon: 'none' })
  169. return
  170. }
  171. const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
  172. if (!emailRegex.test(email.value)) {
  173. uni.showToast({ title: '请输入正确的邮箱格式', icon: 'none' })
  174. return
  175. }
  176. // 5. 密码验证
  177. if (!password.value) {
  178. uni.showToast({ title: '请输入密码', icon: 'none' })
  179. return
  180. }
  181. if (password.value.length < 6 || password.value.length > 20) {
  182. uni.showToast({ title: '密码长度需在 6 到 20 个字符之间', icon: 'none' })
  183. return
  184. }
  185. // 6. 确认密码验证
  186. if (!confirmPassword.value) {
  187. uni.showToast({ title: '请再次输入密码', icon: 'none' })
  188. return
  189. }
  190. if (password.value !== confirmPassword.value) {
  191. uni.showToast({ title: '两次输入的密码不一致', icon: 'none' })
  192. return
  193. }
  194. // 7. 协议勾选验证
  195. if (!checked.value) {
  196. uni.showToast({ title: '请先阅读并勾选协议', icon: 'none' })
  197. return
  198. }
  199. try {
  200. uni.showLoading({ title: '提交申请中...' })
  201. await register({
  202. avatar: avatar.value,
  203. companyName: companyName.value,
  204. username: username.value,
  205. name: name.value,
  206. email: email.value,
  207. password: password.value,
  208. confirmPassword: confirmPassword.value
  209. })
  210. uni.hideLoading()
  211. uni.showToast({
  212. title: '提交成功',
  213. icon: 'success'
  214. })
  215. // 缓存商户名称和提交时间,供审核界面展示使用
  216. uni.setStorageSync('registered_merchant', companyName.value)
  217. uni.setStorageSync('registered_time', new Date().toLocaleString())
  218. setTimeout(() => {
  219. uni.reLaunch({
  220. url: '/pages/login/review'
  221. })
  222. }, 1000)
  223. } catch (error) {
  224. console.error('Register error:', error)
  225. uni.hideLoading()
  226. setTimeout(() => {
  227. uni.showToast({ title: typeof error === 'string' ? error : '注册提交失败', icon: 'none' })
  228. }, 100)
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .login-page {
  234. min-height: 100vh;
  235. background: #f2f3f7;
  236. display: flex;
  237. flex-direction: column;
  238. }
  239. :deep(.nav-bar) {
  240. position: absolute !important;
  241. }
  242. .back-btn {
  243. position: absolute;
  244. top: calc(var(--status-bar-height, 44px) + 20rpx);
  245. left: 32rpx;
  246. width: 76rpx;
  247. height: 76rpx;
  248. border-radius: 50%;
  249. background: rgba(255, 255, 255, 0.35);
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  254. z-index: 1000;
  255. }
  256. .hero-bg {
  257. background: linear-gradient(150deg, #ffd53f 0%, #ff9500 100%);
  258. padding: 0 40rpx 80rpx;
  259. position: relative;
  260. overflow: hidden;
  261. min-height: 300rpx;
  262. display: flex;
  263. flex-direction: column;
  264. justify-content: flex-end;
  265. }
  266. .deco-circle {
  267. position: absolute;
  268. border-radius: 50%;
  269. background: rgba(255, 255, 255, 0.12);
  270. }
  271. .c1 {
  272. width: 400rpx;
  273. height: 400rpx;
  274. top: -160rpx;
  275. right: -120rpx;
  276. }
  277. .c2 {
  278. width: 260rpx;
  279. height: 260rpx;
  280. top: 80rpx;
  281. left: -100rpx;
  282. }
  283. .c3 {
  284. width: 160rpx;
  285. height: 160rpx;
  286. bottom: 80rpx;
  287. right: 80rpx;
  288. }
  289. .hero-content {
  290. position: relative;
  291. z-index: 2;
  292. }
  293. .brand-desc {
  294. display: block;
  295. font-size: 28rpx;
  296. color: rgba(255, 255, 255, 0.8);
  297. letter-spacing: 2rpx;
  298. }
  299. .form-card {
  300. background: #fff;
  301. border-radius: 56rpx 56rpx 0 0;
  302. margin-top: -60rpx;
  303. padding: 60rpx 48rpx 60rpx;
  304. flex: 1;
  305. position: relative;
  306. z-index: 10;
  307. }
  308. .input-group {
  309. display: flex;
  310. align-items: center;
  311. background: #f5f6f8;
  312. border-radius: 28rpx;
  313. padding: 0 32rpx;
  314. height: 100rpx;
  315. margin-bottom: 32rpx;
  316. }
  317. .input-icon-wrap {
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. margin-right: 20rpx;
  322. }
  323. .custom-input {
  324. flex: 1;
  325. height: 100rpx;
  326. font-size: 28rpx;
  327. color: #333;
  328. }
  329. .input-placeholder {
  330. color: #bbb;
  331. }
  332. .agreement-row {
  333. margin: 32rpx 0 48rpx 0;
  334. }
  335. .agree-label {
  336. display: flex;
  337. align-items: center;
  338. flex-wrap: wrap;
  339. }
  340. .agree-text {
  341. font-size: 24rpx;
  342. color: #999;
  343. }
  344. .text-link {
  345. font-size: 24rpx;
  346. color: #ff9500;
  347. }
  348. .login-btn {
  349. width: 100%;
  350. height: 104rpx;
  351. font-size: 34rpx;
  352. font-weight: 700;
  353. color: #fff;
  354. background: linear-gradient(90deg, #ffd53f, #ff9500);
  355. border: none;
  356. border-radius: 52rpx;
  357. letter-spacing: 4rpx;
  358. &::after {
  359. border: none;
  360. }
  361. }
  362. .register-redirect-row {
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. margin-top: 36rpx;
  367. font-size: 26rpx;
  368. }
  369. .redirect-hint {
  370. color: #999;
  371. }
  372. .redirect-action {
  373. color: #ff9500;
  374. font-weight: bold;
  375. margin-left: 12rpx;
  376. text-decoration: underline;
  377. }
  378. .custom-picker {
  379. flex: 1;
  380. height: 100rpx;
  381. }
  382. .picker-value {
  383. height: 100rpx;
  384. line-height: 100rpx;
  385. font-size: 28rpx;
  386. color: #333;
  387. text-align: left;
  388. }
  389. .picker-value.placeholder {
  390. color: #bbb;
  391. }
  392. .textarea-group {
  393. height: auto;
  394. align-items: flex-start;
  395. padding-top: 24rpx;
  396. padding-bottom: 24rpx;
  397. }
  398. .textarea-icon-wrap {
  399. margin-top: 4rpx;
  400. }
  401. .custom-textarea {
  402. flex: 1;
  403. height: 140rpx;
  404. font-size: 28rpx;
  405. color: #333;
  406. line-height: 1.4;
  407. }
  408. .avatar-upload-wrap {
  409. display: flex;
  410. justify-content: center;
  411. margin-bottom: 40rpx;
  412. }
  413. .avatar-placeholder {
  414. width: 160rpx;
  415. height: 160rpx;
  416. background: #f5f6f8;
  417. border-radius: 50%;
  418. display: flex;
  419. flex-direction: column;
  420. align-items: center;
  421. justify-content: center;
  422. border: 2rpx dashed #d9d9d9;
  423. }
  424. .avatar-image {
  425. width: 160rpx;
  426. height: 160rpx;
  427. border-radius: 50%;
  428. border: 2rpx solid #eee;
  429. }
  430. .avatar-text {
  431. font-size: 20rpx;
  432. color: #999;
  433. margin-top: 8rpx;
  434. }
  435. </style>