提交 21d7b477 authored 作者: zs's avatar zs

edit

上级 b15b1d72
......@@ -6,6 +6,25 @@ import {
// 巡检
export default {
async selectLastData(data) {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
let rs = await sqllitedb.selectSQL(
`SELECT *
FROM ${table.inspectionRecordName}
WHERE userId = '${data}'
AND createTime >= strftime('%s', 'now') - 7*24*60*60
AND inspectionType = 1
ORDER BY createTime DESC
LIMIT 1;`
);
return rs;
} catch (e) {
console.log(e.message);
} finally {
await sqllitedb.closeDB();
}
},
async selectList() {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
......
......@@ -55,6 +55,7 @@
import {
copyDirectory
} from "@/utils/IoReadingAndWriting.js"
import inspectApi from "@/api/inspect.js"
export default {
data() {
return {
......@@ -86,11 +87,9 @@
console.log(this.$store.state);
},
methods: {
copyFile() {
const SYNCHRONIZE_DATA_PAD = "_documents/data"; // 存储pad端的生产数据
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/photos`;
const targetDirectoryPath = `${SYNCHRONIZE_DATA_PAD}/asmzx/pad/巡检数据/${this.userName}`;
copyDirectory(directoryPath, targetDirectoryPath)
async copyFile() {
let res= await inspectApi.selectLastData(this.$store.state.now_user.userId)
console.log(res,'=========')
},
// 修改密码
......
......@@ -135,7 +135,7 @@
async clickHandle() {
if (this.loading) return;
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/发送数据`;
const targetDirectoryPath = `${SYNCHRONIZE_DATA_PAD}/history`;
const targetDirectoryPath = `${SYNCHRONIZE_DATA_PAD}/history/${new Date().getTime()}`;
// checkAndCreateDirectory(directoryPath).then(() => {
copyDirectory(directoryPath, targetDirectoryPath)
......@@ -246,11 +246,12 @@
let ids = this.list.map((e) => e.id);
// 复制照片
await this.copyPhotos();
await zipCompress(`${SYNCHRONIZE_DATA_PAD}/发送数据`,
zipCompress(`${SYNCHRONIZE_DATA_PAD}/发送数据`,
`${SYNCHRONIZE_DATA_PAD}/fssj/${userName}_JFXJ_${timeStr}.zip`
);
debugger
// zip
await inspectApi.updateSyncData(ids);
// await inspectApi.updateSyncData(ids);
this.close();
this.loading = false;
......
......@@ -473,15 +473,48 @@ export function getUserList() {
export function zipCompress(sourceDir, zipPath) {
return new Promise((resolve, reject) => {
plus.zip.compress(
plus.io.convertLocalFileSystemURL(sourceDir),
plus.io.convertLocalFileSystemURL(zipPath),
{
recursive: true,
overwrite: true,
},
() => resolve(zipPath),
(error) => reject(`压缩失败: ${error.message}`)
);
// 递归函数,用于收集目录中的所有文件路径
function collectFiles(dirEntry, filePaths = []) {
return new Promise((resolveCollect, rejectCollect) => {
var directoryReader = dirEntry.createReader();
directoryReader.readEntries(function(entries) {
var promises = [];
entries.forEach(function(entry) {
if (entry.isFile) {
filePaths.push(entry.toLocalURL());
} else if (entry.isDirectory) {
promises.push(collectFiles(entry, filePaths));
}
});
Promise.all(promises).then(() => resolveCollect(filePaths)).catch(rejectCollect);
}, function(e) {
rejectCollect(e);
});
});
}
// 开始收集文件
plus.io.resolveLocalFileSystemURL(sourceDir, function(dirEntry) {
if (dirEntry.isDirectory) {
collectFiles(dirEntry).then(function(allFilePaths) {
debugger
// 使用收集到的文件路径进行压缩
plus.zip.compress(
allFilePaths,
plus.io.convertLocalFileSystemURL(zipPath),
function() {
resolve(zipPath);
},
function(error) {
reject(`压缩失败: ${error.message}`);
}
);
}).catch(reject);
} else {
reject('提供的路径不是一个目录');
}
}, function(e) {
reject(`解析文件系统URL失败: ${e.message}`);
});
});
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论