提交 9e026987 authored 作者: caodi\cd's avatar caodi\cd

fix:提交

上级 2d20fea5
......@@ -28,6 +28,8 @@
/* android打包配置 */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
......
......@@ -124,18 +124,18 @@ export default {
// 巡检管理
toInspectionManagement() {
uni.navigateTo({
url: "/pages/inspectionManagement/index",
url: "/pages/inspectionManagement/index?backValue=home",
});
},
toListingManagement() {
uni.navigateTo({
url: "/pages/listingManagement/index",
url: "/pages/listingManagement/index?backValue=home",
});
},
// 井道巡检
toShaftInspection() {
uni.navigateTo({
url: "/pages/shaftInspection/shaftInspectionNew",
url: "/pages/shaftInspection/shaftInspectionNew?backValue=home",
});
},
//退出--弹出对话框
......
......@@ -54,6 +54,7 @@ import {
getLogContent,
LOG_TYPE_ENUM,
writeDeviceData,
copyImagesToFolder,
} from "@/utils/IoReadingAndWriting.js";
import moment from "moment";
import { Base64 } from "js-base64";
......@@ -125,10 +126,26 @@ export default {
});
});
},
// 保存图片到指定地址
copyImages(imagePaths, userName) {
const targetPath = `${SYNCHRONIZE_DATA_PAD}/设备上架照片/${userName}`;
console.log("imagePath打包", imagePaths);
//请空文件夹
deleteAllFilesInDirectory(targetPath).then(() => {
// 复制
copyImagesToFolder(imagePaths, targetPath).then((res) => {
console.log("图片复制后", res);
});
});
},
// 处理数据
coverData() {
const userName = this.$store.state.now_user.user;
let syncedData = this.list;
let imagePaths = this.list.map((user) => user.imgPath);
// 保存照片
this.copyImages(imagePaths, userName);
console.log("syncedData打包", syncedData);
let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss");
syncedData.forEach((item) => {
item.synchronization = true;
......@@ -150,7 +167,7 @@ export default {
.then((res) => {
console.log("tmepList", tmepList);
this.$store.commit("SET_DEVICEDATA", arr);
console.log("arr",arr)
console.log("arr", arr);
setTimeout(() => {
uni.showToast({
title: "打包成功",
......@@ -175,6 +192,9 @@ export default {
// 更新同步时间
this.updateSysTime();
this.getDetails();
uni.navigateTo({
url: "/pages/listingManagement/index?backValue=home",
});
}, 2 * 1000);
})
.catch((error) => {
......
......@@ -38,8 +38,7 @@
<text
class="inner-circle"
v-if="filteredData(selectedPhotos, group, date)"
></text
>
></text>
</view>
<text class="date">{{ date }}</text>
</view>
......@@ -147,7 +146,9 @@ export default {
mounted() {},
methods: {
back() {
uni.navigateBack();
uni.navigateTo({
url: "/pages/home/home",
});
}, // 回显数据
getDetails() {
uni.showLoading();
......@@ -169,35 +170,41 @@ export default {
},
// 拍照
takePhoto() {
let $this = this;
uni.chooseImage({
count: 1,
sourceType: ["camera"], // 可以从相机拍摄
success: async (res) => {
success: (res) => {
console.log(111, res);
const tempFilePath = res.tempFilePaths[0];
// 存储照片到本地
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: function () {
console.log("图片已成功保存到相册");
},
fail: function (err) {
console.error("保存图片到相册失败:", err);
},
});
const base64 = await this.convertFileToBase64(tempFilePath);
success: async function (res) {
console.log("图片已成功保存到相册", tempFilePath, res);
const base64 = await $this.convertFileToBase64(tempFilePath);
// 数据合成
const newPhoto = {
id: this.getFileName(tempFilePath),
id: $this.getFileName(tempFilePath),
url: base64,
imgPath: res.path,
date: moment(new Date()).format("yyyy-MM-DD"),
time: moment(new Date()).format("yyyy-MM-DD HH:mm"),
selected: false,
synchronization: false,
};
console.log("newPhoto", newPhoto);
this.photos.unshift(newPhoto);
this.addPhotos(this.photos, `照片编号(${newPhoto.id})`, "设备上架");
$this.photos.unshift(newPhoto);
$this.addPhotos(
$this.photos,
`照片编号(${newPhoto.id})`,
"设备上架"
);
},
fail: function (err) {
console.error("保存图片到相册失败:", err);
},
});
},
});
},
......@@ -309,22 +316,6 @@ export default {
this.getDetails();
}
},
// 数据同步
syncData() {
const syncedData = this.selectedPhotos.map((photo) => ({
id: photo.id,
time: photo.time,
synchronization: true,
status: photo.synchronization ? "已同步" : "待同步",
}));
// 存储到本地
uni.setStorageSync("syncedPhotos", syncedData);
// 更新同步状态
this.selectedPhotos.forEach((photo) => {
photo.synchronization = true;
});
this.selectedPhotos = [];
},
},
};
</script>
......
......@@ -42,7 +42,7 @@ export const getLogContent = (type, detail = "", module = "其他模块") => {
detail,
type,
time: timeStr,
...now_user
...now_user,
};
};
......@@ -55,23 +55,22 @@ export const addLog = (content) => {
return new Promise((resolve, reject) => {
const now_user = store.state.now_user;
let fileName = `${now_user.user}.txt`;
const temp = content.filter(item => item.user == now_user.user)
const temp = content.filter((item) => item.user == now_user.user);
const fileContent = Base64.encode(JSON.stringify(temp)); // 方便验证
// store 更新日志
store.commit("SET_LOG_LIST", content);
createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/日志文件/${now_user.user}`,
fileName,
fileContent
).then((res) => {
)
.then((res) => {
resolve();
}) .catch((error) => reject(error));
})
.catch((error) => reject(error));
});
};
......@@ -86,13 +85,10 @@ export const readLogData = () => {
return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath)
.then((res) => {
const temp = res.map((element) => {
return JSON.parse(Base64.decode(element));
});
resolve(lodash.flattenDeep(temp));
})
.catch((error) => reject(error));
......@@ -112,7 +108,6 @@ export const writeDarf = (content) => {
fileName,
fileContent
).then((res) => {
resolve();
});
});
......@@ -153,14 +148,9 @@ export const readDarfData = () => {
*/
export const writeInspectionData = (content, userName) => {
return new Promise((resolve, reject) => {
let fileName = `list.txt`;
const fileContent = Base64.encode(JSON.stringify(content));
createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/巡检数据/${userName}`,
fileName,
......@@ -181,7 +171,6 @@ export const readInspectionData = () => {
? `${SYNCHRONIZE_DATA_PAD}/巡检数据`
: `${SYNCHRONIZE_DATA_PAD}/巡检数据/${now_user.user}`;
return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath)
.then((res) => {
......@@ -200,16 +189,11 @@ export const readInspectionData = () => {
* @param {*} isEncryption 是否加密
* @returns
*/
export const writeDeviceData= (content, userName) => {
export const writeDeviceData = (content, userName) => {
return new Promise((resolve, reject) => {
let fileName = `list.txt`;
const fileContent = Base64.encode(JSON.stringify(content));
createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/设备上架/${userName}`,
fileName,
......@@ -222,21 +206,21 @@ export const writeDeviceData= (content, userName) => {
});
};
// 读取【设备上架】文件
export const readDeviceData= () => {
export const readDeviceData = () => {
const now_user = store.state.now_user;
console.log("now_user",now_user)
console.log("now_user", now_user);
const isAdmin = now_user.isAdmin;
// const directoryPath = isAdmin
// ? `${SYNCHRONIZE_DATA_PAD}/设备上架`
// : `${SYNCHRONIZE_DATA_PAD}/设备上架/${now_user.user}`;
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/设备上架/${now_user.user}`;
console.log("directoryPath",directoryPath)
console.log("directoryPath", directoryPath);
return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath)
.then((res) => {
console.log("directoryPathres",res)
console.log("directoryPathres", res);
const temp = res.map((element) => {
return JSON.parse(Base64.decode(element));
});
......@@ -364,6 +348,95 @@ export function copyDirectory(sourceDirectoryPath, targetDirectoryPath) {
);
});
}
// 复制多张图片到指定目录的函数
export function copyImagesToFolder(sourcePaths, targetDir) {
// 第一步:检查运行环境是否支持plus API
// if (!window.plus || !plus.io) {
// console.error("[文件操作] 当前环境不支持plus API");
// return;
// }
console.log("[文件操作] 开始复制文件:", sourcePaths, "->", targetDir);
// 第二步:准备目标目录
prepareTargetDirectory(targetDir, (dirEntry) => {
// 目标目录准备好后,开始复制所有文件
sourcePaths.forEach((sourcePath) => {
copySingleImage(sourcePath, dirEntry);
});
}, (error) => {
console.error("[文件操作] 准备目标目录失败:", error.message);
});
}
// 准备目标目录
function prepareTargetDirectory(targetDir, successCallback, errorCallback) {
plus.io.resolveLocalFileSystemURL(
targetDir,
function(dirEntry) {
// 目标目录已存在
console.log("[文件操作] 目标目录已存在");
successCallback(dirEntry);
},
function(e) {
// 目标目录不存在,尝试创建
console.log("[文件操作] 目标目录不存在,尝试创建...");
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function(fs) {
// 创建目录
fs.root.getDirectory(
targetDir,
{
create: true,
},
function(dirEntry) {
console.log("[文件操作] 目标目录创建成功");
successCallback(dirEntry);
},
function(error) {
errorCallback(error);
}
);
},
function(error) {
errorCallback(error);
}
);
}
);
}
// 复制单个图片
function copySingleImage(sourcePath, targetDirEntry) {
plus.io.resolveLocalFileSystemURL(
sourcePath,
function(entry) {
// 源文件存在,开始复制
console.log("[文件操作] 源文件存在:", sourcePath);
// 获取文件名
const fileName = sourcePath.substring(sourcePath.lastIndexOf("/") + 1);
console.log("[文件操作] 文件名:", fileName);
// 执行复制操作
entry.copyTo(
targetDirEntry,
fileName,
function(newEntry) {
console.log("[文件操作] 文件复制成功,新路径:", newEntry.fullPath);
},
function(error) {
console.error("[文件操作] 文件复制失败:", error.message);
}
);
},
function(e) {
// 源文件不存在或无法访问
console.error("[文件操作] 源文件不存在或无法访问:", e.message);
}
);
}
// 删除文件夹中所有文件
export function deleteAllFilesInDirectory(directoryPath) {
......@@ -442,7 +515,6 @@ export function deleteAllFilesInDirectory(directoryPath) {
});
}
// 初始化 -- 读取数据文件
export const readDirectoryData = () => {
return new Promise(async (resolve, reject) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论