ZaiZai пре 2 година
родитељ
комит
0524d2d521
3 измењених фајлова са 17 додато и 2 уклоњено
  1. 5 1
      App.vue
  2. 4 0
      pages/index/index.vue
  3. 8 1
      store/index.js

+ 5 - 1
App.vue

@@ -86,6 +86,7 @@
             },
             initWebSocket(user_id) {
                 const _this = this
+                const store = useAppStore()
                 uni.connectSocket({
                     url: getWssApiUrl() + user_id,
                     complete: ()=> {
@@ -110,7 +111,10 @@
                 //收到的消息
                 uni.onSocketMessage(({data}) => {
                     const countData = isString(data) ? JSON.parse(data) : {}
-                    console.log(countData)
+                    if (!isNullES(countData)) {
+                        console.log(countData)
+                        store.setMsgCountData(countData)
+                    }
                 });
             },
             sendSocketMessage() {

+ 4 - 0
pages/index/index.vue

@@ -9,6 +9,9 @@
                 </view>
             </view>
         </template>
+        <view class="relative px-5" v-if="msgCountData.taskCount > 0">
+            <uni-notice-bar show-icon :text="`您有${msgCountData.taskCount}条待办任务,请注意及时处理`" />
+        </view>
         <template v-if="!isListType">
             <view class="hc-flex-conten mt-4">
                 <view class="left-col-card-1" :class="isAnimation?'is-animation':''" @click="isDataFill">
@@ -214,6 +217,7 @@ const hobby = [{text: '以后忽略此页面提示', value: 0}]
 
 //是否动画
 const isAnimation = ref(store.isAnimation)
+const msgCountData = ref(store.msgCountData)
 
 onShow(()=>{
     if(store.isAnimation) {

+ 8 - 1
store/index.js

@@ -15,7 +15,9 @@ export const useAppStore = defineStore('main', {
         contractInfo: getStorage('contractInfo') ?? {},
         projectId: getStorage('projectId') ?? '',
         contractId: getStorage('contractId') ?? '',
-        isAnimation: getStorage('isAnimation') ?? false
+        isAnimation: getStorage('isAnimation') ?? false,
+        //消息数据
+        msgCountData: getStorage('msgCountData') ?? {}
     }),
     actions: {
         //系统信息
@@ -52,6 +54,10 @@ export const useAppStore = defineStore('main', {
             this.isAnimation = value
             setStorage('isAnimation', value)
         },
+        setMsgCountData(value) {
+            this.msgCountData = value
+            setStorage('msgCountData', value)
+        },
         //清除缓存和token
         clearStoreData() {
             //清除状态
@@ -64,6 +70,7 @@ export const useAppStore = defineStore('main', {
             this.contractInfo = {}
             this.projectId = ''
             this.contractId = ''
+            this.msgCountData = {}
             clearStorage()
         },
     }