@10yun/cv-mobile-ui 0.5.49 → 0.5.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10yun/cv-mobile-ui",
3
- "version": "0.5.49",
3
+ "version": "0.5.51",
4
4
  "description": "十云cvjs移动端ui,适用uniapp",
5
5
  "author": "10yun",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <view class="cv-mask-icon" :style="iconStyle" @tap="$emit('click', $event)"></view>
3
+ </template>
4
+ <script>
5
+ import maskMixin from '../cv-mask-svg/mixins.js';
6
+ export default {
7
+ name: 'cvMaskPng',
8
+ mixins: [maskMixin],
9
+ data() {
10
+ return {
11
+ iconType: 'png'
12
+ };
13
+ }
14
+ };
15
+ </script>
16
+ <style scoped>
17
+ .cv-mask-icon {
18
+ /* 基础样式重置 */
19
+ display: inline-block;
20
+ vertical-align: middle;
21
+ cursor: pointer;
22
+ }
23
+ /* 悬浮颜色修改:直接切换背景色(精准高效) */
24
+ .cv-mask-icon:hover {
25
+ background-color: v-bind('hoverColor') !important;
26
+ }
27
+ </style>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <view class="mask-icon" :style="iconStyle" @tap="$emit('click', $event)"></view>
3
+ </template>
4
+ <script>
5
+ import maskMixin from './mixins.js';
6
+ export default {
7
+ name: 'cvMaskSvg',
8
+ mixins: [maskMixin]
9
+ };
10
+ </script>
11
+ <style scoped>
12
+ .cv-mask-icon {
13
+ /* 基础样式重置 */
14
+ display: inline-block;
15
+ vertical-align: middle;
16
+ cursor: pointer;
17
+ }
18
+ /* 悬浮颜色修改:直接切换背景色(精准高效) */
19
+ .cv-mask-icon:hover {
20
+ background-color: v-bind('hoverColor') !important;
21
+ }
22
+ </style>
@@ -0,0 +1,131 @@
1
+ export default {
2
+ emits: ['click'],
3
+ props: {
4
+ // 图标类型(对应远程 SVG 遮罩文件名)
5
+ name: {
6
+ type: String,
7
+ required: true,
8
+ validator: (v) => v.trim().length > 0
9
+ },
10
+ // 图标大小(小程序推荐rpx)
11
+ size: {
12
+ type: [Number, String],
13
+ default: 24
14
+ },
15
+ // 图标颜色(精准控制,无需滤镜)
16
+ color: {
17
+ type: String,
18
+ default: '#333333'
19
+ },
20
+ // 悬浮颜色
21
+ hoverColor: {
22
+ type: String,
23
+ default: ''
24
+ },
25
+ // 开启悬浮效果
26
+ hoverEffect: {
27
+ type: Boolean,
28
+ default: false
29
+ }
30
+ },
31
+ data() {
32
+ return {
33
+ iconType: 'svg'
34
+ };
35
+ },
36
+ computed: {
37
+ // 核心修改:将 图片资源 地址替换为 远程 地址(远程 CDN 存放 PNG、SVG 遮罩)
38
+ maskIconUrl() {
39
+ // 远程 CDN 根地址(可抽离为全局常量)
40
+ const cdnBase = 'https://10ui.cn/icons';
41
+ let processedName = this.name || '';
42
+ let iconPath = '';
43
+
44
+ // 步骤1:驼峰命名转连字符分隔(核心:匹配大写字母,添加前置-后转小写)
45
+ // 正则说明:
46
+ // [A-Z] 匹配所有大写字母(驼峰的标识)
47
+ // 替换为:'-' + 匹配到的大写字母(后续步骤2统一转小写,此处可先转小写也可后转)
48
+ processedName = processedName.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`);
49
+ // 处理特殊情况:若字符串以-开头(如原名称以大写字母开头,如 Avatar → -avatar),去除首尾多余-
50
+ processedName = processedName.replace(/^-|-$/g, '');
51
+
52
+ // 步骤2:全部转换为小写(兼容混合大小写场景,如 avatar-Filled → avatar-filled)
53
+ processedName = processedName.toLowerCase().trim();
54
+
55
+ // 步骤3:定义正则,匹配末尾的 -filled(确保是整体,不分割)
56
+ const filledSuffixReg = /-filled$/;
57
+ const isFilledSuffix = filledSuffixReg.test(processedName);
58
+
59
+ if (isFilledSuffix) {
60
+ // 情况A:末尾带 -filled,需要拆分非-filled部分,保留-filled为整体
61
+ // 步骤:先截取除了末尾-filled之外的字符串,再处理分割,最后拼接-filled
62
+ const withoutFilled = processedName.slice(0, processedName.lastIndexOf('-filled'));
63
+ if (withoutFilled) {
64
+ // 非-filled部分有内容(如 xxxx-avatar-filled → withoutFilled = xxxx-avatar)
65
+ // 对非-filled部分按-分割,过滤空元素后拼接为路径
66
+ const pathArr = withoutFilled.split('-').filter((item) => item.trim().length > 0);
67
+ // 拼接:非-filled部分路径 + / + filled整体(如 xxxx/avatar + / + filled → xxxx/avatar-filled)
68
+ iconPath = `${pathArr.join('/')}-filled`;
69
+ } else {
70
+ // 非-filled部分无内容(如直接是 avatar-filled → withoutFilled 为空)
71
+ iconPath = processedName; // 直接使用整体,如 avatar-filled
72
+ }
73
+ } else {
74
+ // 情况B:末尾不带 -filled,正常按-分割拼接
75
+ if (processedName.includes('-')) {
76
+ const pathArr = processedName.split('-').filter((item) => item.trim().length > 0);
77
+ iconPath = pathArr.join('/');
78
+ } else {
79
+ iconPath = processedName;
80
+ }
81
+ }
82
+
83
+ // 处理 iconType,兼容大小写+默认值(保留原有逻辑)
84
+ const targetIconType = this.iconType?.toLowerCase() || 'png';
85
+
86
+ // 拼接最终 URL
87
+ switch (targetIconType) {
88
+ case 'svg':
89
+ return `${cdnBase}/${iconPath}.svg`;
90
+ case 'png':
91
+ return `${cdnBase}/png/${iconPath}.png`;
92
+ default:
93
+ return `${cdnBase}/png/${iconPath}.png`;
94
+ }
95
+ },
96
+ // 处理图标大小
97
+ iconSize() {
98
+ if (typeof this.size === 'string' && (this.size.includes('px') || this.size.includes('rpx'))) {
99
+ return this.size;
100
+ }
101
+ return `${parseFloat(this.size)}px`;
102
+ },
103
+ // 核心样式:mask-image + 背景色(控制颜色)
104
+ iconStyle() {
105
+ const baseStyle = {
106
+ // 图标大小:宽高一致
107
+ width: this.iconSize,
108
+ height: this.iconSize,
109
+ // 图标颜色:通过背景色控制(精准无偏差)
110
+ backgroundColor: this.color,
111
+ // 遮罩层: 引用远程 图片,保留 -webkit- 前缀兼容小程序
112
+ WebkitMaskImage: `url(${this.maskIconUrl})`,
113
+ maskImage: `url(${this.maskIconUrl})`,
114
+ // 遮罩属性: 保持形状完整,不拉伸
115
+ WebkitMaskSize: 'contain',
116
+ maskSize: 'contain',
117
+ WebkitMaskRepeat: 'no-repeat',
118
+ maskRepeat: 'no-repeat',
119
+ WebkitMaskPosition: 'center',
120
+ maskPosition: 'center'
121
+ };
122
+
123
+ // 悬浮过渡效果
124
+ if (this.hoverEffect) {
125
+ baseStyle.transition = 'background-color 0.2s ease';
126
+ }
127
+
128
+ return baseStyle;
129
+ }
130
+ }
131
+ };
@@ -83,5 +83,27 @@ export default {
83
83
  };
84
84
  </script>
85
85
  <style scoped>
86
- @import './style.css';
86
+ /* 不能引入,不然v-bind无法生效 @import './style.css'; */
87
+
88
+ .u-grid {
89
+ /* #ifdef APP-NVUE */
90
+ width: 100%;
91
+ position: relative;
92
+ box-sizing: border-box;
93
+ overflow: hidden;
94
+ display: block;
95
+ /* #endif */
96
+ justify-content: center;
97
+ /* #ifndef APP-NVUE */
98
+ display: flex;
99
+ /* #endif */
100
+ flex-direction: row;
101
+ flex-wrap: wrap;
102
+ align-items: center;
103
+ /* #ifndef APP-NVUE */
104
+ display: grid !important;
105
+ grid-gap: v-bind(gap);
106
+ grid-template-columns: repeat(v-bind(col), 1fr);
107
+ /* #endif */
108
+ }
87
109
  </style>
@@ -65,6 +65,7 @@
65
65
  import { props } from './props';
66
66
  import { mpMixin } from '../../libs/mixin/mpMixin';
67
67
  import { mixin } from '../../libs/mixin/mixin';
68
+ import { addUnit, addStyle, getWindowInfo, getPx } from '../../libs/function/index';
68
69
  /**
69
70
  * Navbar 自定义导航栏
70
71
  * @description 此组件一般用于在特殊情况下,需要自定义导航栏的时候用到,自动状态栏高度、小程序胶囊预留位置等,一般建议使用uni-app带的导航栏。