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', @foreach (var column in Model.TableField){ if(@column.EffectType == "fk"){ @:Get@(@column.FkEntityName)Dropdown = '/api/@(@Model.LowerClassName)/@(@column.FkEntityName)Dropdown', }else if(@column.EffectType == "ApiTreeSelect"){ @:Get@(@column.FkEntityName)Tree = '/@(@Model.LowerClassName)/@(@column.FkEntityName)Tree', }else if(@column.EffectType == "Upload"){ @:Upload@(@column.ColumnName) = '/api/@(@Model.LowerClassName)/Upload@(@column.ColumnName)', } } } // 增加@(@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, }); @foreach (var column in Model.TableField){ if(@column.EffectType == "fk"){ @:export const get@(@column.FkEntityName)Dropdown = () => @:request({ @:url: Api.Get@(@column.FkEntityName)Dropdown, @:method: 'get' @:}); }else if(@column.EffectType == "ApiTreeSelect"){ @: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.ColumnName) = (params: any) => @:uploadFileHandle(params, Api.Upload@(@column.ColumnName)) } } @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; } }