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.
Files changed (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
package/changelog.md ADDED
@@ -0,0 +1,6 @@
1
+ ## 0.0.1(2025-08-04)
2
+
3
+ - 兼容安卓,iOS,微信小程序,H5 等
4
+ - 使用 Vue3 已重构 60+精选组件,功能丰富,多端兼容,让您快速集成,开箱即用
5
+ - 详尽的文档支持,现代化的演示效果
6
+ - 按需引入,精简打包体积
@@ -0,0 +1,205 @@
1
+ <template>
2
+ <u-popup
3
+ mode="bottom"
4
+ :border-radius="borderRadius"
5
+ :popup="false"
6
+ v-model="popupValue"
7
+ :maskCloseAble="maskCloseAble"
8
+ length="auto"
9
+ :safeAreaInsetBottom="safeAreaInsetBottom"
10
+ @close="popupClose"
11
+ :z-index="uZIndex"
12
+ >
13
+ <view class="u-tips u-border-bottom" v-if="tips.text" :style="[tipsStyle]">
14
+ {{ tips.text }}
15
+ </view>
16
+ <block v-for="(item, index) in list" :key="index">
17
+ <view
18
+ @touchmove.stop.prevent
19
+ @tap="itemClick(index)"
20
+ :style="[itemStyle(index)]"
21
+ class="u-action-sheet-item u-line-1"
22
+ :class="[index < list.length - 1 ? 'u-border-bottom' : '']"
23
+ :hover-stay-time="150"
24
+ >
25
+ <text>{{ item.text }}</text>
26
+ <text class="u-action-sheet-item__subtext u-line-1" v-if="item.subText">{{ item.subText }}</text>
27
+ </view>
28
+ </block>
29
+ <view class="u-gab" v-if="cancelBtn"> </view>
30
+ <view @touchmove.stop.prevent class="u-actionsheet-cancel u-action-sheet-item" hover-class="u-hover-class" :hover-stay-time="150" v-if="cancelBtn" @tap="close">{{
31
+ cancelText
32
+ }}</view>
33
+ </u-popup>
34
+ </template>
35
+
36
+ <script setup lang="ts">
37
+ import { computed } from 'vue';
38
+ import { $u } from '../..';
39
+
40
+ defineOptions({
41
+ name: 'u-action-sheet'
42
+ });
43
+
44
+ /**
45
+ * actionSheet 操作菜单
46
+ * @description 本组件用于从底部弹出一个操作菜单,供用户选择并返回结果。本组件功能类似于uni的uni.showActionSheetAPI,配置更加灵活,所有平台都表现一致。
47
+ * @tutorial https://www.uviewui.com/components/actionSheet.html
48
+ * @property {Array<Object>} list 按钮的文字数组,见官方文档示例
49
+ * @property {Object} tips 顶部的提示文字,见官方文档示例
50
+ * @property {String} cancel-text 取消按钮的提示文字
51
+ * @property {Boolean} cancel-btn 是否显示底部的取消按钮(默认true)
52
+ * @property {Number String} border-radius 弹出部分顶部左右的圆角值,单位rpx(默认0)
53
+ * @property {Boolean} mask-close-able 点击遮罩是否可以关闭(默认true)
54
+ * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
55
+ * @property {Number String} z-index z-index值(默认1075)
56
+ * @property {String} cancel-text 取消按钮的提示文字
57
+ * @event {Function} click 点击ActionSheet列表项时触发
58
+ * @event {Function} close 点击取消按钮时触发
59
+ * @example <u-action-sheet :list="list" @click="click" v-model="show"></u-action-sheet>
60
+ */
61
+
62
+ const props = defineProps({
63
+ /** 点击遮罩是否可以关闭actionsheet */
64
+ maskCloseAble: {
65
+ type: Boolean,
66
+ default: true
67
+ },
68
+ /** 按钮的文字数组,可以自定义颜色和字体大小,字体单位为rpx */
69
+ list: {
70
+ type: Array as () => Array<any>,
71
+ default: () => []
72
+ },
73
+ /** 顶部的提示文字 */
74
+ tips: {
75
+ type: Object as () => { text: string; color?: string; fontSize?: string },
76
+ default: () => ({ text: '', color: '', fontSize: '26' })
77
+ },
78
+ /** 底部的取消按钮 */
79
+ cancelBtn: {
80
+ type: Boolean,
81
+ default: true
82
+ },
83
+ /** 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距 */
84
+ safeAreaInsetBottom: {
85
+ type: Boolean,
86
+ default: false
87
+ },
88
+ /** 通过双向绑定控制组件的弹出与收起 */
89
+ modelValue: {
90
+ type: Boolean,
91
+ default: false
92
+ },
93
+ /** 弹出的顶部圆角值 */
94
+ borderRadius: {
95
+ type: [String, Number],
96
+ default: 0
97
+ },
98
+ /** 弹出的z-index值 */
99
+ zIndex: {
100
+ type: [String, Number],
101
+ default: 0
102
+ },
103
+ /** 取消按钮的文字提示 */
104
+ cancelText: {
105
+ type: String,
106
+ default: '取消'
107
+ }
108
+ });
109
+
110
+ const emit = defineEmits(['update:modelValue', 'click', 'close']);
111
+
112
+ const popupValue = computed({
113
+ get: () => props.modelValue,
114
+ set: (val: boolean) => emit('update:modelValue', val)
115
+ });
116
+
117
+ // 顶部提示的样式
118
+ const tipsStyle = computed(() => {
119
+ let style: Record<string, string> = {};
120
+ if (props.tips.color) style.color = props.tips.color;
121
+ if (props.tips.fontSize) style.fontSize = props.tips.fontSize + 'rpx';
122
+ return style;
123
+ });
124
+
125
+ // 操作项目的样式
126
+ const itemStyle = (index: number) => {
127
+ let style: Record<string, string> = {};
128
+ if (props.list[index]?.color) style.color = props.list[index].color;
129
+ if (props.list[index]?.fontSize) style.fontSize = props.list[index].fontSize + 'rpx';
130
+ // 选项被禁用的样式
131
+ if (props.list[index]?.disabled) style.color = '#c0c4cc';
132
+ return style;
133
+ };
134
+
135
+ // 计算z-index
136
+ const uZIndex = computed(() => {
137
+ // 如果用户有传递z-index值,优先使用
138
+ return props.zIndex ? props.zIndex : $u.zIndex.popup;
139
+ });
140
+
141
+ /**
142
+ * 点击取消按钮
143
+ */
144
+ function close() {
145
+ // 发送input事件,并不会作用于父组件,而是要设置组件内部通过props传递的value参数
146
+ // 这是一个vue发送事件的特殊用法
147
+ popupClose();
148
+ emit('close');
149
+ }
150
+
151
+ /**
152
+ * 弹窗关闭
153
+ */
154
+ function popupClose() {
155
+ emit('update:modelValue', false);
156
+ }
157
+
158
+ /**
159
+ * 点击某一个item
160
+ * @param index 选项索引
161
+ */
162
+ function itemClick(index: number) {
163
+ // disabled的项禁止点击
164
+ if (props.list[index]?.disabled) return;
165
+ emit('click', index);
166
+ emit('update:modelValue', false);
167
+ }
168
+ </script>
169
+
170
+ <style lang="scss" scoped>
171
+ @import '../../libs/css/style.components.scss';
172
+
173
+ .u-tips {
174
+ font-size: 26rpx;
175
+ text-align: center;
176
+ padding: 34rpx 0;
177
+ line-height: 1;
178
+ color: $u-tips-color;
179
+ }
180
+
181
+ .u-action-sheet-item {
182
+ @include vue-flex;
183
+ line-height: 1;
184
+ justify-content: center;
185
+ align-items: center;
186
+ font-size: 32rpx;
187
+ padding: 34rpx 0;
188
+ flex-direction: column;
189
+ }
190
+
191
+ .u-action-sheet-item__subtext {
192
+ font-size: 24rpx;
193
+ color: $u-tips-color;
194
+ margin-top: 20rpx;
195
+ }
196
+
197
+ .u-gab {
198
+ height: 12rpx;
199
+ background-color: rgb(234, 234, 236);
200
+ }
201
+
202
+ .u-actionsheet-cancel {
203
+ color: $u-main-color;
204
+ }
205
+ </style>
@@ -0,0 +1,241 @@
1
+ <template>
2
+ <view
3
+ class="u-alert-tips"
4
+ v-if="show"
5
+ :class="[!show ? 'u-close-alert-tips' : '', type ? 'u-alert-tips--bg--' + type + '-light' : '', type ? 'u-alert-tips--border--' + type + '-disabled' : '']"
6
+ :style="{
7
+ backgroundColor: bgColor,
8
+ borderColor: borderColor
9
+ }"
10
+ >
11
+ <view class="u-icon-wrap">
12
+ <u-icon v-if="showIcon" :name="uIconName" :size="description ? 40 : 32" class="u-icon" :color="uIconType" :custom-style="iconStyle"></u-icon>
13
+ </view>
14
+ <view class="u-alert-content" @tap.stop="onClick">
15
+ <view class="u-alert-title" :style="uTitleStyle">
16
+ {{ title }}
17
+ </view>
18
+ <view v-if="description" class="u-alert-desc" :style="descStyle">
19
+ {{ description }}
20
+ </view>
21
+ </view>
22
+ <view class="u-icon-wrap">
23
+ <u-icon
24
+ @click="onClose"
25
+ v-if="closeAble && !closeText"
26
+ hoverClass="u-type-error-hover-color"
27
+ name="close"
28
+ color="#c0c4cc"
29
+ :size="22"
30
+ class="u-close-icon"
31
+ :style="{
32
+ top: description ? '18rpx' : '24rpx'
33
+ }"
34
+ ></u-icon>
35
+ </view>
36
+ <text
37
+ v-if="closeAble && closeText"
38
+ class="u-close-text"
39
+ :style="{
40
+ top: description ? '18rpx' : '24rpx'
41
+ }"
42
+ >{{ closeText }}</text
43
+ >
44
+ </view>
45
+ </template>
46
+
47
+ <script setup lang="ts">
48
+ import uIcon from '../u-icon/u-icon.vue';
49
+ import { computed } from 'vue';
50
+ import { $u } from '../..';
51
+
52
+ defineOptions({
53
+ name: 'u-alert-tips'
54
+ });
55
+
56
+ /**
57
+ * alertTips 警告提示
58
+ * @description 警告提示,展现需要关注的信息
59
+ * @tutorial https://uviewui.com/components/alertTips.html
60
+ * @property {String} title 显示的标题文字
61
+ * @property {String} description 辅助性文字,颜色比title浅一点,字号也小一点,可选
62
+ * @property {String} type 关闭按钮(默认为叉号icon图标)
63
+ * @property {String} icon 图标名称
64
+ * @property {Object} icon-style 图标的样式,对象形式
65
+ * @property {Object} title-style 标题的样式,对象形式
66
+ * @property {Object} desc-style 描述的样式,对象形式
67
+ * @property {String} close-able 用文字替代关闭图标,close-able为true时有效
68
+ * @property {Boolean} show-icon 是否显示左边的辅助图标
69
+ * @property {Boolean} show 显示或隐藏组件
70
+ * @event {Function} click 点击组件时触发
71
+ * @event {Function} close 点击关闭按钮时触发
72
+ */
73
+ type Types = 'primary' | 'info' | 'error' | 'warning' | 'success';
74
+
75
+ const props = defineProps({
76
+ /** 显示文字 */
77
+ title: { type: String, default: '' },
78
+ /** 主题,success/warning/info/error */
79
+ type: { type: String as () => Types, default: 'warning' },
80
+ /** 辅助性文字 */
81
+ description: { type: String, default: '' },
82
+ /** 是否可关闭 */
83
+ closeAble: { type: Boolean, default: false },
84
+ /** 关闭按钮自定义文本 */
85
+ closeText: { type: String, default: '' },
86
+ /** 是否显示图标 */
87
+ showIcon: { type: Boolean, default: false },
88
+ /** 文字颜色,如果定义了color值,icon会失效 */
89
+ color: { type: String, default: '' },
90
+ /** 背景颜色 */
91
+ bgColor: { type: String, default: '' },
92
+ /** 边框颜色 */
93
+ borderColor: { type: String, default: '' },
94
+ /** 是否显示 */
95
+ show: { type: Boolean, default: true },
96
+ /** 左边显示的icon */
97
+ icon: { type: String, default: '' },
98
+ /** icon的样式 */
99
+ iconStyle: { type: Object, default: () => ({}) },
100
+ /** 标题的样式 */
101
+ titleStyle: { type: Object, default: () => ({}) },
102
+ /** 描述文字的样式 */
103
+ descStyle: { type: Object, default: () => ({}) }
104
+ });
105
+
106
+ const emit = defineEmits(['click', 'close']);
107
+
108
+ /**
109
+ * 标题样式,合并加粗和用户自定义样式
110
+ */
111
+ const uTitleStyle = computed(() => {
112
+ let style: Record<string, any> = {};
113
+ // 如果有描述文字的话,标题进行加粗
114
+ style.fontWeight = props.description ? 500 : 'normal';
115
+ // 将用户传入样式对象和style合并,传入的优先级比style高,同属性会被覆盖
116
+ return $u.deepMerge(style, props.titleStyle);
117
+ });
118
+
119
+ /**
120
+ * 图标名称,优先使用用户传入,否则根据type主题推定默认图标
121
+ */
122
+ const uIconName = computed(() => {
123
+ // 如果有设置icon名称就使用,否则根据type主题,推定一个默认的图标
124
+ return props.icon ? props.icon : $u.type2icon(props.type);
125
+ });
126
+
127
+ /**
128
+ * 图标类型,优先使用iconStyle,否则用type
129
+ */
130
+ const uIconType = computed(() => {
131
+ // 如果有设置图标的样式,优先使用,没有的话,则用type的样式
132
+ return Object.keys(props.iconStyle).length ? '' : props.type;
133
+ });
134
+
135
+ /**
136
+ * 点击内容
137
+ */
138
+ function onClick() {
139
+ emit('click');
140
+ }
141
+
142
+ /**
143
+ * 点击关闭按钮
144
+ */
145
+ function onClose() {
146
+ emit('close');
147
+ }
148
+ </script>
149
+
150
+ <style lang="scss" scoped>
151
+ @import '../../libs/css/style.components.scss';
152
+
153
+ .u-alert-tips {
154
+ @include vue-flex;
155
+ align-items: center;
156
+ padding: 16rpx 30rpx;
157
+ border-radius: 8rpx;
158
+ position: relative;
159
+ transition: all 0.3s linear;
160
+ border: 1px solid #fff;
161
+
162
+ &--bg--primary-light {
163
+ background-color: $u-type-primary-light;
164
+ }
165
+
166
+ &--bg--info-light {
167
+ background-color: $u-type-info-light;
168
+ }
169
+
170
+ &--bg--success-light {
171
+ background-color: $u-type-success-light;
172
+ }
173
+
174
+ &--bg--warning-light {
175
+ background-color: $u-type-warning-light;
176
+ }
177
+
178
+ &--bg--error-light {
179
+ background-color: $u-type-error-light;
180
+ }
181
+
182
+ &--border--primary-disabled {
183
+ border-color: $u-type-primary-disabled;
184
+ }
185
+
186
+ &--border--success-disabled {
187
+ border-color: $u-type-success-disabled;
188
+ }
189
+
190
+ &--border--error-disabled {
191
+ border-color: $u-type-error-disabled;
192
+ }
193
+
194
+ &--border--warning-disabled {
195
+ border-color: $u-type-warning-disabled;
196
+ }
197
+
198
+ &--border--info-disabled {
199
+ border-color: $u-type-info-disabled;
200
+ }
201
+ }
202
+
203
+ .u-close-alert-tips {
204
+ opacity: 0;
205
+ visibility: hidden;
206
+ }
207
+
208
+ .u-icon {
209
+ margin-right: 16rpx;
210
+ }
211
+
212
+ .u-alert-title {
213
+ font-size: 28rpx;
214
+ color: $u-main-color;
215
+ }
216
+
217
+ .u-alert-desc {
218
+ font-size: 26rpx;
219
+ text-align: left;
220
+ color: $u-content-color;
221
+ }
222
+
223
+ .u-close-icon {
224
+ position: absolute;
225
+ top: 20rpx;
226
+ right: 20rpx;
227
+ }
228
+
229
+ .u-close-hover {
230
+ color: red;
231
+ }
232
+
233
+ .u-close-text {
234
+ font-size: 24rpx;
235
+ color: $u-tips-color;
236
+ position: absolute;
237
+ top: 20rpx;
238
+ right: 20rpx;
239
+ line-height: 1;
240
+ }
241
+ </style>
@@ -0,0 +1,220 @@
1
+ <template>
2
+ <view class="u-avatar" :style="wrapStyle" @tap="onClick">
3
+ <image @error="onLoadError" :style="imgStyle" class="u-avatar__img" v-if="!uText && avatar" :src="avatar" :mode="imgMode"></image>
4
+ <text class="u-line-1" v-else-if="uText" :style="{ fontSize: '38rpx' }">{{ uText }}</text>
5
+ <slot v-else></slot>
6
+ <view class="u-avatar__sex" v-if="showSex" :class="['u-avatar__sex--' + sexIcon]" :style="uSexStyle">
7
+ <u-icon :name="sexIcon" size="20"></u-icon>
8
+ </view>
9
+ <view class="u-avatar__level" v-if="showLevel" :style="uLevelStyle">
10
+ <u-icon :name="levelIcon" size="20"></u-icon>
11
+ </view>
12
+ </view>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { ref, computed, watch } from 'vue';
17
+
18
+ defineOptions({
19
+ name: 'u-avatar'
20
+ });
21
+
22
+ let base64Avatar =
23
+ 'data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4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g1owN+PvORborq+7Hnwl3gUbO74VzRydt8pKn68ANcJwmqwkpLmnUDkAAAAfNy9atqtyagut0AxXt5xIV8Fbj6lRd7Am5G65V6qUvtwfyx94GMAAAAAAAAAAAAAAAAAAAOU2nVOj5gdsc3LiqRvTpyqwOxbnnrhdfpSfrQB7pnv/AGvuS9gHXPMy5/Fem1yq0v0A6W29XqwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf//Z';
24
+
25
+ /**
26
+ * avatar 头像
27
+ * @description 本组件一般用于展示头像的地方,如个人中心,或者评论列表页的用户头像展示等场所。
28
+ * @tutorial https://www.uviewui.com/components/avatar.html
29
+ * @property {String} bg-color 背景颜色,一般显示文字时用(默认#ffffff)
30
+ * @property {String} src 头像路径,如加载失败,将会显示默认头像
31
+ * @property {String Number} size 头像尺寸,可以为指定字符串(large, default, mini),或者数值,单位rpx(默认default)
32
+ * @property {String} mode 显示类型,见上方说明(默认circle)
33
+ * @property {String} sex-icon 性别图标,man-男,woman-女(默认man)
34
+ * @property {String} level-icon 等级图标(默认level)
35
+ * @property {String} sex-bg-color 性别图标背景颜色
36
+ * @property {String} level-bg-color 等级图标背景颜色
37
+ * @property {String} show-sex 是否显示性别图标(默认false)
38
+ * @property {String} show-level 是否显示等级图标(默认false)
39
+ * @property {String} img-mode 头像图片的裁剪类型,与uni的image组件的mode参数一致,如效果达不到需求,可尝试传widthFix值(默认aspectFill)
40
+ * @property {String} index 用户传递的标识符值,如果是列表循环,可穿v-for的index值
41
+ * @event {Function} click 头像被点击
42
+ * @example <u-avatar :src="src"></u-avatar>
43
+ */
44
+ const props = defineProps({
45
+ /** 背景颜色 */
46
+ bgColor: { type: String, default: 'transparent' },
47
+ /** 头像路径 */
48
+ src: { type: String, default: '' },
49
+ /** 尺寸,large-大,default-中等,mini-小,如果为数值,则单位为rpx,宽度等于高度 */
50
+ size: { type: [String, Number], default: 'default' },
51
+ /** 头像模型,square-带圆角方形,circle-圆形 */
52
+ mode: { type: String, default: 'circle' },
53
+ /** 文字内容 */
54
+ text: { type: String, default: '' },
55
+ /** 图片的裁剪模型 */
56
+ imgMode: { type: String, default: 'aspectFill' },
57
+ /** 标识符 */
58
+ index: { type: [String, Number], default: '' },
59
+ /** 右上角性别角标,man-男,woman-女 */
60
+ sexIcon: { type: String, default: 'man' },
61
+ /** 右下角的等级图标 */
62
+ levelIcon: { type: String, default: 'level' },
63
+ /** 右下角等级图标背景颜色 */
64
+ levelBgColor: { type: String, default: '' },
65
+ /** 右上角性别图标的背景颜色 */
66
+ sexBgColor: { type: String, default: '' },
67
+ /** 是否显示性别图标 */
68
+ showSex: { type: Boolean, default: false },
69
+ /** 是否显示等级图标 */
70
+ showLevel: { type: Boolean, default: false }
71
+ });
72
+
73
+ const emit = defineEmits(['click']);
74
+
75
+ // 头像的地址,因为如果加载错误,需要赋值为默认图片,props值无法修改,所以需要一个中间值
76
+ const avatar = ref(props.src ? props.src : base64Avatar);
77
+ const error = ref(false);
78
+
79
+ // 用户可能会在头像加载失败时,再次修改头像值,所以需要重新赋值
80
+ watch(
81
+ () => props.src,
82
+ n => {
83
+ if (!n) {
84
+ // 如果传入null或者'',或者undefined,显示默认头像
85
+ avatar.value = base64Avatar;
86
+ error.value = true;
87
+ } else {
88
+ avatar.value = n;
89
+ error.value = false;
90
+ }
91
+ }
92
+ );
93
+
94
+ /**
95
+ * 头像外层样式
96
+ */
97
+ const wrapStyle = computed(() => {
98
+ let style: Record<string, string> = {};
99
+ style.height = props.size === 'large' ? '120rpx' : props.size === 'default' ? '90rpx' : props.size === 'mini' ? '70rpx' : props.size + 'rpx';
100
+ style.width = style.height;
101
+ style.flex = `0 0 ${style.height}`;
102
+ style.backgroundColor = props.bgColor;
103
+ style.borderRadius = props.mode === 'circle' ? '500px' : '5px';
104
+ if (props.text) style.padding = '0 6rpx';
105
+ return style;
106
+ });
107
+
108
+ /**
109
+ * 图片样式
110
+ */
111
+ const imgStyle = computed(() => {
112
+ let style: Record<string, string> = {};
113
+ style.borderRadius = props.mode === 'circle' ? '500px' : '5px';
114
+ return style;
115
+ });
116
+
117
+ /**
118
+ * 取字符串的第一个字符
119
+ */
120
+ const uText = computed(() => {
121
+ return String(props.text)[0];
122
+ });
123
+
124
+ /**
125
+ * 性别图标的自定义样式
126
+ */
127
+ const uSexStyle = computed(() => {
128
+ let style: Record<string, string> = {};
129
+ if (props.sexBgColor) style.backgroundColor = props.sexBgColor;
130
+ return style;
131
+ });
132
+
133
+ /**
134
+ * 等级图标的自定义样式
135
+ */
136
+ const uLevelStyle = computed(() => {
137
+ let style: Record<string, string> = {};
138
+ if (props.levelBgColor) style.backgroundColor = props.levelBgColor;
139
+ return style;
140
+ });
141
+
142
+ /**
143
+ * 图片加载错误时,显示默认头像
144
+ */
145
+ function onLoadError() {
146
+ error.value = true;
147
+ avatar.value = base64Avatar;
148
+ }
149
+
150
+ /**
151
+ * 头像被点击
152
+ */
153
+ function onClick() {
154
+ emit('click', props.index);
155
+ }
156
+ </script>
157
+
158
+ <style lang="scss" scoped>
159
+ @import '../../libs/css/style.components.scss';
160
+
161
+ .u-avatar {
162
+ /* #ifndef APP-NVUE */
163
+ display: inline-flex;
164
+ /* #endif */
165
+ align-items: center;
166
+ justify-content: center;
167
+ font-size: 28rpx;
168
+ color: $u-content-color;
169
+ border-radius: 10px;
170
+ position: relative;
171
+
172
+ &__img {
173
+ width: 100%;
174
+ height: 100%;
175
+ }
176
+
177
+ &__sex {
178
+ position: absolute;
179
+ width: 32rpx;
180
+ color: #ffffff;
181
+ height: 32rpx;
182
+ @include vue-flex;
183
+ justify-content: center;
184
+ align-items: center;
185
+ border-radius: 100rpx;
186
+ top: 5%;
187
+ z-index: 1;
188
+ right: -7%;
189
+ border: 1px #ffffff solid;
190
+
191
+ &--man {
192
+ background-color: $u-type-primary;
193
+ }
194
+
195
+ &--woman {
196
+ background-color: $u-type-error;
197
+ }
198
+
199
+ &--none {
200
+ background-color: $u-type-warning;
201
+ }
202
+ }
203
+
204
+ &__level {
205
+ position: absolute;
206
+ width: 32rpx;
207
+ color: #ffffff;
208
+ height: 32rpx;
209
+ @include vue-flex;
210
+ justify-content: center;
211
+ align-items: center;
212
+ border-radius: 100rpx;
213
+ bottom: 5%;
214
+ z-index: 1;
215
+ right: -7%;
216
+ border: 1px #ffffff solid;
217
+ background-color: $u-type-warning;
218
+ }
219
+ }
220
+ </style>