实例
/**
* mock数据与接口
* 资源管理接口
*/
const Mock = require("mockjs");
import api from "../api/index";
import vue from "vue";
//是否mock数据
let isMock:boolean = process.env.VUE_APP_IS_MOCK == "true";
//获取mock数据
function getMockData(template:any){
const result = Mock.mock(template);
return result;
}
//返回参数类型定义
interface res{
code:number,
message:string,
data:any
}
//请求获取数据
const actions = {
// 发布信息资源
async publishInfoResource(obj:{id:string}) {
const template = {
code: 0,
message: "success",
data: {
iSuccess:'Y'
}
};
if (isMock) {
//是否是mock数据
return getMockData(template)
}
let params={
infoResourceId: obj.id
}
let result:res = await vue.prototype.$http.post(api.publish, params).then(
(data: any) => {
return data.data;
},
(error: any) => {
return {};
}
);
return result;
},
//取消发布信息资源
async cancelPublishInfoResource(obj:{id:string}) {
const template = {
code: 0,
message: "success",
data: {
iSuccess:'Y'
}
};
if (isMock) {
//是否是mock数据
return getMockData(template)
}
let params={
infoResourceId: obj.id
}
let result:res = await vue.prototype.$http.post(api.cancelPublish, params).then(
(data: any) => {
return data.data;
},
(error: any) => {
return {};
}
);
return result;
},
//关联文件接口
async fileRelation(obj:{infoResourceId:string,dataResourceId:string}) {
const template = {
code: 0,
message: "success",
data: {
iSuccess:'Y'
}
};
if (isMock) {
//是否是mock数据
return getMockData(template)
}
let result:res = await vue.prototype.$http.post(api.fileRelation, obj).then(
(data: any) => {
return data.data;
},
(error: any) => {
return {};
}
);
return result;
},
//详情页关联文件列表
async getInfoDetailFileList(obj:{infoResourceId:string}) {
const template = {
code: 0,
message: "success",
'data|10': [
{
"id": "@id",
"fileName": "@cname",
"fileNameExtension": "cname",
"fileType": "png",
"fileSize": "12"
}
]
};
if (isMock) {
//是否是mock数据
return getMockData(template)
}
let result:res = await vue.prototype.$http.get(api.infoDetailFileList, {params:obj}).then(
(data: any) => {
return data.data;
},
(error: any) => {
return {};
}
);
return result;
},
};
export default actions;