register.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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="请输入姓名"
  50. placeholder-class="input-placeholder" />
  51. </view>
  52. <!-- 邮箱 -->
  53. <view class="input-group">
  54. <view class="input-icon-wrap">
  55. <uni-icons type="email" size="18" color="#ffc837"></uni-icons>
  56. </view>
  57. <input class="custom-input" v-model="email" placeholder="请输入邮箱"
  58. placeholder-class="input-placeholder" />
  59. </view>
  60. <!-- 密码 -->
  61. <view class="input-group">
  62. <view class="input-icon-wrap">
  63. <uni-icons type="locked" size="18" color="#ffc837"></uni-icons>
  64. </view>
  65. <input class="custom-input" v-model="password" type="password" placeholder="请输入密码"
  66. placeholder-class="input-placeholder" />
  67. </view>
  68. <!-- 确认密码 -->
  69. <view class="input-group">
  70. <view class="input-icon-wrap">
  71. <uni-icons type="locked" size="18" color="#ffc837"></uni-icons>
  72. </view>
  73. <input class="custom-input" v-model="confirmPassword" type="password" placeholder="请再次输入密码"
  74. placeholder-class="input-placeholder" />
  75. </view>
  76. <!-- 协议勾选 -->
  77. <view class="agreement-row">
  78. <checkbox-group @change="onCheckChange">
  79. <label class="agree-label">
  80. <checkbox :checked="checked" color="#ffc837" style="transform: scale(0.7);" />
  81. <text class="agree-text">我已阅读并同意</text>
  82. <text class="text-link" @click.stop="showAgreement(2)">《隐私政策》</text>
  83. <text class="agree-text">和</text>
  84. <text class="text-link" @click.stop="showAgreement(4)">《托运协议》</text>
  85. </label>
  86. </checkbox-group>
  87. </view>
  88. <!-- 提交注册按钮 -->
  89. <button class="login-btn" @click="onSubmit">提交注册申请</button>
  90. <!-- 返回登录 -->
  91. <view class="register-redirect-row">
  92. <text class="redirect-hint">已有账号?</text>
  93. <text class="redirect-action" @click="goToLogin">立即登录</text>
  94. </view>
  95. </view>
  96. <!-- 隐私政策/托运协议弹窗 -->
  97. <policy-dialog v-model:visible="dialogVisible" :title="dialogTitle" :content="dialogContent"></policy-dialog>
  98. </view>
  99. </template>
  100. <script setup>
  101. import { ref } from 'vue'
  102. import navBar from '@/components/nav-bar/index.vue'
  103. import policyDialog from '@/components/policy-dialog/index.vue'
  104. import { getAgreement } from '@/api/system/agreement'
  105. import { register } from '@/api/auth'
  106. const avatar = ref('')
  107. const companyName = ref('')
  108. const username = ref('')
  109. const name = ref('')
  110. const email = ref('')
  111. const password = ref('')
  112. const confirmPassword = ref('')
  113. const checked = ref(false)
  114. const dialogVisible = ref(false)
  115. const dialogTitle = ref('')
  116. const dialogContent = ref('')
  117. const onChooseAvatar = () => {
  118. uni.chooseImage({
  119. count: 1,
  120. success: (res) => {
  121. avatar.value = res.tempFilePaths[0]
  122. }
  123. })
  124. }
  125. const onCheckChange = () => {
  126. checked.value = !checked.value
  127. }
  128. const goToLogin = () => {
  129. uni.reLaunch({
  130. url: '/pages/login/index'
  131. })
  132. }
  133. const onClickLeft = () => {
  134. uni.navigateBack({
  135. fail: () => {
  136. goToLogin()
  137. }
  138. })
  139. }
  140. const showAgreement = async (agreementId) => {
  141. try {
  142. uni.showLoading({ title: '加载中...' })
  143. const res = await getAgreement(agreementId)
  144. if (res && res.title) {
  145. dialogTitle.value = res.title || '协议详情'
  146. let decodedContent = res.content || '暂无内容'
  147. if (res.content) {
  148. try {
  149. decodedContent = decodeURIComponent(escape(window.atob(res.content)))
  150. } catch (e) {
  151. decodedContent = res.content
  152. }
  153. }
  154. dialogContent.value = decodedContent
  155. dialogVisible.value = true
  156. } else {
  157. uni.showToast({ title: '数据格式异常', icon: 'none' })
  158. }
  159. } catch (error) {
  160. uni.showToast({ title: '加载失败,请稍后重试', icon: 'none' })
  161. } finally {
  162. uni.hideLoading()
  163. }
  164. }
  165. const onSubmit = async () => {
  166. // 1. 商户名称验证
  167. if (!companyName.value) {
  168. uni.showToast({ title: '请输入商户名称', icon: 'none' })
  169. return
  170. }
  171. if (companyName.value.length < 2 || companyName.value.length > 50) {
  172. uni.showToast({ title: '商户名称长度需在 2 到 50 个字符之间', icon: 'none' })
  173. return
  174. }
  175. // 2. 用户账号验证
  176. if (!username.value) {
  177. uni.showToast({ title: '请输入用户账号', icon: 'none' })
  178. return
  179. }
  180. const usernameRegex = /^[a-zA-Z0-9_-]{4,20}$/
  181. if (!usernameRegex.test(username.value)) {
  182. uni.showToast({ title: '账号必须为 4 到 20 位字母、数字、下划线或减号', icon: 'none' })
  183. return
  184. }
  185. // 3. 姓名验证
  186. if (!name.value) {
  187. uni.showToast({ title: '请输入姓名', icon: 'none' })
  188. return
  189. }
  190. if (name.value.length < 2 || name.value.length > 20) {
  191. uni.showToast({ title: '姓名长度需在 2 到 20 个字符之间', icon: 'none' })
  192. return
  193. }
  194. // 4. 邮箱验证
  195. if (!email.value) {
  196. uni.showToast({ title: '请输入邮箱', icon: 'none' })
  197. return
  198. }
  199. const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/
  200. if (!emailRegex.test(email.value)) {
  201. uni.showToast({ title: '请输入正确的邮箱格式', icon: 'none' })
  202. return
  203. }
  204. // 5. 密码验证
  205. if (!password.value) {
  206. uni.showToast({ title: '请输入密码', icon: 'none' })
  207. return
  208. }
  209. if (password.value.length < 6 || password.value.length > 20) {
  210. uni.showToast({ title: '密码长度需在 6 到 20 个字符之间', icon: 'none' })
  211. return
  212. }
  213. // 6. 确认密码验证
  214. if (!confirmPassword.value) {
  215. uni.showToast({ title: '请再次输入密码', icon: 'none' })
  216. return
  217. }
  218. if (password.value !== confirmPassword.value) {
  219. uni.showToast({ title: '两次输入的密码不一致', icon: 'none' })
  220. return
  221. }
  222. // 7. 协议勾选验证
  223. if (!checked.value) {
  224. uni.showToast({ title: '请先阅读并勾选协议', icon: 'none' })
  225. return
  226. }
  227. try {
  228. uni.showLoading({ title: '提交申请中...' })
  229. await register({
  230. avatar: avatar.value,
  231. companyName: companyName.value,
  232. username: username.value,
  233. name: name.value,
  234. email: email.value,
  235. password: password.value,
  236. confirmPassword: confirmPassword.value
  237. })
  238. uni.hideLoading()
  239. uni.showToast({
  240. title: '提交成功',
  241. icon: 'success'
  242. })
  243. // 缓存商户名称和提交时间,供审核界面展示使用
  244. uni.setStorageSync('registered_merchant', companyName.value)
  245. uni.setStorageSync('registered_time', new Date().toLocaleString())
  246. setTimeout(() => {
  247. uni.reLaunch({
  248. url: '/pages/login/review'
  249. })
  250. }, 1000)
  251. } catch (error) {
  252. console.error('Register error:', error)
  253. uni.hideLoading()
  254. setTimeout(() => {
  255. uni.showToast({ title: typeof error === 'string' ? error : '注册提交失败', icon: 'none' })
  256. }, 100)
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .login-page {
  262. min-height: 100vh;
  263. background: #f2f3f7;
  264. display: flex;
  265. flex-direction: column;
  266. }
  267. :deep(.nav-bar) {
  268. position: absolute !important;
  269. }
  270. .back-btn {
  271. position: absolute;
  272. top: calc(var(--status-bar-height, 44px) + 20rpx);
  273. left: 32rpx;
  274. width: 76rpx;
  275. height: 76rpx;
  276. border-radius: 50%;
  277. background: rgba(255, 255, 255, 0.35);
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  282. z-index: 1000;
  283. }
  284. .hero-bg {
  285. background: linear-gradient(150deg, #ffd53f 0%, #ff9500 100%);
  286. padding: 0 40rpx 80rpx;
  287. position: relative;
  288. overflow: hidden;
  289. min-height: 300rpx;
  290. display: flex;
  291. flex-direction: column;
  292. justify-content: flex-end;
  293. }
  294. .deco-circle {
  295. position: absolute;
  296. border-radius: 50%;
  297. background: rgba(255, 255, 255, 0.12);
  298. }
  299. .c1 {
  300. width: 400rpx;
  301. height: 400rpx;
  302. top: -160rpx;
  303. right: -120rpx;
  304. }
  305. .c2 {
  306. width: 260rpx;
  307. height: 260rpx;
  308. top: 80rpx;
  309. left: -100rpx;
  310. }
  311. .c3 {
  312. width: 160rpx;
  313. height: 160rpx;
  314. bottom: 80rpx;
  315. right: 80rpx;
  316. }
  317. .hero-content {
  318. position: relative;
  319. z-index: 2;
  320. }
  321. .brand-desc {
  322. display: block;
  323. font-size: 28rpx;
  324. color: rgba(255, 255, 255, 0.8);
  325. letter-spacing: 2rpx;
  326. }
  327. .form-card {
  328. background: #fff;
  329. border-radius: 56rpx 56rpx 0 0;
  330. margin-top: -60rpx;
  331. padding: 60rpx 48rpx 60rpx;
  332. flex: 1;
  333. position: relative;
  334. z-index: 10;
  335. }
  336. .input-group {
  337. display: flex;
  338. align-items: center;
  339. background: #f5f6f8;
  340. border-radius: 28rpx;
  341. padding: 0 32rpx;
  342. height: 100rpx;
  343. margin-bottom: 32rpx;
  344. }
  345. .input-icon-wrap {
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. margin-right: 20rpx;
  350. }
  351. .custom-input {
  352. flex: 1;
  353. height: 100rpx;
  354. font-size: 28rpx;
  355. color: #333;
  356. }
  357. .input-placeholder {
  358. color: #bbb;
  359. }
  360. .agreement-row {
  361. margin: 32rpx 0 48rpx 0;
  362. }
  363. .agree-label {
  364. display: flex;
  365. align-items: center;
  366. flex-wrap: wrap;
  367. }
  368. .agree-text {
  369. font-size: 24rpx;
  370. color: #999;
  371. }
  372. .text-link {
  373. font-size: 24rpx;
  374. color: #ff9500;
  375. }
  376. .login-btn {
  377. width: 100%;
  378. height: 104rpx;
  379. font-size: 34rpx;
  380. font-weight: 700;
  381. color: #fff;
  382. background: linear-gradient(90deg, #ffd53f, #ff9500);
  383. border: none;
  384. border-radius: 52rpx;
  385. letter-spacing: 4rpx;
  386. &::after { border: none; }
  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>