zdg #105

Merged
zhengdegang merged 17 commits from zdg into main 2024-08-07 16:11:14 +08:00
5 changed files with 211 additions and 31 deletions
Showing only changes of commit 7dfa51f5dc - Show all commits

View File

@ -1,7 +1,8 @@
/** /**
* 共享数据状态-多窗口 * 共享数据状态-多窗口
*/ */
const { ipcRenderer } = require('electron') // app使用 // const { ipcRenderer } = require('electron') // app使用
const { ipcRenderer } = window.electron || {}
export function shareStorePlugin({store}) { export function shareStorePlugin({store}) {
store.$subscribe(() => { // 自动同步 store.$subscribe(() => { // 自动同步
// 在存储变化的时候执行 // 在存储变化的时候执行
@ -20,14 +21,14 @@ function stateSync(store) {
const storeName = store.$id const storeName = store.$id
const jsonStr = JSON.stringify(store.$state) const jsonStr = JSON.stringify(store.$state)
// 通知主线程更新 // 通知主线程更新
ipcRenderer.invoke('pinia-state-change', storeName, jsonStr) ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
} }
// 同步数据-接收主线程消息 // 同步数据-接收主线程消息
function stateChange(store) { function stateChange(store) {
const storeName = store.$id const storeName = store.$id
ipcRenderer.on('pinia-state-set', (e, sName, jsonStr) => { ipcRenderer?.on('pinia-state-set', (e, sName, jsonStr) => {
if (sName == storeName) { // 更新对应数据 if (sName == storeName) { // 更新对应数据
console.log('state-set', jsonStr, sName) // console.log('state-set', jsonStr, sName)
const curJson = JSON.stringify(store.$state) // 当前数据 const curJson = JSON.stringify(store.$state) // 当前数据
const isUp = curJson != jsonStr // 不同的时候才写入,不然会导致触发数据变化监听,导致死循环 const isUp = curJson != jsonStr // 不同的时候才写入,不然会导致触发数据变化监听,导致死循环
if (!isUp) return if (!isUp) return

View File

@ -39,15 +39,19 @@ export const getStaticUrl = (url = '', type = 'app', exitPath = '', isFile = fal
* url:路由地址,width:窗口宽度,height:窗口高度,option:自定义选项 * url:路由地址,width:窗口宽度,height:窗口高度,option:自定义选项
* @returns * @returns
*/ */
export function ipcMsgSend(key, data) { export function ipcMsgSend(key, data, type) {
return new Promise((resolve) => { if (type == 'old') {
// 返回结果-监听 return new Promise((resolve) => {
ipcRenderer.once(`${key}-reply`, (e, res) => { // 返回结果-监听
resolve(res) ipcRenderer.once(`${key}-reply`, (e, res) => {
resolve(res)
})
// 发送消息
ipcRenderer.send(key, data)
}) })
// 发送消息 } else { // 新版本-默认
ipcRenderer.send(key, data) return ipcRenderer.invoke(key, data)
}) }
} }
/** /**
* 创建-窗口 调用该方法 * 创建-窗口 调用该方法
@ -173,13 +177,13 @@ const eventHandles = (type, win) => {
case 'tool-sphere': { // 创建-悬浮球 case 'tool-sphere': { // 创建-悬浮球
// 监听设置穿透 // 监听设置穿透
const setIgnore = (_, ignore) => {win.setIgnoreMouseEvents(ignore, {forward: true})} const setIgnore = (_, ignore) => {win.setIgnoreMouseEvents(ignore, {forward: true})}
Remote.ipcMain.on('tool-sphere:set:ignore', setIgnore) Remote.ipcMain.handle('tool-sphere:set:ignore', setIgnore) // 异步
// 关闭窗口 // 关闭窗口
Remote.ipcMain.once('tool-sphere:close', () => { win&&win.destroy() }) Remote.ipcMain.once('tool-sphere:close', () => { win&&win.destroy() })
// 放大监听-测试 // 放大监听-测试
Remote.ipcMain.once('maximize-window', () => {win&&win.destroy()}) Remote.ipcMain.once('maximize-window', () => {win&&win.destroy()})
const on = { const on = {
onClosed: () => {Remote.ipcMain.off('tool-sphere:set:ignore', setIgnore)} onClosed: () => {Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore)}
} }
publicMethods(on) // 加载公共方法 publicMethods(on) // 加载公共方法
break} break}

View File

@ -0,0 +1,137 @@
<template>
<div class="warp" ref="btnRef">
<slot name="start"></slot>
<!-- 工具按钮 -->
<el-space direction="vertical">
<template v-for="(item,index) in list">
<slot :name="item.prop" :item="item" :index="index">
<div class="c-btn flex flex-col items-center gap-2 p-2" @click.stop="clickHandel(item,$event)">
<i class="iconfont" :class="item.icon" :style="item.style" />
<span>{{item.label||item.text||item.name}}</span>
</div>
</slot>
</template>
<slot name="append"></slot>
</el-space>
<slot name="end"></slot>
<!-- 内容部分 -->
<transition name="el-fade-in">
<div class="c-popover" :style="`--top: ${topPos}px;--height:${hPost}px;`" v-show="isVisible">
<div class="content">{{activeObj}}</div>
</div>
</transition>
</div>
</template>
<script setup>
import { computed, defineProps, ref, reactive, watchEffect, onMounted } from 'vue'
// -
const colors = ['#00f389', '#ff7f00', '#ffff00', '#409EFF', '#00baff', '#13b189', '#F56C6C']
const emit = defineEmits(['update:modelValue','change'])
const props = defineProps({
modelValue: { //
type: Boolean,
default: true
},
data: { //
type: Array,
default: () => [
{ label: '资源', prop: 'resource', icon: 'icon-hudong' },
{ label: '互动', prop: 'interact', icon: 'icon-hudong' },
{ label: '窗口', prop: 'win', icon: 'icon-hudong' },
{ label: '下课', prop: 'over', icon: 'icon-hudong' },
]
}
})
const isVisible = ref(false) //
const activeObj = ref(null) //
const btnRef = ref(null) // -ref
const topPos = ref(30) // -
const hPost = ref(0) // -
let posBtnAll = {} //
// === ===
const list = computed(() => props.data.map((o,i) => {
o.style = getStyle(o.style, i)
return o
}))
onMounted(() => {
posBtnAll = btnRef.value.getBoundingClientRect()
hPost.value = posBtnAll.height
})
// === ===
//
const getIndex = i => i % colors.length
//
const getStyle = (style,index) => {
const color = colors[getIndex(index)]
if (!style) return {color}
else {
if (typeof style === 'object') return {...style, color}
return `${style}${style.endsWith(';')?'':';'}color:${color};`
}
}
//
const clickHandel = (o, e) => {
const node = e.target.parentNode.getBoundingClientRect()
const isColse = activeObj.value && activeObj.value.prop === o.prop && isVisible.value
isVisible.value = !isColse //
activeObj.value = o
const nodeH = parseInt(node.height / 2) //
topPos.value = parseInt(node.top) - posBtnAll.top + nodeH
emit('change', o)
}
</script>
<style lang="scss" scoped>
.warp{
border: 1px solid;
position: fixed;
top: 50%;
transform: translateY(-50%);
right: 10px;
min-height: 40vh;
min-width: 4em;
border-radius: 4em;
background-color: #121212;
.el-space{margin: 20px 0;}
.c-btn{
color: #d9dce3;
cursor: pointer;
.iconfont{
font-size: 20px;
color: attr(color);
}
span{font-size: 12px;}
&:hover{
border-radius: 4px;
background: #454545fa;
}
}
}
.c-popover{
--top: 30px;
--height: 40vh;
position: fixed;
inset: 50% 75px auto auto;
transform: translateY(-50%);
background-color: #121212;
padding: 10px;
border-radius: 4px;
min-height: var(--height);
width: 30em;
text-align: left;
&:before{
content: "";
width: 10px;
height: 10px;
background-color: #121212;
position: absolute;
right: -5px;
top: var(--top);
transform: rotate(45deg);
}
}
.content{
color: red;
}
</style>

View File

@ -0,0 +1,39 @@
/**
* 处理元素是否穿透-窗口
*/
import { ipcMsgSend } from '@/utils/tool'
class Ignore {
el // 绑定元素
binding // 绑定对象(参数)
value // 绑定值
isAuto // 是否自动控制
constructor(el, binding) {
this.el = el
this.binding = binding
this.value = binding.value
this.isAuto = !(this.value && this.value instanceof Boolean)
}
// 设置是否穿透
send(bool) {
ipcMsgSend('tool-sphere:set:ignore', bool)
}
// 监听元素移入移出,自动设置
mounted() {
this.el.addEventListener('mouseenter', () => { // 进入
this.send(false) // 元素不穿透,鼠标有效
})
this.el.addEventListener('mouseleave', () => { // 离开
this.send(true) // 元素穿透,鼠标无效
})
}
}
export default {
mounted(el, binding) {
const ignore = new Ignore(el, binding)
if (ignore.isAuto) { // 自动控制
ignore.mounted()
} else { // 手动设置
ignore.send(ignore.value)
}
}
}

View File

@ -1,9 +1,11 @@
<template> <template>
<div class="warp-all"> <div class="warp-all">
<!-- 画板 -->
<board-vue v-model="tabActive" v-show="isShow"></board-vue> <board-vue v-model="tabActive" v-show="isShow"></board-vue>
<!-- 侧边工具栏 -->
<side-vue v-ignore></side-vue>
<!-- 底部工具栏 :style="dataPos.style"--> <!-- 底部工具栏 :style="dataPos.style"-->
<div class="tool-bottom-all" <div class="tool-bottom-all" @mouseenter="mouseChange(0)" @mouseleave="mouseChange(1)">
@mouseenter="mouseChange(0)" @mouseleave="mouseChange(1)">
<div v-drag="{handle:'.tool-bottom-all', dragtime}" <div v-drag="{handle:'.tool-bottom-all', dragtime}"
@v-drag-start="dragtime = Date.now()"> @v-drag-start="dragtime = Date.now()">
<div class="c-logo" @click="logoHandle" title="拖动 | 折叠 | 展开"> <div class="c-logo" @click="logoHandle" title="拖动 | 折叠 | 展开">
@ -15,7 +17,7 @@
@change="tabChange"> @change="tabChange">
<template #default="{item}"> <template #default="{item}">
<div class="c-btn flex flex-col items-center gap-2 p-2"> <div class="c-btn flex flex-col items-center gap-2 p-2">
<i class="iconfont" :class="item.icon" :style="item.style"></i> <i class="iconfont" :class="item.icon" :style="item.style" />
<span>{{item.label}}</span> <span>{{item.label}}</span>
</div> </div>
</template> </template>
@ -29,18 +31,21 @@
// electron // electron
import { onMounted, ref, reactive, watchEffect } from 'vue' import { onMounted, ref, reactive, watchEffect } from 'vue'
import logo from '@root/resources/icon.png' // logo import logo from '@root/resources/icon.png' // logo
import boardVue from './components/board.vue' // import boardVue from './components/board.vue' // -
import sideVue from './components/side.vue' // -
import vDrag from './directive/drag' // - import vDrag from './directive/drag' // -
import vIgnore from './directive/ignore' // -穿
import { useToolState } from '@/store/modules/tool' import { useToolState } from '@/store/modules/tool'
const { ipcRenderer } = require('electron') // app使 import { ipcMsgSend } from '@/utils/tool' //
// const ipcRenderer = { send: () => {} } // 使 // const { ipcRenderer } = require('electron') // app使
const { ipcRenderer } = window.electron || {}
const tabActive = ref('select') // const tabActive = ref('select') //
const isFold = ref(false) // const isFold = ref(false) //
const isDrag = ref(false) // const isDrag = ref(false) //
const dragtime = ref(0) // - const dragtime = ref(0) // -
const isShow = ref(false) const isShow = ref(true) // -
const toolStore = useToolState() const toolStore = useToolState() //
const btnList = [ // const btnList = [ //
{ label: '选择', value: 'select', icon: 'icon-mouse' }, { label: '选择', value: 'select', icon: 'icon-mouse' },
{ label: '画笔', value: 'brush', icon: 'icon-huabi' }, { label: '画笔', value: 'brush', icon: 'icon-huabi' },
@ -51,16 +56,11 @@ const btnList = [ // 工具栏按钮列表
// { label: '', value: 'more', icon: 'icon-xiazai9' }, // { label: '', value: 'more', icon: 'icon-xiazai9' },
] ]
onMounted(() => { onMounted(() => {
// isShow.value = toolStore.showBoardAll // -
// console.log('xxx: ', toolStore.model)
// setTimeout(() => {
// toolStore.windowState.test = ''
// }, 2000);
}) })
// ==== === // ==== ===
const tabChange = (val) => { // tab-change const tabChange = (val) => { // tab-change
// console.log('xxxx:', val) // console.log('xxxx:', val)
toolStore.showBoardAll = true
switch (val) { switch (val) {
case 'brush': // case 'brush': //
break break
@ -73,7 +73,7 @@ const tabChange = (val) => { // 切换tab-change
case 'more': case 'more':
break break
case 'close': case 'close':
ipcRenderer.send('tool-sphere:close') ipcRenderer?.send('tool-sphere:close')
break break
default: default:
break break
@ -85,11 +85,10 @@ const logoHandle = (e,t) => { // logo 点击-事件 折叠|展开
isFold.value = !isFold.value isFold.value = !isFold.value
} }
} }
const mouseChange = (bool) => { // 穿 const mouseChange = (bool) => { // 穿
let resBool = false let resBool = false
if (tabActive.value == 'select') resBool = !!bool if (tabActive.value == 'select') resBool = !!bool
ipcRenderer.send('tool-sphere:set:ignore', resBool) ipcRenderer?.send('tool-sphere:set:ignore', resBool)
} }
watchEffect(() => { // watchEffect(() => { //
isShow.value = toolStore.showBoardAll // - isShow.value = toolStore.showBoardAll // -