浏览代码

登录获取用户信息+验证码更新+根据条件查询:实现分页+刷新 完美

刘冰洁 1 年之前
父节点
当前提交
edbf901ed0

+ 1 - 1
.env

@@ -7,7 +7,7 @@ VITE_APP_TITLE=Soybean管理系统
 VITE_APP_DESC=SoybeanAdmin是一个中后台管理系统模版
 
 # 权限路由模式: static | dynamic
-VITE_AUTH_ROUTE_MODE=static
+VITE_AUTH_ROUTE_MODE = static
 
 # 路由首页(根路由重定向), 用于static模式的权限路由,dynamic模式取决于后端返回的路由首页
 VITE_ROUTE_HOME_PATH=/dashboard/analysis

+ 1 - 1
mock/api/auth.ts

@@ -34,7 +34,7 @@ const apis: MockMethod[] = [
         };
       }
 
-      const findItem = userModel.find(item => item.userName === userName && item.password === password);
+      const findItem = userModel.find(item => item.username === userName && item.password === password);
 
       if (findItem) {
         return {

+ 1 - 0
src/composables/router.ts

@@ -17,6 +17,7 @@ export function useRouterPush(inSetup = true) {
    */
   function routerPush(to: RouteLocationRaw, newTab = false) {
     if (newTab) {
+			console.log(newTab);
       const routerData = router.resolve(to);
       window.open(routerData.href, '_blank');
       return Promise.resolve();

+ 1 - 1
src/constants/business.ts

@@ -1,7 +1,7 @@
 export const loginModuleLabels: Record<UnionKey.LoginModule, string> = {
   'pwd-login': '账密登录',
   'code-login': '手机验证码登录',
-  register: '注册',
+  "register": '注册',
   'reset-pwd': '重置密码',
   'bind-wechat': '微信绑定'
 };

+ 2 - 1
src/router/guard/dynamic.ts

@@ -12,7 +12,8 @@ export async function createDynamicRouteGuard(
   next: NavigationGuardNext
 ) {
   const route = useRouteStore();
-  const isLogin = Boolean(localStg.get('token'));
+  //const isLogin = Boolean(localStg.get('token'));
+	const isLogin = Boolean(localStorage.getItem('token'));
 
   // 初始化权限路由
   if (!route.isInitAuthRoute) {

+ 2 - 1
src/router/guard/permission.ts

@@ -22,7 +22,8 @@ export async function createPermissionGuard(
   }
 
   const auth = useAuthStore();
-  const isLogin = Boolean(localStg.get('token'));
+  //const isLogin = Boolean(localStg.get('token'));
+	const isLogin = Boolean(localStorage.getItem('token'));
   const permissions = to.meta.permissions || [];
   const needLogin = Boolean(to.meta?.requiresAuth) || Boolean(permissions.length);
   const hasPermission = !permissions.length || permissions.includes(auth.userInfo.userRole);

+ 8 - 4
src/service/api/auth.ts

@@ -1,3 +1,4 @@
+import { localStg } from '~/src/utils';
 import { request,mockRequest } from '../request';
 
 /**
@@ -36,14 +37,17 @@ export interface AdminLoginRes {
  * 登录
  * @param userName - 用户名
  * @param password - 密码
+ * @param captchaVerification - 验证码
  */
 export function fetchLogin(params: AdminLoginParams) {
-  return request.post<ApiAuth.Token>('/adminLogin',params);
+  let res = request.post('/adminLogin',params);
+  return  res;
 }
 
 /** 获取用户信息 */
-export function fetchUserInfo() {
-  return mockRequest.get<ApiAuth.UserInfo>('/getUserInfo');
+export function fetchUserInfo(param:string) {
+	let res = request.get('/getUserInfo')
+  return res;
 }
 
 /**
@@ -51,7 +55,7 @@ export function fetchUserInfo() {
  * @param userId - 用户id
  * @description 后端根据用户id查询到对应的角色类型,并将路由筛选出对应角色的路由数据返回前端
  */
-export function fetchUserRoutes(userId: string) {
+export function fetchUserRoutes(userId: number) {
   return mockRequest.post<ApiRoute.Route>('/getUserRoutes', { userId });
 }
 

+ 0 - 0
src/service/api/login.ts


+ 0 - 0
src/service/api/man.ts


+ 8 - 8
src/service/api/sort.ts

@@ -79,7 +79,7 @@ export interface UpdateEasEduCategoryParams {
   id?: number|null;
   name?: string|null;
   description?: string|null;
-  createTime?:  string;
+  createTime?:  string|null;
   modifyTime?: string;
   createUid?: number|null;
   disabled?: string|null;
@@ -130,13 +130,13 @@ export function selectById_1(id: number) {
 // 根据条件进行查询课程类别
 // 参数接口
 export interface SelectByCondition_1Params {
-  id?: number;
-  name?: string;
-  description?: string;
-  createTime?: Record<string, unknown>;
-  modifyTime?: Record<string, unknown>;
-  createUid?: number;
-  disabled?: string;
+  id?: number | null;
+  name?: string|null;
+  description?: string|null;
+  createTime?: null|string;
+  modifyTime?: null|string;
+  createUid?: null|number;
+  disabled?: string|null;
 }
 
 // 响应接口

+ 9 - 12
src/service/request/instance.ts

@@ -31,7 +31,8 @@ export default class CustomAxiosInstance {
       codeKey: 'status',
       dataKey: 'data',
       msgKey: 'code',
-      successCode: true
+      successCode: true,
+			total:'total'
     }
   ) {
     this.backendConfig = backendConfig;
@@ -43,23 +44,19 @@ export default class CustomAxiosInstance {
   setInterceptor() {
     this.instance.interceptors.request.use(
       async config => {
-				console.log("--------------------", config);
         const handleConfig = { ...config };
         if (handleConfig.headers) {
           // 数据转换
-					console.log(handleConfig.headers);
           const contentType = handleConfig.headers['Content-Type'] as UnionKey.ContentType;
-					// console.log(contentType);
           handleConfig.data = await transformRequestData(handleConfig.data, contentType);
           // 设置token
-          handleConfig.headers.Authorization = localStg.get('token') ||'';
+          handleConfig.headers["Authorization"]= localStorage.getItem('token') ;
         }
-				console.log(handleConfig);
         return handleConfig;
       },
       (axiosError: AxiosError) => {
         const error = handleAxiosError(axiosError);
-        return handleServiceResult(error, null);
+        return handleServiceResult(error, null,null);
       }
     );
     this.instance.interceptors.response.use(
@@ -67,10 +64,10 @@ export default class CustomAxiosInstance {
         const { status } = response;
         if (status === 200 || status < 300 || status === 304 ) {
           const backend = response.data;
-          const { codeKey, dataKey, successCode } = this.backendConfig;
+          const { codeKey, dataKey, successCode,total} = this.backendConfig;
           // 请求成功
           if (backend[codeKey] === successCode ) {
-            return handleServiceResult(null, backend[dataKey]);
+            return handleServiceResult(null, backend[dataKey],backend[total]);
           }
           // token失效, 刷新token
           if (REFRESH_TOKEN_CODE.includes(backend[codeKey])) {
@@ -81,14 +78,14 @@ export default class CustomAxiosInstance {
           }
 
           const error = handleBackendError(backend, this.backendConfig);
-          return handleServiceResult(error, null);
+          return handleServiceResult(error, null,null);
         }
         const error = handleResponseError(response);
-        return handleServiceResult(error, null);
+        return handleServiceResult(error, null,null);
       }) as (response: AxiosResponse<any, any>) => Promise<AxiosResponse<any, any>>,
       (axiosError: AxiosError) => {
         const error = handleAxiosError(axiosError);
-        return handleServiceResult(error, null);
+        return handleServiceResult(error, null,null);
       }
     );
   }

+ 7 - 2
src/service/request/request.ts

@@ -29,6 +29,7 @@ export function createRequest(axiosConfig: AxiosRequestConfig, backendConfig?: S
    * - method: 请求方法(默认get)
    * - data: 请求的body的data
    * - axiosConfig: axios配置
+	 * - total
    */
   async function asyncRequest<T>(param: RequestParam): Promise<Service.RequestResult<T>> {
     const { url } = param;
@@ -38,6 +39,7 @@ export function createRequest(axiosConfig: AxiosRequestConfig, backendConfig?: S
       instance,
       method,
       url,
+			
       data: param.data,
       config: param.axiosConfig
     })) as Service.RequestResult<T>;
@@ -95,6 +97,7 @@ interface RequestResultHook<T = any> {
   error: Ref<Service.RequestError | null>;
   loading: Ref<boolean>;
   network: Ref<boolean>;
+	total:Ref<number>;
 }
 
 /**
@@ -120,11 +123,12 @@ export function createHookRequest(axiosConfig: AxiosRequestConfig, backendConfig
     startLoading();
     const data = ref<T | null>(null) as Ref<T | null>;
     const error = ref<Service.RequestError | null>(null);
-
+		const total = ref<number>() as Ref<number>;
     function handleRequestResult(response: any) {
       const res = response as Service.RequestResult<T>;
       data.value = res.data;
       error.value = res.error;
+			total.value=res.total as number
       endLoading();
       setNetwork(window.navigator.onLine);
     }
@@ -141,7 +145,8 @@ export function createHookRequest(axiosConfig: AxiosRequestConfig, backendConfig
       data,
       error,
       loading,
-      network
+      network,
+			total
     };
   }
 

+ 9 - 4
src/store/modules/auth/helpers.ts

@@ -2,18 +2,23 @@ import { localStg } from '@/utils';
 
 /** 获取token */
 export function getToken() {
-  return localStg.get('token') || '';
+  return localStorage.getItem('token');
 }
 
 /** 获取用户信息 */
 export function getUserInfo() {
   const emptyInfo: Auth.UserInfo = {
-    userId: '',
-    userName: '',
-    userRole: 'user'
+    id: null,
+		username: '',
+		phone:null,
+		email:'',
+		permissions:[],
+		departments:[],
+    userRole: 'admin'
   };
   const userInfo: Auth.UserInfo = localStg.get('userInfo') || emptyInfo;
 
+	console.log(userInfo);
   return userInfo;
 }
 

+ 15 - 14
src/store/modules/auth/index.ts

@@ -60,8 +60,8 @@ export const useAuthStore = defineStore('auth-store', {
       const loginSuccess = await this.loginByToken(backendToken);
 
       if (loginSuccess) {
+				console.log(loginSuccess);
         await route.initAuthRoute();
-
         // 跳转登录后的地址
         toLoginRedirect();
 
@@ -69,7 +69,7 @@ export const useAuthStore = defineStore('auth-store', {
         if (route.isInitAuthRoute) {
           window.$notification?.success({
             title: '登录成功!',
-            content: `欢迎回来,${this.userInfo.userName}!`,
+            content: `欢迎回来,${this.userInfo.username}!`,
             duration: 3000
           });
         }
@@ -84,30 +84,31 @@ export const useAuthStore = defineStore('auth-store', {
      * 根据token进行登录
      * @param backendToken - 返回的token
      */
+
     async loginByToken(backendToken: ApiAuth.Token) {
       let successFlag = false;
-
       // 先把token存储到缓存中(后面接口的请求头需要token)
       const { token, refreshToken } = backendToken;
-      localStg.set('token', token);
-      localStg.set('refreshToken', refreshToken);
-
+      localStorage.setItem('token', token);
+      localStorage.setItem('refreshToken', refreshToken);
+			const params=	localStorage.getItem('token');
       // 获取用户信息
-      const { data } = await fetchUserInfo();
+      const { data } = await fetchUserInfo(params);
+			console.log(data);
       if (data) {
         // 成功后把用户信息存储到缓存中
-        localStg.set('userInfo', data);
-
+        localStorage.setItem('userInfo', JSON.stringify(data));
+				console.log(localStorage.getItem('userInfo'));
         // 更新状态
-        this.userInfo = data;
+				this.userInfo = data as Auth.UserInfo;
         this.token = token;
-
         successFlag = true;
       }
-
+			console.log(successFlag);
       return successFlag;
+
     },
-		
+
     /**
      * 登录
      * @param userName - 用户名
@@ -118,7 +119,7 @@ export const useAuthStore = defineStore('auth-store', {
       this.loginLoading = true;
       const { data } = await fetchLogin(params);
       if (data) {
-        await this.handleActionAfterLogin(data);
+        await this.handleActionAfterLogin(data as ApiAuth.Token);
       }
       this.loginLoading = false;
     },

+ 7 - 8
src/store/modules/route/index.ts

@@ -91,8 +91,9 @@ export const useRouteStore = defineStore('route-store', {
       vueRoutes.forEach(route => {
         router.addRoute(route);
       });
-
+			console.log(vueRoutes);
       this.cacheRoutes = getCacheRoutes(vueRoutes);
+			console.log(this.cacheRoutes);
     },
     /** 动态路由模式下:更新根路由的重定向 */
     handleUpdateRootRedirect(routeKey: AuthRoute.AllRouteKey) {
@@ -110,13 +111,12 @@ export const useRouteStore = defineStore('route-store', {
       const { resetAuthStore } = useAuthStore();
       const { initHomeTab } = useTabStore();
 
-      const { userId } = localStg.get('userInfo') || {};
-
-      if (!userId) {
+      const { id } = localStorage.getItem('userInfo');
+      if (!id) {
         throw new Error('userId 不能为空!');
       }
 
-      const { error, data } = await fetchUserRoutes(userId);
+      const { error, data } = await fetchUserRoutes(id);
 
       if (!error) {
         this.routeHomeName = data.home;
@@ -134,12 +134,11 @@ export const useRouteStore = defineStore('route-store', {
     async initStaticRoute() {
       const { initHomeTab } = useTabStore();
       const auth = useAuthStore();
-
+			console.log(auth);
       const routes = filterAuthRoutesByUserPermission(staticRoutes, auth.userInfo.userRole);
+			console.log(routes);
       this.handleAuthRoute(routes);
-
       initHomeTab(this.routeHomeName, router);
-
       this.isInitAuthRoute = true;
     },
     /** 初始化权限路由 */

+ 2 - 2
src/typings/api.d.ts

@@ -25,7 +25,7 @@ declare namespace ApiRoute {
 declare namespace ApiUserManagement {
   interface User {
     /** 用户id */
-    id: number | null;
+    id: number ;
     /** 用户名 */
     name: string | null;
     /** 用户年龄 */
@@ -34,7 +34,7 @@ declare namespace ApiUserManagement {
     /** 用户手机号码 */
     modifyTime: string;
     /** 用户邮箱 */
-    createUid: number | null;
+    createUid: string|null;
     /**
      * 用户状态
      * - Y: 启用

+ 7 - 3
src/typings/business.d.ts

@@ -6,14 +6,18 @@ declare namespace Auth {
    * - admin: 管理员
    * - user: 用户
    */
-  type RoleType = 'super' | 'admin' | 'user';
+  type RoleType =  'admin' ;
 
   /** 用户信息 */
   interface UserInfo {
     /** 用户id */
-    userId: string;
+    id: number|null;
     /** 用户名 */
-    userName: string;
+    username: string;
+		phone:number|null;
+		email:string;
+		permissions:[];
+		departments:[];
     /** 用户角色类型 */
     userRole: RoleType;
   }

+ 4 - 0
src/typings/system.d.ts

@@ -16,6 +16,7 @@ declare namespace Service {
     code: string | number;
     /** 错误信息 */
     msg: string;
+
   }
 
   /** 后端接口返回的数据结构配置 */
@@ -28,6 +29,7 @@ declare namespace Service {
     msgKey: string;
     /** 后端业务上定义的成功请求的状态 */
     successCode: boolean;
+		total:string
   }
 
   /** 自定义的请求成功结果 */
@@ -36,6 +38,7 @@ declare namespace Service {
     error: null;
     /** 请求数据 */
     data: T;
+		total:string;
   }
 
   /** 自定义的请求失败结果 */
@@ -44,6 +47,7 @@ declare namespace Service {
     error: RequestError;
     /** 请求数据 */
     data: null;
+		total:null;
   }
 
   /** 自定义的请求结果 */

+ 2 - 1
src/utils/crypto/index.ts

@@ -31,6 +31,7 @@ export function decrypto(cipherText: string) {
     mode: CryptoJS.mode.ECB, //模式
     padding: CryptoJS.pad.Pkcs7, //补零
   });
+
   return CryptoJS.enc.Utf8.stringify(cryptoStr).toString();
-  return null;
+
 }

+ 0 - 1
src/utils/router/auth.ts

@@ -16,7 +16,6 @@ function filterAuthRouteByUserPermission(route: AuthRoute.Route, permission: Aut
   const filterRoute = { ...route };
   const hasPermission =
     !route.meta.permissions || permission === 'super' || route.meta.permissions.includes(permission);
-
   if (filterRoute.children) {
     const filterChildren = filterRoute.children.map(item => filterAuthRouteByUserPermission(item, permission)).flat(1);
     Object.assign(filterRoute, { children: filterChildren });

+ 1 - 0
src/utils/router/cache.ts

@@ -16,6 +16,7 @@ export function getCacheRoutes(routes: RouteRecordRaw[]) {
       });
     }
   });
+	console.log(cacheNames);
   return cacheNames;
 }
 

+ 0 - 1
src/utils/router/menu.ts

@@ -95,7 +95,6 @@ function addPartialProps(config: {
   const item = { ...config.menu };
 
   const { icon, localIcon, children } = config;
-
   if (localIcon) {
     Object.assign(item, { icon: iconRender({ localIcon }) });
   }

+ 10 - 5
src/utils/service/handler.ts

@@ -1,15 +1,17 @@
 /** 统一失败和成功的请求结果的数据类型 */
-export async function handleServiceResult<T = any>(error: Service.RequestError | null, data: any) {
+export async function handleServiceResult<T = any>(error: Service.RequestError | null, data: any,total:any) {
   if (error) {
     const fail: Service.FailedResult = {
       error,
-      data: null
+      data: null,
+			total:null,
     };
     return fail;
   }
   const success: Service.SuccessResult<T> = {
     error: null,
-    data
+    data,
+		total
   };
   return success;
 }
@@ -26,7 +28,8 @@ export function adapter<T extends Service.ServiceAdapter>(
     if (flag) {
       result = {
         error: item.error,
-        data: null
+        data: null,
+				total:null
       };
     }
     return flag;
@@ -34,9 +37,11 @@ export function adapter<T extends Service.ServiceAdapter>(
 
   if (!hasError) {
     const adapterFunArgs = args.map(item => item.data);
+		const adapterFunArgss=args.map(item => item.total);
     result = {
       error: null,
-      data: adapterFun(...adapterFunArgs)
+      data: adapterFun(...adapterFunArgs),
+			total:adapterFun(...adapterFunArgss),
     };
   }
 

+ 1 - 2
src/utils/storage/local.ts

@@ -1,5 +1,5 @@
 import { decrypto, encrypto } from '../crypto';
-interface StorageData<T> {
+ interface StorageData<T> {
   value: T;
   expire: number | null;
 }
@@ -7,7 +7,6 @@ interface StorageData<T> {
 function createLocalStorage<T extends StorageInterface.Local = StorageInterface.Local>() {
   /** 默认缓存期限为7天 */
   const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7;
-
   function set<K extends keyof T>(key: K, value: T[K], expire: number | null = DEFAULT_CACHE_TIME) {
     const storageData: StorageData<T[K]> = {
       value,

+ 3 - 4
src/views/_builtin/login/components/pwd-login/components/verifition/Verify/VerifySlide.vue

@@ -9,7 +9,7 @@
 				<transition name="tips">
 					<span class="verify-tips" v-if="tipWords" :class="passFlag ? 'suc-bg' : 'err-bg'">{{ tipWords }}</span>
 				</transition>
-			</div> 
+			</div>
 		</div>
 		<!-- 公共部分 -->
 		<div class="verify-bar-area" :style="{ width: setSize.imgWidth, height: barSize.height,'line-height': barSize.height}">
@@ -102,7 +102,7 @@ export default {
 		const { mode, captchaType, vSpace, imgSize, barSize, type, blockSize, explain } = toRefs(props)
 
 		const { proxy } = getCurrentInstance();
-		let secretKey = ref(''),        //后端返回的ase加密秘钥
+		let secretKey = ref(''),       //后端返回的ase加密秘钥
 				passFlag = ref(''),         //是否通过的标识
 				backImgBase = ref(''),      //验证码背景图片
 				blockBackImgBase = ref(''), //验证滑块的背景图片
@@ -316,7 +316,6 @@ export default {
 			}
 			reqGet(data).then(res => {
 				if (res.code == "0") {
-					console.log(res)
 					backImgBase.value = res.data.originalImageBase64
 					blockBackImgBase.value = res.data.jigsawImageBase64
 					backToken.value = res.data.token
@@ -357,7 +356,7 @@ export default {
 			refresh,
 			start
 		}
-	},
+	}
 }
 </script>
 

+ 2 - 5
src/views/_builtin/login/components/pwd-login/index.vue

@@ -27,7 +27,7 @@
 				<other-account @login="handleLoginOtherAccount" />
 		</n-space>
 	</n-form>
-	<div class="mask" v-if="mode==='pop'">
+	<div class="mask" v-show="mode==='pop'">
 		<div class="verifybox" :style="{ 'max-width': '340px' }">
 			<div class="verifybox-top">
 				请完成安全验证
@@ -37,7 +37,7 @@
 			</div>
 			<div class="verifybox-bottom" :style="{ padding: mode === 'pop' ? '15px' : '0' }">
 				<!-- 验证码容器 -->
-				<verify-slide  @success="verifySlideClose"  />
+				<verify-slide @success="verifySlideClose"  />
 			</div>
 		</div>
 	</div>
@@ -54,10 +54,7 @@ import { OtherAccount } from './components';
 import { encrypto } from '@/utils/crypto/index'
 
 const mode =ref('push')
-const clickShow = ref(false)
-
 const closeBox = () => {
-	clickShow.value = false;
 	mode.value='push'
 };
 

+ 9 - 17
src/views/management/sort/components/table-action-add.vue

@@ -42,9 +42,8 @@ import type { FormInst, FormItemRule } from 'naive-ui';
 import { userStatusOptions } from '@/constants';
 import {createRequiredFormRule } from '@/utils';
 import dayjs from 'dayjs';
-import { addEasEduCategory, AddEasEduCategoryParams,updateEasEduCategory,UpdateEasEduCategoryParams } from '~/src/service/api/sort';
-import {getTableData} from '../index.vue'
-// const timestamp = ref(1483135260000)
+import { addEasEduCategory, AddEasEduCategoryParams,updateEasEduCategory,UpdateEasEduCategoryParams,SelectByCondition_1Params } from '~/src/service/api/sort';
+
 
 export interface Props {
 	/** 弹窗可见性 */
@@ -56,7 +55,7 @@ export interface Props {
 	 */
 	type?: 'add' | 'edit' ;
 	/** 编辑的表格行数据 */
-	editData?: UserManagement.User | null;
+	editData?: SelectByCondition_1Params | null;
 }
 
 export type ModalType = NonNullable<Props['type']>;
@@ -70,6 +69,8 @@ const props = withDefaults(defineProps<Props>(), {
 
 interface Emits {
 	(e: 'update:visible', visible: boolean): void;
+	  /** 点击协议 */
+	(e: 'searchCondition'): void;
 }
 
 const emit = defineEmits<Emits>();
@@ -100,7 +101,7 @@ const title = computed(() => {
 const formRef = ref<HTMLElement & FormInst>();
 
 
-interface FormModel extends Pick<UserManagement.User, 'id' |'name' | 'description' | 'createUid' | 'disabled'|'createTime'> {
+interface FormModel extends Pick<SelectByCondition_1Params, 'id' |'name' | 'description' | 'createUid' | 'disabled'|'createTime'> {
   modifyTime: string;
 }
 
@@ -128,9 +129,8 @@ function createDefaultFormModel(): FormModel {
 	};
 }
 
-function handleUpdateFormModel(model: Partial<FormModel>) {
+function handleUpdateFormModel(model: SelectByCondition_1Params) {
 	Object.assign(formModel, model);
-	// console.log(	Object.assign(formModel, model));
 }
 
 function handleUpdateFormModelByModalType() {
@@ -157,7 +157,6 @@ async function handleSubmit() {
       // id: formModel.id,
       name: formModel.name,
       description: formModel.description,
-      // createTime: formModel.createTime,
       createUid: formModel.createUid,
       disabled: formModel.disabled
     };
@@ -166,7 +165,7 @@ async function handleSubmit() {
       .then(res => {
         console.log(res);
         window.$message?.success('新增成功!');
-				getTableData();
+  			emit('searchCondition')
         closeModal();
       })
       .catch(error => {
@@ -185,22 +184,16 @@ async function handleSubmit() {
 				createUid: formModel.createUid,
 				disabled: formModel.disabled
      };
-
     // 调用更新接口
     updateEasEduCategory(params)
       .then(res => {
         console.log(res);
         window.$message?.success('更新成功!');
+				emit('searchCondition')
         closeModal();
-        getTableData();
       })
-      .catch(error => {
-        console.error(error);
-        window.$message?.error('更新失败!');
-      });
   }
 }
-
 watch(
 	() => props.visible,
 	newValue => {
@@ -211,4 +204,3 @@ watch(
 );
 </script>
 
-<style scoped></style>

+ 106 - 157
src/views/management/sort/index.vue

@@ -5,59 +5,60 @@
 				<n-space class="pb-14px" justify="space-between">
 					<!-- 加入查询组件 -->
 					<n-space>
-						<n-button type="primary"  @click="addTableData">
+						<n-button type="primary" @click="addTableData">
 							<icon-ic-round-plus class="mr-4px text-20px" />
 							新增
 						</n-button>
-						<n-button type="error" @click="deleteTableData" @update:checked-row-keys="handleCheck">
+						<n-button type="error" @click="deleteTableData" >
 							<icon-ic-round-delete class="mr-4px text-20px" />
 							删除
 						</n-button>
 						<!-- 添加查询按钮 -->
-						<n-button type="primary" @click="handleOpenSearch">
+						<n-button type="primary" @click="">
 							<icon-simple-line-icons:magnifier class="mr-4px text-16px" />
 							查询
 						</n-button>
-						<n-input-group>
-							<n-input :style="{ width: '100%', }" placeholder="请输入id查询..." @clear="searchClear"  @change="handleChange"
-								@keyup.enter="handleSearch" v-model="searchId" clearable />
-							<n-button type="primary" ghost @click="handleSearch">
-								搜索
-							</n-button>
-						</n-input-group>
 						<div class="mr-5px"></div>
 						<n-input-group>
-							<span class="w-40px mr-5px line-height-33.99px">页码</span>
-							<n-input-number :style="{ width: '48%', marginRight: '2%' }" placeholder="请输入页码..." clearable v-model="pagination.page"
-								@update:value="searchPage"  @clear="searchConClear"/>
-							<span class="w-40px mr-5px line-height-33.99px">条数</span>
-							<n-input-number :style="{ width: '48%' }" placeholder="请输入数据条数..." clearable v-model="pagination.pageSize"
-								@update:value="searchSize"  @clear="searchConClear" />
-							<n-button type="primary" ghost @click="searchCondition">
+							<n-input-number :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.id"
+								placeholder="请输入ID..." clearable />
+							<n-input :style="{ width: '98%', marginRight: '2%' }" :value="conditionParams.name"
+								@input="event => conditionParams.name = event" placeholder="请输入学科名称..." clearable />
+							<n-input :style="{ width: '98%', marginRight: '2%' }" :value="conditionParams.description"
+								@input="event => conditionParams.description = event" placeholder="请输入学科描述..." clearable  />
+							<n-input-number :style="{ width: '120%', marginRight: '2%' }" v-model:value="conditionParams.createUid"
+								placeholder="请输入用户ID..." clearable />
+							<n-input :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.createTime"
+								@input="event => conditionParams.createTime = event" placeholder="请输入创建时间..." clearable />
+							<n-input :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.modifyTime"
+								@input="event => conditionParams.modifyTime = event" placeholder="请输入修改时间..." clearable/>
+							<n-select :options="userStatusOptions" :style="{ width: '98%', marginRight: '2%' }"
+								v-model:value="conditionParams.disabled" @input="event => conditionParams.disabled = event"
+								placeholder="输入查询状态..." clearable />
+							<n-button type="primary" ghost @click="searchCondition()">
 								搜索
 							</n-button>
 						</n-input-group>
-						<!-- <column-search v-if="showSearch" v-model:columns="columns" /> -->
 					</n-space>
 					<n-space align="center" :size="18">
-						<n-button size="small" type="primary" @click="getTableData">
+						<n-button size="small" type="primary" @click="searchCondition">
 							<icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
 							刷新表格
 						</n-button>
 					</n-space>
 				</n-space>
-				<n-data-table v-if="searchForm.length > 0" :columns="createColumns" :data="searchForm" :loading="loading"
-					:pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
-				<n-data-table v-if="searchForm.length <= 0" :columns="createColumns" :data="tableData" :loading="loading"
-					:pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
-				<table-action-add v-model:visible="visible" :type="modalType" :edit-data="editData" />
+				<n-data-table :columns="columns" :data="tableData" :loading="loading" :row-key="rowKey" @update:checked-row-keys="handleCheck"
+					:pagination="pagination" />
+				<table-action-add  v-model:visible="visible"  :type="modalType" @searchCondition="searchCondition"
+					:pagination="pagination" :edit-data="(editData as SelectByCondition_1Params)" />
 			</n-card>
 		</n-scrollbar>
 	</div>
 </template>
 
 <script setup lang="tsx" >
-import { ref } from 'vue'
+import { userStatusOptions } from '@/constants';
+import { ref, Ref, reactive ,watch} from 'vue'
 import { NButton, NSpace, NTag, NPopconfirm } from 'naive-ui';
 import type { DataTableColumns, PaginationProps } from 'naive-ui';
 import { useBoolean, useLoading } from '@/hooks';
@@ -65,40 +66,39 @@ import type { DataTableRowKey } from 'naive-ui'
 import TableActionAdd from './components/table-action-add.vue'
 import type { ModalType } from './components/table-action-add.vue';
 import { userStatusLabels } from '@/constants';
-import { selectAll_1, deleteById, selectById_1 } from '~/src/service/api/sort';
-import { selectByCondition_1 } from '~/src/service/api/sort';
+import { deleteById,selectAll_1 } from '~/src/service/api/sort';
+import { selectByCondition_1} from '~/src/service/api/sort';
 import type { SelectByCondition_1Params } from '~/src/service/api/sort';
+
 type RowData = {
-	key: number
+	key: string
 	id: number
 	name: string
 	description: string
 	createTime: string
 	modifyTime: string
-	createUid: number
+	createUid: string
 	disabled: string
 }
+const conditionParams: SelectByCondition_1Params = reactive({
+	id: null,
+	name: null,
+	description: null,
+	createUid: null,
+	createTime: null,
+	modifyTime: null,
+	disabled: null
+});
+
 const { loading, startLoading, endLoading } = useLoading(false);
 const { bool: visible, setTrue: openModal } = useBoolean();
-const tableData = ref<any[]>([]);
-const searchInput = ref([]) as any;
-const searchForm = ref([]) as any;
-const searchId = ref<number>(0); // 定义为数字类型,默认值为0
-// const searchData = ref<any[]>([]);
-const searchConData = ref<any[]>([]);
-const searchpagedata = ref<number>(0)
-const searchpagesize = ref<number>(0)
+const tableData = ref<SelectByCondition_1Params[]>([]);
 
-function searchPage(v: number | null) {
-	searchpagedata.value = Number(v)
-}
-function searchSize(v: number | null) {
-	searchpagesize.value = Number(v)
-}
 const pagination: PaginationProps = ref({
 	page: 1,
 	pageSize: 10,
 	showSizePicker: true,
+	itemCount:1,
 	pageSizes: [10, 20, 50],
 	onChange: (page: number) => {
 		// 处理页码变化
@@ -111,100 +111,50 @@ const pagination: PaginationProps = ref({
 	}
 }).value;
 
-function searchCondition() {
-	const pageNum = searchpagedata.value as number;
-	const pageSize = searchpagesize.value as number;
-	const params: SelectByCondition_1Params = {};
-	if(pageNum  &&  pageSize){
-		selectByCondition_1(pageNum, pageSize, params).then(res => {
-		searchConData.value = res.data as [];
-		pagination.page =searchpagedata.value
-		pagination.pageSize=searchpagesize.value
-		window.$message?.success('查询成功');
-		})
-	}
-	else if(!pageNum && !pageSize) {
-		searchpagedata.value =0;
-		searchpagesize.value=0;
-		window.$message?.warning('请输入页码和条数进行查询');
-	}
-}
-export async function getTableData() {
+async function searchCondition() {
 	startLoading();
-	selectAll_1().then(res => {
-		setTimeout(() => {
+	// 检查 conditionParams 对象中的值是否存在不为空的条件  some 检查数组中是否有至少一个元素满足指定的条件 检查每个值是否不为 null 且不为空字符串
+	const hasConditions = Object.values(conditionParams).some(value => value !== null && value !== '');
+	if(hasConditions){
+			const res = await selectByCondition_1(pagination.page as number, pagination.pageSize as number, conditionParams);
 			tableData.value = res.data as [];
+			pagination.itemCount = Number(res.total);
+			// 如果满足条件的数据超出当前页的数据范围,则重新查询所有满足条件的数据
+			if (pagination.itemCount > (pagination.page - 1) * pagination.pageSize + tableData.value.length) {
+					const allRes = await selectByCondition_1(1, pagination.itemCount, conditionParams);
+					tableData.value = allRes.data as [];
+					pagination.itemCount = Number(allRes.total);
+					// 调整分页参数
+					pagination.page = Math.ceil(allRes.total / pagination.pageSize);
+			} else {
+					const allRes = await selectByCondition_1(1, pagination.itemCount, conditionParams);
+					tableData.value = allRes.data as [];
+			}
 			endLoading();
-		}, 1000);
-	});
-	checkedRowKeysRef.value=[]
+	}
+	else{
+		const res = await selectAll_1();
+    tableData.value = res.data as [];
+    pagination.itemCount = tableData.value.length;
+		endLoading();
+	}
 }
 function init() {
-	getTableData();
+	searchCondition();
 }
+// 在条件改变时立即触发搜索
+watch(conditionParams, () => {
+	if (Object.values(conditionParams).every(value => value === '' || value === null)) {
+    // 如果所有条件参数都为空,则查询所有数据
+    searchCondition();
+  }
+	  searchCondition();
+});
 // 初始化
 init();
 
-function searchConClear(){
-	searchConData.value.length = 0
-	searchpagedata.value =0;
-	searchpagesize.value=0;
-	getTableData();
-}
-
-const showSearch = ref(false)
-function handleOpenSearch() {
-// 点击查询时显示搜索框
-	showSearch.value = !showSearch.value;
-}
-// 输入数据
-function handleChange(v: string) {
-	searchId.value = Number(v)
-}
-// 根据id查询数据
-async function handleSearch() {
-	if (searchId.value) {
-		await selectById_1(searchId.value)
-			.then(res => {
-				// 更新数据
-				searchInput.value = res.data as [];
-				const filteredItems = tableData.value.filter(item => item.id === searchInput.value.id)
-				searchForm.value = filteredItems;
-				window.$message?.success('查询成功');
-			})
-	}
-	else {
-		searchForm.value.length = 0
-		window.$message?.warning('请输入有效的ID进行查询');
-	}
-}
-
-function searchClear() {
-	searchForm.value.length = 0
-	getTableData();
-}
-
 const checkedRowKeysRef = ref<DataTableRowKey[]>([])
-	const s = ref<DataTableRowKey[]>([])
-// 根据id进行删除
-async function deleteTableData() {
-	const ids = checkedRowKeysRef.value.filter((item)=>!s.value?.includes(item));
-	s.value=checkedRowKeysRef.value
-	if (ids.length !== 0) {
-		console.log(ids);
-		for (const id of ids) {
-			// 调用删除接口
-			await deleteById(id as number)
-				.then((res) => {
-						window.$message?.success('删除成功!');
-				})
-		}
-		getTableData(); // 删除完成后刷新表格数据
-	} else {
-		// 没有选择任何行时的操作
-		window.$message?.error('未选择要删除的行');
-	}
-}
+const s = ref<DataTableRowKey[]>([])
 
 const modalType = ref<ModalType>('add' || 'edit');
 
@@ -217,31 +167,47 @@ function addTableData() {
 	setModalType('add');
 }
 
-const editData = ref<UserManagement.User | null>(null);
-function setEditData(data: UserManagement.User | null) {
+const editData = ref<SelectByCondition_1Params | null>(null);
+function setEditData(data: SelectByCondition_1Params | null) {
 	editData.value = data;
 }
-console.log(tableData.value);
-function handleEditTable(rowId: number | null) {
+function handleEditTable(rowId: number) {
 	const findItem = tableData.value.find(item => item.id === rowId);
 	setModalType('edit');
 	openModal();
 	if (findItem) {
 		setEditData(findItem);
 	}
-	getTableData(); // 编辑完成后刷新表格数据
 }
 
-function handleDeleteTable(rowId: number | null) {
-	const findItem = tableData.value.find(item => item.id === rowId);
-	if (findItem) {
-		deleteById(findItem.id).then((r) => {
-			getTableData(); // 编辑完成后刷新表格数据
-		})
+function handleDeleteTable(rowId: number) {
+	const rowIdNumber = Number(rowId);
+	deleteById(rowIdNumber).then(() => {
+		searchCondition(); // 删除完成后刷新表格数据
+	})
+
+}
+const rowKey = (row: RowData) => row.id
+function handleCheck(rowKeys: DataTableRowKey[]) {
+	checkedRowKeysRef.value = rowKeys
+}
+async function deleteTableData() {
+	const ids = checkedRowKeysRef.value.filter((item) => !s.value?.includes(item));
+	s.value = checkedRowKeysRef.value
+	if (ids.length !== 0) {
+		for (const id of ids) {
+		await	deleteById(id as number).then((res)=>{
+			})
+		}
+		window.$message?.success('删除成功!');
+		searchCondition(); // 删除完成后刷新表格数据
+	} else {
+		// 没有选择任何行时的操作
+		window.$message?.error('未选择要删除的行');
 	}
 }
 
-const createColumns = (): DataTableColumns<UserManagement.User> => [
+const columns: Ref<DataTableColumns<UserManagement.User>> = ref([
 	{
 		type: 'selection',
 		align: 'center',
@@ -312,23 +278,6 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
 				</NSpace>
 			);
 		}
-
 	},
-]
-
-const	rowKey= (row: RowData) => row.id
-function handleCheck(rowKeys: DataTableRowKey[]) {
-	checkedRowKeysRef.value = rowKeys
-}
-		// handleKeyDown(event:KeyboardEvent) {
-    //   if (event.key === 'Backspace' && searchId.value===0) {
-    //     // 处理删除键按下且输入框为空的情况
-    //     // 执行刷新操作,例如调用 API 获取原来的列表数据
-		// 		getTableData()
-    //   }
-		// 	console.log(1);
-    // },
-
-
-
+])
 </script>

+ 0 - 2
src/views/management/sort/indexcopy.vue

@@ -104,14 +104,12 @@ export async function getTableData() {
 	startLoading();
 	selectAll_1().then(res => {
 		setTimeout(() => {
-			// console.log(res);
 			tableData.value = res.data as [];
 			endLoading();
 		}, 1000);
 	});
 }
 
-
 const checkedRowKeysRef = ref<DataTableRowKey[]>([])
 
 async function deleteTableData() {

+ 197 - 115
src/views/management/sort/indexsss.vue

@@ -1,49 +1,76 @@
 <template>
 	<div class="h-full overflow-hidden">
-		<n-card title="课程分类" :bordered="false" class="rounded-16px shadow-sm">
-			<n-space class="pb-12px" justify="space-between">
-				<n-space>
-					<n-button type="primary" :data="addData" @click="addTableData">
-						<icon-ic-round-plus class="mr-4px text-20px" />
-						新增
-					</n-button>
-					<n-button type="error" @click="deleteTableData" @update:checked-row-keys="handleCheck">
-						<icon-ic-round-delete class="mr-4px text-20px" />
-						删除
-					</n-button>
-					<!-- <n-button type="success">
-            <icon-uil:export class="mr-4px text-20px" />
-            导出Excel
-          </n-button> -->
-				</n-space>
-				<n-space align="center" :size="18">
-					<n-button size="small" type="primary" @click="getTableData">
-						<icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
-						刷新表格
-					</n-button>
-					<column-setting v-model:columns="columns" />
+
+			<n-card title="课程分类" :bordered="false" class="rounded-16px shadow-sm">
+				<n-space class="pb-14px" justify="space-between">
+					<!-- 加入查询组件 -->
+					<n-space>
+						<n-button type="primary" @click="addTableData">
+							<icon-ic-round-plus class="mr-4px text-20px" />
+							新增
+						</n-button>
+						<n-button type="error" @click="deleteTableData" @update:checked-row-keys="handleCheck">
+							<icon-ic-round-delete class="mr-4px text-20px" />
+							删除
+						</n-button>
+						<!-- 添加查询按钮 -->
+						<n-button type="primary" @click="handleOpenSearch">
+							<icon-simple-line-icons:magnifier class="mr-4px text-16px" />
+							查询
+						</n-button>
+						<div class="mr-5px"></div>
+						<n-input-group>
+							<n-input :style="{ width: '50%',marginRight:'2%'}" :value="conditionParams.id"
+							@input="event => conditionParams.id = event" placeholder="请输入ID..." />
+							<n-input :style="{ width: '50%',marginRight:'2%'}" :value="conditionParams.name"
+								@input="event => conditionParams.name = event" placeholder="请输入学科名称..." />
+							<n-input :style="{ width: '50%',marginRight:'2%' }" :value="conditionParams.description"
+								@input="event => conditionParams.description = event" placeholder="请输入学科描述..." />
+							<n-input :style="{ width: '50%',marginRight:'2%' }" :value="conditionParams.createUid"
+								@input="event => conditionParams.createUid = event" placeholder="请输入创建用户ID..." />
+							<n-input :style="{ width: '50%',marginRight:'2%' }" :value="conditionParams.createTime"
+								@input="event => conditionParams.createTime = event" placeholder="请输入创建时间..." />
+							<n-input :style="{ width: '50%',marginRight:'2%' }" :value="conditionParams.modifyTime"
+								@input="event => conditionParams.modifyTime = event" placeholder="请输入修改时间..." />
+							<n-select :style="{ width: '50%' }" :value="conditionParams.disabled"
+								@input="event => conditionParams.disabled = event" placeholder="输入查询状态..." />
+							<n-button type="primary" ghost @click="searchCondition()">
+								搜索
+							</n-button>
+						</n-input-group>
+					</n-space>
+					<n-space align="center" :size="18">
+						<n-button size="small" type="primary" @click="searchCondition">
+							<icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
+							刷新表格
+						</n-button>
+					</n-space>
 				</n-space>
-			</n-space>
-			<n-data-table :columns="columns" :data="tableData" :loading="loading" :pagination="pagination" :row-key="rowKey"
-				@update:checked-row-keys="handleCheck" />
-			<table-action-add v-model:visible="visible" :type="modalType" />
-		</n-card>
+				<n-scrollbar>
+				<!-- <n-data-table  :columns="columns" :data="searchForm" :loading="loading"
+					:pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" /> -->
+				<n-data-table  :columns="columns" :data="tableData" :loading="loading"
+					:pagination="pagination" :row-key="rowKey"  />
+				<table-action-add v-model:visible="visible" :type="modalType" :edit-data="(editData as SelectByCondition_1Params)" @update:checked-row-keys="handleCheck"/>
+				<div style="width: 100%; height: 300px;"></div>
+			</n-scrollbar>
+			</n-card>
+
 	</div>
 </template>
 
-<script lang="tsx" >
-import { defineComponent, ref } from 'vue'
-import { NButton, NSpace,NTag ,NPopconfirm} from 'naive-ui';
+<script setup lang="tsx" >
+import { ref, Ref, reactive } from 'vue'
+import { NButton, NSpace, NTag, NPopconfirm } from 'naive-ui';
 import type { DataTableColumns, PaginationProps } from 'naive-ui';
 import { useBoolean, useLoading } from '@/hooks';
 import type { DataTableRowKey } from 'naive-ui'
 import TableActionAdd from './components/table-action-add.vue'
 import type { ModalType } from './components/table-action-add.vue';
-// import {  userStatusLabels } from '@/constants';
 import { userStatusLabels } from '@/constants';
-import { selectAll_1, deleteById } from '~/src/service/api/sort';
-import type { AddEasEduCategoryParams } from '~/src/service/api/sort';
-
+import {  deleteById } from '~/src/service/api/sort';
+import { selectByCondition_1 } from '~/src/service/api/sort';
+import type { SelectByCondition_1Params } from '~/src/service/api/sort';
 type RowData = {
 	key: number
 	id: number
@@ -54,17 +81,25 @@ type RowData = {
 	createUid: number
 	disabled: string
 }
+const conditionParams: SelectByCondition_1Params = reactive({
+	id: null,
+	name: null,
+	description: null,
+	createUid:null,
+	createTime: null,
+	modifyTime: null,
+	disabled: null
+});
+
 const { loading, startLoading, endLoading } = useLoading(false);
 const { bool: visible, setTrue: openModal } = useBoolean();
-
 const tableData = ref<any[]>([]);
-
-// const checkedRowKeysRef = ref<DataTableRowKey[]>([])
 const pagination: PaginationProps = ref({
 	page: 1,
 	pageSize: 10,
 	showSizePicker: true,
-	pageSizes: [10, 20, 50],
+	pageCount: 12,
+	pageSizes: [10, 20, 30,40,50],
 	onChange: (page: number) => {
 		// 处理页码变化
 		pagination.page = page;
@@ -76,77 +111,149 @@ const pagination: PaginationProps = ref({
 	}
 }).value;
 
-export async function getTableData() {
-	startLoading();
-	selectAll_1().then(res => {
-		setTimeout(() => {
-			// console.log(res);
-			tableData.value = res.data as [];
-			endLoading();
-		}, 1000);
-	});
+// function searchCondition() {
+// 	const pageNum = searchpagedata.value as number;
+// 	const pageSize = searchpagesize.value as number;
+// 	const params: SelectByCondition_1Params = {};
+// 	if (pageNum && pageSize) {
+// 		selectByCondition_1(pageNum, pageSize, params).then(res => {
+// 			searchConData.value = res.data as [];
+// 			pagination.page = searchpagedata.value
+// 			pagination.pageSize = searchpagesize.value
+// 			window.$message?.success('查询成功');
+// 		})
+// 	}
+// 	else if (!pageNum && !pageSize) {
+// 		searchpagedata.value = 0;
+// 		searchpagesize.value = 0;
+// 		window.$message?.warning('请输入页码和条数进行查询');
+// 	}
+// }
+// function getTableData() {
+// 	startLoading();
+// 	selectAll_1().then(res => {
+// 		setTimeout(() => {
+// 			tableData.value = res.data as [];
+// 			endLoading();
+// 		}, 1000);
+// 	});
+
+// }
+function init() {
+	searchCondition();
 }
+// 初始化
+init();
 
+// function searchConClear() {
+// 	searchConData.value.length = 0
+// 	searchpagedata.value = 0;
+// 	searchpagesize.value = 0;
+// 	getTableData();
+// }
 
-const checkedRowKeysRef = ref<DataTableRowKey[]>([])
+const showSearch = ref(false)
+function handleOpenSearch() {
+	// 点击查询时显示搜索框
+	showSearch.value = !showSearch.value;
+}
+// 输入数据
+// function handleChange(v: string) {
+// 	searchId.value = Number(v)
+// }
+// 根据id查询数据
+// async function handleSearch() {
+// 	if (searchId.value) {
+// 		await selectById_1(searchId.value)
+// 			.then(res => {
+// 				// 更新数据
+// 				searchInput.value = res.data as [];
+// 				const filteredItems = tableData.value.filter(item => item.id === searchInput.value.id)
+// 				searchForm.value = filteredItems;
+// 				window.$message?.success('查询成功');
+// 			})
+// 	}
+// 	else {
+// 		searchForm.value.length = 0
+// 		window.$message?.warning('请输入有效的ID进行查询');
+// 	}
+// }
+
+// function searchClear() {
+// 	searchForm.value.length = 0
+// 	getTableData();
+// }
 
+const checkedRowKeysRef = ref<DataTableRowKey[]>([])
+const s = ref<DataTableRowKey[]>([])
+// 根据id进行删除
 async function deleteTableData() {
-	const ids = checkedRowKeysRef.value;
-	// console.log(ids);
+	const ids = checkedRowKeysRef.value.filter((item) => !s.value?.includes(item));
+	s.value = checkedRowKeysRef.value
 	if (ids.length !== 0) {
 		console.log(ids);
-		for (let id of ids) {
+		for (const id of ids) {
 			// 调用删除接口
-			console.log(id);
 			await deleteById(id as number)
 				.then((res) => {
-					const deleteRes = res.data;
-					if (!deleteRes)
-						console.log(`成功删除课程,ID: ${id}`);
 					window.$message?.success('删除成功!');
 				})
-				.catch((error) => {
-					// 错误处理
-					console.error(`删除课程发生错误,ID: ${id}`, error);
-					window.$message?.error('删除失败!');
-				});
 		}
-		getTableData(); // 删除完成后刷新表格数据
+		searchCondition(); // 删除完成后刷新表格数据
 	} else {
 		// 没有选择任何行时的操作
-		console.warn('未选择要删除的行');
+		window.$message?.error('未选择要删除的行');
 	}
-
 }
 
-
-const modalType = ref<ModalType>('add');
+const modalType = ref<ModalType>('add' || 'edit');
 
 function setModalType(type: ModalType) {
 	modalType.value = type;
 }
-
-const addData = ref<AddEasEduCategoryParams[]>([]);
+// 添加
 function addTableData() {
 	openModal();
-	getTableData(); // 删除完成后刷新表格数据
 	setModalType('add');
-	// const params: AddEasEduCategoryParams = {};
-	// addEasEduCategory(params).then(res => {
-	// 	console.log(res);
-	// 	addData.value = res.data as [];
-	// });
-
 }
 
-function init() {
-	getTableData();
+const editData = ref<SelectByCondition_1Params | null>(null);
+function setEditData(data:SelectByCondition_1Params | null) {
+	editData.value = data;
+}
+function handleEditTable(findItem: SelectByCondition_1Params) {
+	//  findItem = tableData.value.find(item => item.id === rowId);
+	setModalType('edit');
+	openModal();
+	if (findItem) {
+		setEditData(findItem);
+	}
+	searchCondition(); // 编辑完成后刷新表格数据
 }
 
-// 初始化
-init();
+function handleDeleteTable(rowId: string) {
+	// const findItem = tableData.value.find(item => item.id === rowId);
+	const rowIdNumber = Number(rowId);
+		deleteById(rowIdNumber)
+		init()
+}
+function deleteSubjectsList() {
+	const difference = checkedRowKeysRef.value.filter(item => !s.value.includes(item));
+	s.value = checkedRowKeysRef.value
+	for (let i = 0; i < difference.length; i++) {
+		deleteById(Number(difference[i]));
+	}
+	init();
+}
+function searchCondition() {
+	selectByCondition_1(pagination.page, pagination.pageSize, conditionParams).then(r => {
+		tableData.value = r.data as [];
+	}).catch(() => {
+		console.log('jdias')
+	})
+}
 
-const createColumns = (): DataTableColumns<UserManagement.User> => [
+const columns: Ref<DataTableColumns<SelectByCondition_1Params>> = ref([
 	{
 		type: 'selection',
 		align: 'center',
@@ -154,7 +261,8 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
 	{
 		key: 'id',
 		title: "ID",
-		align: 'center'
+		align: 'center',
+
 	},
 	{
 		key: 'name',
@@ -189,12 +297,11 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
 		render: row => {
 			if (row.disabled) {
 				const tagTypes: Record<UserManagement.UserStatusKey, NaiveUI.ThemeColor> = {
-					'Y': 'success',
 					'N': 'error',
+					'Y': 'success',
 				};
 				return <NTag type={tagTypes[row.disabled]}>{userStatusLabels[row.disabled]}</NTag>;
-		  }
-			return
+			}
 		}
 	},
 	{
@@ -204,10 +311,10 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
 		render: row => {
 			return (
 				<NSpace justify={'center'}>
-					<NButton size={'small'} >
+					<NButton size={'small'} onClick={() => handleEditTable(row)} >
 						编辑
 					</NButton>
-					<NPopconfirm >
+					<NPopconfirm onPositiveClick={() => handleDeleteTable(row.id.toString())}>
 						{{
 							default: () => '确认删除',
 							trigger: () => <NButton size={'small'}>删除</NButton>
@@ -218,34 +325,9 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
 		}
 
 	},
-]
-
-export default defineComponent({
-	components: {
-		TableActionAdd,
-	},
-	setup() {
-		const checkedRowKeysRef = ref<DataTableRowKey[]>([])
-
-		return {
-			tableData,
-			addData,
-			loading,
-			modalType,
-			getTableData,
-			addTableData,
-			setModalType,
-			deleteTableData,
-			visible,
-			columns:createColumns(),
-			checkedRowKeys: checkedRowKeysRef,
-			pagination,
-			rowKey: (row: RowData) => row.id,
-			handleCheck(rowKeys: DataTableRowKey[]) {
-				checkedRowKeysRef.value = rowKeys
-				console.log(checkedRowKeysRef.value);
-			}
-		}
-	}
-})
+])as Ref<DataTableColumns<SelectByCondition_1Params>>
+const rowKey = (row: RowData) => row.id
+function handleCheck(rowKeys: DataTableRowKey[]) {
+	checkedRowKeysRef.value = rowKeys
+}
 </script>

+ 1 - 11
src/views/management/user/index.vue

@@ -193,18 +193,10 @@ function setModalType(type: ModalType) {
 	modalType.value = type;
 }
 
-
-// const addData = ref<AddEasEduCategoryParams[]>([]);
 function addTableData() {
 	openModal();
 	getTableData(); // 删除完成后刷新表格数据
 	setModalType('add');
-	// const params: AddEasEduCategoryParams = {};
-	// addEasEduCategory(params).then(res => {
-	// 	console.log(res);
-	// 	addData.value = res.data as [];
-	// });
-
 }
 
 
@@ -228,15 +220,13 @@ function handleEditTable(rowId: string) {
 	openModal();
 }
 
-
-
-
 function handleDeleteTable(rowId: string) {
 	window.$message?.info(`点击了删除,rowId为${rowId}`);
 }
 
 const pagination: PaginationProps = ref({
 	page: 1,
+
 	pageSize: 10,
 	showSizePicker: true,
 	pageSizes: [10, 20, 50],