Skip to content

Commit

Permalink
feat: add new demo
Browse files Browse the repository at this point in the history
  • Loading branch information
bestony committed Dec 20, 2019
1 parent 02a9460 commit ca82f6a
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 0 deletions.
14 changes: 14 additions & 0 deletions miniprogram/tcb-demo-happy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 腾讯云云开发圣诞祝福

这是云开发团队为云开发者特制的圣诞祝福,在打开后请按照下述步骤完成配置,即可看到:

- 开通云开发
- 在云开发下创建一个数据库,名称为happy;
- 将cloudfunctions/database文件夹下的json文件导入happy数据库
- 将cloudfunctions/getbless右键创建云函数
- 重新编译运行,即可看到祝福哦

## 参考文档

- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)

10 changes: 10 additions & 0 deletions miniprogram/tcb-demo-happy/cloudfunctions/getbless/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const cloud = require('wx-server-sdk')

cloud.init();
const db = cloud.database();

exports.main = async (event, context) => {
let ibless = (await db.collection('happy').doc('mess').get()).data.bless;
let lucky = Math.floor(Math.random() * ibless.length);
return ibless[lucky];
}
14 changes: 14 additions & 0 deletions miniprogram/tcb-demo-happy/cloudfunctions/getbless/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "getbless",
"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"
}
}
9 changes: 9 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App({
onLaunch(){
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init();
}
}
});
11 changes: 11 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"pages": [
"index/index"
],
"window": {
"navigationBarBackgroundColor": "#f3302d",
"navigationBarTitleText": "",
"navigationBarTextStyle": "white"
},
"sitemapLocation": "sitemap.json"
}
7 changes: 7 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
page{
background-color: #f3302d;
padding-top: 15px;
}
button::after{
border: none;
}
38 changes: 38 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Page({
data: {
dear:'亲爱的微信小程序开发者:',
message:'圣诞快乐!感谢你对腾讯云云开发的支持,我们的进步离不开你的努力。我们会与你携手共进,一起去发现更多可能。',
me:'——腾讯云云开发团队'
},
Getbless:function(){
wx.showLoading({
title: '获取祝福中',
})
wx.cloud.callFunction({
name:'getbless',
success(res){
wx.hideLoading();
wx.showModal({
title: '圣诞快乐',
content: res.result,
showCancel: false,
confirmText: '收下'
})
},
fail(e){
wx.hideLoading();
wx.showModal({
title: '圣诞快乐',
content: '内容走丢了,请连接网络重试吧!',
showCancel:false
})
}
})
},
onShareAppMessage:function(){
return {
title:"【云开发】圣诞节祝福卡片",
imageUrl:'https://636c-cloud-cmm55-1300478727.tcb.qcloud.la/happy/share.png'
}
}
})
3 changes: 3 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
15 changes: 15 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<view class="mywish">Merry Christmas!</view>

<button class="mytouch" bindtap="Getbless">来个圣诞祝福</button>

<view class="mycard">
<view class="mycard_text">
<view class="card_title">{{dear}}</view>
<view class="card_text">{{message}}</view>
<view class="card_bottom">{{me}}</view>
</view>
</view>

<image class="myimage"
src="cloud://cloud-cmm55.636c-cloud-cmm55-1300478727/happy/bottom.png"
mode="widthFix"></image>
63 changes: 63 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.mywish{
font-size: 25px;
color: #ecb444;
font-weight: 900;
text-align: center;
}

.myblessbox{
margin:25px 12px;
color: white;
font-size: 12px;
}

.myblessitem{
margin-bottom: 12px;
letter-spacing: 1px;
}

.mytouch{
margin-top: 25px;
width: 75%;
font-size: 15px;
font-weight: 900;
background-color: #30c07a;
color: #fdf8e5;
}

.mycard{
width: 75%;
margin: 25px auto;
padding: 15px;
background-color: rgb(238, 231, 234);
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
}

.mycard_text{
font-size: 13px;
height: calc(100% - 30px);
padding: 10px;
border: 5px solid #f3302d;
color: rgb(95, 90, 78);
}

.card_title{
line-height: 4;
font-weight:bold;
}

.card_text{
line-height: 1.8;
}

.card_bottom{
line-height: 4;
text-align: right;
font-weight:bold;
}

.myimage{
width: 100%;
position: fixed;
bottom:0;
}
7 changes: 7 additions & 0 deletions miniprogram/tcb-demo-happy/miniprogram/sitemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
44 changes: 44 additions & 0 deletions miniprogram/tcb-demo-happy/project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"miniprogramRoot": "miniprogram/",
"cloudfunctionRoot": "cloudfunctions/",
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"enhance": true
},
"appid": "",
"projectname": "happy",
"libVersion": "2.8.1",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"list": []
},
"miniprogram": {
"current": 0,
"list": [
{
"id": -1,
"name": "db guide",
"pathName": "pages/databaseGuide/databaseGuide"
}
]
}
}
}

0 comments on commit ca82f6a

Please sign in to comment.