提交 1da6ceaf authored 作者: zs's avatar zs

复制设备上传照片到list

上级 457ba96b
<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,
} from "@/utils/systemCofig"; } from "@/utils/systemCofig";
import { import {
copyDirectory, copyDirectory,
deleteAllFilesInDirectory, deleteAllFilesInDirectory,
addLog, addLog,
getLogContent, getLogContent,
LOG_TYPE_ENUM, LOG_TYPE_ENUM,
writeDeviceData, writeDeviceData,
copyImagesToFolder, 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";
export default { export default {
props: { props: {
list: { list: {
type: Array, type: Array,
default: () => { default: () => {
return []; return [];
}, },
}, },
photos: { photos: {
type: Array, type: Array,
default: () => { default: () => {
return []; return [];
}, },
}, },
}, },
components: {}, components: {},
data() { data() {
return { return {
loading: false, loading: false,
}; };
}, },
mounted() {}, mounted() {},
watch: { watch: {
list(newData) { list(newData) {
const temp = []; const temp = [];
newData.forEach((item) => { newData.forEach((item) => {
temp.push(...(item.list || [])); temp.push(...(item.list || []));
}); });
}, },
}, },
methods: { methods: {
close() { close() {
console.log("this.loading", this.loading); console.log("this.loading", this.loading);
if (!this.loading) { if (!this.loading) {
this.$emit("close"); this.$emit("close");
} }
}, },
getDetails() { getDetails() {
this.$emit("getDetails"); this.$emit("getDetails");
}, },
/** /**
* 1.生成两个文件. 机房文件 和 井道文件 * 1.生成两个文件. 机房文件 和 井道文件
* 2. 更新巡检数据状态 synchronization 置为 1 * 2. 更新巡检数据状态 synchronization 置为 1
* 3. 写入数据 * 3. 写入数据
* 读取上一次打包的文件, 复制到 [ history ] 文件夹中 * 读取上一次打包的文件, 复制到 [ history ] 文件夹中
*/ */
clickHandle() { clickHandle() {
if (this.loading) return; if (this.loading) return;
this.coverData(); this.coverData();
}, },
// 保存图片到指定地址 // 保存图片到指定地址
copyImages(imagePaths, userName) { async copyImages(imagePaths, userName) {
const targetPath = `${SYNCHRONIZE_DATA_PAD}/设备上架照片/${userName}`; const targetPath = `${SYNCHRONIZE_DATA_PAD}/设备上架照片/${userName}`;
console.log("imagePath打包", imagePaths); const backtargetPath = `${SYNCHRONIZE_DATA_PAD}/list/${userName}`; // 复制文件到list目录下
//请空文件夹 console.log("imagePath打包", imagePaths);
deleteAllFilesInDirectory(targetPath).then(() => { await copyImagesToFolder(imagePaths, backtargetPath)
// 复制 //请空文件夹
copyImagesToFolder(imagePaths, targetPath).then((res) => { deleteAllFilesInDirectory(targetPath).then(() => {
uni.showToast({ // 复制
title: "打包成功", copyImagesToFolder(imagePaths, targetPath).then((res) => {
icon: "none", uni.showToast({
duration: 1000, title: "打包成功",
}); icon: "none",
setTimeout(() => { duration: 1000,
this.loading = false; });
this.close(); setTimeout(() => {
uni.navigateTo({ this.loading = false;
url: "/pages/listingManagement/index?backValue=home", this.close();
}); uni.navigateTo({
}, 1000); url: "/pages/listingManagement/index?backValue=home",
}); });
}); }, 1000);
}, });
// 处理数据 });
coverData() { },
const userName = this.$store.state.now_user.user; // 处理数据
let syncedData = this.list; coverData() {
let imagePaths = this.list.map((user) => user.imgPath); const userName = this.$store.state.now_user.user;
// 保存照片 let syncedData = this.list;
let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss"); let imagePaths = this.list.map((user) => user.imgPath);
syncedData.forEach((item) => { // 保存照片
item.synchronization = true; let timeStr = moment().format("yyyy_MM_DD_hh_mm_ss");
item.selected = false; syncedData.forEach((item) => {
item.status = "已同步"; item.synchronization = true;
}); item.selected = false;
console.log("syncedData", syncedData); item.status = "已同步";
this.loading = true; });
let SBSJ_DATA_FILE_NAME = `${userName}_SBSJ_${timeStr}.txt`; console.log("syncedData", syncedData);
const tmepList = this.packedData(syncedData, SBSJ_DATA_FILE_NAME); this.loading = true;
let SBSJ_DATA_FILE_NAME = `${userName}_SBSJ_${timeStr}.txt`;
const tmepList = this.packedData(syncedData, SBSJ_DATA_FILE_NAME);
let arr = this.photos.map((item) => { let arr = this.photos.map((item) => {
// 查找 B 数组中是否有对应的对象 // 查找 B 数组中是否有对应的对象
const updatedItem = syncedData.find((bItem) => bItem.id === item.id); const updatedItem = syncedData.find((bItem) => bItem.id === item.id);
// 如果有,则返回 B 数组中的对象,否则返回原对象 // 如果有,则返回 B 数组中的对象,否则返回原对象
return updatedItem ? updatedItem : item; return updatedItem ? updatedItem : item;
}); });
// writeDeviceData(tmepList, userName) // writeDeviceData(tmepList, userName)
// .then((res) => { // .then((res) => {
// console.log("tmepList", tmepList); // console.log("tmepList", tmepList);
this.$store.commit("SET_DEVICEDATA", arr); this.$store.commit("SET_DEVICEDATA", arr);
setTimeout( setTimeout(
() => { () => {
let length = arr.length; let length = arr.length;
// 生成日志 // 生成日志
const logContent = getLogContent( const logContent = getLogContent(
LOG_TYPE_ENUM.sys, LOG_TYPE_ENUM.sys,
`${length}张照同步`, `${length}张照同步`,
"同步" "同步"
); );
this.$logApi.addlog(logContent) this.$logApi.addlog(logContent)
const log_list = this.$store.state.log_list; const log_list = this.$store.state.log_list;
log_list.push(logContent); log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list); this.$store.commit("SET_LOG_LIST", log_list);
addLog(log_list).then(() => {}); addLog(log_list).then(() => {});
// 更新同步时间 // 更新同步时间
this.updateSysTime(); this.updateSysTime();
this.copyImages(imagePaths, userName); this.copyImages(imagePaths, userName);
// this.getDetails(); // this.getDetails();
}, },
2 * 1000 2 * 1000
// uni.navigateTo({ // uni.navigateTo({
// url: "/pages/listingManagement/index?backValue=home", // url: "/pages/listingManagement/index?backValue=home",
// }) // })
); );
// }) // })
// .catch((error) => { // .catch((error) => {
// this.loading = false; // this.loading = false;
// uni.showToast({ // uni.showToast({
// title: error, // title: error,
// icon: "none", // icon: "none",
// duration: 2000, // duration: 2000,
// }); // });
// }) // })
// .catch(() => { // .catch(() => {
// setTimeout(() => { // setTimeout(() => {
// uni.showToast({ // uni.showToast({
// title: "打包失败", // title: "打包失败",
// icon: "none", // icon: "none",
// duration: 2000, // duration: 2000,
// }); // });
// this.loading = false; // this.loading = false;
// }, 2 * 1000); // }, 2 * 1000);
// }); // });
}, },
// 打包文件 // 打包文件
packedData(content, fileName) { packedData(content, fileName) {
const fileContent = setSm2(content); const fileContent = setSm2(content);
return createFileWithPlusIO( return createFileWithPlusIO(
`${SYNCHRONIZE_DATA_PAD}/发送数据`, `${SYNCHRONIZE_DATA_PAD}/发送数据`,
fileName, fileName,
fileContent fileContent
); );
}, },
// 更新最近一次同步时间 // 更新最近一次同步时间
updateSysTime() { updateSysTime() {
getUserList().then((personList) => { getUserList().then((personList) => {
const now_user = this.$store.state.now_user; const now_user = this.$store.state.now_user;
const key = personList.findIndex( const key = personList.findIndex(
(item) => item.userId == now_user.userId (item) => item.userId == now_user.userId
); );
// 更新用户同步时间 // 更新用户同步时间
const userInfo = personList[key]; const userInfo = personList[key];
const LastSynchronizationTime = moment().format("yyyy-MM-DD HH:mm"); const LastSynchronizationTime = moment().format("yyyy-MM-DD HH:mm");
personList[key].LastSynchronizationTime = LastSynchronizationTime; personList[key].LastSynchronizationTime = LastSynchronizationTime;
userInfo.LastSynchronizationTime = LastSynchronizationTime; userInfo.LastSynchronizationTime = LastSynchronizationTime;
this.$store.commit("SET_USER", userInfo); this.$store.commit("SET_USER", userInfo);
uni.setStorageSync("last_time", userInfo.LastSynchronizationTime || ""); uni.setStorageSync("last_time", userInfo.LastSynchronizationTime || "");
// 更新用户数据 // 更新用户数据
const fileContent = JSON.stringify( const fileContent = JSON.stringify(
Base64.encode(JSON.stringify(personList)) Base64.encode(JSON.stringify(personList))
); );
uni.setStorage({ uni.setStorage({
key: "user_data", key: "user_data",
data: JSON.stringify(personList), data: JSON.stringify(personList),
fail: (error) => { fail: (error) => {
console.log("APP.vue 存储数据失败", error); console.log("APP.vue 存储数据失败", error);
}, },
}); });
createFileWithPlusIO(SYNCHRONIZE_DATA_PAD, USER_FILE_NAME, fileContent) createFileWithPlusIO(SYNCHRONIZE_DATA_PAD, USER_FILE_NAME, fileContent)
.then(() => { .then(() => {
console.log("---用户数据更新成功"); console.log("---用户数据更新成功");
}) })
.catch((error) => { .catch((error) => {
console.log("---用户数据更新失败", 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 {
padding: 3% 20px 32px 24px;
width: 400px;
height: 60%;
box-sizing: border-box;
background-image: linear-gradient(
-6deg,
#f9ffe7 0%,
#ffffff 12%,
#fcfeff 73%,
#ccf1ff 100%
);
border: 0.4px solid rgba(224, 224, 224, 1);
border-radius: 12px;
position: relative;
.row-item { .synchronous-content {
display: flex; padding: 3% 20px 32px 24px;
align-items: center; width: 400px;
justify-content: center; height: 60%;
} box-sizing: border-box;
background-image: linear-gradient(-6deg,
#f9ffe7 0%,
#ffffff 12%,
#fcfeff 73%,
#ccf1ff 100%);
border: 0.4px solid rgba(224, 224, 224, 1);
border-radius: 12px;
position: relative;
.title { .row-item {
font-family: PingFangSC-Medium; display: flex;
font-size: 18px; align-items: center;
color: #000000; justify-content: center;
text-align: center; }
line-height: 26px;
font-weight: 500;
}
.count-num {
margin: 5% 0 5% 0;
align-items: flex-end;
.num {
display: inline-block;
font-family: AlibabaPuHuiTi_2_65_Medium;
font-size: 50px;
color: #3774f6;
line-height: 44px;
font-weight: 500;
}
}
.operating-instructions { .title {
margin-bottom: 8%; font-family: PingFangSC-Medium;
.title { font-size: 18px;
font-size: 13px; color: #000000;
color: #4a4a4a; text-align: center;
line-height: 24px; line-height: 26px;
font-weight: 600; font-weight: 500;
text-align: left; }
}
.instructions-item {
font-size: 12px;
color: #7c7c7c;
line-height: 22px;
font-weight: 400;
}
}
// 打包按钮 .count-num {
.bottom-row { margin: 5% 0 5% 0;
position: absolute; align-items: flex-end;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
.button { .num {
display: flex; display: inline-block;
align-items: center; font-family: AlibabaPuHuiTi_2_65_Medium;
justify-content: center; font-size: 50px;
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%); color: #3774f6;
box-shadow: 0px 10px 24px 0px rgba(51, 104, 246, 0.24); line-height: 44px;
border-radius: 27px; font-weight: 500;
width: 160px; }
height: 40px; }
color: #fff;
}
}
// 关闭按钮 .operating-instructions {
.close-button { margin-bottom: 8%;
position: absolute;
bottom: -40px; .title {
left: 50%; font-size: 13px;
transform: translateX(-50%); color: #4a4a4a;
.iconfont { line-height: 24px;
font-size: 24px; font-weight: 600;
} text-align: left;
} }
}
} .instructions-item {
</style> font-size: 12px;
color: #7c7c7c;
line-height: 22px;
font-weight: 400;
}
}
// 打包按钮
.bottom-row {
position: absolute;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
.button {
display: flex;
align-items: center;
justify-content: center;
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
box-shadow: 0px 10px 24px 0px rgba(51, 104, 246, 0.24);
border-radius: 27px;
width: 160px;
height: 40px;
color: #fff;
}
}
// 关闭按钮
.close-button {
position: absolute;
bottom: -40px;
left: 50%;
transform: translateX(-50%);
.iconfont {
font-size: 24px;
}
}
}
}
</style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论