提交 00c239e5 authored 作者: 秦浙峰's avatar 秦浙峰

fix()去除condole, 人员列表

上级 0732dd0a
......@@ -9,9 +9,10 @@ import {
readFileContent,
USER_LiST,
USER_FILE_NAME,
All_USER_FILE_NAME,
} from "./utils/systemCofig";
import { Base64 } from "js-base64";
import {differenceBy} from "lodash";
import { differenceBy } from "lodash";
import { readDirectoryData } from "@/utils/IoReadingAndWriting.js";
export default {
......@@ -65,15 +66,17 @@ export default {
onHide: function () {
// app关闭时将数据存储到本地缓存
uni.setStorageSync("now_user", this.$store.state.now_user);
uni.setStorageSync("last_time", this.$store.state.now_user.LastSynchronizationTime);
uni.setStorageSync(
"last_time",
this.$store.state.now_user.LastSynchronizationTime
);
// 清除store 数据
this.$store.commit("SET_DARF_DATA", {});
this.$store.commit("SET_LOG_LIST", []);
this.$store.commit("SET_ALL_DATA", []);
},
onUnload() {
},
onUnload() {},
methods: {
/**
* 第一步: 检查目录是否存在,如果没有就创建
......@@ -81,7 +84,7 @@ export default {
* 第三步:存储读取到的数据
*/
async init() {
checkAndCreateDirectory(SYNCHRONIZE_DATA_PAD)
await checkAndCreateDirectory(SYNCHRONIZE_DATA_PAD)
.then(() => {
return new Promise((resolve, reject) => {
// 检查目录下的文件是否存在
......@@ -115,24 +118,83 @@ export default {
});
})
.then(async (res) => {
// 获取文件数据
let userData = Base64.decode(res);
const diffUserList = await this.diffUserList(userData)
if(diffUserList.length){
this.updateIpadUsetList([...USER_LiST,...diffUserList])
const diffUserList = await this.diffUserList(userData);
userData = JSON.stringify([...USER_LiST,...diffUserList])
if (diffUserList.length) {
this.updateIpadUsetList([...USER_LiST, ...diffUserList]);
userData = JSON.stringify([...USER_LiST, ...diffUserList]);
}
await new Promise((resolve, reject) => {
// 检查是否存在全部用户列表数据
checkFileExists(SYNCHRONIZE_DATA_PAD, All_USER_FILE_NAME)
.then((allUserFileEntry) => {
// console.log("1---------");
return readFileContent(allUserFileEntry)
.then((res) => {
resolve(res);
})
.catch((error) => {
reject(error);
});
})
.catch(async (error) => {
// 文件不存在, 写入文件
const fileContent = res;
await createFileWithPlusIO(
SYNCHRONIZE_DATA_PAD,
All_USER_FILE_NAME,
fileContent
)
.then((allRes) => {
// console.log("2---------allRes", allRes);
resolve(allRes);
})
.catch((error) => {
reject(error);
});
});
}).then((allResData) => {
let allUserData = Base64.decode(allResData);
// console.log("3---------", typeof allUserData, typeof userData);
let data1 = eval(allUserData);
let data2 = eval(userData);
let key = "userId";
data2.forEach((obj) => {
if (!data1.find((item) => item[key] === obj[key])) {
console.log(item[key]);
data1.push(obj);
}
});
// console.log(
// "allUserDataList=====================",
// allUserData,
// userData,
// data1
// );
// 更新数据file中
this.updateIpadUsetList(data1);
uni.setStorage({
key: "user_data",
data: userData,
data: JSON.stringify(data1),
fail: (error) => {
console.log("APP.vue 存储数据失败", error);
},
});
});
// uni.setStorage({
// key: "user_data",
// data: userData,
// fail: (error) => {
// console.log("APP.vue 存储数据失败", error);
// },
// });
})
.catch((error) => {
console.log("---", error);
......@@ -141,28 +203,39 @@ export default {
.catch((error) => {
console.log("---目录创建失败", error);
});
// setTimeout(() => {
// const value = uni.getStorageSync("user_data");
// console.log(value, "value");
// },2000)
},
// 比较代码中的用户列表 和 ipad中存储用户的 差异
async diffUserList(ipadUserList = []){
const temp = eval(ipadUserList)
const diffResult = differenceBy(USER_LiST, temp, "userId")
async diffUserList(ipadUserList = []) {
const temp = eval(ipadUserList);
console.log(USER_LiST, temp, "temp");
const diffResult = differenceBy(temp, USER_LiST, "userId");
return diffResult
return diffResult;
},
// 更新 ipad 用户信息
updateIpadUsetList(tempPersonList){
updateIpadUsetList(tempPersonList) {
const temp = JSON.stringify(tempPersonList);
const fileContent = JSON.stringify(Base64.encode(temp));
createFileWithPlusIO(SYNCHRONIZE_DATA_PAD, USER_FILE_NAME, fileContent);
},
// 更新 ipad 用户信息 总的
updateIpadUsetList(tempPersonList) {
const temp = JSON.stringify(tempPersonList);
const fileContent = JSON.stringify(Base64.encode(temp));
createFileWithPlusIO(
SYNCHRONIZE_DATA_PAD,
USER_FILE_NAME,
All_USER_FILE_NAME,
fileContent
)
}
);
},
},
};
</script>
......
......@@ -70,6 +70,7 @@ import {
SYNCHRONIZE_DATA_PAD,
createFileWithPlusIO,
USER_FILE_NAME,
All_USER_FILE_NAME,
} from "@/utils/systemCofig";
export default {
data() {
......@@ -112,6 +113,7 @@ export default {
uni.navigateBack();
},
onShow() {
console.log(1111111, uni.getStorageSync("user_data"));
const value = this.$store.state.now_user;
if (value) {
this.user = value;
......@@ -119,6 +121,7 @@ export default {
const val = uni.getStorageSync("user_data");
if (val) {
this.personList = JSON.parse(val);
console.log(this.personList, "personList", val);
}
},
methods: {
......@@ -129,7 +132,6 @@ export default {
logOut() {
uni.removeStorage({
key: "now_user",
});
// uni.clearStorage(); //测试将所有缓存清除
uni.navigateTo({
......@@ -153,6 +155,11 @@ export default {
const temp = JSON.stringify(tempPersonList);
const fileContent = JSON.stringify(Base64.encode(temp));
createFileWithPlusIO(
SYNCHRONIZE_DATA_PAD,
All_USER_FILE_NAME,
fileContent
).then((res) => {
createFileWithPlusIO(
SYNCHRONIZE_DATA_PAD,
USER_FILE_NAME,
......@@ -170,11 +177,11 @@ export default {
const log_list = this.$store.state.log_list;
log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list);
addLog(log_list).then((res) => {
});
addLog(log_list).then((res) => {});
this.logOut();
});
});
} else {
this.formData = {
oldPd: "",
......
......@@ -3,7 +3,9 @@ import { Base64 } from "js-base64";
export const BASE_PATH = "_documents/data/asmzx"; // 基础路径
export const SYNCHRONIZE_DATA_PATH = "_documents/data/asmzx"; // 同步数据
export const SYNCHRONIZE_DATA_PAD = "_documents/data/asmzx/pad"; // 存储pad端的生产数据
export const USER_FILE_NAME = "userList.txt"; // 存储内置用户的文件名
export const USER_FILE_NAME = "userList.txt"; // 存储内置用户的文件名 会导入进行覆盖
export const All_USER_FILE_NAME = "allUserList.txt"; // 存储内置用户的文件名 会导入进行覆盖
export const FILE_ENUM = {
// 文件枚举
fileSystemError: {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论