test 列表刷新
This commit is contained in:
@@ -262,6 +262,12 @@
|
|||||||
"navigationBarTitleText": "ListView 列表视图"
|
"navigationBarTitleText": "ListView 列表视图"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "data/list-view-refresh",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "ListViewRefresh 列表刷新"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "data/waterfall",
|
"path": "data/waterfall",
|
||||||
"style": {
|
"style": {
|
||||||
|
|||||||
29
pages/demo/components/goods-item.uvue
Normal file
29
pages/demo/components/goods-item.uvue
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<template>
|
||||||
|
<view class="w-full p-3 bg-white rounded-xl mb-3 dark:bg-surface-800">
|
||||||
|
<cl-image :src="item.image" mode="widthFix" width="100%" height="250rpx"></cl-image>
|
||||||
|
<cl-text :pt="{ className: 'mt-2' }">{{ item.title }}</cl-text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, type PropType } from "vue";
|
||||||
|
import { useParent } from "@/cool";
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: "goods-item"
|
||||||
|
});
|
||||||
|
|
||||||
|
type GoodsItem = {
|
||||||
|
id: number;
|
||||||
|
likeCount: number;
|
||||||
|
title: string;
|
||||||
|
image: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
item: {
|
||||||
|
type: Object as PropType<GoodsItem>,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
77
pages/demo/data/list-view-refresh.uvue
Normal file
77
pages/demo/data/list-view-refresh.uvue
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<template>
|
||||||
|
<cl-page>
|
||||||
|
<view class="p-3">
|
||||||
|
<cl-list-view :data="data" :virtual="false">
|
||||||
|
<template #item="{ value }">
|
||||||
|
<goods-item :item="value"></goods-item>
|
||||||
|
</template>
|
||||||
|
</cl-list-view>
|
||||||
|
</view>
|
||||||
|
</cl-page>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { useListView } from "@/uni_modules/cool-ui";
|
||||||
|
import { ref } from "vue";
|
||||||
|
import { random } from "@/cool";
|
||||||
|
import GoodsItem from "../components/goods-item.uvue";
|
||||||
|
|
||||||
|
let id = 0;
|
||||||
|
|
||||||
|
const data = useListView([
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "春日樱花盛开时节,粉色花瓣如诗如画般飘洒",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/1.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "夕阳西下的海滩边,金色阳光温柔地洒在波光粼粼的海面上,构成令人心旷神怡的日落美景",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/2.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "寒冬腊月时分,洁白雪花纷纷扬扬地覆盖着整个世界,感受冬日的宁静与美好",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/3.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "都市夜景霓虹闪烁,五彩斑斓光芒照亮城市营造梦幻般景象",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/5.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "云雾缭绕的山间风光如诗如画让人心旷神怡,微风轻抚树梢带来阵阵清香,鸟儿在林间自由歌唱",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/6.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "古老建筑与现代摩天大楼交相辉映,传统与现代完美融合创造独特城市景观",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/7.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "广袤田野绿意盎然风光无限,金黄麦浪在微风中轻柔摇曳,农家炊烟袅袅升起",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/8.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "璀璨星空下银河横跨天际,繁星闪烁神秘光芒营造浪漫夜空美景",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/9.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id++,
|
||||||
|
likeCount: random(100, 1000),
|
||||||
|
title: "雄伟瀑布从高耸悬崖飞流直下激起千层浪花,彩虹在水雾中若隐若现如梦如幻",
|
||||||
|
image: "https://unix.cool-js.com/images/demo/10.jpg"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
class="item dark:!bg-surface-800"
|
class="item dark:!bg-surface-800"
|
||||||
hover-class="opacity-80"
|
hover-class="opacity-80"
|
||||||
:hover-stay-time="50"
|
:hover-stay-time="50"
|
||||||
@tap="toPath(child.path!)"
|
@tap="toPath(child)"
|
||||||
>
|
>
|
||||||
<cl-icon :name="child.icon" :size="36"></cl-icon>
|
<cl-icon :name="child.icon" :size="36"></cl-icon>
|
||||||
<cl-text
|
<cl-text
|
||||||
@@ -80,6 +80,7 @@ type Item = {
|
|||||||
label: string;
|
label: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
|
disabled?: boolean;
|
||||||
children?: Item[];
|
children?: Item[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ const data = computed<Item[]>(() => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t("口令输入"),
|
label: t("口令输入"),
|
||||||
icon: "t-box-line",
|
icon: "input-method-line",
|
||||||
path: "/pages/demo/form/input-otp"
|
path: "/pages/demo/form/input-otp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -258,6 +259,12 @@ const data = computed<Item[]>(() => {
|
|||||||
icon: "list-view",
|
icon: "list-view",
|
||||||
path: "/pages/demo/data/list-view"
|
path: "/pages/demo/data/list-view"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("列表刷新"),
|
||||||
|
icon: "refresh-line",
|
||||||
|
path: "/pages/demo/data/list-view-refresh",
|
||||||
|
disabled: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t("瀑布流"),
|
label: t("瀑布流"),
|
||||||
icon: "layout-column-line",
|
icon: "layout-column-line",
|
||||||
@@ -373,6 +380,12 @@ const data = computed<Item[]>(() => {
|
|||||||
icon: "crop-line",
|
icon: "crop-line",
|
||||||
path: "/pages/demo/other/cropper"
|
path: "/pages/demo/other/cropper"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("富文本"),
|
||||||
|
icon: "text-snippet",
|
||||||
|
path: "/pages/demo/other/rict-text",
|
||||||
|
disabled: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "DayUts",
|
label: "DayUts",
|
||||||
icon: "timer-2-line",
|
icon: "timer-2-line",
|
||||||
@@ -388,8 +401,14 @@ const data = computed<Item[]>(() => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
function toPath(path: string) {
|
function toPath(item: Item) {
|
||||||
router.to(path);
|
if (item.disabled == true) {
|
||||||
|
return ui.showToast({
|
||||||
|
message: t("该功能正在开发中")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
router.to(item.path!);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLocale() {
|
function setLocale() {
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
direction="vertical"
|
direction="vertical"
|
||||||
@scroll="onScroll"
|
@scroll="onScroll"
|
||||||
>
|
>
|
||||||
<view class="cl-list-view__virtual-list" :style="{ height: listHeight + 'px' }">
|
<view
|
||||||
|
class="cl-list-view__virtual-list"
|
||||||
|
:style="{ height: virtual ? listHeight + 'px' : 'auto' }"
|
||||||
|
>
|
||||||
<view class="cl-list-view__spacer-top" :style="{ height: spacerTopHeight + 'px' }">
|
<view class="cl-list-view__spacer-top" :style="{ height: spacerTopHeight + 'px' }">
|
||||||
<slot name="top"></slot>
|
<slot name="top"></slot>
|
||||||
</view>
|
</view>
|
||||||
@@ -54,14 +57,12 @@
|
|||||||
},
|
},
|
||||||
pt.item?.className
|
pt.item?.className
|
||||||
]"
|
]"
|
||||||
:hover-class="parseClass([[isDark, '!bg-surface-800', '!bg-surface-50']])"
|
|
||||||
:hover-stay-time="50"
|
|
||||||
:style="{
|
:style="{
|
||||||
height: itemHeight + 'px'
|
height: virtual ? itemHeight + 'px' : 'auto'
|
||||||
}"
|
}"
|
||||||
@tap="onItemTap(item)"
|
@tap="onItemTap(item)"
|
||||||
>
|
>
|
||||||
<slot name="item" :data="item.data" :item="item">
|
<slot name="item" :item="item" :data="item.data" :value="item.data.value">
|
||||||
<view class="cl-list-view__item-inner">
|
<view class="cl-list-view__item-inner">
|
||||||
<cl-text> {{ item.data.label }} </cl-text>
|
<cl-text> {{ item.data.label }} </cl-text>
|
||||||
</view>
|
</view>
|
||||||
@@ -133,7 +134,7 @@ defineSlots<{
|
|||||||
// 分组头部插槽
|
// 分组头部插槽
|
||||||
header(props: { index: string }): any;
|
header(props: { index: string }): any;
|
||||||
// 列表项插槽
|
// 列表项插槽
|
||||||
item(props: { data: ClListViewItem; item: VirtualItem }): any;
|
item(props: { data: ClListViewItem; item: VirtualItem; value: any | null }): any;
|
||||||
// 底部插槽
|
// 底部插槽
|
||||||
bottom(): any;
|
bottom(): any;
|
||||||
// 索引插槽
|
// 索引插槽
|
||||||
@@ -490,6 +491,10 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
data
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ export type ClSelectPickerViewProps = {
|
|||||||
columns?: ClSelectOption[][];
|
columns?: ClSelectOption[][];
|
||||||
itemHeight?: number;
|
itemHeight?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
resetOnChange?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ import { parse } from "@/cool";
|
|||||||
import type { ClCascaderOption, ClListViewItem } from "../types";
|
import type { ClCascaderOption, ClListViewItem } from "../types";
|
||||||
|
|
||||||
export function useListView(data: UTSJSONObject[]) {
|
export function useListView(data: UTSJSONObject[]) {
|
||||||
return data.map((e) => parse<ClListViewItem>(e)!);
|
return data.map((e) => {
|
||||||
|
return parse<ClListViewItem>({
|
||||||
|
...e,
|
||||||
|
value: e
|
||||||
|
})!;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCascader(data: UTSJSONObject[]) {
|
export function useCascader(data: UTSJSONObject[]) {
|
||||||
|
|||||||
4
uni_modules/cool-ui/types/component.d.ts
vendored
4
uni_modules/cool-ui/types/component.d.ts
vendored
@@ -126,6 +126,10 @@ declare type ClListItemComponentPublicInstance = {
|
|||||||
initSwipe: () => void;
|
initSwipe: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare type ClListViewComponentPublicInstance = {
|
||||||
|
data: ClListViewItem[];
|
||||||
|
};
|
||||||
|
|
||||||
declare type ClCascaderComponentPublicInstance = {
|
declare type ClCascaderComponentPublicInstance = {
|
||||||
open: () => void;
|
open: () => void;
|
||||||
close: () => void;
|
close: () => void;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export type ClListItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ClListViewItem = {
|
export type ClListViewItem = {
|
||||||
label: string;
|
label?: string;
|
||||||
value?: any;
|
value?: any;
|
||||||
index?: string;
|
index?: string;
|
||||||
children?: ClListViewItem[];
|
children?: ClListViewItem[];
|
||||||
|
|||||||
Reference in New Issue
Block a user