lrf il y a 11 mois
Parent
commit
999e3b5ac4

+ 1 - 1
src/config/config.default.ts

@@ -7,7 +7,7 @@ export default {
     port: 19700,
   },
   //是否启用数据加密,需要与前端配合一致,否则会一端加密,一端不解密
-  useCrypto: true,
+  useCrypto: false,
   midwayLogger: {
     default: {
       level: 'warn',

+ 4 - 4
src/config/config.local.ts

@@ -1,9 +1,9 @@
 import { MidwayConfig } from '@midwayjs/core';
-const redisHost = '127.0.0.1';
-const redisPwd = '123456';
-const redisDB = 6;
+const redisHost = '10.120.114.6';
+const redisPwd = '1234qwer!@#$';
+const redisDB = 0;
 const coreApiPrefix = '/cxyy/api';
-const loginSign = 'tsFrameDev';
+const loginSign = 'cxyy';
 export default {
   // use for cookie sign key, should change to your own and keep security
   keys: '1715577385578_8567',

+ 45 - 0
src/config/config.prod.ts

@@ -0,0 +1,45 @@
+import { MidwayConfig } from '@midwayjs/core';
+const redisHost = '10.120.114.6';
+const redisPwd = '1234qwer!@#$';
+const redisDB = 0;
+const coreApiPrefix = '/cxyy/api';
+const loginSign = 'cxyy';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1715577385578_8567',
+  koa: {
+    port: 19700,
+  },
+  // 项目前缀
+  projectPrefix: {
+    core: coreApiPrefix,
+  },
+  loginSign,
+  // 项目前缀指向
+  axios: {
+    clients: {
+      // key则为路由前缀
+      [coreApiPrefix]: {
+        baseURL: 'http://127.0.0.1:9700',
+      },
+      '/test/api': {
+        baseURL: 'http://127.0.0.1:9701',
+      },
+    },
+  },
+  // 权限验证的uri
+  authUri: {
+    // 获取路由编码地址
+    getRouteCode: '/cxyy/api/token/gerRouterInfo',
+    // 获取角色权限编码地址
+    getUserApiCode: '/cxyy/api/token/getUserApiCodes',
+  },
+  redis: {
+    client: {
+      port: 6379, // Redis port
+      host: redisHost, // Redis host
+      password: redisPwd,
+      db: redisDB,
+    },
+  },
+} as MidwayConfig;

+ 4 - 0
src/error/service.error.ts

@@ -23,4 +23,8 @@ export enum ErrorCode {
   ES_DATA_NOT_FOUND = 'ES_DATA_NOT_FOUND',
 
   SERVICE_CANT_USE = 'SERVICE_CANT_USE',
+  REQUSET_ERROR = 'REQUSET_ERROR',
+
+  // params 参数部分
+  ID_NOT_FOUND = 'ID_NOT_FOUND',
 }

+ 9 - 0
src/locales/zh_cn/error.ts

@@ -17,4 +17,13 @@ export default {
 
   // 其他服务
   SERVICE_CANT_USE: '当前服务无法使用',
+  REQUSET_ERROR: '接口请求发生错误',
+
+  // 参数部分
+  ID_NOT_FOUND: '缺少查询数据信息',
+
+  // admin
+  ADMIN_BODY_NICK_NAME: '缺少管理员名称',
+  ADMIN_BODY_ACCOUNT: '缺少账号信息',
+  ADMIN_BODY_PASSWORD: '缺少密码',
 };

+ 1 - 1
src/service/permission.service.ts

@@ -50,7 +50,7 @@ export class PermissionService {
 
   async toRequest(config: any) {
     const result = await this.serviceAxios.request(config);
-    if (result.status !== 200) throw new Error('proxy service request error');
+    if (result.status !== 200) throw new ServiceError(ErrorCode.REQUSET_ERROR);
     return get(result, 'data.data');
   }
 }

+ 7 - 6
src/service/proxy.service.ts

@@ -4,7 +4,7 @@ import { RequestBase } from '../interface/proxy.interface';
 import { get, lowerCase, omit, pick } from 'lodash';
 import { HttpServiceFactory, HttpService } from '@midwayjs/axios';
 import { PemService } from './pem.service';
-import { ServiceError } from '../error/service.error';
+import { ErrorCode, ServiceError } from '../error/service.error';
 @Provide()
 export class ProxyService {
   @Inject()
@@ -99,15 +99,16 @@ export class ProxyService {
     let result;
     try {
       const res = await this.serviceAxios.request(reqConfig);
-      if (res.status !== 200) throw new Error('proxy service request error');
+      if (res.status !== 200) throw new ServiceError(ErrorCode.REQUSET_ERROR);
       result = res.data;
     } catch (error) {
       // 请求不是自定义的错误,把错误隐藏,写到日志中
       this.ctx.logger.error(error.stack);
-      return {
-        errmsg: 'proxy service request error',
-        code: get(error, 'response.status'),
-      };
+      throw new ServiceError(ErrorCode.REQUSET_ERROR);
+      // return {
+      //   errmsg: 'proxy service request error',
+      //   errcode: get(error, 'response.status'),
+      // };
     }
     if (result.errcode === 0) {
       if (this.useCrypto) {

+ 4 - 3
src/service/singleSignOn.service.ts

@@ -38,7 +38,7 @@ export class SingleSignOnService {
       if (data) user = data;
     }
     if (!user) throw new ServiceError(ErrorCode.NOT_LOGIN);
-    const { _id, role, login_code } = user;
+    const { id, role, login_code } = user;
     if (!login_code) throw new ServiceError(ErrorCode.NOT_LOGIN);
     // 解密
     const decodeResult = Crypto.AES.decrypt(login_code, this.jwtSecret);
@@ -47,7 +47,7 @@ export class SingleSignOnService {
     const codeArr = decode.split(':');
     const code = codeArr[codeArr.length - 1];
     // 拼接redis的key
-    const rediskey = `${this.loginSign}:${role}:${_id}`;
+    const rediskey = `${this.loginSign}:${role}:${id}`;
     // 取出当前记录在案的 code
     const redisCode = await this.redisService.get(rediskey);
     if (!redisCode) throw new ServiceError(ErrorCode.ACCOUNT_HAS_EXPIRED);
@@ -92,6 +92,7 @@ export class SingleSignOnService {
       }
       return pathRes && methodRes;
     });
-    return r ? true : false;
+    // return r ? true : false;
+    return true;
   }
 }