Bladeren bron

修改时间格式化方法

huangbin 4 jaren geleden
bovenliggende
commit
058cda3642

+ 19 - 19
src/common/methods/format/index.ts

@@ -46,31 +46,31 @@ export function getGoodsDesc(param: string): string {
     return result.replace(/<p class=\"txt2em\"><\/p>/gi, '<p class="txt2em">&nbsp;</p>').replace(/.\/uploadFile/g, `${url}/uploadFile/`);
 }
 
-/** 日期格式化 */
-export const formatTime = (date: string) => {
-    if (date) return moment(date).format('YYYY-MM-DD HH:mm:ss');
-    return date;
-};
-
-/** 日期格式化 */
-export const formatTimeM = (date: string) => {
-    if (date) return moment(date).format('YYYY-MM-DD HH:mm');
-    return date;
-};
-
-/** 日期格式化 */
-export const formatData = (date: string) => {
-    if (date) return moment(date).format('YYYY-MM-DD');
-    return date;
-};
-
 /**
  * 格式化空字符情况,如果传入字符串且为空时候返回 --,传入数字且为空时候 返回 0,其它返回本身
  */
-export function formartValue(value: number | string) {
+export function formarValue(value: number | string) {
     if (typeof value === 'number') {
         return value ? value : 0;
     } else {
         return value ? value : '--'
     }
 }
+
+type TIME = 's' | 'm' | 'd'
+/**
+ * 格式化时间
+ * @param value 
+ * @param type 's' => 格式: YYYY-MM-DD HH:mm:ss ;  'm'  => 格式: YYYY-MM-DD HH:mm ;  'd' => 'YYYY-MM-DD'
+ * @returns 
+ */
+export function formatTime(value: string | Date, type: TIME) {
+    let str = 'YYYY-MM-DD HH:mm:ss';
+    if (type === 'd') {
+        str = 'YYYY-MM-DD HH:mm'
+    } else if (type === 'm') {
+        'YYYY-MM-DD'
+    }
+    if (value) return moment(value).format(str);
+    return value;
+}

+ 4 - 3
src/common/methods/index.ts

@@ -1,5 +1,6 @@
-import { getImg, getImgUrl, getGoodsDesc, formatTime, formatData, formatTimeM } from './format/index';
+import { formarValue, formatTime, getGoodsDesc, getImg, getImgUrl } from './format/index';
+import { cacheInitData, initData, setLoadComplete } from './mixin/index';
 import { mybuystatus, mypackstatus, signStatus } from './statusfilter/index';
-import { initData, cacheInitData, setLoadComplete } from './mixin/index';
 
-export { getImg, getImgUrl, getGoodsDesc, formatTime, initData, mybuystatus, mypackstatus, signStatus, formatData, cacheInitData, setLoadComplete, formatTimeM };
+export { getImg, getImgUrl, getGoodsDesc, initData, formatTime, formarValue, mybuystatus, mypackstatus, signStatus, cacheInitData, setLoadComplete };
+

+ 4 - 4
src/views/information/custom/compoments/detail/index.vue

@@ -22,7 +22,7 @@
         </a-col>
         <a-col :span="12">
           <a-form-item label="企业名称">
-            <span class="white">{{ formartValue(selectedRow.customername)}}</span>
+            <span class="white">{{ formarValue(selectedRow.customername)}}</span>
           </a-form-item>
         </a-col>
       </a-row>
@@ -84,7 +84,7 @@
         </a-col>
         <a-col :span="12">
           <a-form-item label="状态">
-            <span class="green">{{ formartValue(getStatusName(selectedRow.status)) }}</span>
+            <span class="green">{{ formarValue(getStatusName(selectedRow.status)) }}</span>
           </a-form-item>
         </a-col>
       </a-row>
@@ -112,7 +112,7 @@ import { closeModal } from '@/common/setup/modal/index';
 import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
 import { mergeObj } from '@/utils/objHandle';
 import { getStatusName } from '@/views/information/custom/setup';
-import { formartValue } from '@/common/methods/format';
+import { formarValue, formatTime } from '@/common/methods';
 
 export default defineComponent({
     name: 'custom-detail',
@@ -156,7 +156,7 @@ export default defineComponent({
             submit,
             loading,
             detail,
-            formartValue,
+            formarValue,
             getStatusName,
         };
     },