142 lines
5.1 KiB
JavaScript
142 lines
5.1 KiB
JavaScript
import axios from 'axios';
|
||
import store from '../store'; // 引入 Vuex store
|
||
|
||
const backendUrl = store.state.backendUrl;
|
||
|
||
/**
|
||
* 提交登录检查请求
|
||
*
|
||
* 该函数使用axios库发送POST请求到后端服务器,以检查用户登录状态
|
||
* 主要作用是验证用户是否已经登录,或者提供的登录信息是否正确
|
||
*
|
||
* @param {Object} payload - 包含登录所需信息的对象,如用户名和密码
|
||
* @returns {Promise} - 返回一个Promise对象,包含后端的响应数据
|
||
*
|
||
* 注意:这里使用了动态的后端地址,以便于在不同环境下进行配置
|
||
* 函数名LoginCheck采用了驼峰命名法,以符合JavaScript命名的常见规范
|
||
*/
|
||
export function LoginCheck(payload) {
|
||
// 构造请求URL
|
||
const url = `${backendUrl}/LoginCheck`; // 使用动态的后端地址
|
||
// 发送POST请求
|
||
return axios.post(url, payload)
|
||
// 处理成功响应
|
||
.then(response => response.data)
|
||
// 处理错误响应
|
||
.catch(error => {
|
||
// 抛出具体错误信息
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
|
||
/**
|
||
* 向后端发送获取位置数据的请求
|
||
*
|
||
* 该函数使用axios库通过POST方法向后端发送请求,请求指定URL的资源
|
||
* 它主要用于获取位置相关数据,可以根据需要更改后端URL和请求数据格式
|
||
*
|
||
* @param {Object} data - 请求后端时携带的数据对象
|
||
* @returns {Promise} - 返回一个Promise对象,包含后端响应的数据
|
||
*/
|
||
export function getdata(data) {
|
||
// 构造请求URL,这里使用了模板字符串来动态插入后端地址
|
||
const url = `${backendUrl}/request/getlocation`; // 使用动态的后端地址
|
||
// 使用axios发送POST请求
|
||
return axios.post(url, data)
|
||
// 当请求成功时,提取响应中的数据部分并返回
|
||
.then(response => response.data)
|
||
// 当请求失败时,抛出错误,便于调用者处理
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 向后端发送查询请求的信息
|
||
*
|
||
* 此函数使用axios库通过POST方法向后端发送查询请求它动态地构造请求URL,
|
||
* 并将查询数据作为参数传递给后端服务如果请求失败,它会捕获错误并重新抛出,
|
||
* 以便调用者可以处理错误
|
||
*
|
||
* @param {Object} data - 包含查询参数的对象
|
||
* @returns {Promise} - 返回一个Promise对象,当查询成功时,Promise解析为后端返回的数据
|
||
* @throws {Error} - 当查询失败时,抛出一个错误对象
|
||
*/
|
||
export function QueryInfo(data) {
|
||
// 动态地构造请求URL,以便能够根据环境变化调整后端地址
|
||
const url = `${backendUrl}/api/query`;
|
||
|
||
// 使用axios发送POST请求到后端,并传递查询数据
|
||
return axios.post(url, data)
|
||
// 当请求成功时,提取并返回响应数据
|
||
.then(response => response.data)
|
||
// 当请求失败时,捕获错误并重新抛出,以便调用者可以处理
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
|
||
/**
|
||
* 根据标签创建箱号
|
||
*
|
||
* 该函数通过POST请求向后端发送数据,以创建箱号
|
||
* 它使用了动态构建的URL,以适应不同的后端环境
|
||
*
|
||
* @param {Object} data - 包含创建箱号所需信息的对象
|
||
* @returns {Promise} - 返回一个Promise对象,解析为后端响应的数据
|
||
* @throws {Error} - 如果请求失败,抛出错误,包含错误的详细信息
|
||
*/
|
||
export function CreateBoxID_PO(data) {
|
||
// 动态构建请求URL,适应不同的后端服务地址
|
||
const url = `${backendUrl}/PoStockIn/POCreateBoxByLabel`;
|
||
|
||
// 发送POST请求到后端,并处理响应
|
||
return axios.post(url, data)
|
||
.then(response => response.data)
|
||
.catch(error => {
|
||
// 如果发生错误,抛出详细的错误信息
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
|
||
export function MDCReceive(data) {
|
||
const url = `${backendUrl}/MDCManage/MDCReceive`; // 使用动态的后端地址
|
||
return axios.post(url, data)
|
||
.then(response => response.data)
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
export function Unboxing(data) {
|
||
const url = `${backendUrl}/MDCManage/Unboxing`; // 使用动态的后端地址
|
||
return axios.post(url, data)
|
||
.then(response => response.data)
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
export function StockOutPMS(data) {
|
||
const url = `${backendUrl}/Material/StockOutPMS`; // 使用动态的后端地址
|
||
return axios.post(url, data)
|
||
.then(response => response.data)
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|
||
|
||
export function MDCReceiveNew(data) {
|
||
const url = `${backendUrl}/MDCManage/MDCReceiveNew`; // 使用动态的后端地址
|
||
return axios.post(url, data)
|
||
.then(response => response.data)
|
||
.catch(error => {
|
||
throw error.response ? error.response.data : error;
|
||
});
|
||
}
|