register.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. <!-- 隐私政策/用户服务协议弹窗 -->
  95. <policy-dialog v-model:visible="dialogVisible" :title="dialogTitle" :content="dialogContent"></policy-dialog>
  96. </view>
  97. </template>
  98. <script setup>
  99. import { ref } from 'vue'
  100. import navBar from '@/components/nav-bar/index.vue'
  101. import policyDialog from '@/components/policy-dialog/index.vue'
  102. import { getAgreement } from '@/api/system/agreement'
  103. import { register } from '@/api/auth'
  104. const avatar = ref('')
  105. const companyName = ref('')
  106. const username = ref('')
  107. const name = ref('')
  108. const email = ref('')
  109. const password = ref('')
  110. const confirmPassword = ref('')
  111. const checked = ref(false)
  112. const dialogVisible = ref(false)
  113. const dialogTitle = ref('')
  114. const dialogContent = ref('')
  115. const onChooseAvatar = () => {
  116. uni.chooseImage({
  117. count: 1,
  118. success: (res) => {
  119. avatar.value = res.tempFilePaths[0]
  120. }
  121. })
  122. }
  123. const onCheckChange = () => {
  124. checked.value = !checked.value
  125. }
  126. const goToLogin = () => {
  127. uni.reLaunch({
  128. url: '/pages/login/index'
  129. })
  130. }
  131. const onClickLeft = () => {
  132. uni.navigateBack({
  133. fail: () => {
  134. goToLogin()
  135. }
  136. })
  137. }
  138. const showAgreement = async (agreementId) => {
  139. try {
  140. uni.showLoading({ title: '加载中...' })
  141. const res = await getAgreement(agreementId)
  142. if (res && res.title) {
  143. dialogTitle.value = res.title || '协议详情'
  144. let decodedContent = res.content || '暂无内容'
  145. if (res.content) {
  146. try {
  147. decodedContent = decodeURIComponent(escape(window.atob(res.content)))
  148. } catch (e) {
  149. decodedContent = res.content
  150. }
  151. }
  152. dialogContent.value = decodedContent
  153. dialogVisible.value = true
  154. } else {
  155. uni.showToast({ title: '数据格式异常', icon: 'none' })
  156. }
  157. } catch (error) {
  158. uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' })
  159. } finally {
  160. uni.hideLoading()
  161. }
  162. }
  163. const onSubmit = async () => {
  164. // 1. 商户名称验证
  165. if (!companyName.value) {
  166. uni.showToast({ title: '请输入商户名称', icon: 'none' })
  167. return
  168. }
  169. if (companyName.value.length < 2 || companyName.value.length > 50) {
  170. uni.showToast({ title: '商户名称长度需在 2 到 50 个字符之间', icon: 'none' })
  171. return
  172. }
  173. // 2. 用户账号验证
  174. if (!username.value) {
  175. uni.showToast({ title: '请输入用户账号', icon: 'none' })
  176. return
  177. }
  178. const usernameRegex = /^[a-zA-Z0-9_-]{4,20}$/
  179. if (!usernameRegex.test(username.value)) {
  180. uni.showToast({ title: '账号必须为 4 到 20 位字母、数字、下划线或减号', icon: 'none' })
  181. return
  182. }
  183. // 3. 姓名验证
  184. if (!name.value) {
  185. uni.showToast({ title: '请输入姓名', icon: 'none' })
  186. return
  187. }
  188. if (name.value.length < 2 || name.value.length > 20) {
  189. uni.showToast({ title: '姓名长度需在 2 到 20 个字符之间', icon: 'none' })
  190. return
  191. }
  192. // 4. 邮箱验证
  193. if (!email.value) {
  194. uni.showToast({ title: '请输入邮箱', icon: 'none' })
  195. return
  196. }
  197. const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
  198. if (!emailRegex.test(email.value)) {
  199. uni.showToast({ title: '请输入正确的邮箱格式', icon: 'none' })
  200. return
  201. }
  202. // 5. 密码验证
  203. if (!password.value) {
  204. uni.showToast({ title: '请输入密码', icon: 'none' })
  205. return
  206. }
  207. if (password.value.length < 6 || password.value.length > 20) {
  208. uni.showToast({ title: '密码长度需在 6 到 20 个字符之间', icon: 'none' })
  209. return
  210. }
  211. // 6. 确认密码验证
  212. if (!confirmPassword.value) {
  213. uni.showToast({ title: '请再次输入密码', icon: 'none' })
  214. return
  215. }
  216. if (password.value !== confirmPassword.value) {
  217. uni.showToast({ title: '两次输入的密码不一致', icon: 'none' })
  218. return
  219. }
  220. // 7. 协议勾选验证
  221. if (!checked.value) {
  222. uni.showToast({ title: '请先阅读并勾选协议', icon: 'none' })
  223. return
  224. }
  225. try {
  226. uni.showLoading({ title: '提交申请中...' })
  227. await register({
  228. avatar: avatar.value,
  229. companyName: companyName.value,
  230. username: username.value,
  231. name: name.value,
  232. email: email.value,
  233. password: password.value,
  234. confirmPassword: confirmPassword.value
  235. })
  236. uni.hideLoading()
  237. uni.showToast({
  238. title: '提交成功',
  239. icon: 'success'
  240. })
  241. // 缓存商户名称和提交时间,供审核界面展示使用
  242. uni.setStorageSync('registered_merchant', companyName.value)
  243. uni.setStorageSync('registered_time', new Date().toLocaleString())
  244. setTimeout(() => {
  245. uni.reLaunch({
  246. url: '/pages/login/review'
  247. })
  248. }, 1000)
  249. } catch (error) {
  250. console.error('Register error:', error)
  251. uni.hideLoading()
  252. setTimeout(() => {
  253. uni.showToast({ title: typeof error === 'string' ? error : '注册提交失败', icon: 'none' })
  254. }, 100)
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .login-page {
  260. min-height: 100vh;
  261. background: #f2f3f7;
  262. display: flex;
  263. flex-direction: column;
  264. }
  265. :deep(.nav-bar) {
  266. position: absolute !important;
  267. }
  268. .back-btn {
  269. position: absolute;
  270. top: calc(var(--status-bar-height, 44px) + 20rpx);
  271. left: 32rpx;
  272. width: 76rpx;
  273. height: 76rpx;
  274. border-radius: 50%;
  275. background: rgba(255, 255, 255, 0.35);
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  280. z-index: 1000;
  281. }
  282. .hero-bg {
  283. background: linear-gradient(150deg, #ffd53f 0%, #ff9500 100%);
  284. padding: 0 40rpx 80rpx;
  285. position: relative;
  286. overflow: hidden;
  287. min-height: 300rpx;
  288. display: flex;
  289. flex-direction: column;
  290. justify-content: flex-end;
  291. }
  292. .deco-circle {
  293. position: absolute;
  294. border-radius: 50%;
  295. background: rgba(255, 255, 255, 0.12);
  296. }
  297. .c1 {
  298. width: 400rpx;
  299. height: 400rpx;
  300. top: -160rpx;
  301. right: -120rpx;
  302. }
  303. .c2 {
  304. width: 260rpx;
  305. height: 260rpx;
  306. top: 80rpx;
  307. left: -100rpx;
  308. }
  309. .c3 {
  310. width: 160rpx;
  311. height: 160rpx;
  312. bottom: 80rpx;
  313. right: 80rpx;
  314. }
  315. .hero-content {
  316. position: relative;
  317. z-index: 2;
  318. }
  319. .brand-desc {
  320. display: block;
  321. font-size: 28rpx;
  322. color: rgba(255, 255, 255, 0.8);
  323. letter-spacing: 2rpx;
  324. }
  325. .form-card {
  326. background: #fff;
  327. border-radius: 56rpx 56rpx 0 0;
  328. margin-top: -60rpx;
  329. padding: 60rpx 48rpx 60rpx;
  330. flex: 1;
  331. position: relative;
  332. z-index: 10;
  333. }
  334. .input-group {
  335. display: flex;
  336. align-items: center;
  337. background: #f5f6f8;
  338. border-radius: 28rpx;
  339. padding: 0 32rpx;
  340. height: 100rpx;
  341. margin-bottom: 32rpx;
  342. }
  343. .input-icon-wrap {
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. margin-right: 20rpx;
  348. }
  349. .custom-input {
  350. flex: 1;
  351. height: 100rpx;
  352. font-size: 28rpx;
  353. color: #333;
  354. }
  355. .input-placeholder {
  356. color: #bbb;
  357. }
  358. .agreement-row {
  359. margin: 32rpx 0 48rpx 0;
  360. }
  361. .agree-label {
  362. display: flex;
  363. align-items: center;
  364. flex-wrap: wrap;
  365. }
  366. .agree-text {
  367. font-size: 24rpx;
  368. color: #999;
  369. }
  370. .text-link {
  371. font-size: 24rpx;
  372. color: #ff9500;
  373. }
  374. .login-btn {
  375. width: 100%;
  376. height: 104rpx;
  377. font-size: 34rpx;
  378. font-weight: 700;
  379. color: #fff;
  380. background: linear-gradient(90deg, #ffd53f, #ff9500);
  381. border: none;
  382. border-radius: 52rpx;
  383. letter-spacing: 4rpx;
  384. &::after {
  385. border: none;
  386. }
  387. }
  388. .register-redirect-row {
  389. display: flex;
  390. justify-content: center;
  391. align-items: center;
  392. margin-top: 36rpx;
  393. font-size: 26rpx;
  394. }
  395. .redirect-hint {
  396. color: #999;
  397. }
  398. .redirect-action {
  399. color: #ff9500;
  400. font-weight: bold;
  401. margin-left: 12rpx;
  402. text-decoration: underline;
  403. }
  404. .custom-picker {
  405. flex: 1;
  406. height: 100rpx;
  407. }
  408. .picker-value {
  409. height: 100rpx;
  410. line-height: 100rpx;
  411. font-size: 28rpx;
  412. color: #333;
  413. text-align: left;
  414. }
  415. .picker-value.placeholder {
  416. color: #bbb;
  417. }
  418. .textarea-group {
  419. height: auto;
  420. align-items: flex-start;
  421. padding-top: 24rpx;
  422. padding-bottom: 24rpx;
  423. }
  424. .textarea-icon-wrap {
  425. margin-top: 4rpx;
  426. }
  427. .custom-textarea {
  428. flex: 1;
  429. height: 140rpx;
  430. font-size: 28rpx;
  431. color: #333;
  432. line-height: 1.4;
  433. }
  434. .avatar-upload-wrap {
  435. display: flex;
  436. justify-content: center;
  437. margin-bottom: 40rpx;
  438. }
  439. .avatar-placeholder {
  440. width: 160rpx;
  441. height: 160rpx;
  442. background: #f5f6f8;
  443. border-radius: 50%;
  444. display: flex;
  445. flex-direction: column;
  446. align-items: center;
  447. justify-content: center;
  448. border: 2rpx dashed #d9d9d9;
  449. }
  450. .avatar-image {
  451. width: 160rpx;
  452. height: 160rpx;
  453. border-radius: 50%;
  454. border: 2rpx solid #eee;
  455. }
  456. .avatar-text {
  457. font-size: 20rpx;
  458. color: #999;
  459. margin-top: 8rpx;
  460. }
  461. </style>