图片复现问题
parent
818b08a5f3
commit
ef5b1ff229
|
@ -7,7 +7,6 @@ import 'package:qhd_prevention/customWidget/toast_util.dart';
|
||||||
import 'package:qhd_prevention/http/ApiService.dart';
|
import 'package:qhd_prevention/http/ApiService.dart';
|
||||||
import 'package:qhd_prevention/pages/my_appbar.dart';
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
||||||
|
|
||||||
|
|
||||||
class PhotoItem {
|
class PhotoItem {
|
||||||
final String id;
|
final String id;
|
||||||
final String filePath;
|
final String filePath;
|
||||||
|
@ -20,9 +19,9 @@ class PhotoItem {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class DangerImageUpdataPage extends StatefulWidget {
|
class DangerImageUpdataPage extends StatefulWidget {
|
||||||
const DangerImageUpdataPage(this.id, {super.key});
|
const DangerImageUpdataPage(this.id, {super.key, required this.imgList});
|
||||||
|
final List<PhotoItem> imgList;
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
@ -31,39 +30,38 @@ class DangerImageUpdataPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
||||||
|
late List<PhotoItem> _imgList = [];
|
||||||
|
|
||||||
List<PhotoItem> _imgList = [];
|
|
||||||
|
|
||||||
List<String> _yinHuanImages = [];
|
|
||||||
// List<dynamic> alreadyImageList=[];
|
// List<dynamic> alreadyImageList=[];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_imgList = widget.imgList;
|
||||||
_getAlreadyUpImages();
|
_getAlreadyUpImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _getAlreadyUpImages() async {
|
Future<void> _getAlreadyUpImages() async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final result = await ApiService.getAlreadyUpImages(widget.id);
|
final result = await ApiService.getAlreadyUpImages(widget.id);
|
||||||
if (result['result'] == 'success') {
|
if (result['result'] == 'success') {
|
||||||
final List<dynamic> newList = result['imgs'] ?? [];
|
final List<dynamic> newList = result['imgs'] ?? [];
|
||||||
setState(() {
|
setState(() {
|
||||||
for(int i=0;i<newList.length;i++){
|
for (Map item in newList) {
|
||||||
_imgList.add(PhotoItem(
|
String id = item['IMGFILES_ID'] ?? '';
|
||||||
id: newList[i]["IMGFILES_ID"], // 新图片没有ID
|
String filePath = item['FILEPATH'] ?? '';
|
||||||
filePath: newList[i]["FILEPATH"],
|
_imgList.add(
|
||||||
|
PhotoItem(
|
||||||
|
id: id, // 新图片没有ID
|
||||||
|
filePath: ApiService.baseImgPath+filePath,
|
||||||
type: "1",
|
type: "1",
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
_yinHuanImages.add(ApiService.baseImgPath +newList[i]["FILEPATH"]);
|
|
||||||
}
|
|
||||||
// alreadyImageList.addAll(newList);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
ToastUtil.showNormal(context, "加载数据失败");
|
ToastUtil.showNormal(context, "加载数据失败");
|
||||||
// _showMessage('加载数据失败');
|
// _showMessage('加载数据失败');
|
||||||
|
@ -81,43 +79,31 @@ class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
||||||
appBar: MyAppbar(title: "检查照片"),
|
appBar: MyAppbar(title: "检查照片"),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
RepairedPhotoSection(
|
RepairedPhotoSection(
|
||||||
title: "检查照片",
|
title: "检查照片",
|
||||||
maxCount: 4,
|
maxCount: 4,
|
||||||
mediaType: MediaType.image,
|
mediaType: MediaType.image,
|
||||||
isShowAI: false,
|
isShowAI: false,
|
||||||
initialMediaPaths: _yinHuanImages,
|
initialMediaPaths: _imgList.map((e)=> e.filePath).toList(),
|
||||||
onMediaAdded: (value) {
|
onMediaAdded: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_imgList.add(PhotoItem(
|
_imgList.add(
|
||||||
|
PhotoItem(
|
||||||
id: "", // 新图片没有ID
|
id: "", // 新图片没有ID
|
||||||
filePath: value,
|
filePath: value,
|
||||||
type: "2",
|
type: "2",
|
||||||
));
|
),
|
||||||
_yinHuanImages.add(value);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onMediaRemoved: (path) {
|
onMediaRemoved: (path) {
|
||||||
int delete = 0;
|
int delete = 0;
|
||||||
for(int i=0;i<_yinHuanImages.length;i++){
|
|
||||||
if(_yinHuanImages[i]==path){
|
|
||||||
delete=i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_onImageRemoved(_imgList[delete]);
|
_onImageRemoved(_imgList[delete]);
|
||||||
_yinHuanImages.removeAt(delete);
|
|
||||||
_imgList.removeAt(delete);
|
_imgList.removeAt(delete);
|
||||||
|
|
||||||
},
|
},
|
||||||
onAiIdentify: () {
|
onAiIdentify: () {},
|
||||||
|
onChanged: (List<File> value) {},
|
||||||
}, onChanged: (List<File> value) {
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
// 下一步按钮
|
// 下一步按钮
|
||||||
|
@ -135,23 +121,16 @@ class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child:
|
child: SizedBox(
|
||||||
SizedBox(
|
|
||||||
width: screenWidth - 30,
|
width: screenWidth - 30,
|
||||||
height: 50,
|
height: 50,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (_imgList.length > 4) {
|
if (_imgList.length > 4) {
|
||||||
ToastUtil.showNormal(context, "图片不能大于4张");
|
ToastUtil.showNormal(context, "图片不能大于4张");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(int i=0;i<_imgList.length;i++){
|
_submitAll();
|
||||||
if(_imgList[i].type=="2") {
|
|
||||||
_addImgFiles(_yinHuanImages[i], "14", widget.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ToastUtil.showNormal(context, "提交成功");
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"提交",
|
"提交",
|
||||||
|
@ -164,32 +143,46 @@ class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],)
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Future<void> _submitAll() async {
|
||||||
|
int i = 0;
|
||||||
|
for (PhotoItem item in _imgList) {
|
||||||
|
if (item.type == '2') {
|
||||||
|
String imgPath = await _addImgFiles(item.filePath, "14", widget.id);
|
||||||
|
if (imgPath.isEmpty) {
|
||||||
|
// 单张上传失败时的处理
|
||||||
|
ToastUtil.showError(context, "第${i+1}张上传失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToastUtil.showNormal(context, "提交成功");
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
Future<String> _addImgFiles(String imagePath, String type, String id) async {
|
Future<String> _addImgFiles(String imagePath, String type, String id) async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final raw = await ApiService.addImgFiles(imagePath, type, id);
|
final raw = await ApiService.addImgFiles(imagePath, type, id);
|
||||||
if (raw['result'] == 'success') {
|
if (raw['result'] == 'success') {
|
||||||
return raw['imgPath'];
|
Map pd = raw['pd'];
|
||||||
|
final String img = pd['FILEPATH'];
|
||||||
|
return img;
|
||||||
} else {
|
} else {
|
||||||
// _showMessage('反馈提交失败');
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('上传图片失败:$e');
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
// 出错时可以 Toast 或者在页面上显示错误状态
|
|
||||||
print('加载首页数据失败:$e');
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> _onImageRemoved(PhotoItem item) async {
|
Future<String> _onImageRemoved(PhotoItem item) async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final raw = await ApiService.onImageRemoved(item.id);
|
final raw = await ApiService.onImageRemoved(item.id);
|
||||||
if (raw['result'] == 'success') {
|
if (raw['result'] == 'success') {
|
||||||
return raw['imgPath'];
|
return raw['imgPath'];
|
||||||
|
@ -197,12 +190,10 @@ class _DangerImageUpdataPageState extends State<DangerImageUpdataPage> {
|
||||||
// _showMessage('反馈提交失败');
|
// _showMessage('反馈提交失败');
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 出错时可以 Toast 或者在页面上显示错误状态
|
// 出错时可以 Toast 或者在页面上显示错误状态
|
||||||
print('加载首页数据失败:$e');
|
print('加载首页数据失败:$e');
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ class _DangerProjectPageState extends State<DangerProjectPage> {
|
||||||
color: option['color'],
|
color: option['color'],
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
onImageTap: () {
|
onImageTap: () {
|
||||||
pushPage(DangerImageUpdataPage(item["RECORDITEM_ID"]), context);
|
_getAlreadyUpImages(item);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
@ -209,6 +209,34 @@ class _DangerProjectPageState extends State<DangerProjectPage> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Future<void> _getAlreadyUpImages(Map item) async {
|
||||||
|
try {
|
||||||
|
final result = await ApiService.getAlreadyUpImages(item["RECORDITEM_ID"]);
|
||||||
|
if (result['result'] == 'success') {
|
||||||
|
final List<dynamic> newList = result['imgs'] ?? [];
|
||||||
|
List<PhotoItem> imgList = [];
|
||||||
|
for (Map item in newList) {
|
||||||
|
String id = item['IMGFILES_ID'] ?? '';
|
||||||
|
String filePath = item['FILEPATH'] ?? '';
|
||||||
|
imgList.add(
|
||||||
|
PhotoItem(
|
||||||
|
id: id, // 新图片没有ID
|
||||||
|
filePath: ApiService.baseImgPath+filePath,
|
||||||
|
type: "1",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pushPage(DangerImageUpdataPage(item["RECORDITEM_ID"], imgList: imgList), context);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ToastUtil.showNormal(context, "加载数据失败");
|
||||||
|
// _showMessage('加载数据失败');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// 出错时可以 Toast 或者在页面上显示错误状态
|
||||||
|
print('加载数据失败:$e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 构建单选按钮
|
// 构建单选按钮
|
||||||
Widget _buildOptionButton({
|
Widget _buildOptionButton({
|
||||||
|
|
282
pubspec.lock
282
pubspec.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue