Browse Source

12.2

master
lichong 3 weeks ago
parent
commit
c0fb2f5899
  1. 106
      src/main/index.js
  2. 2
      src/renderer/src/assets/js/db.js
  3. 49
      src/renderer/src/assets/json/file.json
  4. 70
      src/renderer/src/components/formcomponent.vue
  5. 52
      src/renderer/src/components/tablecomponent.vue
  6. 14
      src/renderer/src/components/treecomponent.vue
  7. 618
      src/renderer/src/views/dangan.vue

106
src/main/index.js

@ -1,8 +1,7 @@
import { app, shell, BrowserWindow, nativeImage, ipcMain } from 'electron' import { app, shell, BrowserWindow, nativeImage, ipcMain } from 'electron'
import * as path from 'path' import * as path from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { machineIdSync } from 'node-machine-id'; const fs = require('fs');
// logo // logo
const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg'))
// 主窗口 // 主窗口
@ -55,10 +54,107 @@ app.whenReady().then(() => {
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow() if (BrowserWindow.getAllWindows().length === 0) createWindow()
}) })
ipcMain.on('deviceIdentify', () => { // 新增文件夹
let res = machineIdSync() ipcMain.on('createFloder', (e, pathListStr) => {
mainWindow.webContents.send(`deviceResult`, res) let pathList = JSON.parse(pathListStr)
// 获取应用程序的用户数据目录
let successList = []
let errorList = []
for (let index = 0; index < pathList.length; index++) {
let element = pathList[index];
let folderPath = path.join("E:\\test\\", element);
try {
fs.mkdirSync(`${folderPath}\\`, { recursive: true });
successList.push(element)
} catch (error) {
errorList.push(element)
}
}
mainWindow.webContents.send(`createFloderResult`, JSON.stringify({ successList, errorList }))
})
// 重命名文件夹
ipcMain.on('putFloder', (e, pathObjStr) => {
let pathObj = JSON.parse(pathObjStr)
// 获取应用程序的用户数据目录
let successList = []
let errorList = []
let oldfolderPath = path.join("E:\\test\\", pathObj.oldPath);
let newfolderPath = path.join("E:\\test\\", pathObj.newPath);
try {
fs.rename(`${oldfolderPath}\\`, `${newfolderPath}\\`, error => {
if (error) {
errorList.push(pathObj)
} else {
successList.push(pathObj)
}
mainWindow.webContents.send(`putFloderResult`, JSON.stringify({ successList, errorList }))
});
} catch (error) {
}
})
// 删除文件夹
ipcMain.on('delFloder', (e, pathObjStr) => {
let pathObj = JSON.parse(pathObjStr)
// 获取应用程序的用户数据目录
let successList = []
let errorList = []
let folderPath = path.join("E:\\test\\", pathObj.name);
fs.rm(folderPath, { recursive: true, force: true }, function (err) {
if (err) {
errorList.push(pathObj)
} else {
successList.push(pathObj)
}
mainWindow.webContents.send(`delFloderResult`, JSON.stringify({ successList, errorList }))
});
})
// 新增文件
ipcMain.on('createFile', (e, pathListStr) => {
let pathList = JSON.parse(pathListStr)
// 获取应用程序的用户数据目录
let successList = []
let errorList = []
for (let index = 0; index < pathList.length; index++) {
let element = pathList[index];
let destinationFilePath = path.join("E:\\test\\", element.path);
let sourceFilePath = element.prePath;
try {
fs.copyFileSync(sourceFilePath, destinationFilePath);
successList.push(element)
} catch (error) {
errorList.push(element)
}
}
mainWindow.webContents.send(`createFileResult`, JSON.stringify({ successList, errorList }))
})
// 重命名文件
ipcMain.on('putFile', (e, paramsStr) => {
let paramsObj = JSON.parse(paramsStr)
mainWindow.webContents.send(`putFileResult`, paramsObj)
}) })
// 删除文件
ipcMain.on('delFile', (e, paramsStr) => {
let paramsObj = JSON.parse(paramsStr)
mainWindow.webContents.send(`delFileResult`, paramsObj)
})
// 打开文件
ipcMain.on('openFile', (e, pathStr) => {
let filePath = path.join("E:\\test\\", pathStr);
shell.openPath(filePath)
})
// 下载文件
ipcMain.on('downloadFile', (e, pathStr) => {
let filePath = path.join("E:\\test\\", pathStr);
// 读取文件后传给前端
fs.readFile(filePath, function (err, data) {
if (err) {
console.error('读取文件时出错:', err);
mainWindow.webContents.send(`downloadFileResult`, { success: false, error: err.message });
} else {
mainWindow.webContents.send(`downloadFileResult`, { success: true, data, path: pathStr });
}
});
});
}) })
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required'); app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
// Quit when all windows are closed, except on macOS. There, it's common // Quit when all windows are closed, except on macOS. There, it's common

2
src/renderer/src/assets/js/db.js

@ -4,6 +4,6 @@ export const myDatabase = new Dexie('myDatabase');
// 定义数据库版本 // 定义数据库版本
myDatabase.version(1).stores({ myDatabase.version(1).stores({
treeList: '++id, label, currentId, preId, prepreId, level, note, create_at, update_at', treeList: '++id, label, currentId, path, status, preId, delete, fileList, prepreId, level, note, create_at, update_at',
fileList: '++id, treeId, xiangmuName, juanName, fileName, fileType, uploadTime, status, path, note, create_at, update_at' fileList: '++id, treeId, xiangmuName, juanName, fileName, fileType, uploadTime, status, path, note, create_at, update_at'
}); });

