|
@@ -1,20 +1,28 @@
|
|
<template>
|
|
<template>
|
|
<!-- #ifdef APP-NVUE -->
|
|
<!-- #ifdef APP-NVUE -->
|
|
- <text :style="{ color: color, 'font-size': size + 'px' }" class="uni-icons" @click="_onClick">{{unicode}}</text>
|
|
|
|
|
|
+ <text :style="styleObj" class="uni-icons" @click="_onClick">{{unicode}}</text>
|
|
<!-- #endif -->
|
|
<!-- #endif -->
|
|
<!-- #ifndef APP-NVUE -->
|
|
<!-- #ifndef APP-NVUE -->
|
|
- <text :style="{ color: color, 'font-size': size + 'px' }" class="uni-icons" :class="['uniui-'+type,customPrefix,customPrefix?type:'']" @click="_onClick"></text>
|
|
|
|
|
|
+ <text :style="styleObj" class="uni-icons" :class="['uniui-'+type,customPrefix,customPrefix?type:'']" @click="_onClick">
|
|
|
|
+ <slot></slot>
|
|
|
|
+ </text>
|
|
<!-- #endif -->
|
|
<!-- #endif -->
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
- import icons from './icons.js';
|
|
|
|
|
|
+ import { fontData } from './uniicons_file_vue.js';
|
|
|
|
+
|
|
|
|
+ const getVal = (val) => {
|
|
|
|
+ const reg = /^[0-9]*$/g
|
|
|
|
+ return (typeof val === 'number' || reg.test(val)) ? val + 'px' : val;
|
|
|
|
+ }
|
|
|
|
+
|
|
// #ifdef APP-NVUE
|
|
// #ifdef APP-NVUE
|
|
var domModule = weex.requireModule('dom');
|
|
var domModule = weex.requireModule('dom');
|
|
import iconUrl from './uniicons.ttf'
|
|
import iconUrl from './uniicons.ttf'
|
|
domModule.addRule('fontFace', {
|
|
domModule.addRule('fontFace', {
|
|
'fontFamily': "uniicons",
|
|
'fontFamily': "uniicons",
|
|
- 'src': "url('"+iconUrl+"')"
|
|
|
|
|
|
+ 'src': "url('" + iconUrl + "')"
|
|
});
|
|
});
|
|
// #endif
|
|
// #endif
|
|
|
|
|
|
@@ -30,7 +38,7 @@
|
|
*/
|
|
*/
|
|
export default {
|
|
export default {
|
|
name: 'UniIcons',
|
|
name: 'UniIcons',
|
|
- emits:['click'],
|
|
|
|
|
|
+ emits: ['click'],
|
|
props: {
|
|
props: {
|
|
type: {
|
|
type: {
|
|
type: String,
|
|
type: String,
|
|
@@ -44,23 +52,36 @@
|
|
type: [Number, String],
|
|
type: [Number, String],
|
|
default: 16
|
|
default: 16
|
|
},
|
|
},
|
|
- customPrefix:{
|
|
|
|
|
|
+ customPrefix: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: ''
|
|
|
|
+ },
|
|
|
|
+ fontFamily: {
|
|
type: String,
|
|
type: String,
|
|
default: ''
|
|
default: ''
|
|
}
|
|
}
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- icons: icons.glyphs
|
|
|
|
|
|
+ icons: fontData
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- computed:{
|
|
|
|
- unicode(){
|
|
|
|
- let code = this.icons.find(v=>v.font_class === this.type)
|
|
|
|
- if(code){
|
|
|
|
- return unescape(`%u${code.unicode}`)
|
|
|
|
|
|
+ computed: {
|
|
|
|
+ unicode() {
|
|
|
|
+ let code = this.icons.find(v => v.font_class === this.type)
|
|
|
|
+ if (code) {
|
|
|
|
+ return code.unicode
|
|
}
|
|
}
|
|
return ''
|
|
return ''
|
|
|
|
+ },
|
|
|
|
+ iconSize() {
|
|
|
|
+ return getVal(this.size)
|
|
|
|
+ },
|
|
|
|
+ styleObj() {
|
|
|
|
+ if (this.fontFamily !== '') {
|
|
|
|
+ return `color: ${this.color}; font-size: ${this.iconSize}; font-family: ${this.fontFamily};`
|
|
|
|
+ }
|
|
|
|
+ return `color: ${this.color}; font-size: ${this.iconSize};`
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -74,9 +95,10 @@
|
|
<style lang="scss">
|
|
<style lang="scss">
|
|
/* #ifndef APP-NVUE */
|
|
/* #ifndef APP-NVUE */
|
|
@import './uniicons.css';
|
|
@import './uniicons.css';
|
|
|
|
+
|
|
@font-face {
|
|
@font-face {
|
|
font-family: uniicons;
|
|
font-family: uniicons;
|
|
- src: url('./uniicons.ttf') format('truetype');
|
|
|
|
|
|
+ src: url('./uniicons.ttf');
|
|
}
|
|
}
|
|
|
|
|
|
/* #endif */
|
|
/* #endif */
|
|
@@ -85,5 +107,4 @@
|
|
text-decoration: none;
|
|
text-decoration: none;
|
|
text-align: center;
|
|
text-align: center;
|
|
}
|
|
}
|
|
-
|
|
|
|
</style>
|
|
</style>
|