feat:x-icon

main
向文可 4 years ago
parent 5e535e0de0
commit c8fca257b6

@ -0,0 +1,16 @@
module.exports = {
printWidth: 120,
tabWidth: 4,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: 'as-needed',
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: true,
bracketSameLine: false,
arrowParens: 'always',
htmlWhitespaceSensitivity: 'ignore',
vueIndentScriptAndStyle: true,
endOfLine: 'auto',
};

@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"moduleResolution": "Node",
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
"exclude": ["node_modules"]
}

@ -1,28 +1,37 @@
{
"name": "russia-block",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.25"
},
"devDependencies": {
"@originjs/vite-plugin-global-style": "^1.0.2",
"@types/node": "^17.0.21",
"@vitejs/plugin-legacy": "^1.7.1",
"@vitejs/plugin-vue": "^2.2.0",
"@vitejs/plugin-vue-jsx": "^1.3.8",
"consola": "^2.15.3",
"less": "^4.1.2",
"unplugin-auto-import": "^0.6.4",
"unplugin-vue-components": "^0.18.0",
"vite": "^2.8.0",
"vite-plugin-remove-console": "^0.0.6",
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svg-icons": "^2.0.1"
}
"name": "russia-block",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@element-plus/icons": "^0.0.11",
"axios": "^0.26.1",
"dayjs": "^1.11.0",
"element-plus": "^2.1.2",
"lodash": "^4.17.21",
"qs": "^6.10.3",
"sortablejs": "^1.14.0",
"vue": "^3.2.25",
"vue-router": "^4.0.14",
"vuex": "^4.0.2"
},
"devDependencies": {
"@originjs/vite-plugin-global-style": "^1.0.2",
"@types/node": "^17.0.21",
"@vitejs/plugin-legacy": "^1.7.1",
"@vitejs/plugin-vue": "^2.2.0",
"@vitejs/plugin-vue-jsx": "^1.3.8",
"consola": "^2.15.3",
"less": "^4.1.2",
"unplugin-auto-import": "^0.6.4",
"unplugin-vue-components": "^0.18.0",
"vite": "^2.8.0",
"vite-plugin-remove-console": "^0.0.6",
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svg-icons": "^2.0.1"
}
}

@ -1,8 +1,10 @@
<template>
<div id="app">
<h1>
<SvgIcon name="vue" color="red" size="30"></SvgIcon><span>马士兵严选</span
><SvgIcon name="msb" size="30"></SvgIcon>
<span>马士兵严选</span>
<XIcon name="vue" svg color="red" size="30" />
<XIcon name="msb" svg size="30"></XIcon>
<XIcon name="app-store" size="30" />
</h1>
</div>
</template>

@ -4,7 +4,9 @@
declare module 'vue' {
export interface GlobalComponents {
ElIcon: typeof import('element-plus/es')['ElIcon']
SvgIcon: typeof import('./components/SvgIcon.vue')['default']
XIcon: typeof import('./components/XIcon.vue')['default']
}
}

@ -1,42 +0,0 @@
<template>
<svg class="svg-icon" aria-hidden="true">
<use :href="symbolId" :fill="color" />
</svg>
</template>
<script>
export default defineComponent({
name: 'SvgIcon',
props: {
prefix: {
type: String,
default: 'icon',
},
name: {
type: String,
required: true,
},
color: {
type: String,
default: '#333',
},
size: {
type: [Number, String],
default: 16,
},
},
setup(props) {
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
const size = computed(() =>
typeof new Number(props.size) !== Number.NaN ? props.size + 'px' : props.size
);
return { symbolId, size };
},
});
</script>
<style lang="less" scoped>
.svg-icon {
width: v-bind(size);
height: v-bind(size);
}
</style>

@ -0,0 +1,58 @@
<template>
<template v-if="name">
<i v-if="isRemix" class="x-icon" :class="'x-icon-' + name" v-bind="{ ...$props, ...$attrs }"></i>
<svg v-else-if="svg" class="x-icon" aria-hidden="true">
<use :href="symbolId" :fill="color" />
</svg>
<el-icon v-else class="x-icon">
<component :is="name" v-bind="{ ...$props, ...$attrs }" />
</el-icon>
</template>
</template>
<script>
export default defineComponent({
name: 'XIcon',
props: {
name: {
type: String,
default: '',
},
size: {
type: [String, Number],
default: 14,
},
svg: {
type: Boolean,
default: false,
},
color: {
type: String,
default: 'inherit',
},
},
setup(props) {
const symbolId = computed(() => `#icon-${props.name}`);
const size = computed(() =>
typeof new Number(props.size) !== Number.NaN ? props.size + 'px' : props.size
);
const isRemix = computed(() => props.name.indexOf('-') !== -1 || props.isCustomSvg);
return {
symbolId,
size,
color: props.color,
isRemix,
};
},
});
</script>
<style lang="less" scoped>
.x-icon {
font-size: v-bind(size);
color: v-bind(color);
}
svg.x-icon {
width: v-bind(size);
height: v-bind(size);
}
</style>

@ -0,0 +1,2 @@
import 'virtual:svg-icons-register';
import '@/icons/remixicon.less';

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 1.1 MiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 877 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

@ -0,0 +1,4 @@
const fs = require('fs');
let data = fs.readFileSync('./remixicon.less').toString();
let res = data.match(/(?<=\.x-icon-).*?(?=:before)/g);
fs.writeFileSync('index.json', JSON.stringify(res));

@ -1,6 +1,6 @@
import { createApp } from 'vue';
import App from './App.vue';
import 'virtual:svg-icons-register';
import '@/icons';
createApp(App).mount('#app');

@ -30,7 +30,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
vue(),
vueJsx(),
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), 'src/icons')],
iconDirs: [resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]',
}),
createStyleImportPlugin({

Loading…
Cancel
Save