提交 6b8010dd authored 作者: zs's avatar zs

区分批量同步与单独同步

上级 7e20ba05
...@@ -102,6 +102,7 @@ export default { ...@@ -102,6 +102,7 @@ export default {
'_documents', '_documents',
'_documents/data', '_documents/data',
'_documents/data/asmzx', '_documents/data/asmzx',
'_documents/data/photos',
'_documents/data/asmzx/pad' '_documents/data/asmzx/pad'
]; ];
......
<template> <template>
<view class="synchronous-dialog"> <view class="synchronous-dialog">
<view class="synchronous-content"> <view class="synchronous-content">
<view class="row-item"> <view class="row-item">
<text class="title">待打包数据</text> <text class="title">待打包数据</text>
</view> </view>
<view class="row-item count-num"> <view class="row-item count-num">
<text class="num">{{ list.length }}</text> <text class="num">{{ list.length }}</text>
<text></text> <text></text>
</view> </view>
<view class="operating-instructions"> <view class="operating-instructions">
<view class="title">操作说明:</view> <view class="title">操作说明:</view>
<view class="instructions-item"> <view class="instructions-item">
1、在PAD端,点击“数据打包”,做好同步准备。 1、在PAD端,点击“数据打包”,做好同步准备。
</view> </view>
<view class="instructions-item"> <view class="instructions-item">
2、完成打包后,将PAD直联PC机,等待PC机自动导入需同步记录。 2、完成打包后,将PAD直联PC机,等待PC机自动导入需同步记录。
</view> </view>
<view class="instructions-item"> <view class="instructions-item">
3、PC端自动导入完成后,请点击“同步数据”,同步成功后,列表自动刷新展示同步数据;且PAD同步的数据不支持修改。 3、PC端自动导入完成后,请点击“同步数据”,同步成功后,列表自动刷新展示同步数据;且PAD同步的数据不支持修改。
</view> </view>
</view> </view>
<view class="row-item bottom-row"> <view class="row-item bottom-row">
<button class="button" :loading="loading" @click="clickHandle"> <button class="button" :loading="loading" @click="clickHandle">
数据打包 数据打包
</button> </button>
</view> </view>
<!-- 关闭按钮 --> <!-- 关闭按钮 -->
<div class="close-button"> <div class="close-button">
<text class="iconfont icon-shibai1" @click="close"></text> <text class="iconfont icon-shibai1" @click="close"></text>
</div> </div>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { import {
SYNCHRONIZE_DATA_PAD, SYNCHRONIZE_DATA_PAD,
checkAndCreateDirectory, checkAndCreateDirectory,
createFileWithPlusIO, createFileWithPlusIO,
setSm2, setSm2,
USER_FILE_NAME, USER_FILE_NAME,
getUserList, getUserList,
zipCompress, zipCompress,
} from "@/utils/systemCofig"; } from "@/utils/systemCofig";
import { findPhotosUrls } from "@/utils/index.js"; import {
import { copySelectedFiles } from "@/utils/plus.js"; findPhotosUrls
} from "@/utils/index.js";
import { import {
writeInspectionData, copySelectedFiles
copyDirectory, } from "@/utils/plus.js";
deleteAllFilesInDirectory,
addLog, import {
getLogContent, writeInspectionData,
LOG_TYPE_ENUM, copyDirectory,
} from "@/utils/IoReadingAndWriting.js"; deleteAllFilesInDirectory,
import moment from "moment"; addLog,
import { getAllInspections } from "@/request/index.js"; getLogContent,
import { Base64 } from "js-base64"; LOG_TYPE_ENUM,
import inspectApi from "@/api/inspect"; } from "@/utils/IoReadingAndWriting.js";
import inspect from "@/api/inspect"; import moment from "moment";
export default { import {
props: { getAllInspections
list: { } from "@/request/index.js";
type: Array, import {
default: () => {}, Base64
}, } from "js-base64";
}, import inspectApi from "@/api/inspect";
components: {}, import inspect from "@/api/inspect";
data() { export default {
return { props: {
loading: false, list: {
notSynchronizationList: [], // 未同步数据 type: Array,
allList: [], // 所有数据 default: () => {},
}; },
}, },
computed: { components: {},
userInfo() { data() {
return this.$store.state.now_user; return {
}, loading: false,
}, notSynchronizationList: [], // 未同步数据
allList: [], // 所有数据
watch: { };
list(newVal) { },
console.log("newVal", newVal); computed: {
this.init(); userInfo() {
}, return this.$store.state.now_user;
}, },
// async mounted() { },
// const temp = [];
// this.list.forEach((item) => { watch: {
// temp.push(...(item.list || [])); list(newVal) {
// }); console.log("newVal", newVal);
// console.log("this.list", this.list); this.init();
// console.log("temp", temp); },
// this.notSynchronizationList = temp.filter( },
// (item) => item.synchronization == 0 && item.isSign === true // async mounted() {
// ); // const temp = [];
// this.list.forEach((item) => {
// getAllInspections().then((res) => { // temp.push(...(item.list || []));
// this.allList = res; // });
// }); // console.log("this.list", this.list);
// }, // console.log("temp", temp);
methods: { // this.notSynchronizationList = temp.filter(
init() { // (item) => item.synchronization == 0 && item.isSign === true
const temp = []; // );
this.notSynchronizationList = this.list;
// getAllInspections().then((res) => {
getAllInspections().then((res) => { // this.allList = res;
this.allList = res; // });
}); // },
}, methods: {
close() { init() {
this.$emit("close"); const temp = [];
}, this.notSynchronizationList = this.list;
/** getAllInspections().then((res) => {
* 1.生成两个文件. 机房文件 和 井道文件 this.allList = res;
* 2. 更新巡检数据状态 synchronization 置为 1 });
* 3. 写入数据 },
* 读取上一次打包的文件, 复制到 [ history ] 文件夹中 close() {
*/ this.$emit("close");
async clickHandle() { },
if (this.loading) return;
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/发送数据`; /**
const targetDirectoryPath = `${SYNCHRONIZE_DATA_PAD}/history/${new Date().getTime()}`; * 1.生成两个文件. 机房文件 和 井道文件
* 2. 更新巡检数据状态 synchronization 置为 1
// checkAndCreateDirectory(directoryPath).then(() => { * 3. 写入数据
copyDirectory(directoryPath, targetDirectoryPath) * 读取上一次打包的文件, 复制到 [ history ] 文件夹中
.then(() => { */
return deleteAllFilesInDirectory(directoryPath); async clickHandle() {
}) if (this.loading) return;
.then(() => { const directoryPath = `${SYNCHRONIZE_DATA_PAD}/发送数据`;
this.coverData(); const targetDirectoryPath = `${SYNCHRONIZE_DATA_PAD}/history/${new Date().getTime()}`;
})
.catch((error) => { // checkAndCreateDirectory(directoryPath).then(() => {
uni.showToast({ copyDirectory(directoryPath, targetDirectoryPath)
title: error, .then(() => {
icon: "none", return deleteAllFilesInDirectory(directoryPath);
duration: 1000, })
}); .then(() => {
}); this.coverData();
// }); })
}, .catch((error) => {
copyPhotos() { uni.showToast({
this.list.forEach((e) => { title: error,
if (typeof e.inspectionData === "string") { icon: "none",
e.inspectionData = JSON.parse(e.inspectionData) || "{}"; duration: 1000,
} });
}); });
const urls = findPhotosUrls(this.list).map((url) => url.split("/").pop()); // });
console.log("urls", urls); },
return copySelectedFiles( copyPhotos() {
"_documents/data/photos", this.list.forEach((e) => {
`${SYNCHRONIZE_DATA_PAD}/发送数据`, if (typeof e.inspectionData === "string") {
urls e.inspectionData = JSON.parse(e.inspectionData) || "{}";
); }
}, });
// 处理数据 const urls = findPhotosUrls(this.list).map((url) => url.split("/").pop());
coverData() { console.log("urls", urls);
const userName = this.$store.state.now_user.user; return copySelectedFiles(
const notSynchronizationList = this.notSynchronizationList; "_documents/data/photos",
const allList = this.allList; `${SYNCHRONIZE_DATA_PAD}/发送数据`,
console.log("窗口allList", allList); urls
console.log( );
"窗口this.notSynchronizationList", },
this.notSynchronizationList // 处理数据
); coverData() {
const userName = this.$store.state.now_user.user;
let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss"); const notSynchronizationList = this.notSynchronizationList;
const allList = this.allList;
const JFXJ_DATA = notSynchronizationList console.log("窗口allList", allList);
.filter((item) => item.inspectionType == 1) console.log(
.map((item) => { "窗口this.notSynchronizationList",
return item; this.notSynchronizationList
}); // 机房数据类型是 1 );
const JDXJ_DATA = notSynchronizationList let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss");
.filter((item) => item.inspectionType == 2)
.map((item) => { const JFXJ_DATA = notSynchronizationList
return item; .filter((item) => item.inspectionType == 1)
}); // 井道数据类型是 2 .map((item) => {
console.log(5151, JFXJ_DATA, JDXJ_DATA); return item;
}); // 机房数据类型是 1
this.loading = true;
const tmepList = []; const JDXJ_DATA = notSynchronizationList
.filter((item) => item.inspectionType == 2)
if (JFXJ_DATA.length) { .map((item) => {
let JFXJ_DATA_FILE_NAME = `${userName}_JFXJ_${timeStr}.txt`; return item;
tmepList.push(this.packedData(JFXJ_DATA, JFXJ_DATA_FILE_NAME)); }); // 井道数据类型是 2
} console.log(5151, JFXJ_DATA, JDXJ_DATA);
const batchData = [...JFXJ_DATA, ...JDXJ_DATA]
if (JDXJ_DATA.length) { this.loading = true;
let JDXJ_DATA_FILE_NAME = `${userName}_JDXJ_${timeStr}.txt`; const tmepList = [];
tmepList.push(this.packedData(JDXJ_DATA, JDXJ_DATA_FILE_NAME)); if (notSynchronizationList.length > 1) {
} let JFXJ_DATA_FILE_NAME = `${userName}_XJ_${timeStr}.txt`;
tmepList.push(this.packedData(batchData, JFXJ_DATA_FILE_NAME));
console.log("同步窗口"); } else {
console.log("同步窗口", tmepList); if (JFXJ_DATA.length) {
Promise.all(tmepList) let JFXJ_DATA_FILE_NAME = `${userName}_JFXJ_${timeStr}.txt`;
.then(() => { tmepList.push(this.packedData(JFXJ_DATA, JFXJ_DATA_FILE_NAME));
// 更新巡检数据状态 }
const synchronizationUids = notSynchronizationList.map((item) => {
item.synchronization = 1; if (JDXJ_DATA.length) {
return item.uid; let JDXJ_DATA_FILE_NAME = `${userName}_JDXJ_${timeStr}.txt`;
}); tmepList.push(this.packedData(JDXJ_DATA, JDXJ_DATA_FILE_NAME));
}
const userData = {}; }
allList.forEach((item) => {
if (synchronizationUids.includes(item.uid)) { console.log("同步窗口");
item.synchronization = 1; console.log("同步窗口", tmepList);
} Promise.all(tmepList)
if (userData[item.createByName]) { .then(() => {
userData[item.createByName].push(item); // 更新巡检数据状态
} else { const synchronizationUids = notSynchronizationList.map((item) => {
userData[item.createByName] = [item]; item.synchronization = 1;
} return item.uid;
}); });
this.$store.commit("SET_ALL_DATA", allList);
const userData = {};
const keys = Object.keys(userData);
const promiseArr = keys.map((key) => { allList.forEach((item) => {
const val = userData[key]; if (synchronizationUids.includes(item.uid)) {
return writeInspectionData(val, key); item.synchronization = 1;
}); }
if (userData[item.createByName]) {
Promise.all(promiseArr) userData[item.createByName].push(item);
.then(async () => { } else {
setTimeout(async () => { userData[item.createByName] = [item];
uni.showToast({ }
title: "打包成功", });
icon: "none", // this.$store.commit("SET_ALL_DATA", allList);
duration: 2000,
}); const keys = Object.keys(userData);
let ids = this.list.map((e) => e.id); const promiseArr = keys.map((key) => {
// 复制照片 const val = userData[key];
await this.copyPhotos(); return writeInspectionData(val, key);
zipCompress( });
`${SYNCHRONIZE_DATA_PAD}/发送数据`,
`${SYNCHRONIZE_DATA_PAD}/fssj/${userName}_JFXJ_${timeStr}.zip` Promise.all(promiseArr)
); .then(async () => {
// zip setTimeout(async () => {
await inspectApi.updateSyncData(ids); uni.showToast({
this.close(); title: "打包成功",
this.loading = false; icon: "none",
duration: 2000,
// 生成日志 });
const logContent = getLogContent( let ids = this.list.map((e) => e.id);
LOG_TYPE_ENUM.sys, // 复制照片
"", await this.copyPhotos();
"同步模块" zipCompress(
); `${SYNCHRONIZE_DATA_PAD}/发送数据`,
this.$logApi.addlog(logContent) `${SYNCHRONIZE_DATA_PAD}/fssj/${userName}_XJ_${timeStr}.zip`
const log_list = this.$store.state.log_list; );
log_list.push(logContent); // zip
this.$store.commit("SET_LOG_LIST", log_list); await inspectApi.updateSyncData(ids);
addLog(log_list).then((res) => {}); this.close();
this.loading = false;
// 更新同步时间
this.updateSysTime(); // 生成日志
}, 2 * 1000); const logContent = getLogContent(
}) LOG_TYPE_ENUM.sys,
.catch((error) => { "",
this.loading = false; "同步模块"
);
uni.showToast({ this.$logApi.addlog(logContent)
title: error, const log_list = this.$store.state.log_list;
icon: "none", log_list.push(logContent);
duration: 2000, this.$store.commit("SET_LOG_LIST", log_list);
}); addLog(log_list).then((res) => {});
});
}) // 更新同步时间
.catch(() => { this.updateSysTime();
setTimeout(() => { }, 2 * 1000);
uni.showToast({ })
title: "打包失败", .catch((error) => {
icon: "none", this.loading = false;
duration: 2000,
}); uni.showToast({
this.loading = false; title: error,
}, 2 * 1000); icon: "none",
}); duration: 2000,
}, });
});
// 使用示例 })
// 打包文件 .catch(() => {
packedData(content, fileName) { setTimeout(() => {
// const fileContent = setSm2(content); uni.showToast({
const fileContent = Base64.encode(JSON.stringify(content)); title: "打包失败",
icon: "none",
console.log("packedData", fileContent); duration: 2000,
return createFileWithPlusIO( });
`${SYNCHRONIZE_DATA_PAD}/发送数据`, this.loading = false;
fileName, }, 2 * 1000);
fileContent });
); },
},
// 使用示例
// 更新最近一次同步时间 // 打包文件
updateSysTime() { packedData(content, fileName) {
getUserList().then((personList) => { // const fileContent = setSm2(content);
const now_user = this.$store.state.now_user; const fileContent = Base64.encode(JSON.stringify(content));
const key = personList.findIndex(
(item) => item.userId == now_user.userId console.log("packedData", fileContent);
); return createFileWithPlusIO(
// 更新用户同步时间 `${SYNCHRONIZE_DATA_PAD}/发送数据`,
const userInfo = personList[key]; fileName,
const LastSynchronizationTime = moment().format("yyyy-MM-DD HH:mm"); fileContent
personList[key].LastSynchronizationTime = LastSynchronizationTime; );
userInfo.LastSynchronizationTime = LastSynchronizationTime; },
this.$store.commit("SET_USER", userInfo); // 更新最近一次同步时间
uni.setStorageSync("last_time", userInfo.LastSynchronizationTime || ""); updateSysTime() {
getUserList().then((personList) => {
// 更新用户数据 const now_user = this.$store.state.now_user;
const fileContent = JSON.stringify( const key = personList.findIndex(
Base64.encode(JSON.stringify(personList)) (item) => item.userId == now_user.userId
); );
uni.setStorage({ // 更新用户同步时间
key: "user_data", const userInfo = personList[key];
data: JSON.stringify(personList), const LastSynchronizationTime = moment().format("yyyy-MM-DD HH:mm");
fail: (error) => { personList[key].LastSynchronizationTime = LastSynchronizationTime;
console.log("APP.vue 存储数据失败", error); userInfo.LastSynchronizationTime = LastSynchronizationTime;
},
}); this.$store.commit("SET_USER", userInfo);
createFileWithPlusIO(SYNCHRONIZE_DATA_PAD, USER_FILE_NAME, fileContent) uni.setStorageSync("last_time", userInfo.LastSynchronizationTime || "");
.then(() => {
console.log("---用户数据更新成功"); // 更新用户数据
}) const fileContent = JSON.stringify(
.catch((error) => { Base64.encode(JSON.stringify(personList))
console.log("---用户数据更新失败", error); );
}); uni.setStorage({
}); key: "user_data",
}, data: JSON.stringify(personList),
}, fail: (error) => {
}; console.log("APP.vue 存储数据失败", error);
},
});
createFileWithPlusIO(SYNCHRONIZE_DATA_PAD, USER_FILE_NAME, fileContent)
.then(() => {
console.log("---用户数据更新成功");
})
.catch((error) => {
console.log("---用户数据更新失败", error);
});
});
},
},
};
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.synchronous-dialog { .synchronous-dialog {
position: fixed; position: fixed;
z-index: 999; z-index: 999;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: rgba(0, 0, 0, 0.5); background: rgba(0, 0, 0, 0.5);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
.synchronous-content { .synchronous-content {
padding: 3% 20px 32px 24px; padding: 3% 20px 32px 24px;
width: 400px; width: 400px;
height: 60%; height: 60%;
box-sizing: border-box; box-sizing: border-box;
background-image: linear-gradient( background-image: linear-gradient(-6deg,
-6deg, #f9ffe7 0%,
#f9ffe7 0%, #ffffff 12%,
#ffffff 12%, #fcfeff 73%,
#fcfeff 73%, #ccf1ff 100%);
#ccf1ff 100% border: 0.4px solid rgba(224, 224, 224, 1);
); border-radius: 12px;
border: 0.4px solid rgba(224, 224, 224, 1); position: relative;
border-radius: 12px;
position: relative; .row-item {
display: flex;
.row-item { align-items: center;
display: flex; justify-content: center;
align-items: center; }
justify-content: center;
} .title {
font-family: PingFangSC-Medium;
.title { font-size: 18px;
font-family: PingFangSC-Medium; color: #000000;
font-size: 18px; text-align: center;
color: #000000; line-height: 26px;
text-align: center; font-weight: 500;
line-height: 26px; }
font-weight: 500;
} .count-num {
margin: 5% 0 5% 0;
.count-num { align-items: flex-end;
margin: 5% 0 5% 0;
align-items: flex-end; .num {
display: inline-block;
.num { font-family: AlibabaPuHuiTi_2_65_Medium;
display: inline-block; font-size: 50px;
font-family: AlibabaPuHuiTi_2_65_Medium; color: #3774f6;
font-size: 50px; line-height: 44px;
color: #3774f6; font-weight: 500;
line-height: 44px; }
font-weight: 500; }
}
} .operating-instructions {
margin-bottom: 8%;
.operating-instructions {
margin-bottom: 8%; .title {
font-size: 13px;
.title { color: #4a4a4a;
font-size: 13px; line-height: 24px;
color: #4a4a4a; font-weight: 600;
line-height: 24px; text-align: left;
font-weight: 600; }
text-align: left;
} .instructions-item {
font-size: 12px;
.instructions-item { color: #7c7c7c;
font-size: 12px; line-height: 22px;
color: #7c7c7c; font-weight: 400;
line-height: 22px; }
font-weight: 400; }
}
} // 打包按钮
.bottom-row {
// 打包按钮 position: absolute;
.bottom-row { bottom: 24px;
position: absolute; left: 50%;
bottom: 24px; transform: translateX(-50%);
left: 50%;
transform: translateX(-50%); .button {
display: flex;
.button { align-items: center;
display: flex; justify-content: center;
align-items: center; background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
justify-content: center; box-shadow: 0px 10px 24px 0px rgba(51, 104, 246, 0.24);
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%); border-radius: 27px;
box-shadow: 0px 10px 24px 0px rgba(51, 104, 246, 0.24); width: 160px;
border-radius: 27px; height: 40px;
width: 160px; color: #fff;
height: 40px; }
color: #fff; }
}
} // 关闭按钮
.close-button {
// 关闭按钮 position: absolute;
.close-button { bottom: -40px;
position: absolute; left: 50%;
bottom: -40px; transform: translateX(-50%);
left: 50%;
transform: translateX(-50%); .iconfont {
font-size: 24px;
.iconfont { }
font-size: 24px; }
} }
} }
} </style>
} \ No newline at end of file
</style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论