From 1a025f4ced069e54510231158d7ef654aaea59f6 Mon Sep 17 00:00:00 2001 From: Booker Zhao Date: Sat, 6 Jul 2024 13:55:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E8=A1=8C=E7=A8=8B=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quickstartFunctions/config.json | 7 - .../createCollection/index.js | 56 ---- .../fetchGoodsList/index.js | 11 - .../quickstartFunctions/genMpQrcode/index.js | 18 -- .../getMiniProgramCode/index.js | 20 -- .../quickstartFunctions/getOpenId/index.js | 17 -- cloudfunctions/quickstartFunctions/index.js | 31 --- .../quickstartFunctions/package.json | 14 - .../quickstartFunctions/selectRecord/index.js | 12 - .../quickstartFunctions/sumRecord/index.js | 18 -- .../quickstartFunctions/updateRecord/index.js | 32 --- miniprogram/app.js | 2 +- miniprogram/pages/index/index.js | 42 +-- miniprogram/pages/index/index.json | 4 +- miniprogram/pages/index/index.wxml | 69 ++--- miniprogram/pages/index/index.wxss | 243 +++--------------- project.config.json | 2 +- 17 files changed, 61 insertions(+), 537 deletions(-) delete mode 100644 cloudfunctions/quickstartFunctions/config.json delete mode 100644 cloudfunctions/quickstartFunctions/createCollection/index.js delete mode 100644 cloudfunctions/quickstartFunctions/fetchGoodsList/index.js delete mode 100644 cloudfunctions/quickstartFunctions/genMpQrcode/index.js delete mode 100644 cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js delete mode 100644 cloudfunctions/quickstartFunctions/getOpenId/index.js delete mode 100644 cloudfunctions/quickstartFunctions/index.js delete mode 100644 cloudfunctions/quickstartFunctions/package.json delete mode 100644 cloudfunctions/quickstartFunctions/selectRecord/index.js delete mode 100644 cloudfunctions/quickstartFunctions/sumRecord/index.js delete mode 100644 cloudfunctions/quickstartFunctions/updateRecord/index.js diff --git a/cloudfunctions/quickstartFunctions/config.json b/cloudfunctions/quickstartFunctions/config.json deleted file mode 100644 index 41a485c..0000000 --- a/cloudfunctions/quickstartFunctions/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "permissions": { - "openapi": [ - "wxacode.get" - ] - } -} \ No newline at end of file diff --git a/cloudfunctions/quickstartFunctions/createCollection/index.js b/cloudfunctions/quickstartFunctions/createCollection/index.js deleted file mode 100644 index 75a40b9..0000000 --- a/cloudfunctions/quickstartFunctions/createCollection/index.js +++ /dev/null @@ -1,56 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); - -const db = cloud.database(); - -// 创建集合云函数入口函数 -exports.main = async (event, context) => { - try { - // 创建集合 - await db.createCollection('sales'); - await db.collection('sales').add({ - // data 字段表示需新增的 JSON 数据 - data: { - region: '华东', - city: '上海', - sales: 11 - } - }); - await db.collection('sales').add({ - // data 字段表示需新增的 JSON 数据 - data: { - region: '华东', - city: '南京', - sales: 11 - } - }); - await db.collection('sales').add({ - // data 字段表示需新增的 JSON 数据 - data: { - region: '华南', - city: '广州', - sales: 22 - } - }); - await db.collection('sales').add({ - // data 字段表示需新增的 JSON 数据 - data: { - region: '华南', - city: '深圳', - sales: 22 - } - }); - return { - success: true - }; - } catch (e) { - // 这里catch到的是该collection已经存在,从业务逻辑上来说是运行成功的,所以catch返回success给前端,避免工具在前端抛出异常 - return { - success: true, - data: 'create collection success' - }; - } -}; diff --git a/cloudfunctions/quickstartFunctions/fetchGoodsList/index.js b/cloudfunctions/quickstartFunctions/fetchGoodsList/index.js deleted file mode 100644 index 02647cb..0000000 --- a/cloudfunctions/quickstartFunctions/fetchGoodsList/index.js +++ /dev/null @@ -1,11 +0,0 @@ -const cloud = require('wx-server-sdk'); -cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }); -exports.main = async (event, context) => { - return { - dataList: [ - { _id: '1', title: '微信气泡徽章', price: 1800 }, - { _id: '2', title: '微信地球鼠标垫', price: 5800 }, - { _id: '3', title: '微信黄脸大贴纸', price: 500 } - ], - } -}; \ No newline at end of file diff --git a/cloudfunctions/quickstartFunctions/genMpQrcode/index.js b/cloudfunctions/quickstartFunctions/genMpQrcode/index.js deleted file mode 100644 index 4abd7e0..0000000 --- a/cloudfunctions/quickstartFunctions/genMpQrcode/index.js +++ /dev/null @@ -1,18 +0,0 @@ -const cloud = require('wx-server-sdk'); -cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }); - -exports.main = async (event, context) => { - const pagePath = event.pagePath; - // 获取小程序二维码的buffer - const resp = await cloud.openapi.wxacode.get({ - path: pagePath, - }); - const { buffer } = resp; - // 将图片上传云存储空间 - const upload = await cloud.uploadFile({ - cloudPath: String(pagePath).replaceAll('/', '_') + '.png', - fileContent: buffer - }); - return upload.fileID; -}; - \ No newline at end of file diff --git a/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js b/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js deleted file mode 100644 index 08e1a82..0000000 --- a/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js +++ /dev/null @@ -1,20 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); - -// 获取小程序二维码云函数入口函数 -exports.main = async (event, context) => { - // 获取小程序二维码的buffer - const resp = await cloud.openapi.wxacode.get({ - path: 'pages/index/index' - }); - const { buffer } = resp; - // 将图片上传云存储空间 - const upload = await cloud.uploadFile({ - cloudPath: 'code.png', - fileContent: buffer - }); - return upload.fileID; -}; diff --git a/cloudfunctions/quickstartFunctions/getOpenId/index.js b/cloudfunctions/quickstartFunctions/getOpenId/index.js deleted file mode 100644 index 94b7b94..0000000 --- a/cloudfunctions/quickstartFunctions/getOpenId/index.js +++ /dev/null @@ -1,17 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); - -// 获取openId云函数入口函数 -exports.main = async (event, context) => { - // 获取基础信息 - const wxContext = cloud.getWXContext(); - - return { - openid: wxContext.OPENID, - appid: wxContext.APPID, - unionid: wxContext.UNIONID, - }; -}; diff --git a/cloudfunctions/quickstartFunctions/index.js b/cloudfunctions/quickstartFunctions/index.js deleted file mode 100644 index 4d5e339..0000000 --- a/cloudfunctions/quickstartFunctions/index.js +++ /dev/null @@ -1,31 +0,0 @@ -const getOpenId = require('./getOpenId/index'); -const getMiniProgramCode = require('./getMiniProgramCode/index'); -const createCollection = require('./createCollection/index'); -const selectRecord = require('./selectRecord/index'); -const updateRecord = require('./updateRecord/index'); -const sumRecord = require('./sumRecord/index'); -const fetchGoodsList = require('./fetchGoodsList/index'); -const genMpQrcode = require('./genMpQrcode/index'); - -// 云函数入口函数 -exports.main = async (event, context) => { - switch (event.type) { - case 'getOpenId': - return await getOpenId.main(event, context); - case 'getMiniProgramCode': - return await getMiniProgramCode.main(event, context); - case 'createCollection': - return await createCollection.main(event, context); - case 'selectRecord': - return await selectRecord.main(event, context); - case 'updateRecord': - return await updateRecord.main(event, context); - case 'sumRecord': - return await sumRecord.main(event, context); - case 'fetchGoodsList': - return await fetchGoodsList.main(event, context); - case 'genMpQrcode': - return await genMpQrcode.main(event, context); - } -}; - diff --git a/cloudfunctions/quickstartFunctions/package.json b/cloudfunctions/quickstartFunctions/package.json deleted file mode 100644 index 4350dbb..0000000 --- a/cloudfunctions/quickstartFunctions/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "quickstartFunctions", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "wx-server-sdk": "~2.4.0" - } -} diff --git a/cloudfunctions/quickstartFunctions/selectRecord/index.js b/cloudfunctions/quickstartFunctions/selectRecord/index.js deleted file mode 100644 index c7848a7..0000000 --- a/cloudfunctions/quickstartFunctions/selectRecord/index.js +++ /dev/null @@ -1,12 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); -const db = cloud.database(); - -// 查询数据库集合云函数入口函数 -exports.main = async (event, context) => { - // 返回数据库查询结果 - return await db.collection('sales').get(); -}; diff --git a/cloudfunctions/quickstartFunctions/sumRecord/index.js b/cloudfunctions/quickstartFunctions/sumRecord/index.js deleted file mode 100644 index dfdc293..0000000 --- a/cloudfunctions/quickstartFunctions/sumRecord/index.js +++ /dev/null @@ -1,18 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); -const db = cloud.database(); -const $ = db.command.aggregate; - -// 聚合记录云函数入口函数 -exports.main = async (event, context) => { - // 返回数据库聚合结果 - return db.collection('sales').aggregate() - .group({ - _id: '$region', - sum: $.sum('$sales') - }) - .end(); -}; diff --git a/cloudfunctions/quickstartFunctions/updateRecord/index.js b/cloudfunctions/quickstartFunctions/updateRecord/index.js deleted file mode 100644 index 2ce3ad0..0000000 --- a/cloudfunctions/quickstartFunctions/updateRecord/index.js +++ /dev/null @@ -1,32 +0,0 @@ -const cloud = require('wx-server-sdk'); - -cloud.init({ - env: cloud.DYNAMIC_CURRENT_ENV -}); -const db = cloud.database(); - -// 修改数据库信息云函数入口函数 -exports.main = async (event, context) => { - try { - // 遍历修改数据库信息 - for (let i = 0; i < event.data.length; i++) { - await db.collection('sales').where({ - _id: event.data[i]._id - }) - .update({ - data: { - sales: event.data[i].sales - }, - }); - } - return { - success: true, - data: event.data - }; - } catch (e) { - return { - success: false, - errMsg: e - }; - } -}; diff --git a/miniprogram/app.js b/miniprogram/app.js index bae1837..7509bc8 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -9,7 +9,7 @@ App({ // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 // 如不填则使用默认环境(第一个创建的环境) - env: 'wx-env01-3gf49vue58112f19', + env: 'app0', traceUser: true, }); } diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js index b5e6caf..b943679 100644 --- a/miniprogram/pages/index/index.js +++ b/miniprogram/pages/index/index.js @@ -1,36 +1,8 @@ -const { envList } = require("../../envList"); -const { QuickStartPoints, QuickStartSteps } = require("./constants"); - Page({ - data: { - knowledgePoints: QuickStartPoints, - steps: QuickStartSteps, - }, - - copyCode(e) { - const code = e.target?.dataset?.code || ''; - wx.setClipboardData({ - data: code, - success: () => { - wx.showToast({ - title: '已复制', - }) - }, - fail: (err) => { - console.error('复制失败-----', err); - } - }) - }, - - discoverCloud() { - wx.switchTab({ - url: '/pages/examples/index', - }) - }, - - gotoGoodsListPage() { - wx.navigateTo({ - url: '/pages/goods-list/index', - }) - }, -}); + // 表单提交事件处理函数 + submitForm: function(e) { + const formData = e.detail.value; + console.log('表单数据', formData); + // 这里可以调用后端API生成行程,或者进行其他逻辑处理 + } + }); \ No newline at end of file diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index bdf6915..2732dd6 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -2,5 +2,7 @@ "usingComponents": { "cloud-tip-modal": "/components/cloudTipModal/index" }, - "navigationBarBackgroundColor": "#fff" + "navigationBarBackgroundColor": "#000", + "navigationBarTextStyle": "white", + "navigationBarTitleText": "AI 智能生成路书" } \ No newline at end of file diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index d32bde5..5a5f986 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,58 +1,25 @@ - - - - 快速开始 - - 欢迎使用云开发!本页将带你了解如何使用云开发提供的能力快速开发小程序。 - - - 你将学习到 - - {{ point.title }} - + + +
+ + + 目的地 + - 5分钟上手教程 - - 我们将会使用常用的云开发能力,快速实现一个简单的商品列表页面。无需购买服务器,即可快速开发出后台服务、读取数据库、存取文件、调用微信开放服务。页面最终效果如下图所示。 - - - + + + 旅行天数 + - 查看页面 - - - - - - NO. - 0{{ step.id }} - - {{ step.title }} - - - - - - - - - - - - - - - - 查看页面 - + + + 兴趣点 +