master
2022-06-09 c6b04bbd291289e93131155249042c69c8d2d0bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { isObject } from "../utils";
 
export function Permission(value: string) {
    return function (target: any, key: any, descriptor: any) {
        if (!target.permission) {
            target.permission = {};
        }
 
        setTimeout(() => {
            target.permission[key] = (
                (target.namespace ? target.namespace + "/" : "") + value
            ).replace(/\//g, ":");
        }, 0);
 
        return descriptor;
    };
}
 
export function Service(value: any) {
    return function (target: any) {
        // 命名
        if (typeof value == "string") {
            target.prototype.namespace = value;
        }
 
        // 复杂项
        if (isObject(value)) {
            const { proxy, namespace, url, mock } = value;
            const item = __PROXY_LIST__[proxy];
 
            if (proxy && !item) {
                console.error(`${proxy} 指向的地址不存在!`);
            }
 
            target.prototype.namespace = namespace;
            target.prototype.mock = mock;
 
            if (proxy) {
                target.prototype.proxy = proxy;
                target.prototype.url = url || item ? item.target : null;
            }
        }
    };
}