@tzk-design-vue2/shared 1.0.0
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/README.md +70 -0
- package/adapters/api.js +234 -0
- package/adapters/event.js +86 -0
- package/adapters/style.js +89 -0
- package/config/error.js +36 -0
- package/index.js +32 -0
- package/mixins/component.js +44 -0
- package/mixins/error-boundary.js +15 -0
- package/mixins/event.js +44 -0
- package/mixins/form.js +81 -0
- package/package.json +21 -0
- package/store/index.js +19 -0
- package/store/modules/component.js +124 -0
- package/styles/index.css +21 -0
- package/styles/index.less +9 -0
- package/styles/mixins.css +18 -0
- package/styles/mixins.less +136 -0
- package/styles/variables/color.css +4 -0
- package/styles/variables/color.less +54 -0
- package/styles/variables/common.css +3 -0
- package/styles/variables/common.less +64 -0
- package/styles/variables/spacing.css +4 -0
- package/styles/variables/spacing.less +38 -0
- package/styles/variables/typography.css +3 -0
- package/styles/variables/typography.less +35 -0
- package/utils/dom.js +134 -0
- package/utils/error-handler.js +191 -0
- package/utils/format.js +127 -0
- package/utils/performance.js +137 -0
- package/utils/platform.js +179 -0
- package/utils/type.js +105 -0
- package/utils/warn.js +64 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平台判断工具函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-unreachable */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 获取系统信息
|
|
9
|
+
* @returns {Object}
|
|
10
|
+
*/
|
|
11
|
+
let systemInfo = null;
|
|
12
|
+
|
|
13
|
+
export function getSystemInfo() {
|
|
14
|
+
if (systemInfo) return systemInfo;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
systemInfo = uni.getSystemInfoSync();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
systemInfo = {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return systemInfo;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 是否为微信小程序
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
export function isWeixin() {
|
|
30
|
+
// #ifdef MP-WEIXIN
|
|
31
|
+
return true;
|
|
32
|
+
// #endif
|
|
33
|
+
// #ifndef MP-WEIXIN
|
|
34
|
+
return false;
|
|
35
|
+
// #endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 是否为支付宝小程序
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
export function isAlipay() {
|
|
43
|
+
// #ifdef MP-ALIPAY
|
|
44
|
+
return true;
|
|
45
|
+
// #endif
|
|
46
|
+
// #ifndef MP-ALIPAY
|
|
47
|
+
return false;
|
|
48
|
+
// #endif
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 是否为百度小程序
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
export function isBaidu() {
|
|
56
|
+
// #ifdef MP-BAIDU
|
|
57
|
+
return true;
|
|
58
|
+
// #endif
|
|
59
|
+
// #ifndef MP-BAIDU
|
|
60
|
+
return false;
|
|
61
|
+
// #endif
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 是否为字节跳动小程序
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
export function isToutiao() {
|
|
69
|
+
// #ifdef MP-TOUTIAO
|
|
70
|
+
return true;
|
|
71
|
+
// #endif
|
|
72
|
+
// #ifndef MP-TOUTIAO
|
|
73
|
+
return false;
|
|
74
|
+
// #endif
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 是否为 QQ 小程序
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
export function isQQ() {
|
|
82
|
+
// #ifdef MP-QQ
|
|
83
|
+
return true;
|
|
84
|
+
// #endif
|
|
85
|
+
// #ifndef MP-QQ
|
|
86
|
+
return false;
|
|
87
|
+
// #endif
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 是否为 H5
|
|
92
|
+
* @returns {boolean}
|
|
93
|
+
*/
|
|
94
|
+
export function isH5() {
|
|
95
|
+
// #ifdef H5
|
|
96
|
+
return true;
|
|
97
|
+
// #endif
|
|
98
|
+
// #ifndef H5
|
|
99
|
+
return false;
|
|
100
|
+
// #endif
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 是否为 App
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
export function isApp() {
|
|
108
|
+
// #ifdef APP-PLUS
|
|
109
|
+
return true;
|
|
110
|
+
// #endif
|
|
111
|
+
// #ifndef APP-PLUS
|
|
112
|
+
return false;
|
|
113
|
+
// #endif
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 是否为小程序环境
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
*/
|
|
120
|
+
export function isMiniProgram() {
|
|
121
|
+
return isWeixin() || isAlipay() || isBaidu() || isToutiao() || isQQ();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 是否为 iOS
|
|
126
|
+
* @returns {boolean}
|
|
127
|
+
*/
|
|
128
|
+
export function isIOS() {
|
|
129
|
+
const system = getSystemInfo();
|
|
130
|
+
return system.platform === 'ios';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 是否为 Android
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
export function isAndroid() {
|
|
138
|
+
const system = getSystemInfo();
|
|
139
|
+
return system.platform === 'android';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 获取平台名称
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
146
|
+
export function getPlatform() {
|
|
147
|
+
if (isWeixin()) return 'weixin';
|
|
148
|
+
if (isAlipay()) return 'alipay';
|
|
149
|
+
if (isBaidu()) return 'baidu';
|
|
150
|
+
if (isToutiao()) return 'toutiao';
|
|
151
|
+
if (isQQ()) return 'qq';
|
|
152
|
+
if (isH5()) return 'h5';
|
|
153
|
+
if (isApp()) return 'app';
|
|
154
|
+
return 'unknown';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* rpx 转 px
|
|
159
|
+
* @param {number} rpx - rpx 值
|
|
160
|
+
* @returns {number}
|
|
161
|
+
*/
|
|
162
|
+
export function rpxToPx(rpx) {
|
|
163
|
+
const system = getSystemInfo();
|
|
164
|
+
const screenWidth = system.screenWidth || 375;
|
|
165
|
+
return (rpx / 750) * screenWidth;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* px 转 rpx
|
|
170
|
+
* @param {number} px - px 值
|
|
171
|
+
* @returns {number}
|
|
172
|
+
*/
|
|
173
|
+
export function pxToRpx(px) {
|
|
174
|
+
const system = getSystemInfo();
|
|
175
|
+
const screenWidth = system.screenWidth || 375;
|
|
176
|
+
return (px / screenWidth) * 750;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* eslint-enable no-unreachable */
|
package/utils/type.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 类型判断工具函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取数据类型
|
|
7
|
+
* @param {*} value
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function getType(value) {
|
|
11
|
+
return Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 是否为字符串
|
|
16
|
+
* @param {*} value
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
export function isString(value) {
|
|
20
|
+
return typeof value === 'string';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 是否为数字
|
|
25
|
+
* @param {*} value
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function isNumber(value) {
|
|
29
|
+
return typeof value === 'number' && !isNaN(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 是否为布尔值
|
|
34
|
+
* @param {*} value
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function isBoolean(value) {
|
|
38
|
+
return typeof value === 'boolean';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 是否为数组
|
|
43
|
+
* @param {*} value
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
46
|
+
export function isArray(value) {
|
|
47
|
+
return Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 是否为对象
|
|
52
|
+
* @param {*} value
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
export function isObject(value) {
|
|
56
|
+
return value !== null && typeof value === 'object' && !isArray(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 是否为函数
|
|
61
|
+
* @param {*} value
|
|
62
|
+
* @returns {boolean}
|
|
63
|
+
*/
|
|
64
|
+
export function isFunction(value) {
|
|
65
|
+
return typeof value === 'function';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 是否已定义
|
|
70
|
+
* @param {*} value
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function isDef(value) {
|
|
74
|
+
return value !== undefined && value !== null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 是否未定义
|
|
79
|
+
* @param {*} value
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
*/
|
|
82
|
+
export function isUndef(value) {
|
|
83
|
+
return value === undefined || value === null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 是否为空
|
|
88
|
+
* @param {*} value
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
export function isEmpty(value) {
|
|
92
|
+
if (isUndef(value)) return true;
|
|
93
|
+
if (isArray(value) || isString(value)) return value.length === 0;
|
|
94
|
+
if (isObject(value)) return Object.keys(value).length === 0;
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 是否为 Promise
|
|
100
|
+
* @param {*} value
|
|
101
|
+
* @returns {boolean}
|
|
102
|
+
*/
|
|
103
|
+
export function isPromise(value) {
|
|
104
|
+
return isDef(value) && isFunction(value.then) && isFunction(value.catch);
|
|
105
|
+
}
|
package/utils/warn.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 开发环境警告系统
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 打印警告信息
|
|
7
|
+
* @param {string} message - 警告信息
|
|
8
|
+
* @param {Object} context - 上下文
|
|
9
|
+
*/
|
|
10
|
+
export function warn(message, context) {
|
|
11
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
12
|
+
|
|
13
|
+
console.warn(`[TZK Warn] ${message}`);
|
|
14
|
+
|
|
15
|
+
if (context) {
|
|
16
|
+
console.warn('[TZK Warn Context]', context);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Props 类型校验警告
|
|
22
|
+
* @param {string} propName - 属性名
|
|
23
|
+
* @param {*} value - 属性值
|
|
24
|
+
* @param {string} expectedType - 期望类型
|
|
25
|
+
* @param {string} componentName - 组件名
|
|
26
|
+
*/
|
|
27
|
+
export function warnPropType(propName, value, expectedType, componentName) {
|
|
28
|
+
const actualType = typeof value;
|
|
29
|
+
warn(
|
|
30
|
+
`Invalid prop: type check failed for prop "${propName}". Expected ${expectedType}, got ${actualType}.`,
|
|
31
|
+
{ componentName, propName, value }
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 废弃 API 警告
|
|
37
|
+
* @param {string} oldApi - 旧 API
|
|
38
|
+
* @param {string} newApi - 新 API
|
|
39
|
+
* @param {string} version - 废弃版本
|
|
40
|
+
*/
|
|
41
|
+
export function warnDeprecated(oldApi, newApi, version) {
|
|
42
|
+
warn(
|
|
43
|
+
`"${oldApi}" is deprecated and will be removed in version ${version}. Please use "${newApi}" instead.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 性能警告
|
|
49
|
+
* @param {string} message - 警告信息
|
|
50
|
+
* @param {Object} data - 数据
|
|
51
|
+
*/
|
|
52
|
+
export function warnPerformance(message, data) {
|
|
53
|
+
warn(`Performance warning: ${message}`, data);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 最佳实践建议
|
|
58
|
+
* @param {string} message - 建议信息
|
|
59
|
+
*/
|
|
60
|
+
export function suggestBestPractice(message) {
|
|
61
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
62
|
+
|
|
63
|
+
console.info(`[TZK Suggestion] ${message}`);
|
|
64
|
+
}
|