import { CategoryModel } from './../pages/category/Model' ; import { message } from 'antd' ; import jsonp from 'jsonp' ; import ajax from './ajax' ; import { ResponseValue } from './Model' ; import { ReqMethodEnum } from './ReqMethodEnum' ; import { PageSplitModel } from './Model' ; import { ProductsModel } from '../pages/product/Model' ; import { BASE_URL } from '../utils/Constants' ; import { RoleModel } from '../pages/role/Model' ; import { UserModel } from '../pages/user/model' ; name test msg param { string } name param { string } password return { * } export const reqLogin = ( name , password ) : Promise < ResponseValue < UserModel > > => ajax < ResponseValue < UserModel > > ( '/api/user/login' , { name , password } , ReqMethodEnum . POST ) ; name test msg param { any } user return { * } export const reqAddUser = ( user ) : Promise < string > => ajax < string > ( '/api/user/add' , user , ReqMethodEnum . POST ) ; export const reqWheater = ( city ) : Promise < { dayPictureUrl : any ; weather : any ; } > => { return new Promise ( ( resolve , reject ) => { jsonp ( `http://api.map.baidu.com/telematics/v3/weather?location=${ city }&output=json&ak=3p49MVra6urFRGOT9s8UBWr2` , ( err , data ) => { if ( ! err && data . status === 'success' ) { const { dayPictureUrl , weather } = data . results [ 0 ] . weather_data [ 0 ] ; resolve ( { dayPictureUrl , weather } ) ; } else { message . error ( '获取天气信息失败!' ) ; } } ) ; } ) ; } ; name test msg param { string } id return { Promise < CategoryModel > } export const reqCategoryById = ( id ) : Promise < CategoryModel > => ajax < CategoryModel > ( `/api/category/findCategoryById/${ id }` ) ; name test msg param { string } parentId return { Promise < ResponseValue < any > } export const reqCategorys = ( parentId ) : Promise < ResponseValue < any > > => ajax < ResponseValue < any > > ( `/api/category/list/${ parentId }` ) ; name test msg param { string } parentId param { string } categoryName param { string } name return { Promise < ResponseValue < any > > } export const reqAddCategory = ( parentId , categoryName , name ) : Promise < ResponseValue < any > > => ajax < ResponseValue < any > > ( '/api/category/add' , { parentId , categoryName , name } , ReqMethodEnum . POST ) ; name test msg param { id return { Promise < ResponseValue < any > > } export const reqUpdateCategory = ( id , parentId , name , categoryName ) : Promise < ResponseValue < any > > => ajax < ResponseValue < any > > ( '/api/category/update' , { id , parentId , name , categoryName } , ReqMethodEnum . PUT ) ; name test msg param { number } pageNum param { number } pageSize return { Promise < PageSplitModel < ProductsModel > } export const reqProducts = ( pageNum , pageSize ) : Promise < PageSplitModel < ProductsModel > > => ajax < PageSplitModel < ProductsModel > > ( '/api/products/list' , { pageNum , pageSize } , ReqMethodEnum . POST ) ; name test msg param { desc return { Promise < PageSplitModel < ProductsModel > } export const reqProductsByDesc = ( desc , pageNum , pageSize ) : Promise < PageSplitModel < ProductsModel > > => ajax < PageSplitModel < ProductsModel > > ( `/api/products/searchByDesc/${ desc }/${ pageNum }/${ pageSize }` , ReqMethodEnum . GET ) ; name test msg param { * } return { * } export const reqProductsByName = ( name , pageNum , pageSize ) : Promise < PageSplitModel < ProductsModel > > => ajax < PageSplitModel < ProductsModel > > ( `/api/products/searchByName` , { name : name , pageNum : pageNum , pageSize : pageSize , } , ReqMethodEnum . GET ) ; name test msg param { number } id param { number } status return { Promise < number > } export const reqUpdateStatus = ( id , status ) : Promise < number > => ajax < number > ( `/api/products/updateStatus/${ id }` , { status : status } , ReqMethodEnum . PUT ) ; name test msg param { number } id param { string } images return { Promise < number > } export const reqUpdateProductsImages = ( id , images ) : Promise < number > => ajax < number > ( `/api/products/updateImages/${ id }` , { images , } , ReqMethodEnum . PUT ) ; name test msg param { string } fileName return { Promise < ResponseValue < number > } export const reqDeleteProductsImages = ( fileName ) : Promise < ResponseValue < number > > => ajax < ResponseValue < number > > ( `${ BASE_URL }/deleteFile/${ fileName }` , { } , ReqMethodEnum . DELETE ) ; name test msg param { ProductsModel } product return { Promise < ResponseValue < number > > } export const reqAddProduct = ( product ) : Promise < ResponseValue < number > > => ajax < ResponseValue < number > > ( `/api/products/addProduct` , product , ReqMethodEnum . POST ) ; name test msg param { number } id param { ProductsModel } product return { Promise < ResponseValue < number > > } export const reqUpdateProduct = ( id , product ) : Promise < ResponseValue < number > > => ajax < ResponseValue < number > > ( `/api/products/updateProduct/${ id }` , product , ReqMethodEnum . PUT ) ; name test msg param { } return { Promise < ResponseValue < RoleModel [ ] > } export const reqRoles = ( ) : Promise < ResponseValue < RoleModel [ ] > > => ajax < ResponseValue < RoleModel [ ] > > ( '/api/role/getRoles' , { } , ReqMethodEnum . GET ) ; name test msg param { RoleModel } role return { Promise < String > } export const reqCreateRole = ( role ) : Promise < string > => ajax ( '/api/role/createRole' , role , ReqMethodEnum . POST ) ; name test msg param { string } name return { Promise < string > } export const reqCreateRoleByName = ( name ) : Promise < string > => ajax < string > ( '/api/role/createRoleByName' , name , ReqMethodEnum . POST ) ; name test msg param { string } id param { RoleModel } role return { * } export const reqUpdateRole = ( id , role ) : Promise < string > => ajax < string > ( `/api/role/updateRole/${ id }` , role , ReqMethodEnum . PUT ) ; name test msg param { } return { Promise < UserModel [ ] > } export const reqUsers = ( ) : Promise < UserModel [ ] > => ajax < UserModel [ ] > ( '/api/user/getUsers' , { } , ReqMethodEnum . GET ) ; name test msg param { UserModel } user return { string } export const reqUpdateUser = ( user ) : Promise < string > => ajax < string > ( `/api/user/update/${ user . id }` , user , ReqMethodEnum . PUT ) ; name test msg param { number } id return { * } export const reqDeleteUser = ( id ) : Promise < string > => ajax < string > ( `/api/user/delete/${ id }` , { } , ReqMethodEnum . DELETE ) ; name test msg param { string } id return { role } export const reqRoleById = ( id ) : Promise < RoleModel > => ajax < RoleModel > ( `/api/role/get/${ id }` , { } , ReqMethodEnum . GET ) ;