diff --git a/src/components/lx-header/lx-header.vue b/src/components/lx-header/lx-header.vue
index 9d5bcabf2b9d095cc04fa1285ac7f2a449f9fa50..8a035bdb35858efe1086f117d6cf185b9eb4e953 100644
--- a/src/components/lx-header/lx-header.vue
+++ b/src/components/lx-header/lx-header.vue
@@ -82,7 +82,7 @@ const style = computed(() => {
const goBack = () => {
if (getCurrentPages().length <= 1) {
goToPage({
- url: '/pages/index/index',
+ url: 'pages/index/index',
mode: 'redirectTo'
})
} else {
diff --git a/src/components/lx-list-scroll/lx-list-scroll.vue b/src/components/lx-list-scroll/lx-list-scroll.vue
new file mode 100644
index 0000000000000000000000000000000000000000..260fc858884ef9edaca706b941bbd61d99ea9ba8
--- /dev/null
+++ b/src/components/lx-list-scroll/lx-list-scroll.vue
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/lx-list/lx-list.vue b/src/components/lx-list/lx-list.vue
index ca6c438df9b576a8a5995dcd0cc65ecaf451fe1a..9475baf417afd397bb860544b611113ca1ee1b76 100644
--- a/src/components/lx-list/lx-list.vue
+++ b/src/components/lx-list/lx-list.vue
@@ -2,59 +2,151 @@
/*
* @description: 分页组件
* @fileName: List.vue
- * @params api : 数据请求的apiFunction
+ * @params {Function} api : 数据请求的接口API
+ * @params {Function} afterLoadData : 数据请求完毕前置处理方法
+ * @params {Boolean} isNeedSearch : 是否需要搜索
+ * @params {Boolean} isFixedSearch : 是否需要固定定位搜索框(仅listType:'default'有效)
+ * @params {object: any} options : 数据请求的额外参数
+ * @params {'default' | 'scrollView'} listType : scrollView为scroll-view包裹的分页
+ * @params {number} scrollTopThreshold : 用于指定滚动条距离顶部的阈值->触发输入框固定 (仅listType:'scrollView'有效)
+ * @ref setListParams {Function} : 使用==>ref.value.setListParams(obj, isClear) obj:请求额外的参数 isClear是否清空请求参数
* @author: lxx
* @date: 2023-07-28 11:36:23
- * @version: V1.0.0
+ * @update: 2023-10-13 10:34:03
+ * @version: V1.0.1
*/
import { LoadData } from '@/hooks/useListLoadClass'
-import { ref } from 'vue'
import { debounce } from '@/utils/util'
-import { toRefs } from 'vue'
-
-type listPropsInt = {
+interface listPropsInt {
api: Function
afterLoadData?: Function
isNeedSearch?: boolean
+ isFixedSearch?: boolean
options?: any
+ scrollTopThreshold?: number
+ listType?: 'default' | 'scrollView'
}
+// 接收传值
+// 3.2.x defineProps泛型类型参数仅限于类型文字或对本地接口的引用
const props = withDefaults(defineProps(), {
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- api: () => {},
+ api: () => ({}),
isNeedSearch: true,
+ isFixedSearch: true,
// eslint-disable-next-line @typescript-eslint/no-empty-function
- options: {}
+ options: {},
+ scrollTopThreshold: 50,
+ listType: 'default'
})
-
-const inputTxt = ref('')
let { options, api, afterLoadData } = toRefs(props)
-if (props.isNeedSearch) {
- let obj = { type: 2 }
- options.value = Object.assign(options.value, obj)
-}
-let { list, isLoading, isEmpty, isNoData, setParams } = LoadData({
+
+// 分页相关
+let { list, isLoading, isEmpty, isNoData, setParams, LoadMore } = LoadData({
api: api.value,
afterLoadData: afterLoadData?.value,
options: options.value
})
+// 搜索相关
+const inputTxt = ref('')
const inputChange = debounce(() => {
console.log('input change')
setParams({ search: inputTxt.value })
})
+
+// 用于父组件设置额外的参数(选项卡切换的时候使用)
+const setListParams = (obj: any, isClear = false) => {
+ const param = ref<{
+ search?: string
+ [key: string]: any
+ }>({})
+ if (props.isNeedSearch) {
+ param.value.search = inputTxt.value
+ }
+ param.value = { ...obj }
+ setParams({ ...param.value }, isClear)
+}
+defineExpose({
+ setListParams
+})
+// 页面滚动相关
+const scrollTop = ref(0)
+const scroll = (e: any) => {
+ scrollTop.value = e.detail.scrollTop
+}
+
+const emit = defineEmits(['scrollTolower'])
+const scrolltolower = () => {
+ console.log('触底啦!')
+ LoadMore()
+ emit('scrollTolower')
+}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/hooks/useListLoadClass.ts b/src/hooks/useListLoadClass.ts
index a9843c9c94820f88a8133412557bdf03b85f92f9..e9755c29b4e30cd77aaa2f03b75bb20f89a8b9f2 100644
--- a/src/hooks/useListLoadClass.ts
+++ b/src/hooks/useListLoadClass.ts
@@ -5,9 +5,6 @@
* @date: 2023-07-08 08:55:52
* @version: V1.0.0
*/
-import { ref, computed } from 'vue'
-import { onReachBottom } from '@dcloudio/uni-app'
-
class LoadDataClass {
// 请求参数
static queryParams = {
@@ -43,6 +40,7 @@ class LoadDataClass {
constructor(apiFunctions: Function, afterLoadData?: Function, options: any = {}) {
this.Query = apiFunctions
this.afterLoadData = afterLoadData
+ // console.log('options', options)
// 存在额外参数拼接
this.setParams(options)
}
@@ -116,22 +114,27 @@ interface LoadDataInt {
api: Function
afterLoadData?: Function
options?: any
+ isNeedReachBottom?: boolean
}
-export function LoadData({ api, afterLoadData, options }: LoadDataInt) {
+export function LoadData({ api, afterLoadData, options, isNeedReachBottom = true }: LoadDataInt) {
const data = new LoadDataClass(api, afterLoadData, options)
// 下拉加载
- onReachBottom(() => {
- console.log('onReachBottom')
- data.LoadMore()
- })
+ if (isNeedReachBottom) {
+ onReachBottom(() => {
+ console.log('onReachBottom')
+ data.LoadMore()
+ })
+ }
+
return {
list: data.list,
isLoading: data.isLoading,
isNoData: data.isNoData,
isEmpty: data.isEmpty,
ReLoad: data.ReLoad,
- setParams: data.setParams
+ setParams: data.setParams,
+ LoadMore: data.LoadMore
}
}
diff --git a/src/pages.json b/src/pages.json
index 7f897023d27833e48090066ea02ecb6765d783d6..2669e637630cfa80fa8b364f89ed9ff021d2fa5b 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -33,6 +33,15 @@
"enablePullDownRefresh": false,
"navigationStyle": "custom"
}
+ },
+ {
+ "name": "listDemo",
+ "path": "pages/listDemo/listDemoScroll",
+ "style": {
+ "navigationBarTitleText": "列表页-scrollview版",
+ "enablePullDownRefresh": false,
+ "navigationStyle": "custom"
+ }
}
],
"subPackages": [
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 02925b4e22cdd66f66e911a58d2e7ed227b981da..76a16a0115821d9d78b84bdc1c241216ff91d593 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -31,7 +31,7 @@ console.log('xxx', formatTime(Date.now(), 'yyyy-MM-dd'))
-
+
模态框,常用于消息提示、消息确认、在当前页面内完成特定的交互操作
diff --git a/src/pages/listDemo/listDemo.vue b/src/pages/listDemo/listDemo.vue
index 3d36fcd464117efb55f6c516c74e02dd05c560be..30bec5b62cb6e5d8dd19e6a59aea203ad30194bc 100644
--- a/src/pages/listDemo/listDemo.vue
+++ b/src/pages/listDemo/listDemo.vue
@@ -1,21 +1,25 @@
-
-
-
- {{ index }} ---- {{ item }}
-
-
+
+
+
+ {{ index }} ---- {{ item }}
+
+
diff --git a/src/pages/listDemo/listDemoScroll.vue b/src/pages/listDemo/listDemoScroll.vue
new file mode 100644
index 0000000000000000000000000000000000000000..e8e68b55718be919fed313fdda01884b47c30aff
--- /dev/null
+++ b/src/pages/listDemo/listDemoScroll.vue
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ {{ index }} ---- {{ item }}
+
+
+
+
+
+