lxui-uni 0.1.1 → 0.1.2
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/.env +1 -0
- package/README.md +3 -0
- package/components/lx-list/lx-list.vue +8 -14
- package/components/lx-operate-bottom/lx-operate-bottom.vue +1 -0
- package/components/lx-submit-btn/lx-submit-btn.vue +5 -1
- package/libs/hooks/useListLoadClass/index.ts +132 -117
- package/package.json +1 -1
- package/theme.scss +0 -2
package/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NPM_TOKEN=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
|
package/README.md
CHANGED
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
* @version: V1.0.1
|
|
14
14
|
*/
|
|
15
15
|
import { LoadData } from '../../libs/hooks/useListLoadClass'
|
|
16
|
-
import { debounce } from '../../libs/util'
|
|
17
16
|
import { toRefs, ref } from 'vue';
|
|
18
17
|
import lxListState from '../lx-list-state/lx-list-state.vue'
|
|
19
18
|
interface listPropsInt {
|
|
20
19
|
api: Function
|
|
21
20
|
afterLoadData?: Function
|
|
22
21
|
options?: any
|
|
23
|
-
listType?: 'default' | 'scrollView'
|
|
22
|
+
listType?: 'default' | 'scrollView',
|
|
23
|
+
// 列表数据字段
|
|
24
|
+
listDataField?: string
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// 接收传值
|
|
@@ -29,23 +30,18 @@ const props = withDefaults(defineProps<listPropsInt>(), {
|
|
|
29
30
|
api: () => ({}),
|
|
30
31
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
31
32
|
options: {},
|
|
32
|
-
listType: 'default'
|
|
33
|
+
listType: 'default',
|
|
34
|
+
listDataField: 'items'
|
|
33
35
|
})
|
|
34
36
|
let { options, api, afterLoadData } = toRefs(props)
|
|
35
|
-
// console.log('props', props.options, options.value)
|
|
36
37
|
|
|
37
38
|
// 分页相关
|
|
38
39
|
let { list, isLoading, isEmpty, isNoData, setParams, LoadMore } = LoadData({
|
|
39
40
|
api: api.value,
|
|
40
41
|
afterLoadData: afterLoadData?.value,
|
|
41
|
-
options: options.value
|
|
42
|
+
options: options.value,
|
|
43
|
+
listDataField: props.listDataField
|
|
42
44
|
})
|
|
43
|
-
// 搜索相关
|
|
44
|
-
// const inputTxt = ref('')
|
|
45
|
-
// const inputChange = debounce(() => {
|
|
46
|
-
// console.log('input change')
|
|
47
|
-
// setParams({ search: inputTxt.value })
|
|
48
|
-
// })
|
|
49
45
|
|
|
50
46
|
// 用于父组件设置额外的参数(选项卡切换的时候使用)--> isClear true 清空列表需测试
|
|
51
47
|
const setListParams = (obj: any, isClear = true) => {
|
|
@@ -53,9 +49,7 @@ const setListParams = (obj: any, isClear = true) => {
|
|
|
53
49
|
search?: string
|
|
54
50
|
[key: string]: any
|
|
55
51
|
}>({})
|
|
56
|
-
|
|
57
|
-
// param.value.search = inputTxt.value
|
|
58
|
-
// }
|
|
52
|
+
|
|
59
53
|
param.value = { ...obj }
|
|
60
54
|
setParams({ ...param.value }, isClear)
|
|
61
55
|
}
|
|
@@ -35,14 +35,18 @@ const emit = defineEmits(['submit'])
|
|
|
35
35
|
padding: 0 28rpx;
|
|
36
36
|
/* 兼容 iOS < 11.2 */
|
|
37
37
|
padding-bottom: constant(safe-area-inset-bottom);
|
|
38
|
+
padding-bottom: max(constant(safe-area-inset-bottom, 10rpx), 10rpx);
|
|
38
39
|
/* 兼容 iOS >= 11.2 */
|
|
39
40
|
padding-bottom: env(safe-area-inset-bottom);
|
|
41
|
+
padding-bottom: max(env(safe-area-inset-bottom, 10rpx), 10rpx);
|
|
40
42
|
padding-top: 10rpx;
|
|
41
43
|
position: fixed;
|
|
42
|
-
bottom: 10rpx;
|
|
44
|
+
// bottom: 10rpx;
|
|
45
|
+
bottom: 0;
|
|
43
46
|
left: 50%;
|
|
44
47
|
transform: translateX(-50%);
|
|
45
48
|
width: 100%;
|
|
49
|
+
background-color: #fff;
|
|
46
50
|
|
|
47
51
|
.submit_btn {
|
|
48
52
|
margin: 0 auto;
|
|
@@ -5,108 +5,118 @@
|
|
|
5
5
|
* @date: 2023-07-08 08:55:52
|
|
6
6
|
* @version: V1.0.0
|
|
7
7
|
*/
|
|
8
|
-
import { reactive, ref, computed } from
|
|
9
|
-
import { onReachBottom } from
|
|
8
|
+
import { reactive, ref, computed } from 'vue'
|
|
9
|
+
import { onReachBottom } from '@dcloudio/uni-app'
|
|
10
10
|
|
|
11
11
|
class LoadDataClass {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
// 请求参数
|
|
13
|
+
static queryParams = reactive({
|
|
14
|
+
page: 1,
|
|
15
|
+
limit: 10
|
|
16
|
+
})
|
|
17
|
+
// 列表数据
|
|
18
|
+
list = ref<any[]>([])
|
|
19
|
+
total = ref(0)
|
|
20
|
+
// 列表返回字段
|
|
21
|
+
listDataField = ref<string>('items')
|
|
22
|
+
// 前置处理方法
|
|
23
|
+
afterLoadData: Function | undefined
|
|
24
|
+
// 请求方法
|
|
25
|
+
Query: Function
|
|
26
|
+
// 加载状态参数
|
|
27
|
+
isLoading = ref(false)
|
|
28
|
+
// 无更多数据了
|
|
29
|
+
isNoData = computed(() => {
|
|
30
|
+
if (LoadDataClass.queryParams.page * LoadDataClass.queryParams.limit >= this.total.value) {
|
|
31
|
+
return true
|
|
32
|
+
} else {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
// 显示暂无数据
|
|
37
|
+
isEmpty = computed(() => {
|
|
38
|
+
if (this.total.value === 0) {
|
|
39
|
+
return true
|
|
40
|
+
} else {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
apiFunctions: Function,
|
|
47
|
+
afterLoadData?: Function,
|
|
48
|
+
options: any = {},
|
|
49
|
+
listDataField: string = 'items'
|
|
50
|
+
) {
|
|
51
|
+
this.queryParamsReset()
|
|
52
|
+
this.Query = apiFunctions
|
|
53
|
+
this.afterLoadData = afterLoadData
|
|
54
|
+
this.listDataField.value = listDataField || 'items'
|
|
55
|
+
// console.log('options', options)
|
|
56
|
+
// 存在额外参数拼接
|
|
57
|
+
this.setParams(options)
|
|
58
|
+
}
|
|
59
|
+
// 加载数据
|
|
60
|
+
LoadData = async () => {
|
|
61
|
+
uni.showLoading({
|
|
62
|
+
title: '加载中...'
|
|
41
63
|
})
|
|
64
|
+
this.isLoading.value = true
|
|
65
|
+
const res = await this.Query(LoadDataClass.queryParams)
|
|
66
|
+
this.afterLoadData && this.afterLoadData(res)
|
|
67
|
+
this.total.value = res.data.total
|
|
68
|
+
this.list.value = this.list.value.concat(res.data[this.listDataField.value])
|
|
42
69
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
uni.hideLoading()
|
|
71
|
+
uni.stopPullDownRefresh()
|
|
72
|
+
this.isLoading.value = false
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 添加额外参数刷新
|
|
76
|
+
* @param options: 参数
|
|
77
|
+
* @param isClear: 是否清空数据 false
|
|
78
|
+
*/
|
|
79
|
+
setParams = (options: any, isClear: boolean = false) => {
|
|
80
|
+
if (isClear) {
|
|
81
|
+
this.queryParamsReset()
|
|
82
|
+
} else {
|
|
83
|
+
LoadDataClass.queryParams.page = 1
|
|
50
84
|
}
|
|
85
|
+
this.list.value = []
|
|
86
|
+
console.log('setParams', options);
|
|
87
|
+
|
|
88
|
+
LoadDataClass.queryParams = Object.assign(LoadDataClass.queryParams, options)
|
|
51
89
|
// 加载数据
|
|
52
|
-
LoadData
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
* 添加额外参数刷新
|
|
68
|
-
* @param options: 参数
|
|
69
|
-
* @param isClear: 是否清空数据 false
|
|
70
|
-
*/
|
|
71
|
-
setParams = (options: any, isClear: boolean = false) => {
|
|
72
|
-
if (isClear) {
|
|
73
|
-
this.queryParamsReset()
|
|
74
|
-
} else {
|
|
75
|
-
LoadDataClass.queryParams.page = 1
|
|
76
|
-
}
|
|
77
|
-
this.list.value = []
|
|
78
|
-
LoadDataClass.queryParams = Object.assign(LoadDataClass.queryParams, options)
|
|
79
|
-
// 加载数据
|
|
80
|
-
this.LoadData()
|
|
81
|
-
}
|
|
82
|
-
// 加载更多
|
|
83
|
-
LoadMore = () => {
|
|
84
|
-
if (this.isNoData.value || this.isLoading.value) return // 无数据或者加载中不进行加载
|
|
85
|
-
LoadDataClass.queryParams.page += 1
|
|
86
|
-
this.LoadData()
|
|
87
|
-
}
|
|
88
|
-
// 重置参数
|
|
89
|
-
queryParamsReset = () => {
|
|
90
|
-
LoadDataClass.queryParams = reactive({
|
|
91
|
-
page: 1,
|
|
92
|
-
limit: 10
|
|
93
|
-
})
|
|
94
|
-
}
|
|
90
|
+
this.LoadData()
|
|
91
|
+
}
|
|
92
|
+
// 加载更多
|
|
93
|
+
LoadMore = () => {
|
|
94
|
+
if (this.isNoData.value || this.isLoading.value) return // 无数据或者加载中不进行加载
|
|
95
|
+
LoadDataClass.queryParams.page += 1
|
|
96
|
+
this.LoadData()
|
|
97
|
+
}
|
|
98
|
+
// 重置参数
|
|
99
|
+
queryParamsReset = () => {
|
|
100
|
+
LoadDataClass.queryParams = reactive({
|
|
101
|
+
page: 1,
|
|
102
|
+
limit: 10
|
|
103
|
+
})
|
|
104
|
+
}
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
this.LoadData()
|
|
106
|
+
/**
|
|
107
|
+
* 刷新
|
|
108
|
+
* @param isClear: 是否清空数据
|
|
109
|
+
*/
|
|
110
|
+
ReLoad = (isClear: boolean = false) => {
|
|
111
|
+
this.isLoading.value = false
|
|
112
|
+
this.list.value = []
|
|
113
|
+
if (isClear) {
|
|
114
|
+
this.queryParamsReset()
|
|
115
|
+
} else {
|
|
116
|
+
LoadDataClass.queryParams.page = 1
|
|
109
117
|
}
|
|
118
|
+
this.LoadData()
|
|
119
|
+
}
|
|
110
120
|
}
|
|
111
121
|
/**
|
|
112
122
|
* 分页加载数据方法
|
|
@@ -115,31 +125,36 @@ class LoadDataClass {
|
|
|
115
125
|
* @returns
|
|
116
126
|
*/
|
|
117
127
|
interface LoadDataInt {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
128
|
+
api: Function
|
|
129
|
+
afterLoadData?: Function
|
|
130
|
+
options?: any
|
|
131
|
+
isNeedReachBottom?: boolean
|
|
132
|
+
listDataField?: string
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
export function LoadData({
|
|
125
|
-
|
|
135
|
+
export function LoadData({
|
|
136
|
+
api,
|
|
137
|
+
afterLoadData,
|
|
138
|
+
options,
|
|
139
|
+
isNeedReachBottom = true,
|
|
140
|
+
listDataField = 'items'
|
|
141
|
+
}: LoadDataInt) {
|
|
142
|
+
const data = new LoadDataClass(api, afterLoadData, options, listDataField)
|
|
126
143
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
144
|
+
// 下拉加载
|
|
145
|
+
if (isNeedReachBottom) {
|
|
146
|
+
onReachBottom(() => {
|
|
147
|
+
data.LoadMore()
|
|
148
|
+
})
|
|
149
|
+
}
|
|
134
150
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
return {
|
|
152
|
+
list: data.list,
|
|
153
|
+
isLoading: data.isLoading,
|
|
154
|
+
isNoData: data.isNoData,
|
|
155
|
+
isEmpty: data.isEmpty,
|
|
156
|
+
ReLoad: data.ReLoad,
|
|
157
|
+
setParams: data.setParams,
|
|
158
|
+
LoadMore: data.LoadMore
|
|
159
|
+
}
|
|
144
160
|
}
|
|
145
|
-
|
package/package.json
CHANGED