|
|
@@ -1,7 +1,7 @@
|
|
|
import { getToken, getTokenFromApi } from './auth'
|
|
|
-import { saveMediaInfo, saveMediaRecord, getLatestRecord, removeInfoAndRecord } from '@/api/work'
|
|
|
+import { saveMediaInfo, saveMediaRecord, getLatestRecord, removeInfoAndRecord, getJoinList } from '@/api/work'
|
|
|
import { globalConfig } from '@/config'
|
|
|
-
|
|
|
+import upload from '@/utils/upload.uts'
|
|
|
|
|
|
// 类型定义保持不变
|
|
|
export type ApiResponse = {
|
|
|
@@ -164,13 +164,13 @@ export const downloadDataFromAPI = async (productCode : string, callback ?: () =
|
|
|
// 使用async/await处理循环中的异步操作
|
|
|
const processAllRecords = async () => {
|
|
|
// 创建一个Map来跟踪不同photoitem的计数
|
|
|
- const photoItemCounter: Map<string, number> = new Map();
|
|
|
-
|
|
|
+ const photoItemCounter : Map<string, number> = new Map();
|
|
|
+
|
|
|
for (var i = 0; i < recordList.length; i++) {
|
|
|
// 更新进度
|
|
|
processedRecords++;
|
|
|
showProgress(processedRecords);
|
|
|
-
|
|
|
+
|
|
|
const record : MediaRecordData = recordList[i] as MediaRecordData;
|
|
|
// 获取各个字段的值
|
|
|
const photoitem = record.photoitem as string;
|
|
|
@@ -178,11 +178,11 @@ export const downloadDataFromAPI = async (productCode : string, callback ?: () =
|
|
|
if (!photoItemCounter.has(photoitem)) {
|
|
|
photoItemCounter.set(photoitem, 1);
|
|
|
} else {
|
|
|
- const currentCount = photoItemCounter.get(photoitem);
|
|
|
- photoItemCounter.set(photoitem, (currentCount != null ? currentCount : 0) + 1);
|
|
|
- }
|
|
|
- const senum = photoItemCounter.get(photoitem);
|
|
|
- const finalSenum = senum != null ? senum : 1;
|
|
|
+ const currentCount = photoItemCounter.get(photoitem);
|
|
|
+ photoItemCounter.set(photoitem, (currentCount != null ? currentCount : 0) + 1);
|
|
|
+ }
|
|
|
+ const senum = photoItemCounter.get(photoitem);
|
|
|
+ const finalSenum = senum != null ? senum : 1;
|
|
|
const partno = record.partno;
|
|
|
const part = record.part;
|
|
|
const pk = record.pk;
|
|
|
@@ -324,4 +324,68 @@ export const downloadDataFromAPI = async (productCode : string, callback ?: () =
|
|
|
uni.hideLoading();
|
|
|
return false;
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+export const uploadDataToAPI = async (productCode : string, callback ?: () => void) : Promise<boolean> => {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //暂定需要上传的数据文件
|
|
|
+ //const infoJson = await getLatestRecord(productCode, null);
|
|
|
+ const apiToken = await getTokenFromApi();
|
|
|
+
|
|
|
+ const showProgress = (index : number) => {
|
|
|
+ // 在Android设备上,需要给hideLoading和showLoading之间添加延迟
|
|
|
+ // 先隐藏之前的加载提示
|
|
|
+ uni.hideLoading();
|
|
|
+ // 添加50ms的延迟,确保hideLoading完全执行后再显示新的进度
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.showLoading({
|
|
|
+ title: `正在上传第${index}个任务数据`,
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ }, 50);
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ getJoinList('app_media_record as r', 'app_media_info as i', 'r.*,i.productno', 'r.pid=i.pdid', 'i.productno', productCode, null).then((res : UTSJSONObject) => {
|
|
|
+ let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
|
|
|
+ if (dataList != null && dataList.length > 0) {
|
|
|
+ let imgList = dataList.filter(item => item.getNumber("status") == 3 && item.getString("urlpdt") != '')
|
|
|
+ let uploadFiles = Array<string>()
|
|
|
+ let uploadNames = Array<string>()
|
|
|
+ if (imgList.length > 0) {
|
|
|
+ imgList.forEach(img => {
|
|
|
+ let urlArr = img['urlpdt'].indexof(",")>-1? img['urlpdt'].split(",") : [img['urlpdt']]
|
|
|
+ uploadFiles.push(...urlArr);
|
|
|
+ let nameArr = img['imgname'].indexof(",")>-1? img['imgname'].split(",") : [img['imgname']]
|
|
|
+ uploadNames.push(...nameArr)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (uploadFiles.length === 0) {
|
|
|
+ uni.showToast({ title: '上传图片数据为空', icon: 'error' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ uploadFiles.forEach((filePath, index) => {
|
|
|
+ //文件上传
|
|
|
+ upload({
|
|
|
+ apiUrl: globalConfig.apiUrl,
|
|
|
+ name: uploadNames[index],
|
|
|
+ filePath: filePath,
|
|
|
+ formData: {
|
|
|
+ //传递数据
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ uni.showToast({ title: '上传失败,请重试', icon: 'error' });
|
|
|
+ uni.hideLoading();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+})
|