gaosp
2024-01-29 a359332dbd9fbedee6db289a8dfcf1986d8639b1
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * @Date: 2024-01-10 20:37:45
 * @LastEditors: Sneed
 * @LastEditTime: 2024-01-29 20:33:21
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/api/Api.js
 */
import ajax from '@/utils/ajax'
import { cfgUtil } from 'cfgUtil'
// const BASE_URL = process.env.BASE_API
const HttpConstants = {
    // 使用部门 下啦数据
    useDepartments: '/account/useDepartments',
    // 台账保存
    accountCreate: '/account/create',
    accountUpdate: '/account/update',
    //设备类型
    deviceTypeCreate: '/devicetype/create',
    deviceTypeUpdate: '/devicetype/update',
    deviceTypeDelete: '/devicetype/delete',
    // 车间 工段下啦数据
    getWsl: '/machine/workshopList',
    getPcl: '/machine/protocolList'
}
const getFnObj = {
    login: {
        url: '/user/login',
        method: 'POST'
    },
    accountQuery: {
        url: '/account/remainings',
        method: 'GET'
    },
    deviceRemainings: {
        url: '/account/remainings',
        method: 'GET'
    },
    accountDel: {
        url: '/account/delete',
        method: 'POST'
    },
    componentQuery: {
        url: '/component/pageQuery',
        method: 'POST'
    },
    deviceTypeQuery: {
        url: '/devicetype/pageQuery',
        method: 'POST'
    },
    maintainCreate: {
        url: '/maintain/save',
        method: 'POST'
    },
    maintainUpdate: {
        url: '/maintain/modify',
        method: 'POST'
    },
    maintainDel: {
        url: '/maintain/delete',
        method: 'POST'
    },
    maintaindelete: {
        url: '/devicetype/delete',
        method: 'POST'
    },
    deviceTypeQuery: {
        url: '/devicetype/pageQuery',
        method: 'POST'
    },
    deviceTypeCreate: {
        url: '/devicetype/save',
        method: 'POST'
    },
    deviceTypeUpdate: {
        url: '/devicetype/update',
        method: 'POST'
    },
    deviceTypeDelete: {
        url: '/devicetype/delete',
        method: 'POST'
    },
    deviceTypeList:  {
        url: '/devicetype/list',
        method: 'GET'
    },
    machineList: {
        url: '/machine/list',
        method: 'POST'
    },
    machineConcern: {
        url: '/machine/concern',
        method: 'POST'
    },
    machineQuery: {
        url: '/machine/pageQuery',
        method: 'POST'
    },
    machineSave: {
        url: '/machine/save',
        method: 'POST'
    },
    machineUpdate: {
        url: '/machine/modify',
        method: 'POST'
    },
    userList: {
        url: '/user/list',
        method: 'GET'
    },
    getbyid: {
        url: '/machinedata/getbyid',
        method: 'POST'
    },
    
}
// 正式环境配置地址
export const URL_CFG = {
    BASE_URL: '',
    WEB_SOCKET_URL: ''
}
 
// 当前用户
export function initApplicationCfg() {
    return new Promise((resolve) => {
        if (!URL_CFG.BASE_URL || !URL_CFG.BASE_URL) {
            URL_CFG.BASE_URL = process.env.NODE_ENV === 'development' ? process.env.BASE_API : cfgUtil.baseUrl
            // URL_CFG.WEB_SOCKET_URL = process.env.NODE_ENV === 'development' ? 'ws://192.168.234.2:8087/mdc/websocket' : cfgUtil.wsUrl
            URL_CFG.WEB_SOCKET_URL = process.env.NODE_ENV === 'development' ? 'ws://localhost:8087/mdc/websocket' : cfgUtil.wsUrl
        }
        resolve(true)
    })
}
/**
 *
 * @param method
 * @param params
 * @return {*}
 */
function sendRequest(method, params) {
    return ajax.postJson(URL_CFG.BASE_URL + method, params)
}
function sendFormRequest(method, params) {
    return ajax.post(URL_CFG.BASE_URL + method, params)
}
/*
* @param method
* @param params
* @return {*}
*/
export function getData(method, params) {
    return ajax.get(URL_CFG.BASE_URL + method, params)
}
 
// 使用部门下拉框
export function getUseDpts(user, pw) {
    return getData(HttpConstants.useDepartments, {})
}
// 台账保存
export function accountCreate(params) {
    return sendRequest(HttpConstants.accountCreate, params)
}
export function accountUpdate(params) {
    return sendRequest(HttpConstants.accountUpdate, params)
}
 
// 设备类型保存
export function deviceTypeCreate(params) {
    return sendRequest(HttpConstants.deviceTypeCreate, params)
}
export function deviceTypeUpdate(params) {
    return sendRequest(HttpConstants.deviceTypeUpdate, params)
}
export function deviceTypeDelete(ids) {
    console.log(HttpConstants.deviceTypeDelete)
    return sendRequest(HttpConstants.deviceTypeDelete, { ids: ids })
}
 
// 
export function getWsl(params) {
    return getData(HttpConstants.getWsl, params)
}
 
export function getPcl(params) {
    return getData(HttpConstants.getPcl, params)
}
 
export function getRequest (key,params) {
    if (getFnObj[key].method === 'GET') {
        return getData(getFnObj[key].url,params || {})
    } else {
        return sendRequest(getFnObj[key].url, params || {})
        
    }
}
export function getFormRequest (key,params) {
    if (getFnObj[key].method === 'GET') {
        // return getData(getFnObj[key].url,params || {})
    } else {
        return sendFormRequest(getFnObj[key].url, params || {})
        
    }
}
export function getUrl (key) {
    return getFnObj[key].url
}