49
src/renderer/src/assets/json/file.json

@ -4,7 +4,6 @@
"prop": "xiangmuName", "prop": "xiangmuName",
"type": "text", "type": "text",
"tableShow": true, "tableShow": true,
"formShow": true,
"export": true "export": true
}, },
{ {
@ -17,50 +16,68 @@
"label": "文件名", "label": "文件名",
"prop": "fileName", "prop": "fileName",
"type": "text", "type": "text",
"tooltip": "如果不填写则默认使用上传文件的文件名",
"tableShow": true, "tableShow": true,
"formShow": true, "formShow": false,
"export": true "export": true
}, },
{
"label": "文件",
"prop": "file",
"type": "file",
"tableShow": false,
"formShow": true,
"export": false
},
{
"label": "文件大小",
"prop": "size",
"type": "size",
"tableShow": true,
"formShow": false,
"export": false
},
{ {
"label": "文件类型", "label": "文件类型",
"prop": "fileType", "prop": "fileType",
"type": "select", "type": "select",
"tooltip": "如果不填写则默认使用上传文件的文件类型,如果填写请正确填写",
"option": [ "option": [
{ {
"label": "doc", "label": "doc",
"value": "doc" "value": "application/msword"
}, },
{ {
"label": "docx", "label": "docx",
"value": "docx" "value": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}, },
{ {
"label": "jpg", "label": "jpg",
"value": "jpg" "value": "image/jpeg"
}, },
{ {
"label": "mp4", "label": "mp4",
"value": "mp4" "value": "video/mp4"
}, },
{ {
"label": "pdf", "label": "pdf",
"value": "pdf" "value": "application/pdf"
}, },
{ {
"label": "png", "label": "png",
"value": "png" "value": "image/png"
}, },
{ {
"label": "xls", "label": "xls",
"value": "xls" "value": "application/vnd.ms-excel"
}, },
{ {
"label": "xlsx", "label": "xlsx",
"value": "xlsx" "value": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
} }
], ],
"tableShow": true, "tableShow": true,
"formShow": true, "formShow": false,
"export": true "export": true
}, },
{ {
@ -77,11 +94,15 @@
"type": "select", "type": "select",
"option": [ "option": [
{ {
"value": "0", "value": "",
"label": "全部"
},
{
"value": "正常",
"label": "正常" "label": "正常"
}, },
{ {
"value": "1", "value": "注销",
"label": "注销" "label": "注销"
} }
], ],
@ -94,7 +115,7 @@
"prop": "path", "prop": "path",
"type": "text", "type": "text",
"tableShow": true, "tableShow": true,
"formShow": true, "formShow": false,
"export": true "export": true
}, },
{ {

70
src/renderer/src/components/formcomponent.vue

@ -1,14 +1,14 @@
<template> <template>
<div class="tableClass"> <div class="tableClass">
<el-form :model="formData" label-suffix="" :disabled="disabled" inline> <el-form :model="formData" label-suffix="" :disabled="disabled" inline>
<el-form-item :label="formItem.label" :key="formIndex" v-for="(formItem, formIndex) in formHeader"> <el-form-item :label="formItem.label" :key="formIndex" v-for="(formItem, formIndex) in formHeader"
style="margin: 8px;">
<template v-if="formItem.type === 'text'"> <template v-if="formItem.type === 'text'">
<el-input v-model="formData[formItem.prop]" /> <el-input v-model="formData[formItem.prop]" />
</template> </template>
<template v-if="formItem.type === 'select'"> <template v-else-if="formItem.type === 'select'">
<el-select v-model="formData[formItem.prop]" size="large" style="width: 240px"> <el-select v-model="formData[formItem.prop]" size="large" style="width: 240px">
<el-option v-for="item in formItem.tableDisplay" :key="item.value" :label="item.label" <el-option v-for="item in formItem.option" :key="item.value" :label="item.label" :value="item.value" />
:value="item.value" />
</el-select> </el-select>
</template> </template>
<template v-else-if="formItem.type === 'number'"> <template v-else-if="formItem.type === 'number'">
@ -30,13 +30,27 @@
:disabled="['create_at', 'update_at'].indexOf(formItem.prop) !== -1" :disabled="['create_at', 'update_at'].indexOf(formItem.prop) !== -1"
:placeholder="`请选择${formItem.label}`" /> :placeholder="`请选择${formItem.label}`" />
</template> </template>
<template v-else-if="formItem.type === 'file'">
<el-upload :show-file-list="true" v-model:file-list="formData[formItem.prop]"
:before-upload="beforeAvatarUpload" :on-change="(file, files) => successSubmit(file, files, formItem)"
:on-remove="(file, files) => successSubmit(file, files, formItem)"
accept=".doc,.docx,.jpg,.mp4,.pdf,.png,.xls,.xlsx," :multiple="formData[`${formItem.prop}Limit`] > 1"
:auto-upload="false" :limit="formData[`${formItem.prop}Limit`]">
<el-button type="success">
<el-icon>
<Upload />
</el-icon>
<span>选择文件</span>
</el-button>
</el-upload>
</template>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</template> </template>
<script> <script>
import _, { max, min } from 'lodash' import _ from 'lodash'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
export default { export default {
@ -70,7 +84,51 @@ export default {
} }
}, },
methods: {}, methods: {
/**
* 上传表格检查
*/
beforeAvatarUpload(rawFile) {
let imgList = [
'application/msword',//doc
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',//docx
"image/jpeg",//jpg
"video/mp4",//mp4
"application/pdf",//pdf
"image/png",//png
"application/vnd.ms-excel",//xls
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",//xlsx
]
if (imgList.indexOf(rawFile.type) === -1) {
this.$msgbox.alert('请上传doc,docx,jpg,mp4,pdf,png,xls,xlsx格式的表格文件!')
return false
} else if (rawFile.size / 1024 / 1024 / 1024 > 10) {
this.$msgbox.alert('表格文件的大小为小于10GB,数据过多时会处理过慢')
return true
}
return true
},
async successSubmit(file, files, formItem) {
let fileList = []
// if (this.formData[`${formItem.prop}Limit`] < files.length) {
// ElMessage({
// message: `${formItem.label}${this.formData[formItem.prop + 'Limit']} ${this.formData[formItem.prop + 'Limit']}`,
// type: "warning"
// })
// }
for (let i = 0; i < files.length; i++) {
let fileItem = files[i];
fileList.push({
name: fileItem.raw.name,
prePath: fileItem.raw.path,
type: fileItem.raw.type,
size: fileItem.raw.size,
})
}
this.formData[formItem.prop] = fileList
},
},
async mounted() { }, async mounted() { },
watch: {}, watch: {},
computed: {} computed: {}

52
src/renderer/src/components/tablecomponent.vue

@ -19,34 +19,38 @@
<template v-else-if="headerItem.type === 'date'"> <template v-else-if="headerItem.type === 'date'">
<span>{{ row[headerItem.prop] }}</span> <span>{{ row[headerItem.prop] }}</span>
</template> </template>
<template v-else-if="headerItem.type === 'size'">
<span>{{ genSize(row[headerItem.prop]) }}</span>
</template>
<template v-else>{{ row[headerItem.prop] }}</template> <template v-else>{{ row[headerItem.prop] }}</template>
</template> </template>
</vxe-column> </vxe-column>
</template> </template>
<vxe-column fixed="right" title="操作" width="145"> <vxe-column fixed="right" title="操作" width="200">
<template #default="{ row }"> <template #default="{ row }">
<el-button type="primary" text @click="optClick(row, 'view')"> <el-button type="primary" text @click="optClick(row, 'view')" size="small" style="padding: 5px;">
<el-icon> <!-- <el-icon>
<View /> <View />
</el-icon> </el-icon> -->
<span>预览</span> <span>预览</span>
</el-button> </el-button>
<el-button type="primary" text @click="optClick(row, 'edit')"> <el-button type="primary" text @click="optClick(row, 'edit')" size="small" style="padding: 5px;">
<el-icon> <!-- <el-icon>
<EditPen /> <EditPen />
</el-icon> </el-icon> -->
<span>修改</span> <span>修改</span>
</el-button> </el-button>
<el-button type="primary" text @click="optClick(row, 'unregister')"> <el-button :type="row.status === '正常' ? 'primary' : 'success'" text @click="optClick(row, 'unregister')"
<el-icon> size="small" style="padding: 5px;">
<!-- <el-icon>
<Delete /> <Delete />
</el-icon> </el-icon> -->
<span>注销</span> <span>{{ row.status === "正常" ? "注销" : "正常" }}</span>
</el-button> </el-button>
<el-button type="primary" text @click="optClick(row, 'download')"> <el-button type="primary" text @click="optClick(row, 'download')" size="small" style="padding: 5px;">
<el-icon> <!-- <el-icon>
<Download /> <Download />
</el-icon> </el-icon> -->
<span>下载</span> <span>下载</span>
</el-button> </el-button>
</template> </template>
@ -89,6 +93,26 @@ export default {
optClick(row, type) { optClick(row, type) {
this.$emit(type, row) this.$emit(type, row)
}, },
genSize(num) {
//
if (_.isNaN(Number(num))) {
return "";
}
let bytes = Number(num);
if (bytes >= 1024 ** 4) {
return `${(bytes / 1024 ** 4).toFixed(2)}TB`;
}
if (bytes >= 1024 ** 3) {
return `${(bytes / 1024 ** 3).toFixed(2)}GB`;
}
if (bytes >= 1024 ** 2) {
return `${(bytes / 1024 ** 2).toFixed(2)}MB`;
}
if (bytes >= 1024) {
return `${(bytes / 1024).toFixed(2)}KB`;
}
return `${bytes}B`;
}
}, },
async mounted() { }, async mounted() { },
watch: {}, watch: {},

