Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit de90b07b
authored
Aug 09, 2024
by
Li Kui
Committed by
GitHub
Aug 09, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: menu-badge color not correct (#4089)
1 parent
3f04f6b0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
8 deletions
packages/@core/base/shared/src/color/convert.test.ts
packages/@core/base/shared/src/color/convert.ts
packages/@core/ui-kit/shadcn-ui/src/components/menu-badge/menu-badge.vue
packages/@core/base/shared/src/color/convert.test.ts
View file @
de90b07
import
{
describe
,
expect
,
it
}
from
'vitest'
;
import
{
describe
,
expect
,
it
}
from
'vitest'
;
import
{
convertToHsl
,
convertToHslCssVar
,
convertToRgb
}
from
'./convert'
;
import
{
convertToHsl
,
convertToHslCssVar
,
convertToRgb
,
isValidColor
,
}
from
'./convert'
;
describe
(
'color conversion functions'
,
()
=>
{
describe
(
'color conversion functions'
,
()
=>
{
it
(
'should correctly convert color to HSL format'
,
()
=>
{
it
(
'should correctly convert color to HSL format'
,
()
=>
{
...
@@ -39,3 +44,15 @@ describe('color conversion functions', () => {
...
@@ -39,3 +44,15 @@ describe('color conversion functions', () => {
expect
(
convertToRgb
(
color
)).
toEqual
(
expectedRgba
);
expect
(
convertToRgb
(
color
)).
toEqual
(
expectedRgba
);
});
});
});
});
describe
(
'isValidColor'
,
()
=>
{
it
(
'isValidColor function'
,
()
=>
{
// 测试有效颜色
expect
(
isValidColor
(
'blue'
)).
toBe
(
true
);
expect
(
isValidColor
(
'#000000'
)).
toBe
(
true
);
// 测试无效颜色
expect
(
isValidColor
(
'invalid color'
)).
toBe
(
false
);
expect
(
isValidColor
()).
toBe
(
false
);
});
});
packages/@core/base/shared/src/color/convert.ts
View file @
de90b07
...
@@ -41,4 +41,22 @@ function convertToRgb(str: string): string {
...
@@ -41,4 +41,22 @@ function convertToRgb(str: string): string {
return
new
TinyColor
(
str
.
replaceAll
(
/deg|grad|rad|turn/g
,
''
)).
toRgbString
();
return
new
TinyColor
(
str
.
replaceAll
(
/deg|grad|rad|turn/g
,
''
)).
toRgbString
();
}
}
export
{
convertToHsl
,
convertToHslCssVar
,
convertToRgb
,
TinyColor
};
/**
* 检查颜色是否有效
* @param {string} color - 待检查的颜色
* 如果颜色有效返回true,否则返回false
*/
function
isValidColor
(
color
?:
string
)
{
if
(
!
color
)
{
return
false
;
}
return
new
TinyColor
(
color
).
isValid
;
}
export
{
convertToHsl
,
convertToHslCssVar
,
convertToRgb
,
isValidColor
,
TinyColor
,
};
packages/@core/ui-kit/shadcn-ui/src/components/menu-badge/menu-badge.vue
View file @
de90b07
...
@@ -3,7 +3,7 @@ import type { MenuRecordBadgeRaw } from '@vben-core/typings';
...
@@ -3,7 +3,7 @@ import type { MenuRecordBadgeRaw } from '@vben-core/typings';
import
{
computed
}
from
'vue'
;
import
{
computed
}
from
'vue'
;
import
{
convertToRgb
}
from
'@vben-core/shared'
;
import
{
isValidColor
}
from
'@vben-core/shared'
;
import
BadgeDot
from
'./menu-badge-dot.vue'
;
import
BadgeDot
from
'./menu-badge-dot.vue'
;
...
@@ -15,10 +15,10 @@ const props = withDefaults(defineProps<Props>(), {});
...
@@ -15,10 +15,10 @@ const props = withDefaults(defineProps<Props>(), {});
const
variantsMap
:
Record
<
string
,
string
>
=
{
const
variantsMap
:
Record
<
string
,
string
>
=
{
default
:
'bg-green-500'
,
default
:
'bg-green-500'
,
destructive
:
'
bg-destructive'
,
destructive
:
'bg-destructive'
,
primary
:
'bg-primary'
,
primary
:
'bg-primary'
,
success
:
'
bg-green-500'
,
success
:
'bg-green-500'
,
warning
:
'
bg-yellow-500'
,
warning
:
'bg-yellow-500'
,
};
};
const
isDot
=
computed
(()
=>
props
.
badgeType
===
'dot'
);
const
isDot
=
computed
(()
=>
props
.
badgeType
===
'dot'
);
...
@@ -34,9 +34,9 @@ const badgeClass = computed(() => {
...
@@ -34,9 +34,9 @@ const badgeClass = computed(() => {
});
});
const
badgeStyle
=
computed
(()
=>
{
const
badgeStyle
=
computed
(()
=>
{
if
(
badgeClass
.
value
)
{
if
(
badgeClass
.
value
&&
isValidColor
(
badgeClass
.
value
)
)
{
return
{
return
{
backgroundColor
:
convertToRgb
(
badgeClass
.
value
)
,
backgroundColor
:
badgeClass
.
value
,
};
};
}
}
return
{};
return
{};
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment