Skip to content

Commit

Permalink
cloud function and database init
Browse files Browse the repository at this point in the history
  • Loading branch information
infinityu committed Jan 8, 2020
1 parent 22936d6 commit 34f240b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
},
onLaunch: function() {
console.log('App Launch');
wx.cloud.init({
traceUser: true,
env: 'typo-battle-prdct-05f8e4'
});
uni.getSystemInfo({
success: function(e) {
// #ifdef MP-WEIXIN
Expand Down
17 changes: 17 additions & 0 deletions functions/wish/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()

return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
sum: event.a + event.b
}
}
14 changes: 14 additions & 0 deletions functions/wish/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "wish",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "latest"
}
}
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "wxb3e0c4ce12fa8606",
"cloudfunctionRoot": "./functions/",
"setting" : {
"urlCheck" : false
},
Expand Down
41 changes: 38 additions & 3 deletions pages/wish/wish-swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
export default {
data() {
return {
imgPath: "https://mina-img-store-1258554429.cos.ap-shanghai.myqcloud.com/new-year-wish/",
return {
wish_db: null,
windowHeight: 800,
windowWidth: 400,
currentPageIndex: 0,
Expand Down Expand Up @@ -226,7 +226,42 @@
});
},
onLoad() {
console.log("onLoad");
console.log("onLoad");
const db = wx.cloud.database({
env: 'typo-battle-prdct-05f8e4'
})
this.wish_db = db.collection('wish_redirect');
// this.wish_db.add({
// // data 字段表示需新增的 JSON 数据
// data: {
// // _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了
// description: "learn cloud database",
// due: new Date("2018-09-01"),
// tags: [
// "cloud",
// "database"
// ],
// // 为待办事项添加一个地理位置(113°E,23°N)
// location: new db.Geo.Point(113, 23),
// done: false
// },
// success: function(res) {
// // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
// console.log(res)
// },
// fail: function(res){
// console.log(res);
// }
// })
wx.cloud.callFunction({
name: 'wish',
complete: res => {
console.log('callFunction wish result: ', res)
}
})
// load background music
const bgAudioMannager = uni.getBackgroundAudioManager();
bgAudioMannager.title = '春节序曲';
bgAudioMannager.singer = '中华人民解放军军乐团';
Expand Down
15 changes: 15 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
configureWebpack: {
plugins: [
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'functions'),
to: path.join(__dirname, 'unpackage/dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM, 'functions')
}
])
]
}
}

0 comments on commit 34f240b

Please sign in to comment.