DigitalFactory/Admin.NET/Admin.NET.Web.Entry/wwwroot/Template/Manage.js.vm

116 lines
3.7 KiB
Plaintext

@{Dictionary<string, int> definedObjects = new Dictionary<string, int>();}
import request from '/@@/utils/request';
enum Api {
Add@(@Model.ClassName) = '/api/@(@Model.LowerClassName)/add',
Delete@(@Model.ClassName) = '/api/@(@Model.LowerClassName)/delete',
Update@(@Model.ClassName) = '/api/@(@Model.LowerClassName)/update',
Page@(@Model.ClassName) = '/api/@(@Model.LowerClassName)/page',
Detail@(@Model.ClassName) = '/api/@(@Model.LowerClassName)/detail',
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && (@column.WhetherAddUpdate == "Y" || column.QueryWhether == "Y")){
@:Get@(@column.FkEntityName)@(@column.PropertyName)Dropdown = '/api/@(@Model.LowerClassName)/@(@column.FkEntityName)@(@column.PropertyName)Dropdown',
}else if(@column.EffectType == "ApiTreeSelect" && !definedObjects.ContainsKey("Get@(@column.FkEntityName)Tree")){
@{definedObjects.Add("Get@(@column.FkEntityName)Tree", 1);}
@:Get@(@column.FkEntityName)Tree = '/api/@(@Model.LowerClassName)/@(@column.FkEntityName)Tree',
}else if(@column.EffectType == "Upload"){
@:Upload@(@column.PropertyName) = '/api/@(@Model.LowerClassName)/Upload@(@column.PropertyName)',
}
}
}
// 增加@(@Model.BusName)
export const add@(@Model.ClassName) = (params?: any) =>
request({
url: Api.Add@(@Model.ClassName),
method: 'post',
data: params,
});
// 删除@(@Model.BusName)
export const delete@(@Model.ClassName) = (params?: any) =>
request({
url: Api.Delete@(@Model.ClassName),
method: 'post',
data: params,
});
// 编辑@(@Model.BusName)
export const update@(@Model.ClassName) = (params?: any) =>
request({
url: Api.Update@(@Model.ClassName),
method: 'post',
data: params,
});
// 分页查询@(@Model.BusName)
export const page@(@Model.ClassName) = (params?: any) =>
request({
url: Api.Page@(@Model.ClassName),
method: 'post',
data: params,
});
// 详情@(@Model.BusName)
export const detail@(@Model.ClassName) = (id: any) =>
request({
url: Api.Detail@(@Model.ClassName),
method: 'get',
data: { id },
});
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && (@column.WhetherAddUpdate == "Y" || column.QueryWhether == "Y")){
@:export const get@(@column.FkEntityName)@(@column.PropertyName)Dropdown = () =>
@:request({
@:url: Api.Get@(@column.FkEntityName)@(@column.PropertyName)Dropdown,
@:method: 'get'
@:});
}else if(@column.EffectType == "ApiTreeSelect" && !definedObjects.ContainsKey("get@(@column.FkEntityName)Tree")){
@{definedObjects.Add("get@(@column.FkEntityName)Tree", 1);}
@:export const get@(@column.FkEntityName)Tree = () =>
@:request({
@:url: Api.Get@(@column.FkEntityName)Tree,
@:method: 'get'
@:});
}else if(@column.EffectType == "Upload"){
@:/**
@:* 上传@(@column.ColumnComment)
@:*/
@:export const upload@(@column.PropertyName) = (params: any) =>
@:uploadFileHandle(params, Api.Upload@(@column.PropertyName))
}
}
@foreach (var column in Model.TableField){
if(@column.EffectType == "Upload"){
@:export const uploadFileHandle = (params: any, url: string) => {
@:const formData = new window.FormData();
@:formData.append('file', params.file);
@://自定义参数
@:if (params.data) {
@:Object.keys(params.data).forEach((key) => {
@:const value = params.data![key];
@:if (Array.isArray(value)) {
@:value.forEach((item) => {
@:formData.append(`${key}[]`, item);
@:});
@:return;
@:}
@:formData.append(key, params.data![key]);
@:});
@:}
@:return request({
@:url: url,
@:method: 'POST',
@:data: formData,
@:headers: {
@:'Content-type': 'multipart/form-data;charset=UTF-8',
@:// ts-ignore
@:ignoreCancelToken: true,
@:},
@:});
@:};
break;
}
}