浏览代码

公用方法: 计算该日期是星期几

lxf 2 年之前
父节点
当前提交
51c3afc03f
共有 2 个文件被更改,包括 12 次插入1 次删除
  1. 2 1
      src/main.js
  2. 10 0
      src/utils/util.js

+ 2 - 1
src/main.js

@@ -44,7 +44,7 @@ import {
   selectDictLabels
 } from '@/utils/ruoyi'
 
-import { dictDataEcho, moneyFormat } from '@/utils/util'
+import { dictDataEcho, moneyFormat, calculationWeek } from '@/utils/util'
 
 // 分页组件
 import Pagination from '@/components/Pagination'
@@ -77,6 +77,7 @@ app.config.globalProperties.selectDictLabels = selectDictLabels
 //字典回显
 app.config.globalProperties.dictDataEcho = dictDataEcho
 app.config.globalProperties.moneyFormat = moneyFormat
+app.config.globalProperties.calculationWeek = calculationWeek
 
 
 

+ 10 - 0
src/utils/util.js

@@ -1,3 +1,5 @@
+import moment from "moment";
+
 //根据value值回显字典label值
 export function dictDataEcho(value, arr) {
   if (value && arr) {
@@ -37,3 +39,11 @@ export function moneyFormat(s, n) {
     return "0.00";
   }
 }
+
+// 计算该日期是星期几
+export function calculationWeek(val, format) {
+  let weekArrayList = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
+  let index = new Date(moment(val, format).format("yyyy-MM-DD")).getDay();
+  let week = weekArrayList[index];
+  return week;
+}