feat: 新增勘察明细管理与修改密码功能
This commit is contained in:
1 parent
56830e94ec
commit
774403785c
12 files changed
+1553
-18
No files matched your search
@@ -6,6 +6,31 @@ import 'package:dio/dio.dart';
|
||||
import '../storage/token_storage.dart';
|
||||
import 'api_response.dart';
|
||||
|
||||
/// 图片上传结果,与后端 `POST /api/upload/image` 的 `data` 对齐。
|
||||
class UploadResult {
|
||||
const UploadResult({
|
||||
required this.key,
|
||||
required this.url,
|
||||
required this.name,
|
||||
required this.size,
|
||||
});
|
||||
|
||||
/// 对象存储 key,持久化到业务表。
|
||||
final String key;
|
||||
|
||||
/// 预签名访问 URL,用于即时预览。
|
||||
final String url;
|
||||
final String name;
|
||||
final int size;
|
||||
|
||||
factory UploadResult.fromJson(Map<String, dynamic> json) => UploadResult(
|
||||
key: json['key'] as String? ?? '',
|
||||
url: json['url'] as String? ?? '',
|
||||
name: json['name'] as String? ?? '',
|
||||
size: (json['size'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
/// 统一请求封装,等价于 uni-app 版 `utils/request.ts`:
|
||||
/// - 自动注入 `Authorization: Bearer <token>`
|
||||
/// - 解析 `{ code, message, data }`,非 200 也照常返回给调用方判断
|
||||
@@ -64,6 +89,36 @@ class ApiClient {
|
||||
bool needAuth = true,
|
||||
}) => _send<T>('PUT', url, body: body, parse: parse, needAuth: needAuth);
|
||||
|
||||
/// 上传现场照片到对象存储(multipart/form-data,字段名 `file`)。
|
||||
/// 走电工通道 `POST /api/worker-app/upload/image`(电工 token 无法访问管理端 `/api/upload`)。
|
||||
/// 依赖对象存储:失败直接抛异常,由调用方阻断保存并提示用户。
|
||||
Future<UploadResult> uploadImage(String filePath) async {
|
||||
try {
|
||||
final form = FormData.fromMap({
|
||||
'file': await MultipartFile.fromFile(filePath),
|
||||
});
|
||||
final res = await _dio.post<dynamic>(
|
||||
'/worker-app/upload/image',
|
||||
data: form,
|
||||
options: Options(headers: _authHeader()),
|
||||
);
|
||||
final json = _asMap(res.data);
|
||||
final code = (json['code'] as num?)?.toInt();
|
||||
final data = json['data'];
|
||||
if (code == 200 && data is Map) {
|
||||
return UploadResult.fromJson(data.cast<String, dynamic>());
|
||||
}
|
||||
throw ApiException(
|
||||
(json['message'] as String?) ?? '图片上传失败',
|
||||
code: code,
|
||||
);
|
||||
} on ApiException {
|
||||
rethrow;
|
||||
} catch (_) {
|
||||
throw const ApiException('图片上传失败:网络异常');
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() => _unauthorizedController.close();
|
||||
|
||||
// ---- 内部实现 ----
|
||||
|
||||
Reference in new issue
Block a user