post请求(body)
// 风险清单管理-分页查询
const riskList = (data: any) => {
return axios({
method: 'post',
url: SERVICE_BASIC + '/Risk/RiskListManagementController/riskList',
data: JSON.stringify(data),
});
};
普通键值对
key:value
list传值
['1','2','3']
map类型或实体类型,json格式
[{
a:'1',
b:''
}]
post请求(query得形式)
// 隐患排查--导入接口
export const importTemplate = (data: any) => {
return axios({
method: 'post',
url:
SERVICE_BASIC +
'/knowledge/hiddenDanger/importTemplate?enterpriseType=' +
data.enterpriseType +
'&' +
'troubleshootingName=' +
data.troubleshootingName +
'&' +
'troubleshootingType=' +
data.troubleshootingType,
data: data.xlsFile,
});
};
post请求(formdata得形式)
// 附件----附件上传-新增页面
export const baseFileSave = (data: any) => {
return axios({
method: 'post',
url: SERVICE_ENCLOSURE + '/knoFilepath/baseFileSave',
data,
});
};
// 附件上传
private submitEnclosure(file: any) {
// formdata 格式得传参
const myFormData: any = new FormData();
myFormData.set('file', file.file);
myFormData.set('fileType', this.fileType);
this.myFileList = (this.$refs.upload as any).uploadFiles;
let serviceStr: any = '';
if (this.type === 'add') {
myFormData.set('moduleId', this.moduleId);
serviceStr = 'baseFileSave';
} else if (this.type === 'edit') {
myFormData.set('id', this.dataId);
myFormData.set('moduleId', this.moduleId);
serviceStr = 'baseUpload';
}
this.serviceobj[serviceStr](myFormData)
.then((res: any) => {
console.log('$refs.upload');
console.log((this.$refs.upload as any).fileList);
// let temFileList = (this.$refs.upload as any).fileList;
this.fullscreenLoading = false;
if (res.data.msg === '成功') {
this.$message.success('上传成功!');
const newName = res.data.data.fileName;
this.myFileList.forEach((item: any) => {
if (item.name === newName) {
item.id = res.data.data.id;
}
});
this.watchMyFileList(this.myFileList);
this.$emit('onUploadSuccess', file, this.myFileList);
}
})
.catch((err: any) => {
this.fullscreenLoading = false;
return false;
});
}
get请求
// 导出
private exportFun() {
let idArr: any = '';
if (this.$store.state.commonModule.dataCheckedArr.length > 0) {
this.$store.state.commonModule.dataCheckedArr.forEach((i: any) => {
idArr += 'idList=' + i.id + '&';
});
} else {
idArr = 'idList=';
}
// 直接在url后面拼接参数
window.location.href =
(this as any).$SERVICE_BASIC +
'/knowledge/discretion/discretionKnoExport?' +
idArr;
}