mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
perf: useRenderIcon
hooks
This commit is contained in:
parent
3676014eb6
commit
a9a8115d46
@ -1,8 +1,14 @@
|
|||||||
|
import { iconType } from "./types";
|
||||||
import { h, defineComponent, Component } from "vue";
|
import { h, defineComponent, Component } from "vue";
|
||||||
import { IconifyIconOffline, FontIcon } from "../index";
|
import { IconifyIconOffline, FontIcon } from "../index";
|
||||||
|
|
||||||
// 支持fontawesome4、5+、iconfont、remixicon、element-plus的icons、自定义svg
|
/**
|
||||||
export function useRenderIcon(icon: string): Component {
|
* 支持fontawesome4、5+、iconfont、remixicon、element-plus的icons、自定义svg
|
||||||
|
* @param icon 必传 string 图标
|
||||||
|
* @param attrs 可选 iconType 属性
|
||||||
|
* @returns Component
|
||||||
|
*/
|
||||||
|
export function useRenderIcon(icon: string, attrs?: iconType): Component {
|
||||||
// iconfont
|
// iconfont
|
||||||
const ifReg = /^IF-/;
|
const ifReg = /^IF-/;
|
||||||
// typeof icon === "function" 属于SVG
|
// typeof icon === "function" 属于SVG
|
||||||
@ -19,7 +25,8 @@ export function useRenderIcon(icon: string): Component {
|
|||||||
render() {
|
render() {
|
||||||
return h(FontIcon, {
|
return h(FontIcon, {
|
||||||
icon: iconName,
|
icon: iconName,
|
||||||
iconType
|
iconType,
|
||||||
|
...attrs
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -31,7 +38,8 @@ export function useRenderIcon(icon: string): Component {
|
|||||||
name: "Icon",
|
name: "Icon",
|
||||||
render() {
|
render() {
|
||||||
return h(IconifyIconOffline, {
|
return h(IconifyIconOffline, {
|
||||||
icon: icon
|
icon: icon,
|
||||||
|
...attrs
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
18
src/components/ReIcon/src/types.ts
Normal file
18
src/components/ReIcon/src/types.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export interface iconType {
|
||||||
|
// iconify (https://docs.iconify.design/icon-components/vue/#properties)
|
||||||
|
inline?: boolean;
|
||||||
|
width?: string | number;
|
||||||
|
height?: string | number;
|
||||||
|
horizontalFlip?: boolean;
|
||||||
|
verticalFlip?: boolean;
|
||||||
|
flip?: string;
|
||||||
|
rotate?: number | string;
|
||||||
|
color?: string;
|
||||||
|
horizontalAlign?: boolean;
|
||||||
|
verticalAlign?: boolean;
|
||||||
|
align?: string;
|
||||||
|
onLoad?: Function;
|
||||||
|
|
||||||
|
// all icon
|
||||||
|
style?: object;
|
||||||
|
}
|
@ -7,6 +7,7 @@ export default {
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, unref } from "vue";
|
import { ref, unref } from "vue";
|
||||||
import { storageSession } from "/@/utils/storage";
|
import { storageSession } from "/@/utils/storage";
|
||||||
|
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
|
||||||
|
|
||||||
let purview = ref<string>(storageSession.getItem("info").username);
|
let purview = ref<string>(storageSession.getItem("info").username);
|
||||||
|
|
||||||
@ -36,6 +37,11 @@ function changRole() {
|
|||||||
查看左侧菜单变化(系统管理),模拟后台根据不同角色返回对应路由
|
查看左侧菜单变化(系统管理),模拟后台根据不同角色返回对应路由
|
||||||
</p>
|
</p>
|
||||||
</h4>
|
</h4>
|
||||||
<el-button type="primary" @click="changRole">切换角色</el-button>
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
@click="changRole"
|
||||||
|
:icon="useRenderIcon('user', { color: '#fff' })"
|
||||||
|
>切换角色</el-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user