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

fix:提交

上级 2d20fea5
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
/* android打包配置 */ /* android打包配置 */
"android" : { "android" : {
"permissions" : [ "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.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>", "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
......
...@@ -124,18 +124,18 @@ export default { ...@@ -124,18 +124,18 @@ export default {
// 巡检管理 // 巡检管理
toInspectionManagement() { toInspectionManagement() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/inspectionManagement/index", url: "/pages/inspectionManagement/index?backValue=home",
}); });
}, },
toListingManagement() { toListingManagement() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/listingManagement/index", url: "/pages/listingManagement/index?backValue=home",
}); });
}, },
// 井道巡检 // 井道巡检
toShaftInspection() { toShaftInspection() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/shaftInspection/shaftInspectionNew", url: "/pages/shaftInspection/shaftInspectionNew?backValue=home",
}); });
}, },
//退出--弹出对话框 //退出--弹出对话框
......
...@@ -54,6 +54,7 @@ import { ...@@ -54,6 +54,7 @@ import {
getLogContent, getLogContent,
LOG_TYPE_ENUM, LOG_TYPE_ENUM,
writeDeviceData, writeDeviceData,
copyImagesToFolder,
} from "@/utils/IoReadingAndWriting.js"; } from "@/utils/IoReadingAndWriting.js";
import moment from "moment"; import moment from "moment";
import { Base64 } from "js-base64"; import { Base64 } from "js-base64";
...@@ -125,10 +126,26 @@ export default { ...@@ -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() { coverData() {
const userName = this.$store.state.now_user.user; const userName = this.$store.state.now_user.user;
let syncedData = this.list; 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"); let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss");
syncedData.forEach((item) => { syncedData.forEach((item) => {
item.synchronization = true; item.synchronization = true;
...@@ -150,7 +167,7 @@ export default { ...@@ -150,7 +167,7 @@ export default {
.then((res) => { .then((res) => {
console.log("tmepList", tmepList); console.log("tmepList", tmepList);
this.$store.commit("SET_DEVICEDATA", arr); this.$store.commit("SET_DEVICEDATA", arr);
console.log("arr",arr) console.log("arr", arr);
setTimeout(() => { setTimeout(() => {
uni.showToast({ uni.showToast({
title: "打包成功", title: "打包成功",
...@@ -175,6 +192,9 @@ export default { ...@@ -175,6 +192,9 @@ export default {
// 更新同步时间 // 更新同步时间
this.updateSysTime(); this.updateSysTime();
this.getDetails(); this.getDetails();
uni.navigateTo({
url: "/pages/listingManagement/index?backValue=home",
});
}, 2 * 1000); }, 2 * 1000);
}) })
.catch((error) => { .catch((error) => {
......
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
<text <text
class="inner-circle" class="inner-circle"
v-if="filteredData(selectedPhotos, group, date)" v-if="filteredData(selectedPhotos, group, date)"
></text ></text>
>
</view> </view>
<text class="date">{{ date }}</text> <text class="date">{{ date }}</text>
</view> </view>
...@@ -147,7 +146,9 @@ export default { ...@@ -147,7 +146,9 @@ export default {
mounted() {}, mounted() {},
methods: { methods: {
back() { back() {
uni.navigateBack(); uni.navigateTo({
url: "/pages/home/home",
});
}, // 回显数据 }, // 回显数据
getDetails() { getDetails() {
uni.showLoading(); uni.showLoading();
...@@ -169,35 +170,41 @@ export default { ...@@ -169,35 +170,41 @@ export default {
}, },
// 拍照 // 拍照
takePhoto() { takePhoto() {
let $this = this;
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sourceType: ["camera"], // 可以从相机拍摄 sourceType: ["camera"], // 可以从相机拍摄
success: async (res) => { success: (res) => {
console.log(111, res); console.log(111, res);
const tempFilePath = res.tempFilePaths[0]; const tempFilePath = res.tempFilePaths[0];
// 存储照片到本地 // 存储照片到本地
uni.saveImageToPhotosAlbum({ uni.saveImageToPhotosAlbum({
filePath: tempFilePath, filePath: tempFilePath,
success: function () { success: async function (res) {
console.log("图片已成功保存到相册"); console.log("图片已成功保存到相册", tempFilePath, res);
const base64 = await $this.convertFileToBase64(tempFilePath);
// 数据合成
const newPhoto = {
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})`,
"设备上架"
);
}, },
fail: function (err) { fail: function (err) {
console.error("保存图片到相册失败:", err); console.error("保存图片到相册失败:", err);
}, },
}); });
const base64 = await this.convertFileToBase64(tempFilePath);
// 数据合成
const newPhoto = {
id: this.getFileName(tempFilePath),
url: base64,
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})`, "设备上架");
}, },
}); });
}, },
...@@ -309,22 +316,6 @@ export default { ...@@ -309,22 +316,6 @@ export default {
this.getDetails(); 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> </script>
...@@ -560,8 +551,8 @@ export default { ...@@ -560,8 +551,8 @@ export default {
cursor: pointer; cursor: pointer;
transition: all 0.3s ease; transition: all 0.3s ease;
margin-bottom: 2px; margin-bottom: 2px;
font-size: 8px; font-size: 8px;
text-align: center; text-align: center;
&.active { &.active {
background: #3774f6; background: #3774f6;
color: #fff; color: #fff;
......
...@@ -42,7 +42,7 @@ export const getLogContent = (type, detail = "", module = "其他模块") => { ...@@ -42,7 +42,7 @@ export const getLogContent = (type, detail = "", module = "其他模块") => {
detail, detail,
type, type,
time: timeStr, time: timeStr,
...now_user ...now_user,
}; };
}; };
...@@ -55,23 +55,22 @@ export const addLog = (content) => { ...@@ -55,23 +55,22 @@ export const addLog = (content) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const now_user = store.state.now_user; const now_user = store.state.now_user;
let fileName = `${now_user.user}.txt`; 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)); // 方便验证 const fileContent = Base64.encode(JSON.stringify(temp)); // 方便验证
// store 更新日志 // store 更新日志
store.commit("SET_LOG_LIST", content); store.commit("SET_LOG_LIST", content);
createFileWithPlusIO( createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/日志文件/${now_user.user}`, `${SYNCHRONIZE_DATA_PAD}/日志文件/${now_user.user}`,
fileName, fileName,
fileContent fileContent
).then((res) => { )
.then((res) => {
resolve(); resolve();
}) .catch((error) => reject(error)); })
.catch((error) => reject(error));
}); });
}; };
...@@ -86,13 +85,10 @@ export const readLogData = () => { ...@@ -86,13 +85,10 @@ export const readLogData = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath) readFilesInDirectory(directoryPath)
.then((res) => { .then((res) => {
const temp = res.map((element) => { const temp = res.map((element) => {
return JSON.parse(Base64.decode(element)); return JSON.parse(Base64.decode(element));
}); });
resolve(lodash.flattenDeep(temp)); resolve(lodash.flattenDeep(temp));
}) })
.catch((error) => reject(error)); .catch((error) => reject(error));
...@@ -112,7 +108,6 @@ export const writeDarf = (content) => { ...@@ -112,7 +108,6 @@ export const writeDarf = (content) => {
fileName, fileName,
fileContent fileContent
).then((res) => { ).then((res) => {
resolve(); resolve();
}); });
}); });
...@@ -153,14 +148,9 @@ export const readDarfData = () => { ...@@ -153,14 +148,9 @@ export const readDarfData = () => {
*/ */
export const writeInspectionData = (content, userName) => { export const writeInspectionData = (content, userName) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let fileName = `list.txt`; let fileName = `list.txt`;
const fileContent = Base64.encode(JSON.stringify(content)); const fileContent = Base64.encode(JSON.stringify(content));
createFileWithPlusIO( createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/巡检数据/${userName}`, `${SYNCHRONIZE_DATA_PAD}/巡检数据/${userName}`,
fileName, fileName,
...@@ -180,7 +170,6 @@ export const readInspectionData = () => { ...@@ -180,7 +170,6 @@ export const readInspectionData = () => {
const directoryPath = isAdmin const directoryPath = isAdmin
? `${SYNCHRONIZE_DATA_PAD}/巡检数据` ? `${SYNCHRONIZE_DATA_PAD}/巡检数据`
: `${SYNCHRONIZE_DATA_PAD}/巡检数据/${now_user.user}`; : `${SYNCHRONIZE_DATA_PAD}/巡检数据/${now_user.user}`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath) readFilesInDirectory(directoryPath)
...@@ -200,16 +189,11 @@ export const readInspectionData = () => { ...@@ -200,16 +189,11 @@ export const readInspectionData = () => {
* @param {*} isEncryption 是否加密 * @param {*} isEncryption 是否加密
* @returns * @returns
*/ */
export const writeDeviceData= (content, userName) => { export const writeDeviceData = (content, userName) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let fileName = `list.txt`; let fileName = `list.txt`;
const fileContent = Base64.encode(JSON.stringify(content)); const fileContent = Base64.encode(JSON.stringify(content));
createFileWithPlusIO( createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/设备上架/${userName}`, `${SYNCHRONIZE_DATA_PAD}/设备上架/${userName}`,
fileName, fileName,
...@@ -222,21 +206,21 @@ export const writeDeviceData= (content, userName) => { ...@@ -222,21 +206,21 @@ export const writeDeviceData= (content, userName) => {
}); });
}; };
// 读取【设备上架】文件 // 读取【设备上架】文件
export const readDeviceData= () => { export const readDeviceData = () => {
const now_user = store.state.now_user; 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 isAdmin = now_user.isAdmin;
// const directoryPath = isAdmin // const directoryPath = isAdmin
// ? `${SYNCHRONIZE_DATA_PAD}/设备上架` // ? `${SYNCHRONIZE_DATA_PAD}/设备上架`
// : `${SYNCHRONIZE_DATA_PAD}/设备上架/${now_user.user}`; // : `${SYNCHRONIZE_DATA_PAD}/设备上架/${now_user.user}`;
const directoryPath = `${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) => { return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath) readFilesInDirectory(directoryPath)
.then((res) => { .then((res) => {
console.log("directoryPathres",res) console.log("directoryPathres", res);
const temp = res.map((element) => { const temp = res.map((element) => {
return JSON.parse(Base64.decode(element)); return JSON.parse(Base64.decode(element));
}); });
...@@ -364,6 +348,95 @@ export function copyDirectory(sourceDirectoryPath, targetDirectoryPath) { ...@@ -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) { export function deleteAllFilesInDirectory(directoryPath) {
...@@ -442,7 +515,6 @@ export function deleteAllFilesInDirectory(directoryPath) { ...@@ -442,7 +515,6 @@ export function deleteAllFilesInDirectory(directoryPath) {
}); });
} }
// 初始化 -- 读取数据文件 // 初始化 -- 读取数据文件
export const readDirectoryData = () => { export const readDirectoryData = () => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论