register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <view class="container">
  3. <view class="bg-shape shadow"></view>
  4. <view class="bg-shape2 shadow"></view>
  5. <view class="register-box">
  6. <view class="header">
  7. <text class="title">账号注册</text>
  8. <text class="subtitle">欢迎开启您的科研工作之旅</text>
  9. </view>
  10. <view class="step-nav">
  11. <uv-steps :current="active" activeColor="#3b82f6" inactiveColor="#94a3b8" customStyle="padding: 0 40rpx;">
  12. <uv-steps-item title="账号设置"></uv-steps-item>
  13. <uv-steps-item title="基本信息"></uv-steps-item>
  14. </uv-steps>
  15. </view>
  16. <scroll-view scroll-y class="form-scroll-view" :show-scrollbar="false">
  17. <view class="form-content">
  18. <!-- Step 0: 登录信息 -->
  19. <view v-if="active === 0" class="step-wrapper">
  20. <view class="form-group">
  21. <text class="label">登录账号<text class="required">*</text></text>
  22. <uv-input v-model="form.userName" placeholder="请输入登录账号" border="none" @blur="checkUsername" clearable
  23. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  24. <template #prefix>
  25. <uv-icon name="account" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  26. </template>
  27. </uv-input>
  28. </view>
  29. <view class="form-group">
  30. <text class="label">密码<text class="required">*</text></text>
  31. <uv-input v-model="form.password" :type="showPassword ? 'text' : 'password'" clearable
  32. placeholder="请输入密码" border="none" @blur="checkPasswordValidate"
  33. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  34. <template #prefix>
  35. <uv-icon name="lock" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  36. </template>
  37. <template #suffix>
  38. <uv-icon :name="showPassword ? 'eye-fill' : 'eye-off'" size="20" color="#94a3b8"
  39. @click="showPassword = !showPassword" customStyle="margin-left: 16rpx"></uv-icon>
  40. </template>
  41. </uv-input>
  42. </view>
  43. <view class="form-group">
  44. <text class="label">确认密码<text class="required">*</text></text>
  45. <uv-input v-model="form.confirmPassword" :type="showConfirmPassword ? 'text' : 'password'" clearable
  46. placeholder="请再次填写密码" border="none"
  47. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  48. <template #prefix>
  49. <uv-icon name="lock-fill" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  50. </template>
  51. <template #suffix>
  52. <uv-icon :name="showConfirmPassword ? 'eye-fill' : 'eye-off'" size="20" color="#94a3b8"
  53. @click="showConfirmPassword = !showConfirmPassword" customStyle="margin-left: 16rpx"></uv-icon>
  54. </template>
  55. </uv-input>
  56. </view>
  57. <view class="password-hint">
  58. <text>提示:密码需包含大小写字母、数字和特殊字符,长度在10-20位</text>
  59. </view>
  60. </view>
  61. <!-- Step 1: 个人信息 -->
  62. <view v-if="active === 1" class="step-wrapper">
  63. <view class="form-group">
  64. <text class="label">姓名<text class="required">*</text></text>
  65. <uv-input v-model="form.nickName" placeholder="请输入您的姓名" border="none" clearable
  66. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  67. <template #prefix>
  68. <uv-icon name="account" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  69. </template>
  70. </uv-input>
  71. </view>
  72. <view class="form-group">
  73. <text class="label">性别<text class="required">*</text></text>
  74. <view class="radio-box">
  75. <uv-radio-group v-model="form.sex" placement="row">
  76. <uv-radio v-for="(item, index) in sexOptions" :key="index" :name="item.dictValue"
  77. :label="item.dictLabel" customStyle="margin-right: 40rpx;"></uv-radio>
  78. </uv-radio-group>
  79. </view>
  80. </view>
  81. <view class="form-group">
  82. <text class="label">组织部门<text class="required">*</text></text>
  83. <view class="selector-box" @click="handleOpenDept">
  84. <uv-icon name="tags" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  85. <text v-if="form.deptName" class="val">{{ form.deptName }}</text>
  86. <text v-else class="placeholder">请选择所在部门</text>
  87. <uv-icon name="arrow-right" size="14" color="#94a3b8" customStyle="margin-left: auto"></uv-icon>
  88. </view>
  89. </view>
  90. <view class="form-group" v-if="form.deptId === 999999">
  91. <text class="label">单位名称<text class="required">*</text></text>
  92. <uv-input v-model="form.unitName" placeholder="请输入单位名称" border="none"
  93. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  94. <template #prefix>
  95. <uv-icon name="home" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  96. </template>
  97. </uv-input>
  98. </view>
  99. <view class="form-group">
  100. <text class="label">手机号码<text class="required">*</text></text>
  101. <uv-input v-model="form.phone" type="number" maxlength="11" placeholder="用于接收重要通知" border="none" clearable
  102. @blur="checkPhone" customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  103. <template #prefix>
  104. <uv-icon name="phone" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  105. </template>
  106. </uv-input>
  107. </view>
  108. <view class="form-group">
  109. <text class="label">电子邮箱<text class="required">*</text></text>
  110. <uv-input v-model="form.email" placeholder="请输入常用的邮箱" border="none" clearable
  111. customStyle="background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  112. <template #prefix>
  113. <uv-icon name="email" size="20" color="#94a3b8" customStyle="margin-right: 16rpx"></uv-icon>
  114. </template>
  115. </uv-input>
  116. </view>
  117. <view class="form-group">
  118. <text class="label">证件号码<text class="required">*</text></text>
  119. <view class="id-group">
  120. <view class="id-type">{{ idTypeLabel }}</view>
  121. <uv-input v-model="form.idCode" placeholder="请输入证件号" border="none" clearable
  122. customStyle="flex: 1; background: #f1f5f9; padding: 24rpx 30rpx; border-radius: 20rpx;">
  123. </uv-input>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. </scroll-view>
  129. <view class="footer-actions">
  130. <view class="btn-group">
  131. <view class="btn-side" v-if="active > 0">
  132. <uv-button text="上一步" @click="preStep" plain color="#64748b"
  133. customStyle="height: 100rpx; border-radius: 50rpx; border-color: #e2e8f0; font-weight: 600;"></uv-button>
  134. </view>
  135. <view class="btn-main">
  136. <uv-button v-if="active === 0" text="下一步" @click="nextStep" shape="circle"
  137. color="linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)"
  138. customStyle="height: 100rpx; font-size: 30rpx; font-weight: 600; box-shadow: 0 10rpx 20rpx rgba(37, 99, 235, 0.2); border: none;"></uv-button>
  139. <uv-button v-if="active === 1" text="立即提交注册" @click="onRegister" :loading="loading" shape="circle"
  140. color="linear-gradient(135deg, #059669 0%, #10b981 100%)"
  141. customStyle="height: 100rpx; font-size: 30rpx; font-weight: 600; box-shadow: 0 10rpx 20rpx rgba(16, 185, 129, 0.2); border: none;"></uv-button>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. <uv-toast ref="toastRef"></uv-toast>
  147. <!-- 部门选择组件 -->
  148. <SelectDept ref="selectDeptRef" :treeData="deptTree" v-model="form.deptId" @select="onDeptSelect" />
  149. </view>
  150. </template>
  151. <script setup lang="ts">
  152. import { ref, reactive, computed } from 'vue';
  153. import { onLoad } from '@dcloudio/uni-app';
  154. import { useSystemApi, useDeptApi } from '@/api/system/index';
  155. import { useLoginApi } from '@/api/system/login';
  156. import { encryptWithBackendConfig } from '@/utils/aesCrypto';
  157. import smCrypto from 'sm-crypto';
  158. import SelectDept from '@/components/SelectDept/index.vue';
  159. const sm3 = smCrypto.sm3;
  160. const systemApi = useSystemApi();
  161. const deptApi = useDeptApi();
  162. const loginApi = useLoginApi();
  163. const active = ref(0);
  164. const loading = ref(false);
  165. const toastRef = ref();
  166. const selectDeptRef = ref();
  167. const showPassword = ref(false);
  168. const showConfirmPassword = ref(false);
  169. const deptTree = ref<any[]>([]);
  170. const sexOptions = ref<any[]>([]);
  171. const userCertList = ref<any[]>([]);
  172. const form = reactive({
  173. userName: '',
  174. password: '',
  175. confirmPassword: '',
  176. nickName: '',
  177. userType: '10',
  178. deptId: undefined as number | undefined,
  179. deptName: '',
  180. phone: '',
  181. email: '',
  182. sex: '30',
  183. idType: '20', // 默认身份证
  184. idCode: '',
  185. registerType: '10',
  186. saltValue: '',
  187. status: '10',
  188. unitName: '',
  189. });
  190. const idTypeLabel = computed(() => {
  191. if (userCertList.value.length > 0) {
  192. const cert = userCertList.value.find(item => item.dictValue === form.idType);
  193. if (cert) return cert.dictLabel;
  194. }
  195. return form.idType === '20' ? '身份证' : '其他证件';
  196. });
  197. const searchTree = (tree: any[], id: number): any => {
  198. for (const node of tree) {
  199. if (node.id === id) return node;
  200. if (node.children && node.children.length > 0) {
  201. const found = searchTree(node.children, id);
  202. if (found) return found;
  203. }
  204. }
  205. return null;
  206. };
  207. const initData = async () => {
  208. try {
  209. const results = await Promise.allSettled([
  210. systemApi.getDictDataByType('sys_com_sex'),
  211. deptApi.getDeptTree({}),
  212. systemApi.getDictDataByType('sys_user_certificate')
  213. ]);
  214. const dictRes = results[0].status === 'fulfilled' ? results[0].value : null;
  215. const deptRes = results[1].status === 'fulfilled' ? results[1].value : null;
  216. const certRes = results[2].status === 'fulfilled' ? results[2].value : null;
  217. if (dictRes && dictRes.code === 200 && dictRes.data) {
  218. sexOptions.value = dictRes.data.values || [];
  219. }
  220. if (certRes && certRes.code === 200 && certRes.data) {
  221. userCertList.value = certRes.data.values || [];
  222. }
  223. if (deptRes && deptRes.code === 200 && deptRes.data) {
  224. let tree = deptRes.data;
  225. if (form.userType === '10' && tree.length > 0) {
  226. const root = searchTree(tree, 100001);
  227. if (root) tree = [root];
  228. }
  229. deptTree.value = tree;
  230. }
  231. } catch (err) {
  232. console.error('Init data fail:', err);
  233. }
  234. };
  235. const handleOpenDept = () => {
  236. if (deptTree.value.length === 0) {
  237. uni.showLoading({ title: '加载中...' });
  238. initData().then(() => {
  239. uni.hideLoading();
  240. if (deptTree.value.length > 0) {
  241. selectDeptRef.value.open();
  242. } else {
  243. uni.showModal({ title: '提示', content: '未能获取到部门数据,请稍后重试', showCancel: false });
  244. }
  245. });
  246. return;
  247. }
  248. selectDeptRef.value.open();
  249. };
  250. const onDeptSelect = (item: any) => {
  251. form.deptName = item.deptName;
  252. };
  253. const checkUsername = async () => {
  254. if (!form.userName) return;
  255. try {
  256. await loginApi.checkUserNamePhoneExists({ userName: form.userName, phone: '' });
  257. } catch (err) { }
  258. };
  259. const checkPhone = async () => {
  260. if (!form.phone || form.phone.length !== 11) return;
  261. try {
  262. await loginApi.checkUserNamePhoneExists({ userName: '', phone: form.phone });
  263. } catch (err) { }
  264. };
  265. const checkPasswordValidate = async () => {
  266. if (!form.password) return;
  267. try {
  268. await loginApi.validatePassword({ password: form.password });
  269. } catch (err) { }
  270. };
  271. const validateStep0 = () => {
  272. if (!form.userName) {
  273. toastRef.value.show({ message: '请输入账户名称', type: 'error' });
  274. return false;
  275. }
  276. if (!form.password || form.password.length < 10 || form.password.length > 20) {
  277. toastRef.value.show({ message: '密码长度在10-20位之间', type: 'error' });
  278. return false;
  279. }
  280. if (form.password !== form.confirmPassword) {
  281. toastRef.value.show({ message: '两次密码输入不一致', type: 'error' });
  282. return false;
  283. }
  284. return true;
  285. };
  286. const validateStep1 = () => {
  287. if (!form.nickName) {
  288. toastRef.value.show({ message: '请输入姓名', type: 'error' });
  289. return false;
  290. }
  291. if (!form.deptId) {
  292. toastRef.value.show({ message: '请选择组织部门', type: 'error' });
  293. return false;
  294. }
  295. if (!form.phone || form.phone.length !== 11) {
  296. toastRef.value.show({ message: '请输入正确的手机号', type: 'error' });
  297. return false;
  298. }
  299. if (!form.idCode) {
  300. toastRef.value.show({ message: '请输入证件号', type: 'error' });
  301. return false;
  302. }
  303. return true;
  304. };
  305. const preStep = () => {
  306. active.value--;
  307. };
  308. const nextStep = () => {
  309. if (validateStep0()) {
  310. active.value++;
  311. }
  312. };
  313. const onRegister = async () => {
  314. if (validateStep1()) {
  315. loading.value = true;
  316. try {
  317. const params = JSON.parse(JSON.stringify(form));
  318. params.password = sm3(params.password);
  319. params.saltValue = encryptWithBackendConfig(params.password);
  320. delete params.confirmPassword;
  321. const res: any = await loginApi.register(params);
  322. if (res.code === 200) {
  323. toastRef.value.show({ message: '注册成功,请等待管理员审核', type: 'success' });
  324. setTimeout(() => {
  325. uni.reLaunch({ url: '/pages/login/register' });
  326. }, 3000);
  327. } else {
  328. toastRef.value.show({ message: res.msg || '注册失败', type: 'error' });
  329. }
  330. } catch (err) {
  331. console.error(err);
  332. } finally {
  333. loading.value = false;
  334. }
  335. }
  336. };
  337. const goBack = () => {
  338. uni.navigateBack();
  339. };
  340. onLoad(() => {
  341. initData();
  342. });
  343. </script>
  344. <style scoped>
  345. .container {
  346. min-height: 100vh;
  347. position: relative;
  348. background: #f8fafc;
  349. overflow: hidden;
  350. display: flex;
  351. justify-content: center;
  352. align-items: center;
  353. padding: 40rpx 30rpx;
  354. box-sizing: border-box;
  355. }
  356. .bg-shape {
  357. position: absolute;
  358. top: -100rpx;
  359. right: -100rpx;
  360. width: 500rpx;
  361. height: 500rpx;
  362. border-radius: 50%;
  363. background: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
  364. opacity: 0.15;
  365. filter: blur(40rpx);
  366. }
  367. .bg-shape2 {
  368. position: absolute;
  369. bottom: -150rpx;
  370. left: -100rpx;
  371. width: 600rpx;
  372. height: 600rpx;
  373. border-radius: 50%;
  374. background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  375. opacity: 0.15;
  376. filter: blur(50rpx);
  377. }
  378. .register-box {
  379. width: 100%;
  380. height: 92vh;
  381. background: rgba(255, 255, 255, 0.9);
  382. backdrop-filter: blur(20px);
  383. border-radius: 40rpx;
  384. display: flex;
  385. flex-direction: column;
  386. position: relative;
  387. z-index: 10;
  388. border: 2rpx solid rgba(255, 255, 255, 0.5);
  389. box-shadow: 0 20rpx 40rpx rgba(0, 0, 0, 0.05);
  390. overflow: hidden;
  391. }
  392. .header {
  393. padding: 50rpx 40rpx 30rpx;
  394. flex-shrink: 0;
  395. }
  396. .title {
  397. font-size: 48rpx;
  398. font-weight: 800;
  399. color: #1e293b;
  400. display: block;
  401. margin-bottom: 8rpx;
  402. }
  403. .subtitle {
  404. font-size: 26rpx;
  405. color: #64748b;
  406. display: block;
  407. }
  408. .step-nav {
  409. padding-bottom: 30rpx;
  410. flex-shrink: 0;
  411. }
  412. .form-scroll-view {
  413. flex: 1;
  414. min-height: 0;
  415. padding: 0 40rpx;
  416. box-sizing: border-box;
  417. }
  418. .form-content {
  419. padding-bottom: 40rpx;
  420. }
  421. .form-group {
  422. margin-bottom: 30rpx;
  423. }
  424. .label {
  425. font-size: 26rpx;
  426. font-weight: 600;
  427. color: #334155;
  428. margin-bottom: 12rpx;
  429. display: block;
  430. padding-left: 8rpx;
  431. }
  432. .required {
  433. color: #ef4444;
  434. margin-left: 6rpx;
  435. }
  436. .password-hint {
  437. margin-top: 10rpx;
  438. display: flex;
  439. align-items: center;
  440. font-size: 20rpx;
  441. color: #ef4444;
  442. padding-left: 10rpx;
  443. }
  444. .radio-box {
  445. background: #f1f5f9;
  446. padding: 24rpx 30rpx;
  447. border-radius: 20rpx;
  448. }
  449. .selector-box {
  450. background: #f1f5f9;
  451. padding: 24rpx 30rpx;
  452. border-radius: 20rpx;
  453. display: flex;
  454. align-items: center;
  455. }
  456. .selector-box .placeholder {
  457. color: #94a3b8;
  458. font-size: 28rpx;
  459. }
  460. .selector-box .val {
  461. color: #1e293b;
  462. font-size: 28rpx;
  463. }
  464. .id-group {
  465. display: flex;
  466. gap: 16rpx;
  467. align-items: center;
  468. }
  469. .id-type {
  470. width: 220rpx;
  471. height: 88rpx;
  472. line-height: 88rpx;
  473. background: #e2e8f0;
  474. color: #475569;
  475. font-size: 24rpx;
  476. text-align: center;
  477. border-radius: 20rpx;
  478. }
  479. .footer-actions {
  480. padding: 30rpx 40rpx 40rpx;
  481. background: rgba(255, 255, 255, 0.5);
  482. border-top: 2rpx solid rgba(241, 245, 249, 0.5);
  483. border-radius: 0 0 40rpx 40rpx;
  484. }
  485. .btn-group {
  486. display: flex;
  487. gap: 20rpx;
  488. }
  489. .btn-side {
  490. flex: 1;
  491. }
  492. .btn-main {
  493. flex: 2;
  494. }
  495. .back-link {
  496. margin-top: 30rpx;
  497. text-align: center;
  498. font-size: 26rpx;
  499. color: #3b82f6;
  500. font-weight: 500;
  501. }
  502. </style>