uview-pro 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +6 -0
- package/components/u-action-sheet/u-action-sheet.vue +205 -0
- package/components/u-alert-tips/u-alert-tips.vue +241 -0
- package/components/u-avatar/u-avatar.vue +220 -0
- package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
- package/components/u-avatar-cropper/weCropper.d.ts +54 -0
- package/components/u-avatar-cropper/weCropper.js +1267 -0
- package/components/u-avatar-cropper/weCropper.ts +1254 -0
- package/components/u-back-top/u-back-top.vue +156 -0
- package/components/u-badge/u-badge.vue +189 -0
- package/components/u-button/u-button.vue +562 -0
- package/components/u-calendar/u-calendar.vue +725 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
- package/components/u-card/u-card.vue +240 -0
- package/components/u-cell-group/u-cell-group.vue +56 -0
- package/components/u-cell-item/u-cell-item.vue +245 -0
- package/components/u-checkbox/u-checkbox.vue +310 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
- package/components/u-circle-progress/u-circle-progress.vue +210 -0
- package/components/u-col/u-col.vue +135 -0
- package/components/u-collapse/u-collapse.vue +82 -0
- package/components/u-collapse-item/u-collapse-item.vue +190 -0
- package/components/u-column-notice/u-column-notice.vue +264 -0
- package/components/u-count-down/u-count-down.vue +333 -0
- package/components/u-count-to/u-count-to.vue +297 -0
- package/components/u-divider/u-divider.vue +141 -0
- package/components/u-dropdown/u-dropdown.vue +311 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
- package/components/u-empty/u-empty.vue +111 -0
- package/components/u-field/u-field.vue +469 -0
- package/components/u-form/u-form.vue +162 -0
- package/components/u-form-item/u-form-item.vue +476 -0
- package/components/u-full-screen/u-full-screen.vue +80 -0
- package/components/u-gap/u-gap.vue +48 -0
- package/components/u-grid/u-grid.vue +101 -0
- package/components/u-grid-item/u-grid-item.vue +136 -0
- package/components/u-icon/u-icon.vue +389 -0
- package/components/u-image/types.ts +48 -0
- package/components/u-image/u-image.vue +218 -0
- package/components/u-index-anchor/u-index-anchor.vue +101 -0
- package/components/u-index-list/u-index-list.vue +376 -0
- package/components/u-input/u-input.vue +462 -0
- package/components/u-keyboard/u-keyboard.vue +188 -0
- package/components/u-lazy-load/u-lazy-load.vue +288 -0
- package/components/u-line/u-line.vue +71 -0
- package/components/u-line-progress/u-line-progress.vue +128 -0
- package/components/u-link/u-link.vue +87 -0
- package/components/u-loading/u-loading.vue +111 -0
- package/components/u-loadmore/u-loadmore.vue +205 -0
- package/components/u-mask/u-mask.vue +137 -0
- package/components/u-message-input/u-message-input.vue +315 -0
- package/components/u-modal/u-modal.vue +284 -0
- package/components/u-navbar/u-navbar.vue +314 -0
- package/components/u-no-network/image.ts +2 -0
- package/components/u-no-network/u-no-network.vue +311 -0
- package/components/u-notice-bar/u-notice-bar.vue +274 -0
- package/components/u-number-box/u-number-box.vue +344 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
- package/components/u-parse/libs/CssHandler.js +100 -0
- package/components/u-parse/libs/MpHtmlParser.js +580 -0
- package/components/u-parse/libs/config.js +80 -0
- package/components/u-parse/libs/handler.wxs +22 -0
- package/components/u-parse/libs/trees.vue +505 -0
- package/components/u-parse/u-parse.vue +645 -0
- package/components/u-picker/u-picker.vue +808 -0
- package/components/u-popup/u-popup.vue +404 -0
- package/components/u-radio/u-radio.vue +272 -0
- package/components/u-radio-group/u-radio-group.vue +116 -0
- package/components/u-rate/u-rate.vue +349 -0
- package/components/u-read-more/u-read-more.vue +199 -0
- package/components/u-row/u-row.vue +95 -0
- package/components/u-row-notice/u-row-notice.vue +273 -0
- package/components/u-search/u-search.vue +298 -0
- package/components/u-section/u-section.vue +175 -0
- package/components/u-select/u-select.vue +387 -0
- package/components/u-skeleton/u-skeleton.vue +230 -0
- package/components/u-slider/u-slider.vue +293 -0
- package/components/u-steps/u-steps.vue +200 -0
- package/components/u-sticky/u-sticky.vue +189 -0
- package/components/u-subsection/u-subsection.vue +388 -0
- package/components/u-swipe-action/u-swipe-action.vue +289 -0
- package/components/u-swiper/u-swiper.vue +305 -0
- package/components/u-switch/u-switch.vue +146 -0
- package/components/u-tabbar/u-tabbar.vue +347 -0
- package/components/u-table/u-table.vue +104 -0
- package/components/u-tabs/u-tabs.vue +322 -0
- package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
- package/components/u-tag/u-tag.vue +270 -0
- package/components/u-td/u-td.vue +76 -0
- package/components/u-th/u-th.vue +70 -0
- package/components/u-time-line/u-time-line.vue +39 -0
- package/components/u-time-line-item/u-time-line-item.vue +88 -0
- package/components/u-toast/types.ts +4 -0
- package/components/u-toast/u-toast.vue +238 -0
- package/components/u-top-tips/u-top-tips.vue +118 -0
- package/components/u-tr/u-tr.vue +24 -0
- package/components/u-upload/u-upload.vue +600 -0
- package/components/u-verification-code/u-verification-code.vue +194 -0
- package/components/u-waterfall/u-waterfall.vue +186 -0
- package/iconfont.css +910 -0
- package/index.scss +23 -0
- package/index.ts +166 -0
- package/libs/config/config.ts +26 -0
- package/libs/config/zIndex.ts +37 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +176 -0
- package/libs/css/style.components.scss +7 -0
- package/libs/css/style.h5.scss +8 -0
- package/libs/css/style.mp.scss +72 -0
- package/libs/css/style.nvue.scss +3 -0
- package/libs/css/style.vue.scss +175 -0
- package/libs/function/$parent.ts +22 -0
- package/libs/function/addUnit.ts +13 -0
- package/libs/function/color.ts +37 -0
- package/libs/function/colorGradient.ts +123 -0
- package/libs/function/debounce.ts +28 -0
- package/libs/function/deepClone.ts +39 -0
- package/libs/function/deepMerge.ts +34 -0
- package/libs/function/getParent.ts +59 -0
- package/libs/function/getRect.ts +26 -0
- package/libs/function/guid.ts +42 -0
- package/libs/function/md5.ts +397 -0
- package/libs/function/parent.ts +21 -0
- package/libs/function/queryParams.ts +60 -0
- package/libs/function/random.ts +16 -0
- package/libs/function/randomArray.ts +11 -0
- package/libs/function/route.ts +118 -0
- package/libs/function/sys.ts +15 -0
- package/libs/function/test.ts +229 -0
- package/libs/function/throttle.ts +31 -0
- package/libs/function/timeFormat.ts +54 -0
- package/libs/function/timeFrom.ts +48 -0
- package/libs/function/toast.ts +14 -0
- package/libs/function/trim.ts +21 -0
- package/libs/function/type2icon.ts +36 -0
- package/libs/hooks/useEmitter.ts +77 -0
- package/libs/hooks/useParent.ts +29 -0
- package/libs/request/index.ts +237 -0
- package/libs/store/index.ts +88 -0
- package/libs/util/area.ts +1 -0
- package/libs/util/async-validator.js +1356 -0
- package/libs/util/city.ts +1 -0
- package/libs/util/emitter.ts +112 -0
- package/libs/util/mitt.ts +118 -0
- package/libs/util/parent.ts +20 -0
- package/libs/util/province.ts +1 -0
- package/package.json +98 -0
- package/readme.md +165 -0
- package/theme.scss +38 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-grid-item"
|
|
4
|
+
:hover-class="parentData.hoverClass"
|
|
5
|
+
:hover-stay-time="200"
|
|
6
|
+
@tap="click"
|
|
7
|
+
:style="{
|
|
8
|
+
background: bgColor,
|
|
9
|
+
width: width
|
|
10
|
+
}"
|
|
11
|
+
>
|
|
12
|
+
<view class="u-grid-item-box" :style="[customStyle]" :class="[parentData.border ? 'u-border-right u-border-bottom' : '']">
|
|
13
|
+
<slot />
|
|
14
|
+
</view>
|
|
15
|
+
</view>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { ref, computed, getCurrentInstance, onMounted } from 'vue';
|
|
20
|
+
import { $u } from '../..';
|
|
21
|
+
|
|
22
|
+
defineOptions({ name: 'u-grid-item' });
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* gridItem 宫格项
|
|
26
|
+
* @description 宫格组件一般用于同时展示多个同类项目的场景,可以给宫格的项目设置徽标组件(badge),或者图标等,也可以扩展为左右滑动的轮播形式。搭配u-grid使用
|
|
27
|
+
* @tutorial https://www.uviewui.com/components/grid.html
|
|
28
|
+
* @property {String} bg-color 宫格的背景颜色(默认#ffffff)
|
|
29
|
+
* @property {String|Number} index 点击宫格时,返回的值
|
|
30
|
+
* @property {Object} custom-style 自定义样式,对象形式
|
|
31
|
+
* @event {Function} click 点击宫格触发
|
|
32
|
+
* @example <u-grid-item></u-grid-item>
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// props 定义,保留参数注释
|
|
36
|
+
const props = defineProps({
|
|
37
|
+
/** 背景颜色 */
|
|
38
|
+
bgColor: { type: String, default: '#ffffff' },
|
|
39
|
+
/** 点击时返回的index */
|
|
40
|
+
index: { type: [Number, String], default: '' },
|
|
41
|
+
/** 自定义样式,对象形式 */
|
|
42
|
+
customStyle: { type: Object, default: () => ({ padding: '30rpx 0' }) }
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// emits 定义
|
|
46
|
+
const emit = defineEmits(['click']);
|
|
47
|
+
|
|
48
|
+
const instance = getCurrentInstance();
|
|
49
|
+
|
|
50
|
+
// 父组件参数
|
|
51
|
+
const parentData = ref({
|
|
52
|
+
hoverClass: '',
|
|
53
|
+
col: 3,
|
|
54
|
+
border: true
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// 计算每个grid-item的宽度
|
|
58
|
+
const width = computed(() => 100 / Number(parentData.value.col) + '%');
|
|
59
|
+
|
|
60
|
+
// 获取父组件参数
|
|
61
|
+
function updateParentData() {
|
|
62
|
+
if (!instance) return;
|
|
63
|
+
const parent = $u.parentData('u-grid', instance);
|
|
64
|
+
if (parent) {
|
|
65
|
+
parentData.value.hoverClass = parent.props.hoverClass;
|
|
66
|
+
parentData.value.col = parent.props.col;
|
|
67
|
+
parentData.value.border = parent.props.border;
|
|
68
|
+
// 注册到父组件children
|
|
69
|
+
if (Array.isArray(parent.children.value)) {
|
|
70
|
+
const exist = parent.children.value.find((val: any) => val === instance);
|
|
71
|
+
if (!exist) parent.children.value.push(instance);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 点击宫格
|
|
78
|
+
*/
|
|
79
|
+
function click() {
|
|
80
|
+
emit('click', props.index);
|
|
81
|
+
const parent = $u.parentData('u-grid', instance);
|
|
82
|
+
if (parent && typeof parent.click === 'function') parent.click(props.index);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onMounted(() => {
|
|
86
|
+
updateParentData();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
defineExpose({ updateParentData, click });
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<style scoped lang="scss">
|
|
93
|
+
@import '../../libs/css/style.components.scss';
|
|
94
|
+
|
|
95
|
+
.u-grid-item {
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
background: #fff;
|
|
98
|
+
@include vue-flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
position: relative;
|
|
102
|
+
flex-direction: column;
|
|
103
|
+
|
|
104
|
+
/* #ifdef MP */
|
|
105
|
+
position: relative;
|
|
106
|
+
float: left;
|
|
107
|
+
/* #endif */
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.u-grid-item-hover {
|
|
111
|
+
background: #f7f7f7 !important;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.u-grid-marker-box {
|
|
115
|
+
position: absolute;
|
|
116
|
+
/* #ifndef APP-NVUE */
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
/* #endif */
|
|
119
|
+
line-height: 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.u-grid-marker-wrap {
|
|
123
|
+
position: absolute;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.u-grid-item-box {
|
|
127
|
+
padding: 30rpx 0;
|
|
128
|
+
@include vue-flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
flex: 1;
|
|
133
|
+
width: 100%;
|
|
134
|
+
height: 100%;
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :style="[customStyle]" class="u-icon" @tap="onClick" :class="['u-icon--' + labelPos]">
|
|
3
|
+
<image class="u-icon__img" v-if="isImg" :src="name" :mode="imgMode" :style="[imgStyle]" />
|
|
4
|
+
<text v-else class="u-icon__icon" :class="customClass" :style="[iconStyle]" :hover-class="hoverClass" @touchstart="onTouchstart">
|
|
5
|
+
<text v-if="showDecimalIcon" :style="[decimalIconStyle]" :class="decimalIconClass" :hover-class="hoverClass" class="u-icon__decimal"></text>
|
|
6
|
+
</text>
|
|
7
|
+
<text v-if="label !== ''" class="u-icon__label" :style="labelStyle">
|
|
8
|
+
{{ label }}
|
|
9
|
+
</text>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { computed } from 'vue';
|
|
15
|
+
import { $u } from '../..';
|
|
16
|
+
|
|
17
|
+
defineOptions({
|
|
18
|
+
name: 'u-icon'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* icon 图标
|
|
23
|
+
* @description 基于字体的图标集,包含了大多数常见场景的图标。
|
|
24
|
+
* @tutorial https://www.uviewui.com/components/icon.html
|
|
25
|
+
* @property {String} name 图标名称,见示例图标集
|
|
26
|
+
* @property {String} color 图标颜色(默认inherit)
|
|
27
|
+
* @property {String | Number} size 图标字体大小,单位rpx(默认32)
|
|
28
|
+
* @property {String | Number} label-size label字体大小,单位rpx(默认28)
|
|
29
|
+
* @property {String} label 图标右侧的label文字(默认28)
|
|
30
|
+
* @property {String} label-pos label文字相对于图标的位置,只能right或bottom(默认right)
|
|
31
|
+
* @property {String} label-color label字体颜色(默认#606266)
|
|
32
|
+
* @property {Object} custom-style icon的样式,对象形式
|
|
33
|
+
* @property {String} custom-prefix 自定义字体图标库时,需要写上此值
|
|
34
|
+
* @property {String | Number} margin-left label在右侧时与图标的距离,单位rpx(默认6)
|
|
35
|
+
* @property {String | Number} margin-top label在下方时与图标的距离,单位rpx(默认6)
|
|
36
|
+
* @property {String | Number} margin-bottom label在上方时与图标的距离,单位rpx(默认6)
|
|
37
|
+
* @property {String | Number} margin-right label在左侧时与图标的距离,单位rpx(默认6)
|
|
38
|
+
* @property {String} index 一个用于区分多个图标的值,点击图标时通过click事件传出
|
|
39
|
+
* @property {String} hover-class 图标按下去的样式类,用法同uni的view组件的hover-class参数,详情见官网
|
|
40
|
+
* @property {String} width 显示图片小图标时的宽度
|
|
41
|
+
* @property {String} height 显示图片小图标时的高度
|
|
42
|
+
* @property {String | Number} top 图标在垂直方向上的定位
|
|
43
|
+
* @property {Boolean} show-decimal-icon 是否为DecimalIcon
|
|
44
|
+
* @property {String} inactive-color 背景颜色,可接受主题色,仅Decimal时有效
|
|
45
|
+
* @property {String | Number} percent 显示的百分比,仅Decimal时有效
|
|
46
|
+
* @event {Function} click 点击图标时触发
|
|
47
|
+
* @event {Function} touchstart 图标触摸时触发
|
|
48
|
+
* @example <u-icon name="photo" color="#2979ff" size="28"></u-icon>
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
const emit = defineEmits<{
|
|
52
|
+
(e: 'click', index: string | number): void;
|
|
53
|
+
(e: 'touchstart', index: string | number): void;
|
|
54
|
+
}>();
|
|
55
|
+
|
|
56
|
+
const props = defineProps({
|
|
57
|
+
/**
|
|
58
|
+
* 图标名称,见示例图标集
|
|
59
|
+
* @default ''
|
|
60
|
+
*/
|
|
61
|
+
name: { type: String, default: '' },
|
|
62
|
+
/**
|
|
63
|
+
* 图标颜色,可接受主题色
|
|
64
|
+
* @default ''
|
|
65
|
+
*/
|
|
66
|
+
color: { type: String, default: '' },
|
|
67
|
+
/**
|
|
68
|
+
* 字体大小,单位rpx(默认32)
|
|
69
|
+
* @default 'inherit'
|
|
70
|
+
*/
|
|
71
|
+
size: { type: [Number, String], default: 'inherit' },
|
|
72
|
+
/**
|
|
73
|
+
* 是否显示粗体
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
bold: { type: Boolean, default: false },
|
|
77
|
+
/**
|
|
78
|
+
* 点击图标的时候传递事件出去的index(用于区分点击了哪一个)
|
|
79
|
+
* @default ''
|
|
80
|
+
*/
|
|
81
|
+
index: { type: [Number, String], default: '' },
|
|
82
|
+
/**
|
|
83
|
+
* 触摸图标时的类名
|
|
84
|
+
* @default ''
|
|
85
|
+
*/
|
|
86
|
+
hoverClass: { type: String, default: '' },
|
|
87
|
+
/**
|
|
88
|
+
* 自定义扩展前缀,方便用户扩展自己的图标库
|
|
89
|
+
* @default 'uicon'
|
|
90
|
+
*/
|
|
91
|
+
customPrefix: { type: String, default: 'uicon' },
|
|
92
|
+
/**
|
|
93
|
+
* 图标右边或者下面的文字
|
|
94
|
+
* @default ''
|
|
95
|
+
*/
|
|
96
|
+
label: { type: [String, Number], default: '' },
|
|
97
|
+
/**
|
|
98
|
+
* label的位置,只能右边或者下边
|
|
99
|
+
* @default 'right'
|
|
100
|
+
* @values 'right' | 'bottom'
|
|
101
|
+
*/
|
|
102
|
+
labelPos: { type: String, default: 'right' },
|
|
103
|
+
/**
|
|
104
|
+
* label的大小,单位rpx(默认28)
|
|
105
|
+
* @default '28'
|
|
106
|
+
*/
|
|
107
|
+
labelSize: { type: [String, Number], default: '28' },
|
|
108
|
+
/**
|
|
109
|
+
* label的颜色
|
|
110
|
+
* @default '#606266'
|
|
111
|
+
*/
|
|
112
|
+
labelColor: { type: String, default: '#606266' },
|
|
113
|
+
/**
|
|
114
|
+
* label与图标的距离(横向排列),单位rpx(默认6)
|
|
115
|
+
* @default '6'
|
|
116
|
+
*/
|
|
117
|
+
marginLeft: { type: [String, Number], default: '6' },
|
|
118
|
+
/**
|
|
119
|
+
* label与图标的距离(竖向排列),单位rpx(默认6)
|
|
120
|
+
* @default '6'
|
|
121
|
+
*/
|
|
122
|
+
marginTop: { type: [String, Number], default: '6' },
|
|
123
|
+
/**
|
|
124
|
+
* label与图标的距离(竖向排列),单位rpx(默认6)
|
|
125
|
+
* @default '6'
|
|
126
|
+
*/
|
|
127
|
+
marginRight: { type: [String, Number], default: '6' },
|
|
128
|
+
/**
|
|
129
|
+
* label与图标的距离(竖向排列),单位rpx(默认6)
|
|
130
|
+
* @default '6'
|
|
131
|
+
*/
|
|
132
|
+
marginBottom: { type: [String, Number], default: '6' },
|
|
133
|
+
/**
|
|
134
|
+
* 图片的mode,参考uni-app image组件
|
|
135
|
+
* @default 'widthFix'
|
|
136
|
+
*/
|
|
137
|
+
imgMode: { type: String, default: 'widthFix' },
|
|
138
|
+
/**
|
|
139
|
+
* 自定义样式,对象形式
|
|
140
|
+
* @default {}
|
|
141
|
+
*/
|
|
142
|
+
customStyle: { type: Object as () => Record<string, any>, default: () => ({}) },
|
|
143
|
+
/**
|
|
144
|
+
* 用于显示图片小图标时,图片的宽度,单位rpx
|
|
145
|
+
* @default ''
|
|
146
|
+
*/
|
|
147
|
+
width: { type: [String, Number], default: '' },
|
|
148
|
+
/**
|
|
149
|
+
* 用于显示图片小图标时,图片的高度,单位rpx
|
|
150
|
+
* @default ''
|
|
151
|
+
*/
|
|
152
|
+
height: { type: [String, Number], default: '' },
|
|
153
|
+
/**
|
|
154
|
+
* 用于解决某些情况下,让图标垂直居中的用途,单位rpx
|
|
155
|
+
* @default 0
|
|
156
|
+
*/
|
|
157
|
+
top: { type: [String, Number], default: 0 },
|
|
158
|
+
/**
|
|
159
|
+
* 是否为DecimalIcon
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
showDecimalIcon: { type: Boolean, default: false },
|
|
163
|
+
/**
|
|
164
|
+
* 背景颜色,可接受主题色,仅Decimal时有效
|
|
165
|
+
* @default '#ececec'
|
|
166
|
+
*/
|
|
167
|
+
inactiveColor: { type: String, default: '#ececec' },
|
|
168
|
+
/**
|
|
169
|
+
* 显示的百分比,仅Decimal时有效
|
|
170
|
+
* @default '50'
|
|
171
|
+
*/
|
|
172
|
+
percent: { type: [Number, String], default: '50' }
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 计算图标的类名集合
|
|
177
|
+
* @returns {string[]}
|
|
178
|
+
*/
|
|
179
|
+
const customClass = computed(() => {
|
|
180
|
+
let classes: string[] | string = [];
|
|
181
|
+
classes.push(props.customPrefix + '-' + props.name);
|
|
182
|
+
// uView的自定义图标类名为u-iconfont
|
|
183
|
+
if (props.customPrefix === 'uicon') {
|
|
184
|
+
classes.push('u-iconfont');
|
|
185
|
+
} else {
|
|
186
|
+
classes.push(props.customPrefix);
|
|
187
|
+
}
|
|
188
|
+
// 主题色,通过类配置
|
|
189
|
+
if (props.showDecimalIcon && props.inactiveColor && $u.config.type.includes(props.inactiveColor)) {
|
|
190
|
+
classes.push('u-icon__icon--' + props.inactiveColor);
|
|
191
|
+
} else if (props.color && $u.config.type.includes(props.color)) {
|
|
192
|
+
classes.push('u-icon__icon--' + props.color);
|
|
193
|
+
}
|
|
194
|
+
// 阿里,头条,百度小程序通过数组绑定类名时,无法直接使用[a, b, c]的形式,否则无法识别
|
|
195
|
+
// 故需将其拆成一个字符串的形式,通过空格隔开各个类名
|
|
196
|
+
// #ifdef MP-ALIPAY || MP-TOUTIAO || MP-BAIDU
|
|
197
|
+
classes = (classes as string[]).join(' ');
|
|
198
|
+
// #endif
|
|
199
|
+
return classes;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 计算图标的样式
|
|
204
|
+
* @returns {CSSProperties}
|
|
205
|
+
*/
|
|
206
|
+
const iconStyle = computed(() => {
|
|
207
|
+
const style: Record<string, any> = {
|
|
208
|
+
fontSize: props.size === 'inherit' ? 'inherit' : $u.addUnit(props.size),
|
|
209
|
+
fontWeight: props.bold ? 'bold' : 'normal',
|
|
210
|
+
// 某些特殊情况需要设置一个到顶部的距离,才能更好的垂直居中
|
|
211
|
+
top: $u.addUnit(props.top)
|
|
212
|
+
};
|
|
213
|
+
// 非主题色值时,才当作颜色值
|
|
214
|
+
if (props.showDecimalIcon && props.inactiveColor && !$u.config.type.includes(props.inactiveColor)) {
|
|
215
|
+
style.color = props.inactiveColor;
|
|
216
|
+
} else if (props.color && !$u.config.type.includes(props.color)) {
|
|
217
|
+
style.color = props.color;
|
|
218
|
+
}
|
|
219
|
+
return style;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 判断传入的name属性是否为图片路径
|
|
224
|
+
* @returns {boolean}
|
|
225
|
+
*/
|
|
226
|
+
const isImg = computed(() => {
|
|
227
|
+
return props.name.indexOf('/') !== -1;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 计算图片图标的样式
|
|
232
|
+
* @returns {any}
|
|
233
|
+
*/
|
|
234
|
+
const imgStyle = computed(() => {
|
|
235
|
+
// 如果设置width和height属性,则优先使用,否则使用size属性
|
|
236
|
+
const style: any = {
|
|
237
|
+
width: props.width ? $u.addUnit(props.width) : $u.addUnit(props.size),
|
|
238
|
+
height: props.height ? $u.addUnit(props.height) : $u.addUnit(props.size)
|
|
239
|
+
};
|
|
240
|
+
return style;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 计算小数图标的样式,仅DecimalIcon时有效
|
|
245
|
+
* @returns {CSSProperties}
|
|
246
|
+
*/
|
|
247
|
+
const decimalIconStyle = computed(() => {
|
|
248
|
+
const style: any = {
|
|
249
|
+
fontSize: props.size === 'inherit' ? 'inherit' : $u.addUnit(props.size),
|
|
250
|
+
fontWeight: props.bold ? 'bold' : 'normal',
|
|
251
|
+
// 某些特殊情况需要设置一个到顶部的距离,才能更好的垂直居中
|
|
252
|
+
top: $u.addUnit(props.top),
|
|
253
|
+
width: props.percent + '%'
|
|
254
|
+
};
|
|
255
|
+
// 非主题色值时,才当作颜色值
|
|
256
|
+
if (props.color && !$u.config.type.includes(props.color)) {
|
|
257
|
+
style.color = props.color;
|
|
258
|
+
}
|
|
259
|
+
return style;
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 计算小数图标的类名,仅DecimalIcon时有效
|
|
264
|
+
* @returns {string | string[]}
|
|
265
|
+
*/
|
|
266
|
+
const decimalIconClass = computed(() => {
|
|
267
|
+
let classes: string[] | string = [];
|
|
268
|
+
classes.push(props.customPrefix + '-' + props.name);
|
|
269
|
+
// uView的自定义图标类名为u-iconfont
|
|
270
|
+
if (props.customPrefix === 'uicon') {
|
|
271
|
+
classes.push('u-iconfont');
|
|
272
|
+
} else {
|
|
273
|
+
classes.push(props.customPrefix);
|
|
274
|
+
}
|
|
275
|
+
if (props.color && $u.config.type.includes(props.color)) {
|
|
276
|
+
classes.push('u-icon__icon--' + props.color);
|
|
277
|
+
} else {
|
|
278
|
+
classes.push('u-icon__icon--primary');
|
|
279
|
+
}
|
|
280
|
+
// 阿里,头条,百度小程序通过数组绑定类名时,无法直接使用[a, b, c]的形式,否则无法识别
|
|
281
|
+
// 故需将其拆成一个字符串的形式,通过空格隔开各个类名
|
|
282
|
+
// #ifdef MP-ALIPAY || MP-TOUTIAO || MP-BAIDU
|
|
283
|
+
classes = (classes as string[]).join(' ');
|
|
284
|
+
// #endif
|
|
285
|
+
return classes;
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* 计算label的样式
|
|
290
|
+
* @returns {any}
|
|
291
|
+
*/
|
|
292
|
+
const labelStyle = computed(() => {
|
|
293
|
+
return {
|
|
294
|
+
color: props.labelColor,
|
|
295
|
+
fontSize: $u.addUnit(props.labelSize),
|
|
296
|
+
marginLeft: props.labelPos === 'right' ? $u.addUnit(props.marginLeft) : 0,
|
|
297
|
+
marginTop: props.labelPos === 'bottom' ? $u.addUnit(props.marginTop) : 0,
|
|
298
|
+
marginRight: props.labelPos === 'left' ? $u.addUnit(props.marginRight) : 0,
|
|
299
|
+
marginBottom: props.labelPos === 'top' ? $u.addUnit(props.marginBottom) : 0
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 点击图标时触发
|
|
305
|
+
* @emits click(index)
|
|
306
|
+
*/
|
|
307
|
+
function onClick() {
|
|
308
|
+
emit('click', props.index);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 图标触摸时触发
|
|
313
|
+
* @emits touchstart(index)
|
|
314
|
+
*/
|
|
315
|
+
function onTouchstart() {
|
|
316
|
+
emit('touchstart', props.index);
|
|
317
|
+
}
|
|
318
|
+
</script>
|
|
319
|
+
|
|
320
|
+
<style scoped lang="scss">
|
|
321
|
+
@import '../../libs/css/style.components.scss';
|
|
322
|
+
@import '../../iconfont.css';
|
|
323
|
+
|
|
324
|
+
.u-icon {
|
|
325
|
+
display: inline-flex;
|
|
326
|
+
align-items: center;
|
|
327
|
+
|
|
328
|
+
&--left {
|
|
329
|
+
flex-direction: row-reverse;
|
|
330
|
+
align-items: center;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
&--right {
|
|
334
|
+
flex-direction: row;
|
|
335
|
+
align-items: center;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
&--top {
|
|
339
|
+
flex-direction: column-reverse;
|
|
340
|
+
justify-content: center;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&--bottom {
|
|
344
|
+
flex-direction: column;
|
|
345
|
+
justify-content: center;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
&__icon {
|
|
349
|
+
position: relative;
|
|
350
|
+
|
|
351
|
+
&--primary {
|
|
352
|
+
color: $u-type-primary;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
&--success {
|
|
356
|
+
color: $u-type-success;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
&--error {
|
|
360
|
+
color: $u-type-error;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
&--warning {
|
|
364
|
+
color: $u-type-warning;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
&--info {
|
|
368
|
+
color: $u-type-info;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
&__decimal {
|
|
373
|
+
position: absolute;
|
|
374
|
+
top: 0;
|
|
375
|
+
left: 0;
|
|
376
|
+
display: inline-block;
|
|
377
|
+
overflow: hidden;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
&__img {
|
|
381
|
+
height: auto;
|
|
382
|
+
will-change: transform;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
&__label {
|
|
386
|
+
line-height: 1;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
</style>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ComponentPublicInstance, type ExtractPropTypes } from 'vue'
|
|
2
|
+
|
|
3
|
+
// 定义 ImageProps 的类型
|
|
4
|
+
export const ImageProps = {
|
|
5
|
+
/** 图片地址 */
|
|
6
|
+
src: { type: String, default: '' },
|
|
7
|
+
/** 裁剪模式 */
|
|
8
|
+
mode: { type: String, default: 'aspectFill' },
|
|
9
|
+
/** 宽度,单位任意,如果为数值,则为rpx单位(默认100%) */
|
|
10
|
+
width: { type: [String, Number], default: '100%' },
|
|
11
|
+
/** 高度,单位任意,如果为数值,则为rpx单位(默认 auto) */
|
|
12
|
+
height: { type: [String, Number], default: 'auto' },
|
|
13
|
+
/** 图片形状,circle-圆形,square-方形(默认square) */
|
|
14
|
+
shape: { type: String, default: 'square' },
|
|
15
|
+
/** 圆角值,单位任意,如果为数值,则为rpx单位(默认 0) */
|
|
16
|
+
borderRadius: { type: [String, Number], default: 0 },
|
|
17
|
+
/** 是否懒加载,仅微信小程序、App、百度小程序、字节跳动小程序有效(默认 true) */
|
|
18
|
+
lazyLoad: { type: Boolean, default: true },
|
|
19
|
+
/** 是否开启长按图片显示识别小程序码菜单,仅微信小程序有效(默认 true) */
|
|
20
|
+
showMenuByLongpress: { type: Boolean, default: true },
|
|
21
|
+
/** 加载中的图标,或者小图片(默认 photo) */
|
|
22
|
+
loadingIcon: { type: String, default: 'photo' },
|
|
23
|
+
/** 加载失败的图标,或者小图片(默认 error-circle) */
|
|
24
|
+
errorIcon: { type: String, default: 'error-circle' },
|
|
25
|
+
/** 是否显示加载中的图标或者自定义的slot(默认 true) */
|
|
26
|
+
showLoading: { type: Boolean, default: true },
|
|
27
|
+
/** 是否显示加载错误的图标或者自定义的slot(默认 true) */
|
|
28
|
+
showError: { type: Boolean, default: true },
|
|
29
|
+
/** 是否需要淡入效果(默认 true) */
|
|
30
|
+
fade: { type: Boolean, default: true },
|
|
31
|
+
/** 只支持网络资源,只对微信小程序有效(默认 false) */
|
|
32
|
+
webp: { type: Boolean, default: false },
|
|
33
|
+
/** 搭配fade参数的过渡时间,单位ms(默认 500) */
|
|
34
|
+
duration: { type: [String, Number], default: 500 },
|
|
35
|
+
/** 背景颜色,用于深色页面加载图片时,为了和背景色融合(默认 #f3f4f6) */
|
|
36
|
+
bgColor: { type: String, default: '#f3f4f6' }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 将 ImageProps 转换为类型
|
|
40
|
+
export type ImageProps = ExtractPropTypes<typeof ImageProps>
|
|
41
|
+
|
|
42
|
+
// 暴露的组件实例方法
|
|
43
|
+
export type ImageExpose = {
|
|
44
|
+
changeStatus: (status: 'loading' | 'error' | 'normal') => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 组件实例类型
|
|
48
|
+
export type ImageInstance = ComponentPublicInstance<ImageProps, ImageExpose>
|