Parcourir la source

Fix: 消息long类型转换

chris il y a 3 ans
Parent
commit
84b6117a99

+ 26 - 0
src/api/util.js

@@ -79,3 +79,29 @@ export function dateToString (date) {
   }
   return year + '-' + month + '-' + day
 }
+
+export function dateTimeToString (date) {
+  let date1 = new Date(date)
+  const year = date1.getFullYear() + ''
+  let month = (date1.getMonth() + 1) + ''
+  let day = (date1.getDate()) + ''
+  let h = date1.getHours() + ''
+  let m = date1.getMinutes() + ''
+  let s = date1.getSeconds() + ''
+  if (month.length === 1) {
+    month = '0' + month
+  }
+  if (day.length === 1) {
+    day = '0' + day
+  }
+  if (h.length === 1) {
+    h = '0' + h
+  }
+  if (m.length === 1) {
+    m = '0' + m
+  }
+  if (s.length === 1) {
+    s = '0' + s
+  }
+  return year + '-' + month + '-' + day + ' ' + h + ':' + m + ':' + s
+}

+ 10 - 2
src/views/modules/msg-center/notice.vue

@@ -66,12 +66,15 @@
         label="发布人">
       </el-table-column>
       <el-table-column
-        prop="createTime"
+        prop="-"
         header-align="center"
         align="center"
         width="160"
         :show-tooltip-when-overflow="true"
         label="发布时间">
+        <template slot-scope="scope">
+          <span>{{timestampToTime(scope.row.publishTime)}}</span>
+        </template>
       </el-table-column>
       <el-table-column
         fixed="right"
@@ -90,6 +93,7 @@
 
 <script>
   import {readNotice, routeMsg} from '@/utils/msg'
+  import {dateTimeToString} from '@/api/util'
   export default {
     name: 'notice',
     created () {
@@ -127,7 +131,7 @@
       getNoticeList () {
         let msg = Object.assign([], this.$store.state.common.msgCollection)
         if (!msg) return
-        this.dataList = msg
+        this.dataList = msg.sort(item => item.publishTime).reverse()
         if (this.dataForm.title) {
           this.dataList = this.dataList.filter(item => item.title && item.title.indexOf(this.dataForm.title) !== -1)
         }
@@ -147,6 +151,10 @@
       // 查看消息
       detailHandle (row) {
         routeMsg(this, row)
+      },
+      timestampToTime (l) {
+        if (!l) return ''
+        return dateTimeToString(l)
       }
     }
   }

+ 1 - 1
src/views/modules/notice/notice.vue

@@ -85,7 +85,7 @@
         prop="publishTime"
         header-align="center"
         align="center"
-        min-width="100"
+        min-width="160"
         label="发布时间">
       </el-table-column>
       <el-table-column