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, onMounted,
watch, watch,
reactive, reactive,
defineProps,
defineExpose,
nextTick, nextTick,
defineEmits
} from 'vue' } from 'vue'
import { fabric } from 'fabric' import { fabric } from 'fabric'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'

View File

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

View File

@ -1,8 +1,8 @@
/** /**
* 共享数据状态-多窗口 * 共享数据状态-多窗口
*/ */
// const { ipcRenderer } = require('electron') // app使用 const isNode = typeof require !== 'undefined' // 是否支持node函数
const { ipcRenderer } = window.electron || {} const { ipcRenderer } = isNode?require('electron'):{} // app使用
export function shareStorePlugin({store}) { export function shareStorePlugin({store}) {
store.$subscribe(() => { // 自动同步 store.$subscribe(() => { // 自动同步
// 在存储变化的时候执行 // 在存储变化的时候执行
@ -20,6 +20,7 @@ export function shareStorePlugin({store}) {
function stateSync(store) { function stateSync(store) {
const storeName = store.$id const storeName = store.$id
const jsonStr = JSON.stringify(store.$state) const jsonStr = JSON.stringify(store.$state)
// console.log('state-change', jsonStr, storeName)
// 通知主线程更新 // 通知主线程更新
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr) 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 BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':''
const isDev = isNode?process.env.NODE_ENV !== 'production':'' const isDev = isNode?process.env.NODE_ENV !== 'production':''
// 暴露Remote中的属性
export const ipcMain = Remote?.ipcMain || {}
/** /**
* 获取静态资源开发和生产环境 * 获取静态资源开发和生产环境
* @param {*} url * @param {*} url
@ -56,6 +58,17 @@ export function ipcMsgSend(key, data, type) {
return ipcRenderer?.invoke(key, data) 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 类型 * @param {*} type 类型
@ -96,6 +109,7 @@ export const createWindow = async (type, data) => {
resizable: true, // 禁止窗口大小缩放 resizable: true, // 禁止窗口大小缩放
alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前 alwaysOnTop: false, // 窗口是否总是显示在其他窗口之前
} }
data.isConsole = true // 是否开启控制台
data.option = {...defOption, ...option} data.option = {...defOption, ...option}
const win = await toolWindow(data) const win = await toolWindow(data)
win.type = type // 唯一标识 win.type = type // 唯一标识
@ -152,7 +166,7 @@ export function toolWindow({url, isConsole, option={}}) {
// 内部监听器-是否打印 // 内部监听器-是否打印
if (!!isConsole) { if (!!isConsole) {
win.webContents.on('console-message', (e,leve,m,lin,s) => { 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()}) Remote.ipcMain.once('maximize-window', () => {win&&win.destroy()})
const on = { 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) // 加载公共方法 publicMethods(on) // 加载公共方法
break} break}

View File

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

View File

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

View File

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

View File

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