File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 9393
9494<script >
9595import { mapState } from ' vuex'
96+ import * as api from ' @/api/feeds.js'
97+ import { transTime } from ' @/util'
9698import FeedImage from ' ./FeedImage.vue'
9799import FeedVideo from ' ./FeedVideo.vue'
98100import CommentItem from ' ./CommentItem.vue'
99- import * as api from ' @/api/feeds.js'
100101
101102export default {
102103 name: ' FeedCard' ,
@@ -168,8 +169,7 @@ export default {
168169 },
169170 time () {
170171 let str = this .feed .created_at
171- if (typeof str === ' string' ) str = str .replace (/ -/ g , ' /' ) // 兼容 IOS 保证传入数据格式 YYYY/MM/dd HH:mm:ss
172- return new Date (str)
172+ return transTime (str)
173173 },
174174 isToday () {
175175 // 时间差 = 当前时间 - date (单位: 秒)
Original file line number Diff line number Diff line change 11import plueMessageBundle from 'plus-message-bundle'
2+ import { transTime } from '@/util'
23
34/**
45 * ThinkSNS Plus 消息解析器,获取顶部消息.
@@ -71,12 +72,7 @@ export const addTimeOffset = date => {
7172
7273export const time2tips = date => {
7374 if ( typeof date === 'string' ) {
74- date = date . replace ( / - / g, '/' ) // for safari
75- // match 2018/10/17 01:48:52"
76- if ( date . match ( / ^ \d { 4 } \/ \d { 2 } \/ \d { 2 } \d { 2 } : \d { 2 } : \d { 2 } $ / ) ) {
77- // 如果匹配到服务器返回的时间是非标准格式的祖鲁时间,需要进行本地化
78- date = + new Date ( date ) - timeOffset
79- }
75+ date = transTime ( date )
8076 }
8177 const time = new Date ( date )
8278 const offset = ( new Date ( ) . getTime ( ) - time ) / 1000
Original file line number Diff line number Diff line change 1+ import { timeOffset } from '@/filters'
2+
13/**
24 * 空函数
35 * 用于默认函数引用判断
@@ -184,3 +186,13 @@ export const generateString = length => {
184186 . toString ( 36 )
185187 . substr ( 2 , length )
186188}
189+
190+ export const transTime = ( date ) => {
191+ date = date . replace ( / - / g, '/' ) // for safari
192+ // match 2018/10/17 01:48:52"
193+ if ( date . match ( / ^ \d { 4 } \/ \d { 2 } \/ \d { 2 } \d { 2 } : \d { 2 } : \d { 2 } $ / ) ) {
194+ // 如果匹配到服务器返回的时间是非标准格式的祖鲁时间,需要进行本地化
195+ date = + new Date ( date ) - timeOffset
196+ }
197+ return new Date ( date )
198+ }
You can’t perform that action at this time.
0 commit comments