lxui-uni 0.0.8 → 0.0.9

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.
@@ -1,22 +1,22 @@
1
- const version = '3'
2
-
3
- // 开发环境才提示,生产环境不会提示
4
- if (process.env.NODE_ENV === 'development') {
5
- console.log(`\n %c lxui-uni V${version} %c https://blog.csdn.net/qq_51091386/article/details/138125947 \n\n`, 'color: #ffffff; background: #3c9cff; padding:5px 0;', 'color: #3c9cff;background: #ffffff; padding:5px 0;');
6
- }
7
-
8
- export let uploadUrl = '/api/v1.Resources/upload'
9
- export let uploadBaseUrl = ''
10
- const setConfig = (config: any) => {
11
- console.log(config)
12
- if (config?.uploadUrl) {
13
- uploadUrl = config.uploadUrl
14
- }
15
- if (config?.uploadBaseUrl) {
16
- uploadBaseUrl = config.uploadBaseUrl
17
- }
18
- }
19
- export default {
20
- version,
21
- setConfig
1
+ const version = '3'
2
+
3
+ // 开发环境才提示,生产环境不会提示
4
+ if (process.env.NODE_ENV === 'development') {
5
+ console.log(`\n %c lxui-uni V${version} %c https://blog.csdn.net/qq_51091386/article/details/138125947 \n\n`, 'color: #ffffff; background: #3c9cff; padding:5px 0;', 'color: #3c9cff;background: #ffffff; padding:5px 0;');
6
+ }
7
+
8
+ export let uploadUrl = '/api/v1.Resources/upload'
9
+ export let uploadBaseUrl = ''
10
+ const setConfig = (config: any) => {
11
+ console.log(config)
12
+ if (config?.uploadUrl) {
13
+ uploadUrl = config.uploadUrl
14
+ }
15
+ if (config?.uploadBaseUrl) {
16
+ uploadBaseUrl = config.uploadBaseUrl
17
+ }
18
+ }
19
+ export default {
20
+ version,
21
+ setConfig
22
22
  }
@@ -1,143 +1,145 @@
1
- /*
2
- * @description: 分页请求
3
- * @fileName: useListLoadClass.ts
4
- * @author: lxx
5
- * @date: 2023-07-08 08:55:52
6
- * @version: V1.0.0
7
- */
8
- import { reactive, ref, computed } from "vue"
9
- class LoadDataClass {
10
- // 请求参数
11
- static queryParams = reactive({
12
- page: 1,
13
- limit: 10
14
- })
15
- // 列表数据
16
- list = ref<any[]>([])
17
- total = ref(0)
18
- // 前置处理方法
19
- afterLoadData: Function | undefined
20
- // 请求方法
21
- Query: Function
22
- // 加载状态参数
23
- isLoading = ref(false)
24
- // 无更多数据了
25
- isNoData = computed(() => {
26
- if (LoadDataClass.queryParams.page * LoadDataClass.queryParams.limit >= this.total.value) {
27
- return true
28
- } else {
29
- return false
30
- }
31
- })
32
- // 显示暂无数据
33
- isEmpty = computed(() => {
34
- if (this.total.value === 0) {
35
- return true
36
- } else {
37
- return false
38
- }
39
- })
40
-
41
- constructor(apiFunctions: Function, afterLoadData?: Function, options: any = {}) {
42
- this.queryParamsReset()
43
- this.Query = apiFunctions
44
- this.afterLoadData = afterLoadData
45
- // console.log('options', options)
46
- // 存在额外参数拼接
47
- this.setParams(options)
48
- }
49
- // 加载数据
50
- LoadData = async () => {
51
- uni.showLoading({
52
- title: '加载中...'
53
- })
54
- this.isLoading.value = true
55
- const res = await this.Query(LoadDataClass.queryParams)
56
- this.afterLoadData && this.afterLoadData(res)
57
- this.total.value = res.data.total
58
- this.list.value = this.list.value.concat(res.data.items)
59
-
60
- uni.hideLoading()
61
- uni.stopPullDownRefresh()
62
- this.isLoading.value = false
63
- }
64
- /**
65
- * 添加额外参数刷新
66
- * @param options: 参数
67
- * @param isClear: 是否清空数据 false
68
- */
69
- setParams = (options: any, isClear: boolean = false) => {
70
- if (isClear) {
71
- this.queryParamsReset()
72
- } else {
73
- LoadDataClass.queryParams.page = 1
74
- }
75
- this.list.value = []
76
- LoadDataClass.queryParams = Object.assign(LoadDataClass.queryParams, options)
77
- // 加载数据
78
- this.LoadData()
79
- }
80
- // 加载更多
81
- LoadMore = () => {
82
- if (this.isNoData.value || this.isLoading.value) return // 无数据或者加载中不进行加载
83
- LoadDataClass.queryParams.page += 1
84
- this.LoadData()
85
- }
86
- // 重置参数
87
- queryParamsReset = () => {
88
- LoadDataClass.queryParams = reactive({
89
- page: 1,
90
- limit: 10
91
- })
92
- }
93
-
94
- /**
95
- * 刷新
96
- * @param isClear: 是否清空数据
97
- */
98
- ReLoad = (isClear: boolean = false) => {
99
- this.isLoading.value = false
100
- this.list.value = []
101
- if (isClear) {
102
- this.queryParamsReset()
103
- } else {
104
- LoadDataClass.queryParams.page = 1
105
- }
106
- this.LoadData()
107
- }
108
- }
109
- /**
110
- * 分页加载数据方法
111
- * @param api: ListAPI 方法
112
- * @param afterLoadData: res数据前置处理方法
113
- * @returns
114
- */
115
- interface LoadDataInt {
116
- api: Function
117
- afterLoadData?: Function
118
- options?: any
119
- isNeedReachBottom?: boolean
120
- }
121
-
122
- export function LoadData({ api, afterLoadData, options, isNeedReachBottom = true }: LoadDataInt) {
123
- const data = new LoadDataClass(api, afterLoadData, options)
124
-
125
- // 下拉加载---暂时注释通过ref直接调用 >待优化
126
- // if (isNeedReachBottom) {
127
- // onReachBottom(() => {
128
- // console.log('onReachBottom')
129
- // data.LoadMore()
130
- // })
131
- // }
132
-
133
- return {
134
- list: data.list,
135
- isLoading: data.isLoading,
136
- isNoData: data.isNoData,
137
- isEmpty: data.isEmpty,
138
- ReLoad: data.ReLoad,
139
- setParams: data.setParams,
140
- LoadMore: data.LoadMore
141
- }
142
- }
143
-
1
+ /*
2
+ * @description: 分页请求
3
+ * @fileName: useListLoadClass.ts
4
+ * @author: lxx
5
+ * @date: 2023-07-08 08:55:52
6
+ * @version: V1.0.0
7
+ */
8
+ import { reactive, ref, computed } from "vue"
9
+ import { onReachBottom } from "@dcloudio/uni-app"
10
+
11
+ class LoadDataClass {
12
+ // 请求参数
13
+ static queryParams = reactive({
14
+ page: 1,
15
+ limit: 10
16
+ })
17
+ // 列表数据
18
+ list = ref<any[]>([])
19
+ total = ref(0)
20
+ // 前置处理方法
21
+ afterLoadData: Function | undefined
22
+ // 请求方法
23
+ Query: Function
24
+ // 加载状态参数
25
+ isLoading = ref(false)
26
+ // 无更多数据了
27
+ isNoData = computed(() => {
28
+ if (LoadDataClass.queryParams.page * LoadDataClass.queryParams.limit >= this.total.value) {
29
+ return true
30
+ } else {
31
+ return false
32
+ }
33
+ })
34
+ // 显示暂无数据
35
+ isEmpty = computed(() => {
36
+ if (this.total.value === 0) {
37
+ return true
38
+ } else {
39
+ return false
40
+ }
41
+ })
42
+
43
+ constructor(apiFunctions: Function, afterLoadData?: Function, options: any = {}) {
44
+ this.queryParamsReset()
45
+ this.Query = apiFunctions
46
+ this.afterLoadData = afterLoadData
47
+ // console.log('options', options)
48
+ // 存在额外参数拼接
49
+ this.setParams(options)
50
+ }
51
+ // 加载数据
52
+ LoadData = async () => {
53
+ uni.showLoading({
54
+ title: '加载中...'
55
+ })
56
+ this.isLoading.value = true
57
+ const res = await this.Query(LoadDataClass.queryParams)
58
+ this.afterLoadData && this.afterLoadData(res)
59
+ this.total.value = res.data.total
60
+ this.list.value = this.list.value.concat(res.data.items)
61
+
62
+ uni.hideLoading()
63
+ uni.stopPullDownRefresh()
64
+ this.isLoading.value = false
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
+ }
95
+
96
+ /**
97
+ * 刷新
98
+ * @param isClear: 是否清空数据
99
+ */
100
+ ReLoad = (isClear: boolean = false) => {
101
+ this.isLoading.value = false
102
+ this.list.value = []
103
+ if (isClear) {
104
+ this.queryParamsReset()
105
+ } else {
106
+ LoadDataClass.queryParams.page = 1
107
+ }
108
+ this.LoadData()
109
+ }
110
+ }
111
+ /**
112
+ * 分页加载数据方法
113
+ * @param api: ListAPI 方法
114
+ * @param afterLoadData: res数据前置处理方法
115
+ * @returns
116
+ */
117
+ interface LoadDataInt {
118
+ api: Function
119
+ afterLoadData?: Function
120
+ options?: any
121
+ isNeedReachBottom?: boolean
122
+ }
123
+
124
+ export function LoadData({ api, afterLoadData, options, isNeedReachBottom = true }: LoadDataInt) {
125
+ const data = new LoadDataClass(api, afterLoadData, options)
126
+
127
+ // 下拉加载
128
+ if (isNeedReachBottom) {
129
+ onReachBottom(() => {
130
+ console.log('onReachBottom')
131
+ data.LoadMore()
132
+ })
133
+ }
134
+
135
+ return {
136
+ list: data.list,
137
+ isLoading: data.isLoading,
138
+ isNoData: data.isNoData,
139
+ isEmpty: data.isEmpty,
140
+ ReLoad: data.ReLoad,
141
+ setParams: data.setParams,
142
+ LoadMore: data.LoadMore
143
+ }
144
+ }
145
+