优化细节
This commit is contained in:
120
.vscode/template.code-snippets
vendored
Normal file
120
.vscode/template.code-snippets
vendored
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
{
|
||||||
|
"page": {
|
||||||
|
"prefix": "page",
|
||||||
|
"scope": "vue",
|
||||||
|
"body": [
|
||||||
|
"<template>",
|
||||||
|
" <cl-page>",
|
||||||
|
" <view class=\"p-3\">",
|
||||||
|
" $1",
|
||||||
|
" </view>",
|
||||||
|
" </cl-page>",
|
||||||
|
"</template>",
|
||||||
|
"",
|
||||||
|
"<script lang=\"ts\" setup>",
|
||||||
|
"import { service, router } from \"@/cool\";",
|
||||||
|
"",
|
||||||
|
"</script>",
|
||||||
|
"",
|
||||||
|
"<style lang=\"scss\" scoped>",
|
||||||
|
"",
|
||||||
|
"</style>",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"description": "page snippets"
|
||||||
|
},
|
||||||
|
"popup": {
|
||||||
|
"prefix": "popup",
|
||||||
|
"scope": "vue",
|
||||||
|
"body": [
|
||||||
|
"<template>",
|
||||||
|
" <cl-popup v-model=\"visible\">",
|
||||||
|
" <view class=\"component$1\"> </view>",
|
||||||
|
" </cl-popup>",
|
||||||
|
"</template>",
|
||||||
|
"",
|
||||||
|
"<script lang=\"ts\" setup>",
|
||||||
|
"import { ref } from \"vue\";",
|
||||||
|
"import { service, router } from \"@/cool\";",
|
||||||
|
"",
|
||||||
|
"// 是否可见",
|
||||||
|
"const visible = ref(false);",
|
||||||
|
"",
|
||||||
|
"// 打开",
|
||||||
|
"function open() {",
|
||||||
|
" visible.value = true;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"// 关闭",
|
||||||
|
"function close() {",
|
||||||
|
" visible.value = false;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"defineExpose({",
|
||||||
|
" open,",
|
||||||
|
" close,",
|
||||||
|
"});",
|
||||||
|
"</script>",
|
||||||
|
"",
|
||||||
|
"<style lang=\"scss\" scoped>",
|
||||||
|
"",
|
||||||
|
"</style>",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"description": "popup snippets"
|
||||||
|
},
|
||||||
|
"pager": {
|
||||||
|
"prefix": "list-view-refresh",
|
||||||
|
"scope": "vue",
|
||||||
|
"body": [
|
||||||
|
"<template>",
|
||||||
|
" <cl-list-view",
|
||||||
|
" :data=\"listView\"",
|
||||||
|
" :virtual=\"false\"",
|
||||||
|
" :pt=\"{",
|
||||||
|
" refresher: {",
|
||||||
|
" className: 'pt-3'",
|
||||||
|
" }",
|
||||||
|
" }\"",
|
||||||
|
" :refresher-enabled=\"true\"",
|
||||||
|
" @pull=\"onPull\"",
|
||||||
|
" @bottom=\"loadMore\"",
|
||||||
|
" >",
|
||||||
|
" <template #item=\"{ value }\">",
|
||||||
|
" <view class=\"p-3\">",
|
||||||
|
" $1",
|
||||||
|
" </view>",
|
||||||
|
" </template>",
|
||||||
|
" </cl-list-view>",
|
||||||
|
"</template>",
|
||||||
|
"",
|
||||||
|
"<script lang=\"ts\" setup>",
|
||||||
|
"import { ref } from \"vue\";",
|
||||||
|
"import { usePager } from \"@/cool\";",
|
||||||
|
"import { useUi } from \"@/uni_modules/cool-ui\";",
|
||||||
|
"",
|
||||||
|
"const ui = useUi();",
|
||||||
|
"",
|
||||||
|
"const listViewRef = ref<ClListViewComponentPublicInstance | null>(null);",
|
||||||
|
"",
|
||||||
|
"const { refresh, listView, loading, loadMore } = usePager((params) => {",
|
||||||
|
" return service.$1.page(params);",
|
||||||
|
"});",
|
||||||
|
"",
|
||||||
|
"async function onPull() {",
|
||||||
|
" await refresh({ page: 1 });",
|
||||||
|
" listViewRef.value!.stopRefresh();",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"onReady(() => {",
|
||||||
|
" ui.showLoading(\"加载中\");",
|
||||||
|
" refresh({",
|
||||||
|
" page: 1,",
|
||||||
|
" size: 20,",
|
||||||
|
" });",
|
||||||
|
"});",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"description": "list-view refresh snippets"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
|||||||
<cl-page>
|
<cl-page>
|
||||||
<cl-list-view
|
<cl-list-view
|
||||||
ref="listViewRef"
|
ref="listViewRef"
|
||||||
:data="data"
|
:data="listView"
|
||||||
:virtual="false"
|
:virtual="false"
|
||||||
:pt="{
|
:pt="{
|
||||||
refresher: {
|
refresher: {
|
||||||
@@ -27,10 +27,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useListView, useUi, type ClListViewItem } from "@/uni_modules/cool-ui";
|
import { useUi } from "@/uni_modules/cool-ui";
|
||||||
import { computed, ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { usePager } from "@/cool";
|
import { usePager } from "@/cool";
|
||||||
import GoodsItem from "../components/goods-item.uvue";
|
import GoodsItem from "../components/goods-item.uvue";
|
||||||
|
import { t } from "@/locale";
|
||||||
|
|
||||||
const ui = useUi();
|
const ui = useUi();
|
||||||
|
|
||||||
@@ -38,8 +39,9 @@ const listViewRef = ref<ClListViewComponentPublicInstance | null>(null);
|
|||||||
|
|
||||||
let id = 0;
|
let id = 0;
|
||||||
|
|
||||||
const { refresh, list, loading, loadMore } = usePager((params) => {
|
const { refresh, list, listView, loading, loadMore } = usePager((params) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
// 模拟请求
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve({
|
resolve({
|
||||||
list: [
|
list: [
|
||||||
@@ -101,17 +103,14 @@ const { refresh, list, loading, loadMore } = usePager((params) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = computed<ClListViewItem[]>(() => {
|
|
||||||
return useListView(list.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onPull() {
|
async function onPull() {
|
||||||
await refresh({ page: 1 });
|
await refresh({ page: 1 });
|
||||||
listViewRef.value!.stopRefresh();
|
listViewRef.value!.stopRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady(() => {
|
onReady(() => {
|
||||||
ui.showLoading("加载中");
|
ui.showLoading(t("加载中"));
|
||||||
|
// 默认请求
|
||||||
refresh({});
|
refresh({});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
>{{ message }}</cl-text
|
>{{ message }}</cl-text
|
||||||
>
|
>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<cl-safe-area type="bottom" v-if="safeAreaBottom"></cl-safe-area>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -53,6 +55,11 @@ const props = defineProps({
|
|||||||
finishText: {
|
finishText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: () => t("没有更多了")
|
default: () => t("没有更多了")
|
||||||
|
},
|
||||||
|
// 是否显示底部安全区
|
||||||
|
safeAreaBottom: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,7 +87,7 @@ const message = computed(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.cl-loadmore-wrapper {
|
.cl-loadmore-wrapper {
|
||||||
@apply flex flex-row items-center justify-center py-2;
|
@apply flex flex-col items-center justify-center py-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cl-loadmore {
|
.cl-loadmore {
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
<template>
|
|
||||||
<view class="back-top-wrapper" :style="{ bottom }">
|
|
||||||
<view
|
|
||||||
class="back-top"
|
|
||||||
:class="{
|
|
||||||
'is-show': visible
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<cl-icon name="skip-up-line" color="white" size="25px"></cl-icon>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { computed, ref } from "vue";
|
|
||||||
import { usePage } from "@/cool";
|
|
||||||
|
|
||||||
defineOptions({
|
|
||||||
name: "cl-page-back-top"
|
|
||||||
});
|
|
||||||
|
|
||||||
const page = usePage();
|
|
||||||
const { screenHeight } = uni.getWindowInfo();
|
|
||||||
|
|
||||||
// 是否显示回到顶部按钮
|
|
||||||
const visible = ref(false);
|
|
||||||
|
|
||||||
// 底部距离
|
|
||||||
const bottom = computed(() => {
|
|
||||||
let h = 20;
|
|
||||||
|
|
||||||
if (page.hasCustomTabBar()) {
|
|
||||||
h += page.getTabBarHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
return h + "px";
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听页面滚动
|
|
||||||
page.onPageScroll((top) => {
|
|
||||||
// 控制是否显示回到顶部按钮
|
|
||||||
visible.value = top > screenHeight - 100;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.back-top {
|
|
||||||
@apply flex flex-row items-center justify-center bg-primary-500 rounded-full;
|
|
||||||
width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
transition-property: transform;
|
|
||||||
transition-duration: 0.3s;
|
|
||||||
transform: translateX(160rpx);
|
|
||||||
|
|
||||||
&.is-show {
|
|
||||||
transform: translateX(-20px);
|
|
||||||
}
|
|
||||||
|
|
||||||
&-wrapper {
|
|
||||||
@apply fixed z-50 overflow-visible;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
:scroll-with-animation="true"
|
:scroll-with-animation="true"
|
||||||
@scroll="onScroll"
|
@scroll="onScroll"
|
||||||
>
|
>
|
||||||
<back-top v-if="backTop" @tap="scrollToTop"></back-top>
|
<cl-back-top v-if="backTop" @tap="scrollToTop"></cl-back-top>
|
||||||
<theme></theme>
|
<theme></theme>
|
||||||
<ui></ui>
|
<ui></ui>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
|
|
||||||
<!-- #ifndef APP -->
|
<!-- #ifndef APP -->
|
||||||
<back-top v-if="backTop" @tap="scrollToTop"></back-top>
|
<cl-back-top v-if="backTop" @tap="scrollToTop"></cl-back-top>
|
||||||
<theme></theme>
|
<theme></theme>
|
||||||
<ui></ui>
|
<ui></ui>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref, watch } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
import { router, usePage } from "@/cool";
|
import { router, usePage } from "@/cool";
|
||||||
import BackTop from "./back-top.uvue";
|
|
||||||
import Theme from "./theme.uvue";
|
import Theme from "./theme.uvue";
|
||||||
import Ui from "./ui.uvue";
|
import Ui from "./ui.uvue";
|
||||||
import { locale, t } from "@/locale";
|
import { locale, t } from "@/locale";
|
||||||
@@ -34,7 +33,7 @@ defineOptions({
|
|||||||
name: "cl-page"
|
name: "cl-page"
|
||||||
});
|
});
|
||||||
|
|
||||||
const props = defineProps({
|
defineProps({
|
||||||
// 是否显示回到顶部按钮
|
// 是否显示回到顶部按钮
|
||||||
backTop: {
|
backTop: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -111,6 +111,22 @@ export type ClListViewItem = {
|
|||||||
children?: ClListViewItem[];
|
children?: ClListViewItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ClListViewGroup = {
|
||||||
|
index: string;
|
||||||
|
children: ClListViewItem[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ClListViewVirtualItem = {
|
||||||
|
key: string;
|
||||||
|
type: "header" | "item";
|
||||||
|
index: number;
|
||||||
|
top: number;
|
||||||
|
height: number;
|
||||||
|
data: ClListViewItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ClListViewRefresherStatus = "default" | "pulling" | "refreshing";
|
||||||
|
|
||||||
export type ClCascaderOption = ClListViewItem;
|
export type ClCascaderOption = ClListViewItem;
|
||||||
|
|
||||||
export type ClPopupDirection = "top" | "right" | "bottom" | "center" | "left";
|
export type ClPopupDirection = "top" | "right" | "bottom" | "center" | "left";
|
||||||
|
|||||||
Reference in New Issue
Block a user