uview-pro 0.0.8 → 0.0.10

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 CHANGED
@@ -1,8 +1,23 @@
1
+ ## 0.0.10(2025-08-26)
2
+
3
+ ### ✨ Features | 新功能
4
+
5
+ - 添加 easycom 组件自动扫描 ([b125039](https://gitee.com/anyup/uView-Pro/commit/b1250390a4f594f5deaa133d7a92bd6e72707890))
6
+ - 增强 u-select 组件的类型安全和功能 ([38635e9](https://gitee.com/anyup/uView-Pro/commit/38635e963f9eff6e4c730692e8c97f10b3a092c5))
7
+
8
+ ## 0.0.9(2025-08-25)
9
+
10
+ ### ♻️ Code Refactoring | 代码重构
11
+
12
+ - 优化全局工具导出方式 ([7a80b6f](https://gitee.com/anyup/uView-Pro/commit/7a80b6f99ad3022ca995f99f8ec6803af7941eb9))
13
+
1
14
  ## 0.0.8(2025-08-25)
15
+
2
16
  ### ♻️ Code Refactoring | 代码重构
3
17
 
4
18
  - 重构组件 Props 属性定义,每个组件具有完善的 ts 类型定义 ([8cc0de7](https://gitee.com/anyup/uView-Pro/commit/8cc0de7c1527b48dd223d89207135eea01766294))
5
19
  - 重构类型定义并统一到全局类型文件 global types ([b0fd010](https://gitee.com/anyup/uView-Pro/commit/b0fd0107289eb1c6df2f58d91b63d9b25902caee))
20
+
6
21
  ## 0.0.7(2025-08-21)
7
22
 
8
23
  ### 🐛 Bug Fixes | Bug 修复
@@ -1,5 +1,5 @@
1
1
  import type { ExtractPropTypes, PropType } from 'vue';
2
- import type { SelectMode } from '../../types/global';
2
+ import type { SelectListItem, SelectMode } from '../../types/global';
3
3
 
4
4
  /**
5
5
  * SelectProps 列选择器 props 类型定义
@@ -7,7 +7,7 @@ import type { SelectMode } from '../../types/global';
7
7
  */
8
8
  export const SelectProps = {
9
9
  /** 列数据 */
10
- list: { type: Array as PropType<any[]>, default: () => [] },
10
+ list: { type: Array as PropType<SelectListItem[] | SelectListItem[][]>, default: () => [] },
11
11
  /** 是否显示边框 */
12
12
  border: { type: Boolean, default: true },
13
13
  /** 通过双向绑定控制组件的弹出与收起 */
@@ -9,45 +9,29 @@
9
9
  <u-icon name="arrow-down-fill" size="26" color="#c0c4cc"></u-icon>
10
10
  </view>
11
11
  </view> -->
12
- <u-popup
13
- :maskCloseAble="maskCloseAble"
14
- mode="bottom"
15
- :popup="false"
16
- v-model="popupValue"
17
- length="auto"
18
- :safeAreaInsetBottom="safeAreaInsetBottom"
19
- @close="close"
20
- :z-index="uZIndex"
21
- >
12
+ <u-popup :maskCloseAble="maskCloseAble" mode="bottom" :popup="false" v-model="popupValue" length="auto"
13
+ :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex">
22
14
  <view class="u-select">
23
15
  <view class="u-select__header" @touchmove.stop.prevent="">
24
- <view
25
- class="u-select__header__cancel u-select__header__btn"
26
- :style="{ color: cancelColor }"
27
- hover-class="u-hover-class"
28
- :hover-stay-time="150"
29
- @tap="getResult('cancel')"
30
- >
16
+ <view class="u-select__header__cancel u-select__header__btn" :style="{ color: cancelColor }"
17
+ hover-class="u-hover-class" :hover-stay-time="150" @tap="getResult('cancel')">
31
18
  {{ cancelText }}
32
19
  </view>
33
20
  <view class="u-select__header__title">
34
21
  {{ title }}
35
22
  </view>
36
- <view
37
- class="u-select__header__confirm u-select__header__btn"
38
- :style="{ color: moving ? cancelColor : confirmColor }"
39
- hover-class="u-hover-class"
40
- :hover-stay-time="150"
41
- @touchmove.stop=""
42
- @tap.stop="getResult('confirm')"
43
- >
23
+ <view class="u-select__header__confirm u-select__header__btn"
24
+ :style="{ color: moving ? cancelColor : confirmColor }" hover-class="u-hover-class"
25
+ :hover-stay-time="150" @touchmove.stop="" @tap.stop="getResult('confirm')">
44
26
  {{ confirmText }}
45
27
  </view>
46
28
  </view>
47
29
  <view class="u-select__body">
48
- <picker-view @change="columnChange" class="u-select__body__picker-view" :value="defaultSelector" @pickstart="pickstart" @pickend="pickend" v-if="modelValue">
30
+ <picker-view @change="columnChange" class="u-select__body__picker-view" :value="defaultSelector"
31
+ @pickstart="pickstart" @pickend="pickend" v-if="modelValue">
49
32
  <picker-view-column v-for="(item, index) in columnData" :key="index">
50
- <view class="u-select__body__picker-view__item" v-for="(item1, index1) in item" :key="index1">
33
+ <view class="u-select__body__picker-view__item" v-for="(item1, index1) in item"
34
+ :key="index1">
51
35
  <view class="u-line-1">{{ item1[labelName] }}</view>
52
36
  </view>
53
37
  </picker-view-column>
@@ -61,6 +45,7 @@
61
45
  <script setup lang="ts">
62
46
  import { ref, computed, watch } from 'vue';
63
47
  import { SelectProps } from './types';
48
+ import type { SelectListItem } from '../../types/global';
64
49
 
65
50
  defineOptions({
66
51
  name: 'u-select'
@@ -94,9 +79,9 @@ const emit = defineEmits(['update:modelValue', 'confirm', 'cancel', 'click']);
94
79
 
95
80
  const defaultSelector = ref<number[]>([0]);
96
81
  // picker-view的数据
97
- const columnData = ref<any[][]>([]);
82
+ const columnData = ref<SelectListItem[][]>([]);
98
83
  // 每次队列发生变化时,保存选择的结果
99
- const selectValue = ref<any[]>([]);
84
+ const selectValue = ref<SelectListItem[]>([]);
100
85
  // 上一次列变化时的index
101
86
  const lastSelectIndex = ref<number[]>([]);
102
87
  // 列数
@@ -164,7 +149,7 @@ function setColumnNum() {
164
149
 
165
150
  // 获取需要展示在picker中的列数据
166
151
  function setColumnData() {
167
- let data: any[][] = [];
152
+ let data: SelectListItem[][] = [];
168
153
  selectValue.value = [];
169
154
  if (props.mode == 'mutil-column-auto') {
170
155
  // 获得所有数据中的第一个元素
@@ -173,7 +158,7 @@ function setColumnData() {
173
158
  for (let i = 0; i < columnNum.value; i++) {
174
159
  // 第一列默认为整个list数组
175
160
  if (i == 0) {
176
- data[i] = props.list;
161
+ data[i] = is2DList(props.list) ? props.list[i] || [] : props.list as SelectListItem[];
177
162
  column = column && typeof column === 'object' ? column[props.childName] : [];
178
163
  } else {
179
164
  // 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项
@@ -185,9 +170,9 @@ function setColumnData() {
185
170
  }
186
171
  }
187
172
  } else if (props.mode == 'single-column') {
188
- data[0] = props.list;
173
+ data[0] = Array.isArray(props.list) && !is2DList(props.list) ? props.list as SelectListItem[] : [];
189
174
  } else if (props.mode == 'mutil-column') {
190
- data = props.list as any[][];
175
+ data = is2DList(props.list) ? props.list : [props.list as SelectListItem[]];
191
176
  }
192
177
  columnData.value = data;
193
178
  }
@@ -286,6 +271,11 @@ function getResult(event: 'update:modelValue' | 'confirm' | 'cancel' | 'click' |
286
271
  function selectHandler() {
287
272
  emit('click');
288
273
  }
274
+
275
+ // 类型守卫提前声明
276
+ function is2DList(list: SelectListItem[] | SelectListItem[][]): list is SelectListItem[][] {
277
+ return Array.isArray(list) && list.length > 0 && Array.isArray(list[0]);
278
+ }
289
279
  </script>
290
280
 
291
281
  <style scoped lang="scss">
package/index.ts CHANGED
@@ -9,7 +9,7 @@ import timeFormat from './libs/function/timeFormat';
9
9
  // 时间戳格式化,返回多久之前
10
10
  import timeFrom from './libs/function/timeFrom';
11
11
  // 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
12
- import colorGradient from './libs/function/colorGradient';
12
+ import colorGradients from './libs/function/colorGradient';
13
13
  // 生成全局唯一guid字符串
14
14
  import guid from './libs/function/guid';
15
15
  // 主题相关颜色,info|success|warning|primary|default|error,此颜色已在uview.scss中定义,但是为js中也能使用,故也定义一份
@@ -75,8 +75,8 @@ export interface UViewUtils {
75
75
  timeFormat: typeof timeFormat;
76
76
  date: typeof timeFormat;
77
77
  timeFrom: typeof timeFrom;
78
- colorGradient: typeof colorGradient.colorGradient;
79
- colorToRgba: typeof colorGradient.colorToRgba;
78
+ colorGradient: typeof colorGradients.colorGradient;
79
+ colorToRgba: typeof colorGradients.colorToRgba;
80
80
  guid: typeof guid;
81
81
  color: typeof color;
82
82
  sys: typeof sys;
@@ -89,8 +89,8 @@ export interface UViewUtils {
89
89
  post: typeof http.post;
90
90
  put: typeof http.put;
91
91
  delete: typeof http.delete;
92
- hexToRgb: typeof colorGradient.hexToRgb;
93
- rgbToHex: typeof colorGradient.rgbToHex;
92
+ hexToRgb: typeof colorGradients.hexToRgb;
93
+ rgbToHex: typeof colorGradients.rgbToHex;
94
94
  test: typeof test;
95
95
  random: typeof random;
96
96
  deepClone: typeof deepClone;
@@ -118,8 +118,8 @@ export const $u: UViewUtils = {
118
118
  timeFormat: timeFormat,
119
119
  date: timeFormat, // 另名date
120
120
  timeFrom,
121
- colorGradient: colorGradient.colorGradient,
122
- colorToRgba: colorGradient.colorToRgba,
121
+ colorGradient: colorGradients.colorGradient,
122
+ colorToRgba: colorGradients.colorToRgba,
123
123
  guid,
124
124
  color,
125
125
  sys,
@@ -132,8 +132,8 @@ export const $u: UViewUtils = {
132
132
  post: http.post,
133
133
  put: http.put,
134
134
  delete: http.delete,
135
- hexToRgb: colorGradient.hexToRgb,
136
- rgbToHex: colorGradient.rgbToHex,
135
+ hexToRgb: colorGradients.hexToRgb,
136
+ rgbToHex: colorGradients.rgbToHex,
137
137
  test,
138
138
  random,
139
139
  deepClone,
@@ -164,3 +164,39 @@ const install = (): void => {
164
164
  export default {
165
165
  install
166
166
  };
167
+
168
+ // 工具方法单独导出,支持 import { deepClone } from 'uview-pro'
169
+ export {
170
+ queryParams,
171
+ route,
172
+ timeFormat,
173
+ timeFrom,
174
+ guid,
175
+ color,
176
+ sys,
177
+ os,
178
+ type2icon,
179
+ randomArray,
180
+ deepClone,
181
+ deepMerge,
182
+ addUnit,
183
+ test,
184
+ random,
185
+ trim,
186
+ toast,
187
+ debounce,
188
+ throttle,
189
+ getRect,
190
+ getParent,
191
+ $parent,
192
+ parent,
193
+ parentData,
194
+ dispatch,
195
+ broadcast,
196
+ http,
197
+ config,
198
+ zIndex
199
+ };
200
+
201
+ // 颜色相关方法单独导出
202
+ export const { colorGradient, colorToRgba, hexToRgb, rgbToHex } = colorGradients;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "id": "uview-pro",
3
3
  "name": "uview-pro",
4
- "displayName": "uView Pro 基于Vue3+TS全面重构的UI组件库,拥有70+精选组件",
5
- "version": "0.0.8",
4
+ "displayName": "【Vue3重构版】uView Pro 基于Vue3+TS全面重构的70+精选UI组件库",
5
+ "version": "0.0.10",
6
6
  "description": "uView Pro,是全面支持Vue3的uni-app生态框架,70+精选组件已使用TypeScript重构,已全面支持uni-app Vue3.0",
7
7
  "main": "index.ts",
8
8
  "module": "index.ts",
package/readme.md CHANGED
@@ -69,7 +69,7 @@ uView Pro QQ 交流群: [点击进入](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027
69
69
 
70
70
  <table class="table">
71
71
  <tr>
72
- <td><img src="https://ik.imagekit.io/anyup/images/social/weixin-chat.png?updatedAt=1755597368053" width="250" height="345" ></td>
72
+ <td><img src="https://ik.imagekit.io/anyup/images/social/weixin-chat.png?updatedAt=1756174917808" width="250" height="345" ></td>
73
73
  <td><img src="https://ik.imagekit.io/anyup/images/social/qq-chat.png" width="250" height="345" ></td>
74
74
  </tr>
75
75
  <tr>
@@ -103,85 +103,124 @@ pnpm add uview-pro
103
103
 
104
104
  [https://ext.dcloud.net.cn/plugin?id=24633](https://ext.dcloud.net.cn/plugin?id=24633)
105
105
 
106
- ## 快速上手
106
+ ## 配置
107
107
 
108
- 1. `main.ts`引入 uView
108
+ uView Pro 支持 `npm` `uni_modules` 两种主流安装方式,配置方式高度一致。无论采用哪种方式,均可通过 easycom 实现组件自动引入,极大提升开发效率。以下为统一的配置说明:
109
+
110
+ ### 1. 安装 uView Pro
111
+
112
+ - npm 安装:
113
+
114
+ ```bash
115
+ npm install uview-pro
116
+ # 或
117
+ yarn add uview-pro
118
+ # 或
119
+ pnpm add uview-pro
120
+ ```
121
+
122
+ - uni_modules 安装:
123
+
124
+ 通过 HBuilderX 插件市场或手动下载,将 uView Pro 放入 `uni_modules` 目录。
125
+
126
+ [插件市场:https://ext.dcloud.net.cn/plugin?id=24633](https://ext.dcloud.net.cn/plugin?id=24633)
127
+
128
+ ### 2. 引入 uView Pro 主库
129
+
130
+ 在 `main.ts` 中引入并注册 uView Pro:
109
131
 
110
132
  ```js
111
133
  // main.ts
112
134
  import { createSSRApp } from 'vue';
113
- // npm安装方式
135
+ // npm 方式
114
136
  import uViewPro from 'uview-pro';
115
-
116
- // uni_modules安装方式
117
- // import uViewPro from '@/uni_modules/uview-pro';
137
+ // uni_modules 方式
138
+ // import uViewPro from "@/uni_modules/uview-pro";
118
139
 
119
140
  export function createApp() {
120
141
  const app = createSSRApp(App);
121
142
  app.use(uViewPro);
122
- // 其他配置
123
143
  return {
124
144
  app
125
145
  };
126
146
  }
127
147
  ```
128
148
 
129
- 2. `App.vue`引入基础样式(注意 style 标签需声明 scss 属性支持)
149
+ ### 3. 引入全局样式
130
150
 
131
- ```css
132
- /* App.vue */
133
- <style lang="scss">
134
- /* npm安装方式 */
135
- @import "uview-pro/index.scss";
151
+ 在 `uni.scss` 中引入主题样式:
136
152
 
137
- /* uni_modules安装方式 */
138
- /* @import "@/uni_modules/uview-pro/index.scss"; */
139
- </style>
153
+ ```scss
154
+ /* uni.scss */
155
+ // npm 方式
156
+ @import 'uview-pro/theme.scss';
157
+ // uni_modules 方式
158
+ // @import "@/uni_modules/uview-pro/theme.scss";
140
159
  ```
141
160
 
142
- 3. `uni.scss`引入全局 scss 变量文件
143
-
144
- ```css
145
- /* npm安装方式 */
146
- @import 'uview-pro/theme.scss';
161
+ `App.vue` 首行引入基础样式:
147
162
 
148
- /* uni_modules安装方式 */
149
- /* @import '@/uni_modules/uview-pro/theme.scss'; */
163
+ ```scss
164
+ <style lang="scss">
165
+ // npm 方式
166
+ @import "uview-pro/index.scss";
167
+ // uni_modules 方式
168
+ // @import "@/uni_modules/uview-pro/index.scss";
169
+ </style>
150
170
  ```
151
171
 
152
- 4. `pages.json`配置 easycom 规则(按需引入)
172
+ ### 4. 配置 easycom 自动引入组件
153
173
 
154
- ```js
174
+ 在 `pages.json` 中配置 easycom 规则,实现组件自动引入:
175
+
176
+ ```json
155
177
  // pages.json
156
178
  {
157
179
  "easycom": {
158
- // 注意一定要放在custom里,否则无效,https://ask.dcloud.net.cn/question/131175
180
+ "autoscan": true,
159
181
  "custom": {
160
- // uni_modules安装的方式需要前面的"@/uni_modules/",npm安装的方式无需"@/",以下方式任选其一
161
- // npm安装方式
182
+ // npm 方式
162
183
  "^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
163
- // uni_modules安装方式
184
+ // uni_modules 方式
164
185
  // "^u-(.*)": "@/uni_modules/uview-pro/components/u-$1/u-$1.vue"
165
186
  }
166
187
  },
167
- // 此为本身已有的内容
168
188
  "pages": [
169
- // ......
189
+ // ...
170
190
  ]
171
191
  }
172
192
  ```
173
193
 
174
- 请通过[快速上手](https://uview-pro.netlify.app/components/quickstart.html)了解更详细的内容
194
+ **温馨提示**
195
+
196
+ - 1.修改 `easycom` 规则后需重启 HX 或重新编译项目。
197
+ - 2.请确保 `pages.json` 中只有一个 easycom 字段,否则请自行合并多个规则。
198
+ - 3.一定要放在 `custom` 内,否则无效。
199
+
200
+ ### 5. Volar 类型提示支持
201
+
202
+ 如需在 CLI 项目中获得 Volar 的全局类型提示,请在 `tsconfig.json` 中添加:
203
+
204
+ ```json
205
+ {
206
+ "compilerOptions": {
207
+ // npm 方式
208
+ "types": ["uview-pro/types"]
209
+ // uni_modules 方式
210
+ // "types": ["@/uni_modules/uview-pro/types"]
211
+ }
212
+ }
213
+ ```
175
214
 
176
- ## 使用方法
215
+ > HBuilderX 项目暂不支持 tsconfig.json 的 types 配置,CLI 项目推荐配置以获得最佳 TS 体验。
177
216
 
178
- 配置 easycom 规则后,自动按需引入,无需`import`组件,直接引用即可。
217
+ ### 6. 组件使用
179
218
 
180
- > 注意:配置完以上规则后,一定要重新运行 uni-app 项目,否则不会生效
219
+ 配置完成后,无需 import components 注册,可直接在 SFC 中使用 uView Pro 组件:
181
220
 
182
- ```html
221
+ ```vue
183
222
  <template>
184
- <u-button>按钮</u-button>
223
+ <u-button type="primary">按钮</u-button>
185
224
  </template>
186
225
  ```
187
226
 
package/types/global.d.ts CHANGED
@@ -148,6 +148,14 @@ export type RowAlign = 'top' | 'center' | 'bottom';
148
148
  export type SearchShape = 'round' | 'square';
149
149
  // select 组件 mode single-column-单列,mutil-column-多列,mutil-column-auto-多列联动
150
150
  export type SelectMode = 'single-column' | 'mutil-column' | 'mutil-column-auto';
151
+ // select 组件 list item
152
+ export type SelectListItem = {
153
+ label: string;
154
+ value: string | number;
155
+ children?: SelectListItem[];
156
+ extra?: any;
157
+ [key: string]: any;
158
+ };
151
159
  // Step 组件 mode
152
160
  export type StepsListItem = {
153
161
  name: string;