Parcourir la source

消息存草稿功能

刘洋 il y a 1 an
Parent
commit
0b5d3acc91

+ 1 - 0
src/components/common/ContentEditAble.vue

@@ -55,6 +55,7 @@ const paste = (event: any) => {
 function updateContent(content: string) {
   if (contenteditableEle.value) {
     contenteditableEle.value.innerHTML = content
+    placeCaretAtEnd(contenteditableEle.value)
   }
 }
 

+ 22 - 47
src/components/shared/message/MessageList.vue

@@ -125,7 +125,7 @@
 
 <script setup lang="ts" name="MessageList">
 /** 消息列表*/
-import { ref, watch, onUnmounted, computed, nextTick, unref } from 'vue'
+import { ref, watch, onUnmounted, computed, nextTick, unref, onMounted } from 'vue'
 import { ElButton, ElIcon, ElMessage } from 'element-plus'
 import { Close } from '@element-plus/icons-vue'
 import useFetch from '@/hooks/useFetch'
@@ -136,6 +136,7 @@ import { setLastMsgs } from '@/hooks/useMessageLoop'
 import bus from '@/utils/bus'
 import type { ExtractApiResponse } from '@/api/api'
 import ContentEditAble from '@/components/common/ContentEditAble.vue'
+import { getUserConfigByType, setUserConfigByType } from '@/utils/common'
 type MessageType = ExtractArrayValue<ExtractApiResponse<'getMessageList'>>
 const historyMsgWrap = ref()
 const mainStore = useMainStore()
@@ -170,7 +171,7 @@ const sendCurrentPaper = () => {
 
 /** 消息内容 */
 const messageContent = ref<string>('')
-watch(messageContent, () => {
+watch(messageContent, (val: string) => {
   // let reg = /<span class=\"pointer inline link-button\" contenteditable=\"false\" data-path=.*>查看试卷<\/span>/g
   // let arr = messageContent.value.match(reg)
   // let text = messageContent.value.replace(reg, '【查看试卷临时替换字符】')
@@ -183,6 +184,11 @@ watch(messageContent, () => {
     const paperButton = document.querySelector(`.content-edit-able [data-path="${props.paperPath}"]`)
     sendedPaper.value = !!paperButton
   })
+  if (sendTargetId.value) {
+    let config: any = getUserConfigByType('draft')
+    config[sendTargetId.value] = val || ''
+    setUserConfigByType('draft', config)
+  }
 })
 /** 图片路径 */
 const paperPath = ref<string>('')
@@ -221,40 +227,25 @@ watch(historyReverse, (newVal: any, oldVal: any) => {
     })
   }
 })
+const sendTargetId = computed(() => {
+  return currentMessage.value?.sendUserId == mainStore?.myUserInfo?.id
+    ? currentMessage.value?.receiveUserId
+    : currentMessage.value?.sendUserId
+})
 watch(currentMessage, (newVal: any, oldVal: any) => {
   if (currentMessage.value) {
-    // useFetch('handleReadMessage')
-    //   .fetch({ id: currentMessage.value.id })
-    //   .then(() => {
-    //     if (currentMessage.value?.unReadCount) {
-    //       // currentMessage.value.unReadCount--
-    //       currentMessage.value.unReadCount = 0
-    //     }
-    //     if (currentMessage.value?.sendUserId) {
-    //       getMessageHistory({
-    //         sendUserId:
-    //           currentMessage.value.sendUserId == mainStore?.myUserInfo?.id
-    //             ? currentMessage.value.receiveUserId
-    //             : currentMessage.value.sendUserId,
-    //       }).then(() => {
-    //         let newV = unref(newVal)
-    //         let oldV = unref(oldVal)
-    //         if (newV.id != oldV?.id) {
-    //           setTimeout(scrollToBottom, 1)
-    //         }
-    //       })
-    //     }
-    //   })
+    messageContent.value = ''
     if (currentMessage.value?.unReadCount) {
       // currentMessage.value.unReadCount--
       currentMessage.value.unReadCount = 0
     }
     if (currentMessage.value?.sendUserId) {
+      const targetId =
+        currentMessage.value.sendUserId == mainStore?.myUserInfo?.id
+          ? currentMessage.value.receiveUserId
+          : currentMessage.value.sendUserId
       getMessageHistory({
-        sendUserId:
-          currentMessage.value.sendUserId == mainStore?.myUserInfo?.id
-            ? currentMessage.value.receiveUserId
-            : currentMessage.value.sendUserId,
+        sendUserId: targetId,
       }).then(() => {
         let newV = unref(newVal)
         let oldV = unref(oldVal)
@@ -262,6 +253,9 @@ watch(currentMessage, (newVal: any, oldVal: any) => {
           setTimeout(scrollToBottom, 1)
         }
       })
+
+      const targetIdDraft = getUserConfigByType('draft')?.[targetId]
+      targetIdDraft && (messageContent.value = targetIdDraft)
     }
   }
 })
@@ -330,25 +324,6 @@ const onContentClick = (e: Event) => {
   }
 }
 
-// getMessageList().then((result) => {
-//   currentMessage.value = result?.[0]
-//   if (result[0]) {
-//     bus.emit('getCurMsg', result[0])
-//   }
-// })
-// watch(
-//   () => mainStore.newMsgs,
-//   () => {
-//     getMessageList().then((res) => {
-//       if (res && Array.isArray(res)) {
-//         let find = res.find((item) => item.sendUserId == currentMessage.value?.sendUserId)
-//         if (!!find) {
-//           currentMessage.value = find
-//         }
-//       }
-//     })
-//   }
-// )
 onUnmounted(() => {
   useFetch('getUnReadMessage')
     .fetch()

+ 10 - 4
src/components/shared/message/MessageSend.vue

@@ -74,7 +74,7 @@
 </template>
 
 <script setup lang="tsx" name="MessageSend">
-import { ref, computed, watch, nextTick } from 'vue'
+import { ref, computed, watch, nextTick, onMounted } from 'vue'
 import { ElInput, ElButton, ElTree, ElIcon, ElMessage } from 'element-plus'
 import { Close } from '@element-plus/icons-vue'
 import ContentEditAble from '@/components/common/ContentEditAble.vue'
@@ -82,7 +82,7 @@ import ImagePreview from '../ImagePreview.vue'
 import useFetch from '@/hooks/useFetch'
 import useVModel from '@/hooks/useVModel'
 import MessageHistory from '@/components/shared/message/MessageHistory.vue'
-import { transHtmlContent } from '@/utils/common'
+import { getUserConfigByType, setUserConfigByType } from '@/utils/common'
 import type { ExtractApiResponse } from '@/api/api'
 
 type MarkerItem = ExtractArrayValue<ExtractApiResponse<'getUserGroup'>['chiffGroup']>
@@ -242,7 +242,7 @@ const onCheckChange = () => {
   }
 }
 
-watch(messageContent, () => {
+watch(messageContent, (val: string) => {
   // let reg = /<span class=\"pointer inline link-button\" contenteditable=\"false\" data-path=.*>查看试卷<\/span>/g
   // let arr = messageContent.value.match(reg)
   // let text = messageContent.value.replace(reg, '【查看试卷临时替换字符】')
@@ -255,8 +255,14 @@ watch(messageContent, () => {
     const paperButton = document.querySelector(`.content-edit-able [data-path="${props.paperPath}"]`)
     sendedPaper.value = !!paperButton
   })
+  let config: any = getUserConfigByType('draft')
+  config.other = val || ''
+  setUserConfigByType('draft', config)
+})
+onMounted(() => {
+  const draft = getUserConfigByType('draft')?.other
+  draft && (messageContent.value = draft)
 })
-
 const onContentClick = (e: Event) => {
   const target = e.target as HTMLButtonElement
   const path = target.getAttribute('data-path')

+ 9 - 2
src/modules/bootstrap/login/index.vue

@@ -42,6 +42,7 @@ import useMainLayoutStore from '@/store/layout'
 import useFetch from '@/hooks/useFetch'
 import useForm from '@/hooks/useForm'
 import { sessionStorage, localStorage } from '@/plugins/storage'
+import { initConfigModelData } from '@/utils/common'
 
 import type { EpFormItem, EpFormRules } from 'global-type'
 import type { ExtractApiParams, ExtractApiResponse } from '@/api/api'
@@ -119,8 +120,14 @@ async function onSubmit() {
 function loginSuccess(loginInfo: ExtractApiResponse<'userLogin'>) {
   /** sessionStorage 缓存login result */
   sessionStorage.set('LOGIN_RESULT', loginInfo)
-  if (!localStorage.get('USER_CONFIG')) {
-    localStorage.set('USER_CONFIG', { [loginInfo.id]: {} })
+  let config: any = localStorage.get('USER_CONFIG')
+  if (!config) {
+    localStorage.set('USER_CONFIG', { [loginInfo.id]: initConfigModelData() })
+  } else {
+    if (!config[loginInfo.id]) {
+      config[loginInfo.id] = {}
+      localStorage.set('USER_CONFIG', config)
+    }
   }
   /** pinia store 存储 login result */
   mainStore.loginInfo = loginInfo

+ 34 - 15
src/modules/quality/ending-check/components/SubjectProgress.vue

@@ -126,6 +126,15 @@ const getMainName = (row?: SubjectProgress) => {
   return [number, name].filter(Boolean).join('-')
 }
 
+const getRateLabel = (value: number) => {
+  if (subjectProgressEndList.value?.length) {
+    let rate = subjectProgressEndList.value.find((v) => v.finishCount == value)?.finishRate
+    return rate ? rate + '%' : ''
+  } else {
+    return ''
+  }
+}
+
 const getYAxisData = (field: keyof SubjectProgress | 'name', data?: SubjectProgress[]) => {
   if (!data) {
     return []
@@ -150,7 +159,8 @@ const totalChartsOption = computed<EChartsOption>(() => {
     legend: {
       right: 0,
       itemWidth: 14,
-      data: ['试卷总量', '已完成', '完成比'],
+      // data: ['试卷总量', '已完成', '完成比'],
+      data: ['试卷总量', '已完成'],
     },
     yAxis: {
       axisLine: { show: false },
@@ -199,28 +209,37 @@ const totalChartsOption = computed<EChartsOption>(() => {
           color: '#0064FF',
         },
         data: getYAxisData('finishCount', subjectProgressEndList?.value),
-      },
-      {
-        name: '完成比',
-        type: 'bar',
-        barWidth: 44,
-        barGap: '-200%',
-        showBackground: true,
-        xAxisIndex: 1,
-        itemStyle: {
-          color: 'rgba(0, 186, 151,0.3)',
-        },
         label: {
           show: true,
           color: '#444',
           fontSize: 10,
           formatter({ value }) {
-            return value > 0 ? `${value}%` : ''
+            return getRateLabel(value)
           },
-          position: 'insideTopRight',
+          position: 'right',
         },
-        data: getYAxisData('finishRate', subjectProgressEndList?.value),
       },
+      // {
+      //   name: '完成比',
+      //   type: 'bar',
+      //   barWidth: 44,
+      //   barGap: '-200%',
+      //   showBackground: true,
+      //   xAxisIndex: 1,
+      //   itemStyle: {
+      //     color: 'rgba(0, 186, 151,0.3)',
+      //   },
+      //   label: {
+      //     show: true,
+      //     color: '#444',
+      //     fontSize: 10,
+      //     formatter({ value }) {
+      //       return value > 0 ? `${value}%` : ''
+      //     },
+      //     position: 'insideTopRight',
+      //   },
+      //   data: getYAxisData('finishRate', subjectProgressEndList?.value),
+      // },
     ],
   }
 })

+ 26 - 0
src/utils/common.ts

@@ -1,5 +1,6 @@
 import useMainStore from '@/store/main'
 import Big from 'big.js'
+import { localStorage, sessionStorage } from '@/plugins/storage'
 /**
  * @description 是否被定义
  * @param {any} val
@@ -304,3 +305,28 @@ export const preloadImg = (url: any) => {
     images.push(img)
   }
 }
+
+export const initConfigModelData = (): any => {
+  return {
+    draft: { other: '' },
+  }
+}
+
+export const getUserConfigByType = (type: string) => {
+  const userConfig = localStorage.get('USER_CONFIG')
+  const userInfo = sessionStorage.get('LOGIN_RESULT')
+  if (userInfo?.id) {
+    return userConfig[userInfo.id][type]
+  } else {
+    return initConfigModelData()[type]
+  }
+}
+
+export const setUserConfigByType = (type: string, value: any) => {
+  const userConfig = localStorage.get('USER_CONFIG')
+  const userInfo = sessionStorage.get('LOGIN_RESULT')
+  if (userInfo?.id) {
+    userConfig[userInfo.id][type] = value
+    localStorage.set('USER_CONFIG', userConfig)
+  }
+}