Compare commits

...

9 Commits

Author SHA1 Message Date
yangws cfac2086e6 fix:看不了学生信息; 2024-09-03 16:31:40 +08:00
zhengdegang 5433e47d0b Merge pull request '修复bug-数据共享' (#168) from zdg into main
Reviewed-on: #168
2024-09-03 13:19:35 +08:00
zdg eb3778dde2 修复bug-数据共享 2024-09-03 13:18:40 +08:00
zhengdegang 411ef757e2 Merge pull request 'zdg' (#167) from zdg into main
Reviewed-on: #167
2024-09-02 22:23:07 +08:00
zdg 0201385e75 Merge branch 'main' of http://27.128.240.72:3000/zhuhao/AIx_Smarttalk into zdg 2024-09-02 22:22:14 +08:00
zdg ea9af1440e 数据库共享:结合 pinia + electron-store
关闭开发 本地文件日志,只有生产有日志文件记录
2024-09-02 22:22:03 +08:00
zdg b4c2751e8c 注释代码放开 2024-09-02 18:35:16 +08:00
yangws c5257b760a Merge pull request 'fix:隐藏掉班级中心所有的操作按钮;' (#166) from yangws into main
Reviewed-on: #166
2024-09-02 16:58:33 +08:00
zdg 1d808950b5 优化bug 2024-09-02 16:33:25 +08:00
11 changed files with 104 additions and 49 deletions

View File

@ -13,7 +13,7 @@ import remote from '@electron/remote/main'
// 第二步: 初始化remote
remote.initialize()
// 日志配置-初始化(日志直接绑定到console上)
Logger.initialize()
if(!is.dev) Logger.initialize()
// 持久化数据-初始化
Store.initialize()

View File

@ -383,16 +383,7 @@ defineExpose({
savaDataStore
})
watchEffect(() => {
setTimeout(() => {
console.log(toolState,'监听')
}, 300)
if(toolState.isPdfWin){
// if(toolState.isToolWin){
// ispointer.value=false
// }else{
// ispointer.value=true
// }
watchToolState() //
}
})

View File

@ -3,13 +3,14 @@
*/
const isNode = typeof require !== 'undefined' // 是否支持node函数
const { ipcRenderer } = isNode?require('electron'):{} // app使用
import { sessionStore } from '@/utils/store'
// const Remote = isNode?require('@electron/remote'):{} // 远程模块
export function shareStorePlugin({store}) {
store.$subscribe((mutation, state) => { // 自动同步
// mutation 变量包含了变化前后的状态
// mutation.events: key newValue target oldValue oldTarget
// state 是变化后的状态
// console.log('store.$subscribe', mutation)
// console.log('store.$subscribe', mutation, state, store)
// 在存储变化的时候执行
// const storeName = store.$id
const storeName = mutation.storeId
@ -19,13 +20,15 @@ export function shareStorePlugin({store}) {
const { storeId: storeName, payload, events, type } = mutation // direct
// if (!Object.keys(payload).length) return
if (type != 'direct' || !events || Array.isArray(events) || !events.key) return
stateSync(storeName, events.key, events.newValue) // 需要同步
stateSync(storeName, events.key, events.newValue, state) // 需要同步
}
})
// 暴露方法-手动同步
store.stateSync = (storeName, key, value) => {
if (!storeName && !!key && !!value) stateSync(storeName, key, value)
else stateSyncAll(store)
const state = store.$state
if (!storeName && !!key && !!value) stateSync(storeName, key, value, state)
else stateSyncAll(store, state)
}
// 暴露方法-发送当前状态-新窗口
store.stateSyncInit = wid => stateSyncInit(wid, store)
@ -34,14 +37,16 @@ export function shareStorePlugin({store}) {
}
// 同步数据-发送给主线程-单独
function stateSync(storeName, key, value) {
function stateSync(storeName, key, value, state) {
// console.log('state-change', storeName, key, value)
try {
let jsonStr = ''
if (typeof key === 'string') jsonStr = JSON.stringify({[key]:value})
else if (typeof value === 'object') jsonStr = JSON.stringify(key)
const { data, keystr } = filterByKey(state, key, value)
const jsonStr = JSON.stringify(data) // 从新组装-json数据
// 更新本地数据-session
sessionStore.set(keystr, value)
// 通知主线程更新
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
// console.log('======',keystr, jsonStr )
} catch (error) {
console.log('state-change-error', error)
}
@ -95,3 +100,29 @@ const circularSafeStringify = (obj) => {
});
}
// 过滤对象
const filterByKey = (obj, key, value) => {
let res = { data:{}, keystr:'' }
for (let k in obj) {
if (obj.hasOwnProperty(k)) {
const isEqual = JSON.stringify(obj[k]) === JSON.stringify(value) // 值是否相同
if (k === key && isEqual) {
// 如果匹配,则添加到新对象中
res.data[k] = obj[k];
res.keystr = k;
} else {
if (obj[k] !== null && typeof obj[k] === 'object') {
// 如果是对象,则递归处理
const {data, keystr} = filterByKey(obj[k], key, value)
if(!!keystr) {
res.data[k] = data
res.keystr = `${k}.${keystr}`
}
}
}
}
}
return res;
}
// 对象克隆
const objClone = (obj) => JSON.parse(JSON.stringify(obj))

View File

@ -2,6 +2,10 @@
* 工具类-窗口-状态管理
*/
import { defineStore } from 'pinia'
import { sessionStore } from '@/utils/tool'
// 默认数据
const defData = sessionStore.store || {}
export const useToolState = defineStore('tool', {
state: () => ({
@ -10,9 +14,10 @@ export const useToolState = defineStore('tool', {
isPdfWin: false, // pdf窗口是否打开
isToolWin: false, // 工具窗口是否打开
curSubjectNode: {
data: {}, // 当前教材节点 (包含当前教材 单元)
data: {}, // 当前教材节点 (包含当前教材 单元)
querySearch: {} // 查询资源所需参数
}
},
...defData // 默认数据-覆盖上面的配置(不要删除, 会导致新窗口-获取状态失败)
}),
actions: {
}

View File

@ -0,0 +1,25 @@
/**
* @description : 存储对象-本地存储 封装工具(渲染器)
* @author : zdg
* @date : 2024-09-03
*/
const isNode = typeof require !== 'undefined' // 是否支持node函数
const Store = isNode?require('electron-store'):null // 持久化存储
// 暴露sessionStore存储对象
export const sessionStore = Store ? new Store({
name: 'session-store', // 存储文件名
fileExtension: 'ini', // 文件后缀名
encryptionKey: 'BvPLmgCC4DSIG0KkTec5' // 数据加密-防止用户直接改配置
}) : {}
// 暴露localStore存储对象
export const localStore = Store ? new Store({
name: 'local-store', // 存储文件名
fileExtension: 'ini', // 文件后缀名
encryptionKey: '6CyoHQmUaPmLzvVsh' // 数据加密-防止用户直接改配置
}) : {}
export default {
sessionStore, localStore
}

View File

@ -11,30 +11,26 @@ const path = isNode?require('path'):{}
const Remote = isNode?require('@electron/remote'):{}
const { ipcRenderer } = isNode?require('electron'):window.electron || {}
const API = isNode?window.api:{} // preload-api
import { useToolState } from '@/store/modules/tool' // 获取store状态
const Store = isNode?require('electron-store'):null // 持久化存储
// import { useToolState } from '@/store/modules/tool' // 获取store状态
// const Store = isNode?require('electron-store'):null // 持久化存储
import store from './store'
// 常用变量
const BaseUrl = isNode?process.env['ELECTRON_RENDERER_URL']+'/#':''
const isDev = isNode?process.env.NODE_ENV !== 'production':''
const toolState = useToolState() // 获取store状态
// const toolState = useToolState() // 获取store状态
// 暴露Remote中的属性
export const ipcMain = Remote?.ipcMain || {}
// 暴露sessionStore存储对象
export const sessionStore = Store ? new Store({
name: 'session-store', // 存储文件名
fileExtension: 'ini', // 文件后缀名
encryptionKey: 'BvPLmgCC4DSIG0KkTec5' // 数据加密-防止用户直接改配置
}) : {}
export const sessionStore = store.sessionStore
// 暴露localStore存储对象
export const localStore = Store ? new Store({
name: 'local-store', // 存储文件名
fileExtension: 'ini', // 文件后缀名
encryptionKey: '6CyoHQmUaPmLzvVsh' // 数据加密-防止用户直接改配置
}) : {}
export const localStore = store.localStore
// 暴露Store存储对象
export const Store = store
/**
* 获取静态资源开发和生产环境
@ -137,7 +133,7 @@ export const createWindow = async (type, data) => {
winPdf.restore();
} else{
winPdf.focus();
toolState.isPdfWin=true
// toolState.isPdfWin=true
}
return
@ -204,9 +200,9 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) {
mainWin.once('closed', () => { win.destroy()})
// 内部监听器
win.webContents.on('did-finish-load', () => {
setTimeout(() => {
toolState.stateSyncInit(win.id) // 同步状态
}, 200);
// setTimeout(() => {
// toolState.stateSyncInit(win.id) // 同步状态
// }, 200);
})
// 内部监听器-是否打印
if (!!isConsole) {

View File

@ -104,9 +104,12 @@ const switchPageMode = () => {
}
}
onMounted(async () => {
const isDev = process.env.NODE_ENV == 'development'
toolState.isPdfWin=true //pdf
pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线
// pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //
if (isDev)
pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //
else
pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线
textbookId.value = route.query.textbookId
pdfObj.bookId=textbookId.value
//

View File

@ -13,7 +13,7 @@
<div>
<div class="studentContent">
<template v-if="studentList.length > 0">
<div v-for="(item,index) in studentList" :key="index" style="width: 10%" @click="addStudent(item.studentid)">
<div v-for="(item,index) in studentList" :key="index" style="width: 10%">
<div>
<el-avatar
src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"

View File

@ -122,6 +122,7 @@
:book-id="uploadData.textbookId"
@add-success="initReserv"
></reserv>
<!-- <button @click="ipcMsgSend('tool-sphere:close')">测试</button> -->
</template>
<script setup>
import { Check } from '@element-plus/icons-vue'
@ -144,12 +145,13 @@ import { parseCataByNode, creatPPT, asyncLocalFile } from '@/utils/talkFile'
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
import SetHomework from '@/components/set-homework/index.vue'
import outLink from '@/utils/linkConfig'
import { createWindow } from '@/utils/tool'
import { createWindow, ipcMsgSend } from '@/utils/tool'
import { cloneDeep } from 'lodash'
import { delClasswork } from '@/api/teaching/classwork'
import { getSelfReserv, startClass } from '@/api/classManage'
import { useGetHomework } from '@/hooks/useGetHomework'
const toolStore = useToolState()
const fs = require('fs')
const { ipcRenderer } = window.electron || {}
@ -423,7 +425,8 @@ export default {
this.uploadData.levelThirdId = cata[2]
this.uploadData.textbookId = data.textBook.curBookId
toolStore.curSubjectNode.data = data
toolStore.curSubjectNode.querySearch = this.uploadData
//
this.$nextTick(() =>{ toolStore.curSubjectNode.querySearch = this.uploadData })
this.initHomeWork()
await this.asyncAllFile()
},

View File

@ -29,7 +29,7 @@ onMounted(async() => {
const handleMode = (newVal, oldVal) => {
if(toolStore.isPdfWin){
if(newVal=='clear'){
emit('update:modelValue', oldVal)
setTimeout(() => emit('update:modelValue', oldVal), 10)
}
return
}
@ -47,7 +47,7 @@ const handleMode = (newVal, oldVal) => {
case 'clear': //
if(oldVal){
FabricVue.history?.clean()
emit('update:modelValue', oldVal)
setTimeout(() => emit('update:modelValue', oldVal), 10)
}
break

View File

@ -51,8 +51,9 @@ import imChat from './components/imChat.vue' // im-chat-子组件
import vDrag from './directive/drag' // -
import vIgnore from './directive/ignore' // -穿
import { useToolState } from '@/store/modules/tool' // -
import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' //
import { ipcMsgSend, ipcMain, sessionStore } from '@/utils/tool' //
import MsgEnum from '@/plugins/imChat/msgEnum' // -(nuem)
const route = useRoute();
const tabActive = ref('select') //
const isFold = ref(false) //
@ -82,10 +83,11 @@ const btnList = [ // 工具栏按钮列表
// === ===
onMounted(async() => {
if (!electron) return //
// console.log(sessionStore)
// window.test = sessionStore
// window.test1 = toolStore
getClassInfo() // ex3
setTimeout(() => {
resetStatus() // -
}, 200);
resetStatus() // -
})
// ==== ===
@ -104,7 +106,6 @@ const getClassInfo = async () => {
const tabChange = (val) => {
const bool = !toolStore.isPdfWin && !toolStore.showBoardAll
if(bool) toolStore.showBoardAll = true
// ipcMsgSend('tool-sphere:close')
toolStore.model = val // tab
}
// logo - |