├── .gitignore
├── README.md
├── cloudfunctions
└── login
│ ├── index.js
│ └── package.json
├── miniprogram
├── app.js
├── app.json
├── app.wxss
├── images
│ ├── banner.jpg
│ ├── banner5.jpg
│ ├── bg.jpg
│ ├── chuangyicai.jpg
│ ├── collect.png
│ ├── hongbei.jpg
│ ├── jiachangcai.jpg
│ ├── kuaishouc.jpg
│ ├── liangcai.jpg
│ ├── like.jpg
│ ├── like
│ │ ├── bugai.jpg
│ │ ├── hugan.jpg
│ │ ├── jianfei.jpg
│ │ ├── paidu.jpg
│ │ ├── qingfei.jpg
│ │ └── yangwei.jpg
│ ├── loading
│ │ └── loading-bars.svg
│ ├── mianshi.jpg
│ ├── more.png
│ ├── nav
│ │ ├── index-active.png
│ │ ├── index.png
│ │ ├── menu-active.png
│ │ ├── menu.png
│ │ ├── menu1.png
│ │ ├── user-active.png
│ │ └── user.png
│ ├── search.png
│ ├── see.png
│ ├── share.png
│ ├── sucai.jpg
│ ├── tags.png
│ ├── wan.png
│ ├── wu.png
│ ├── xiawu.png
│ ├── ye.png
│ └── zao.png
├── pages
│ ├── chooseLib
│ │ ├── chooseLib.js
│ │ ├── chooseLib.json
│ │ ├── chooseLib.wxml
│ │ └── chooseLib.wxss
│ ├── detail
│ │ ├── detail.js
│ │ ├── detail.json
│ │ ├── detail.wxml
│ │ └── detail.wxss
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ ├── index.wxss
│ │ └── user-unlogin.png
│ ├── list
│ │ ├── list.js
│ │ ├── list.json
│ │ ├── list.wxml
│ │ └── list.wxss
│ ├── menu
│ │ ├── menu.js
│ │ ├── menu.json
│ │ ├── menu.wxml
│ │ └── menu.wxss
│ ├── search
│ │ ├── search.js
│ │ ├── search.json
│ │ ├── search.wxml
│ │ └── search.wxss
│ └── user
│ │ ├── user-unlogin.png
│ │ ├── user.js
│ │ ├── user.json
│ │ ├── user.wxml
│ │ └── user.wxss
├── style
│ └── guide.wxss
└── utils
│ ├── ald-stat-conf.js
│ └── ald-stat.js
└── project.config.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows
2 | [Dd]esktop.ini
3 | Thumbs.db
4 | $RECYCLE.BIN/
5 |
6 | # macOS
7 | .DS_Store
8 | .fseventsd
9 | .Spotlight-V100
10 | .TemporaryItems
11 | .Trashes
12 |
13 | # Node.js
14 | node_modules/
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # micro_app_food
2 | 微信小程序-菜谱
3 |
--------------------------------------------------------------------------------
/cloudfunctions/login/index.js:
--------------------------------------------------------------------------------
1 | // 云函数入口文件
2 | const cloud = require('wx-server-sdk')
3 |
4 | cloud.init()
5 |
6 | // 云函数入口函数
7 | exports.main = async (event, context) => {
8 | const wxContext = cloud.getWXContext()
9 |
10 | return {
11 | event,
12 | openid: wxContext.OPENID,
13 | appid: wxContext.APPID,
14 | unionid: wxContext.UNIONID,
15 | }
16 | }
--------------------------------------------------------------------------------
/cloudfunctions/login/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "login",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "wx-server-sdk": "latest"
13 | }
14 | }
--------------------------------------------------------------------------------
/miniprogram/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | // const ald = require('./utils/ald-stat.js')
3 |
4 | App({
5 | onLaunch: function () {
6 |
7 | if (!wx.cloud) {
8 | console.error('请使用 2.2.3 或以上的基础库以使用云能力')
9 | } else {
10 | wx.cloud.init({
11 | env: "recipes-17ddbf",//这个就是环境id
12 | traceUser: true,
13 | })
14 | }
15 |
16 | this.globalData = {}
17 | }
18 | })
19 |
--------------------------------------------------------------------------------
/miniprogram/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/index/index",
4 | "pages/menu/menu",
5 | "pages/user/user",
6 | "pages/detail/detail",
7 | "pages/chooseLib/chooseLib",
8 | "pages/search/search",
9 | "pages/list/list"
10 | ],
11 | "window": {
12 | "backgroundColor": "#F6F6F6",
13 | "backgroundTextStyle": "light",
14 | "navigationBarBackgroundColor": "#F6F6F6",
15 | "navigationBarTitleText": "小菜一碟",
16 | "navigationBarTextStyle": "black"
17 | },
18 | "tabBar": {
19 | "color": "#6e6d6b",
20 | "selectedColor": "#FF6262",
21 | "borderStyle": "white",
22 | "backgroundColor": "#fff",
23 | "box-shadow": "0 0 6px 0",
24 | "list": [
25 | {
26 | "pagePath": "pages/index/index",
27 | "iconPath": "/images/nav/index.png",
28 | "selectedIconPath": "/images/nav/index-active.png",
29 | "text": "首页"
30 | },
31 | {
32 | "pagePath": "pages/menu/menu",
33 | "iconPath": "/images/nav/menu.png",
34 | "selectedIconPath": "/images/nav/menu-active.png",
35 | "text": "菜单"
36 | },
37 | {
38 | "pagePath": "pages/user/user",
39 | "iconPath": "/images/nav/user.png",
40 | "selectedIconPath": "/images/nav/user-active.png",
41 | "text": "我的"
42 | }
43 | ]
44 | }
45 | }
--------------------------------------------------------------------------------
/miniprogram/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | page {
3 | height: 100%;
4 | }
--------------------------------------------------------------------------------
/miniprogram/images/banner.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/banner.jpg
--------------------------------------------------------------------------------
/miniprogram/images/banner5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/banner5.jpg
--------------------------------------------------------------------------------
/miniprogram/images/bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/bg.jpg
--------------------------------------------------------------------------------
/miniprogram/images/chuangyicai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/chuangyicai.jpg
--------------------------------------------------------------------------------
/miniprogram/images/collect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/collect.png
--------------------------------------------------------------------------------
/miniprogram/images/hongbei.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/hongbei.jpg
--------------------------------------------------------------------------------
/miniprogram/images/jiachangcai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/jiachangcai.jpg
--------------------------------------------------------------------------------
/miniprogram/images/kuaishouc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/kuaishouc.jpg
--------------------------------------------------------------------------------
/miniprogram/images/liangcai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/liangcai.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/bugai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/bugai.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/hugan.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/hugan.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/jianfei.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/jianfei.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/paidu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/paidu.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/qingfei.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/qingfei.jpg
--------------------------------------------------------------------------------
/miniprogram/images/like/yangwei.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/like/yangwei.jpg
--------------------------------------------------------------------------------
/miniprogram/images/loading/loading-bars.svg:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/miniprogram/images/mianshi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/mianshi.jpg
--------------------------------------------------------------------------------
/miniprogram/images/more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/more.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/index-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/index-active.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/index.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/menu-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/menu-active.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/menu.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/menu1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/menu1.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/user-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/user-active.png
--------------------------------------------------------------------------------
/miniprogram/images/nav/user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/nav/user.png
--------------------------------------------------------------------------------
/miniprogram/images/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/search.png
--------------------------------------------------------------------------------
/miniprogram/images/see.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/see.png
--------------------------------------------------------------------------------
/miniprogram/images/share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/share.png
--------------------------------------------------------------------------------
/miniprogram/images/sucai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/sucai.jpg
--------------------------------------------------------------------------------
/miniprogram/images/tags.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/tags.png
--------------------------------------------------------------------------------
/miniprogram/images/wan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/wan.png
--------------------------------------------------------------------------------
/miniprogram/images/wu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/wu.png
--------------------------------------------------------------------------------
/miniprogram/images/xiawu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/xiawu.png
--------------------------------------------------------------------------------
/miniprogram/images/ye.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/ye.png
--------------------------------------------------------------------------------
/miniprogram/images/zao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/images/zao.png
--------------------------------------------------------------------------------
/miniprogram/pages/chooseLib/chooseLib.js:
--------------------------------------------------------------------------------
1 | // pages/chooseLib/chooseLib.js
2 | Page({
3 |
4 | /**
5 | * 页面的初始数据
6 | */
7 | data: {
8 |
9 | },
10 |
11 | /**
12 | * 生命周期函数--监听页面加载
13 | */
14 | onLoad: function (options) {
15 |
16 | },
17 |
18 | /**
19 | * 生命周期函数--监听页面初次渲染完成
20 | */
21 | onReady: function () {
22 |
23 | },
24 |
25 | /**
26 | * 生命周期函数--监听页面显示
27 | */
28 | onShow: function () {
29 |
30 | },
31 |
32 | /**
33 | * 生命周期函数--监听页面隐藏
34 | */
35 | onHide: function () {
36 |
37 | },
38 |
39 | /**
40 | * 生命周期函数--监听页面卸载
41 | */
42 | onUnload: function () {
43 |
44 | },
45 |
46 | /**
47 | * 页面相关事件处理函数--监听用户下拉动作
48 | */
49 | onPullDownRefresh: function () {
50 |
51 | },
52 |
53 | /**
54 | * 页面上拉触底事件的处理函数
55 | */
56 | onReachBottom: function () {
57 |
58 | },
59 |
60 | /**
61 | * 用户点击右上角分享
62 | */
63 | onShareAppMessage: function () {
64 |
65 | }
66 | })
--------------------------------------------------------------------------------
/miniprogram/pages/chooseLib/chooseLib.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "选择基础库"
3 | }
--------------------------------------------------------------------------------
/miniprogram/pages/chooseLib/chooseLib.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 初始化失败
7 |
8 |
9 | 请使用 2.2.3 或以上的基础库以使用云能力
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/miniprogram/pages/chooseLib/chooseLib.wxss:
--------------------------------------------------------------------------------
1 | /* pages/chooseLib/chooseLib.wxss */
2 |
3 | @import "../../style/guide.wxss";
4 |
5 | .black {
6 | color: black;
7 | }
--------------------------------------------------------------------------------
/miniprogram/pages/detail/detail.js:
--------------------------------------------------------------------------------
1 | // miniprogram/pages/detail/detail.js
2 | const app = getApp()
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | detail: {},
11 | openid: '',
12 | tags: [], // 标签
13 | ingredients: [], // 主料
14 | burden: [], // 辅料
15 | loading: true,
16 | logged: false,
17 | isExit: true, // 此菜品是否存在
18 | isCollect: true // 菜品是否已收藏
19 | },
20 |
21 | /**
22 | * 生命周期函数--监听页面加载
23 | */
24 | onLoad: function (options) {
25 | let isLogin = wx.getStorageSync('isLogin')
26 | this.loadDetail(options.id) // 加载详情
27 |
28 | wx.setStorageSync('shareId', options.id)
29 |
30 | console.log(options.id)
31 | console.log('用户是否授权:', isLogin)
32 | console.log('是否已有用户openId:', app.globalData.openid)
33 |
34 | this.setData({
35 | logged: isLogin ? true : false
36 | })
37 |
38 | // 是否存在用户的openId
39 | if (app.globalData.openid) {
40 | this.setData({
41 | openid: app.globalData.openid
42 | })
43 | }
44 |
45 | this.getcollect(options.id) // 获取收藏菜品,并判断是否已收藏
46 | },
47 |
48 | loadDetail(param) {
49 | let that = this
50 | wx.showLoading({
51 | title: '详情加载中...',
52 | })
53 |
54 | // 从云数据库读取列表
55 | const db = wx.cloud.database()
56 | const _ = db.command
57 | console.log(param)
58 | db.collection('foods').where({
59 | id: _.eq(param)
60 | }).get({
61 | success(res) {
62 | console.log('查询结果:', res.data)
63 | console.log(res.data.length)
64 | if (res.data.length) {
65 | console.log(12345)
66 | console.log(res.data[0])
67 | console.log(res.data[0].ingredients.split(',').join(':').split(';'))
68 | console.log(res.data[0].burden.split(',').join(':').split(';'))
69 | that.setData({
70 | detail: res.data[0],
71 | tags: res.data[0].category,
72 | ingredients: res.data[0].ingredients.split(',').join(':').split(';'),
73 | burden: res.data[0].burden.split(',').join(':').split(';')
74 | })
75 | console.log(111111)
76 | wx.setNavigationBarTitle({
77 | title: res.data[0].title
78 | })
79 | } else {
80 | console.log('该id为空')
81 | that.setData({
82 | isExit: false
83 | })
84 | }
85 | wx.hideLoading();
86 | },
87 | fail(res) {
88 | console.log('查询失败')
89 | }
90 | },
91 | console.log("this.data.detail.id"),
92 | console.log(this.data.detail.id)
93 | )
94 | },
95 |
96 | // 登录授权
97 | getUser(e) {
98 | console.log(e);
99 | wx.getUserInfo({
100 | success: (res) => {
101 | console.log(res)
102 | wx.setStorageSync('isLogin', 'isLogin')
103 | this.setData({
104 | logged: true
105 | })
106 | }
107 | })
108 | },
109 |
110 | // 授权后可以收藏
111 | bindCollect () {
112 | let that = this
113 | // 先检查是否以获取openId
114 | if (!this.data.openid) {
115 | wx.cloud.callFunction({
116 | name: 'login',
117 | data: {},
118 | success: res => {
119 | console.log('取到openId:', res.result)
120 | app.globalData.openid = res.result.openid
121 | that.setData({
122 | openid: res.result.openid
123 | })
124 |
125 | that.onCollect()
126 |
127 | wx.vibrateLong({
128 | success: res => {
129 | console.log('震动成功');
130 | },
131 | fail: (err) => {
132 | console.log('震动失败');
133 | }
134 | })
135 |
136 | wx.showToast({
137 | icon: '收藏',
138 | title: '收藏成功',
139 | })
140 | },
141 | fail: err => {
142 | wx.showToast({
143 | icon: 'none',
144 | title: '获取 openid 失败,请检查是否有部署 login 云函数',
145 | })
146 | console.log('[云函数] [login] 获取 openid 失败,请检查是否有部署云函数,错误信息:', err)
147 | }
148 | })
149 | } else {
150 | that.onCollect()
151 | wx.vibrateLong({
152 | success: res => {
153 | console.log('震动成功');
154 | },
155 | fail: (err) => {
156 | console.log('震动失败');
157 | }
158 | })
159 | if(that.data.isCollect) {
160 | wx.showToast({
161 | icon: '收藏',
162 | title: '收藏成功',
163 | })
164 | } else {
165 | wx.showToast({
166 | icon: '收藏',
167 | title: '已经取消收藏',
168 | })
169 | }
170 |
171 | }
172 | },
173 |
174 | // 收藏
175 | onCollect () {
176 | const db = wx.cloud.database()
177 | let that = this
178 |
179 | // 查看是否有收藏记录
180 | db.collection('collects').where({
181 | _openid: this.data.openid,
182 | _id: 'collect' + this.data.openid
183 | }).get({
184 | success: res => {
185 | console.log('[数据库] [查询记录] 成功: ', res)
186 | let like = that.data.detail // 需要收藏的菜品
187 | delete like._id
188 | delete like._openid
189 |
190 | if (!res.data.length) { // 如果从未收藏
191 | console.log(' 从未收藏')
192 | let detailArray = []
193 | detailArray.push(like)
194 | db.collection('collects').add({
195 | data: {
196 | _id: 'collect' + that.data.openid,
197 | description: 'like',
198 | collectList: detailArray
199 | }
200 | }).then(res => {
201 | console.log(res)
202 | })
203 | } else { // 如果已有收藏记录
204 | console.log('已有收藏记录')
205 | let detailArray = res.data[0].collectList
206 | let i = 0
207 | let flag = false
208 |
209 | // 判断已有的收藏记录中是否已经收藏了此菜品
210 | detailArray.map((val,index) => {
211 | if (val.id == like.id) {
212 | i = index
213 | flag = true
214 | }
215 | })
216 |
217 | that.setData({
218 | isCollect: flag
219 | })
220 |
221 | that.data.isCollect ? detailArray.splice(i,1) : detailArray.push(like)
222 |
223 | db.collection('collects').doc('collect' + that.data.openid).update({
224 | data: {
225 | collectList: detailArray
226 | }
227 | }).then((res)=>{
228 | console.log(res)
229 | })
230 | }
231 | },
232 | fail: err => {
233 | wx.showToast({
234 | icon: 'none',
235 | title: '查询记录失败'
236 | })
237 | console.error('[数据库] [查询记录] 失败:', err)
238 | }
239 | })
240 | },
241 |
242 | // 读取收藏列表
243 | getcollect(param) {
244 | let that = this
245 | const db = wx.cloud.database()
246 | // 查看是否有收藏记录
247 | db.collection('collects').where({
248 | _openid: this.data.openid,
249 | _id: 'collect' + this.data.openid
250 | }).get({
251 | success: res => {
252 | console.log('[数据库] [查询记录] 成功: ', res)
253 | if (!res.data.length) { // 如果从未收藏
254 | console.log(' 从未收藏')
255 | } else { // 如果已有收藏记录
256 | console.log(res.data)
257 | let detailArray = res.data[0].collectList
258 | let flag = false
259 | // 判断已有的收藏记录中是否已经收藏了此菜品
260 | detailArray.map((val, index) => {
261 | if (val.id == param) {
262 | flag = true
263 | }
264 | })
265 | console.log(flag)
266 | that.setData({
267 | isCollect: !flag
268 | })
269 | }
270 | },
271 | fail: err => {
272 | wx.showToast({
273 | icon: 'none',
274 | title: '查询记录失败'
275 | })
276 | console.error('[数据库] [查询记录] 失败:', err)
277 | }
278 | })
279 | },
280 |
281 | // onShareAppMessage(res) {
282 | // let id = wx.getStorageSync('shareId')
283 | // if (res.from === 'button') {
284 | // // 来自页面内转发按钮
285 | // console.log(res.target)
286 | // }
287 | // return {
288 | // title: '小菜一碟',
289 | // path: `pages/detail/detail?id=${id}`
290 | // }
291 | // },
292 |
293 | onBackhome () {
294 | wx.switchTab({
295 | url: `/pages/index/index`,
296 | })
297 | },
298 |
299 | /**
300 | * 生命周期函数--监听页面初次渲染完成
301 | */
302 | onReady: function () {
303 |
304 | },
305 |
306 | /**
307 | * 生命周期函数--监听页面显示
308 | */
309 | onShow: function () {
310 |
311 | },
312 |
313 | /**
314 | * 生命周期函数--监听页面隐藏
315 | */
316 | onHide: function () {
317 |
318 | },
319 |
320 | /**
321 | * 生命周期函数--监听页面卸载
322 | */
323 | onUnload: function () {
324 |
325 | },
326 |
327 | /**
328 | * 页面相关事件处理函数--监听用户下拉动作
329 | */
330 | onPullDownRefresh: function () {
331 |
332 | },
333 |
334 | /**
335 | * 页面上拉触底事件的处理函数
336 | */
337 | onReachBottom: function () {
338 |
339 | },
340 |
341 | /**
342 | * 用户点击右上角分享
343 | */
344 | onShareAppMessage: function () {
345 | let id = wx.getStorageSync('shareId')
346 |
347 | return {
348 | title: '小菜一碟',
349 | path: `pages/detail/detail?id=${id}`
350 | }
351 | }
352 | })
--------------------------------------------------------------------------------
/miniprogram/pages/detail/detail.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {}
3 | }
--------------------------------------------------------------------------------
/miniprogram/pages/detail/detail.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | {{detail.title}}
8 | {{detail.count}} 人浏览
9 |
10 | {{item}}
11 |
12 |
13 | {{detail.intro}}
14 |
15 |
16 |
17 | 主料
18 | {{item}}
19 |
20 |
21 | 辅料
22 | {{item}}
23 |
24 |
25 | 步骤
26 |
27 | 第{{index + 1}}步
28 |
29 | {{item.step}}
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | 分享
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | 收藏
56 | 已收藏
57 |
58 |
59 |
60 | --- 未找到您搜索的菜品 ---
61 |
--------------------------------------------------------------------------------
/miniprogram/pages/detail/detail.wxss:
--------------------------------------------------------------------------------
1 | /* miniprogram/pages/detail/detail.wxss */
2 | page {
3 | background: #e7e8e7;
4 | }
5 | .detail {
6 | font-size: 28rpx;
7 | }
8 | .detail .banner {
9 | height: 500rpx;
10 | overflow: hidden;
11 | }
12 | .detail .banner image {
13 | width: 100%;
14 | height: 100%;
15 | }
16 | .title {
17 | background: #fff;
18 | text-align: center;
19 | padding: 40rpx 30rpx;
20 | }
21 |
22 | .title>text:nth-child(1) {
23 | font-size: 34rpx;
24 | margin-bottom: 20rpx;
25 | display: block;
26 | color: #444;
27 | }
28 | .title .tags text {
29 | display: inline-block;
30 | border: 1px solid #ddd;
31 | color: #777;
32 | margin: 10rpx;
33 | padding: 4rpx 20rpx;
34 | border-radius: 30rpx;
35 | font-size: 24rpx;
36 | }
37 | .title .see {
38 | font-size: 24rpx;
39 | color: #777;
40 | padding-bottom: 20rpx;
41 | display: flex;
42 | align-items: center;
43 | justify-content: center;
44 | }
45 | .title .see image {
46 | width: 30rpx;
47 | margin-right: 10rpx;
48 | }
49 | .title .intro {
50 | font-size: 24rpx;
51 | color: #666;
52 | padding-top: 30rpx;
53 | }
54 |
55 | .ingredients {
56 | margin-top: 20rpx;
57 | padding: 20rpx 30rpx;
58 | display: flex;
59 | flex-direction: column;
60 | background: #fff;
61 | }
62 | .ingredients text:nth-child(1) {
63 | font-size: 36rpx;
64 | font-weight: bold;
65 | text-align: center;
66 | padding: 20rpx;
67 | }
68 |
69 | .ingredients text:not(:first-child) {
70 | font-size: 28rpx;
71 | padding: 10rpx 0;
72 | color: #666;
73 | }
74 |
75 | .steps {
76 | margin-top: 20rpx;
77 | padding: 20rpx 30rpx;
78 | background: #fff;
79 | }
80 | .steps .top {
81 | font-size: 36rpx;
82 | font-weight: bold;
83 | text-align: center;
84 | display: block;
85 | padding: 20rpx;
86 | }
87 |
88 | .steps .item {
89 | padding: 30rpx 0;
90 | text-align: center;
91 | }
92 | .steps .item text {
93 | font-size: 32rpx;
94 | color: #FF6262;
95 | padding: 0 20rpx;
96 | margin-bottom: 20rpx;
97 | border-left: 8rpx solid #FF6262;
98 | display: block;
99 | text-align: left;
100 | }
101 |
102 | .steps .item view {
103 | font-size: 28rpx;
104 | color: #444;
105 | padding: 20rpx 0;
106 | }
107 |
108 | .collect {
109 | height: 120rpx;
110 | width: 120rpx;
111 | position: fixed;
112 | bottom: 30rpx;
113 | right: 30rpx;
114 | display: flex;
115 | flex-direction: column;
116 | align-items: center;
117 | justify-content: center;
118 | font-size: 24rpx;
119 | background: rgba(0, 0, 0, .6);
120 | border-radius: 50%;
121 | z-index: 10;
122 | }
123 |
124 | .collect image {
125 | height: 50rpx;
126 | width: 50rpx;
127 | }
128 | .collect text {
129 | color: #fff;
130 | }
131 |
132 | .collect button {
133 | position: absolute;
134 | height: 100%;
135 | width: 100%;
136 | opacity: 0.1;
137 | }
138 |
139 |
140 | .share {
141 | height: 120rpx;
142 | width: 120rpx;
143 | position: fixed;
144 | bottom: 170rpx;
145 | right: 30rpx;
146 | display: flex;
147 | flex-direction: column;
148 | align-items: center;
149 | justify-content: center;
150 | font-size: 24rpx;
151 | background: rgba(0, 0, 0, .6);
152 | border-radius: 50%;
153 | z-index: 10;
154 | }
155 | .share image {
156 | height: 70rpx;
157 | width: 70rpx;
158 | }
159 | .share text {
160 | color: #fff;
161 | }
162 |
163 | .share button {
164 | position: absolute;
165 | height: 100%;
166 | width: 100%;
167 | opacity: 0.1;
168 | z-index: 99;
169 | }
170 |
171 | .backhome {
172 | height: 100rpx;
173 | width: 100rpx;
174 | position: fixed;
175 | top: 10rpx;
176 | right: 20rpx;
177 | display: flex;
178 | flex-direction: column;
179 | align-items: center;
180 | justify-content: center;
181 | font-size: 24rpx;
182 | background: rgba(255, 255, 255, .4);
183 | border-radius: 50%;
184 | z-index: 10;
185 | }
186 | .backhome image {
187 | height: 60rpx;
188 | width: 60rpx;
189 | }
190 | .backhome text {
191 | color: #fff;
192 | }
193 |
194 |
195 |
--------------------------------------------------------------------------------
/miniprogram/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | const app = getApp()
3 |
4 | Page({
5 | data: {
6 | imgUrls: [
7 | {
8 | id: 10222,
9 | url: '/images/banner5.jpg'
10 | }, {
11 | id: 1,
12 | url: '/images/banner.jpg'
13 | }
14 | ],
15 | indicatorDots: true,
16 | autoplay: true,
17 | indicatorColor: '#fedb00',
18 | interval: 2000,
19 | duration: 400,
20 | activeCategoryId: 1,
21 | category: [{
22 | id: "37",
23 | parentId: "1005",
24 | img: "/images/wu.png",
25 | name: '早餐'
26 | },
27 | {
28 | id: "38",
29 | parentId: "1005",
30 | img: "/images/zao.png",
31 | name: '午餐'
32 | },
33 | {
34 | id: "39",
35 | parentId: "1005",
36 | img: "/images/xiawu.png",
37 | name: '下午茶'
38 | },
39 | {
40 | id: "40",
41 | parentId: "1005",
42 | img: "/images/wan.png",
43 | name: '晚餐'
44 | },
45 | {
46 | id: "41",
47 | parentId: "1005",
48 | img: "/images/ye.png",
49 | name: '夜宵'
50 | }
51 | ],
52 | scroll: [{
53 | id: 1,
54 | parentId: "10001",
55 | img: "/images/jiachangcai.jpg",
56 | name: '家常菜'
57 | },
58 | {
59 | id: 2,
60 | parentId: "10001",
61 | img: "/images/kuaishouc.jpg",
62 | name: '快手菜'
63 | },
64 | {
65 | id: 3,
66 | parentId: "10001",
67 | img: "/images/chuangyicai.jpg",
68 | name: '创意菜'
69 | },
70 | {
71 | id: 4,
72 | parentId: "10001",
73 | img: "/images/sucai.jpg",
74 | name: '素菜'
75 | },
76 | {
77 | id: 5,
78 | parentId: "10001",
79 | img: "/images/liangcai.jpg",
80 | name: '凉菜'
81 | }
82 | ],
83 | list: [{
84 | id: 31,
85 | parentId: "10004",
86 | img: "/images/like/yangwei.jpg",
87 | name: '养胃',
88 | detail: {
89 | banner: '',
90 | title: ''
91 | }
92 | }, {
93 | id: 35,
94 | parentId: "10004",
95 | img: "/images/like/bugai.jpg",
96 | name: '美容',
97 | detail: {
98 | banner: '',
99 | title: ''
100 | }
101 | }, {
102 | id: 33,
103 | parentId: "10004",
104 | img: "/images/like/paidu.jpg",
105 | name: '明目',
106 | detail: {
107 | banner: '',
108 | title: ''
109 | }
110 | }, {
111 | id: 28,
112 | parentId: "10004",
113 | img: "/images/like/qingfei.jpg",
114 | name: '清热去火',
115 | detail: {
116 | banner: '',
117 | title: ''
118 | }
119 | }, {
120 | id: 29,
121 | parentId: "10004",
122 | img: "/images/like/hugan.jpg",
123 | name: '增肥',
124 | detail: {
125 | banner: '',
126 | title: ''
127 | }
128 | }, {
129 | id: 30,
130 | parentId: "10004",
131 | img: "/images/like/jianfei.jpg",
132 | name: '减肥',
133 | detail: {
134 | banner: '',
135 | title: ''
136 | }
137 | }],
138 | avatarUrl: './user-unlogin.png',
139 | userInfo: {},
140 | logged: false,
141 | takeSession: false,
142 | requestResult: ''
143 | },
144 |
145 | onLoad: function() {
146 | if (!wx.cloud) {
147 | wx.redirectTo({
148 | url: '../chooseLib/chooseLib',
149 | })
150 | return
151 | }
152 |
153 | // 获取用户信息
154 | wx.getSetting({
155 | success: res => {
156 | if (res.authSetting['scope.userInfo']) {
157 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
158 | wx.getUserInfo({
159 | success: res => {
160 | this.setData({
161 | avatarUrl: res.userInfo.avatarUrl,
162 | userInfo: res.userInfo
163 | })
164 | }
165 | })
166 | }
167 | }
168 | })
169 |
170 | // 获取用户openId
171 | this.onGetOpenid()
172 | },
173 |
174 | goSearch(e) {
175 | wx.navigateTo({
176 | url: `/pages/search/search`,
177 | })
178 | },
179 |
180 | goDetail(e) {
181 | wx.navigateTo({
182 | url: `/pages/detail/detail?id=${e.currentTarget.dataset.id}`,
183 | })
184 | },
185 |
186 | goList(e) {
187 | console.log(e)
188 | wx.navigateTo({
189 | url: `/pages/list/list?content=${e.currentTarget.dataset.content}&tags=${e.currentTarget.dataset.tags}`,
190 | })
191 | },
192 |
193 | goMenu(e) {
194 | wx.switchTab({
195 | url: `/pages/menu/menu`,
196 | })
197 | },
198 |
199 | onGetUserInfo: function(e) {
200 | if (!this.logged && e.detail.userInfo) {
201 | this.setData({
202 | logged: true,
203 | avatarUrl: e.detail.userInfo.avatarUrl,
204 | userInfo: e.detail.userInfo
205 | })
206 | }
207 | },
208 |
209 | onGetOpenid: function() {
210 | // 调用云函数
211 | wx.cloud.callFunction({
212 | name: 'login',
213 | data: {},
214 | success: res => {
215 | console.log('[云函数] [login] user openid: ', res.result.openid)
216 | app.globalData.openid = res.result.openid
217 | },
218 | fail: err => {
219 | console.error('[云函数] [login] 调用失败', err)
220 | wx.showToast({
221 | icon: 'none',
222 | title: '获取 openid 失败,请检查是否有部署 login 云函数',
223 | })
224 | }
225 | })
226 | },
227 |
228 | // 上传图片
229 | doUpload: function() {
230 | // 选择图片
231 | wx.chooseImage({
232 | count: 1,
233 | sizeType: ['compressed'],
234 | sourceType: ['album', 'camera'],
235 | success: function(res) {
236 |
237 | wx.showLoading({
238 | title: '上传中',
239 | })
240 |
241 | const filePath = res.tempFilePaths[0]
242 |
243 | // 上传图片
244 | const cloudPath = 'my-image' + filePath.match(/\.[^.]+?$/)[0]
245 | wx.cloud.uploadFile({
246 | cloudPath,
247 | filePath,
248 | success: res => {
249 | console.log('[上传文件] 成功:', res)
250 |
251 | app.globalData.fileID = res.fileID
252 | app.globalData.cloudPath = cloudPath
253 | app.globalData.imagePath = filePath
254 |
255 | wx.navigateTo({
256 | url: '../storageConsole/storageConsole'
257 | })
258 | },
259 | fail: e => {
260 | console.error('[上传文件] 失败:', e)
261 | wx.showToast({
262 | icon: 'none',
263 | title: '上传失败',
264 | })
265 | },
266 | complete: () => {
267 | wx.hideLoading()
268 | }
269 | })
270 |
271 | },
272 | fail: e => {
273 | console.error(e)
274 | }
275 | })
276 | },
277 |
278 | onShareAppMessage(res) {
279 | return {
280 | title: '小菜一碟',
281 | path: `pages/index/index`
282 | }
283 | },
284 |
285 | })
--------------------------------------------------------------------------------
/miniprogram/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {}
3 | }
--------------------------------------------------------------------------------
/miniprogram/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | {{item.name}}
22 |
23 |
24 |
25 |
26 | 热门标签
27 | 查看更多 >>
28 |
29 |
30 |
31 |
32 | {{item.name}}
33 |
34 |
35 |
36 |
37 |
38 | 猜你喜欢
39 | 您喜欢的美食
40 |
41 |
42 |
43 |
44 |
45 | {{item.name}}
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/miniprogram/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 |
3 | page {
4 | background: #f6f6f6;
5 | display: flex;
6 | flex-direction: column;
7 | justify-content: flex-start;
8 | }
9 |
10 | .userinfo, .uploader, .tunnel {
11 | margin-top: 40rpx;
12 | height: 140rpx;
13 | width: 100%;
14 | background: #fff;
15 | border: 1px solid rgba(0, 0, 0, 0.1);
16 | border-left: none;
17 | border-right: none;
18 | display: flex;
19 | flex-direction: row;
20 | align-items: center;
21 | transition: all 300ms ease;
22 | }
23 |
24 | .userinfo-avatar {
25 | width: 100rpx;
26 | height: 100rpx;
27 | margin: 20rpx;
28 | border-radius: 50%;
29 | background-size: cover;
30 | background-color: white;
31 | }
32 |
33 | .userinfo-avatar:after {
34 | border: none;
35 | }
36 |
37 | .userinfo-nickname {
38 | font-size: 32rpx;
39 | color: #007aff;
40 | background-color: white;
41 | background-size: cover;
42 | }
43 |
44 | .userinfo-nickname::after {
45 | border: none;
46 | }
47 |
48 | .uploader, .tunnel {
49 | height: auto;
50 | padding: 0 0 0 40rpx;
51 | flex-direction: column;
52 | align-items: flex-start;
53 | box-sizing: border-box;
54 | }
55 |
56 | .uploader-text, .tunnel-text {
57 | width: 100%;
58 | line-height: 52px;
59 | font-size: 34rpx;
60 | color: #007aff;
61 | }
62 |
63 | .uploader-container {
64 | width: 100%;
65 | height: 400rpx;
66 | padding: 20rpx 20rpx 20rpx 0;
67 | display: flex;
68 | align-content: center;
69 | justify-content: center;
70 | box-sizing: border-box;
71 | border-top: 1px solid rgba(0, 0, 0, 0.1);
72 | }
73 |
74 | .uploader-image {
75 | width: 100%;
76 | height: 360rpx;
77 | }
78 |
79 | .tunnel {
80 | padding: 0 0 0 40rpx;
81 | }
82 |
83 | .tunnel-text {
84 | position: relative;
85 | color: #222;
86 | display: flex;
87 | flex-direction: row;
88 | align-content: center;
89 | justify-content: space-between;
90 | box-sizing: border-box;
91 | border-top: 1px solid rgba(0, 0, 0, 0.1);
92 | }
93 |
94 | .tunnel-text:first-child {
95 | border-top: none;
96 | }
97 |
98 | .tunnel-switch {
99 | position: absolute;
100 | right: 20rpx;
101 | top: -2rpx;
102 | }
103 |
104 | .disable {
105 | color: #888;
106 | }
107 |
108 | .service {
109 | position: fixed;
110 | right: 40rpx;
111 | bottom: 40rpx;
112 | width: 140rpx;
113 | height: 140rpx;
114 | border-radius: 50%;
115 | background: linear-gradient(#007aff, #0063ce);
116 | box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
117 | display: flex;
118 | align-content: center;
119 | justify-content: center;
120 | transition: all 300ms ease;
121 | }
122 |
123 | .service-button {
124 | position: absolute;
125 | top: 40rpx;
126 | }
127 |
128 | .service:active {
129 | box-shadow: none;
130 | }
131 |
132 | .request-text {
133 | padding: 20rpx 0;
134 | font-size: 24rpx;
135 | line-height: 36rpx;
136 | word-break: break-all;
137 | }
138 |
139 | .top {
140 | background: #FF6262;
141 | height: 300rpx;
142 | position: relative;
143 | padding: 10rpx 20rpx;
144 | }
145 |
146 | .top .user {
147 | width: 50rpx;
148 | height: 60rpx;
149 | position: absolute;
150 | top: 10rpx;
151 | right: 10rpx;
152 | }
153 |
154 | .top text {
155 | display: block;
156 | text-align: center;
157 | height: 40rpx;
158 | font-style: oblique;
159 | font-weight: bold;
160 | letter-spacing: 2rpx;
161 | }
162 |
163 | .top .search {
164 | border: 1px solid fff;
165 | box-sizing: border-box;
166 | border-radius: 30rpx;
167 | height: 60rpx;
168 | padding: 0 20rpx;
169 | background: #fff;
170 | display: flex;
171 | align-items: center;
172 | justify-content: flex-start;
173 | font-size: 28rpx;
174 |
175 | }
176 | .top .search image {
177 | height: 36rpx;
178 | width: 36rpx;
179 | margin-right: 20rpx;
180 | }
181 | .top input {
182 | border: none;
183 | flex: 1;
184 | }
185 |
186 | swiper {
187 | height: 240rpx;
188 | margin: 0 30rpx;
189 | position: relative;
190 | transform: translate(0, -160rpx);
191 | margin-bottom: -160rpx;
192 | overflow: hidden;
193 | border-radius: 20rpx;
194 | border: 1px solid #fae4e6;
195 | background: #FF6262;
196 | }
197 |
198 | .slide-image {
199 | width: 100%;
200 | height: 240rpx;
201 | border-radius: 20rpx;
202 | }
203 |
204 | .category {
205 | width: 100%;
206 | padding: 36rpx 0;
207 | display: flex;
208 | align-items: center;
209 | justify-content: space-around;
210 | }
211 |
212 | .category view {
213 | display: flex;
214 | flex-direction: column;
215 | align-items: center;
216 | justify-content: space-around;
217 | padding:10rpx 24rpx;
218 | }
219 |
220 | .category image {
221 | height: 60rpx;
222 | width: 60rpx;
223 | }
224 |
225 | .category text {
226 | font-size: 28rpx;
227 | color: #666;
228 | }
229 |
230 | /* 热门标签 */
231 |
232 | .place {
233 | padding: 12rpx 0;
234 | width: 100%;
235 | height: 280rpx;
236 | overflow: hidden;
237 | }
238 |
239 | .block .title {
240 | display: flex;
241 | align-items: center;
242 | justify-content: space-between;
243 | padding: 18rpx;
244 | }
245 |
246 | .block .title text {
247 | font-size: 40rpx;
248 | font-weight: bold;
249 | }
250 |
251 | .block .title .more {
252 | font-size: 28rpx;
253 | font-weight: 400;
254 | color: #666;
255 | }
256 |
257 | .scroll-view {
258 | width: 100%;
259 | height: 240rpx;
260 | white-space: nowrap; /* 规定段落中的文本不进行换行 */
261 | }
262 |
263 | .scroll-view view {
264 | width: 180rpx;
265 | height: 180rpx;
266 | padding: 0 16rpx;
267 | box-sizing: content-box;
268 | display: inline-block; /* 设置行内块元素 */
269 | position: relative;
270 | }
271 |
272 | .scroll-view view image {
273 | width: 180rpx;
274 | height: 180rpx;
275 | border-radius: 10rpx;
276 | opacity: 0.9;
277 | }
278 |
279 | .scroll-view view text {
280 | font-size: 24rpx;
281 | font-weight: bold;
282 | color: #fff;
283 | position: absolute;
284 | bottom: 10rpx;
285 | left: 30rpx;
286 | padding: 2rpx 20rpx;
287 | background: rgba(255, 96, 96, .6);
288 | border-radius: 10rpx;
289 | }
290 |
291 | /* 猜你喜欢 */
292 |
293 | .like {
294 | height: auto;
295 | padding: 12rpx 0;
296 | }
297 |
298 | .like .list .box {
299 | display: inline-block;
300 | box-sizing: border-box;
301 | width: 50%;
302 | padding: 10rpx;
303 | text-align: center;
304 | }
305 |
306 | .like .list view image {
307 | height: 360rpx;
308 | width: 300rpx;
309 | border-radius: 16rpx;
310 | /* box-shadow: 0 0 4rpx #c97276; */
311 | }
312 |
313 | .like .list .tip text {
314 | font-size: 28rpx;
315 | color: #444;
316 | }
317 |
318 | .like .list .tip .price {
319 | font-size: 24rpx;
320 | color: red;
321 | }
322 |
323 | .type-navbar-item text {
324 | border-bottom: 4rpx solid #fff;
325 | }
326 |
327 | .type-item-on text {
328 | border-bottom: 4rpx solid #c97276;
329 | }
330 |
--------------------------------------------------------------------------------
/miniprogram/pages/index/user-unlogin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/pages/index/user-unlogin.png
--------------------------------------------------------------------------------
/miniprogram/pages/list/list.js:
--------------------------------------------------------------------------------
1 | // miniprogram/pages/list/list.js
2 | Page({
3 |
4 | /**
5 | * 页面的初始数据
6 | */
7 | data: {
8 | list: [],
9 | index: 0, // 页码起始下标
10 | num: 10, // 每页展示个数
11 | searchContent: '', // 搜索内容或者搜索标签id
12 | searchIsTags: false, // 是否搜索的是标签id
13 | loading: false, // 是否正在加载
14 | isOver: false, // 滑动到底
15 | noList: false // 搜索结果为空
16 | },
17 |
18 | /**
19 | * 生命周期函数--监听页面加载
20 | */
21 | onLoad: function (options) {
22 | wx.setNavigationBarTitle({
23 | title: options.content //页面标题为路由参数
24 | })
25 |
26 | console.log(options)
27 |
28 | if (options.tags) {
29 | this.data.searchContent = options.content
30 | this.data.searchIsTags = true
31 | this.loadList(options.content)
32 | } else {
33 | this.data.searchContent = options.content
34 | this.loadList(options.content)
35 | }
36 |
37 | },
38 |
39 | goDetail (e) {
40 | console.log('detail');
41 | console.log(e.currentTarget.dataset.id);
42 | wx.navigateTo({
43 | url: `/pages/detail/detail?id=${e.currentTarget.dataset.id}`,
44 | })
45 | },
46 |
47 | // 上拉加载
48 | lower() {
49 | console.log('lower');
50 | if (!this.data.loading) {
51 | if (this.data.searchIsTags) {
52 | this.loadList(this.data.searchContent)
53 | } else {
54 | this.loadList(this.data.searchContent)
55 | }
56 |
57 | }
58 | },
59 |
60 | // 加载列表
61 | loadList(content) {
62 | let that = this
63 | const db = wx.cloud.database()
64 | const _ = db.command
65 | if (!this.data.isOver) {
66 | let { list, index, num } = this.data;
67 | wx.showLoading({
68 | title: '正在加载...',
69 | mask: true
70 | });
71 | this.setData({
72 | loading: true
73 | });
74 |
75 | // 从云数据库读取列表
76 | const db = wx.cloud.database();
77 | const MAX_LIMIT = 8
78 | db.collection('foods').skip(index).limit(MAX_LIMIT).where({
79 | category: content
80 | }).get().then(res => {
81 | console.log(res);
82 | if (res.data.length){
83 | list.push(...res.data)
84 | this.setData({
85 | list,
86 | index: index + MAX_LIMIT,
87 | loading: false
88 | })
89 | console.log(list)
90 | } else {
91 | this.setData({
92 | loading: false,
93 | isOver: true
94 | })
95 | }
96 | wx.hideLoading()
97 |
98 | })
99 |
100 | }
101 | },
102 |
103 | /**
104 | * 生命周期函数--监听页面初次渲染完成
105 | */
106 | onReady: function () {
107 |
108 | },
109 |
110 | /**
111 | * 生命周期函数--监听页面显示
112 | */
113 | onShow: function () {
114 |
115 | },
116 |
117 | /**
118 | * 生命周期函数--监听页面隐藏
119 | */
120 | onHide: function () {
121 |
122 | },
123 |
124 | /**
125 | * 生命周期函数--监听页面卸载
126 | */
127 | onUnload: function () {
128 |
129 | },
130 |
131 | /**
132 | * 页面相关事件处理函数--监听用户下拉动作
133 | */
134 | onPullDownRefresh: function () {
135 |
136 | },
137 |
138 | /**
139 | * 页面上拉触底事件的处理函数
140 | */
141 | onReachBottom: function () {
142 |
143 | },
144 |
145 | /**
146 | * 用户点击右上角分享
147 | */
148 | onShareAppMessage: function () {
149 |
150 | }
151 | })
--------------------------------------------------------------------------------
/miniprogram/pages/list/list.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {}
3 | }
--------------------------------------------------------------------------------
/miniprogram/pages/list/list.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 | {{item.title}}
10 | 原料:{{item.ingredients}}
11 | 用料:{{item.burden}}
12 | {{item.count}} 人浏览
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | --- 我是有底线的 ---
21 |
22 |
23 | --- 未找到您搜索的菜品 ---
24 |
25 |
--------------------------------------------------------------------------------
/miniprogram/pages/list/list.wxss:
--------------------------------------------------------------------------------
1 | /* miniprogram/pages/list/list.wxss */
2 |
3 | .box {
4 | border: 1px solid #ddd;
5 | margin: 20rpx 30rpx 40rpx 30rpx;
6 | padding: 20rpx 30rpx 20rpx 270rpx;
7 | font-size: 28rpx;
8 | height: 200rpx;
9 | overflow: hidden;
10 | position: relative;
11 | border-radius: 10rpx;
12 | box-shadow: 1px 1px 6rpx #ccc;
13 | }
14 |
15 | .box image {
16 | height: 200rpx;
17 | width: 220rpx;
18 | position: absolute;
19 | top: 20rpx;
20 | left: 10rpx;
21 | border-radius: 10rpx;
22 | }
23 |
24 | .box view {
25 | padding-top: 0rpx;
26 | }
27 |
28 | .box view text {
29 | display: block;
30 | overflow: hidden;
31 | white-space: nowrap;
32 | text-overflow: ellipsis;
33 | padding-bottom: 10rpx;
34 | color: #555;
35 | font-size: 24rpx;
36 | }
37 | .box view text.title {
38 | color: #333;
39 | font-weight: 600;
40 | font-size: 30rpx;
41 | padding-bottom: 16rpx;
42 | }
43 | .box view text.see {
44 | color: #FF6262;
45 | padding-top: 10rpx;
46 | }
--------------------------------------------------------------------------------
/miniprogram/pages/menu/menu.js:
--------------------------------------------------------------------------------
1 | // miniprogram/pages/menu/menu.js
2 |
3 | Page({
4 |
5 | /**
6 | * 页面的初始数据
7 | */
8 | data: {
9 | list: []
10 | },
11 |
12 | /**
13 | * 生命周期函数--监听页面加载
14 | */
15 | onLoad: function (options) {
16 | this.loadList()
17 | },
18 |
19 | // 获取列表数据
20 | loadList() {
21 | let { list } = this.data;
22 | wx.showLoading({
23 | title: '正在加载...',
24 | mask: true
25 | });
26 | this.setData({
27 | loading: true
28 | });
29 |
30 | // 从云数据库读取列表
31 | const db = wx.cloud.database();
32 |
33 | db.collection('foods').doc('categorys').get().then(res => {
34 | console.log(res.data.category_list);
35 | list.push(...res.data.category_list)
36 | this.setData({
37 | list
38 | })
39 | console.log(list)
40 | wx.hideLoading()
41 | })
42 | },
43 |
44 | goList(e) {
45 | console.log(e)
46 | wx.navigateTo({
47 | url: `/pages/list/list?content=${e.currentTarget.dataset.content}&tags=${e.currentTarget.dataset.tags}`,
48 | })
49 | },
50 |
51 | /**
52 | * 生命周期函数--监听页面初次渲染完成
53 | */
54 | onReady: function () {
55 |
56 | },
57 |
58 | /**
59 | * 生命周期函数--监听页面显示
60 | */
61 | onShow: function () {
62 |
63 | },
64 |
65 | /**
66 | * 生命周期函数--监听页面隐藏
67 | */
68 | onHide: function () {
69 |
70 | },
71 |
72 | /**
73 | * 生命周期函数--监听页面卸载
74 | */
75 | onUnload: function () {
76 |
77 | },
78 |
79 | /**
80 | * 页面相关事件处理函数--监听用户下拉动作
81 | */
82 | onPullDownRefresh: function () {
83 |
84 | },
85 |
86 | /**
87 | * 页面上拉触底事件的处理函数
88 | */
89 | onReachBottom: function () {
90 |
91 | },
92 |
93 | /**
94 | * 用户点击右上角分享
95 | */
96 | onShareAppMessage: function () {
97 |
98 | }
99 | })
--------------------------------------------------------------------------------
/miniprogram/pages/menu/menu.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {},
3 | "navigationBarTitleText": "菜单"
4 | }
--------------------------------------------------------------------------------
/miniprogram/pages/menu/menu.wxml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/miniprogram/pages/menu/menu.wxss:
--------------------------------------------------------------------------------
1 | /* miniprogram/pages/menu/menu.wxss */
2 | .menu {
3 | padding: 20rpx;
4 | font-size: 28rpx;
5 | }
6 | .menu image {
7 | height: 40rpx;
8 | width: 40rpx;
9 | margin-right: 10rpx;
10 | }
11 | .menu .item {
12 | margin-bottom: 30rpx;
13 | }
14 | .menu .title {
15 | display: flex;
16 | align-items: center;
17 | justify-content: center;
18 | font-size: 34rpx;
19 | color: #555;
20 | }
21 | .menu .item .classic {
22 | display: flex;
23 | flex-wrap: wrap;
24 | padding: 20rpx 0;
25 | justify-content: center;
26 | align-items: center;
27 | }
28 | .menu .item .classic text {
29 | border: 1px solid #f8dada;
30 | padding: 10rpx 20rpx;
31 | margin: 20rpx;
32 | color: #777;
33 | font-size: 24rpx;
34 | border-radius: 18rpx;
35 | }
36 |
--------------------------------------------------------------------------------
/miniprogram/pages/search/search.js:
--------------------------------------------------------------------------------
1 | // miniprogram/pages/search/search.js
2 | const app = getApp()
3 | Page({
4 |
5 | /**
6 | * 页面的初始数据
7 | */
8 | data: {
9 | inputValue: '',
10 | openid: '',
11 | showHistory: true,
12 | historyList: []
13 | },
14 |
15 | /**
16 | * 生命周期函数--监听页面加载
17 | */
18 | onLoad: function(options) {
19 |
20 | console.log('是否已有用户openId:', app.globalData.openid)
21 |
22 | // 是否存在用户的openId
23 | if (app.globalData.openid) {
24 | this.setData({
25 | openid: app.globalData.openid
26 | })
27 | }
28 |
29 | },
30 |
31 | bindKeyInput(e) {
32 | this.setData({
33 | inputValue: e.detail.value
34 | })
35 | console.log(this.data.inputValue)
36 | },
37 |
38 | // 进入搜索结果页 -> list
39 | goSearch() {
40 | let content = this.data.inputValue
41 | if (!content) {
42 | console.log('内容为空')
43 | return
44 | }
45 |
46 | this.onHistory(content)
47 |
48 | wx.navigateTo({
49 | url: `/pages/list/list?content=${content}`,
50 | })
51 | },
52 |
53 | historyGoSearch(e) {
54 | console.log(e)
55 | let content = e.currentTarget.dataset.title
56 | wx.navigateTo({
57 | url: `/pages/list/list?content=${content}`,
58 | })
59 | },
60 |
61 | // 清空历史记录
62 | bindClearHistory() {
63 | const db = wx.cloud.database()
64 | db.collection('historys').doc('history' + this.data.openid).update({
65 | data: {
66 | historyList: []
67 | }
68 | }).then((res) => {
69 | console.log(res)
70 | wx.showToast({
71 | icon: '删除',
72 | title: '清空历史',
73 | })
74 | })
75 |
76 | this.setData({
77 | historyList: []
78 | })
79 | },
80 |
81 | // 添加历史记录
82 | onHistory (content) {
83 | const db = wx.cloud.database()
84 | let that = this
85 |
86 | // 查看是否有历史记录
87 | db.collection('historys').where({
88 | _openid: this.data.openid,
89 | _id: 'history' + this.data.openid
90 | }).get({
91 | success: res => {
92 | console.log('[数据库] [查询记录] 成功: ', res)
93 | if (!res.data.length) {
94 | console.log(' 历史记录为空')
95 | let historyArray = []
96 | historyArray.unshift(content)
97 | db.collection('historys').add({
98 | data: {
99 | _id: 'history' + that.data.openid,
100 | description: 'history',
101 | historyList: historyArray
102 | }
103 | }).then(res => {
104 | console.log(res)
105 | })
106 | } else {
107 | console.log('已有历史记录')
108 | let historyArray = res.data[0].historyList
109 | historyArray.unshift(content)
110 | console.log([...new Set(historyArray)])
111 | db.collection('historys').doc('history' + that.data.openid).update({
112 | data: {
113 | historyList: [...new Set(historyArray)]
114 | }
115 | }).then((res) => {
116 | console.log(res)
117 | })
118 | }
119 | },
120 | fail: err => {
121 | wx.showToast({
122 | icon: 'none',
123 | title: '查询记录失败'
124 | })
125 | console.error('[数据库] [查询记录] 失败:', err)
126 | }
127 | })
128 | },
129 |
130 | // 读取历史记录
131 | getHistory() {
132 | let that = this
133 | const db = wx.cloud.database()
134 | db.collection('historys').doc('history' + that.data.openid).get({
135 | success(res) {
136 | console.log(res.data)
137 | that.setData({
138 | historyList: res.data.historyList
139 | })
140 | }
141 | })
142 | },
143 |
144 |
145 | /**
146 | * 生命周期函数--监听页面初次渲染完成
147 | */
148 | onReady: function() {
149 |
150 | },
151 |
152 | /**
153 | * 生命周期函数--监听页面显示
154 | */
155 | onShow: function() {
156 | this.getHistory()
157 | },
158 |
159 | /**
160 | * 生命周期函数--监听页面隐藏
161 | */
162 | onHide: function() {
163 | this.getHistory()
164 | },
165 |
166 | /**
167 | * 生命周期函数--监听页面卸载
168 | */
169 | onUnload: function() {
170 |
171 | },
172 |
173 | /**
174 | * 页面相关事件处理函数--监听用户下拉动作
175 | */
176 | onPullDownRefresh: function() {
177 |
178 | },
179 |
180 | /**
181 | * 页面上拉触底事件的处理函数
182 | */
183 | onReachBottom: function() {
184 |
185 | },
186 |
187 | /**
188 | * 用户点击右上角分享
189 | */
190 | onShareAppMessage: function() {
191 |
192 | }
193 | })
--------------------------------------------------------------------------------
/miniprogram/pages/search/search.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {},
3 | "navigationBarTitleText": "搜索"
4 | }
--------------------------------------------------------------------------------
/miniprogram/pages/search/search.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 搜索
6 |
7 |
8 | 搜索历史
9 | 清空历史
10 |
11 | {{item}}
12 |
13 |
14 |
15 |
16 | 搜索历史为空
17 |
18 |
--------------------------------------------------------------------------------
/miniprogram/pages/search/search.wxss:
--------------------------------------------------------------------------------
1 | /* miniprogram/pages/search/search.wxss */
2 |
3 | .search {
4 | margin: 20rpx;
5 | box-sizing: border-box;
6 | border-radius: 50rpx;
7 | height: 80rpx;
8 | padding: 0 0 0 20rpx;
9 | background: #fff;
10 | display: flex;
11 | align-items: center;
12 | justify-content: flex-start;
13 | font-size: 28rpx;
14 | border: 1px solid rgba(255, 98, 98, .7);
15 | }
16 |
17 | .search image {
18 | height: 36rpx;
19 | width: 36rpx;
20 | margin-right: 20rpx;
21 | }
22 |
23 | input {
24 | border: none;
25 | flex: 1;
26 | }
27 |
28 | .search text {
29 | padding: 20rpx 40rpx 20rpx 30rpx;
30 | background: #ff6262;
31 | color: #fff;
32 | border-top-right-radius: 50rpx;
33 | border-bottom-right-radius: 50rpx;
34 | }
35 |
36 | .history {
37 | margin-top: 30rpx;
38 | font-size: 28rpx;
39 | padding: 30rpx;
40 | color: #555;
41 | position: relative;
42 | }
43 |
44 | .history view {
45 | margin-top: 40rpx;
46 | display: flex;
47 | flex-wrap: wrap;
48 | }
49 |
50 | .history .title {
51 | color: #ff6262;
52 | }
53 |
54 | .history view text {
55 | border: 1px solid #ddd;
56 | padding: 8rpx 50rpx;
57 | border-radius: 40rpx;
58 | margin: 20rpx 30rpx 20rpx 0;
59 | }
60 |
61 | .clear {
62 | color: #888;
63 | position: absolute;
64 | right: 30rpx;
65 | top: 30rpx;
66 | }
67 |
--------------------------------------------------------------------------------
/miniprogram/pages/user/user-unlogin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darylliu/micro_app_food/53969c7487da4235eee90970a2e83970b17535af/miniprogram/pages/user/user-unlogin.png
--------------------------------------------------------------------------------
/miniprogram/pages/user/user.js:
--------------------------------------------------------------------------------
1 | // miniprogram/pages/user/user.js
2 | const app = getApp()
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | userInfo: {},
11 | avatarUrl: '',
12 | openid: '',
13 | logged: false,
14 | username: '',
15 | place: '',
16 | collectList: []
17 | },
18 |
19 | /**
20 | * 生命周期函数--监听页面加载
21 | */
22 | onLoad: function (options) {
23 | console.log('进入用户页检查是否登录:', this.data.logged)
24 | console.log('是否已授权:', wx.getStorageSync('isLogin'))
25 | console.log('是否已有用户openId:', app.globalData.openid)
26 |
27 | wx.showLoading({
28 | title: '正在加载...',
29 | mask: true
30 | });
31 |
32 | // 获取用户信息
33 | wx.getSetting({
34 | success: res => {
35 | if (res.authSetting['scope.userInfo']) {
36 | console.log('已授权')
37 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
38 | wx.getUserInfo({
39 | success: res => {
40 | this.setData({
41 | logged: true,
42 | avatarUrl: res.userInfo.avatarUrl,
43 | userInfo: res.userInfo,
44 | username: res.userInfo.nickName,
45 | place: res.userInfo.province + ', ' + res.userInfo.country
46 | })
47 | }
48 | })
49 | }
50 | wx.hideLoading();
51 | }
52 | })
53 |
54 | // 是否存在用户的openId
55 | if (app.globalData.openid) {
56 | this.setData({
57 | openid: app.globalData.openid
58 | })
59 | }
60 |
61 | },
62 |
63 | goDetail(e) {
64 | wx.navigateTo({
65 | url: `/pages/detail/detail?id=${e.currentTarget.dataset.id}`,
66 | })
67 | },
68 |
69 | onGetUserInfo: function (e) {
70 | if (!this.data.logged && e.detail.userInfo) {
71 |
72 | console.log(e)
73 | wx.setStorageSync('isLogin', 'isLogin')
74 |
75 | this.setData({
76 | logged: true,
77 | avatarUrl: e.detail.userInfo.avatarUrl,
78 | userInfo: e.detail.userInfo,
79 | username: e.detail.userInfo.nickName,
80 | place: e.detail.userInfo.province + ', ' + e.detail.userInfo.country
81 | })
82 |
83 | }
84 | },
85 |
86 | // 读取收藏列表
87 | getcollect () {
88 | const db = wx.cloud.database()
89 | // 查看是否有收藏记录
90 | db.collection('collects').where({
91 | _openid: this.data.openid,
92 | _id: 'collect' + this.data.openid
93 | }).get({
94 | success: res => {
95 | console.log('[数据库] [查询记录] 成功: ', res)
96 |
97 | if (!res.data.length) { // 如果从未收藏
98 | console.log(' 从未收藏')
99 | this.setData({
100 | collectList: []
101 | })
102 | } else { // 如果已有收藏记录
103 | db.collection('collects').doc('collect' + this.data.openid).get().then(res => {
104 | console.log(res.data)
105 | this.setData({
106 | collectList: res.data.collectList
107 | })
108 | })
109 | }
110 | },
111 | fail: err => {
112 | wx.showToast({
113 | icon: 'none',
114 | title: '查询记录失败'
115 | })
116 | console.error('[数据库] [查询记录] 失败:', err)
117 | }
118 | })
119 | },
120 |
121 | /**
122 | * 生命周期函数--监听页面初次渲染完成
123 | */
124 | onReady: function () {
125 |
126 | },
127 |
128 | /**
129 | * 生命周期函数--监听页面显示
130 | */
131 | onShow: function () {
132 | this.getcollect()
133 | console.log(0)
134 | },
135 |
136 | /**
137 | * 生命周期函数--监听页面隐藏
138 | */
139 | onHide: function () {
140 |
141 | },
142 |
143 | /**
144 | * 生命周期函数--监听页面卸载
145 | */
146 | onUnload: function () {
147 |
148 | },
149 |
150 | /**
151 | * 页面相关事件处理函数--监听用户下拉动作
152 | */
153 | onPullDownRefresh: function () {
154 |
155 | },
156 |
157 | /**
158 | * 页面上拉触底事件的处理函数
159 | */
160 | onReachBottom: function () {
161 |
162 | },
163 |
164 | /**
165 | * 用户点击右上角分享
166 | */
167 | onShareAppMessage: function () {
168 |
169 | }
170 | })
--------------------------------------------------------------------------------
/miniprogram/pages/user/user.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {}
3 | }
--------------------------------------------------------------------------------
/miniprogram/pages/user/user.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 请登录后查看您收藏的菜品
6 |
9 |
10 |
11 |
12 |
13 | {{username}}
14 | {{place}}
15 |
16 |
17 | 我的菜谱
18 |
19 |
20 |
21 |
22 | {{item.title}}
23 | {{item.itro}}
24 | 查看更多>>
25 |
26 |
27 |
28 |
29 | 您还没有收藏过菜品
30 |
31 |
32 |
--------------------------------------------------------------------------------
/miniprogram/pages/user/user.wxss:
--------------------------------------------------------------------------------
1 | /* miniprogram/pages/user/user.wxss */
2 |
3 | .user {
4 | font-size: 28rpx;
5 | }
6 |
7 | .logout {
8 | text-align: center;
9 | padding: 160rpx 200rpx;
10 | }
11 |
12 | .logout button {
13 | margin-top: 100rpx;
14 | line-height: 80rpx;
15 | font: 28rpx;
16 | background: #ff6262;
17 | color: #fff;
18 | }
19 |
20 | .login {
21 | margin: 0;
22 | }
23 |
24 | .login .name image {
25 | height: 140rpx;
26 | width: 140rpx;
27 | border-radius: 50%;
28 | animation: avator linear 16s infinite normal;
29 | }
30 |
31 | @keyframes avator {
32 | 0% {
33 | transform: rotate(0deg);
34 | }
35 |
36 | 100% {
37 | transform: rotate(360deg);
38 | }
39 | }
40 |
41 | .login .name {
42 | background: linear-gradient(#f79642, #f5798d);
43 | display: flex;
44 | flex-direction: column;
45 | align-items: center;
46 | justify-content: center;
47 | padding: 30rpx;
48 | }
49 |
50 | .login .name text {
51 | padding-top: 20rpx;
52 | color: #fff;
53 | }
54 |
55 | .login .collection {
56 | padding: 50rpx 30rpx;
57 | background: #fff;
58 | }
59 | .login .collection .my {
60 | font-weight: bold;
61 | border-left: 3px solid #ff6262;
62 | padding-left: 14rpx;
63 | }
64 |
65 | .box {
66 | border: 1px solid #ddd;
67 | margin: 40rpx 0 0 0;
68 | padding: 20rpx 30rpx 20rpx 270rpx;
69 | font-size: 28rpx;
70 | height: 200rpx;
71 | overflow: hidden;
72 | position: relative;
73 | border-radius: 10rpx;
74 | box-shadow: 1px 1px 6rpx #ccc;
75 | }
76 |
77 | .box image {
78 | height: 200rpx;
79 | width: 220rpx;
80 | position: absolute;
81 | top: 20rpx;
82 | left: 10rpx;
83 | border-radius: 10rpx;
84 | }
85 |
86 | .box view {
87 | padding-top: 0rpx;
88 | }
89 |
90 | .box view text {
91 | display: block;
92 | overflow: hidden;
93 | white-space: nowrap;
94 | text-overflow: ellipsis;
95 | padding-bottom: 10rpx;
96 | color: #555;
97 | font-size: 24rpx;
98 | }
99 |
100 | .box view text.title {
101 | color: #333;
102 | font-weight: 600;
103 | font-size: 30rpx;
104 | padding-bottom: 16rpx;
105 | }
106 |
107 | .box view text.see {
108 | color: #ff6262;
109 | padding-top: 40rpx;
110 | }
111 |
--------------------------------------------------------------------------------
/miniprogram/style/guide.wxss:
--------------------------------------------------------------------------------
1 | page {
2 | background: #f6f6f6;
3 | display: flex;
4 | flex-direction: column;
5 | justify-content: flex-start;
6 | }
7 |
8 | .list {
9 | margin-top: 40rpx;
10 | height: auto;
11 | width: 100%;
12 | background: #fff;
13 | padding: 0 40rpx;
14 | border: 1px solid rgba(0, 0, 0, 0.1);
15 | border-left: none;
16 | border-right: none;
17 | transition: all 300ms ease;
18 | display: flex;
19 | flex-direction: column;
20 | align-items: flex-start;
21 | box-sizing: border-box;
22 | }
23 |
24 | .list-item {
25 | width: 100%;
26 | padding: 0;
27 | line-height: 104rpx;
28 | font-size: 34rpx;
29 | color: #007aff;
30 | border-top: 1px solid rgba(0, 0, 0, 0.1);
31 | display: flex;
32 | flex-direction: row;
33 | align-content: center;
34 | justify-content: space-between;
35 | box-sizing: border-box;
36 | }
37 |
38 | .list-item:first-child {
39 | border-top: none;
40 | }
41 |
42 | .list-item image {
43 | max-width: 100%;
44 | max-height: 20vh;
45 | margin: 20rpx 0;
46 | }
47 |
48 | .request-text {
49 | color: #222;
50 | padding: 20rpx 0;
51 | font-size: 24rpx;
52 | line-height: 36rpx;
53 | word-break: break-all;
54 | }
55 |
56 | .guide {
57 | width: 100%;
58 | padding: 40rpx;
59 | box-sizing: border-box;
60 | display: flex;
61 | flex-direction: column;
62 | }
63 |
64 | .guide .headline {
65 | font-size: 34rpx;
66 | font-weight: bold;
67 | color: #555;
68 | line-height: 40rpx;
69 | }
70 |
71 | .guide .p {
72 | margin-top: 20rpx;
73 | font-size: 28rpx;
74 | line-height: 36rpx;
75 | color: #666;
76 | }
77 |
78 | .guide .code {
79 | margin-top: 20rpx;
80 | font-size: 28rpx;
81 | line-height: 36rpx;
82 | color: #666;
83 | background: white;
84 | white-space: pre;
85 | }
86 |
87 | .guide .code-dark {
88 | margin-top: 20rpx;
89 | background: rgba(0, 0, 0, 0.8);
90 | padding: 20rpx;
91 | font-size: 28rpx;
92 | line-height: 36rpx;
93 | border-radius: 6rpx;
94 | color: #fff;
95 | white-space: pre
96 | }
97 |
98 | .guide image {
99 | max-width: 100%;
100 | }
101 |
102 | .guide .image1 {
103 | margin-top: 20rpx;
104 | max-width: 100%;
105 | width: 356px;
106 | height: 47px;
107 | }
108 |
109 | .guide .image2 {
110 | margin-top: 20rpx;
111 | width: 264px;
112 | height: 100px;
113 | }
114 |
115 | .guide .flat-image {
116 | height: 100px;
117 | }
118 |
119 | .guide .code-image {
120 | max-width: 100%;
121 | }
122 |
123 | .guide .copyBtn {
124 | width: 180rpx;
125 | font-size: 20rpx;
126 | margin-top: 16rpx;
127 | margin-left: 0;
128 | }
129 |
130 | .guide .nav {
131 | margin-top: 50rpx;
132 | display: flex;
133 | flex-direction: row;
134 | align-content: space-between;
135 | }
136 |
137 | .guide .nav .prev {
138 | margin-left: unset;
139 | }
140 |
141 | .guide .nav .next {
142 | margin-right: unset;
143 | }
144 |
145 |
--------------------------------------------------------------------------------
/miniprogram/utils/ald-stat-conf.js:
--------------------------------------------------------------------------------
1 | exports.app_key = "54862e8fa831cac321e20513f7d7d7b1"; //请在此行填写从阿拉丁后台获取的appkey
2 | exports.getLocation = false; //默认不获取用户坐标位置
3 | exports.plugin = false; //您的小程序中是否使用了插件。根据是否启用插件会有不同的接入方式,请参考文档文档。
4 |
5 |
--------------------------------------------------------------------------------
/miniprogram/utils/ald-stat.js:
--------------------------------------------------------------------------------
1 | !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.Ald=t()}(this,function(){function n(){this.concurrency=4,this.queue=[],this.tasks=[],this.activeCount=0;var n=this;this.push=function(t){this.tasks.push(new Promise(function(e,o){var r=function(){n.activeCount++,t().then(function(n){e(n)}).then(function(){n.next()})};n.activeCount0&&n.queue.shift()()}}function t(n){this.app=n}function e(n){b=g(),Q=n,this.aldstat=new t(this)}function o(n){var t;t=n.scene!=cn,cn=n.scene,J=0,Q=n,W=n.query.ald_share_src,$=n.query.aldsrc||"",z=n.query.ald_share_src,E=Date.now(),sn||(G=!1),sn=!1,un||(0!==B&&Date.now()-B>3e4?O=g():t&&(O=g())),0!==B&&Date.now()-B<3e4&&(tn=!0),n.query.ald_share_src&&"1044"==n.scene&&n.shareTicket?wx.getShareInfo({shareTicket:n.shareTicket,success:function(n){X=n,D("event","ald_share_click",JSON.stringify(n))}}):n.query.ald_share_src&&D("event","ald_share_click",1),""===Y&&wx.getSetting({withCredentials:!0,success:function(n){if(n.authSetting["scope.userInfo"]){wx.getUserInfo({withCredentials:!0,success:function(n){var t=v();Y=n,t.ufo=S(n),j=w(n.userInfo.avatarUrl.split("/")),p(t)}})}}}),m("app","show")}function r(){B=Date.now(),""===Y&&wx.getSetting({success:function(n){n.authSetting["scope.userInfo"]&&wx.getUserInfo({withCredentials:!0,success:function(n){Y=n,j=w(n.userInfo.avatarUrl.split("/"));var t=v();t.ufo=S(n),p(t)}})}}),m("app","hide")}function i(n){F++,D("event","ald_error_message",n)}function a(n){rn=n}function s(){en=C?this.$mp.page.route:this.route,x("page","show"),tn=!1}function u(){on=en}function c(){on=en}function f(){D("event","ald_pulldownrefresh",1)}function l(){D("event","ald_reachbottom",1)}function h(n){un=!0;var t=y(n.path),e={};for(var o in Q.query)"ald_share_src"===o&&(e[o]=Q.query[o]);var r="";if(r=n.path.indexOf("?")==-1?n.path+"?":n.path.substr(0,n.path.indexOf("?"))+"?",""!==t)for(var o in t)e[o]=t[o];e.ald_share_src?e.ald_share_src.indexOf(K)==-1&&e.ald_share_src.length<200&&(e.ald_share_src=e.ald_share_src+","+K):e.ald_share_src=K;for(var i in e)i.indexOf("ald")==-1&&(r+=i+"="+e[i]+"&");return n.path=r+"ald_share_src="+e.ald_share_src,D("event","ald_share_status",n),n}function d(){function n(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return n()+n()+n()+n()+n()+n()+n()+n()}function p(n){function t(){return new Promise(function(t,e){wx.request({url:"https://"+U+".aldwx.com/d.html",data:n,header:{AldStat:"MiniApp-Stat",se:T||"",op:N||"",img:j},method:"GET",success:function(n){t(200==n.statusCode?"":"status error")},fail:function(){t("fail")}})})}J++,n.at=O,n.et=Date.now(),n.uu=K,n.v=I,n.ak=H.app_key.replace(/(\t)|(\s)/g,""),n.wsr=Q,n.ifo=G,n.rq_c=J,n.ls=b,wx.Queue.push(t)}function v(){var n={};for(var t in Z)n[t]=Z[t];return n}function w(n){for(var t="",e=0;et.length&&(t=n[e]);return t}function g(){return""+Date.now()+Math.floor(1e7*Math.random())}function S(n){var t={};for(var e in n)"rawData"!=e&&"errMsg"!=e&&(t[e]=n[e]);return t}function y(n){if(n.indexOf("?")==-1)return"";var t={};return n.split("?")[1].split("&").forEach(function(n){var e=n.split("=")[1];t[n.split("=")[0]]=e}),t}function _(n){for(var t in n)if("object"==typeof n[t]&&null!==n[t])return!0;return!1}function m(n,t){var e=v();e.ev=n,e.life=t,e.ec=F,e.st=Date.now(),e.dr=Date.now()-E,$&&(e.qr=$,e.sr=$),W&&(e.usr=W),p(e)}function x(n,t){var e=v();e.ev=n,e.st=Date.now(),e.life=t,e.pp=en,e.pc=on,e.dr=Date.now()-E,un&&(e.so=1),un=!1,rn&&"{}"!=JSON.stringify(rn)&&(e.ag=rn),$&&(e.qr=$,e.sr=$),W&&(e.usr=W),tn&&(e.ps=1),nn||(an=en,nn=!0,e.ifp=nn,e.fp=en),p(e)}function D(n,t,e){var o=v();o.ev=n,o.tp=t,o.st=V,o.dr=Date.now()-E,e&&(o.ct=e),p(o)}function A(n,t,e){if(n[t]){var o=n[t];n[t]=function(n){e.call(this,n,t),o.call(this,n)}}else n[t]=function(n){e.call(this,n,t)}}function M(n){var t={};for(var a in n)"onLaunch"!==a&&"onShow"!==a&&"onHide"!==a&&"onError"!==a&&(t[a]=n[a]);return t.onLaunch=function(t){e.call(this,t),"function"==typeof n.onLaunch&&n.onLaunch.call(this,t)},t.onShow=function(t){o.call(this,t),n.onShow&&"function"==typeof n.onShow&&n.onShow.call(this,t)},t.onHide=function(){r.call(this),n.onHide&&"function"==typeof n.onHide&&n.onHide.call(this)},t.onError=function(t){i.call(this,t),n.onError&&"function"==typeof n.onError&&n.onError.call(this,t)},t}function q(n){var t={};for(var e in n)"onLoad"!==e&&"onShow"!==e&&"onHide"!==e&&"onUnload"!==e&&"onPullDownRefresh"!==e&&"onReachBottom"!==e&&"onShareAppMessage"!==e&&(t[e]=n[e]);return t.onLoad=function(t){a.call(this,t),"function"==typeof n.onLoad&&n.onLoad.call(this,t)},t.onShow=function(t){s.call(this),"function"==typeof n.onShow&&n.onShow.call(this,t)},t.onHide=function(t){u.call(this),"function"==typeof n.onHide&&n.onHide.call(this,t)},t.onUnload=function(t){c.call(this),"function"==typeof n.onUnload&&n.onUnload.call(this,t)},t.onReachBottom=function(t){l(),n.onReachBottom&&"function"==typeof n.onReachBottom&&n.onReachBottom.call(this,t)},t.onPullDownRefresh=function(t){f(),n.onPullDownRefresh&&"function"==typeof n.onPullDownRefresh&&n.onPullDownRefresh.call(this,t)},n.onShareAppMessage&&"function"==typeof n.onShareAppMessage&&(t.onShareAppMessage=function(t){var e=n.onShareAppMessage.call(this,t);return void 0===e?(e={},e.path=this.route):void 0===e.path&&(e.path=this.route),h.call(this,e)}),t}function L(n){return App(M(n))}function P(n){return Page(q(n))}function R(n){return C=!0,M(n)}function k(n){return q(n)}void 0===wx.Queue&&(wx.Queue=new n,wx.Queue.all());var H=require("./ald-stat-conf"),I="7.2.2",U="log",C=!1,O="",b="",E=0,B=0,T="",N="",j="",J=0,Q="",G="",K=function(){var n="";try{n=wx.getStorageSync("aldstat_uuid")}catch(t){n="uuid_getstoragesync"}if(n)G=!1;else{n=d();try{wx.setStorageSync("aldstat_uuid",n),G=!0}catch(n){wx.setStorageSync("aldstat_uuid","uuid_getstoragesync")}}return n}(),V=Date.now(),W="",$="",z="",F=0,X="",Y="",Z={},nn=!1,tn=!1,en="",on="",rn="",an="",sn=!0,un=!1,cn="";!function(){wx.request({url:"https://"+U+".aldwx.com/config/app.json",header:{AldStat:"MiniApp-Stat"},method:"GET",success:function(n){200===n.statusCode&&(I=255)return void console.error("自定义事件参数不能超过255个字符");if(_(t))return void console.error("事件参数,参数内部只支持Number,String等类型,请参考接入文档");D("event",n,JSON.stringify(t))}else void 0===t?D("event",n,!1):console.error("事件参数必须为String,Object类型,且参数长度不能超过255个字符");else console.error("事件名称必须为String类型且不能超过255个字符")},t.prototype.sendSession=function(n){if(""===n||!n)return void console.error("请传入从后台获取的session_key");T=n;var t=v();t.st=Date.now(),t.tp="session",t.ct="session",t.ev="event",""===Y?wx.getSetting({success:function(n){n.authSetting["scope.userInfo"]?wx.getUserInfo({success:function(n){t.ufo=S(n),j=w(n.userInfo.avatarUrl.split("/")),""!==X&&(t.gid=X),p(t)}}):""!==X&&(t.gid=X,p(t))}}):(t.ufo=Y,""!==X&&(t.gid=X),p(t))},t.prototype.sendOpenid=function(n){if(""===n||!n)return void console.error("openID不能为空");N=n;var t=v();t.st=Date.now(),t.tp="openid",t.ev="event",t.ct="openid",p(t)};return H.plugin?{App:L,Page:P,MpvueApp:R,MpvuePage:k}:function(n){!function(){var n=App,t=Page,d=Component;App=function(t){A(t,"onLaunch",e),A(t,"onShow",o),A(t,"onHide",r),A(t,"onError",i),n(t)},Page=function(n){var e=n.onShareAppMessage;A(n,"onLoad",a),A(n,"onUnload",c),A(n,"onShow",s),A(n,"onHide",u),A(n,"onReachBottom",l),A(n,"onPullDownRefresh",f),void 0!==e&&null!==e&&(n.onShareAppMessage=function(n){if(void 0!==e){var t=e.call(this,n);return void 0===t?(t={},t.path=en):void 0===t.path&&(t.path=en),h(t)}}),t(n)},Component=function(n){try{var t=n.methods.onShareAppMessage;A(n.methods,"onLoad",a),A(n.methods,"onUnload",c),A(n.methods,"onShow",s),A(n.methods,"onHide",u),A(n.methods,"onReachBottom",l),A(n.methods,"onPullDownRefresh",f),void 0!==t&&null!==t&&(n.methods.onShareAppMessage=function(n){if(void 0!==t){var e=t.call(this,n);return void 0===e?(e={},e.path=en):void 0===e.path&&(e.path=en),h(e)}}),d(n)}catch(t){d(n)}}}()}()});
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "miniprogramRoot": "miniprogram/",
3 | "cloudfunctionRoot": "cloudfunctions/",
4 | "setting": {
5 | "urlCheck": true,
6 | "es6": true,
7 | "postcss": true,
8 | "minified": true,
9 | "newFeature": true,
10 | "autoAudits": false
11 | },
12 | "appid": "wx41431ba3e90d01d7",
13 | "projectname": "%E5%B0%8F%E8%8F%9C%E4%B8%80%E7%A2%9F",
14 | "libVersion": "2.3.0",
15 | "condition": {
16 | "search": {
17 | "current": -1,
18 | "list": []
19 | },
20 | "conversation": {
21 | "current": -1,
22 | "list": []
23 | },
24 | "plugin": {
25 | "current": -1,
26 | "list": []
27 | },
28 | "game": {
29 | "list": []
30 | },
31 | "miniprogram": {}
32 | }
33 | }
--------------------------------------------------------------------------------