lrf hai 11 meses
pai
achega
89b8793f72

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

@@ -19,7 +19,7 @@ export default {
   axios: {
     clients: {
       // key则为路由前缀
-      coreApiPrefix: {
+      [coreApiPrefix]: {
         baseURL: 'http://127.0.0.1:9700',
       },
       '/test/api': {

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

@@ -15,6 +15,7 @@ export enum ErrorCode {
   BAD_PASSWORD = 'BAD_PASSWORD',
   USER_IS_DISABLED = 'USER_IS_DISABLED',
   ROLE_IS_DISABLED = 'ROLE_IS_DISABLED',
+  NO_AUTH = 'NO_AUTH',
 
   // es
   ES_ERROR = 'ES_ERROR',

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

@@ -8,6 +8,7 @@ export default {
   BAD_PASSWORD: '密码错误',
   USER_IS_DISABLED: '该用户已被禁用',
   ROLE_IS_DISABLED: '当前角色下的用户无法使用',
+  NO_AUTH: '用户没有权限',
 
   // es
   ES_ERROR: 'ElasticSearch发生错误!',

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

@@ -3,6 +3,7 @@ import { RequestBase } from '../interface/proxy.interface';
 import { ProxyService } from './proxy.service';
 import { HttpServiceFactory, HttpService } from '@midwayjs/axios';
 import { get } from 'lodash';
+import { ErrorCode, ServiceError } from '../error/service.error';
 
 @Provide()
 export class PermissionService {
@@ -16,6 +17,7 @@ export class PermissionService {
   proxyService: ProxyService;
   @InjectClient(HttpServiceFactory, 'default')
   serviceAxios: HttpService;
+
   /**
    * 检查用户权限
    *  1.获取请求 完整的uri和method
@@ -43,7 +45,7 @@ export class PermissionService {
     };
     const uacResult: Array<string> = await this.toRequest(getUserApiCodeConfig);
     if (uacResult.includes(rcResult)) return true;
-    throw new Error('no auth');
+    throw new ServiceError(ErrorCode.NO_AUTH);
   }
 
   async toRequest(config: any) {

+ 16 - 8
src/service/singleSignOn.service.ts

@@ -68,22 +68,30 @@ export class SingleSignOnService {
         uri: `${this.corePrefix}/login`,
         method: 'post',
         desc: '登陆接口',
+        type: 'includes',
       },
       {
         uri: `${this.corePrefix}/dict`,
         method: 'get',
         desc: '字典接口',
       },
-      // {
-      //   uri: `${this.corePrefix}/token/tokenView`,
-      //   method: 'get',
-      //   desc: 'token认证',
-      // },
+      {
+        uri: `${this.corePrefix}/token/tokenView`,
+        method: 'get',
+        desc: 'token认证',
+      },
     ];
     const rb = this.proxyService.getRequstBase();
-    const r = whiteList.find(
-      f => f.uri === rb.path && toLower(f.method) === toLower(rb.method)
-    );
+    const r = whiteList.find(f => {
+      let pathRes = false;
+      const methodRes = toLower(f.method) === toLower(rb.method);
+      if (f.type && f.type === 'includes') {
+        pathRes = rb.path.includes(f.uri);
+      } else {
+        pathRes = f.uri === rb.path;
+      }
+      return pathRes && methodRes;
+    });
     return r ? true : false;
   }
 }