提交 66584b83 authored 作者: 邓文彬's avatar 邓文彬

fix(数据获取): 增加数据权限

上级 2a537883
......@@ -54,6 +54,8 @@ export default {
},
function (e) {}
);
// #endif
},
onShow: function () {
const now_user = uni.getStorageSync("now_user") || {};
......@@ -91,6 +93,7 @@ export default {
});
})
.catch((error) => {
console.log("--USER_LiST-", USER_LiST)
// 文件不存在, 写入文件
const fileContent = JSON.stringify(
Base64.encode(JSON.stringify(USER_LiST))
......
......@@ -241,6 +241,14 @@ export default {
},
toPage() {
// if (this.userInfo.isAdmin) {
// uni.showToast({
// title: "暂无权限",
// icon: "none",
// });
// return;
// }
uni.showLoading();
getDarft()
......@@ -263,10 +271,16 @@ export default {
uni.hideLoading();
})
.catch((error) => {
uni.showToast({
title: error.msg,
icon: "none",
duration: 1000,
if (error.code == 0) {
uni.showToast({
title: error.msg,
icon: "none",
duration: 1000,
});
}
uni.navigateTo({
url: "/pages/inspection/inspFirst",
});
uni.hideLoading();
});
......
......@@ -97,11 +97,10 @@ export default {
userName: this.$store.state.now_user.user,
};
},
onLoad(options={}) {
onLoad(options = {}) {
// options就是路由参数,它是一个对象
// this.tabIndex = ;
this.tabClick({}, options.tabIndex || 0)
console.log("---------------------", options); // 假设路由参数中有一个名为id的参数
this.tabClick({}, options.tabIndex || 0);
},
methods: {
// 修改密码
......@@ -127,8 +126,10 @@ export default {
url: "/pages/login/login",
success() {
_this.$store.commit("SET_USER", {});
uni.setStorageSync("now_user", this.$store.state.now_user);
uni.setStorageSync("last_time", this.$store.state.last_time);
// uni.clearStorage(); //测试将所有缓存清除
uni.clearStorage(); //测试将所有缓存清除
},
});
},
......
......@@ -39,6 +39,7 @@ import {
getLogContent,
addLog,
readDirectoryData,
readLogData,
} from "@/utils/IoReadingAndWriting.js";
import moment from "moment";
......@@ -49,8 +50,11 @@ export default {
data() {
return {
person: {
user: "xhqxj",
user: "bjqxj",
pd: "JF85250920",
// user: "hzsgjy", // 超管账号
// pd: "JFXJ85250920",
},
backButtonPress: 0,
personList: [],
......@@ -152,9 +156,24 @@ export default {
duration: 2000,
});
let log_list = [];
readLogData()
.then((res) => {
log_list = res;
})
.catch((error) => {
if (error.code == 0) {
uni.showToast({
title: error.msg,
icon: "none",
duration: 2000,
});
return;
}
});
// 更新日志信息
const logContent = getLogContent(LOG_TYPE_ENUM.login);
const log_list = this.$store.state.log_list || [];
// const log_list = this.$store.state.log_list || [];
log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list);
addLog(log_list);
......
......@@ -4,7 +4,6 @@ import {
readInspectionData,
readDarfData
} from "@/utils/IoReadingAndWriting.js";
import { sortTimeDesc } from "@/utils/common.js";
import lodash from "lodash";
......@@ -14,23 +13,17 @@ import lodash from "lodash";
* @returns
*/
export const getAllInspections = () => {
const all_data = store.state.all_data || [];
return new Promise((resolve, reject) => {
if (all_data.length) {
resolve(all_data)
} else {
readInspectionData()
.then((res) => {
// console.log("----读出来的巡检文件", res);
const tempRes = lodash.orderBy(res, "creatTime", ['desc']);
store.commit("SET_ALL_DATA", tempRes);
resolve(tempRes)
})
.catch((error) => {
reject(error)
})
}
readInspectionData()
.then((res) => {
const tempRes = lodash.orderBy(res, "creatTime", ['desc']);
store.commit("SET_ALL_DATA", tempRes);
resolve(tempRes)
})
.catch((error) => {
reject(error)
})
})
}
......@@ -40,21 +33,18 @@ export const getAllInspections = () => {
* @returns
*/
export const getLogList = () => {
const log_list = store.state.log_list || [];
return new Promise((resolve, reject) => {
if (log_list.length) {
resolve(log_list)
} else {
readLogData()
.then((res) => {
console.log("----读出来的日志文件", res);
store.commit("SET_LOG_LIST", res);
resolve(res)
})
.catch((error) => {
reject(error)
})
}
readLogData()
.then((res) => {
console.log("-getLogList--", res)
const tempRes = lodash.orderBy(res, "time", "desc");
store.commit("SET_LOG_LIST", tempRes);
resolve(tempRes)
})
.catch((error) => {
reject(error)
})
})
}
......@@ -69,7 +59,6 @@ export const getInspectionDetails = (uid) => {
return new Promise((resolve, reject) => {
getAllInspections()
.then((res) => {
console.log("--list-",res)
const detailsInfo = res.filter((item) => item.uid == uid)[0] || {};
resolve(detailsInfo)
......@@ -86,20 +75,15 @@ export const getInspectionDetails = (uid) => {
* @returns
*/
export const getDarft = () => {
const darf_data = store.state.darf_data || {};
return new Promise((resolve, reject) => {
if (darf_data.inspectionType) {
resolve(darf_data)
} else {
readDarfData()
.then((res) => {
console.log("----读出来的草稿文件", res);
store.commit("SET_DARF_DATA", res);
resolve(res)
})
.catch((error) => {
reject(error)
})
}
readDarfData()
.then((res) => {
console.log("----读出来的草稿文件", res);
store.commit("SET_DARF_DATA", res);
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}
\ No newline at end of file
......@@ -75,15 +75,17 @@ export const addLog = (content) => {
// 读取日志
export const readLogData = () => {
const now_user = store.state.now_user;
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/日志文件/${now_user.user}`;
const isAdmin = now_user.isAdmin;
const directoryPath =isAdmin?`${SYNCHRONIZE_DATA_PAD}/日志文件`:`${SYNCHRONIZE_DATA_PAD}/日志文件/${now_user.user}`;
return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath)
.then((res) => {
console.log("--读取日志-, ",directoryPath, res)
const temp = res.map((element) => {
return JSON.parse(Base64.decode(element));
});
// console.log("读取志文件数据--", temp);
resolve(lodash.flattenDeep(temp));
})
......@@ -175,7 +177,8 @@ export const writeInspectionData = (content, isEncryption = false) => {
// 读取【巡检数据】文件
export const readInspectionData = () => {
const now_user = store.state.now_user;
const directoryPath = `${SYNCHRONIZE_DATA_PAD}/巡检数据/${now_user.user}`;
const isAdmin = now_user.isAdmin;
const directoryPath = isAdmin?`${SYNCHRONIZE_DATA_PAD}/巡检数据`:`${SYNCHRONIZE_DATA_PAD}/巡检数据/${now_user.user}`;
return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath)
......
......@@ -60,15 +60,15 @@ export const FILE_ENUM = { // 文件枚举
export const USER_LiST = [
{
id: 1,
user: "hzsgjy",
passWord: "JFXJ85250920",
areaName: "市本级",
id: 1, // 有用
user: "hzsgjy", // 有用
passWord: "JFXJ85250920", // 有用
areaName: "市本级", // 有用
permission: 1,
name: "超管",
name: "超管", // 有用
oid: "scq",
unitName: "所属单位"
unitName: "所属单位", // 所属单位
isAdmin: true, // 标识超管权限
},
{
id: 3,
......@@ -333,7 +333,7 @@ export async function checkFileExists(directoryPath, fileName) {
}
// 读取文件夹下面所有的文件
export const readFilesInDirectory = async (directoryPath) => {
export const readFilesInDirectory11= async (directoryPath) => {
const promiseArr = [];
return new Promise((resolve, reject) => {
plus.io.requestFileSystem(
......@@ -362,7 +362,7 @@ export const readFilesInDirectory = async (directoryPath) => {
// }).catch((error) => {
// reject(error)
// })
}
}
}
Promise.all(promiseArr)
......@@ -390,7 +390,7 @@ export const readFilesInDirectory = async (directoryPath) => {
);
},
function (error) {
console.log("readFilesInDirectory:", error,directoryPath);
console.log("readFilesInDirectory:", error, directoryPath);
reject({
...FILE_ENUM.getDirectoryError
......@@ -410,6 +410,97 @@ export const readFilesInDirectory = async (directoryPath) => {
);
});
};
export const readFilesInDirectory = async (directoryPath) => {
const promiseArr = [];
return new Promise((resolve, reject) => {
plus.io.requestFileSystem(
plus.io.PRIVATE_DOC,
function (fs) {
fs.root.getDirectory(
directoryPath,
{ create: false },
function (dirEntry) {
let directoryReader = dirEntry.createReader();
directoryReader.readEntries(
function (entries) {
entries.forEach((entry) => {
if (entry.isFile) {
// 读取文件内容
promiseArr.push(readFileContent(entry));
} else if (entry.isDirectory) {
// 递归读取子目录内容
promiseArr.push(readFilesInDirectory(entry.fullPath));
}
});
Promise.all(promiseArr)
.then((results) => {
// 扁平化结果数组,因为子目录可能返回一个包含多个文件内容的数组
const flatResults = results.flat(Infinity);
resolve(flatResults);
})
.catch((error) => {
console.log("readFilesInDirectory:", error);
reject({
...FILE_ENUM.getFileError,
message: "读取文件内容失败:" + error.message
});
});
},
function (error) {
console.log("readFilesInDirectory:", error);
reject({
...FILE_ENUM.readDirectoryError,
message: "读取目录条目失败:" + error.message
});
}
);
},
function (error) {
console.log("readFilesInDirectory:", error, directoryPath);
reject({
...FILE_ENUM.getDirectoryError,
message: "获取目录失败:" + error.message
});
}
);
},
function (error) {
console.log("readFilesInDirectory:", error);
reject({
...FILE_ENUM.fileSystemError,
message: "请求文件系统失败:" + error.message
});
}
);
});
};
// // 使用封装的Promise函数
// const rootDirectoryPath = '_doc/your-root-directory'; // 替换为你的根目录路径
// readAllFilesInDirectoryPromise(rootDirectoryPath)
// .then((allFilesContent) => {
// console.log('All files content:', allFilesContent);
// // 处理所有文件内容
// })
// .catch((error) => {
// console.error('Error reading files:', error);
// });
// 使用封装的Promise函数
// const rootDirectoryPath = '_doc/your-root-directory'; // 替换为你的根目录路径
// readAllFilesInDirectoryPromise(rootDirectoryPath)
// .then((allFilesContent) => {
// console.log('All files content:', allFilesContent);
// // 处理所有文件内容
// })
// .catch((error) => {
// console.error('Error reading files:', error);
// });
// 读取【单个文件】内容
export async function readFileContent(fileEntry) {
return new Promise((resolve, reject) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论