Browse Source

消息中心

jiangniuniu 4 years ago
parent
commit
f5cafd3c9b

+ 9 - 1
pages.json

@@ -52,7 +52,15 @@
                 "enablePullDownRefresh": false
             }
             
-        }
+        },
+		{
+		    "path" : "pages/messages/messages",
+		    "style" : {
+		        "navigationBarTitleText": "消息中心",
+		        "enablePullDownRefresh": false
+		    }
+		    
+		}
     ],
 	"globalStyle": {
 		"navigationStyle": "custom",

+ 1 - 1
pages/configure/configure.vue

@@ -29,7 +29,7 @@
     <view class="sure-button">
       <button @click="sureList">保存</button>
     </view>
-    <tm-tabbar :permission="1" />
+    <tm-tabbar/>
   </view>
 </template>
 

+ 3 - 3
pages/configure/server.js

@@ -4,17 +4,17 @@ const requestList = {
 	// 保存配置
 	postResultConfig: {
 		method: 'POST',
-		url: 'imed/pfm/resultConfig'
+		url: 'resultConfig'
 	},
 	//最新配置
 	getResultConfig:{
 		method: 'GET',
-		url: 'imed/pfm/resultConfig'
+		url: 'resultConfig'
 	},
 	//默认配置列表
 	getDefault:{
 		method: 'GET',
-		url: 'imed/pfm/resultConfig/default'
+		url: 'resultConfig/default'
 	}
 	
 };

+ 177 - 0
pages/messages/messages.vue

@@ -0,0 +1,177 @@
+<template>
+	<view class="messages-page">
+		<view class="contBody" @touchend="touchend" :style="MessList.length <= 8 ? {height:'calc(100% - 30rpx)'} : {}">
+			<view v-for="(item,index) in MessList" :key="index" class="messages-content" @click="toDetail(item)">
+				<view class="imgView">
+					<image :src="item.businessType == 1 ? (item.readStatus ? '/static/橙色已读.png' : '/static/橙色未读.png') : (item.readStatus ? '/static/绿色已读.png' : '/static/绿色未读.png')"></image>
+				</view>
+				<view class="contView">
+					<view class="contView-title">
+						{{item.title}}
+					</view>
+					<view class="contView-content">
+						{{item.content}}
+					</view>
+					<view class="contView-time">
+						{{item.effectTime}}
+					</view>
+				</view>
+			</view>
+			<view class="bottomPanDuan"></view>
+		</view>
+		
+		<view class="bottomTishi">
+			<view v-if="loading">
+				向上滑动加载更多!
+			</view>
+			<view v-else>
+				已经到底了~
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	import moment from 'moment';
+	export default {
+		data() {
+			return {
+				pageNum: 1,
+				pageSize: 10,
+				MessList: [],
+				loading: false,
+				currentPage: 0,
+				totalPage: 0,
+			}
+		},
+		mounted() {
+		  this.getMessList();
+		},
+		methods:{
+			getMessList(){
+				var currPage = this.currentPage + 1;
+				this.$store.dispatch({
+					type: "messages/commActions",
+					payload: {
+					  key: "messagesList",
+					  data: {
+						  pageNum: currPage,
+						  pageSize: this.pageSize,
+					  }
+					},
+				}).then(res=>{
+					this.totalPage = res.totalPage;
+					res.list.map((item)=>{
+						item.effectTime = moment(item.effectTime).format('MM-DD hh:mm')
+					})
+					//获取当前页码
+					this.currentPage = res.pageNum;
+					//当前页码与总页码进行比对
+					this.loading = this.currentPage < this.totalPage;
+					//将获得的数据拼接当前渲染数据中
+					this.MessList = this.MessList.concat(res.list);
+				})
+			},
+			touchend(){
+				if(this.currentPage < this.totalPage){
+					var box = document.getElementsByClassName('bottomPanDuan')[0];
+					var pos = box.getBoundingClientRect();
+					if(pos.bottom<=document.documentElement.clientHeight){
+						this.getMessList();
+					}
+				}
+				
+			},
+			toDetail(data){
+				this.$store.dispatch({
+					type: "messages/commActions",
+					payload: {
+					  key: "toRead",
+					  data: {
+						  id:data.id
+					  }
+					},
+				}).then(res=>{
+					uni.navigateTo({
+					  url: '/pages/mission-details/mission-details'
+					});
+					this.MessList = [];
+					for(let i = 0 ; i < this.currentPage; i++){
+						this.$store.dispatch({
+							type: "messages/commActions",
+							payload: {
+							  key: "messagesList",
+							  data: {
+								  pageNum: i,
+								  pageSize: this.pageSize,
+							  }
+							},
+						}).then(res=>{
+							this.MessList = this.MessList.concat(res.list);
+						})
+					}
+				})
+			}
+			
+		},
+		computed:{
+		}
+	}
+</script>
+
+<style lang="less">
+	.messages-page{
+		padding-top: 15rpx;
+		height: 100%;
+		overflow-y: auto;
+		.messages-content{
+			display: flex;
+			background-color: #fff;
+			.imgView{
+				margin-top: 25rpx;
+				margin-left: 25rpx;
+				margin-right: 25rpx;
+				margin-bottom: 63.75rpx;
+				width: 56.25rpx;
+				height: 56.25rpx;
+				vertical-align: top;
+				.image-circle{
+					background-color: ;
+				}
+				image{
+					width: 56.25rpx;
+					height: 90px;
+				}
+			}
+			.contView{
+				flex: 1;
+				border-bottom: 0.62rpx solid #DADEE6;
+				.contView-title{
+					margin-top:25rpx ;
+					font-size: 22.5rpx;
+					font-weight: 500;
+					color: #292C33;
+				}
+				.contView-content{
+					margin:15rpx 0 20rpx;
+					font-size: 20rpx;
+					color: #525866;
+				}
+				.contView-time{
+					margin-bottom: 25rpx;
+					font-size: 17.5rpx;
+					color: #666E80;
+				}
+			}
+		}
+		.bottomTishi{
+			padding: 6.25rpx 0px;
+			width: 100%;
+			// position: absolute;
+			// bottom: 0rpx;
+			text-align: center;
+			font-size: 17.5rpx;
+			color: #525866;
+		}
+	}
+</style>

+ 14 - 0
pages/messages/model.js

@@ -0,0 +1,14 @@
+import { commServer } from './server.js';
+
+export default {
+  namespaced: true,
+  state: {
+  },
+  mutations: {},
+  actions: {
+	commActions({ commit, state }, { payload }) {
+		// payload = {key,data} // data是请求数据,key是请求接口id
+        return commServer(payload);
+	},
+  }
+}

+ 18 - 0
pages/messages/server.js

@@ -0,0 +1,18 @@
+import { creatRequest } from '../../utils/request.js';
+
+const requestList = {
+  //获取分页列表
+  messagesList: {
+    method: 'GET',
+    url: 'notice/page'
+  },
+  //已读
+  toRead: {
+    method: 'GET',
+    url: 'notice/read'
+  },
+};
+export const commServer = ({ key, data }) => {
+  let obj = requestList[key];
+  return creatRequest(obj, data);
+}

+ 2 - 0
pages/model.js

@@ -1,6 +1,8 @@
 import login from './login/model.js';
 import configure from './configure/model.js';
+import messages from  './messages/model.js';
 export default module = {
   login,
   configure,
+  messages,
 }

BIN
static/橙色已读.png


BIN
static/橙色未读.png


BIN
static/绿色已读.png


BIN
static/绿色未读.png


+ 1 - 1
utils/request.js

@@ -8,7 +8,7 @@
 import { URL } from "./requestUrl";
 import { stringify } from 'qs';
 
-const BASE_URL = `${URL}/`;
+const BASE_URL = `${URL}/imed/pfm/`;
 let AllRequestNum = 0; // 存放请求数,以保证有请求未返回就持续loading
 
 /**

+ 116 - 0
utils/ws.js

@@ -0,0 +1,116 @@
+//心跳检测
+const heartCheck = {
+  timeout: 10000, //10s发一次心跳
+  timeoutObj: null,
+  serverTimeoutObj: null,
+  start(ws) {
+    let self = this;
+    this.timeoutObj && clearTimeout(this.timeoutObj);
+    this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
+    this.timeoutObj = setTimeout(() => {
+      // 表示连接已经关闭或者连接不能打开。
+      if (ws && ws.readyState === 3) return;
+      //发送一个心跳,后端收到后,返回一个心跳消息,onmessage拿到返回的心跳就说明连接正常
+      ws && ws.send({data: "ping"});
+      self.serverTimeoutObj = setTimeout(() => {
+        ws && ws.close();
+                websocket.reconnect();
+      }, self.timeout + 3000);
+    }, this.timeout);
+  }
+};
+ 
+const websocket = {
+  ws: null,
+  url: '',
+  connected: false,
+  connecting: false,
+  reconnectTimeId: null,
+    callback: null, // 存放回调函数
+    reconnetCount: 0, // 重连次数
+  lockReconnect: false, // 避免ws重复连接
+  createWebSocket(callback) {
+    if (this.connected || this.connecting) { // 正在连接或者已经连接,请勿重复连接
+      return false
+    }
+    try {
+            if (callback) websocket.callback = callback;
+      this.connecting = true;
+      // 创建
+      this.ws = uni.connectSocket({
+        url: this.url,
+        success(data) {
+          // console.log("websocket连接成功!");
+        }
+      });
+      // 监听 Ws 连接打开
+      this.ws.onOpen((res) => {
+        this.connecting = false;
+        this.connected = true;
+        // console.log("websocket连接打开正常!");
+        //心跳检测重置
+        heartCheck.start(this.ws);
+                this.reconnetCount && (this.reconnetCount = 0);
+      });
+      this.ws.onError((res) => {
+        this.connecting = false;
+        this.connected = false;
+        // console.log("ws连接错误!", res);
+        this.reconnect();
+      });
+      this.ws.onMessage((res) => {
+            if (res.data === 'ping') {
+              heartCheck.start(this.ws); //获取到消息,心跳检测重置
+              this.reconnetCount && (this.reconnetCount = 0);
+            } else {
+          const { type, data } = JSON.parse(res.data);
+          // console.log("ws 收到消息啦:" + type);
+          if (callback) {
+            callback(type, data);
+          } else if (websocket.callback) {
+            websocket.callback(type, data);
+          }
+        }
+      });
+      this.ws.onClose((res) => {
+        this.connected = false;
+        this.ws = null;
+        // console.log('WebSocket 已关闭!');
+        // this.reconnect();
+      });
+    } catch (e) {// 重连
+      this.connected = false;
+      this.ws = null;
+      this.reconnect();
+    }
+  },
+  reconnect() { // 重连
+    if (this.lockReconnect) return;
+        if (this.reconnetCount === 6) {
+          this.close();
+          return
+        }
+    this.lockReconnect = true;
+        this.reconnetCount++;
+    this.reconnectTimeId && clearTimeout(this.reconnectTimeId);
+    this.reconnectTimeId = setTimeout(() => {//没连接上会一直重连,设置延迟避免请求过多
+      this.createWebSocket(websocket.callback);
+      this.lockReconnect = false;
+    }, 3000);
+  },
+  close() { // 关闭
+    if (this.ws && this.ws.close) {
+      this.ws.close && this.ws.close();
+      this.ws = null;
+    }
+        this.connected = false;
+        this.connecting = false;
+        this.lockReconnect = false;
+        this.reconnetCount = 0;
+        this.reconnectTimeId && clearTimeout(this.reconnectTimeId);
+        heartCheck.timeoutObj && clearTimeout(heartCheck.timeoutObj);
+        heartCheck.serverTimeoutObj && clearTimeout(heartCheck.serverTimeoutObj);
+  }
+}
+ 
+export default websocket;

+ 1 - 0
utils/wsUrl.js

@@ -0,0 +1 @@
+export const wsURL = `ws://192.168.1.45:8088/websocket/${hiId}/${user}/${permission}`;