@weitutech/by-components-v3 1.0.0 → 1.0.7

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 CHANGED
@@ -1,39 +1,396 @@
1
- # vue3-comps
1
+ # @weitutech/by-components-v3
2
2
 
3
- This template should help get you started developing with Vue 3 in Vite.
3
+ ### npm 安装
4
+
5
+ ```
6
+ 安装时切换淘宝源比较快
7
+ npm config set registry https://registry.npmmirror.com/
8
+
9
+ npm install @weitutech/by-components
10
+ ```
11
+
12
+ ### 引入
13
+
14
+ ```
15
+ import ByComponentsV3 from "@weitutech/by-components-v3/dist/by-component-v3"
16
+ import "@weitutech/by-components-v3/dist/by-component-v3.css"
17
+ ```
18
+
19
+ ### npm 发布
20
+
21
+ ```
22
+ 第一次发布
23
+ npm login
24
+
25
+ 发布时需要确保npm的源是官方 npm
26
+ npm config set registry https://registry.npmjs.org/
4
27
 
5
- ## Recommended IDE Setup
6
28
 
7
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
29
+ 出现功能修改后,需更新package的版本号
30
+ 清除缓存
31
+ npm cache clean --force
32
+ 发布
33
+ npm publish --access public
34
+ ```
35
+
36
+ ### 注意事项
37
+
38
+ 1. 本地开发时可采用 npm link 方式关联依赖,package 入口配置为 src/main.js
8
39
 
9
- ## Type Support for `.vue` Imports in TS
40
+ ### npm link
10
41
 
11
- TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
42
+ ```
43
+ 组件库中运行 npm link
44
+ 项目中运行 npm link @weitutech/by-components-v3
45
+ ```
12
46
 
13
- ## Customize configuration
47
+ ### 关于新组件开发
14
48
 
