From 087dacbea78ffa5e7dcb2859f19341231eb6f258 Mon Sep 17 00:00:00 2001 From: LingandRX Date: Mon, 21 Apr 2025 22:59:44 +0800 Subject: [PATCH] wxapp --- .cloudbase/container/debug.json | 1 + app.js | 57 ++++++++++++++++ app.json | 16 +++++ app.wxss | 33 +++++++++ images/add.svg | 5 ++ images/default-avatar.svg | 6 ++ images/items.svg | 7 ++ pages/add/add.js | 86 +++++++++++++++++++++++ pages/add/add.wxml | 29 ++++++++ pages/add/add.wxss | 51 ++++++++++++++ pages/detail/detail.js | 42 ++++++++++++ pages/detail/detail.wxml | 24 +++++++ pages/detail/detail.wxss | 46 +++++++++++++ pages/index/index.js | 63 +++++++++++++++++ pages/index/index.wxml | 47 +++++++++++++ pages/index/index.wxss | 117 ++++++++++++++++++++++++++++++++ pages/items/items.js | 47 +++++++++++++ pages/items/items.wxml | 21 ++++++ pages/items/items.wxss | 66 ++++++++++++++++++ project.config.json | 59 ++++++++++++++++ project.private.config.json | 20 ++++++ sitemap.json | 7 ++ utils/debug.js | 27 ++++++++ 23 files changed, 877 insertions(+) create mode 100644 .cloudbase/container/debug.json create mode 100644 app.js create mode 100644 app.json create mode 100644 app.wxss create mode 100644 images/add.svg create mode 100644 images/default-avatar.svg create mode 100644 images/items.svg create mode 100644 pages/add/add.js create mode 100644 pages/add/add.wxml create mode 100644 pages/add/add.wxss create mode 100644 pages/detail/detail.js create mode 100644 pages/detail/detail.wxml create mode 100644 pages/detail/detail.wxss create mode 100644 pages/index/index.js create mode 100644 pages/index/index.wxml create mode 100644 pages/index/index.wxss create mode 100644 pages/items/items.js create mode 100644 pages/items/items.wxml create mode 100644 pages/items/items.wxss create mode 100644 project.config.json create mode 100644 project.private.config.json create mode 100644 sitemap.json create mode 100644 utils/debug.js diff --git a/.cloudbase/container/debug.json b/.cloudbase/container/debug.json new file mode 100644 index 0000000..0d44458 --- /dev/null +++ b/.cloudbase/container/debug.json @@ -0,0 +1 @@ +{"containers":[],"config":{}} \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..6c4cc12 --- /dev/null +++ b/app.js @@ -0,0 +1,57 @@ +App({ + globalData: { + userInfo: null, + items: [] + }, + + onLaunch: function() { + // 获取本地存储的物品数据 + try { + const items = wx.getStorageSync('items') || [] + this.globalData.items = items + } catch (e) { + console.error('获取本地存储失败:', e) + } + + // 调试信息 + if (wx.getSystemInfoSync) { + const systemInfo = wx.getSystemInfoSync() + console.log('系统信息:', systemInfo) + } + + // 检查更新 + if (wx.canIUse('getUpdateManager')) { + const updateManager = wx.getUpdateManager() + updateManager.onCheckForUpdate(function(res) { + if (res.hasUpdate) { + updateManager.onUpdateReady(function() { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success: function(res) { + if (res.confirm) { + updateManager.applyUpdate() + } + } + }) + }) + updateManager.onUpdateFailed(function() { + wx.showModal({ + title: '更新提示', + content: '新版本下载失败,请检查网络设置', + showCancel: false + }) + }) + } + }) + } + }, + + onError: function(err) { + console.error('小程序发生错误:', err) + }, + + onUnhandledRejection: function(err) { + console.error('未处理的 Promise 错误:', err) + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..fe009d7 --- /dev/null +++ b/app.json @@ -0,0 +1,16 @@ +{ + "pages": [ + "pages/index/index", + "pages/items/items", + "pages/add/add", + "pages/detail/detail" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "个人物品管理", + "navigationBarTextStyle": "black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..91a03db --- /dev/null +++ b/app.wxss @@ -0,0 +1,33 @@ +page { + background-color: #f8f8f8; + font-size: 28rpx; + color: #333; + font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, + Segoe UI, Arial, Roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei', + sans-serif; +} + +.container { + display: flex; + flex-direction: column; + min-height: 100vh; + box-sizing: border-box; +} + +button { + margin: 0; + padding: 0; + border: none; + background: none; + line-height: 1; +} + +button::after { + border: none; +} + +image { + display: block; + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/images/add.svg b/images/add.svg new file mode 100644 index 0000000..3a74db6 --- /dev/null +++ b/images/add.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/images/default-avatar.svg b/images/default-avatar.svg new file mode 100644 index 0000000..9eecd9d --- /dev/null +++ b/images/default-avatar.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/images/items.svg b/images/items.svg new file mode 100644 index 0000000..06a4919 --- /dev/null +++ b/images/items.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/pages/add/add.js b/pages/add/add.js new file mode 100644 index 0000000..b547354 --- /dev/null +++ b/pages/add/add.js @@ -0,0 +1,86 @@ +const app = getApp() + +Page({ + data: { + name: '', + description: '', + price: 0, + imageUrl: '' + }, + + onNameInput: function(e) { + this.setData({ + name: e.detail.value + }) + }, + + onDescInput: function(e) { + this.setData({ + description: e.detail.value + }) + }, + + onPriceInput: function(e) { + this.setData({ + price: e.detail.value + }) + }, + + chooseImage: function() { + wx.chooseImage({ + count: 1, + sizeType: ['compressed'], + sourceType: ['album', 'camera'], + success: (res) => { + this.setData({ + imageUrl: res.tempFilePaths[0] + }) + } + }) + }, + + submit: function() { + if (!this.data.name) { + wx.showToast({ + title: '请输入物品名称', + icon: 'none' + }) + return + } + + const newItem = { + id: Date.now().toString(), + name: this.data.name, + description: this.data.description, + imageUrl: this.data.imageUrl, + createTime: new Date().toISOString() + } + + // 更新全局数据 + app.globalData.items.unshift(newItem) + wx.setStorageSync('items', app.globalData.items) + + wx.showToast({ + title: '添加成功', + icon: 'success', + duration: 2000, + success: () => { + setTimeout(() => { + wx.navigateBack() + }, 2000) + } + }) + }, + + goBack: function () { + wx.navigateBack({ + delta: 1, + success: function(res) { + + }, + fail: function(err) { + console.log(err) + } + }) + } +}) \ No newline at end of file diff --git a/pages/add/add.wxml b/pages/add/add.wxml new file mode 100644 index 0000000..5a5bc72 --- /dev/null +++ b/pages/add/add.wxml @@ -0,0 +1,29 @@ + + + 物品名称 + + + + + 物品描述 + + + + + 价格 + + + + + 物品图片 + + + + 点击上传图片 + + + + + + + \ No newline at end of file diff --git a/pages/add/add.wxss b/pages/add/add.wxss new file mode 100644 index 0000000..88c2615 --- /dev/null +++ b/pages/add/add.wxss @@ -0,0 +1,51 @@ +.container { + padding: 30rpx; +} + +.form-item { + margin-bottom: 30rpx; +} + +.label { + display: block; + font-size: 28rpx; + color: #333; + margin-bottom: 10rpx; +} + +input, textarea { + width: 80%; + padding: 20rpx; + border: 1rpx solid #ddd; + border-radius: 8rpx; + font-size: 28rpx; +} + +textarea { + height: 200rpx; +} + +.image-upload { + width: 300rpx; + height: 300rpx; + border: 2rpx dashed #ddd; + border-radius: 8rpx; + display: flex; + justify-content: center; + align-items: center; +} + +.image-upload image { + width: 100%; + height: 100%; + border-radius: 8rpx; +} + +.upload-placeholder { + color: #999; + font-size: 28rpx; +} + +.submit-btn { + margin-top: 50rpx; +} \ No newline at end of file diff --git a/pages/detail/detail.js b/pages/detail/detail.js new file mode 100644 index 0000000..d704279 --- /dev/null +++ b/pages/detail/detail.js @@ -0,0 +1,42 @@ +const app = getApp() + +Page({ + data: { + item: null + }, + + onLoad: function(options) { + const id = options.id + const item = app.globalData.items.find(item => item.id === id) + if (item) { + this.setData({ item }) + } + }, + + deleteItem: function() { + wx.showModal({ + title: '确认删除', + content: '确定要删除这个物品吗?', + success: (res) => { + if (res.confirm) { + const index = app.globalData.items.findIndex(item => item.id === this.data.item.id) + if (index !== -1) { + app.globalData.items.splice(index, 1) + wx.setStorageSync('items', app.globalData.items) + + wx.showToast({ + title: '删除成功', + icon: 'success', + duration: 2000, + success: () => { + setTimeout(() => { + wx.navigateBack() + }, 2000) + } + }) + } + } + } + }) + } +}) \ No newline at end of file diff --git a/pages/detail/detail.wxml b/pages/detail/detail.wxml new file mode 100644 index 0000000..43c05d0 --- /dev/null +++ b/pages/detail/detail.wxml @@ -0,0 +1,24 @@ + + + + + + 物品名称 + {{item.name}} + + + + 物品描述 + {{item.description}} + + + + 添加时间 + {{item.createTime}} + + + + + + + \ No newline at end of file diff --git a/pages/detail/detail.wxss b/pages/detail/detail.wxss new file mode 100644 index 0000000..e653fc3 --- /dev/null +++ b/pages/detail/detail.wxss @@ -0,0 +1,46 @@ +.container { + padding: 30rpx; +} + +.item-image { + width: 100%; + height: 400rpx; + border-radius: 12rpx; + margin-bottom: 30rpx; +} + +.item-info { + background: #fff; + border-radius: 12rpx; + padding: 30rpx; + margin-bottom: 30rpx; +} + +.info-item { + margin-bottom: 20rpx; +} + +.info-item:last-child { + margin-bottom: 0; +} + +.label { + font-size: 28rpx; + color: #999; + margin-bottom: 10rpx; + display: block; +} + +.value { + font-size: 32rpx; + color: #333; + line-height: 1.5; +} + +.action-buttons { + margin-top: 50rpx; +} + +.delete-btn { + width: 100%; +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..f57cb15 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,63 @@ +const app = getApp() + +Page({ + data: { + userInfo: null, + hasUserInfo: false, + canIUseGetUserProfile: false, + items: [], + todayItems: [] + }, + + onLoad: function() { + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true + }) + } + }, + + onShow: function() { + // 更新物品数据 + const items = app.globalData.items || [] + const today = new Date().toISOString().split('T')[0] + const todayItems = items.filter(item => item.createTime.startsWith(today)) + + this.setData({ + items: items, + todayItems: todayItems + }) + }, + + getUserProfile() { + wx.getUserProfile({ + desc: '用于完善用户资料', + success: (res) => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + }, + + navigateToItems: function() { + wx.navigateTo({ + url: '/pages/items/items' + }) + }, + + navigateToAdd: function() { + wx.navigateTo({ + url: '/pages/add/add' + }) + } +}) \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..ef69ca3 --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,47 @@ + + + + + + + + {{items.length}} + 物品总数 + + + {{todayItems.length}} + 今日新增 + + + + + + + + + + 我的物品 + 查看所有物品记录 + + > + + + + + + + + 添加物品 + 记录新的物品 + + > + + + \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..0e1f230 --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,117 @@ +.container { + padding: 0; + background: #f8f8f8; + min-height: 100vh; +} + +.header { + background: #2196F3; + padding: 40rpx 30rpx; + color: #fff; +} + +.user-info { + display: flex; + align-items: center; +} + +.avatar { + width: 120rpx; + height: 120rpx; + border-radius: 50%; + border: 4rpx solid rgba(255, 255, 255, 0.3); + margin-right: 30rpx; +} + +.user-detail { + flex: 1; +} + +.nickname { + font-size: 36rpx; + font-weight: bold; + margin-bottom: 10rpx; + display: block; +} + +.welcome { + font-size: 28rpx; + opacity: 0.8; +} + +.login-btn { + background: rgba(255, 255, 255, 0.2); + color: #fff; + font-size: 28rpx; + padding: 10rpx 30rpx; + border-radius: 30rpx; + margin: 0; +} + +.stats { + display: flex; + background: #fff; + margin: 20rpx; + border-radius: 16rpx; + padding: 30rpx; + box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05); +} + +.stat-item { + flex: 1; + text-align: center; +} + +.stat-num { + font-size: 48rpx; + font-weight: bold; + color: #2196F3; + display: block; + margin-bottom: 10rpx; +} + +.stat-label { + font-size: 28rpx; + color: #666; +} + +.menu-list { + margin: 20rpx; +} + +.menu-item { + display: flex; + align-items: center; + background: #fff; + padding: 30rpx; + border-radius: 16rpx; + margin-bottom: 20rpx; + box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05); +} + +.menu-icon { + width: 80rpx; + height: 80rpx; + margin-right: 30rpx; +} + +.menu-text { + flex: 1; +} + +.menu-title { + font-size: 32rpx; + color: #333; + display: block; + margin-bottom: 8rpx; +} + +.menu-desc { + font-size: 24rpx; + color: #999; +} + +.menu-arrow { + color: #999; + font-size: 32rpx; +} \ No newline at end of file diff --git a/pages/items/items.js b/pages/items/items.js new file mode 100644 index 0000000..636184b --- /dev/null +++ b/pages/items/items.js @@ -0,0 +1,47 @@ +const app = getApp() + +Page({ + data: { + items: [], + filteredItems: [], + searchText: '' + }, + + onLoad: function() { + this.setData({ + items: app.globalData.items, + filteredItems: app.globalData.items + }) + }, + + onShow: function() { + // 每次页面显示时更新数据 + this.setData({ + items: app.globalData.items, + filteredItems: this.filterItems(app.globalData.items, this.data.searchText) + }) + }, + + onSearch: function(e) { + const searchText = e.detail.value + this.setData({ + searchText, + filteredItems: this.filterItems(this.data.items, searchText) + }) + }, + + filterItems: function(items, searchText) { + if (!searchText) return items + return items.filter(item => + item.name.includes(searchText) || + item.description.includes(searchText) + ) + }, + + navigateToDetail: function(e) { + const id = e.currentTarget.dataset.id + wx.navigateTo({ + url: `/pages/detail/detail?id=${id}` + }) + } +}) \ No newline at end of file diff --git a/pages/items/items.wxml b/pages/items/items.wxml new file mode 100644 index 0000000..4f3d174 --- /dev/null +++ b/pages/items/items.wxml @@ -0,0 +1,21 @@ + + + + + + + + + + + {{item.name}} + {{item.description}} + + + + + + + 暂无物品记录 + + \ No newline at end of file diff --git a/pages/items/items.wxss b/pages/items/items.wxss new file mode 100644 index 0000000..b6c24e4 --- /dev/null +++ b/pages/items/items.wxss @@ -0,0 +1,66 @@ +.container { + padding: 20rpx; +} + +.search-bar { + padding: 20rpx; + background: #f5f5f5; + border-radius: 10rpx; + margin-bottom: 20rpx; +} + +.search-bar input { + background: #fff; + padding: 10rpx 20rpx; + border-radius: 8rpx; +} + +.items-list { + display: flex; + flex-direction: column; + gap: 20rpx; +} + +.item-card { + display: flex; + background: #fff; + padding: 20rpx; + border-radius: 10rpx; + box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.1); +} + +.item-image { + width: 160rpx; + height: 160rpx; + border-radius: 8rpx; + margin-right: 20rpx; +} + +.item-info { + flex: 1; + display: flex; + flex-direction: column; + justify-content: space-between; +} + +.item-name { + font-size: 32rpx; + font-weight: bold; + color: #333; +} + +.item-desc { + font-size: 28rpx; + color: #666; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; +} + +.empty-tip { + text-align: center; + padding: 100rpx 0; + color: #999; + font-size: 28rpx; +} \ No newline at end of file diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..a0354fd --- /dev/null +++ b/project.config.json @@ -0,0 +1,59 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "urlCheck": false, + "es6": true, + "enhance": false, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "useMultiFrameRuntime": false, + "useApiHook": false, + "useApiHostProcess": false, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "enableEngineNative": false, + "bundle": false, + "useIsolateContext": false, + "useCompilerModule": true, + "userConfirmedUseCompilerModuleSwitch": false, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false, + "useCompilerPlugins": false, + "ignoreUploadUnusedFiles": true, + "disableUseStrict": false, + "minifyJS": true, + "useStaticServer": true, + "enableWasm": false + }, + "compileType": "miniprogram", + "libVersion": "2.19.4", + "appid": "wx44eba9dbd5555ee9", + "projectname": "个人物品管理", + "condition": {}, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 2 + } +} \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..fcce2ee --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,20 @@ +{ + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "个人物品管理", + "miniprogramRoot": "", + "setting": { + "compileHotReLoad": false, + "urlCheck": false, + "showShadowRootInWxmlPanel": true, + "useStaticServer": true, + "showES6CompileOption": false + }, + "debugOptions": { + "hidedInDevtools": [] + }, + "scripts": {}, + "staticServerOptions": { + "baseURL": "", + "servePath": "" + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..99046b8 --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/utils/debug.js b/utils/debug.js new file mode 100644 index 0000000..110a222 --- /dev/null +++ b/utils/debug.js @@ -0,0 +1,27 @@ +const debug = { + log: function(...args) { + if (wx.getLogManager) { + const logManager = wx.getLogManager() + logManager.log(...args) + } + console.log(...args) + }, + + error: function(...args) { + if (wx.getLogManager) { + const logManager = wx.getLogManager() + logManager.error(...args) + } + console.error(...args) + }, + + warn: function(...args) { + if (wx.getLogManager) { + const logManager = wx.getLogManager() + logManager.warn(...args) + } + console.warn(...args) + } +} + +module.exports = debug \ No newline at end of file