zdg #105

Merged
zhengdegang merged 17 commits from zdg into main 2024-08-07 16:11:14 +08:00
8 changed files with 58 additions and 45 deletions
Showing only changes of commit 4e2512ed77 - Show all commits

View File

@ -13,10 +13,7 @@ import {
onMounted,
watch,
reactive,
defineProps,
defineExpose,
nextTick,
defineEmits
} from 'vue'
import { fabric } from 'fabric'
import { ElMessage } from 'element-plus'

View File

@ -26,7 +26,7 @@ import {
defineProps,
defineExpose,
nextTick,
defineEmits,watchEffect
watchEffect
} from 'vue'
// import { fabric } from 'fabric'
import { ElMessage } from 'element-plus'
@ -272,8 +272,12 @@ onMounted(async () => {
// 2canvas
// handleevent(fabriccanvas.value, imgarr)
// handleevent(fabriccanvas1.value, imgarr, 'two')
setToolStatus() // -(--)
})
// zdg: --
const setToolStatus = () => {
toolState.showBoardAll = false
}
defineExpose({
initPdf,
@ -282,12 +286,12 @@ defineExpose({
watchEffect(() => {
console.log(toolState.showBoardAll,'监听')
if( toolState.showBoardAll){
console.log('xczxcxzsdf')
setTimeout(() => {
toolState.showBoardAll=false
}, 200);
}
// if( toolState.showBoardAll){
// setTimeout(() => {
// console.log('pdf :')
// toolState.showBoardAll=false
// }, 200);
// }
// if(toolState.model=='select'){
// toolState.showBoardAll=false
// }

View File

@ -1,8 +1,8 @@
/**
* 共享数据状态-多窗口
*/
// const { ipcRenderer } = require('electron') // app使用
const { ipcRenderer } = window.electron || {}
const isNode = typeof require !== 'undefined' // 是否支持node函数
const { ipcRenderer } = isNode?require('electron'):{} // app使用
export function shareStorePlugin({store}) {
store.$subscribe(() => { // 自动同步
// 在存储变化的时候执行
@ -20,6 +20,7 @@ export function shareStorePlugin({store}) {
function stateSync(store) {
const storeName = store.$id
const jsonStr = JSON.stringify(store.$state)
// console.log('state-change', jsonStr, storeName)
// 通知主线程更新
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
}

View File

@ -15,6 +15,8 @@ const { ipcRenderer } = isNode?require('electron'):window.electron || {}
const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':''
const isDev = isNode?process.env.NODE_ENV !== 'production':''
// 暴露Remote中的属性
export const ipcMain = Remote?.ipcMain || {}
/**
* 获取静态资源开发和生产环境
* @param {*} url
@ -56,6 +58,17 @@ export function ipcMsgSend(key, data, type) {
return ipcRenderer?.invoke(key, data)
}
}
/**
* @description 封装ipcRenderer事件监听
* @param {*} fn on once handle invoke
* @param {*} key
* @param {Function} cb 回调函数
* @returns
*/
export function ipcHandle(fn,key, cb) {
return ipcRenderer[fn](key, cb)
// return ipcRenderer?.[fn]?.(key, cb)
}
/**
* 创建-窗口 调用该方法
* @param {*} type 类型
@ -96,6 +109,7 @@ export const createWindow = async (type, data) => {
resizable: true, // 禁止窗口大小缩放
alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前
}
data.isConsole = true // 是否开启控制台
data.option = {...defOption, ...option}
const win = await toolWindow(data)
win.type = type // 唯一标识
@ -152,7 +166,7 @@ export function toolWindow({url, isConsole, option={}}) {
// 内部监听器-是否打印
if (!!isConsole) {
win.webContents.on('console-message', (e,leve,m,lin,s) => {
console.log(m)
console.log(`[${win.type}]`,m)
})
}
})
@ -186,7 +200,11 @@ const eventHandles = (type, win) => {
// 放大监听-测试
Remote.ipcMain.once('maximize-window', () => {win&&win.destroy()})
const on = {
onClosed: () => {Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore)}
onClosed: () => {
Remote.ipcMain.removeHandler('tool-sphere:set:ignore', setIgnore)
Remote.ipcMain.removeHandler('tool-sphere:reset')
// Remote.ipcMain.removeAllListeners() // 移除所有监听事件
}
}
publicMethods(on) // 加载公共方法
break}

View File

@ -76,7 +76,7 @@ const minimize = () => {
toolState.isPdfWin=false
toolState.showBoardAll=true //
console.log(toolState.showBoardAll,"关闭")
// ipcRenderer.send('tool-sphere:reset') //tool
ipcRenderer.invoke('tool-sphere:reset') //tool
ipcRenderer.send('open-PDF:minimize')
}
const handleUpdate = (data) => {

View File

@ -19,7 +19,7 @@
</template>
<script setup>
import {ref,defineProps,defineEmits} from "vue";
import {ref} from "vue";
const activeIndex = ref('0')
const props = defineProps({
classList:{

View File

@ -40,7 +40,7 @@ const handleMode = (newVal, oldVal) => {
FabricVue.handleMode(TYPES.ActionMode.DRAW)
FabricVue.canvas.freeDrawingCursor = 'default'
break
case 'eraser': //
case 'erase': //
FabricVue.handleMode(TYPES.ActionMode.ERASE)
break
case 'clear': //
@ -54,7 +54,7 @@ const handleMode = (newVal, oldVal) => {
}
//
watch(() => props.modelValue, (newVal, oldVal) => {
console.log(newVal, oldVal)
// console.log(newVal, oldVal)
handleMode(newVal, oldVal)
})
//

View File

@ -36,7 +36,8 @@ import sideVue from './components/side.vue' // 画板-子组件
import vDrag from './directive/drag' // -
import vIgnore from './directive/ignore' // -穿
import { useToolState } from '@/store/modules/tool'
import { ipcMsgSend } from '@/utils/tool' //
import { ipcMsgSend, ipcHandle, ipcMain } from '@/utils/tool' //
import {FabricVue, TYPES} from '@/plugins/fabric'
const tabActive = ref('select') //
const isFold = ref(false) //
const isDrag = ref(false) //
@ -47,34 +48,22 @@ const boardVueRef=ref(null) // 画板ref
const btnList = [ //
{ label: '选择', value: 'select', icon: 'icon-mouse' },
{ label: '画笔', value: 'brush', icon: 'icon-huabi' },
{ label: '板擦', value: 'eraser', icon: 'icon-xiangpica' },
{ label: '板擦', value: 'erase', icon: 'icon-xiangpica' },
{ label: '清除', value: 'clear', icon: 'icon-xiangpica', style: 'color: #ccc' },
// { label: '', value: 'interact', icon: 'icon-hudong' },
// { label: '', value: 'focus', icon: 'icon-jujiao' },
// { label: '', value: 'more', icon: 'icon-xiazai9' },
]
// onMounted(() => {})
//
onMounted(async() => {
resetStatus() // -
})
// const test = (e) => { console.log('test', e) }
// ==== ===
const tabChange = (val) => { // tab-change
if(!toolStore.isPdfWin) toolStore.showBoardAll = true
switch (val) {
case 'brush': //
break
case 'eraser': //
break
case 'interact':
break
case 'focus':
break
case 'more':
break
case 'close':
ipcMsgSend('tool-sphere:close')
break
default:
break
}
const bool = !toolStore.isPdfWin && !toolStore.showBoardAll
if(bool) toolStore.showBoardAll = true
// ipcMsgSend('tool-sphere:close')
toolStore.model = val // tab
}
const logoHandle = (e,t) => { // logo - |
@ -91,13 +80,17 @@ const mouseChange = (bool) => { // 鼠标移入工具栏 是否穿透
const setIgnore = (bool) => { // 穿
ipcMsgSend('tool-sphere:set:ignore', bool)
}
const resetStatus = () => { //
ipcMain.handle('tool-sphere:reset', () => {
FabricVue.handleMode(tabActive.value)
setTimeout(() => { mouseChange(1) }, 500)
})
}
watchEffect(() => { //
isShow.value = !toolStore.isPdfWin && toolStore.showBoardAll // -
if(!toolStore.isPdfWin && toolStore.showBoardAll){ //
boardVueRef.value.handleMode(tabActive.value)
mouseChange(true)
}
// , : -
const show = !toolStore.isPdfWin && toolStore.showBoardAll
if (show != isShow.value) isShow.value = show
})
</script>