feat: add resident miniapp MVP

This commit is contained in:
王鹏
2026-07-07 16:38:13 +08:00
parent bb325151d6
commit 576c54ec9d
52 changed files with 17865 additions and 66 deletions

View File

@@ -1 +1,46 @@
Page({})
const { listCategories, listProducts } = require('../../api/productApi')
Page({
data: {
loading: false,
categories: [],
activeCategoryId: null,
products: []
},
onLoad() {
this.load()
},
load() {
this.setData({ loading: true })
Promise.all([listCategories(), listProducts()])
.then(([categories, products]) => {
this.setData({
categories: categories || [],
products: products || []
})
})
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
.finally(() => this.setData({ loading: false }))
},
chooseCategory(event) {
const categoryId = event.currentTarget.dataset.id
this.setData({ activeCategoryId: categoryId })
listProducts(categoryId)
.then((products) => this.setData({ products: products || [] }))
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
},
clearCategory() {
this.setData({ activeCategoryId: null })
listProducts()
.then((products) => this.setData({ products: products || [] }))
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
},
goDetail(event) {
wx.navigateTo({ url: '/pages/products/detail?id=' + event.currentTarget.dataset.id })
}
})