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

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

上级 2a537883
...@@ -54,6 +54,8 @@ export default { ...@@ -54,6 +54,8 @@ export default {
}, },
function (e) {} function (e) {}
); );
// #endif
}, },
onShow: function () { onShow: function () {
const now_user = uni.getStorageSync("now_user") || {}; const now_user = uni.getStorageSync("now_user") || {};
...@@ -91,6 +93,7 @@ export default { ...@@ -91,6 +93,7 @@ export default {
}); });
}) })
.catch((error) => { .catch((error) => {
console.log("--USER_LiST-", USER_LiST)
// 文件不存在, 写入文件 // 文件不存在, 写入文件
const fileContent = JSON.stringify( const fileContent = JSON.stringify(
Base64.encode(JSON.stringify(USER_LiST)) Base64.encode(JSON.stringify(USER_LiST))
......
...@@ -241,6 +241,14 @@ export default { ...@@ -241,6 +241,14 @@ export default {
}, },
toPage() { toPage() {
// if (this.userInfo.isAdmin) {
// uni.showToast({
// title: "暂无权限",
// icon: "none",
// });
// return;
// }
uni.showLoading(); uni.showLoading();
getDarft() getDarft()
...@@ -263,10 +271,16 @@ export default { ...@@ -263,10 +271,16 @@ export default {
uni.hideLoading(); uni.hideLoading();
}) })
.catch((error) => { .catch((error) => {
uni.showToast({ if (error.code == 0) {
title: error.msg, uni.showToast({
icon: "none", title: error.msg,
duration: 1000,
icon: "none",
duration: 1000,
});
}
uni.navigateTo({
url: "/pages/inspection/inspFirst",
}); });
uni.hideLoading(); uni.hideLoading();
}); });
......
...@@ -97,11 +97,10 @@ export default { ...@@ -97,11 +97,10 @@ export default {
userName: this.$store.state.now_user.user, userName: this.$store.state.now_user.user,
}; };
}, },
onLoad(options={}) { onLoad(options = {}) {
// options就是路由参数,它是一个对象 // options就是路由参数,它是一个对象
// this.tabIndex = ; // this.tabIndex = ;
this.tabClick({}, options.tabIndex || 0) this.tabClick({}, options.tabIndex || 0);
console.log("---------------------", options); // 假设路由参数中有一个名为id的参数
}, },
methods: { methods: {
// 修改密码 // 修改密码
...@@ -127,8 +126,10 @@ export default { ...@@ -127,8 +126,10 @@ export default {
url: "/pages/login/login", url: "/pages/login/login",
success() { success() {
_this.$store.commit("SET_USER", {}); _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 { ...@@ -39,6 +39,7 @@ import {
getLogContent, getLogContent,
addLog, addLog,
readDirectoryData, readDirectoryData,
readLogData,
} from "@/utils/IoReadingAndWriting.js"; } from "@/utils/IoReadingAndWriting.js";
import moment from "moment"; import moment from "moment";
...@@ -49,8 +50,11 @@ export default { ...@@ -49,8 +50,11 @@ export default {
data() { data() {
return { return {
person: { person: {
user: "xhqxj", user: "bjqxj",
pd: "JF85250920", pd: "JF85250920",
// user: "hzsgjy", // 超管账号
// pd: "JFXJ85250920",
}, },
backButtonPress: 0, backButtonPress: 0,
personList: [], personList: [],
...@@ -152,9 +156,24 @@ export default { ...@@ -152,9 +156,24 @@ export default {
duration: 2000, 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 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); log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list); this.$store.commit("SET_LOG_LIST", log_list);
addLog(log_list); addLog(log_list);
......
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
readInspectionData, readInspectionData,
readDarfData readDarfData
} from "@/utils/IoReadingAndWriting.js"; } from "@/utils/IoReadingAndWriting.js";
import { sortTimeDesc } from "@/utils/common.js";
import lodash from "lodash"; import lodash from "lodash";
...@@ -14,23 +13,17 @@ import lodash from "lodash"; ...@@ -14,23 +13,17 @@ import lodash from "lodash";
* @returns * @returns
*/ */
export const getAllInspections = () => { export const getAllInspections = () => {
const all_data = store.state.all_data || [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (all_data.length) { readInspectionData()
resolve(all_data) .then((res) => {
} else { const tempRes = lodash.orderBy(res, "creatTime", ['desc']);
readInspectionData()
.then((res) => { store.commit("SET_ALL_DATA", tempRes);
// console.log("----读出来的巡检文件", res); resolve(tempRes)
const tempRes = lodash.orderBy(res, "creatTime", ['desc']); })
.catch((error) => {
store.commit("SET_ALL_DATA", tempRes); reject(error)
resolve(tempRes) })
})
.catch((error) => {
reject(error)
})
}
}) })
} }
...@@ -40,21 +33,18 @@ export const getAllInspections = () => { ...@@ -40,21 +33,18 @@ export const getAllInspections = () => {
* @returns * @returns
*/ */
export const getLogList = () => { export const getLogList = () => {
const log_list = store.state.log_list || [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (log_list.length) { readLogData()
resolve(log_list) .then((res) => {
} else { console.log("-getLogList--", res)
readLogData() const tempRes = lodash.orderBy(res, "time", "desc");
.then((res) => { store.commit("SET_LOG_LIST", tempRes);
console.log("----读出来的日志文件", res); resolve(tempRes)
store.commit("SET_LOG_LIST", res); })
resolve(res) .catch((error) => {
}) reject(error)
.catch((error) => { })
reject(error)
})
}
}) })
} }
...@@ -69,7 +59,6 @@ export const getInspectionDetails = (uid) => { ...@@ -69,7 +59,6 @@ export const getInspectionDetails = (uid) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getAllInspections() getAllInspections()
.then((res) => { .then((res) => {
console.log("--list-",res)
const detailsInfo = res.filter((item) => item.uid == uid)[0] || {}; const detailsInfo = res.filter((item) => item.uid == uid)[0] || {};
resolve(detailsInfo) resolve(detailsInfo)
...@@ -86,20 +75,15 @@ export const getInspectionDetails = (uid) => { ...@@ -86,20 +75,15 @@ export const getInspectionDetails = (uid) => {
* @returns * @returns
*/ */
export const getDarft = () => { export const getDarft = () => {
const darf_data = store.state.darf_data || {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (darf_data.inspectionType) { readDarfData()
resolve(darf_data) .then((res) => {
} else { console.log("----读出来的草稿文件", res);
readDarfData() store.commit("SET_DARF_DATA", res);
.then((res) => { resolve(res)
console.log("----读出来的草稿文件", res); })
store.commit("SET_DARF_DATA", res); .catch((error) => {
resolve(res) reject(error)
}) })
.catch((error) => {
reject(error)
})
}
}) })
} }
\ No newline at end of file
...@@ -75,15 +75,17 @@ export const addLog = (content) => { ...@@ -75,15 +75,17 @@ export const addLog = (content) => {
// 读取日志 // 读取日志
export const readLogData = () => { export const readLogData = () => {
const now_user = store.state.now_user; 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) => { return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath) readFilesInDirectory(directoryPath)
.then((res) => { .then((res) => {
console.log("--读取日志-, ",directoryPath, res)
const temp = res.map((element) => { const temp = res.map((element) => {
return JSON.parse(Base64.decode(element)); return JSON.parse(Base64.decode(element));
}); });
// console.log("读取志文件数据--", temp);
resolve(lodash.flattenDeep(temp)); resolve(lodash.flattenDeep(temp));
}) })
...@@ -175,7 +177,8 @@ export const writeInspectionData = (content, isEncryption = false) => { ...@@ -175,7 +177,8 @@ export const writeInspectionData = (content, isEncryption = false) => {
// 读取【巡检数据】文件 // 读取【巡检数据】文件
export const readInspectionData = () => { export const readInspectionData = () => {
const now_user = store.state.now_user; 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) => { return new Promise((resolve, reject) => {
readFilesInDirectory(directoryPath) readFilesInDirectory(directoryPath)
......
...@@ -60,15 +60,15 @@ export const FILE_ENUM = { // 文件枚举 ...@@ -60,15 +60,15 @@ export const FILE_ENUM = { // 文件枚举
export const USER_LiST = [ export const USER_LiST = [
{ {
id: 1, id: 1, // 有用
user: "hzsgjy", user: "hzsgjy", // 有用
passWord: "JFXJ85250920", passWord: "JFXJ85250920", // 有用
areaName: "市本级", areaName: "市本级", // 有用
permission: 1, permission: 1,
name: "超管", name: "超管", // 有用
oid: "scq", oid: "scq",
unitName: "所属单位" unitName: "所属单位", // 所属单位
isAdmin: true, // 标识超管权限
}, },
{ {
id: 3, id: 3,
...@@ -333,7 +333,7 @@ export async function checkFileExists(directoryPath, fileName) { ...@@ -333,7 +333,7 @@ export async function checkFileExists(directoryPath, fileName) {
} }
// 读取文件夹下面所有的文件 // 读取文件夹下面所有的文件
export const readFilesInDirectory = async (directoryPath) => { export const readFilesInDirectory11= async (directoryPath) => {
const promiseArr = []; const promiseArr = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.io.requestFileSystem( plus.io.requestFileSystem(
...@@ -362,7 +362,7 @@ export const readFilesInDirectory = async (directoryPath) => { ...@@ -362,7 +362,7 @@ export const readFilesInDirectory = async (directoryPath) => {
// }).catch((error) => { // }).catch((error) => {
// reject(error) // reject(error)
// }) // })
} }
} }
Promise.all(promiseArr) Promise.all(promiseArr)
...@@ -390,7 +390,7 @@ export const readFilesInDirectory = async (directoryPath) => { ...@@ -390,7 +390,7 @@ export const readFilesInDirectory = async (directoryPath) => {
); );
}, },
function (error) { function (error) {
console.log("readFilesInDirectory:", error,directoryPath); console.log("readFilesInDirectory:", error, directoryPath);
reject({ reject({
...FILE_ENUM.getDirectoryError ...FILE_ENUM.getDirectoryError
...@@ -410,6 +410,97 @@ export const readFilesInDirectory = async (directoryPath) => { ...@@ -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) { export async function readFileContent(fileEntry) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论