|
|
@@ -3,7 +3,7 @@ import type { App, Plugin } from 'vue';
|
|
|
|
|
|
import { unref } from 'vue';
|
|
|
import { isObject } from '/@/utils/is';
|
|
|
-import { cloneDeep } from 'lodash-es';
|
|
|
+import { cloneDeep, intersectionWith } from 'lodash-es';
|
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
@@ -142,7 +142,22 @@ export function formatDictValue(options: Array<any>, value: string) {
|
|
|
return matchItem && matchItem['label'] ? matchItem['label'] : '';
|
|
|
}
|
|
|
|
|
|
-// 获取字典颜色
|
|
|
+// 获取字典值
|
|
|
+export function formatDictLabel(options: Array<any>, label: string) {
|
|
|
+ if (!label) {
|
|
|
+ if (label != '0') {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!options) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ let matchItem = '';
|
|
|
+ matchItem = options.find(item => (item['label'] as string) == label);
|
|
|
+ return matchItem && matchItem['value'] ? matchItem['value'] : '';
|
|
|
+}
|
|
|
+
|
|
|
+// 获取字典背景颜色
|
|
|
export function formatDictColor(options: Array<any>, value: string) {
|
|
|
if (!value) {
|
|
|
if (value != '0') {
|
|
|
@@ -154,7 +169,37 @@ export function formatDictColor(options: Array<any>, value: string) {
|
|
|
}
|
|
|
let matchItem = '';
|
|
|
matchItem = options.find(item => item['value'] == value);
|
|
|
- return matchItem && matchItem['color'] ? matchItem['color'] : '';
|
|
|
+ return matchItem && matchItem['bgColor'] ? matchItem['bgColor'] : '';
|
|
|
+}
|
|
|
+
|
|
|
+// 获取字典字体颜色
|
|
|
+export function formatDictFontColor(options: Array<any>, value: string) {
|
|
|
+ if (!value) {
|
|
|
+ if (value != '0') {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!options) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ let matchItem = '';
|
|
|
+ matchItem = options.find(item => item['value'] == value);
|
|
|
+ return matchItem && matchItem['fontColor'] ? matchItem['fontColor'] : '';
|
|
|
+}
|
|
|
+
|
|
|
+// 获取字典数组
|
|
|
+export function formatDictTags(options: Array<any>, value: Array<any>) {
|
|
|
+ if (!value.length) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ if (!options.length) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ const matchItem =
|
|
|
+ intersectionWith(options, value, (arrVal, othVal) => {
|
|
|
+ return arrVal.value == othVal.value;
|
|
|
+ }) || [];
|
|
|
+ return matchItem;
|
|
|
}
|
|
|
|
|
|
// 转换字典
|
|
|
@@ -210,12 +255,12 @@ export function dateRanges(format = 'YYYY-MM-DD') {
|
|
|
console.log('🚀 ~ file: index.ts:210 ~ dateRanges ~ format:', format);
|
|
|
return {
|
|
|
今天: [dayjs(), dayjs()],
|
|
|
- 本周: [dayjs(), dayjs().endOf('week')],
|
|
|
+ 本周: [dayjs().startOf('week'), dayjs().endOf('week')],
|
|
|
上周: [
|
|
|
dayjs().add(-1, 'week').startOf('week').add(1, 'day'),
|
|
|
dayjs().add(-1, 'week').endOf('week').add(1, 'day'),
|
|
|
],
|
|
|
- 本月: [dayjs(), dayjs().endOf('month')],
|
|
|
+ 本月: [dayjs().startOf('month'), dayjs().endOf('month')],
|
|
|
上月: [dayjs().add(-1, 'month').startOf('month'), dayjs().add(-1, 'month').endOf('month')],
|
|
|
// Today: [dayjs(), dayjs()],
|
|
|
// 'This Month': [dayjs(), dayjs().endOf('month')],
|