소스 검색

修复打开 文件时消息提示不对

liling 2 년 전
부모
커밋
bbaf125ee3
5개의 변경된 파일69개의 추가작업 그리고 45개의 파일을 삭제
  1. 30 23
      src/layout/indexCommon.vue
  2. 24 9
      src/main.js
  3. 1 2
      src/store/modules/websocket.js
  4. 1 1
      src/views/biz/recent/index.vue
  5. 13 10
      src/views/liveChat/index.vue

+ 30 - 23
src/layout/indexCommon.vue

@@ -70,7 +70,7 @@
 								<span class="yuandian" v-if="
                     hasNewMessage &&
                     item.path == '/index' &&
-                    $route.path != item.path
+                    ($route.path != item.path || isSwitchFileIframe)
                   "></span>
 							</div>
 						</router-link><br />
@@ -154,6 +154,7 @@
                   :src="item.src"
                   frameborder="0"
                   :id="`iframe${item.id}`"
+                  :name="`iframe${item.id}`"
                   width="100%"
                   height="800px"
                   class="iframeBox"
@@ -214,6 +215,7 @@ const isAlive = ref(true);
 const toFileData = ref();
 const uid = useUserStore().uid;
 let hasNewMessage=ref(false)
+let isSwitchFileIframe = ref(false); //是否切换到文件预览标签
 const iFrameData = ref(JSON.parse(sessionStorage.getItem('fileTabData')) || [
   {
     id: 1,
@@ -314,7 +316,6 @@ const editableTabs = ref(JSON.parse(sessionStorage.getItem('tabData')) ||[{label
 
 function reload() {
   isAlive.value = false;
-  console.log(11);
   nextTick(() => {
     isAlive.value = true;
   });
@@ -326,19 +327,24 @@ function toggleSideBar() {
   appStore.toggleSideBar();
 }
 const logingName = ref("");
+let lisetenMessageTime=null;
 onMounted(() => {
   logingName.value = Cookies.get("username");
-
-  // console.log('router',router)
-});
-watchEffect(async() => {
-  if(router.currentRoute.value.path=='/index') return;
-	if(websoctStore.noReadList!=null)hasNewMessage.value = true
-	else hasNewMessage.value = false
-	// console.log("===============websoctStore.noReadList:",websoctStore.noReadList,'===========',hasNewMessage.value)
+  clearInterval(lisetenMessageTime)
+  lisetenMessageTime = setInterval(() => {
+    //if(router.currentRoute.value.path=='/index') return;
+    //console.log("===============window.noReadList:", localStorage.getItem("noreadlist"),'===========',isSwitchFileIframe.value)
+    let tmplist = localStorage.getItem("noreadlist")
+    if(tmplist==null || tmplist==''){
+      hasNewMessage.value = false
+      return
+    }
+    tmplist = JSON.parse(tmplist);
+    if(tmplist!=null)hasNewMessage.value = true
+    else hasNewMessage.value = false
+  }, 1000);
 });
 
-
 function handleCommand(command) {
   switch (command) {
     case "setLayout":
@@ -499,9 +505,11 @@ const menuList = reactive({
 	
 const clickPath = (index, items) => {
   items = toRaw(items);
+  localStorage.setItem("inChat",items.path=="/index"?1:0)
   // toFileData.value = null
   console.log("clickPathitems", items);
   // editableTabs.value = arr;
+  isSwitchFileIframe.value=false
   const arr = toRaw(editableTabs.value);
   if (!arr.some((item) => item.label == items.label)) {
     editableTabs.value.push({
@@ -519,10 +527,12 @@ const clickPath = (index, items) => {
   // console.log("editableTabs", editableTabs.value);
 };
 const clickTab = (item) => {
-  console.log("item", toRaw(item));
+  let url = toRaw(item)
+  console.log("item", url);
   setTimeout(() => {
     console.log("toFileData.value", toFileData.value);
     if (toFileData.value) {
+      localStorage.setItem("inChat",0)
       console.log(
         "tofolder",
         JSON.stringify(toRaw(toFileData.value.clickRowId))
@@ -534,17 +544,12 @@ const clickTab = (item) => {
         //   row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
         },
       });
-      // router.push({
-      //   path: toFileData.value.path,
-      //   query: {
-      //     row: toFileData.value.row,
-      //   },
-      // });
       return;
     }
+    localStorage.setItem("inChat",url=="/index" ? 1: 0)
     let regExp = new RegExp(/^\//);
-    if (!regExp.test(toRaw(item))) {
-      const data = JSON.parse(toRaw(item));
+    if (!regExp.test(url)) {
+      const data = JSON.parse(url);
       console.log("data", data);
       router.push({
         // path: "/fileEdit" + data.docId,
@@ -556,7 +561,7 @@ const clickTab = (item) => {
         },
       });
     } else {
-      editableTabsValue.value = item
+      editableTabsValue.value = url      
       router.push({
         path: item,
       });
@@ -566,6 +571,7 @@ const clickTab = (item) => {
 const paneClick = (item) => {
   // 可以拿到当前的标签对象
   isAlive.value = true;
+  isSwitchFileIframe.value = false
   console.log("paneItem", item);
   if (item.clickRowId) {
     // 判断是菜单还是目录
@@ -574,11 +580,12 @@ const paneClick = (item) => {
     toFileData.value = null;
   }
   clickTab(item.path);
-  //   console.log("isAlive", isAlive.value);
 };
 // 点击文件标签
 const filePaneClick = (item) => {
+  localStorage.setItem("inChat",0)
   console.log("filePaneClickitem", item);
+  isSwitchFileIframe.value = true
   const row = toRaw(item);
   const arr = iFrameData.value.map((par) => {
     if (par.id === row.id) {
@@ -594,7 +601,6 @@ const filePaneClick = (item) => {
           outIframe.parentElement.offsetHeight + "px";
         inIframe.style.width = outIframe.style.width =
           outIframe.parentElement.offsetWidth + "px";
-
         // console.log('dom',outIframe.parentElement.offsetWidth);
         // console.log('inIframe',inIframe);
       }, 500);
@@ -734,6 +740,7 @@ const setTabLocal = (data)=>{
 }
 const setFileTabLocal = (data)=>{
   console.log('setFileTabLocal',data);
+  isSwitchFileIframe.value = true
   sessionStorage.setItem('fileTabData', JSON.stringify(data))
 }
 const setEditableTabsValue = (data)=>{

+ 24 - 9
src/main.js

@@ -1,4 +1,6 @@
-import { createApp } from 'vue'
+import {
+    createApp
+} from 'vue'
 
 import Cookies from 'js-cookie'
 
@@ -8,13 +10,15 @@ import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言
 import '@/assets/styles/index.scss' // global css
 
 import App from './App'
-import store from './store'//pinia
+import store from './store' //pinia
 import router from './router'
 import directive from './directive' // directive
 import CKEditor from '@ckeditor/ckeditor5-vue';
 // 注册指令
 import plugins from './plugins' // plugins
-import { download } from '@/utils/request'
+import {
+    download
+} from '@/utils/request'
 
 //引入字体
 import '@/assets/fonts/font.css'
@@ -27,8 +31,17 @@ import elementIcons from '@/components/SvgIcon/svgicon'
 import * as ElementPlusIconsVue from '@element-plus/icons-vue'
 import './permission' // permission control
 // import "@/assets/styles/my-common.scss";
-import { useDict } from '@/utils/dict'
-import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'
+import {
+    useDict
+} from '@/utils/dict'
+import {
+    parseTime,
+    resetForm,
+    addDateRange,
+    handleTree,
+    selectDictLabel,
+    selectDictLabels
+} from '@/utils/ruoyi'
 
 // 分页组件
 import Pagination from '@/components/Pagination'
@@ -47,7 +60,7 @@ import TreeSelect from '@/components/TreeSelect'
 // 字典标签组件
 import DictTag from '@/components/DictTag'
 
-const app = createApp(App).use( CKEditor )
+const app = createApp(App).use(CKEditor)
 // for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
 //   app.component(key, component)
 // }
@@ -82,8 +95,10 @@ directive(app)
 
 // 使用element-plus 并且设置全局的大小
 app.use(ElementPlus, {
-  locale: locale,
-  // 支持 large、default、small
-  size: Cookies.get('size') || 'default'
+    locale: locale,
+    // 支持 large、default、small
+    size: Cookies.get('size') || 'default'
 })
 app.mount('#app')
+window.localStorage.removeItem('noreadlist')
+window.localStorage.removeItem('inChat')

+ 1 - 2
src/store/modules/websocket.js

@@ -10,7 +10,6 @@ const useWebsoctStore = defineStore('websoct', {
     messages: [],
     socket: null,
     messOne:{},
-    newMessage: false,
     falseMessag:false,//消息是否发送成功
     noReadList: null
   }),
@@ -41,7 +40,7 @@ const useWebsoctStore = defineStore('websoct', {
         let lst = this.noReadList[this.messOne.fromId]
         if(lst==null) this.noReadList[this.messOne.fromId] = 1
         else this.noReadList[this.messOne.fromId]=lst+1
-        //this.messages.push(message)
+        localStorage.setItem("noreadlist",JSON.stringify(this.noReadList))
       })
 
       this.socket.addEventListener("close", () => {

+ 1 - 1
src/views/biz/recent/index.vue

@@ -319,7 +319,7 @@ const getList = async () => {
     var arr = [];
     resY.rows.map(async (item) => {
       const detail = await getDir(item.relaId);
-      tableFolderData.value.push(JSON.parse(JSON.stringify(detail.data)));
+      if(detail.data!=null) tableFolderData.value.push(JSON.parse(JSON.stringify(detail.data)));
     });
     console.log("resYarr", arr);
     // tableFolderData.value = resY.rows;

+ 13 - 10
src/views/liveChat/index.vue

@@ -124,6 +124,7 @@ const boottmScroll = () => {
     chatContainer.scrollTop = targetScrollTop;
   });
 };
+let noReadList = null;
 //获取用户的聊天记录
 const msgRecordEvent = async (toIdValue) => {
   if(clickPersonId.value!=toIdValue) return;
@@ -147,14 +148,17 @@ const msgRecordEvent = async (toIdValue) => {
   total.value = resMsgData.total;
   boottmScroll();  
   setTimeout(() => {
-    if(websoctStore.noReadList==null) return;
-    if(websoctStore.noReadList[sendCont.data.toId]!=null) delete websoctStore.noReadList[sendCont.data.toId]
+    noReadList = localStorage.getItem('noreadlist');
+    if(noReadList==null || noReadList=='') return;
+    noReadList = JSON.parse(noReadList);
+    if(noReadList[sendCont.data.toId]!=null) delete noReadList[sendCont.data.toId]
     let i=0
-    for(let k in websoctStore.noReadList){
+    for(let k in noReadList){
       i++
     }
-    if(i==0) websoctStore.noReadList = null;
-  }, 1000); 
+    if(i==0) window.localStorage.removeItem('noreadlist');
+    else window.localStorage.setItem('noreadlist',JSON.stringify(noReadList));
+  }, 500); 
 };
 //点击左侧新建聊天
 const open = ref(false);
@@ -321,11 +325,11 @@ const sendFileClick = async () => {
 };
 //获取用户聊天记录
 const handleNewMessage = async () => {
-  if (websoctStore.newMessage) {
+  //console.log("======当前状态:",localStorage.getItem("inChat"),'    sendCont.data.toId:',sendCont.data.toId)
+  if('1'==localStorage.getItem("inChat")){
+    const hasNewMessage = localStorage.getItem('noreadlist');
+    if(hasNewMessage==null || hasNewMessage=='') return;
     msgRecordEvent(sendCont.data.toId); //获取用户的聊天记录
-    // const resFriend = await msgFriend();
-    //getMsgList();
-    websoctStore.newMessage = false; // 重置新消息标记
   }
 };
 //接收到的新消息
@@ -470,7 +474,6 @@ const formatText = (text) => {
 };
   // 文件下载
   const downLoadfile = (file)=>{
-    console.log('file',file);
       myfile.fileDown(file.docId).then(res=>{
             var reader = new FileReader();
           reader.onloadend = function(event){