提交 23d555ab authored 作者: caicai's avatar caicai

新增分类

上级 0a81fbe8
......@@ -3,6 +3,7 @@ import { saveJson } from '@/libs/utils/backfunction.js';
const fs = require('fs');
const { exec, execSync } = require('child_process');
import SoftList from '../plugins/softList';
import categoryPlugin from '../plugins/category';
class IpcEvents {
create (appManager) {
......@@ -11,6 +12,7 @@ class IpcEvents {
this.win = this.windowManager.mainWindow.win;
this.store = this.windowManager.mainWindow.store;
this.softList = new SoftList(this.windowManager.mainWindow)
this.categoryPlugin = new categoryPlugin(this.windowManager.mainWindow)
/* 翻译器函数
Translator function */
......@@ -282,49 +284,7 @@ class IpcEvents {
// console.log(`Is always on top: ${isAlwaysOnTop}`);
// ```
})
/**
* linux
* 获取当前正在运行的应用
* 获取系统进程信息
*
可以使用以下命令获取系统当前运行的应用:
1. 使用 top 命令查看系统进程信息:
```
top
```
2. 使用 ps 命令查看系统进程信息:
```
ps -ef
```
3. 使用 htop 命令查看系统进程信息:
```
htop
```
4. 使用 lsof 命令查看系统打开的文件和进程信息:
```
lsof
```
5. 使用 netstat 命令查看系统网络连接信息:
```
netstat -an
```
6. 使用 ss 命令查看系统网络连接信息:
```
ss -an
```
*/
ipcMain.on("getRunApp", (e, data) => {
const { exec } = require('child_process');
exec('ps -eo pid,comm', (err, stdout, stderr) => {
......@@ -352,6 +312,23 @@ class IpcEvents {
});
});
})
/* 获取分类列表 */
ipcMain.on("getCategoryList", (e, data) => {
let list = this.categoryPlugin.getList();
e.sender.send("category-list", list);
})
// 软件加入某个分类
ipcMain.on("changeCategory", (e, data) => {
this.categoryPlugin.softChangeCategory({soft:data.soft, category:data.category, sender:e.sender})
// e.sender.send("category-list", list);
})
ipcMain.on("addCategory", (e, data) => {
this.categoryPlugin.addCategory({name:data, sender:e.sender})
// e.sender.send("category-list", list);
})
}
}
......
class category {
constructor (mainWindow) {
this.mainWindow = mainWindow;
this.store = this.mainWindow.store;
}
// 重置列表
resetList() {
this.store.set('category',[
{
name:'备课资源',
id:'bk001',
softIds:[], //当前分类下的软件
},
{
name:'教学工具',
id:'jx002',
softIds:[],
},
{
name:'课后练习',
id:'kh003',
softIds:[],
},
{
name:'教务管理',
id:'jw004',
softIds:[],
},
]);
}
/* 获取分类列表 */
getList () {
// console.log('获取分类列表')
this.mainWindow.win.webContents.send('getMsg', '获取分类列表-mainprocess')
let categoryList = this.store.get('category');
// this.mainWindow.win.webContents.send("categoryList", categoryList);
return categoryList;
}
/* 新增分类 */
addCategory({name, sender}) {
if(name == undefined) return;
let categoryList = this.store.get('category');
name = name.trim();
let hasIn = categoryList.findIndex(v => v.name == name);
if(hasIn != -1) return;
let category = {
name,
id: this.genID(8),
softIds:[]
};
categoryList.unshift(category);
this.store.set('category', categoryList);
sender.send("add-category", category);
this.mainWindow.win.webContents.send("add-category", category);
}
// 获取分类详情
getCategory(id) {
let categoryList = this.store.get('category');
let hasIn = categoryList.findIndex(v => v.id == id);
if(hasIn == -1) return null;
return categoryList[hasIn]
}
/* 更新分类列表 */
updateCategory({id, detail, sender}) {
let categoryList = this.store.get('category');
let hasIn = categoryList.findIndex(v => v.id == id);
console.log('hasIn', hasIn)
if(hasIn == -1) return null;
categoryList[hasIn] = detail;
this.store.set('category', categoryList);
sender.send('change-category',{detail,id});
this.mainWindow.win.webContents.send('getMsg', categoryList)
}
/* 软件改变所属分类、加入到某个分类 */
softChangeCategory({soft,category, sender}) {
let softId = soft.id;
let categoryId = category.id;
if(!softId || !categoryId) return;
let cateDetail = this.getCategory(categoryId);
let hasIn = cateDetail.softIds.includes(softId);
// 已经属于当前分类
if(hasIn) return;
cateDetail.softList = [];
cateDetail.softIds.unshift(softId);
cateDetail.softIds.forEach(v => {
let softD = this.getSoftDetail(v);
if(softD) cateDetail.softList.push(softD);
});
// 更新分类列表
console.log('修改分类',cateDetail,categoryId)
this.updateCategory({detail:cateDetail, id: categoryId, sender})
}
getSoftDetail(softId) {
let appList = this.store.get('apps');
let targetIndex = appList.findIndex(v => v.id == softId);
if(targetIndex==-1) return null;
return appList[targetIndex];
}
/* 获取某个分类下的软件列表 */
getSoftListOf(cateId) {
let softList = [];
let cateDetail = this.getCategory(cateId);
let softDeatil = null;
cateDetail.softIds.forEach(v => {
softDeatil = this.getSoftDetail(v);
if(softDeatil) {
softList.push(softDeatil);
}
});
// return softList;
this.mainWindow.win.webContents.send("softListOfCate", {softList,categoryId:cateId});
}
// 生成唯一id
genID(length){
return Number(Math.random().toString().substr(3,length) + Date.now()).toString(36);
}
}
export default category
\ No newline at end of file
......@@ -13,11 +13,12 @@ class SoftList {
// console.log('获取app列表')
this.mainWindow.win.webContents.send('getMsg', '获取app列表-mainprocess')
let appsList = this.store.get('apps');
// if(appsList && appsList.length > 0) {
// // 已有app列表
// console.log('apps-length', appsList.length)
// return;
// }
if(appsList && appsList.length > 0) {
// 已有app列表
console.log('apps-length', appsList.length)
this.mainWindow.win.webContents.send("appsList", appsList);
return;
}
if (process.platform === 'linux') {
// 当前是Linux平台
console.log('当前是Linux平台')
......@@ -178,7 +179,9 @@ class SoftList {
// icon = this.getMaxPix({name, iconList, icon})
// }
// }
let idStr = this.genID(10);
return {
id: idStr,
type,
iconList: iconList || [],
nameOfZh,
......@@ -219,6 +222,7 @@ class SoftList {
searchIcon:true,
};
})
console.log(newApps)
this.store.set('apps', newApps);
// this.mainWindow.win.webContents.send("appsList", newApps);
} catch (error) {
......@@ -491,6 +495,11 @@ class SoftList {
return addFile;
}
// 生成唯一id
genID(length){
return Number(Math.random().toString().substr(3,length) + Date.now()).toString(36);
}
/* 获取翻译函数(为了保持this正确指向)*/
get () {
return i => {
......
......@@ -7,7 +7,30 @@ import SoftList from '../plugins/softList';
const store = new Store({
defaults: {
apps: [],
apps: [], //app列表
//分类
category: [
{
name:'备课资源',
id:'bk001',
softIds:[], //当前分类下的软件
},
{
name:'教学工具',
id:'jx002',
softIds:[],
},
{
name:'课后练习',
id:'kh003',
softIds:[],
},
{
name:'教务管理',
id:'jw004',
softIds:[],
},
],
},
});
......
......@@ -5,6 +5,7 @@
:src="lItem.icon"
:name="lItem.name"
:detail="lItem"
:index="lIndex"
></item>
</box>
<div v-if="listObj && listObj.list">
......@@ -14,24 +15,38 @@
:src="lItem.icon"
:name="lItem.name"
:detail="lItem"
:index="lIndex"
></item>
</box>
</div>
<right-menu @closeMenu="closeMenu" @select="selectMenu"
:cates="cateList"
:visible="showMenu" :left="menuPosition.left" :top="menuPosition.top"></right-menu>
</div>
</template>
<script>
import box from './box.vue';
import item from './item.vue';
import rightMenu from '@/renderer/components/RightMenu/index.vue';
export default {
components: {
box,
item
item,
rightMenu
},
props: {
cateList: { //分类列表
type: Array,
default: () => {
return [];
}
},
listAll: {
type: Array,
default: []
default: () => {
return [];
}
},
listObj: {
type: Object,
......@@ -115,11 +130,66 @@ export default {
},
data() {
return {
showMenu: false,
menuPosition: {
left:0,
top:0,
current:-1,
id:-1,
}
};
},
computed: {
},
created() {
this.listener();
},
destroyed() {
window.removeEventListener("contextmenu",this.handleEvent)
},
methods: {
handleEvent(e) {
console.dir(e)
e.preventDefault();
e.stopPropagation();
if(e.target.dataset.type === 'closeMask' || this.showMenu) {
// 点击遮罩层
this.closeMenu();
return;
}
if (
(e.target.parentElement &&
e.target.parentElement.dataset.type !== 'right-menu') &&
e.target.dataset.type !== 'right-menu'
) {
return;
}
// 需要显示右键菜单
this.menuPosition.left = e.layerX;
this.menuPosition.top = e.layerY;
this.menuPosition.id = e.target.parentElement ? e.target.parentElement.dataset.id : e.target.dataset.id;
this.menuPosition.current = e.target.parentElement ? e.target.parentElement.dataset.index : e.target.dataset.index;
this.showMenu = true;
},
listener() {
// 监听右键菜单
window.addEventListener("contextmenu", this.handleEvent);
},
selectMenu(item) {
// 选中某个分类
let {id,current} = this.menuPosition;
console.log('this.menuPosition',this.menuPosition,item)
this.$emit('softAddtoCate', {
cate: item,
soft: {id,current}
})
},
closeMenu() {
this.showMenu = false;
this.menuPosition.left=0;
this.menuPosition.top=0;
},
}
}
</script>
......
<template>
<div class="item_wrap" @click="tapApp">
<div class="item_wrap" @click="tapApp" data-type="right-menu" :data-id="detail.id" :data-index="index">
<img :src="src" alt="" class="item_img">
<span class="item_name">{{name}}</span>
</div>
......@@ -8,6 +8,10 @@
<script>
export default {
props: {
index: {
type: [Number, String],
default: ""
},
name: {
type: String,
default: ""
......
......@@ -6,42 +6,24 @@
<cateBox v-for="(cItem, cIndex) in cateList" :key="cIndex">
<div class="dragbox_cate">
<div class="dragbox_cate_name">{{cItem.name}}</div>
<div class="dragbox_cate_list">
<cateItem v-for="(sItem, sIndex) in cItem.list" :key="sIndex" :detail="sItem" :src="sItem.icon" :name="sItem.name"></cateItem>
<div v-if="cItem.softList" class="dragbox_cate_list">
<cateItem v-for="(sItem, sIndex) in cItem.softList" :key="sIndex" :detail="sItem" :src="sItem.icon" :name="sItem.name"></cateItem>
</div>
</div>
</cateBox>
<!-- <draggable v-model="myArray" group="people" @start="drag=true" @end="drag=false">
<div v-for="element in myArray" :key="element.id">{{element.name}}</div>
</draggable>
<div>
<div>列表1</div>
<draggable
class="list-group"
:list="list1"
group="people"
@change="log"
itemKey="name"
>
<template #item="{ element, index }">
<div class="list-group-item">{{ element.name }} {{ index }}</div>
</template>
</draggable>
</div>
<div>
<div>列表2</div>
<draggable
class="list-group"
:list="list2"
group="people"
@change="log"
itemKey="name"
>
<template #item="{ element, index }">
<div class="list-group-item">{{ element.name }} {{ index }}</div>
</template>
</draggable>
</div> -->
<el-dialog
title="添加分类"
:visible.sync="centerDialogVisible"
width="30%"
destroy-on-close
center>
<div style="padding-bottom:12px;fontsize:16px">请输入分类名称</div>
<el-input v-model="cateName" placeholder="请输入"></el-input>
<span slot="footer" class="dialog-footer">
<el-button @click="cancelAdd">取 消</el-button>
<el-button type="primary" @click="sureAdd">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
......@@ -84,29 +66,23 @@ export default {
},
data() {
return {
myArray:[
{ name: "John2", id: 1 },
{ name: "Joao", id: 2 },
{ name: "Jean", id: 3 },
{ name: "Gerard", id: 4 }
],
list1: [
{ name: "John1", id: 1 },
{ name: "Joao", id: 2 },
{ name: "Jean", id: 3 },
{ name: "Gerard", id: 4 }
],
list2: [
{ name: "Juan3", id: 5 },
{ name: "Edgard", id: 6 },
{ name: "Johnson", id: 7 }
]
centerDialogVisible:false,
cateName:""
};
},
methods: {
cancelAdd() {
this.centerDialogVisible = false;
this.cateName = "";
},
sureAdd() {
let name = this.cateName;
if(name == '' || name.trim() == '') name = "未命名";
this.$emit("addCategory", name);
},
addCate() {
// 添加分类
this.$emit("addCategory");
this.centerDialogVisible = true;
},
add: function() {
this.list.push({ name: "Juan" });
......
<template>
<div>
<div class="right-menu-container" :class="{'visible':visible}" :style="`left:${left}px;top:${top}px;`">
<div v-for="(cItem, cIndex) in cates" :key="cIndex"
@click="tapItem(cItem)"
class="right-menu-item">
加入 {{cItem.name}}
</div>
</div>
<div v-if="visible" class="right-menu-mask" @click="closeMenu" data-type="closeMask"></div>
</div>
</template>
<script>
export default {
props: {
cates:{
type: Array,
default: () => {
return [
{
name:'分类1',
type:'1',
},
{
name:'分类2',
type:'2',
},
];
}
},
left:{
type:[Number, String],
default:0,
},
top:{
type:[Number, String],
default:0,
},
visible: {
type: Boolean,
default: false,
}
},
methods: {
closeMenu() {
this.$emit("closeMenu");
},
tapItem(item) {
this.$emit("select",item);
},
}
}
</script>
<style lang="less" scoped>
.right-menu-container {
display: none;
position: absolute;
z-index: 100;
padding: 8px;
min-width: 120px;
width: max-content;
text-align: center;
background: linear-gradient(180deg, rgba(234,240,255,1) 0%, #D6E2FF 100%);
border-radius: 12px 12px 12px 12px;
.right-menu-item {
padding: 8px ;
line-height: 18px;
font-size: 15px;
color: #333;
border-radius: 8px;
cursor: pointer;
&:hover {
color: #399DF9;
// background-color: rgba(255, 255, 249, 0.6);
}
&.active {
background-color: rgba(255, 255, 249, 0.6);
}
}
&.visible {
display: block;
}
}
.right-menu-mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(255, 255, 249, 0.6);
opacity: 0;
}
</style>
\ No newline at end of file
......@@ -32,9 +32,9 @@
<!-- <span v-else-if="current === 'mine'">我的应用</span> -->
</div>
<div>
<Appbox v-if="current === 'all'" :listObj="listObj" :listAll="appList"></Appbox>
<Appbox v-if="current === 'all'" :cateList="categoryList" :listObj="listObj" :listAll="appList" @softAddtoCate="softAddtoCate"></Appbox>
<SchoolBox v-if="current === 'school'"></SchoolBox>
<DragBox v-if="current === 'mine'" :cateList="cateList"></DragBox>
<DragBox ref="dragEl" v-if="current === 'mine'" :cateList="categoryList" @addCategory="addCategory" ></DragBox>
</div>
</el-scrollbar>
</el-main>
......@@ -68,7 +68,8 @@ export default {
appList:[],
listObj: {
lastest:[],
}
},
categoryList:[],
};
},
computed: {
......@@ -103,14 +104,31 @@ export default {
this.ipcOn();
setTimeout(() => {
this.getAppList();
}, 1000)
this.getCategoryList();
}, 100)
},
methods: {
addCategory(name) {
// 添加分类
this.ipcRenderer.send("addCategory",name);
},
softAddtoCate(detail) {
let { cate, soft } = detail;
console.log('软件添加到哪个分类', detail)
this.ipcRenderer.send("changeCategory", {
soft,
category:cate
})
},
getAppList() {
//获取app列表
this.ipcRenderer.send("getApps");
},
getCategoryList() {
// 获取分类列表
this.ipcRenderer.send("getCategoryList");
},
ipcOn() {
// 获取到app列表
this.ipcRenderer.on("appsList", (event, list) => {
......@@ -125,6 +143,21 @@ export default {
// });
// this.getPinyin();
});
this.ipcRenderer.on("category-list", (event, list) => {
console.log("获取到分类列表 2", list);
this.categoryList = list;
});
this.ipcRenderer.on("change-category", (event, {detail,id}) => {
console.log("修改分类 2", detail,id);
// this.categoryList = list;
let curIndex = this.categoryList.findIndex(v => v.id == id);
this.categoryList[curIndex] = detail;
});
this.ipcRenderer.on("add-category", (event, data) => {
this.categoryList.unshift(data);
this.$message("添加成功");
this.$refs.dragEl.cancelAdd();
});
},
changeTap(tabType) {
if(this.current === tabType) return;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论