15
- See [Vite Configuration Reference](https://vite.dev/config/).
49
+ 1. 采用 by 为前缀命名方式
50
+ 2. 避免过度耦合,考虑不同项目的复用性,尽量避免组件内调取接口
16
51
 
17
- ## Project Setup
52
+ ### 表单 by-page-search
18
53
 
19
- ```sh
20
- npm install
21
54
  ```
55
+ <template>
56
+ <by-page-search
57
+ ref="pageSearchRef"
58
+ v-model="searchQuery"
59
+ :search-form-config="formConfig"
60
+ @queryBtnClick="handleQueryClick"
61
+ @change="handleChangePageSearch"
62
+ >
63
+ <template #custom>
64
+ 我是外部自定义内容
65
+ </template>
66
+ </by-page-search>
67
+ </template>
68
+
69
+ <script setup>
70
+ import { ref } from "vue"
22
71
 
23
- ### Compile and Hot-Reload for Development
72
+ const searchQuery = ref({
73
+ // 对应formConfig对象中formItems中的每个field
74
+ })
75
+
76
+ const formConfig = ref({
77
+ labelWidth: "80px",
78
+ itemStyle: {
79
+ padding: "0px 0px"
80
+ },
81
+ // 需要折叠的字段、不分顺序、写在里面的字段都会被隐藏 --- 仅在isFlexible = true 才可用
82
+ flexible: {
83
+ // 这里模拟写一些
84
+ foldField: ["area_id", "department_id", "team_id", "user_id", "favourite_id", "category_id", "brand_id"]
85
+ },
86
+ // 是否开启折叠功能
87
+ isFlexible: true,
88
+ colLayout: {
89
+ xs: 24,
90
+ sm: 12,
91
+ md: 12,
92
+ lg: 6,
93
+ xl: 4
94
+ },
95
+ elSize: "default",
96
+ // 对应表单单独的显隐权限 可设置isHidden来控制
97
+ formItems: [
98
+ // 输入框
99
+ {
100
+ id: 1, // 作为可选的唯一标识,如果field有重复可以设置id作为唯一标识
101
+ field: "input",
102
+ type: "input",
103
+ label: "输入框",
104
+ placeholder: "请输入",
105
+ labelWidth: "70px",
106
+ isHidden: false, // 是否隐藏 false || true
107
+ attrs: {
108
+ // 其他选项配置、参考Element的输入框配置
109
+ }
110
+ },
111
+ // 密码输入框
112
+ {
113
+ field: "password",
114
+ type: "password",
115
+ label: "密码输入框",
116
+ placeholder: "请输入密码",
117
+ labelWidth: "70px",
118
+ attrs: {
119
+ // 其他选项配置、参考Element的输入框配置
120
+ }
121
+ },
122
+ // 选择器
123
+ {
124
+ field: "select",
125
+ type: "select",
126
+ label: "选择器",
127
+ placeholder: "请选择",
128
+ labelWidth: "100px",
129
+ mode: "", // 可选 "group" || false 默认 不传不用配置 group为分组模式
130
+ options: [
131
+ // 必须按照label、value的键值对传入
132
+ { label: "全选", value: undefined },
133
+ { label: "选项一", value: "one" },
134
+ { label: "选项二", value: "two" }
135
+ ],
136
+ attrs: {
137
+ // 其他配置、参考Element的选择器配置
138
+ },
139
+ colLayout: {
140
+ xs: 24,
141
+ sm: 8,
142
+ md: 8,
143
+ lg: 4,
144
+ xl: 4
145
+ }
146
+ },
147
+ // 日期选择器
148
+ {
149
+ field: "datepicker",
150
+ type: "datepicker",
151
+ label: "日期选择器",
152
+ placeholder: "请选择日期",
153
+ labelWidth: "70px",
154
+ attrs: {
155
+ // 其他选项配置、参考Element的配置
156
+ }
157
+ },
158
+ // 级联
159
+ {
160
+ field: "cascader",
161
+ type: "cascader",
162
+ label: "级联",
163
+ placeholder: "请选择",
164
+ labelWidth: "70px",
165
+ options: [], // 于Element保持一致
166
+ attrs: {
167
+ // 其他选项配置、参考Element的配置
168
+ }
169
+ },
170
+ // 开关
171
+ {
172
+ field: "switch",
173
+ type: "switch",
174
+ label: "开关",
175
+ labelWidth: "70px",
176
+ attrs: {
177
+ // 其他选项配置、参考Element的配置
178
+ }
179
+ },
180
+ // 单选框
181
+ {
182
+ field: "radioGroup",
183
+ type: "radioGroup",
184
+ label: "单选框",
185
+ labelWidth: "70px",
186
+ attrs: {
187
+ // 其他选项配置、参考Element的配置
188
+ },
189
+ cGOptions: {
190
+ type: "button", // "button" || "checkbox"
191
+ options: [] // 按照label、value的键值对传入
192
+ }
193
+ },
194
+ // 多选框
195
+ {
196
+ field: "checkboxGroup",
197
+ type: "checkboxGroup",
198
+ label: "多选框",
199
+ labelWidth: "70px",
200
+ attrs: {
201
+ // 其他选项配置、参考Element的配置
202
+ },
203
+ cGOptions: {
204
+ type: "button", // "button" || "checkbox"
205
+ options: [] // 按照label、value的键值对传入
206
+ }
207
+ },
208
+ // 文本类型
209
+ {
210
+ field: "text",
211
+ type: "text",
212
+ label: "文本类型",
213
+ labelWidth: "70px",
214
+ defaultValue: "需要显示的文本"
215
+ },
216
+ // 数字范围输入框
217
+ {
218
+ field: "pairNumberInput",
219
+ type: "pairNumberInput",
220
+ label: "数字范围输入框",
221
+ labelWidth: "70px",
222
+ earliestPlaceholder: "前面输入框的Placeholder",
223
+ latestPlaceholder: "后面输入框的Placeholder"
224
+ },
225
+ {
226
+ field: "custom",
227
+ type: "custom",
228
+ label: "自定义",
229
+ labelWidth: "70px",
230
+ },
231
+ })
232
+ // 查询
233
+ const handleQueryClick = () => {}
234
+ </script>
24
235
 
25
- ```sh
26
- npm run dev
27
236
  ```
28
237
 
29
- ### Type-Check, Compile and Minify for Production
238
+ ### 表格 by-table
239
+
240
+ [vxe-table 文档](https://vxetable.cn/#/start/install)
30
241
 
31
- ```sh
32
- npm run build
242
+ ###### 通用配置
33
243
  ```
244
+ <template>
245
+ <by-table
246
+ ref="BTableRef"
247
+ :grid-options="gridOptions"
248
+ @checkbox-change="({records}) => handleCheckboxChange(records)"
249
+ @checkbox-all="({records}) => handleCheckboxChange(records)"
250
+ @page-change="handlePageChange"
251
+ @sort-change="handleSortChange"
252
+ >
253
+ <template #switch="{ row }">
254
+ <el-switch
255
+ v-if="row.id"
256
+ size="mini"
257
+ :value="row.opt_status==='ENABLE'"
258
+ />
259
+ </template>
260
+ <template #status_text="{ row }">
261
+ <span class="text_pointer_primary">{{ row.status_text }}</span>
262
+ </template>
263
+ <template #operate>
264
+ <el-button type="text">编辑</el-button>
265
+ <el-button style="color:red" type="text">删除</el-button>
266
+ </template>
267
+ </by-table>
268
+ </template>
269
+
270
+ <script setup>
271
+ import { ref } from "vue"
272
+ /**
273
+ * @see https://vxetable.cn/v4/#/grid/api
274
+ * @description 其他配置想看vxe-table文档(除 pagerConfig 和 copyFields 外)
275
+ * @param { false | Object } pagerConfig 分页配置、如果不想设置分页的话则设置false值即可、如果为对象的话则只接受pageSize、currentPage、total字段
276
+ * @param { Array } copyFields 需要用户点击单元格复制的字段标识数组集合
277
+ */
278
+ const gridOptions = ref({
279
+ height: 700,
280
+ pagerConfig: {
281
+ // 默认每页大小
282
+ pageSize: 15,
283
+ // 当前页码
284
+ currentPage: 1,
285
+ // 总条数
286
+ total: 25
287
+ },
288
+ checkboxConfig: {
289
+ checkMethod: ({ row }) => {
290
+ return !!row.id
291
+ },
292
+ visibleMethod: ({ row }) => {
293
+ return !!row.id
294
+ }
295
+ },
296
+ seqConfig: {
297
+ seqMethod: ({ row, rowIndex }) => {
298
+ return row.id ? rowIndex : "汇总"
299
+ }
300
+ },
301
+ copyFields: ["status_text"],
302
+ // 默认显示的排序
303
+ sortConfig: {
304
+ defaultSort: {
305
+ // 默认消耗倒序
306
+ field: "cost", order: "desc"
307
+ }
308
+ },
34
309
 
35
- ### Lint with [ESLint](https://eslint.org/)
310
+ customColumnConfig: { // 自定义列
311
+ showCustomColumn: true, // 是否显示自定义列
312
+ infoMethod: getCustomTableList, // 回显用的接口
313
+ infoMethodParams: {}, // 回显用的接口参数
314
+ submitMethod: setCustomTableList, // 保存用的接口
315
+ submitMethodParams: {}, // 保存用的接口参数
316
+ slots: ["source_material_count"] // 需要使用插槽的字段集合
317
+ },
318
+ columns: [
319
+ { type: "checkbox", width: 50, fixed: "left" },
320
+ { type: "seq", width: 50, fixed: "left", title: "序号" },
321
+ { field: "switch", title: "开关", width: 70, fixed: "left", slots: { default: "switch" }},
322
+ { field: "status_text", title: "状态", width: 70, fixed: "left", slots: { default: "status_text" }},
323
+ { field: "cost", title: "消耗", width: 70 },
324
+ { field: "operate", title: "操作", width: 70, fixed: "left", slots: { default: "operate" }}
325
+ ],
326
+ data: []
327
+ })
36
328
 
37
- ```sh
38
- npm run lint
329
+ // 多选回调
330
+ const handleCheckboxChange = (records) => {
331
+ console.log(records, "records")
332
+ },
333
+ // 排序回调
334
+ const handleSortChange = (context) => {
335
+ this.searchQuery.order = `${context.field} ${context.order}`
336
+ // 以下执行列表接口.....
337
+ },
338
+ // 分页回调
339
+ const handlePageChange = ({ page, limit }) => {
340
+ this.gridOptions.pagerConfig.currentPage = page
341
+ this.gridOptions.pagerConfig.pageSize = limit
342
+ // 以下执行列表接口.....
343
+ }
344
+ </script>
345
+
346
+ ```
347
+ ###### 自定义列支持多级表头
39
348
  ```
349
+ <template>
350
+ <by-table
351
+ :grid-options="gridOptions"
352
+ @setColumn="handleSetColumn"
353
+ @setGroupColumn="handleSetColumn"
354
+ >
355
+ </by-table>
356
+ </template>
357
+
358
+ <script setup>
359
+ import { ref } from "vue"
360
+ const gridOptions = ref({
361
+ border: true,
362
+ stripe: true,
363
+ resizable: true,
364
+ height: 500,
365
+ // 非自定义列的情况下的多级表头配置方式
366
+ columns: [
367
+ { type: 'seq', width: 50 },
368
+ {
369
+ title: '基本信息',
370
+ children: [
371
+ { field: 'name', title: 'Name' },
372
+ {
373
+ title: '其他信息',
374
+ children: [
375
+ { field: 'nickname', title: 'Nickname' },
376
+ { field: 'age', title: 'Age', sortable: true }
377
+ ]
378
+ },
379
+ { field: 'sex', title: 'Sex' }
380
+ ]
381
+ },
382
+ { field: 'address', title: 'Address', sortable: true, showOverflow: true }
383
+ ],
384
+ })
385
+ // setColumn 返回只有一级的表头
386
+ // setGroupColumn 返回多级表头数据
387
+ const handleSetColumn = (columns) => {
388
+ this.gridOptions.columns = [
389
+ { type: "checkbox", width: 50, fixed: "left" },
390
+ { type: "seq", width: 50, fixed: "left", title: "序号" },
391
+ ...columns,
392
+ { title: "操作", width: 80, fixed: "right", slots: { default: "operate" }}
393
+ ]
394
+ },
395
+ </script>
396
+ ```