提交 8e7824a0 authored 作者: JaxBBLL's avatar JaxBBLL
<template>
<!-- 首页 -->
<view class="container">
<!-- 第一个模块 -->
<view class="header">
<view class="title">杭州内网监管在线-运维在线</view>
<view class="header-buttons">
<view class="log-button" @click="lookLog" v-if="isAdmin">操作日志</view>
<div class="exit-button" @click="logOut">
<image
class="logout"
src="@/static/img/logout.svg"
mode="aspectFit"
></image>
</div>
</view>
</view>
<!-- 首页 -->
<view class="container">
<!-- 第一个模块 -->
<view class="header">
<view class="title">杭州内网监管在线-运维在线</view>
<view class="header-buttons">
<view class="log-button" @click="lookLog" v-if="isAdmin">操作日志</view>
<div class="exit-button" @click="logOut">
<image class="logout" src="@/static/img/logout.svg" mode="aspectFit"></image>
</div>
</view>
</view>
<!-- 第二个模块 -->
<view class="profile-section">
<view class="profile-box">
<view class="profile-left">
<view class="avatar">
<image
src="@/static/img/add-img/defaultAvatar.png"
mode="aspectFit"
></image>
<view class="change-password" @click="updatePassword"
>修改密码</view
>
</view>
<view class="username">{{ userName }}</view>
</view>
<view class="profile-right">
<button class="inspection-button" @click="toInspectionManagement">
巡检管理
</button>
<button class="record-button" @click="toListingManagement">
设备上架管理
</button>
</view>
</view>
</view>
<!-- 第二个模块 -->
<view class="profile-section">
<view class="profile-box">
<view class="profile-left">
<view class="avatar">
<image src="@/static/img/add-img/defaultAvatar.png" mode="aspectFit"></image>
<view class="change-password" @click="updatePassword">修改密码</view>
</view>
<view class="username">{{ userName }}</view>
</view>
<view class="profile-right">
<button class="inspection-button" @click="toInspectionManagement">
巡检管理
</button>
<button class="record-button" @click="toListingManagement">
设备上架管理
</button>
</view>
</view>
</view>
<!-- 第三个模块 -->
<view class="card-section">
<view class="card-container">
<view
class="card"
v-for="(card, index) in cards"
:key="index"
:style="{ backgroundImage: `url(${card.image})` }"
@click="toList(card.url)"
>
<view class="card-text">{{ card.text }}</view>
</view>
</view>
</view>
<!-- 退出账号弹出 -->
<uni-popup ref="inputDialog2" type="dialog">
<uni-popup-dialog
ref="inputClose2"
mode="base"
title="确定退出该账号?"
@confirm="dialogInputConfirm2"
>
</uni-popup-dialog>
</uni-popup>
</view>
<!-- 第三个模块 -->
<view class="card-section">
<view class="card-container">
<view class="card" v-for="(card, index) in cards" :key="index"
:style="{ backgroundImage: `url(${card.image})` }" @click="toList(card.url)">
<view class="card-text">{{ card.text }}</view>
</view>
</view>
</view>
<!-- 退出账号弹出 -->
<uni-popup ref="inputDialog2" type="dialog">
<uni-popup-dialog ref="inputClose2" mode="base" title="确定退出该账号?" @confirm="dialogInputConfirm2">
</uni-popup-dialog>
</uni-popup>
</view>
</template>
<script>
export default {
data() {
return {
cards: [
{
image: "../../static/img/jf.png",
text: "机房巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home",
},
{
image: "../../static/img/jd.png",
text: "井道巡检",
url: "/pages/shaftInspection/shaftInspectionList?backValue=home",
},
{
image: "../../static/img/sj.png",
text: "设备上架",
url: "/pages/listingManagement/index?backValue=home",
},
],
userName: this.$store.state.now_user.user,
};
},
computed: {
isAdmin() {
return this.$store.state.now_user.isAdmin;
},
},
created() {
console.log(this.$store.state);
},
methods: {
// 修改密码
updatePassword() {
uni.navigateTo({
url: "/pages/index/editPd",
});
},
//退出
logOut() {
this.$refs.inputDialog2.open();
},
// 查看操作日志
lookLog() {
uni.navigateTo({
url: "/pages/index/operLog",
});
},
// 三模块卡片跳转页面
toList(url) {
uni.navigateTo({
url: url,
});
},
// 巡检管理
toInspectionManagement() {
uni.navigateTo({
url: "/pages/inspectionManagement/index?backValue=home",
});
},
toListingManagement() {
uni.navigateTo({
url: "/pages/listingManagement/index?backValue=home",
});
},
// 井道巡检
toShaftInspection() {
uni.navigateTo({
url: "/pages/shaftInspection/shaftInspectionNew?backValue=home",
});
},
//退出--弹出对话框
dialogInputConfirm2() {
uni.redirectTo({
url: "/pages/login/login",
success: () => {
// uni.clearStorage(); //测试将所有缓存清除
uni.setStorageSync("now_user", this.$store.state.now_user);
uni.setStorageSync(
"last_time",
this.$store.state.now_user.LastSynchronizationTime || ""
);
},
});
},
},
};
export default {
data() {
return {
cards: [{
image: "../../static/img/jf.png",
text: "机房巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home",
},
{
image: "../../static/img/jd.png",
text: "井道巡检",
url: "/pages/shaftInspection/shaftInspectionList?backValue=home",
},
{
image: "../../static/img/sj.png",
text: "设备上架",
url: "/pages/listingManagement/index?backValue=home",
},
],
userName: this.$store.state.now_user.user,
};
},
computed: {
isAdmin() {
return this.$store.state.now_user.isAdmin;
},
},
created() {
console.log(this.$store.state);
},
methods: {
// 修改密码
updatePassword() {
uni.navigateTo({
url: "/pages/index/editPd",
});
},
//退出
logOut() {
this.$refs.inputDialog2.open();
},
// 查看操作日志
lookLog() {
uni.navigateTo({
url: "/pages/index/operLog",
});
},
// 三模块卡片跳转页面
toList(url) {
uni.navigateTo({
url: url,
});
},
// 巡检管理
toInspectionManagement() {
uni.navigateTo({
url: "/pages/inspectionManagement/index?backValue=home",
});
},
toListingManagement() {
uni.navigateTo({
url: "/pages/listingManagement/index?backValue=home",
});
},
// 井道巡检
toShaftInspection() {
uni.navigateTo({
url: "/pages/shaftInspection/shaftInspectionNew?backValue=home",
});
},
//退出--弹出对话框
dialogInputConfirm2() {
uni.redirectTo({
url: "/pages/login/login",
success: () => {
// uni.clearStorage(); //测试将所有缓存清除
uni.setStorageSync("now_user", this.$store.state.now_user);
uni.setStorageSync(
"last_time",
this.$store.state.now_user.LastSynchronizationTime || ""
);
},
});
},
},
};
</script>
<style scoped lang="less">
.container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
height: 100vh;
background-image: linear-gradient(115deg, #e8f0fb 0%, #e1ebfa 100%);
z-index: 1;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
height: 100vh;
background-image: linear-gradient(115deg, #e8f0fb 0%, #e1ebfa 100%);
z-index: 1;
}
.header {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
position: relative;
margin-bottom: 147px;
.header {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
position: relative;
margin-bottom: 147px;
.title {
position: absolute;
left: 50%;
transform: translateX(-50%);
ont-family: PingFangSC-Medium;
font-size: 32px;
color: #000000;
text-align: center;
line-height: 40px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.16);
font-weight: 500;
}
.title {
position: absolute;
left: 50%;
transform: translateX(-50%);
ont-family: PingFangSC-Medium;
font-size: 32px;
color: #000000;
text-align: center;
line-height: 40px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.16);
font-weight: 500;
}
.header-buttons {
display: flex;
align-items: center;
margin-left: auto; // 将按钮组推到最右侧
.header-buttons {
display: flex;
align-items: center;
margin-left: auto; // 将按钮组推到最右侧
.log-button {
width: 112px;
height: 36px;
background: #ffffff;
border-radius: 18px;
margin-right: 10px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #000000;
line-height: 36px;
font-weight: 400;
text-align: center;
}
.log-button {
width: 112px;
height: 36px;
background: #ffffff;
border-radius: 18px;
margin-right: 10px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #000000;
line-height: 36px;
font-weight: 400;
text-align: center;
}
.exit-button {
width: 36px;
height: 36px;
background: #ffffff;
border: 0.5px solid rgba(224, 224, 224, 1);
border-radius: 18px;
display: flex;
justify-content: center;
align-items: center;
.exit-button {
width: 36px;
height: 36px;
background: #ffffff;
border: 0.5px solid rgba(224, 224, 224, 1);
border-radius: 18px;
display: flex;
justify-content: center;
align-items: center;
.logout {
width: 16px;
height: 16px;
}
}
}
}
.logout {
width: 16px;
height: 16px;
}
}
}
}
.profile-section {
width: 720px;
.profile-section {
width: 720px;
.profile-box {
background-color: #fff;
border-radius: 12px;
padding: 16px 32px;
display: flex;
justify-content: space-between;
align-items: center;
.profile-box {
background-color: #fff;
border-radius: 12px;
padding: 16px 32px;
display: flex;
justify-content: space-between;
align-items: center;
.profile-left {
display: flex;
align-items: center;
.profile-left {
display: flex;
align-items: center;
.avatar {
position: relative;
width: 86px;
height: 86px;
border-radius: 50%;
overflow: hidden;
.avatar {
position: relative;
width: 86px;
height: 86px;
border-radius: 50%;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
image {
width: 100%;
height: 100%;
}
.change-password {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
text-align: center;
height: 22px;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #ffffff;
line-height: 20px;
font-weight: 400;
}
}
.change-password {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
text-align: center;
height: 22px;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #ffffff;
line-height: 20px;
font-weight: 400;
}
}
.username {
margin-left: 16px;
font-family: PingFangSC-Medium;
font-size: 20px;
color: #000000;
line-height: 28px;
font-weight: 500;
}
}
.username {
margin-left: 16px;
font-family: PingFangSC-Medium;
font-size: 20px;
color: #000000;
line-height: 28px;
font-weight: 500;
}
}
.profile-right {
display: flex;
.profile-right {
display: flex;
.inspection-button {
width: 112px;
height: 36px;
background-image: linear-gradient(105deg, #68acfb 0%, #3774f6 100%);
border-radius: 18px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #ffffff;
line-height: 36px;
font-weight: 400;
margin-right: 16px;
}
.inspection-button {
width: 112px;
height: 36px;
background-image: linear-gradient(105deg, #68acfb 0%, #3774f6 100%);
border-radius: 18px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #ffffff;
line-height: 36px;
font-weight: 400;
margin-right: 16px;
}
.record-button {
width: 144px;
height: 36px;
background: #ffffff;
border: 1px solid rgba(55, 116, 246, 1);
border-radius: 18px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #3774f6;
line-height: 36px;
font-weight: 400;
}
}
}
}
.record-button {
width: 144px;
height: 36px;
background: #ffffff;
border: 1px solid rgba(55, 116, 246, 1);
border-radius: 18px;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #3774f6;
line-height: 36px;
font-weight: 400;
}
}
}
}
.card-section {
width: 720px;
margin-top: 20px;
.card-section {
width: 720px;
margin-top: 20px;
.card-container {
display: flex;
justify-content: space-between;
.card-container {
display: flex;
justify-content: space-between;
.card {
width: 224px;
height: 194px;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 130px;
background-size: cover; // 背景图覆盖整个卡片
background-position: center; // 背景图居中
.card {
width: 224px;
height: 194px;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 130px;
background-size: cover; // 背景图覆盖整个卡片
background-position: center; // 背景图居中
.card-text {
text-align: center;
font-family: PingFangSC-Semibold;
font-size: 16px;
color: #000000;
line-height: 24px;
font-weight: 600;
}
}
}
}
</style>
.card-text {
text-align: center;
font-family: PingFangSC-Semibold;
font-size: 16px;
color: #000000;
line-height: 24px;
font-weight: 600;
}
}
}
}
</style>
\ No newline at end of file
import { Base64 } from "js-base64";
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 FILE_ENUM = {
// 文件枚举
fileSystemError: {
code: 0,
msg: "请求文件系统失败",
},
getDirectoryError: {
code: 1,
msg: "获取目录失败",
},
getFileError: {
code: 2,
msg: "获取文件失败",
},
readFileError: {
code: 3,
msg: "读取文件失败",
},
fileNotExist: {
code: 4,
msg: "文件不存在",
},
writeFileError: {
code: 5,
msg: "写入文件失败",
},
createFileError: {
code: 6,
msg: "创建文件失败",
},
deleteFileError: {
code: 7,
msg: "删除文件失败",
},
readDirectoryError: {
code: 8,
msg: "读取目录条目失败",
},
copyFileError: {
code: 9,
msg: "文件复制失败",
},
// 文件枚举
fileSystemError: {
code: 0,
msg: "请求文件系统失败",
},
getDirectoryError: {
code: 1,
msg: "获取目录失败",
},
getFileError: {
code: 2,
msg: "获取文件失败",
},
readFileError: {
code: 3,
msg: "读取文件失败",
},
fileNotExist: {
code: 4,
msg: "文件不存在",
},
writeFileError: {
code: 5,
msg: "写入文件失败",
},
createFileError: {
code: 6,
msg: "创建文件失败",
},
deleteFileError: {
code: 7,
msg: "删除文件失败",
},
readDirectoryError: {
code: 8,
msg: "读取目录条目失败",
},
copyFileError: {
code: 9,
msg: "文件复制失败",
},
};
// 内置的用户信息
export const USER_LiST = [
// name-> roleName
// {
// userId: 1, // 有用
// user: "admin", // 有用 谁创建,谁有权限编辑和删除
// passWord: "JF123456", // 有用
// roleName: "超管", // 有用 -- 职位名称
// unitName: "超管所属单位", // 所属单位
// isAdmin: true, // 标识超管权限
// LastSynchronizationTime: "", // 上次同步时间
// },
{
userId: 0, // 有用
user: "叶一凡", // 有用 谁创建,谁有权限编辑和删除
passWord: "123456", // 有用
roleName: "运维", // 有用 -- 职位名称
unitName: "运维", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
{
userId: 262, // 有用
user: "test1", // 有用 谁创建,谁有权限编辑和删除
passWord: "JF123456", // 有用
roleName: "巡检员", // 有用
unitName: "巡检员1所属单位", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
{
userId: 3, // 有用
user: "test2", // 有用 谁创建,谁有权限编辑和删除
passWord: "JF123456", // 有用
roleName: "巡检员", // 有用
unitName: "巡检员1所属单位", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
// name-> roleName
// {
// userId: 1, // 有用
// user: "admin", // 有用 谁创建,谁有权限编辑和删除
// passWord: "JF123456", // 有用
// roleName: "超管", // 有用 -- 职位名称
// unitName: "超管所属单位", // 所属单位
// isAdmin: true, // 标识超管权限
// LastSynchronizationTime: "", // 上次同步时间
// },
{
userId: 0, // 有用
user: "叶一凡", // 有用 谁创建,谁有权限编辑和删除
passWord: "123456", // 有用
roleName: "运维", // 有用 -- 职位名称
unitName: "运维", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
{
userId: 262, // 有用
user: "test1", // 有用 谁创建,谁有权限编辑和删除
passWord: "JF123456", // 有用
roleName: "巡检员", // 有用
unitName: "巡检员1所属单位", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
{
userId: 3, // 有用
user: "test2", // 有用 谁创建,谁有权限编辑和删除
passWord: "JF123456", // 有用
roleName: "巡检员", // 有用
unitName: "巡检员1所属单位", // 所属单位
isAdmin: false, // 标识超管权限
LastSynchronizationTime: "", // 上次同步时间
},
];
/**
......@@ -112,227 +114,235 @@ export const USER_LiST = [
// 检查文件是否存在
export function checkAndCreateDirectory(directoryPath) {
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function (fs) {
// 获取指定目录的目录条目
fs.root.getDirectory(
directoryPath,
{ create: false },
function (dirEntry) {
// 目录存在
console.log(
"systemCofig.js_checkAndCreateDirectory_目录已存在:",
directoryPath
);
resolve(dirEntry);
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function(fs) {
// 获取指定目录的目录条目
fs.root.getDirectory(
directoryPath, {
create: false
},
function(dirEntry) {
// 目录存在
console.log(
"systemCofig.js_checkAndCreateDirectory_目录已存在:",
directoryPath
);
resolve(dirEntry);
return
},
function (error) {
// 目录不存在,创建目录
if (error.code === 1) {
// DOM Exception: NOT_FOUND_ERR (1)
fs.root.getDirectory(
directoryPath,
{ create: true },
function (newDirEntry) {
console.log(
"systemCofig.js_checkAndCreateDirectory_目录创建成功:",
newDirEntry.fullPath
);
resolve(newDirEntry);
},
function (error) {
reject({
...error,
msg: "systemCofig.js_checkAndCreateDirectory__创建目录失败:",
});
}
);
} else {
console.error(
"systemCofig.js_checkAndCreateDirectory_获取目录失败111:",
error.message
);
fs.root.getDirectory(
directoryPath,
{ create: true },
function (newDirEntry) {
console.log(
"systemCofig.js_checkAndCreateDirectory_目录创建成功:",
newDirEntry.fullPath
);
resolve(newDirEntry);
}
);
}
}
);
},
function (error) {
reject({
...error,
msg: "systemCofig.js_checkAndCreateDirectory_请求文件系统失败:",
});
}
);
});
},
function(error) {
// 目录不存在,创建目录
if (error.code === 1) {
// DOM Exception: NOT_FOUND_ERR (1)
fs.root.getDirectory(
directoryPath, {
create: true
},
function(newDirEntry) {
console.log(
"systemCofig.js_checkAndCreateDirectory_目录创建成功:",
newDirEntry.fullPath
);
resolve(newDirEntry);
},
function(error) {
reject({
...error,
msg: "systemCofig.js_checkAndCreateDirectory__创建目录失败:",
});
}
);
} else {
console.error(
"systemCofig.js_checkAndCreateDirectory_获取目录失败111:",
error.message
);
fs.root.getDirectory(
directoryPath, {
create: true
},
function(newDirEntry) {
console.log(
"systemCofig.js_checkAndCreateDirectory_目录创建成功:",
newDirEntry.fullPath
);
resolve(newDirEntry);
}
);
}
}
);
},
function(error) {
reject({
...error,
msg: "systemCofig.js_checkAndCreateDirectory_请求文件系统失败:",
});
}
);
});
}
// 检查文件是否存在
export async function checkFileExists(directoryPath, fileName) {
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function (fs) {
// 获取指定目录的目录条目
fs.root.getDirectory(
directoryPath,
{ create: false },
function (dirEntry) {
// 尝试获取文件
dirEntry.getFile(
fileName,
{ create: false },
function (fileEntry) {
// 文件存在
console.log("文件存在:", fileEntry.fullPath);
resolve(fileEntry);
},
function (error) {
// 文件不存在
reject({
...error,
...FILE_ENUM.fileNotExist,
// code: FILE_ENUM
// msg: "checkFileExists_文件不存在",
});
}
);
},
function (error) {
console.error("获取目录失败:", error.message);
reject({
...error,
...FILE_ENUM.getDirectoryError,
// msg: "checkFileExists_获取目录失败",
});
}
);
},
function (error) {
console.error("请求文件系统失败:", error.message);
reject({
...error,
...FILE_ENUM.fileSystemError,
// msg: "checkFileExists_请求文件系统失败",
});
}
);
});
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function(fs) {
// 获取指定目录的目录条目
fs.root.getDirectory(
directoryPath, {
create: false
},
function(dirEntry) {
// 尝试获取文件
dirEntry.getFile(
fileName, {
create: false
},
function(fileEntry) {
// 文件存在
console.log("文件存在:", fileEntry.fullPath);
resolve(fileEntry);
},
function(error) {
// 文件不存在
reject({
...error,
...FILE_ENUM.fileNotExist,
// code: FILE_ENUM
// msg: "checkFileExists_文件不存在",
});
}
);
},
function(error) {
console.error("获取目录失败:", error.message);
reject({
...error,
...FILE_ENUM.getDirectoryError,
// msg: "checkFileExists_获取目录失败",
});
}
);
},
function(error) {
console.error("请求文件系统失败:", error.message);
reject({
...error,
...FILE_ENUM.fileSystemError,
// msg: "checkFileExists_请求文件系统失败",
});
}
);
});
}
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,
});
}
);
});
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,
});
}
);
});
};
// 读取【单个文件】内容
export async function readFileContent(fileEntry) {
return new Promise((resolve, reject) => {
// 创建FileReader对象
const reader = new plus.io.FileReader();
// 读取文件
reader.onload = function (e) {
resolve(e.target.result);
};
reader.onerror = function (e) {
console.error(
"systemCofig.js_readFileContent_读取文件失败:",
e.target.error
);
reject({
// msg: "systemCofig.js_readFileContent_读取文件失败:",
...e.target.error,
...FILE_ENUM.readFileError,
});
};
// 以文本方式读取文件
reader.readAsText(fileEntry);
});
return new Promise((resolve, reject) => {
// 创建FileReader对象
const reader = new plus.io.FileReader();
// 读取文件
reader.onload = function(e) {
resolve(e.target.result);
};
reader.onerror = function(e) {
console.error(
"systemCofig.js_readFileContent_读取文件失败:",
e.target.error
);
reject({
// msg: "systemCofig.js_readFileContent_读取文件失败:",
...e.target.error,
...FILE_ENUM.readFileError,
});
};
// 以文本方式读取文件
reader.readAsText(fileEntry);
});
}
/**
......@@ -343,118 +353,143 @@ export async function readFileContent(fileEntry) {
* @returns
*/
export function createFileWithPlusIO(directoryPath, fileName, fileContent) {
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function (fs) {
// 获取或创建目录
fs.root.getDirectory(
directoryPath,
{ create: true },
function (dirEntry) {
// 创建文件
dirEntry.getFile(
fileName,
{ create: true },
function (fileEntry) {
// 写入文件
fileEntry.createWriter(
function (fileWriter) {
fileWriter.onwriteend = function () {
resolve(fileContent);
};
fileWriter.onerror = function (error) {
console.log(
"createFileWithPlusIO_文件创建或写入失败:",
error
);
reject({
...error,
...FILE_ENUM.writeFileError,
});
};
// 向文件中写入数据
fileWriter.write(fileContent);
},
function (error) {
console.log(
"createFileWithPlusIO_创建文件写入器失败:",
error
);
reject({
...error,
...FILE_ENUM.createFileError,
});
}
);
},
function (error) {
console.log("createFileWithPlusIO_获取文件失败:", error);
reject({
...error,
...FILE_ENUM.getFileError,
});
}
);
},
function (error) {
console.log("createFileWithPlusIO_获取目录失败:", error);
reject({
...error,
...FILE_ENUM.getDirectoryError,
});
}
);
},
function (error) {
reject({
...error,
...FILE_ENUM.fileSystemError,
msg: "createFileWithPlusIO_请求文件系统失败:",
});
}
);
});
return new Promise((resolve, reject) => {
// 请求文件系统
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function(fs) {
// 获取或创建目录
fs.root.getDirectory(
directoryPath, {
create: true
},
function(dirEntry) {
// 创建文件
dirEntry.getFile(
fileName, {
create: true
},
function(fileEntry) {
// 写入文件
fileEntry.createWriter(
function(fileWriter) {
fileWriter.onwriteend = function() {
resolve(fileContent);
};
fileWriter.onerror = function(error) {
console.log(
"createFileWithPlusIO_文件创建或写入失败:",
error
);
reject({
...error,
...FILE_ENUM.writeFileError,
});
};
// 向文件中写入数据
fileWriter.write(fileContent);
},
function(error) {
console.log(
"createFileWithPlusIO_创建文件写入器失败:",
error
);
reject({
...error,
...FILE_ENUM.createFileError,
});
}
);
},
function(error) {
console.log("createFileWithPlusIO_获取文件失败:", error);
reject({
...error,
...FILE_ENUM.getFileError,
});
}
);
},
function(error) {
console.log("createFileWithPlusIO_获取目录失败:", error);
reject({
...error,
...FILE_ENUM.getDirectoryError,
});
}
);
},
function(error) {
reject({
...error,
...FILE_ENUM.fileSystemError,
msg: "createFileWithPlusIO_请求文件系统失败:",
});
}
);
});
}
// 加密方法
export function setSm2(data) {
const sm2 = require("sm-crypto").sm2; // 获取sm2对象
const cipherMode = 1; // 选择加密策略,1 - C1C3C2,0 - C1C2C3,默认为1
const sysPublicKey =
"042580b43bad40cc813a032ef3a4c3c38fc58796e0684dd9b5087195a305f4241f9bbefcc92a10e7296ffc167d22a921c164b8cbbbdbcf91ddc3f15202b993f03b"; // 系统后台公钥
if (data) {
return sm2.doEncrypt(JSON.stringify(data), sysPublicKey, cipherMode);
} else {
return null;
}
const sm2 = require("sm-crypto").sm2; // 获取sm2对象
const cipherMode = 1; // 选择加密策略,1 - C1C3C2,0 - C1C2C3,默认为1
const sysPublicKey =
"042580b43bad40cc813a032ef3a4c3c38fc58796e0684dd9b5087195a305f4241f9bbefcc92a10e7296ffc167d22a921c164b8cbbbdbcf91ddc3f15202b993f03b"; // 系统后台公钥
if (data) {
return sm2.doEncrypt(JSON.stringify(data), sysPublicKey, cipherMode);
} else {
return null;
}
}
// 获取用户数据
export function getUserList() {
return new Promise((resolve, reject) => {
try {
const value = uni.getStorageSync("user_data");
if (value) {
resolve(eval(value));
} else {
uni.getStorage({
key: "user_data",
success: function (res) {
resolve(eval(value));
},
});
}
} catch (e) {
reject(e)
}
});
return new Promise((resolve, reject) => {
try {
const value = uni.getStorageSync("user_data");
if (value) {
resolve(eval(value));
} else {
uni.getStorage({
key: "user_data",
success: function(res) {
resolve(eval(value));
},
});
}
} catch (e) {
reject(e)
}
});
}
export function zipCompress(name) {
const BASE_PATH = "_documents/data";
const targetPath = plus.io.convertLocalFileSystemURL(BASE_PATH + '/photos');
const zipfile = plus.io.convertLocalFileSystemURL(BASE_PATH + `/${name}.zip`);
plus.zip.compress(
targetPath,
zipfile, {
recursive: true,
overwrite: true
},
function() {
plus.io.resolveLocalFileSystemURL(zipfile, function(zipEntry) {
zipEntry.file(function(file) {
console.log("ZIP 文件大小: " + file.size + " 字节");
});
});
},
function(error) {
alert("压缩失败: " + error.message);
}
);
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论