master
2022-02-14 1684d66eaf39f77980b987359f413d2ff5714940
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// @ts-nocheck
import request from "/@/service/request";
import { baseUrl, isDev } from "/@/config/env";
 
export default class BaseService {
    constructor(options: any = {}) {
        const crud: any = {
            page: "page",
            list: "list",
            info: "info",
            add: "add",
            delete: "delete",
            update: "update"
        };
 
        if (options?.namespace) {
            this.namespace = options?.namespace;
        }
 
        if (!this.permission) this.permission = {};
 
        for (const i in crud) {
            if (this.namespace) {
                this.permission[i] = this.namespace.replace(/\//g, ":") + ":" + crud[i];
            } else {
                this.permission[i] = crud[i];
            }
        }
    }
 
    request(options: any = {}) {
        if (!options.params) options.params = {};
 
        let ns = "";
 
        // 是否 mock 模式
        if (!this.mock) {
            if (isDev) {
                ns = this.proxy || baseUrl;
            } else {
                ns = this.proxy ? this.url : baseUrl;
            }
        }
 
        // 拼接前缀
        if (this.namespace) {
            ns += "/" + this.namespace;
        }
 
        // 处理 http
        if (options.url.indexOf("http") !== 0) {
            options.url = ns + options.url;
        }
 
        return request(options);
    }
 
    list(data: any) {
        return this.request({
            url: "/list",
            method: "POST",
            data
        });
    }
 
    page(data: any) {
        return this.request({
            url: "/page",
            method: "POST",
            data
        });
    }
 
    info(params: any) {
        return this.request({
            url: "/info",
            params
        });
    }
 
    update(data: any) {
        return this.request({
            url: "/update",
            method: "POST",
            data
        });
    }
 
    delete(data: any) {
        return this.request({
            url: "/delete",
            method: "POST",
            data
        });
    }
 
    add(data: any) {
        return this.request({
            url: "/add",
            method: "POST",
            data
        });
    }
}