Kaynağa Gözat

feat(reg): 添加手机号注册验证功能

- 在 greg 页面导入 selectByPhone 接口
- 修改 sendSmsCode 方法,在发送验证码前先检查手机号是否已注册
- 添加对供应商注册流程的手机号验证支持
- 替换硬编码的角色数据为工作台角色列表接口
- 更新组织架构页面的角色加载逻辑
- 优化员工管理页面的表单初始化逻辑
肖路 1 hafta önce
ebeveyn
işleme
e1a00b0521

+ 46 - 17
src/views/greg/index.vue

@@ -268,7 +268,15 @@
 </template>
 
 <script setup lang="ts">
-import { smsCode, selectBusinessByCustomerName, registerCustomer, enterpriseScale, getProductCategoryList, registerSupplier } from '@/api/breg/index';
+import {
+  smsCode,
+  selectBusinessByCustomerName,
+  registerCustomer,
+  enterpriseScale,
+  getProductCategoryList,
+  registerSupplier,
+  selectByPhone
+} from '@/api/breg/index';
 import { onUnmounted } from 'vue';
 import { onPath } from '@/utils/siteConfig';
 import { regionData } from 'element-china-area-data';
@@ -347,24 +355,45 @@ const startCountdown = () => {
 // 获取验证码
 const sendSmsCode = () => {
   if (countdown.value > 0) return;
-
-  if (validateMobile(form.value.purchasePhone)) {
-    smsCode({ phonenumber: form.value.purchasePhone }).then((res: any) => {
-      if (res.code == 200) {
-        ElMessage({
-          message: '验证码已发送',
-          type: 'success'
-        });
-        startCountdown();
+  // 2. 【新增】先调用接口查询用户是否存在
+  selectByPhone(form.value.purchasePhone, '1')
+    .then((res: any) => {
+      // --- 后端返回 200 ---
+      // 根据你的后端逻辑:返回 200 代表 "用户不存在" (R.ok),允许注册
+      if (res.code === 200) {
+        // 手机号可用,继续执行发送验证码逻辑
+        smsCode({ phonenumber: form.value.purchasePhone })
+          .then((smsRes: any) => {
+            if (smsRes.code === 200) {
+              ElMessage({
+                message: '验证码已发送',
+                type: 'success'
+              });
+              startCountdown(); // 开始倒计时
+            } else {
+              // 发送短信接口业务失败
+              ElMessage.error(smsRes.msg || '发送验证码失败');
+            }
+          })
+          .catch((err: any) => {
+            // 发送短信接口网络错误或异常
+            ElMessage.error(err.msg || '发送验证码请求异常');
+          });
+      } else {
       }
+    })
+    .catch((error: any) => {
+      // --- 后端返回非 200 (进入 catch) ---
+      // 根据你的后端逻辑:返回 fail 代表 "用户已存在" (R.fail("该手机号已注册"))
+      const msg = error.msg || '该手机号已注册,请直接登录';
+
+      ElMessage({
+        message: msg,
+        type: 'warning' // 或者使用 'error'
+      });
     });
-  } else {
-    ElMessage({
-      message: '请输入正确的手机号码',
-      type: 'warning'
-    });
-    return;
-  }
+
+
 };
 
 //选择省

+ 6 - 12
src/views/organization/roleManage/index.vue

@@ -66,8 +66,8 @@
 import { ref, reactive, computed, onMounted } from 'vue';
 import { ElMessage, ElMessageBox } from 'element-plus';
 import { PageTitle } from '@/components';
-import { getRoleList, addRole, updateRole, deleteRole } from '@/api/pc/organization';
-import { create } from 'domain';
+import { addRole, updateRole, deleteRole } from '@/api/pc/organization';
+import { getWorkbenchRoleList } from '@/api/pc/system';
 
 const roleList = ref([]);
 const currentPage = ref(1);
@@ -100,16 +100,10 @@ const paginatedRoleList = computed(() => {
 
 const loadRoleList = async () => {
   try {
-    // const res = await getRoleList();
-    // if (res.code === 200 && res.data) {
-    //   roleList.value = res.data;
-    // }
-    roleList.value = [
-      { roleId: 1, roleName: '管理角色', roleSort: 1, status: '0', remark: '管理角色', createTime: '2026-01-27 09:36:27' },
-      { roleId: 2, roleName: '采购角色', roleSort: 2, status: '0', remark: '采购角色', createTime: '2026-01-27 09:36:38' },
-      { roleId: 3, roleName: '查询角色', roleSort: 3, status: '0', remark: '查询角色', createTime: '2026-01-27 09:37:33' },
-      { roleId: 4, roleName: '审核角色', roleSort: 4, status: '0', remark: '审核角色', createTime: '2026-01-27 09:37:50' }
-    ];
+    const res = await getWorkbenchRoleList();
+    if (res.data) {
+      roleList.value = res.data as any;
+    }
   } catch (error) {
     console.error('获取角色列表失败:', error);
     ElMessage.error('获取角色列表失败');

+ 9 - 11
src/views/organization/staffManage/index.vue

@@ -107,7 +107,8 @@ import { ElMessage, ElMessageBox } from 'element-plus';
 import { Search } from '@element-plus/icons-vue';
 import { PageTitle, TablePagination } from '@/components';
 import { DeptInfo } from '@/api/pc/organization/types';
-import { getDeptTree, getRoleList, getContactList, addContact, updateContact, deleteContact } from '@/api/pc/organization';
+import { getDeptTree, getContactList, addContact, updateContact, deleteContact } from '@/api/pc/organization';
+import { getWorkbenchRoleList } from '@/api/pc/system';
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const currentDeptId = ref<number | null>(null);
 const dialogVisible = ref(false);
@@ -169,16 +170,10 @@ const loadDeptTree = async () => {
 // 加载角色列表
 const loadRoleList = async () => {
   try {
-    roleList.value = [
-      { roleId: 1, roleName: '管理角色' },
-      { roleId: 2, roleName: '采购角色' },
-      { roleId: 3, roleName: '查询角色' },
-      { roleId: 4, roleName: '审核角色' }
-    ];
-    // const res = await getRoleList(queryParams);
-    // if (res.code === 200 && res.data) {
-    //   roleList.value = res.data;
-    // }
+    const res = await getWorkbenchRoleList();
+    if (res.data) {
+      roleList.value = res.data as any[];
+    }
   } catch (error) {
     console.error('获取角色列表失败:', error);
   }
@@ -257,10 +252,13 @@ const handleSelectionChange = (rows: any[]) => {
 
 const handleAdd = () => {
   editingRow.value = null;
+  formData.id = null;
   formData.contactName = '';
   formData.phone = '';
   formData.deptId = currentDeptId.value;
+  formData.deptName = '';
   formData.roleId = null;
+  formData.roleName = '';
   formData.status = '0';
   dialogVisible.value = true;
 };

+ 1 - 1
src/views/reg/index.vue

@@ -160,7 +160,7 @@ const sendSmsCode = () => {
   }
 
   // 2. 【新增】先调用接口查询用户是否存在
-  selectByPhone(phone, '1')
+  selectByPhone(phone, '3')
     .then((res: any) => {
       // --- 后端返回 200 ---
       // 根据你的后端逻辑:返回 200 代表 "用户不存在" (R.ok),允许注册