@@ -42,173 +42,71 @@
diff --git a/src/renderer/src/components/move-file/index.vue b/src/renderer/src/components/move-file/index.vue
index f2fec19..6689e4a 100644
--- a/src/renderer/src/components/move-file/index.vue
+++ b/src/renderer/src/components/move-file/index.vue
@@ -137,7 +137,7 @@ const getSubjectContent = async () => {
}
const getSubject = async () => {
- subjectList.value = JSON.parse(localStorage.getItem('subjectList'))
+
if (localStorage.getItem('subjectList')) {
subjectList.value = JSON.parse(localStorage.getItem('subjectList'))
diff --git a/src/renderer/src/hooks/useGetSubject.js b/src/renderer/src/hooks/useGetSubject.js
new file mode 100644
index 0000000..e164e3e
--- /dev/null
+++ b/src/renderer/src/hooks/useGetSubject.js
@@ -0,0 +1,82 @@
+import { ref } from 'vue'
+import useUserStore from '@/store/modules/user'
+import { listEvaluation } from '@/api/subject'
+
+export const useGetSubject = async () =>{
+
+ // user store
+ const userStore = useUserStore()
+ const { edustage, edusubject, userId } = userStore.user
+ const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH
+ // 章节List
+ const unitList = ref([])
+ // 教材List
+ let subjectList = null
+ // 单元章节树结构
+ let treeData = null
+
+
+ // 根据 学科 + 学段 获取所有单元章节
+ const getSubjectUnit = async () =>{
+ let strUnit = localStorage.getItem('unitList')
+ if(strUnit){
+ unitList.value = JSON.parse(strUnit)
+ }
+ else{
+ const unitParams = {
+ edusubject,
+ edustage,
+ itemgroup: 'textbook',
+ orderby: 'orderidx asc',
+ pageSize: 10000
+ }
+ const { rows } = await listEvaluation(unitParams)
+ unitList.value = rows
+ localStorage.setItem('unitList', JSON.stringify(rows))
+ }
+
+ await getSubject()
+ }
+
+ // 获取 学科 + 学段 获取教材
+ const getSubject = async () =>{
+
+ let strSubject = localStorage.getItem('subjectList')
+ if(strSubject){
+ subjectList = JSON.parse(strSubject)
+ }
+ else{
+ const subjectParams = {
+ itemkey: "version",
+ edusubject,
+ edustage,
+ pageSize: 10000,
+ orderby: 'orderidx asc'
+ }
+ const { rows } = await listEvaluation(subjectParams)
+ subjectList = rows
+ localStorage.setItem('subjectList', JSON.stringify(rows))
+ }
+
+ // 默认选中第一个教材
+ if(subjectList && subjectList.length){
+ treeData = getTreeData(subjectList[0].id)
+ }
+ }
+
+ // 单元章节数据转为“树”结构
+ const getTreeData = (bookId) =>{
+ // 根据当前教材的id 查找出对应的章节
+ let data = unitList.value.filter(item => item.rootid == bookId && item.level == 1)
+ data.forEach( item => {
+ item.children = unitList.value.filter( item2 => item2.parentid == item.id && item2.level == 2)
+ })
+ return data
+
+ }
+
+ await getSubjectUnit()
+
+ return { subjectList, treeData, getTreeData }
+
+}
\ No newline at end of file
diff --git a/src/renderer/src/layout/components/Header.vue b/src/renderer/src/layout/components/Header.vue
index e9b53c6..5e3ad3a 100644
--- a/src/renderer/src/layout/components/Header.vue
+++ b/src/renderer/src/layout/components/Header.vue
@@ -37,7 +37,7 @@
{{ userStore.user.nickName }}
-
{{ userStore.user.deptName }}
+
{{ userStore.user.edusubject }}
@@ -52,6 +52,7 @@
+ {{ userStore.user.deptName }}
@@ -72,6 +73,7 @@ import { updateUserInfo } from '@/api/system/user'
import outLink from '@/utils/linkConfig'
import logoIco from '@/assets/images/logo.png'
import { listEvaluation } from '@/api/classManage/index'
+import { clearBookInfo } from '@/utils/ruoyi'
const { ipcRenderer } = window.electron || {}
const userStore = useUserStore()
@@ -190,6 +192,7 @@ function setLayout() {
}
// 切换学科
const changeSubject = async (command) =>{
+ clearBookInfo()
const { userId, userName, phonenumber, plainpwd } = userStore.user
const data = {
userId,
@@ -200,8 +203,6 @@ const changeSubject = async (command) =>{
await updateUserInfo(data)
await userStore.login({username: phonenumber, password: plainpwd})
await userStore.getInfo()
- localStorage.removeItem('subjectList')
- localStorage.removeItem('evaluationList')
router.go()
}
@@ -331,7 +332,7 @@ onMounted(() => {
justify-content: space-around;
.user-depname {
- margin-right: 5px;
+ margin-right: 0;
}
.user-subject {
@@ -351,8 +352,8 @@ onMounted(() => {
align-items: center;
.user-avatar {
- width: 35px;
- height: 35px;
+ width: 45px;
+ height: 45px;
border-radius: 10px;
margin-right: 10px;
}
diff --git a/src/renderer/src/utils/ruoyi.js b/src/renderer/src/utils/ruoyi.js
index e51b433..8d7971e 100644
--- a/src/renderer/src/utils/ruoyi.js
+++ b/src/renderer/src/utils/ruoyi.js
@@ -257,3 +257,17 @@ export const getFileName = (filename) => {
if(!filename) return
return filename.replace(/\.[^/.]+$/, "");
}
+
+// 清除当前选中的教材 章节 相关信息
+export const clearBookInfo = () =>{
+ //当前选中的教材
+ localStorage.removeItem('curBook')
+ // 当前选中的节点
+ localStorage.removeItem('curNode')
+ // 所有章节单元数据
+ localStorage.removeItem('unitList')
+ // 所有教材数据
+ localStorage.removeItem('subjectList')
+ // 展开的节点
+ localStorage.removeItem('defaultExpandedKeys')
+}
\ No newline at end of file
diff --git a/src/renderer/src/views/profile/userInfo.vue b/src/renderer/src/views/profile/userInfo.vue
index 158392d..18e7dc5 100644
--- a/src/renderer/src/views/profile/userInfo.vue
+++ b/src/renderer/src/views/profile/userInfo.vue
@@ -45,6 +45,7 @@ import {updateUserInfo } from '@/api/system/user'
import { listEvaluation } from '@/api/subject/index'
import useUserStore from '@/store/modules/user'
import {ElMessage} from 'element-plus'
+import { clearBookInfo } from '@/utils/ruoyi'
const props = defineProps({
user: {
@@ -137,8 +138,7 @@ function submit() {
userStore.login({username:props.user.userName,password:props.user.plainpwd}).then(() => {
userStore.getInfo().then(res => {
if(res.code === 200){
- localStorage.removeItem('subjectList')
- localStorage.removeItem('evaluationList')
+ clearBookInfo()
ElMessage.success('修改成功')
}else{
ElMessage.error(response.msg)
diff --git a/src/renderer/src/views/tool/components/lesson.vue b/src/renderer/src/views/tool/components/lesson.vue
index 75241ae..a111467 100644
--- a/src/renderer/src/views/tool/components/lesson.vue
+++ b/src/renderer/src/views/tool/components/lesson.vue
@@ -38,7 +38,7 @@ const curBookId = ref('')
const evaluationList = ref([])
const getTreeData = () => {
- evaluationList.value = JSON.parse(localStorage.getItem('evaluationList'))
+ evaluationList.value = JSON.parse(localStorage.getItem('unitList'))
//上册
/**