瀏覽代碼

时间格式化

Karsa 2 年之前
父節點
當前提交
ff5266ccb6
共有 5 個文件被更改,包括 78 次插入21 次删除
  1. 1 2
      api/message.js
  2. 3 1
      pages-activity/reportDetail.vue
  3. 1 1
      pages-report/chapterDetail.vue
  4. 1 1
      pages-report/reportDetail.vue
  5. 72 16
      pages-user/messageList.vue

+ 1 - 2
api/message.js

@@ -27,5 +27,4 @@ export const apiReadOneMessage = params => {
  */
 export const apiDelMessage = params => {
 	return httpPost('/message/delete',params)
-}
-
+}

+ 3 - 1
pages-activity/reportDetail.vue

@@ -14,7 +14,9 @@ export default {
         const eventChannel = this.getOpenerEventChannel()
         eventChannel.on('webUrl', (data)=> {
             const timestamp=new Date().getTime()
-            this.url=`${data.url}&token=${this.$store.state.user.token}&timestamp=${timestamp}`
+						
+            this.url=`${data.url}&userId=${this.userInfo.user_id}&token=${this.$store.state.user.token}&timestamp=${timestamp}`
+						
         })
     }
 }

+ 1 - 1
pages-report/chapterDetail.vue

@@ -35,7 +35,7 @@ export default {
       let fromPage=options.fromPage||''
       const timestamp=new Date().getTime()
       const token=this.$store.state.user.token
-      this.url=`${h5BaseUrl}/hzyb/report/chapterdetail?chapterId=${chapterId}&fromPage=${fromPage}&token=${token}&timestamp=${timestamp}#wechat_redirect`
+      this.url=`${h5BaseUrl}/hzyb/report/chapterdetail?chapterId=${chapterId}&userId=${this.userInfo.user_id}&fromPage=${fromPage}&token=${token}&timestamp=${timestamp}#wechat_redirect`
     },
 
     handleGetMessage(e){

+ 1 - 1
pages-report/reportDetail.vue

@@ -39,7 +39,7 @@ export default {
             let reportId=options.reportId
             const timestamp=new Date().getTime()
             const token=this.$store.state.user.token
-            this.url=`${h5BaseUrl}/hzyb/report/detail?reportId=${reportId}&token=${token}&timestamp=${timestamp}#wechat_redirect`
+            this.url=`${h5BaseUrl}/hzyb/report/detail?reportId=${reportId}&userId=${this.userInfo.user_id}&fromPage=${options.fromPage||''}&token=${token}&timestamp=${timestamp}#wechat_redirect`
         },
 
         handleGetMessage(e){

+ 72 - 16
pages-user/messageList.vue

@@ -30,14 +30,19 @@
 					<view class="left flex">
 						<image :src="item.img" mode="" class="avatar"/>
 						<view class="content">
-							<view class="text_oneLine">{{item.content_first}}</view>
+							<view class="text_oneLine" style="width: 500rpx">{{item.content_first}}</view>
 							<view class="msg text_oneLine">{{item.content_second}}</view>
-							<view class="time">{{item.content_second}}</view>
+							<view class="time">
+								{{item.create_time | formatTime}}
+							</view>
 						</view>
 					</view>
 					<text class="read-ico" v-if="!item.is_read"/>
+					<view class="detail-ico" @click="toReportDetail(item)">
+						查看详情<van-icon name="arrow"/>
+					</view>
 				</view>
-				<view class="action" @click.stop="delMessageHandle(item)">删除</view>
+				<view class="action" @click.stop="delMessageHandle(item,index)">删除</view>
 			</view>
 		</view>
 		<view class="nodata" v-else>
@@ -49,8 +54,33 @@
 </template>
 
 <script>
-import * as $message from '@/api/message'
+	import * as $message from '@/api/message.js'
+	const moment = require('../utils/moment-with-locales.min.js');
+	moment.locale('zh-cn'); 
 	export default {
+		filters: {
+			formatTime(val) {
+				const time = new Date(val);
+				const now = new Date();
+				const infer_time = parseInt((now.getTime() - time.getTime())/1000/60/60/24);//时间差
+				const infer_year = parseInt(now.getFullYear() - time.getFullYear());// 年限差
+	
+				//当天
+				if(infer_time === 0) {
+					return moment(time).format('HH:mm:ss')
+				} else if(infer_time === 1) {
+					return `昨天 ${moment(time).format('HH:mm:ss')}`
+				} else if(infer_time === 2) {
+					return `前天 ${moment(time).format('HH:mm:ss')}`
+				} else if( infer_time >=3 && infer_time <=7 ) { //周内
+					return moment(time).format('ddd HH:mm:ss')
+				} else if(infer_year === 0) {
+					return moment(time).format('MM-DD HH:mm:ss')
+				} else {
+					return moment(time).format('YYYY-MM-DD HH:mm:ss')
+				}
+			}
+		},
 		data() {
 			return {
 				default_tab: 0,
@@ -83,7 +113,7 @@ import * as $message from '@/api/message'
 			
 			/* 获取列表 */
 			async getMessageList() {
-				const { code,data } = $message.apiMessageList({ 
+				const { code,data } = await $message.apiMessageList({ 
 					type: this.default_tab,
 					current_index: this.page_no,
 					page_size: 20
@@ -93,12 +123,12 @@ import * as $message from '@/api/message'
 				const { list,paging } = data;
 				
 				this.isHaveMore = this.page_no >= paging.pages ? false : true;
-				this.messageList = this.page_no === 1 ? (list || []) : [...this.messageList,...list]
+				this.messageList = this.page_no === 1 ? (list || []) : [...this.messageList,...list];
 			},
 			
 			/* 一键已读 */
 			async allReadHandle() {
-				const { code } = $message.apiReadAll({ type: this.default_tab })
+				const { code } = await $message.apiReadAll({ type: this.default_tab })
 				if( code!==200 ) return
 				
 				this.page_no = 1;
@@ -107,19 +137,28 @@ import * as $message from '@/api/message'
 			},
 			
 			/* 删除消息 */
-			delMessageHandle() {
+			delMessageHandle({msg_id},index) {
+				const _this = this;
 				uni.showModal({
 					title: "",
 					content: "确定要删除该留言吗?",
 					confirmColor: "#6784A7",
-					success: function() {
+					success: async function() {
+						const { code } = await $message.apiReadOneMessage({ msg_id })
+						if( code!==200 ) return
 						
+						uni.showToast({
+						  title: '删除成功',
+						  icon: 'none'
+						})
+						_this.messageList.splice(index,1)
 					}
 				})
 			},
 			
 			onPullDownRefresh() {
 			    this.page_no = 1;
+					this.getMessageList()
 			    setTimeout(() => {
 			        uni.stopPullDownRefresh()
 			    }, 1500)
@@ -131,14 +170,23 @@ import * as $message from '@/api/message'
 			    this.getMessageList()
 			},
 			
+			/* 到报告详情 */
+			toReportDetail({ report_chapter_id,report_id  }) {
+				report_chapter_id 
+				? uni.navigateTo({url: `/pages-report/chapterDetail?chapterId=${report_chapter_id}&fromPage=message`})
+				: uni.navigateTo({url:`/pages-report/reportDetail?reportId=${report_id}&fromPage=message`})
+			},
+			
 			async drawStart(item,e) {
 				let touch = e.touches[0];
 				this.startX = touch.clientX;
 				
-				const { msg_id } = item;
-				const { code } = await apiReadOneMessage({ msg_id })
-				if( code!==200 ) return
-				item.is_read = 1;
+				if(!item.is_read) {
+					const { msg_id } = item;
+					const { code } = await $message.apiReadOneMessage({ msg_id })
+					if( code!==200 ) return
+					item.is_read = 1;					
+				}
 			},
 			//触摸滑动
 			drawMove(e) {
@@ -223,8 +271,9 @@ import * as $message from '@/api/message'
 				.content {
 					color: #666;
 					font-size: 28rpx;
-					width: 80%;
+					flex: 1;
 					.msg {
+						width: 500rpx;
 						color: #333;
 						font-size: 30rpx;
 						margin: 10rpx 0;
@@ -236,8 +285,8 @@ import * as $message from '@/api/message'
 				}
 			}
 			.read-ico {
-				width: 30rpx;
-				height: 30rpx;
+				width: 26rpx;
+				height: 26rpx;
 				border-radius: 50%;
 				position: absolute;
 				right: 0;
@@ -245,6 +294,13 @@ import * as $message from '@/api/message'
 				transform: translateY(-50%);
 				background-color: #D62020;
 			}
+			
+			.detail-ico {
+				position: absolute;
+				right: 0;
+				bottom: 0;
+				color: #666;
+			}
 		
 			.action {
 				width: 176rpx;