@weitutech/by-components 1.0.27

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.
@@ -0,0 +1,3 @@
1
+ > 1%
2
+ last 2 versions
3
+ not dead
package/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # 1.0.27 (2024-12-04)
2
+
3
+ ### 🍏 Perf
4
+
5
+ - 多级表头分组之间增加间隔
6
+
7
+ # 1.0.26 (2024-12-04)
8
+
9
+ ### 🐞 Bug fixes
10
+
11
+ - 修复自定义列中,没有列设置 fixed 时的报错
12
+
13
+ # 1.0.25 (2024-12-04)
14
+
15
+ ### 🍏 Perf
16
+
17
+ - 自定义列支持多级表头展示
18
+
19
+ # 1.0.24 (2024-11-30)
20
+
21
+ ### 🐞 Bug fixes
22
+
23
+ - 修复表单中通过插槽的组件数据被清空问题导致卡顿问题
24
+
25
+ ### 🍏 Perf
26
+
27
+ - 优化选择器组件移除 input 事件、防止选择器选择的时候执行两次
28
+
29
+ # 1.0.23 (2024-11-25)
30
+
31
+ ### 🐞 Bug fixes
32
+
33
+ - 修复日期选择器组件在 form 表格组件中使用时对多个不同的时间配置设置初始时间没有生效问题
34
+
35
+ ### 🍏 Perf
36
+
37
+ - 优化日期选择器手动设置自定义值的时候自动匹配高亮出现有的时间选项
38
+ - 优化表格组件中对最大宽度和最小宽度的设置
package/README.md ADDED
@@ -0,0 +1,470 @@
1
+ # @weitutech/by-components
2
+
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
+ 由于对 vxeTable 进行了再次处理,所以需要复制 plugin 文件夹到项目中
15
+ 并手动引入 vxeTable
16
+ plugin 目录可从组件库中复制到项目
17
+
18
+ ```
19
+ import '@/plugin/vxeTable.js';
20
+ import '@weitutech/by-components/lib/index.css'
21
+ import BYComponents from '@weitutech/by-components'
22
+ Vue.use(BYComponents)
23
+ ```
24
+
25
+ ### npm 发布
26
+
27
+ ```
28
+ 第一次发布
29
+ npm login
30
+
31
+ 发布时需要确保npm的源是官方 npm
32
+ npm config set registry https://registry.npmjs.org/
33
+
34
+
35
+ 出现功能修改后,需更新package的版本号
36
+ 清除缓存
37
+ npm cache clean --force
38
+ 发布
39
+ npm publish --access public
40
+ ```
41
+
42
+ ### 注意事项
43
+
44
+ 1. 组件开发中 css 样式单独放在 style 目录下, 整体打包成一个 css 样式引入
45
+ 2. 打包后会在 lib 目录下生成 js 和 css 文件
46
+ 3. 本地开发时可采用 npm link 方式关联依赖,package 入口配置为 src/index.js
47
+
48
+ ### npm link
49
+
50
+ ```
51
+ 组件库中运行 npm link
52
+ 项目中运行 npm link by-components
53
+ ```
54
+
55
+ ### 关于新组件开发
56
+
57
+ 1. 采用 by 为前缀命名方式
58
+ 2. 避免过度耦合,考虑不同项目的复用性,尽量避免组件内调取接口
59
+
60
+ ### 表单 by-page-search
61
+
62
+ ```
63
+ <template>
64
+ <by-page-search
65
+ ref="pageSearchRef"
66
+ v-model="searchQuery"
67
+ :search-form-config="formConfig"
68
+ @queryBtnClick="handleQueryClick"
69
+ @change="handleChangePageSearch"
70
+ >
71
+ <template #custom>
72
+ 我是外部自定义内容
73
+ </template>
74
+ </by-page-search>
75
+ </template>
76
+
77
+ <script>
78
+ export default {
79
+ data() {
80
+ return {
81
+ searchQuery: {
82
+ // 对应formConfig对象中formItems中的每个field
83
+ },
84
+ formConfig: {
85
+ labelWidth: "80px",
86
+ itemStyle: {
87
+ padding: "0px 0px"
88
+ },
89
+ // 需要折叠的字段、不分顺序、写在里面的字段都会被隐藏 --- 仅在isFlexible = true 才可用
90
+ flexible: {
91
+ // 这里模拟写一些
92
+ foldField: ["area_id", "department_id", "team_id", "user_id", "favourite_id", "category_id", "brand_id"]
93
+ },
94
+ // 是否开启折叠功能
95
+ isFlexible: true,
96
+ colLayout: {
97
+ xs: 24,
98
+ sm: 12,
99
+ md: 12,
100
+ lg: 6,
101
+ xl: 4
102
+ },
103
+ elSize: "mini",
104
+ // 对应表单单独的显隐权限 可设置isHidden来控制
105
+ formItems: [
106
+ // 输入框
107
+ {
108
+ id: 1, // 作为可选的唯一标识,如果field有重复可以设置id作为唯一标识
109
+ field: "input",
110
+ type: "input",
111
+ label: "输入框",
112
+ placeholder: "请输入",
113
+ labelWidth: "70px",
114
+ isHidden: false, // 是否隐藏 false || true
115
+ otherOptions: {
116
+ // 其他选项配置、参考Element的输入框配置
117
+ }
118
+ },
119
+ // 密码输入框
120
+ {
121
+ field: "password",
122
+ type: "password",
123
+ label: "密码输入框",
124
+ placeholder: "请输入密码",
125
+ labelWidth: "70px",
126
+ otherOptions: {
127
+ // 其他选项配置、参考Element的输入框配置
128
+ }
129
+ },
130
+ // 选择器
131
+ {
132
+ field: "select",
133
+ type: "select",
134
+ label: "选择器",
135
+ placeholder: "请选择",
136
+ labelWidth: "100px",
137
+ mode: "", // 可选 "group" || false 默认 不传不用配置 group为分组模式
138
+ options: [
139
+ // 必须按照label、value的键值对传入
140
+ { label: "全选", value: undefined },
141
+ { label: "选项一", value: "one" },
142
+ { label: "选项二", value: "two" }
143
+ ],
144
+ otherOptions: {
145
+ // 其他配置、参考Element的选择器配置
146
+ },
147
+ colLayout: {
148
+ xs: 24,
149
+ sm: 8,
150
+ md: 8,
151
+ lg: 4,
152
+ xl: 4
153
+ }
154
+ },
155
+ // 日期选择器
156
+ {
157
+ field: "datepicker",
158
+ type: "datepicker",
159
+ label: "日期选择器",
160
+ placeholder: "请选择日期",
161
+ labelWidth: "70px",
162
+ otherOptions: {
163
+ // 其他选项配置、参考Element的配置
164
+ }
165
+ },
166
+ // 级联
167
+ {
168
+ field: "cascader",
169
+ type: "cascader",
170
+ label: "级联",
171
+ placeholder: "请选择",
172
+ labelWidth: "70px",
173
+ options: [], // 于Element保持一致
174
+ otherOptions: {
175
+ // 其他选项配置、参考Element的配置
176
+ }
177
+ },
178
+ // 开关
179
+ {
180
+ field: "switch",
181
+ type: "switch",
182
+ label: "开关",
183
+ labelWidth: "70px",
184
+ otherOptions: {
185
+ // 其他选项配置、参考Element的配置
186
+ }
187
+ },
188
+ // 单选框
189
+ {
190
+ field: "radioGroup",
191
+ type: "radioGroup",
192
+ label: "单选框",
193
+ labelWidth: "70px",
194
+ otherOptions: {
195
+ // 其他选项配置、参考Element的配置
196
+ },
197
+ cGOptions: {
198
+ type: "button", // "button" || "checkbox"
199
+ options: [] // 按照label、value的键值对传入
200
+ }
201
+ },
202
+ // 多选框
203
+ {
204
+ field: "checkboxGroup",
205
+ type: "checkboxGroup",
206
+ label: "多选框",
207
+ labelWidth: "70px",
208
+ otherOptions: {
209
+ // 其他选项配置、参考Element的配置
210
+ },
211
+ cGOptions: {
212
+ type: "button", // "button" || "checkbox"
213
+ options: [] // 按照label、value的键值对传入
214
+ }
215
+ },
216
+ // 文本类型
217
+ {
218
+ field: "text",
219
+ type: "text",
220
+ label: "文本类型",
221
+ labelWidth: "70px",
222
+ defaultValue: "需要显示的文本"
223
+ },
224
+ // 数字范围输入框
225
+ {
226
+ field: "pairNumberInput",
227
+ type: "pairNumberInput",
228
+ label: "数字范围输入框",
229
+ labelWidth: "70px",
230
+ earliestPlaceholder: "前面输入框的Placeholder",
231
+ latestPlaceholder: "后面输入框的Placeholder"
232
+ },
233
+ {
234
+ field: "custom",
235
+ type: "custom",
236
+ label: "自定义",
237
+ labelWidth: "70px",
238
+ },
239
+ }
240
+ }
241
+ },
242
+ methods: {
243
+ // 查询
244
+ handleQueryClick() {},
245
+ /**
246
+ * @describe 表单回调、以下对推广人员四级和标签于推广账户组件交互是进行一些传参的改变、逻辑依据原老组件需要的参数进行复制处理
247
+ * @param { Object } value 为对象字段名和所赋予的值
248
+ */
249
+ handleChangePageSearch({ field, value }) {
250
+ if (["area_id", "department_id", "team_id", "user_id", "favourite_id"].includes(field)) {
251
+ if (field === "area_id") {
252
+ this.formConfig.formItems.forEach(item => {
253
+ if (item.field === "department_id" || item.field === "team_id" || item.field === "user_id") {
254
+ item.otherOptions.areaId = value
255
+ }
256
+ })
257
+ } else if (field === "department_id") {
258
+ this.formConfig.formItems.forEach(item => {
259
+ if (item.field === "team_id" || item.field === "user_id") {
260
+ item.otherOptions.departmentId = value
261
+ }
262
+ })
263
+ } else if (field === "team_id") {
264
+ this.formConfig.formItems.forEach(item => {
265
+ if (item.field === "user_id") {
266
+ item.otherOptions.teamId = value
267
+ }
268
+ })
269
+ } else if (field === "user_id") {
270
+ this.formConfig.formItems.forEach(item => {
271
+ if (item.field === "favourite_id" || item.field === "advertiser_id") {
272
+ item.otherOptions.userId = value
273
+ }
274
+ })
275
+ } else if (field === "favourite_id") {
276
+ if (value.length) {
277
+ this.formConfig.formItems.forEach(item => {
278
+ if (item.field === "advertiser_id") {
279
+ item.otherOptions.options.favouriteId = value
280
+ item.isHidden = false
281
+ }
282
+ })
283
+ } else {
284
+ this.formConfig.formItems.forEach(item => {
285
+ if (item.field === "advertiser_id") {
286
+ console.log(item, "item")
287
+ item.otherOptions.options.favouriteId = []
288
+ item.isHidden = true
289
+ }
290
+ })
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ }
297
+ </script>
298
+
299
+ ```
300
+
301
+ ### 表格 by-table
302
+
303
+ [vxe-table 文档](https://vxetable.cn/v3.8/#/table/start/install)
304
+
305
+ ###### 通用配置
306
+ ```
307
+ <template>
308
+ <by-table
309
+ ref="BTableRef"
310
+ :grid-options="gridOptions"
311
+ @checkbox-change="({records}) => handleCheckboxChange(records)"
312
+ @checkbox-all="({records}) => handleCheckboxChange(records)"
313
+ @page-change="handlePageChange"
314
+ @sort-change="handleSortChange"
315
+ >
316
+ <template #switch="{ row }">
317
+ <el-switch
318
+ v-if="row.id"
319
+ size="mini"
320
+ :value="row.opt_status==='ENABLE'"
321
+ />
322
+ </template>
323
+ <template #status_text="{ row }">
324
+ <span class="text_pointer_primary">{{ row.status_text }}</span>
325
+ </template>
326
+ <template #operate>
327
+ <el-button type="text">编辑</el-button>
328
+ <el-button style="color:red" type="text">删除</el-button>
329
+ </template>
330
+ </by-table>
331
+ </template>
332
+
333
+ <script>
334
+ export default {
335
+ data() {
336
+ return {
337
+ /**
338
+ * @see https://vxetable.cn/v3.8/#/grid/api
339
+ * @description 其他配置想看vxe-table文档(除 pagerConfig 和 copyFields 外)
340
+ * @param { false | Object } pagerConfig 分页配置、如果不想设置分页的话则设置false值即可、如果为对象的话则只接受pageSize、currentPage、total字段
341
+ * @param { Array } copyFields 需要用户点击单元格复制的字段标识数组集合
342
+ */
343
+ gridOptions: {
344
+ height: 700,
345
+ pagerConfig: {
346
+ // 默认每页大小
347
+ pageSize: 15,
348
+ // 当前页码
349
+ currentPage: 1,
350
+ // 总条数
351
+ total: 25
352
+ },
353
+ checkboxConfig: {
354
+ checkMethod: ({ row }) => {
355
+ return !!row.id
356
+ },
357
+ visibleMethod: ({ row }) => {
358
+ return !!row.id
359
+ }
360
+ },
361
+ seqConfig: {
362
+ seqMethod: ({ row, rowIndex }) => {
363
+ return row.id ? rowIndex : "汇总"
364
+ }
365
+ },
366
+ copyFields: ["status_text"],
367
+ // 默认显示的排序
368
+ sortConfig: {
369
+ defaultSort: {
370
+ // 默认消耗倒序
371
+ field: "cost", order: "desc"
372
+ }
373
+ },
374
+
375
+ customColumnConfig: { // 自定义列
376
+ showCustomColumn: true, // 是否显示自定义列
377
+ infoMethod: getCustomTableList, // 回显用的接口
378
+ submitMethod: setCustomTableList, // 保存用的接口
379
+ slots: ["source_material_count"] // 需要使用插槽的字段集合
380
+ },
381
+ columns: [
382
+ { type: "checkbox", width: 50, fixed: "left" },
383
+ { type: "seq", width: 50, fixed: "left", title: "序号" },
384
+ { field: "switch", title: "开关", width: 70, fixed: "left", slots: { default: "switch" }},
385
+ { field: "status_text", title: "状态", width: 70, fixed: "left", slots: { default: "status_text" }},
386
+ { field: "cost", title: "消耗", width: 70 },
387
+ { field: "operate", title: "操作", width: 70, fixed: "left", slots: { default: "operate" }}
388
+ ],
389
+ data: []
390
+ }
391
+ }
392
+ },
393
+ methods: {
394
+ // 多选回调
395
+ handleCheckboxChange(records) {
396
+ console.log(records, "records")
397
+ },
398
+ // 排序回调
399
+ handleSortChange(context) {
400
+ this.searchQuery.order = `${context.field} ${context.order}`
401
+ // 以下执行列表接口.....
402
+ },
403
+ // 分页回调
404
+ handlePageChange({ page, limit }) {
405
+ this.gridOptions.pagerConfig.currentPage = page
406
+ this.gridOptions.pagerConfig.pageSize = limit
407
+ // 以下执行列表接口.....
408
+ }
409
+ }
410
+ }
411
+ </script>
412
+
413
+ ```
414
+ ###### 自定义列支持多级表头
415
+ ```
416
+ <template>
417
+ <by-table
418
+ :grid-options="gridOptions"
419
+ @setColumn="handleSetColumn"
420
+ @setGroupColumn="handleSetColumn"
421
+ >
422
+ </by-table>
423
+ </template>
424
+
425
+ <script>
426
+ export default {
427
+ data() {
428
+ return {
429
+ gridOptions: {
430
+ border: true,
431
+ stripe: true,
432
+ resizable: true,
433
+ height: 500,
434
+ // 非自定义列的情况下的多级表头配置方式
435
+ columns: [
436
+ { type: 'seq', width: 50 },
437
+ {
438
+ title: '基本信息',
439
+ children: [
440
+ { field: 'name', title: 'Name' },
441
+ {
442
+ title: '其他信息',
443
+ children: [
444
+ { field: 'nickname', title: 'Nickname' },
445
+ { field: 'age', title: 'Age', sortable: true }
446
+ ]
447
+ },
448
+ { field: 'sex', title: 'Sex' }
449
+ ]
450
+ },
451
+ { field: 'address', title: 'Address', sortable: true, showOverflow: true }
452
+ ],
453
+ }
454
+ }
455
+ },
456
+ methods: {
457
+ // setColumn 返回只有一级的表头
458
+ // setGroupColumn 返回多级表头数据
459
+ handleSetColumn(columns) {
460
+ this.gridOptions.columns = [
461
+ { type: "checkbox", width: 50, fixed: "left" },
462
+ { type: "seq", width: 50, fixed: "left", title: "序号" },
463
+ ...columns,
464
+ { title: "操作", width: 80, fixed: "right", slots: { default: "operate" }}
465
+ ]
466
+ },
467
+ }
468
+ }
469
+ </script>
470
+ ```
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ presets: [
3
+ '@vue/cli-plugin-babel/preset'
4
+ ],
5
+ plugins: [
6
+ "@babel/plugin-proposal-optional-chaining",
7
+ "@babel/plugin-proposal-nullish-coalescing-operator"
8
+ ]
9
+ }
package/jsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "esnext",
5
+ "baseUrl": "./",
6
+ "moduleResolution": "node",
7
+ "paths": {
8
+ "@/*": [
9
+ "src/*"
10
+ ]
11
+ },
12
+ "lib": [
13
+ "esnext",
14
+ "dom",
15
+ "dom.iterable",
16
+ "scripthost"
17
+ ]
18
+ }
19
+ }