提交 1099b8bd authored 作者: zs's avatar zs

zip

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