Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
e8fe6a92
提交
e8fe6a92
authored
3月 09, 2021
作者:
Vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perf(icon): icon and SvgIcon integration
上级
9e3adaa3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
21 行删除
+33
-21
index.vue
src/components/Icon/src/index.vue
+33
-21
没有找到文件。
src/components/Icon/src/index.vue
浏览文件 @
e8fe6a92
<
template
>
<
template
>
<span
ref=
"elRef"
:class=
"[$attrs.class, 'app-iconify anticon']"
:style=
"getWrapStyle"
></span>
<SvgIcon
:size=
"size"
:name=
"getSvgIcon"
v-if=
"isSvgIcon"
:class=
"[$attrs.class]"
/>
<span
v-else
ref=
"elRef"
:class=
"[$attrs.class, 'app-iconify anticon']"
:style=
"getWrapStyle"
></span>
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
type
{
PropType
}
from
'vue'
;
import
type
{
PropType
}
from
'vue'
;
...
@@ -13,12 +19,16 @@
...
@@ -13,12 +19,16 @@
computed
,
computed
,
CSSProperties
,
CSSProperties
,
}
from
'vue'
;
}
from
'vue'
;
import
SvgIcon
from
'./SvgIcon.vue'
;
import
Iconify
from
'@purge-icons/generated'
;
import
Iconify
from
'@purge-icons/generated'
;
import
{
isString
}
from
'/@/utils/is'
;
import
{
isString
}
from
'/@/utils/is'
;
import
{
propTypes
}
from
'/@/utils/propTypes'
;
import
{
propTypes
}
from
'/@/utils/propTypes'
;
const
SVG_END_WITH_FLAG
=
'|svg'
;
export
default
defineComponent
({
export
default
defineComponent
({
name
:
'GIcon'
,
name
:
'GIcon'
,
components
:
{
SvgIcon
},
props
:
{
props
:
{
// icon name
// icon name
icon
:
propTypes
.
string
,
icon
:
propTypes
.
string
,
...
@@ -34,28 +44,30 @@
...
@@ -34,28 +44,30 @@
setup
(
props
)
{
setup
(
props
)
{
const
elRef
=
ref
<
ElRef
>
(
null
);
const
elRef
=
ref
<
ElRef
>
(
null
);
const
getIconRef
=
computed
(()
=>
{
const
isSvgIcon
=
computed
(()
=>
props
.
icon
?.
endsWith
(
SVG_END_WITH_FLAG
));
const
{
icon
,
prefix
}
=
props
;
const
getSvgIcon
=
computed
(()
=>
props
.
icon
.
replace
(
SVG_END_WITH_FLAG
,
''
));
return
`
${
prefix
?
prefix
+
':'
:
''
}${
icon
}
`
;
const
getIconRef
=
computed
(()
=>
`
${
props
.
prefix
?
props
.
prefix
+
':'
:
''
}${
props
.
icon
}
`
);
});
const
update
=
async
()
=>
{
const
update
=
async
()
=>
{
if
(
unref
(
isSvgIcon
))
return
;
const
el
=
unref
(
elRef
);
const
el
=
unref
(
elRef
);
if
(
el
)
{
if
(
!
el
)
return
;
await
nextTick
();
const
icon
=
unref
(
getIconRef
);
await
nextTick
();
if
(
!
icon
)
return
;
const
icon
=
unref
(
getIconRef
);
const
svg
=
Iconify
.
renderSVG
(
icon
,
{});
if
(
!
icon
)
return
;
if
(
svg
)
{
el
.
textContent
=
''
;
const
svg
=
Iconify
.
renderSVG
(
icon
,
{});
el
.
appendChild
(
svg
);
if
(
svg
)
{
}
else
{
el
.
textContent
=
''
;
const
span
=
document
.
createElement
(
'span'
);
el
.
appendChild
(
svg
);
span
.
className
=
'iconify'
;
}
else
{
span
.
dataset
.
icon
=
icon
;
const
span
=
document
.
createElement
(
'span'
);
el
.
textContent
=
''
;
span
.
className
=
'iconify'
;
el
.
appendChild
(
span
);
span
.
dataset
.
icon
=
icon
;
}
el
.
textContent
=
''
;
el
.
appendChild
(
span
);
}
}
};
};
...
@@ -78,7 +90,7 @@
...
@@ -78,7 +90,7 @@
onMounted
(
update
);
onMounted
(
update
);
return
{
elRef
,
getWrapStyle
};
return
{
elRef
,
getWrapStyle
,
isSvgIcon
,
getSvgIcon
};
},
},
});
});
</
script
>
</
script
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论