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

fix()去除condole, 人员列表

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