14
src/renderer/src/components/treecomponent.vue

@ -5,13 +5,14 @@
<el-tree-v2 :data="treeData" :props="treeProps" class="bgColor" @node-click="nodeClick" ref="treeRef" <el-tree-v2 :data="treeData" :props="treeProps" class="bgColor" @node-click="nodeClick" ref="treeRef"
:height="height" :expand-on-click-node="false"> :height="height" :expand-on-click-node="false">
<template #default="{ node }"> <template #default="{ node }">
<div style="width: 100%;text-align-last:left;"> <div style="width: 100%;text-align-last:left;" :class="node.data.id === nodeClickId ? 'selectedNode' : ''">
<el-tooltip effect="dark" :content="node.label" placement="right" v-if="node.label.length > textLength"> <el-tooltip effect="dark" :content="node.label" placement="right" v-if="node.label.length > textLength">
<span>{{ node.label.slice(0, textLength) }}</span> <span>{{ node.label.slice(0, textLength) }}</span>
</el-tooltip> </el-tooltip>
<span v-else>{{ node.label }}</span> <span v-else>{{ node.label }}</span>
<span style="position: absolute;right: 8px;" v-if="node.level === 1"> <span style="position: absolute;right: 8px;" v-if="node.level === 1">
<el-button type="primary" link @click="e => editxiangmu(e, node)"> <el-button :type="node.data.id === nodeClickId ? 'success' : 'primary'" link
@click="e => editxiangmu(e, node)">
编辑 编辑
</el-button> </el-button>
<el-button type="danger" link @click="e => delxiangmu(e, node)"> <el-button type="danger" link @click="e => delxiangmu(e, node)">
@ -76,10 +77,13 @@ export default {
_: _, _: _,
dayjs: dayjs, dayjs: dayjs,
textLength: 20, textLength: 20,
nodeClickId: ""
} }
}, },
methods: { methods: {
nodeClick(node) { nodeClick(node) {
console.log(84, node);
this.nodeClickId = node.id
this.$emit("nodeClick", node) this.$emit("nodeClick", node)
}, },
setChecked() { setChecked() {
@ -112,4 +116,10 @@ export default {
background-color: #ccc; background-color: #ccc;
border-radius: 8px; border-radius: 8px;
} }
.selectedNode {
background-color: #409eff;
color: #fff;
border-radius: 8px;
}
</style> </style>

618
src/renderer/src/views/dangan.vue

@ -8,7 +8,7 @@
<template #prepend>项目名</template> <template #prepend>项目名</template>
</el-input> </el-input>
</div> </div>
<el-button type="primary" @click="searchTree"> <el-button type="primary" @click="clearAndSearchTree">
<el-icon> <el-icon>
<Search /> <Search />
</el-icon> </el-icon>
@ -60,7 +60,7 @@
<div style="margin-bottom: 8px;"> <div style="margin-bottom: 8px;">
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="4"> <el-col :span="4">
<el-button type="primary" plain @click="addFile"> <el-button type="primary" plain @click="addFile" :disabled="_.get(treeNode, 'level') !== 3">
<el-icon> <el-icon>
<Plus /> <Plus />
</el-icon> </el-icon>
@ -68,12 +68,12 @@
</el-button> </el-button>
</el-col> </el-col>
<el-col :span="10"> <el-col :span="10">
<el-input v-model="xiangmuObj.xianmguName" style="width: 100%;" placeholder="请输入文件名" clearable> <el-input v-model="wenjianObj.wenjianName" style="width: 100%;" placeholder="请输入文件名" clearable>
<template #prepend>文件名</template> <template #prepend>文件名</template>
</el-input> </el-input>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<el-button type="primary" @click="searchFile"> <el-button type="primary" @click="searchTable">
<el-icon> <el-icon>
<Search /> <Search />
</el-icon> </el-icon>
@ -122,7 +122,6 @@
<script> <script>
import _ from 'lodash' import _ from 'lodash'
import * as XLSX from 'xlsx';
import { v5 } from "uuid"; import { v5 } from "uuid";
import tableHeaderLocal from '../assets/json/file.json' import tableHeaderLocal from '../assets/json/file.json'
import { myDatabase } from '../assets/js/db.js' import { myDatabase } from '../assets/js/db.js'
@ -132,11 +131,21 @@ import treecomponent from "../components/treecomponent.vue"
import formcomponent from "../components/formcomponent.vue" import formcomponent from "../components/formcomponent.vue"
import viewcomponent from "../components/viewcomponent.vue" import viewcomponent from "../components/viewcomponent.vue"
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { refresh } from 'less';
export default { export default {
name: 'dangan', name: 'dangan',
components: { tablecomponent, formcomponent, treecomponent, viewcomponent }, components: { tablecomponent, formcomponent, treecomponent, viewcomponent },
watch: {}, watch: {
"wenjianObj.fileType": {
handler(newValue, oldValue) {
this.searchTable()
}
},
"wenjianObj.status": {
handler(newValue, oldValue) {
this.searchTable()
}
}
},
computed: {}, computed: {},
data() { data() {
return { return {
@ -149,7 +158,6 @@ export default {
wenjianName: "", wenjianName: "",
fileType: "", fileType: "",
status: "", status: "",
parentId: "",
}, },
fileList: [ fileList: [
{ {
@ -158,35 +166,35 @@ export default {
}, },
{ {
label: "doc", label: "doc",
value: "doc" value: "application/msword"
}, },
{ {
label: "docx", label: "docx",
value: "docx" value: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}, },
{ {
label: "jpg", label: "jpg",
value: "jpg" value: "image/jpeg"
}, },
{ {
label: "mp4", label: "mp4",
value: "mp4" value: "video/mp4"
}, },
{ {
label: "pdf", label: "pdf",
value: "pdf" value: "application/pdf"
}, },
{ {
label: "png", label: "png",
value: "png" value: "image/png"
}, },
{ {
label: "xls", label: "xls",
value: "xls" value: "application/vnd.ms-excel"
}, },
{ {
label: "xlsx", label: "xlsx",
value: "xlsx" value: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}, },
], ],
statusList: [ statusList: [
@ -200,13 +208,13 @@ export default {
label: "正常", label: "正常",
color: "#67c23a", color: "#67c23a",
class: "normalClass", class: "normalClass",
value: "normal" value: "正常"
}, },
{ {
label: "注销", label: "注销",
color: "#f56c6c", color: "#f56c6c",
class: "unregisterClass", class: "unregisterClass",
value: "unregister" value: "注销"
}, },
], ],
level1: [], level1: [],
@ -237,26 +245,37 @@ export default {
formHeader: [], formHeader: [],
formData: {} formData: {}
}, },
treeNode: {},
preNode: {},
preFile: {},
uuidNameSpace: "8268af6b-7ef5-5d6d-a489-2d641dfb53bb", uuidNameSpace: "8268af6b-7ef5-5d6d-a489-2d641dfb53bb",
preNodeTemp: {},
treeLoading: false, treeLoading: false,
tableLoading: false, tableLoading: false,
} }
}, },
methods: { methods: {
//
clearAndSearchTree() {
this.treeNode = {}
this.$refs.treeComponentRef.nodeClickId = ""
this.searchTree()
},
//() //()
async searchTree() { async searchTree() {
this.treeLoading = true this.treeLoading = true
let collection = myDatabase.treeList let collection = myDatabase.treeList
let xianmguName = _.trim(this.xiangmuObj.xianmguName) let xianmguName = _.trim(this.xiangmuObj.xianmguName)
collection = collection.filter((equip) => equip.delete === false)
if (xianmguName) { if (xianmguName) {
let reg = new RegExp(xianmguName, "i") let reg = new RegExp(xianmguName, "i")
collection = collection.filter((equip) => reg.test(equip.label)) collection = collection.filter((equip) => reg.test(equip.label))
} }
// jujinnianxian // jujinnianxian
let res = await collection.toArray(); let res = await collection.toArray();
let level1List = _.filter(res, { level: 1, prepreId: "", preId: "", }) let level1List = _.filter(res, { level: 1, prepreId: "", preId: "", delete: false, })
let level2List = _.filter(res, { level: 2, prepreId: "", }) let level2List = _.filter(res, { level: 2, prepreId: "", delete: false, })
let level3List = _.filter(res, { level: 3 }) let level3List = _.filter(res, { level: 3, delete: false, })
this.treeLoading = false this.treeLoading = false
let treeList = [] let treeList = []
for (let i = 0; i < level1List.length; i++) { for (let i = 0; i < level1List.length; i++) {
@ -271,22 +290,60 @@ export default {
let level3Item = level3ListTemp[l]; let level3Item = level3ListTemp[l];
level2Children.push({ level2Children.push({
...level3Item, ...level3Item,
id: level3Item.currentId, check: false,
}) })
} }
level1Children.push({ level1Children.push({
...level2Item, ...level2Item,
id: level2Item.currentId, children: level2Children,
children: level2Children check: false,
}) })
} }
treeList.push({ treeList.push({
...level1Item, ...level1Item,
id: level1Item.currentId, children: level1Children,
children: level1Children check: false,
}) })
} }
this.treeData = treeList this.treeData = treeList
await this.searchTable()
},
//()
async searchTable() {
this.tableLoading = true
let collection = myDatabase.fileList
if (!_.isEmpty(this.treeNode)) {
if (this.treeNode.level === 1) {
collection = collection.filter((equip) => equip.prepretreeId === this.treeNode.currentId)
} else if (this.treeNode.level === 2) {
collection = collection.filter((equip) => equip.pretreeId === this.treeNode.currentId)
} else if (this.treeNode.level === 3) {
collection = collection.filter((equip) => equip.treeId === this.treeNode.currentId)
}
} else {
let fileCurrentIdList = []
for (let i = 0; i < this.treeData.length; i++) {
let treeItem = this.treeData[i];
fileCurrentIdList.push(treeItem.currentId)
}
collection = collection.filter((equip) => fileCurrentIdList.includes(equip.prepretreeId))
}
if (!_.isEmpty(this.wenjianObj)) {
let wenjianName = _.trim(this.wenjianObj.wenjianName)
if (wenjianName) {
collection = collection.filter((equip) => equip.fileName.includes(wenjianName))
}
if (this.wenjianObj.fileType) {
collection = collection.filter((equip) => equip.fileType === this.wenjianObj.fileType)
}
if (this.wenjianObj.status) {
collection = collection.filter((equip) => equip.status === this.wenjianObj.status)
}
}
// jujinnianxian
let res = await collection.toArray();
this.tableLoading = false
this.tableData = res
}, },
//() //()
async addxiangmu() { async addxiangmu() {
@ -314,15 +371,81 @@ export default {
}, },
//() //()
async editxiangmu(node) { async editxiangmu(node) {
console.log(265, node); this.preNode = _.cloneDeep(node)
this.adddanganForm = {
visible: true,
title: `编辑${node.label}`,
disabled: false,
type: "put",
formHeader: [
{
label: "项目名称",
prop: "xianmguName",
type: "text",
placeholder: "请输入项目名称",
required: true,
rules: [
{ required: true, message: "请输入项目名称", trigger: "blur" }
]
}
],
formData: {
xianmguName: node.label
}
}
}, },
//() //()
async delxiangmu(node) { async delxiangmu(node) {
console.log(269, node); ElMessageBox.confirm(
`是否删除(${node.label})项目?同时删除项目时将删除下面的文件夹及文件?`,
'danger',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'danger',
}
)
.then(async () => {
let idList = []
//
idList.push(node.data.id)
let fileIdList = []
for (let i = 0; i < node.data.children.length; i++) {
let level2Item = node.data.children[i];
idList.push(level2Item.id)
for (let j = 0; j < level2Item.children.length; j++) {
let level3Item = level2Item.children[j];
fileIdList.push(level3Item.currentId)
idList.push(level3Item.id)
}
}
//
await myDatabase.treeList.bulkDelete(idList)
window.electron.ipcRenderer.send('delFloder', JSON.stringify({ name: node.label }))
// id
let delfiltIdList = []
let fileCollection = myDatabase.fileList
fileCollection = fileCollection.filter((equip) => fileIdList.includes(equip.treeId))
let delfiltList = await collection.toArray();
for (let i = 0; i < delfiltList.length; i++) {
let fileItem = delfiltList[i];
delfiltIdList.push(fileItem.id)
}
await myDatabase.fileList.bulkDelete(delfiltIdList)
await this.searchTree()
await this.searchTable()
})
.catch((e) => {
ElMessage({
type: 'info',
message: `取消删除(${node.label})项目`,
})
})
}, },
// //
async nodeClick(node) { async nodeClick(node) {
console.log(273, node); this.treeNode = _.cloneDeep(node)
this.searchTable()
}, },
//() //()
async exportData(params = {}, isAll = false) { async exportData(params = {}, isAll = false) {
@ -330,51 +453,89 @@ export default {
}, },
// //
async addFile() { async addFile() {
if (_.get(this.treeNode, 'level') !== 3) {
ElMessage({
message: '请选择项目',
type: 'warning'
})
} else {
let pathList = _.compact(_.split(this.treeNode.path, '\\'))
this.addFileForm = { this.addFileForm = {
visible: true, visible: true,
title: "新增文件", title: `文件路径:E:\\${_.get(this.treeNode, 'path')}`,
disabled: false, disabled: false,
type: "add", type: "add",
formHeader: [ formHeader: this.formHeader,
{
label: "项目名称",
prop: "xianmguName",
type: "text",
placeholder: "请输入项目名称",
required: true,
rules: [
{ required: true, message: "请输入项目名称", trigger: "blur" }
]
}
],
formData: { formData: {
xianmguName: "" xiangmuName: `${_.trim(pathList[0])}`,
juanName: `${_.trim(pathList[1])}`,
fileName: "",
fileLimit: 10000,
file: [],
fileType: "",
uploadTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
status: "正常",
path: "",
note: "",
create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
} }
} }
},
//
async searchFile(params = {}, isAll = false) {
}, },
// //
async refresh(params = {}, isAll = false) { async refresh() {
this.treeNode = {}
await this.searchTable()
}, },
// //
async viewFile(params = {}, isAll = false) { async viewFile(row) {
//
window.electron.ipcRenderer.send('openFile', row.path)
}, },
// //
async editFile(params = {}, isAll = false) { async editFile(row) {
this.addFileForm = {
visible: true,
title: `编辑文件:E:\\test\\${row.xiangmuName}\\${_.join(_.split(row.juanName, "_"), "\\")}\\${row.fileName}`,
disabled: false,
type: "put",
formHeader: this.formHeader,
formData: {
id: row.id,
treeId: row.treeId,
pretreeId: row.pretreeId,
prepretreeId: row.prepretreeId,
xiangmuName: row.xiangmuName,
juanName: row.juanName,
fileName: row.fileName,
fileLimit: 1,
file: [
{
name: row.fileName,
url: `E:\\test\\${row.xiangmuName}\\${_.join(_.split(row.juanName, "_"), "\\")}\\${row.fileName}`,
}
],
fileType: row.fileType,
uploadTime: row.uploadTime,
status: row.status,
path: row.path,
note: row.note,
create_at: row.create_at,
}
}
}, },
// //
async unregisterFile(params = {}, isAll = false) { async unregisterFile(row) {
let org = row.status
row.status = org === "注销" ? "正常" : "注销"
await myDatabase.fileList.put({ ...row })
await this.searchTable()
}, },
// //
async downloadFile(params = {}, isAll = false) { async downloadFile(row) {
//
window.electron.ipcRenderer.send('downloadFile', row.path)
}, },
// //
canceldanganDialog() { canceldanganDialog() {
@ -387,10 +548,23 @@ export default {
} }
}, },
// //
async submitdanganDialog() { async submitdanganDialog() {
let treeList = []
let xianmguName = _.trim(this.adddanganForm.formData.xianmguName) let xianmguName = _.trim(this.adddanganForm.formData.xianmguName)
let collection = myDatabase.treeList
collection = collection.filter((equip) => equip.level === 1 && equip.label === xianmguName)
// jujinnianxian
let ishasXiangmu = await collection.toArray();
if (ishasXiangmu.length > 0) {
ElMessage({
message: '项目已存在,请输入不同的项目名',
type: 'warning'
})
return
}
if (this.adddanganForm.type === "add") {
let treeList = []
let pathList = []
if (xianmguName) { if (xianmguName) {
let firstId = v5(xianmguName, this.uuidNameSpace) let firstId = v5(xianmguName, this.uuidNameSpace)
for (let i = 0; i < this.level2.length; i++) { for (let i = 0; i < this.level2.length; i++) {
@ -401,20 +575,24 @@ export default {
let level3Item = this.level3[level2Item][j]; let level3Item = this.level3[level2Item][j];
let level3Str = `${xianmguName}${level2Item}${level3Item}` let level3Str = `${xianmguName}${level2Item}${level3Item}`
let level3uuid = v5(level3Str, this.uuidNameSpace) let level3uuid = v5(level3Str, this.uuidNameSpace)
// ++id, label, currentId, preId, prepreId, level, note, create_at, update_at
treeList.push({ treeList.push({
label: level3Item, label: level3Item,
currentId: level3uuid, currentId: level3uuid,
path: `${xianmguName}\\${level2Item}\\${level3Item}`,
delete: false,
preId: level2uuid, preId: level2uuid,
prepreId: firstId, prepreId: firstId,
level: 3, level: 3,
create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}) })
pathList.push(`${xianmguName}\\${level2Item}\\${level3Item}`)
} }
treeList.push({ treeList.push({
label: level2Item, label: level2Item,
currentId: level2uuid, currentId: level2uuid,
path: `${xianmguName}\\${level2Item}`,
delete: false,
preId: firstId, preId: firstId,
prepreId: "", prepreId: "",
level: 2, level: 2,
@ -425,6 +603,8 @@ export default {
treeList.push({ treeList.push({
label: xianmguName, label: xianmguName,
currentId: firstId, currentId: firstId,
path: `${xianmguName}`,
delete: false,
preId: "", preId: "",
prepreId: "", prepreId: "",
level: 1, level: 1,
@ -435,8 +615,10 @@ export default {
try { try {
await myDatabase.treeList.bulkAdd(treeList) await myDatabase.treeList.bulkAdd(treeList)
this.canceldanganDialog() this.canceldanganDialog()
pathList = _.uniq(pathList)
console.log(619, pathList, JSON.stringify(pathList));
// d // d
window.electron.ipcRenderer.send('createFloder', JSON.stringify(pathList))
await this.searchTree() await this.searchTree()
} catch (error) { } catch (error) {
ElMessage({ ElMessage({
@ -444,6 +626,77 @@ export default {
type: 'error', type: 'error',
}) })
} }
} else if (this.adddanganForm.type === "put") {
let preNodeTemp = _.cloneDeep(this.preNode.data)
this.preNodeTemp = _.cloneDeep(this.preNode.data)
if (xianmguName) {
for (let i = 0; i < preNodeTemp.children.length; i++) {
let level2Item = preNodeTemp.children[i];
console.log(635, level2Item);
for (let j = 0; j < level2Item.children.length; j++) {
let level3Item = level2Item.children[j];
let level3ItemTemp = {
id: level3Item.id,
label: level3Item.label,
currentId: level3Item.currentId,
path: `${xianmguName}\\${level2Item.label}\\${level3Item.label}`,
delete: false,
preId: level3Item.preId,
prepreId: level3Item.prepreId,
level: 3,
create_at: level3Item.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level3ItemTemp })
}
let level2ItemTemp = {
id: level2Item.id,
label: level2Item.label,
currentId: level2Item.currentId,
path: `${xianmguName}\\${level2Item.label}`,
delete: false,
preId: level2Item.preId,
prepreId: "",
level: 2,
create_at: level2Item.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level2ItemTemp })
}
let level1ItemTemp = {
id: preNodeTemp.id,
label: xianmguName,
currentId: preNodeTemp.currentId,
path: `${xianmguName}`,
delete: false,
preId: "",
prepreId: "",
level: 1,
create_at: preNodeTemp.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level1ItemTemp })
} else {
ElMessage({
message: '请输入新的项目名称',
type: 'warning'
})
return
}
try {
// E
let params = { oldPath: preNodeTemp.label, newPath: xianmguName }
console.log(688, params);
window.electron.ipcRenderer.send('putFloder', JSON.stringify(params))
await this.searchTree()
} catch (error) {
ElMessage({
message: `${error}`,
type: 'error',
})
}
this.canceldanganDialog()
}
}, },
// //
cancelFileDialog() { cancelFileDialog() {
@ -459,42 +712,229 @@ export default {
// //
async submitFileDialog() { async submitFileDialog() {
if (this.addFileForm.type === "add") {
let fileList = _.cloneDeep(this.addFileForm.formData.file)
let tableList = []
let filePathList = _.split(this.treeNode.path, "\\")
for (let i = 0; i < fileList.length; i++) {
let fileItem = fileList[i];
tableList.push({
treeId: this.treeNode.currentId,
pretreeId: this.treeNode.preId,
prepretreeId: this.treeNode.prepreId,
xiangmuName: filePathList[0],
juanName: `${filePathList[1]}_${filePathList[2]}`,
fileName: fileItem.raw.name,
fileType: fileItem.raw.type,
uploadTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
status: "正常",
size: fileItem.raw.size,
path: `${this.treeNode.path}\\${fileItem.raw.name}`,
prePath: fileItem.raw.path,
note: this.addFileForm.formData.note,
create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
})
}
await myDatabase.fileList.bulkAdd(tableList)
window.electron.ipcRenderer.send('createFile', JSON.stringify(tableList))
} else if (this.addFileForm.type === "put") {
let formData = _.cloneDeep(this.addFileForm.formData)
let pathArr = _.split(formData.path, "\\")
console.log(744, pathArr);
let fileItem = {
id: formData.id,
treeId: formData.treeId,
pretreeId: formData.pretreeId,
prepretreeId: formData.prepretreeId,
xiangmuName: formData.xiangmuName,
juanName: formData.juanName,
fileName: formData.file[0].raw.name,
fileType: formData.file[0].raw.type,
uploadTime: formData.uploadTime,
status: formData.status,
size: formData.file[0].raw.size,
path: `${_.join(pathArr.splice(0, pathArr.length - 1), "\\")}\\${formData.file[0].name}`,
prePath: formData.file[0].raw.path,
note: formData.note,
create_at: formData.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.fileList.put({ ...fileItem })
}
await this.searchTable()
this.cancelFileDialog()
},
//
watchApi() {
let that = this
//
window.electron.ipcRenderer.on('createFloderResult', (eve, res) => {
let resObj = JSON.parse(res)
if (resObj.errorList.length) {
ElMessage({
message: `文件夹${resObj.errorList.join(",")}创建失败`,
type: 'error',
})
} else {
// resObj.successList[0].split("\\")[0]
ElMessage({
message: `项目(${_.split(resObj.successList[0], "\\")[0]})新增成功`,
type: 'success',
})
that.searchTree()
}
})
//
window.electron.ipcRenderer.on('putFloderResult', async (eve, res) => {
let resObj = JSON.parse(res)
let preNodeTemp = _.cloneDeep(that.preNodeTemp)
console.log(788, resObj, preNodeTemp);
if (resObj.errorList.length) {
ElMessage({
message: `文件夹${resObj.errorList[0].oldPath}修改为${resObj.errorList[0].newPath},修改失败`,
type: 'error',
})
for (let i = 0; i < preNodeTemp.children.length; i++) {
let level2Item = preNodeTemp.children[i];
for (let j = 0; j < level2Item.children.length; j++) {
let level3Item = level2Item.children[j];
let level3ItemTemp = {
id: level3Item.id,
label: level3Item.label,
currentId: level3Item.currentId,
path: `${resObj.errorList[0].oldPath}\\${level2Item}\\${level3Item}`,
delete: false,
preId: level3Item.preId,
prepreId: level3Item.prepreId,
level: 3,
create_at: level3Item.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level3ItemTemp })
}
let level2ItemTemp = {
id: level2Item.id,
label: level2Item.label,
currentId: level2Item.currentId,
path: `${resObj.errorList[0].oldPath}\\${level2Item.label}`,
delete: false,
preId: level2Item.preId,
prepreId: "",
level: 2,
create_at: level2Item.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level2ItemTemp })
}
let level1ItemTemp = {
id: preNodeTemp.id,
label: resObj.errorList[0].oldPath,
currentId: preNodeTemp.currentId,
path: `${resObj.errorList[0].oldPath}`,
delete: false,
preId: "",
prepreId: "",
level: 1,
create_at: preNodeTemp.create_at,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.treeList.put({ ...level1ItemTemp })
} else {
// resObj.successList[0].split("\\")[0]
ElMessage({
message: `文件夹${resObj.successList[0].oldPath}修改为${resObj.successList[0].newPath},修改成功`,
type: 'success',
})
that.searchTree()
//
let collection = myDatabase.fileList
collection = collection.filter((equip) => _.startsWith(equip.path, `${preNodeTemp.label}\\`))
let fileList = await collection.toArray()
for (let index = 0; index < fileList.length; index++) {
let fileItem = fileList[index];
let fileParmas = {
...fileItem,
path: fileItem.path.replace(preNodeTemp.label, resObj.successList[0].newPath),
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
await myDatabase.fileList.put({ ...fileParmas })
}
}
await that.searchTree()
})
//
window.electron.ipcRenderer.on('delFloderResult', (eve, res) => {
let resObj = JSON.parse(res)
if (resObj.errorList.length) {
ElMessage({
message: `文件夹${resObj.errorList[0].name}删除失败`,
type: 'error',
})
} else {
ElMessage({
message: `文件夹${resObj.successList[0].name}删除成功`,
type: 'success',
})
that.searchTree()
}
})
//
window.electron.ipcRenderer.on('createFileResult', (eve, res) => {
let resObj = JSON.parse(res)
if (resObj.errorList.length) {
let errorList = []
for (let i = 0; i < resObj.errorList.length; i++) {
let element = resObj.errorList[i];
errorList.push(element.fileName)
}
ElMessage({
message: `${resObj.errorList[0].xiangmuName}项目下${resObj.errorList[0].juanName}卷下新增文件${_.join(errorList, ",")}失败`,
type: 'error',
})
} else {
let successList = []
for (let i = 0; i < resObj.successList.length; i++) {
let element = resObj.successList[i];
successList.push(element.fileName)
}
ElMessage({
message: `${resObj.successList[0].xiangmuName}项目下${resObj.successList[0].juanName}卷下新增文件${_.join(successList, ",")}成功`,
type: 'success',
})
that.searchTable()
}
})
//
window.electron.ipcRenderer.on('downloadFileResult', async (eve, result) => {
if (!result.success) {
ElMessage({
message: `文件下载失败${result.error}`,
type: 'error',
});
return;
}
let data = result.data;
let blob = new Blob([data], { type: 'application/octet-stream' });
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = result.path.split('\\').pop(); // 使
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
})
}, },
//
// async submitDialog() {
// for (let i = 0; i < this.formHeader.length; i++) {
// let headItem = this.formHeader[i];
// if (headItem.type === "date") {
// this.adddanganForm.formData[headItem.prop] = dayjs(this.adddanganForm.formData[headItem.prop]).format("YYYY-MM-DD")
// }
// }
// let params = {
// ...this.adddanganForm.formData, ...this.dealRow(this.adddanganForm.formData), create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
// }
// if (this.adddanganForm.type === "put") {
// delete params.create_at
// }
// try {
// await myDatabase.student[this.adddanganForm.type]({ ...params, update_at: dayjs().format('YYYY-MM-DD HH:mm:ss') })
// await this.searchData()
// this.cancelDialog()
// } catch (e) {
// ElMessage(
// {
// type: "error",
// message: ""
// }
// )
// }
// },
}, },
async mounted() { async mounted() {
this.tableHeader = _.filter(tableHeaderLocal, o => o.tableShow) this.tableHeader = _.filter(tableHeaderLocal, o => o.tableShow)
this.formHeader = _.filter(tableHeaderLocal, o => o.formShow) this.formHeader = _.filter(tableHeaderLocal, o => o.formShow)
this.exportHeader = _.filter(tableHeaderLocal, o => o.export) this.exportHeader = _.filter(tableHeaderLocal, o => o.export)
this.searchTree() this.searchTree()
this.searchTable()
this.watchApi()
}, },
} }
</script> </script>

Loading…
Cancel
Save