From 0d58fc80f448d52d62fec65dc2d6a0265a6d8993 Mon Sep 17 00:00:00 2001 From: zhengw <247276359@qq.com> Date: Mon, 12 Jan 2026 16:29:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(components):=20=E6=96=B0=E5=A2=9E=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E3=80=81=E9=80=89=E6=8B=A9=E5=99=A8=E5=92=8C=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=A0=8F=E7=BB=84=E4=BB=B6=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 pagination-plugin 组件,包含完整的分页功能和页面跳转选择 - 添加 select-plugin 组件,支持单选和多选模式的选择弹窗 - 添加 tab-bar-plugin 组件,提供底部导航栏功能 - 在 page-plugin 中集成 t-loading 组件替换原有的加载逻辑 - 移除页面中的登录状态监听逻辑和相关订阅功能 - 修改页面样式传递方式,将 style 属性改为 customStyle - 更新组件依赖配置文件,添加新的组件引用 --- .../components/page-plugin/page-plugin.json | 7 +- .../components/page-plugin/page-plugin.ts | 28 ++--- .../components/page-plugin/page-plugin.wxml | 17 +-- .../pagination-plugin/pagination-plugin.json | 8 ++ .../pagination-plugin/pagination-plugin.ts | 102 ++++++++++++++++++ .../pagination-plugin/pagination-plugin.wxml | 42 ++++++++ .../pagination-plugin/pagination-plugin.wxss | 8 ++ .../select-plugin/select-plugin.json | 10 ++ .../components/select-plugin/select-plugin.ts | 64 +++++++++++ .../select-plugin/select-plugin.wxml | 30 ++++++ .../select-plugin/select-plugin.wxss | 10 ++ .../tab-bar-plugin/tab-bar-plugin.json | 8 ++ .../tab-bar-plugin/tab-bar-plugin.ts | 43 ++++++++ .../tab-bar-plugin/tab-bar-plugin.wxml | 13 +++ .../tab-bar-plugin/tab-bar-plugin.wxss | 0 15 files changed, 365 insertions(+), 25 deletions(-) create mode 100644 miniprogram/pages/components/pagination-plugin/pagination-plugin.json create mode 100644 miniprogram/pages/components/pagination-plugin/pagination-plugin.ts create mode 100644 miniprogram/pages/components/pagination-plugin/pagination-plugin.wxml create mode 100644 miniprogram/pages/components/pagination-plugin/pagination-plugin.wxss create mode 100644 miniprogram/pages/components/select-plugin/select-plugin.json create mode 100644 miniprogram/pages/components/select-plugin/select-plugin.ts create mode 100644 miniprogram/pages/components/select-plugin/select-plugin.wxml create mode 100644 miniprogram/pages/components/select-plugin/select-plugin.wxss create mode 100644 miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.json create mode 100644 miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.ts create mode 100644 miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxml create mode 100644 miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxss diff --git a/miniprogram/pages/components/page-plugin/page-plugin.json b/miniprogram/pages/components/page-plugin/page-plugin.json index fe3d234..32eaf45 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.json +++ b/miniprogram/pages/components/page-plugin/page-plugin.json @@ -3,7 +3,8 @@ "usingComponents": { "t-button": "tdesign-miniprogram/button/button", "t-checkbox": "tdesign-miniprogram/checkbox/checkbox", - "t-divider": "tdesign-miniprogram/divider/divider", - "t-link": "tdesign-miniprogram/link/link" + "t-link": "tdesign-miniprogram/link/link", + "t-loading": "tdesign-miniprogram/loading/loading", + "no-auth-plugin": "/pages/components/no-auth-plugin/no-auth-plugin" } -} \ No newline at end of file +} diff --git a/miniprogram/pages/components/page-plugin/page-plugin.ts b/miniprogram/pages/components/page-plugin/page-plugin.ts index 2e9b43f..9759b63 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.ts +++ b/miniprogram/pages/components/page-plugin/page-plugin.ts @@ -1,6 +1,6 @@ import { base, defaultAvatarUrl } from "@/utils/config"; import { Subscribe } from "@/utils/subscribe"; -import { getCurrentPageRoute, getStorage, setStorage } from "@/utils/util"; +import { setStorage } from "@/utils/util"; // import { IStorage } from "@/utils/storage"; // const app = getApp(); @@ -12,22 +12,22 @@ Component({ isLogin: Boolean, loading: Boolean, isAuth: null, - style: null, + customStyle: null, }, - attached() { - this.setData({ isLogin: getStorage("isLogin") == 1 }); + // attached() { + // this.setData({ isLogin: getStorage("isLogin") == 1 }); - console.log("attached"); - Subscribe.on("isLogin", getCurrentPageRoute(), () => { - this.setData({ isLogin: getStorage("isLogin") == 1 }); - console.log("监听到 isLogin 变化:"); - }); - }, - detached() { - console.log("detached"); - Subscribe.off("isLogin", getCurrentPageRoute()); - }, + // console.log("attached"); + // Subscribe.on("isLogin", getCurrentPageRoute(), () => { + // this.setData({ isLogin: getStorage("isLogin") == 1 }); + // console.log("监听到 isLogin 变化:"); + // }); + // }, + // detached() { + // console.log("detached"); + // Subscribe.off("isLogin", getCurrentPageRoute()); + // }, data: { avatarUrl: defaultAvatarUrl, diff --git a/miniprogram/pages/components/page-plugin/page-plugin.wxml b/miniprogram/pages/components/page-plugin/page-plugin.wxml index 3d67e3f..4b42441 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.wxml +++ b/miniprogram/pages/components/page-plugin/page-plugin.wxml @@ -1,15 +1,15 @@ - + - - + + - + @@ -27,11 +27,12 @@ 我已阅读并同意 - - 《{{appletName}}平台用户服务协议》 + 《{{appletName}}平台用户服务协议》 + - 《{{appletName}}隐私权政策》 - + 《{{appletName}}隐私权政策》 + + diff --git a/miniprogram/pages/components/pagination-plugin/pagination-plugin.json b/miniprogram/pages/components/pagination-plugin/pagination-plugin.json new file mode 100644 index 0000000..4d6b044 --- /dev/null +++ b/miniprogram/pages/components/pagination-plugin/pagination-plugin.json @@ -0,0 +1,8 @@ +{ + "component": true, + "usingComponents": { + "t-picker": "tdesign-miniprogram/picker/picker", + "t-picker-item": "tdesign-miniprogram/picker-item/picker-item" + } +} + diff --git a/miniprogram/pages/components/pagination-plugin/pagination-plugin.ts b/miniprogram/pages/components/pagination-plugin/pagination-plugin.ts new file mode 100644 index 0000000..f7e5c3d --- /dev/null +++ b/miniprogram/pages/components/pagination-plugin/pagination-plugin.ts @@ -0,0 +1,102 @@ +import { getDataSet, toNumber } from "@/utils/util"; + +Component({ + options: { multipleSlots: true }, + /** + * 组件的属性列表 + */ + properties: { + curr_page: { + type: Number, + value: 1, + observer() { + this.page(); + }, + }, + total: { + type: Number, + value: 0, + observer() { + this.page(); + }, + }, + page_count: { + type: Number, + value: 20, + observer() { + this.page(); + }, + }, + }, + + /** + * 组件的初始数据 + */ + data: { + pages: [] as number[], + totalPage: 0, + open: false, + pickerPages: [] as any[], + }, + + /** + * 组件的方法列表 + */ + methods: { + page() { + const totalPage = Math.ceil( + toNumber(this.data.total) / toNumber(this.data.page_count) + ); + const showPageNum = 3; + + // 计算显示的页码范围 + let startPage = Math.max( + 1, + toNumber(this.data.curr_page) - Math.floor(showPageNum / 2) + ); + let endPage = Math.min(totalPage, startPage + showPageNum - 1); + + // 调整起始页码,确保显示的页码数量不超过最大值 + if (endPage - startPage + 1 < showPageNum) { + startPage = Math.max(1, endPage - showPageNum + 1); + } + + // 生成页码数组 + const pages = []; + for (let i = startPage; i <= endPage; i++) { + pages.push(i); + } + + this.setData({ pages, totalPage }); + }, + pageChange(e: any) { + let curr_page = getDataSet(e).page; + // if (curr_page == this.data.curr_page) { + // return; + // } + if (curr_page == "prev") { + curr_page = this.data.curr_page - 1; + } else if (curr_page == "next") { + curr_page = this.data.curr_page + 1; + } + this.triggerEvent("change", { curr_page }); + }, + pageSelect() { + this.setData({ + open: true, + pickerPages: Array.from({ length: this.data.totalPage }, (_, i) => ({ + value: i + 1, + label: `第 ${i + 1} 页`, + })), + }); + }, + onConfirm(e: any) { + const curr_page = e.detail.value[0]; + // if (curr_page == this.data.curr_page) { + // return; + // } + this.triggerEvent("change", { curr_page: curr_page }); + }, + }, +}); + diff --git a/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxml b/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxml new file mode 100644 index 0000000..13e23e4 --- /dev/null +++ b/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxml @@ -0,0 +1,42 @@ + + 共{{total}}条 + + + {{item}} + + + + 跳转 + + + + + + diff --git a/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxss b/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxss new file mode 100644 index 0000000..1f3bcaf --- /dev/null +++ b/miniprogram/pages/components/pagination-plugin/pagination-plugin.wxss @@ -0,0 +1,8 @@ +.box { + display: flex; + align-items: center; + justify-content: center; + flex-wrap: wrap; + column-gap: 8px; + row-gap: 8px; +} diff --git a/miniprogram/pages/components/select-plugin/select-plugin.json b/miniprogram/pages/components/select-plugin/select-plugin.json new file mode 100644 index 0000000..85aa4cf --- /dev/null +++ b/miniprogram/pages/components/select-plugin/select-plugin.json @@ -0,0 +1,10 @@ +{ + "component": true, + "usingComponents": { + "popup-plugin": "/pages/components/popup-plugin/popup-plugin", + "t-radio-group": "tdesign-miniprogram/radio-group/radio-group", + "t-checkbox": "tdesign-miniprogram/checkbox/checkbox", + "t-checkbox-group": "tdesign-miniprogram/checkbox-group/checkbox-group" + } +} + diff --git a/miniprogram/pages/components/select-plugin/select-plugin.ts b/miniprogram/pages/components/select-plugin/select-plugin.ts new file mode 100644 index 0000000..8645f6d --- /dev/null +++ b/miniprogram/pages/components/select-plugin/select-plugin.ts @@ -0,0 +1,64 @@ +Component({ + options: { multipleSlots: true }, + /** + * 组件的属性列表 + */ + properties: { + mode: { + type: String, + value: "single", + }, + title: { + type: String, + value: "请选择", + }, + options: { + type: Array, + value: [], + }, + value: { + type: null, + value: [], + }, + }, + observers: { + "value,mode": function (v, m) { + if (m == "multiple") { + this.setData({ val: Array.isArray(v) ? [...v] : [] }); + } else { + this.setData({ val: v }); + } + }, + }, + + /** + * 组件的初始数据 + */ + data: { + visible: false, + val: [] as any[] | string | number, + }, + + /** + * 组件的方法列表 + */ + methods: { + click() { + this.setData({ visible: true }); + }, + close() { + this.setData({ visible: false }); + }, + radioChange(e: any) { + this.setData({ val: e.detail.value }); + }, + checkboxChange(e: any) { + this.setData({ val: e.detail.value }); + }, + ok() { + this.setData({ visible: false }); + this.triggerEvent("change", { value: this.data.val }); + }, + }, +}); + diff --git a/miniprogram/pages/components/select-plugin/select-plugin.wxml b/miniprogram/pages/components/select-plugin/select-plugin.wxml new file mode 100644 index 0000000..b867e9c --- /dev/null +++ b/miniprogram/pages/components/select-plugin/select-plugin.wxml @@ -0,0 +1,30 @@ + + + + + + + + + + + {{item.label}} + + + + + 确定 + + + diff --git a/miniprogram/pages/components/select-plugin/select-plugin.wxss b/miniprogram/pages/components/select-plugin/select-plugin.wxss new file mode 100644 index 0000000..6ed0c83 --- /dev/null +++ b/miniprogram/pages/components/select-plugin/select-plugin.wxss @@ -0,0 +1,10 @@ +.footer { + display: flex; + align-items: center; + justify-content: center; + position: sticky; + bottom: 0; + background: #fff; + z-index: 1; + padding-top: 12px; +} diff --git a/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.json b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.json new file mode 100644 index 0000000..3417547 --- /dev/null +++ b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.json @@ -0,0 +1,8 @@ +{ + "component": true, + "usingComponents": { + "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar", + "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item" + } +} + diff --git a/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.ts b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.ts new file mode 100644 index 0000000..4ab532a --- /dev/null +++ b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.ts @@ -0,0 +1,43 @@ +Component({ + options: { multipleSlots: true }, + /** + * 组件的属性列表 + */ + properties: { + active: { + type: String, + value: "home", + }, + }, + + /** + * 组件的初始数据 + */ + data: { + list: [ + { value: "home", label: "首页", icon: "home" }, + { value: "scan", label: "扫码", icon: "scan" }, + { value: "my", label: "我的", icon: "user" }, + ], + pages: { + index: "/pages/index/index", + scan: "/pages/processEntry/processEntry", + my: "/pages/my/my", + } as Record, + }, + + /** + * 组件的方法列表 + */ + methods: { + onChange(e: any) { + if (e.detail.value == this.data.active) { + return; + } + wx.reLaunch({ + url: this.data.pages[e.detail.value], + }); + }, + }, +}); + diff --git a/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxml b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxml new file mode 100644 index 0000000..3479f92 --- /dev/null +++ b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxml @@ -0,0 +1,13 @@ + + + {{item.label}} + + + diff --git a/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxss b/miniprogram/pages/components/tab-bar-plugin/tab-bar-plugin.wxss new file mode 100644 index 0000000..e69de29