From 157df649829644c06ea1f10d98983e1bd06359a7 Mon Sep 17 00:00:00 2001 From: wsq <2744814898@qq.com> Date: Mon, 28 Nov 2022 00:03:11 +0800 Subject: [PATCH 1/2] 11 --- .../pages/navigation/index/delete/delete.js | 127 ++++++++++++++++++ .../pages/navigation/index/delete/delete.json | 4 + .../pages/navigation/index/delete/delete.wxml | 41 ++++++ .../pages/navigation/index/delete/delete.wxss | 6 + 4 files changed, 178 insertions(+) create mode 100644 src/miniprogram-1(1)/pages/navigation/index/delete/delete.js create mode 100644 src/miniprogram-1(1)/pages/navigation/index/delete/delete.json create mode 100644 src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxml create mode 100644 src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxss diff --git a/src/miniprogram-1(1)/pages/navigation/index/delete/delete.js b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.js new file mode 100644 index 0000000..358ce35 --- /dev/null +++ b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.js @@ -0,0 +1,127 @@ +// pages/navigation/index/delete/delete.js +const db=wx.cloud.database(); + +let app=getApp(); + +Page({ + /** + * 页面的初始数据 + */ + data: { + clothes:[] + }, + //定义按钮的事件处理函数 + clear(e) + { + var clothes=this.data.clothes + console.log(clothes) + let index=e.currentTarget.dataset.index + console.log(index) + let id=clothes[index]._id + console.log(id) + //界面数据删除 + this.data.clothes.splice(e.currentTarget.dataset.index,1); + this.setData({ clothes: this.data.clothes }); + console.log('删除成功'); + wx.showToast({ + title: '删除成功', + }) + + //初始化云 + wx.cloud.init({ + env:'cloud1-5ggzbo3kcd4ea4e2' + }); + wx.cloud.callFunction({ + name:'get', + complete:res=>{ + console.log('云函数获取openid:',res.result.openid); + wx.setStorageSync('openid',res.result.openid); + console.log(res); + } + }), + //删除数据库中记录 + db.collection('cloth').where({ + '_id':id + }).remove({ + success: function(res) { + console.log(res.data) + wx.showToast({ + title: '删除成功', + }) + console.log('数据库删除成功') + } + }) + db.collection('cloth').where({ + '_id':id + }).get({ + success: res =>{ + console.log(''); + } + }) + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + db.collection('cloth').get({ + success: res =>{ + console.log(res.data); + this.setData({ + clothes:app.globalData.clothes + }) + } + }) + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } + +}) \ No newline at end of file diff --git a/src/miniprogram-1(1)/pages/navigation/index/delete/delete.json b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.json new file mode 100644 index 0000000..bab9e34 --- /dev/null +++ b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.json @@ -0,0 +1,4 @@ +{ + "usingComponents": {}, + "navigationBarTitleText":"" +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxml b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxml new file mode 100644 index 0000000..87a237a --- /dev/null +++ b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxml @@ -0,0 +1,41 @@ + + + + + + + 名称 + + + 模式 + + + 类型 + + + 操作 + + + + + + + + + + {{item.name}} + + + {{item.pattern}} + + + {{item.kind}} + + + + + + + + + diff --git a/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxss b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxss new file mode 100644 index 0000000..43478ab --- /dev/null +++ b/src/miniprogram-1(1)/pages/navigation/index/delete/delete.wxss @@ -0,0 +1,6 @@ +/* pages/navigation/index/delete/delete.wxss */ + + + + + From 3d1dd0007c872499fcc5bef44890eec7b99d269b Mon Sep 17 00:00:00 2001 From: wsq <2744814898@qq.com> Date: Mon, 28 Nov 2022 00:52:17 +0800 Subject: [PATCH 2/2] 11111 --- src/miniprogram-1(1)/.eslintrc.js | 31 + src/miniprogram-1(1)/app.js | 589 ++++++++++++++++++ src/miniprogram-1(1)/app.json | 53 ++ src/miniprogram-1(1)/app.wxss | 10 + .../cloudfunctions/get/config.json | 6 + .../cloudfunctions/get/index.js | 32 + .../cloudfunctions/get/package.json | 14 + .../quickstartFunctions/config.json | 7 + .../createCollection/index.js | 56 ++ .../getMiniProgramCode/index.js | 20 + .../quickstartFunctions/getOpenId/index.js | 17 + .../quickstartFunctions/index.js | 25 + .../quickstartFunctions/package.json | 14 + .../quickstartFunctions/selectRecord/index.js | 12 + .../quickstartFunctions/sumRecord/index.js | 18 + .../quickstartFunctions/updateRecord/index.js | 32 + src/miniprogram-1(1)/project.config.json | 47 ++ .../project.private.config.json | 34 + src/miniprogram-1(1)/sitemap.json | 7 + 19 files changed, 1024 insertions(+) create mode 100644 src/miniprogram-1(1)/.eslintrc.js create mode 100644 src/miniprogram-1(1)/app.js create mode 100644 src/miniprogram-1(1)/app.json create mode 100644 src/miniprogram-1(1)/app.wxss create mode 100644 src/miniprogram-1(1)/cloudfunctions/get/config.json create mode 100644 src/miniprogram-1(1)/cloudfunctions/get/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/get/package.json create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/config.json create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/createCollection/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getOpenId/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/package.json create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/selectRecord/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/sumRecord/index.js create mode 100644 src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/updateRecord/index.js create mode 100644 src/miniprogram-1(1)/project.config.json create mode 100644 src/miniprogram-1(1)/project.private.config.json create mode 100644 src/miniprogram-1(1)/sitemap.json diff --git a/src/miniprogram-1(1)/.eslintrc.js b/src/miniprogram-1(1)/.eslintrc.js new file mode 100644 index 0000000..115cc02 --- /dev/null +++ b/src/miniprogram-1(1)/.eslintrc.js @@ -0,0 +1,31 @@ +/* + * Eslint config file + * Documentation: https://eslint.org/docs/user-guide/configuring/ + * Install the Eslint extension before using this feature. + */ +module.exports = { + env: { + es6: true, + browser: true, + node: true, + }, + ecmaFeatures: { + modules: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + globals: { + wx: true, + App: true, + Page: true, + getCurrentPages: true, + getApp: true, + Component: true, + requirePlugin: true, + requireMiniProgram: true, + }, + // extends: 'eslint:recommended', + rules: {}, +} diff --git a/src/miniprogram-1(1)/app.js b/src/miniprogram-1(1)/app.js new file mode 100644 index 0000000..5a07f0a --- /dev/null +++ b/src/miniprogram-1(1)/app.js @@ -0,0 +1,589 @@ +// app.js +App({ + + onLaunch: function () { + if (!wx.cloud) { + console.error('请使用 2.2.3 或以上的基础库以使用云能力'); + } else { + wx.cloud.init({ + // env 参数说明: + // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 + // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 + // 如不填则使用默认环境(第一个创建的环境) + // env: 'my-env-id', + env: 'cloud1-5ggzbo3kcd4ea4e2', + traceUser: true, + }); + } +}, +//全局变量 +globalData: { +     url: null +   }, + //wx.cloud.callFunction({ + //name:'get', + // data:{ + // name:"", + // pattern:"", + // kind:"", + // style:"", + // colour:"", + // T:"", + // thickness:"", + // season:"" + // }, + // success:res=>{ + // this.globalData.openid=res.result.openid + // }, + // fail:err=>{ + // console.error('[云函数] [login] 调用失败',err) + // } + //}) +globalData:{ + clothes:[{ + name:"t-shirt1", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"white", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt2", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"red", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt3", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"orange", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt4", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"black", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt5", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"red", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt6", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"purple", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt7", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"green", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt8", + pattern:"up", + kind:"t-shirt", + style:"sports", + colour:"white", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt9", + pattern:"up", + kind:"t-shirt", + style:"sports", + colour:"black", + T:-4, + thickness:"thin", + season:"summer" + },{ + name:"t-shirt10", + pattern:"up", + kind:"t-shirt", + style:"leisure", + colour:"blue", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"hoodie1", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"white", + T:2, + thickness:"thin", + season:"spring" + },{ + name:"hoodie2", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"brown", + T:5, + thickness:"thin", + season:"winter" + },{ + name:"hoodie3", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"white", + T:5, + thickness:"thin", + season:"winter" + },{ + name:"hoodie4", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"black", + T:3, + thickness:"proper", + season:"autumn" + },{ + name:"hoodie5", + pattern:"up", + kind:"hoodie", + style:"sports", + colour:"yellow", + T:3, + thickness:"proper", + season:"spring" + },{ + name:"hoodie6", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"black", + T:4, + thickness:"proper", + season:"spring" + },{ + name:"hoodie7", + pattern:"up", + kind:"hoodie", + style:"leisure", + colour:"white", + T:3, + thickness:"proper", + season:"autumn" + },{ + name:"hoodie8", + pattern:"up", + kind:"hoodie", + style:"sports", + colour:"white", + T:3, + thickness:"proper", + season:"autumn" + },{ + name:"hoodie9", + pattern:"up", + kind:"hoodie", + style:"sports", + colour:"pink", + T:5, + thickness:"thick", + season:"winter" + },{ + name:"hoodie10", + pattern:"up", + kind:"hoodie", + style:"sports", + colour:"green", + T:4, + thickness:"proper", + season:"spring" + },{ + name:"skirt1", + pattern:"down", + kind:"skirt", + style:"leisure", + colour:"blue", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"skirt2", + pattern:"down", + kind:"skirt", + style:"business", + colour:"brown", + T:3, + thickness:"thin", + season:"winter" + },{ + name:"skirt3", + pattern:"down", + kind:"skirt", + style:"sport", + colour:"white", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"skirt4", + pattern:"down", + kind:"skirt", + style:"leisure", + colour:"brown", + T:2, + thickness:"proper", + season:"autumn" + },{ + name:"skirt5", + pattern:"all", + kind:"skirt", + style:"leisure", + colour:"red", + T:-10, + thickness:"thin", + season:"summer" + },{ + name:"skirt6", + pattern:"all", + kind:"skirt", + style:"business", + colour:"white", + T:-10, + thickness:"thin", + season:"summer" + },{ + name:"skirt7", + pattern:"all", + kind:"skirt", + style:"leisure", + colour:"black", + T:5, + thickness:"proper", + season:"autumn" + },{ + name:"skirt8", + pattern:"down", + kind:"skirt", + style:"business", + colour:"black", + T:-5, + thickness:"thin", + season:"autumn" + },{ + name:"skirt9", + pattern:"down", + kind:"skirt", + style:"leisure", + colour:"pink", + T:1, + thickness:"proper", + season:"spring" + },{ + name:"skirt10", + pattern:"all", + kind:"skirt", + style:"leisure", + colour:"white", + T:-10, + thickness:"thin", + season:"summer" + },{ + name:"coat1", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"black", + T:5, + thickness:"proper", + season:"autumn" + },{ + name:"coat2", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"white", + T:4, + thickness:"proper", + season:"autumn" + },{ + name:"coat3", + pattern:"up", + kind:"coat", + style:"business", + colour:"white", + T:2, + thickness:"thin", + season:"spring" + },{ + name:"coat4", + pattern:"up", + kind:"coat", + style:"business", + colour:"red", + T:5, + thickness:"thick", + season:"winter" + },{ + name:"coat5", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"white", + T:1, + thickness:"thin", + season:"summer" + },{ + name:"coat6", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"black", + T:9, + thickness:"thick", + season:"winter" + },{ + name:"coat7", + pattern:"up", + kind:"coat", + style:"sports", + colour:"black", + T:3, + thickness:"thin", + season:"spring" + },{ + name:"coat8", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"pink", + T:5, + thickness:"proper", + season:"autumn" + },{ + name:"coat9", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"white", + T:10, + thickness:"thick", + season:"winter" + },{ + name:"coat10", + pattern:"up", + kind:"coat", + style:"leisure", + colour:"khaki", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"sweater1", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"white", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"sweater2", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"black", + T:4, + thickness:"thick", + season:"winter" + },{ + name:"sweater3", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"blue", + T:4, + thickness:"thick", + season:"winter" + },{ + name:"sweater4", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"blue", + T:4, + thickness:"thick", + season:"winter" + },{ + name:"sweater5", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"gray", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"sweater6", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"yellow", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"sweater7", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"yellow", + T:4, + thickness:"thick", + season:"winter" + },{ + name:"sweater8", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"brown", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"sweater9", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"white", + T:4, + thickness:"thick", + season:"winter" + },{ + name:"sweater10", + pattern:"up", + kind:"sweater", + style:"leisure", + colour:"yellow", + T:3, + thickness:"thin", + season:"autumn" + },{ + name:"pants1", + pattern:"down", + kind:"long", + style:"leisure", + colour:"black", + T:1, + thickness:"thin", + season:"spring" + },{ + name:"pants2", + pattern:"down", + kind:"long", + style:"sports", + colour:"white", + T:3, + thickness:"proper", + season:"autumn" + },{ + name:"pants3", + pattern:"down", + kind:"long", + style:"sports", + colour:"purple", + T:1, + thickness:"thin", + season:"summer" + },{ + name:"pants4", + pattern:"down", + kind:"long", + style:"leisure", + colour:"blue", + T:5, + thickness:"thick", + season:"winter" + },{ + name:"pants5", + pattern:"down", + kind:"long", + style:"business", + colour:"gray", + T:3, + thickness:"proper", + season:"autumn" + },{ + name:"pants6", + pattern:"down", + kind:"short", + style:"leisure", + colour:"black", + T:3, + thickness:"proper", + season:"winter" + },{ + name:"pants7", + pattern:"down", + kind:"short", + style:"leisure", + colour:"black", + T:3, + thickness:"proper", + season:"winter" + },{ + name:"pants8", + pattern:"down", + kind:"short", + style:"sports", + colour:"white", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"pants9", + pattern:"down", + kind:"short", + style:"leisure", + colour:"black", + T:-5, + thickness:"thin", + season:"summer" + },{ + name:"pants10", + pattern:"down", + kind:"short", + style:"business", + colour:"brown", + T:-5, + thickness:"thin", + season:"summer" + } +] +}, + + + +}) diff --git a/src/miniprogram-1(1)/app.json b/src/miniprogram-1(1)/app.json new file mode 100644 index 0000000..a8e255b --- /dev/null +++ b/src/miniprogram-1(1)/app.json @@ -0,0 +1,53 @@ +{ + "cloud": true, + "pages": [ + "pages/index/index", + "pages/navigation/index/index", + "pages/navigation/index/show_clothes/show_clothes", + "pages/navigation/index/add/add", + "pages/navigation/index/delete/delete", + "pages/navigation/self/self", + "pages/navigation/userinform/userinform", + "pages/navigation/safety/safety", + "pages/navigation/shezhi/shezhi", + "pages/navigation/index/recommand/recommand", + "pages/navigation/index/add/camera/camera" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "Weixin", + "navigationBarTextStyle": "black" + }, + "usingComponents": { + "van-button": "pages/miniprogram_npm/@vant/weapp/button/index", + "van-tabbar": "pages/miniprogram_npm/@vant/weapp/tabbar/index", + "van-tabbar-item": "pages/miniprogram_npm/@vant/weapp/tabbar-item/index", + "van-image": "pages/miniprogram_npm/@vant/weapp/image/index", + "van-icon": "pages/miniprogram_npm/@vant/weapp/icon/index", + "van-divider": "pages/miniprogram_npm/@vant/weapp/divider/index", + "van-rate": "pages/miniprogram_npm/@vant/weapp/rate/index", + "van-field": "pages/miniprogram_npm/@vant/weapp/field/index", + "van-toast": "pages/miniprogram_npm/@vant/weapp/toast/index" + }, + "sitemapLocation": "sitemap.json", + "tabBar": { + "selectedColor": "#5001", + "backgroundColor": "white", + "borderStyle": "white", + "list": [ + { + "text": "首页", + "pagePath": "pages/navigation/index/index", + "iconPath": "pages/img/首页.png", + "selectedIconPath": "pages/img/首页.png" + }, + { + "text": "我的", + "pagePath": "pages/navigation/self/self", + "iconPath": "pages/img/我的.png", + "selectedIconPath": "pages/img/我的.png" + } + ] + } +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/app.wxss b/src/miniprogram-1(1)/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/src/miniprogram-1(1)/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/src/miniprogram-1(1)/cloudfunctions/get/config.json b/src/miniprogram-1(1)/cloudfunctions/get/config.json new file mode 100644 index 0000000..5ecc33e --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/get/config.json @@ -0,0 +1,6 @@ +{ + "permissions": { + "openapi": [ + ] + } +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/cloudfunctions/get/index.js b/src/miniprogram-1(1)/cloudfunctions/get/index.js new file mode 100644 index 0000000..c77edbb --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/get/index.js @@ -0,0 +1,32 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() // 使用当前云环境 +const db=cloud.database() +const MAX_LIMIT=100 +// 云函数入口函数 +exports.main = async (event, context) => { + const wxContext = cloud.getWXContext() + //先取出集合记录总数 + const countResult=await db.collection('cloth').count() + const total=countResult.total + //计算分几次取 + const batchTimes = Math.ceil(total / 100) + // 承载所有读操作的 promise 的数组 + const tasks = [] + for (let i = 0; i < batchTimes; i++) { + const promise = db.collection('cloth').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get() + tasks.push(promise) + } + // 等待所有 + return (await Promise.all(tasks)).reduce((acc, cur) => { + return { + event, + openid: wxContext.OPENID, + appid: wxContext.APPID, + unionid: wxContext.UNIONID, + data: acc.data.concat(cur.data), + errMsg: acc.errMsg, + } + }) +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/cloudfunctions/get/package.json b/src/miniprogram-1(1)/cloudfunctions/get/package.json new file mode 100644 index 0000000..e7978fe --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/get/package.json @@ -0,0 +1,14 @@ +{ + "name": "get", + "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.6.3" + } +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/config.json b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/config.json new file mode 100644 index 0000000..41a485c --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/config.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "openapi": [ + "wxacode.get" + ] + } +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/createCollection/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/createCollection/index.js new file mode 100644 index 0000000..75a40b9 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/createCollection/index.js @@ -0,0 +1,56 @@ +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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js new file mode 100644 index 0000000..08e1a82 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getMiniProgramCode/index.js @@ -0,0 +1,20 @@ +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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getOpenId/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getOpenId/index.js new file mode 100644 index 0000000..94b7b94 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/getOpenId/index.js @@ -0,0 +1,17 @@ +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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/index.js new file mode 100644 index 0000000..d137f69 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/index.js @@ -0,0 +1,25 @@ +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'); + + +// 云函数入口函数 +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); + } +}; diff --git a/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/package.json b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/package.json new file mode 100644 index 0000000..4350dbb --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/package.json @@ -0,0 +1,14 @@ +{ + "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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/selectRecord/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/selectRecord/index.js new file mode 100644 index 0000000..c7848a7 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/selectRecord/index.js @@ -0,0 +1,12 @@ +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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/sumRecord/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/sumRecord/index.js new file mode 100644 index 0000000..dfdc293 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/sumRecord/index.js @@ -0,0 +1,18 @@ +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/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/updateRecord/index.js b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/updateRecord/index.js new file mode 100644 index 0000000..2ce3ad0 --- /dev/null +++ b/src/miniprogram-1(1)/cloudfunctions/quickstartFunctions/updateRecord/index.js @@ -0,0 +1,32 @@ +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/src/miniprogram-1(1)/project.config.json b/src/miniprogram-1(1)/project.config.json new file mode 100644 index 0000000..52cb98e --- /dev/null +++ b/src/miniprogram-1(1)/project.config.json @@ -0,0 +1,47 @@ +{ + "cloudfunctionRoot": "cloudfunctions/", + "appid": "wx12b2fc1f01d3220c", + "compileType": "miniprogram", + "libVersion": "2.27.0", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "urlCheck": true, + "coverView": true, + "es6": true, + "postcss": true, + "lazyloadPlaceholderEnable": false, + "preloadBackgroundData": false, + "minified": true, + "autoAudits": false, + "uglifyFileName": false, + "uploadWithSourceMap": true, + "enhance": true, + "useMultiFrameRuntime": true, + "showShadowRootInWxmlPanel": true, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "useStaticServer": true, + "showES6CompileOption": false, + "checkInvalidKey": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "disableUseStrict": false, + "useCompilerPlugins": false, + "minifyWXML": true + }, + "condition": {}, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 2 + }, + "description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "miniprogram-1(1)", + "srcMiniprogramRoot": "miniprogram/" +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/project.private.config.json b/src/miniprogram-1(1)/project.private.config.json new file mode 100644 index 0000000..175540c --- /dev/null +++ b/src/miniprogram-1(1)/project.private.config.json @@ -0,0 +1,34 @@ +{ + "projectname": "miniprogram-1(1)", + "setting": { + "compileHotReLoad": true + }, + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "condition": { + "miniprogram": { + "list": [ + { + "name": "", + "pathName": "pages/navagation/show", + "query": "", + "launchMode": "default", + "scene": null + }, + { + "name": "", + "pathName": "pages/navagation/show_clothes", + "query": "", + "launchMode": "default", + "scene": null + }, + { + "name": "", + "pathName": "pages/navigation/index/index", + "query": "", + "launchMode": "default", + "scene": null + } + ] + } + } +} \ No newline at end of file diff --git a/src/miniprogram-1(1)/sitemap.json b/src/miniprogram-1(1)/sitemap.json new file mode 100644 index 0000000..cd24f35 --- /dev/null +++ b/src/miniprogram-1(1)/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file