diff --git a/app/api/base.js b/app/api/base.js index ac9e069..43c1115 100644 --- a/app/api/base.js +++ b/app/api/base.js @@ -1,5 +1,7 @@ module.exports = { - bauseUrl:"http://192.168.2.123:8084", - banner:"/api/banner", - goods:/api/front/pageList/suggest + // bauseUrl:"http://iwenwiki.com:3001",//公共地址 + bauseUrl:"http://192.168.2.192:8084", + // goods:"/api/goods", //商品列表 + goods:"/api/front/pagelist/product/0? page=1&limit=10", + } \ No newline at end of file diff --git a/app/api/index.js b/app/api/index.js index 1563d7a..717bba7 100644 --- a/app/api/index.js +++ b/app/api/index.js @@ -1,7 +1,11 @@ -const {require} = require("../utils/request") -const { goods} = require("./base") +const {request} = require("../utils/request") +const { goods, bauseUrl} = require("./base") function getGoods(data){ - return request() + return request(bauseUrl + goods,"GET",data) +} + +module.exports = { + getGoods } \ No newline at end of file diff --git a/app/components/back-to-top/back-to-top.js b/app/components/back-to-top/back-to-top.js new file mode 100644 index 0000000..cf3927c --- /dev/null +++ b/app/components/back-to-top/back-to-top.js @@ -0,0 +1,22 @@ +Component({ + properties: { + // 是否显示返回顶部按钮 + show: { + type: Boolean, + value: false, + observer: function(newVal) { + this.setData({ isVisible: newVal }); + } + } + }, + data: { + isVisible: false + }, + methods: { + // 触发父页面的返回顶部方法 + scrollToTop() { + // 使用 triggerEvent 触发父页面的事件 + this.triggerEvent('scrolltomain'); + } + } +}); \ No newline at end of file diff --git a/app/components/back-to-top/back-to-top.json b/app/components/back-to-top/back-to-top.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/app/components/back-to-top/back-to-top.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/app/components/back-to-top/back-to-top.wxml b/app/components/back-to-top/back-to-top.wxml new file mode 100644 index 0000000..a665762 --- /dev/null +++ b/app/components/back-to-top/back-to-top.wxml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/app/components/back-to-top/back-to-top.wxss b/app/components/back-to-top/back-to-top.wxss new file mode 100644 index 0000000..74dbac5 --- /dev/null +++ b/app/components/back-to-top/back-to-top.wxss @@ -0,0 +1,18 @@ +.back-to-top { + position: fixed; + bottom: 50px; + right: 20px; + width: 50px; + height: 50px; + background-color: rgba(85, 84, 84, 0.5); + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; + z-index: 1000; +} + +.back-to-top image { + width: 35px; + height: 35px; +} diff --git a/app/components/goods-list/goods-list.js b/app/components/goods-list/goods-list.js index bac4bc5..f3f9df6 100644 --- a/app/components/goods-list/goods-list.js +++ b/app/components/goods-list/goods-list.js @@ -5,7 +5,10 @@ Component({ * 组件的属性列表 */ properties: { - + goodsData: { + type: Array, + value: [] + } }, /** diff --git a/app/components/goods-list/goods-list.wxml b/app/components/goods-list/goods-list.wxml index 197dd4e..4c0fcae 100644 --- a/app/components/goods-list/goods-list.wxml +++ b/app/components/goods-list/goods-list.wxml @@ -1,67 +1,17 @@ - + - + - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 + {{item.storeName}} + 规格:{{item.size}} - ¥21298.00 - - + {{item.price}} + + + - - - - - - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 - - ¥21298.00 - - - - - - - - - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 - - ¥21298.00 - - - - - - - - - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 - - ¥21298.00 - - - - - - - - - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 - - ¥21298.00 - - - - - - - - - 松下(Panasonic)DC-BS1HGK微单相机 数码相机 模块化摄影机 视频 直播多机位 电影 - - ¥21298.00 diff --git a/app/components/goods-list/goods-list.wxss b/app/components/goods-list/goods-list.wxss index 9a902d2..15de161 100644 --- a/app/components/goods-list/goods-list.wxss +++ b/app/components/goods-list/goods-list.wxss @@ -18,7 +18,7 @@ font-size: 14px; text-align: left; line-height:1.05rem; - height: 4.8rem; + height: 2rem; font-family: -apple-system,'Helvetica Neue', sans-serif; overflow: hidden; display: -webkit-box; @@ -33,4 +33,18 @@ } .list .item .goods_info .goods_price text{ font-size: 1rem; +} +.goods_weight{ + color: rgb(107, 107, 107); + font-size: 15px; +} +.cart-icon{ + height: 25px; + width: 25px; + margin-right: 10px; +} +.list .item .goods_info .goods_price{ + display: flex; + align-items:center; + justify-content:space-between; } \ No newline at end of file diff --git a/app/images/arrow-up.png b/app/images/arrow-up.png new file mode 100644 index 0000000..a67c56d Binary files /dev/null and b/app/images/arrow-up.png differ diff --git a/app/images/gouwuche2.png b/app/images/gouwuche2.png new file mode 100644 index 0000000..33cd82b Binary files /dev/null and b/app/images/gouwuche2.png differ diff --git a/app/pages/index/index.js b/app/pages/index/index.js index 242a0d8..5794ad5 100644 --- a/app/pages/index/index.js +++ b/app/pages/index/index.js @@ -1,6 +1,10 @@ +const { + getGoods +} = require("../../api/index.js") Page({ data: { value: "", + showBackToTop: false, navData: [{ id: "1", text: "即将开团", @@ -19,14 +23,65 @@ Page({ icon: "stop-circle-o", color: "#36ab60" } - ] + ], + page: 1, + goodsData: [] }, + onLoad() { + this.http(this.data.page) + }, + /* 点击搜索框获取焦点 - */ - clickSearch(){ -wx.navigateTo({ - url: '/pages/search/search', -}) + */ + clickSearch() { + wx.navigateTo({ + url: '/pages/search/search', + }) + }, + onScroll(event) { + // 获取滚动位置 + const scrollTop = event.detail.scrollTop; + // 当滚动到一定位置时显示返回顶部按钮 + this.setData({ + showBackToTop: scrollTop > 300 + }); + + }, + handleScrollToTop() { + // console.log("尝试返回顶部"); + wx.pageScrollTo({ + scrollTop: 0, + duration: 300, + // success: () => console.log("返回顶部成功"), + // fail: (err) => console.error("返回顶部失败", err) + }); + }, + + http(page) { + getGoods({ + page + }).then(res => { + if (!res.data.msg) { + this.setData({ + // 老数据合并新数据,做累加操作 + goodsData: this.data.goodsData.concat(res.data.data) + }) + } else { + //给出用户提示 + wx.showToast({ + title: res.data.msg, + icon: "success", + duration: 2000 + }) + } + }) + }, + onScrollToLower() { + // 更改页面 + this.setData({ + page: this.data.page += 1 + }) + this.http(this.data.page) } }) \ No newline at end of file diff --git a/app/pages/index/index.json b/app/pages/index/index.json index fa29c04..614852e 100644 --- a/app/pages/index/index.json +++ b/app/pages/index/index.json @@ -4,7 +4,8 @@ "van-search": "@vant/weapp/search/index", "van-grid": "@vant/weapp/grid/index", "van-grid-item": "@vant/weapp/grid-item/index", - "goods-list":"/components/goods-list/goods-list" + "goods-list":"/components/goods-list/goods-list", + "back-to-top":"/components/back-to-top/back-to-top" } - + } \ No newline at end of file diff --git a/app/pages/index/index.wxml b/app/pages/index/index.wxml index bad0cfc..c9aa913 100644 --- a/app/pages/index/index.wxml +++ b/app/pages/index/index.wxml @@ -1,4 +1,7 @@ + + + + + 已经到底啦,往上看看吧 + + + + diff --git a/app/pages/index/index.wxss b/app/pages/index/index.wxss index f485303..83765b2 100644 --- a/app/pages/index/index.wxss +++ b/app/pages/index/index.wxss @@ -19,13 +19,7 @@ display: flex; flex-direction: column; } -/* .head_c{ - position: relative; - bottom: 10px; - display: flex; - align-items:center; - justify-content:space-between; -} */ + .van-search{ width: 360px; } @@ -46,4 +40,4 @@ right: 85px; margin-top: 60px; padding: 10px; overflow-y: auto; -} \ No newline at end of file +} diff --git a/app/pages/search/search.js b/app/pages/search/search.js index dfb045f..a65e11e 100644 --- a/app/pages/search/search.js +++ b/app/pages/search/search.js @@ -1,3 +1,6 @@ +const { + getGoods +} = require("../../api/index.js") Page({ /** @@ -5,6 +8,7 @@ Page({ */ data: { searchText: "" + }, /** diff --git a/app/pages/search/search.json b/app/pages/search/search.json index b640ba8..0741097 100644 --- a/app/pages/search/search.json +++ b/app/pages/search/search.json @@ -1,6 +1,7 @@ { "usingComponents": { "van-search": "@vant/weapp/search/index", - "van-button": "@vant/weapp/button/index" + "van-button": "@vant/weapp/button/index", + "goods-list":"/components/goods-list/goods-list" } } \ No newline at end of file diff --git a/app/pages/search/search.wxml b/app/pages/search/search.wxml index 18b1d04..3168361 100644 --- a/app/pages/search/search.wxml +++ b/app/pages/search/search.wxml @@ -9,4 +9,6 @@ 搜索 + + diff --git a/app/utils/request.js b/app/utils/request.js index dd34843..46af07b 100644 --- a/app/utils/request.js +++ b/app/utils/request.js @@ -9,13 +9,13 @@ function request(url, method, data) { mask: true }); - const promise = new Promise((resolve, reject) => { // 修正:Pomise → Promise + const promise = new Promise((resolve, reject) => { // 修正:Pomise → Promise wx.request({ url: url, - method: method.toUpperCase(), // 确保 method 是大写(GET/POST) + method: method.toUpperCase(), // 确保 method 是大写(GET/POST) data: data, header: { - 'Content-Type': 'application/x-www-form-urlencoded' // 默认表单格式 + 'Content-Type': 'application/x-www-form-urlencoded' // 默认表单格式 }, success(res) { resolve(res);