import 'dart:async'; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:sk_base_mobile/constants/global_url.dart'; import 'package:sk_base_mobile/models/base_response.dart'; import 'package:sk_base_mobile/models/dict_type.model.dart'; import 'package:sk_base_mobile/services/dio.service.dart'; import '../constants/constants.dart'; class Api { // 登录 static Future login(String username, String password) { return DioService.dio.post( Urls.login, data: {'username': username, 'password': password}, ); } // 获取个人信息 static Future getUserInfo() { return DioService.dio.get( Urls.userInfo, ); } // 分页获取项目列表 static Future> getProjects(Map params) { return DioService.dio.get(Urls.projects, queryParameters: {'page': 1, 'pageSize': 10, ...params}); } // 分页获取产品列表 static Future> getProducts(Map params) { return DioService.dio.get(Urls.products, queryParameters: {'page': 1, 'pageSize': 10, ...params}); } // 分页获取原材料出入库列表 static Future> getInventoryInout(Map params) { return DioService.dio.get(Urls.inventoryInout, queryParameters: {'page': 1, 'pageSize': 10, ...(params)}); } // 获取原材料出入库详情 static Future getInventoryInOutInfo(int id) { return DioService.dio.get( '${Urls.inventoryInout}/$id', ); } // 创建出入库记录 static Future createInventoryInout(Map params) { return DioService.dio.post(Urls.inventoryInout, data: params); } // 更新出入库记录 static Future updateInventoryInout(int id, Map params) { return DioService.dio.put('${Urls.inventoryInout}/$id', data: params); } // 分页获取库存列表 static Future> getInventory(Map params) { return DioService.dio.get(Urls.inventory, queryParameters: {'page': 1, 'pageSize': 10, ...(params)}); } // 分页获取用户 static Future> getUsers(Map params) { return DioService.dio.get(Urls.sysUser, queryParameters: {'page': 1, 'pageSize': 10, ...(params)}); } // 一次性获取所有的字典类型(不分页) static Future getDictTypeAll(Map params) { return DioService.dio.post(Urls.getDictType, data: params); } static Future logout() { return DioService.dio.post( Urls.logout, ); } static Future deleteAccount() { return DioService.dio.post( Urls.deleteAccount, ); } static Future saveUserInfo(Map data) { return DioService.dio.post(Urls.saveUserInfo, data: data); } static Future uploadImg(File file, {String? bussinessModule, String? bussinessRecordId}) async { String fileName = file.path.split('/').last; final filePath = await MultipartFile.fromFile(file.path, filename: fileName); final formData = FormData.fromMap({ 'bussinessRecordId': bussinessRecordId, 'bussinessModule': bussinessModule, 'file': filePath, }); return DioService.dio.post(Urls.uploadAttachemnt, data: formData); } static Future updateAvatar(String filename) { return DioService.dio .post(Urls.updateAvatar, data: {'avatarPath': filename}); } }