Skip to content

Commit a10deb9

Browse files
committed
新增云开发示例
1 parent 4a6b4a1 commit a10deb9

File tree

518 files changed

+4073
-1226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

518 files changed

+4073
-1226
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// 云函数入口文件
2+
const cloud = require('wx-server-sdk')
3+
4+
// 云函数入口函数
5+
exports.main = async () => {
6+
cloud.init({
7+
env: process.env.TCB_ENV,
8+
})
9+
const db = cloud.database()
10+
return db.collection('perm4').where({
11+
_openid: 'server'
12+
}).limit(1).get()
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "getServerDataDemo",
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// 云函数入口文件
2+
const cloud = require('wx-server-sdk')
3+
4+
// 云函数入口函数
5+
exports.main = async (event) => {
6+
cloud.init({
7+
env: process.env.TCB_ENV,
8+
})
9+
const fileList = event.fileIdList
10+
const result = await cloud.getTempFileURL({
11+
fileList,
12+
})
13+
return result.fileList
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "getTempFileURL",
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+
}

cloudfunctions/wxContext/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// 云函数入口文件
2+
const cloud = require('wx-server-sdk')
3+
4+
cloud.init()
5+
6+
// 云函数入口函数
7+
exports.main = async () => {
8+
const wxContext = cloud.getWXContext()
9+
10+
return {
11+
openid: wxContext.OPENID,
12+
appid: wxContext.APPID,
13+
unionid: wxContext.UNIONID,
14+
}
15+
}

cloudfunctions/wxContext/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "wxContext",
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+
}

app.js renamed to miniprogram/app.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
const openIdUrl = require('./config').openIdUrl
1+
const config = require('./config')
22

33
App({
44
onLaunch(opts) {
55
console.log('App Launch', opts)
6+
if (!wx.cloud) {
7+
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
8+
} else {
9+
wx.cloud.init({
10+
env: config.envId,
11+
traceUser: true,
12+
})
13+
}
614
},
715
onShow(opts) {
816
console.log('App Show', opts)
@@ -24,7 +32,7 @@ App({
2432
wx.login({
2533
success(data) {
2634
wx.request({
27-
url: openIdUrl,
35+
url: config.openIdUrl,
2836
data: {
2937
code: data.code
3038
},
@@ -45,5 +53,15 @@ App({
4553
}
4654
})
4755
}
56+
},
57+
// 通过云函数获取用户 openid,支持回调或 Promise
58+
getUserOpenIdViaCloud() {
59+
return wx.cloud.callFunction({
60+
name: 'wxContext',
61+
data: {}
62+
}).then(res => {
63+
this.globalData.openid = res.result.openid
64+
return res.result.openid
65+
})
4866
}
4967
})

app.json renamed to miniprogram/app.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,24 @@
8989
"page/API/pages/setting/setting",
9090
"page/API/pages/choose-invoice-title/choose-invoice-title",
9191
"page/API/pages/soter-authentication/soter-authentication",
92-
"page/component/pages/map-styles/map-styles"
92+
"page/component/pages/map-styles/map-styles",
93+
"page/cloud/index",
94+
"page/cloud/pages/user-authentication/user-authentication",
95+
"page/cloud/pages/get-wx-context/get-wx-context",
96+
"page/cloud/pages/upload-file/upload-file",
97+
"page/cloud/pages/download-file/download-file",
98+
"page/cloud/pages/get-temp-file-url/get-temp-file-url",
99+
"page/cloud/pages/delete-file/delete-file",
100+
"page/cloud/pages/cloud-file-component/cloud-file-component",
101+
"page/cloud/pages/crud/crud",
102+
"page/cloud/pages/crud-detail/crud-detail",
103+
"page/cloud/pages/db-permission/db-permission",
104+
"page/cloud/pages/server-date/server-date",
105+
"page/cloud/pages/scf-database/scf-database",
106+
"page/cloud/pages/scf-storage/scf-storage",
107+
"page/component/pages/doc-web-view/doc-web-view",
108+
"page/API/pages/doc-web-view/doc-web-view",
109+
"page/cloud/pages/doc-web-view/doc-web-view"
93110
],
94111
"window": {
95112
"navigationBarTextStyle": "black",
@@ -114,6 +131,12 @@
114131
"iconPath": "image/icon_API.png",
115132
"selectedIconPath": "image/icon_API_HL.png",
116133
"text": "接口"
134+
},
135+
{
136+
"pagePath": "page/cloud/index",
137+
"iconPath": "image/icon_cloud.png",
138+
"selectedIconPath": "image/icon_cloud_HL.png",
139+
"text": "云开发"
117140
}
118141
]
119142
},
@@ -132,5 +155,6 @@
132155
"scope.userLocation": {
133156
"desc": "你的位置信息将用于小程序位置接口的效果展示"
134157
}
135-
}
136-
}
158+
},
159+
"cloud": true
160+
}
File renamed without changes.

config.js renamed to miniprogram/config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ const config = {
3737
uploadFileUrl: `https://${host}/upload`,
3838

3939
// 下载示例图片接口
40-
downloadExampleUrl: `https://${host}/static/weapp.jpg`
40+
downloadExampleUrl: `https://${host}/static/weapp.jpg`,
41+
42+
// 云开发环境 ID
43+
envId: 'release-b86096',
44+
45+
// 云开发-存储 示例文件的文件 ID
46+
demoImageFileId: 'cloud://release-b86096.7265-release-b86096/demo.jpg',
47+
demoVideoFileId: 'cloud://release-b86096.7265-release-b86096/demo.mp4',
4148
}
4249

4350
module.exports = config
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

miniprogram/image/icon_cloud.png

4.29 KB

miniprogram/image/icon_cloud_HL.png

2.67 KB
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

page/API/index.wxml renamed to miniprogram/page/API/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<view wx:else class="index">
33
<view class="index-hd">
44
<image class="index-logo" src="resources/kind/logo.png"></image>
5-
<view class="index-desc">以下将演示小程序接口能力,具体属性参数详见小程序开发文档。</view>
5+
<view class="index-desc">以下将演示小程序接口能力,具体属性参数详见 <navigator url="pages/doc-web-view/doc-web-view" class="weui-agree__link">小程序开发文档</navigator>。</view>
66
</view>
77
<view class="index-bd">
88
<view class="kind-list">

miniprogram/page/API/index.wxss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "../common/index.wxss";
2+
3+
.weui-agree__link {
4+
display: inline;
5+
color: #586c94;
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
2-
.cancel {
3-
color: white;
4-
background: #303F9F;
5-
}
6-
.item {
7-
color: black;
8-
background: #C5CAE9;
9-
}*/
1+
/*
2+
.cancel {
3+
color: white;
4+
background: #303F9F;
5+
}
6+
.item {
7+
color: black;
8+
background: #C5CAE9;
9+
}*/
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
<import src="../../../common/head.wxml" />
2-
<import src="../../../common/foot.wxml" />
3-
4-
<view class="container">
5-
<template is="head" data="{{title: 'createAnimation'}}"/>
6-
7-
<view class="page-body">
8-
<view class="page-section">
9-
10-
<view class="animation-element-wrapper">
11-
<view class="animation-element" animation="{{animation}}"></view>
12-
</view>
13-
<scroll-view class="animation-buttons" scroll-y="true">
14-
<button class="animation-button" bindtap="rotate">旋转</button>
15-
<button class="animation-button" bindtap="scale">缩放</button>
16-
<button class="animation-button" bindtap="translate">移动</button>
17-
<button class="animation-button" bindtap="skew">倾斜</button>
18-
<button class="animation-button" bindtap="rotateAndScale">旋转并缩放</button>
19-
<button class="animation-button" bindtap="rotateThenScale">旋转后缩放</button>
20-
<button class="animation-button" bindtap="all">同时展示全部</button>
21-
<button class="animation-button" bindtap="allInQueue">顺序展示全部</button>
22-
<button class="animation-button animation-button-reset" bindtap="reset">还原</button>
23-
</scroll-view>
24-
</view>
25-
</view>
26-
27-
<template is="foot" />
28-
</view>
1+
<import src="../../../common/head.wxml" />
2+
<import src="../../../common/foot.wxml" />
3+
4+
<view class="container">
5+
<template is="head" data="{{title: 'createAnimation'}}"/>
6+
7+
<view class="page-body">
8+
<view class="page-section">
9+
10+
<view class="animation-element-wrapper">
11+
<view class="animation-element" animation="{{animation}}"></view>
12+
</view>
13+
<scroll-view class="animation-buttons" scroll-y="true">
14+
<button class="animation-button" bindtap="rotate">旋转</button>
15+
<button class="animation-button" bindtap="scale">缩放</button>
16+
<button class="animation-button" bindtap="translate">移动</button>
17+
<button class="animation-button" bindtap="skew">倾斜</button>
18+
<button class="animation-button" bindtap="rotateAndScale">旋转并缩放</button>
19+
<button class="animation-button" bindtap="rotateThenScale">旋转后缩放</button>
20+
<button class="animation-button" bindtap="all">同时展示全部</button>
21+
<button class="animation-button" bindtap="allInQueue">顺序展示全部</button>
22+
<button class="animation-button animation-button-reset" bindtap="reset">还原</button>
23+
</scroll-view>
24+
</view>
25+
</view>
26+
27+
<template is="foot" />
28+
</view>
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
.animation-element-wrapper {
2-
display: flex;
3-
width: 100%;
4-
padding-top: 150rpx;
5-
padding-bottom: 150rpx;
6-
justify-content: center;
7-
overflow: hidden;
8-
background-color: #ffffff;
9-
}
10-
.animation-element {
11-
width: 200rpx;
12-
height: 200rpx;
13-
background-color: #1AAD19;
14-
}
15-
.animation-buttons {
16-
padding: 30rpx 50rpx 10rpx;
17-
width: 100%;
18-
height: 360rpx;
19-
box-sizing: border-box;
20-
}
21-
.animation-button {
22-
float: left;
23-
line-height: 2;
24-
width: 300rpx;
25-
margin: 15rpx 12rpx;
26-
}
27-
28-
.animation-button-reset {
29-
width: 620rpx;
30-
}
1+
.animation-element-wrapper {
2+
display: flex;
3+
width: 100%;
4+
padding-top: 150rpx;
5+
padding-bottom: 150rpx;
6+
justify-content: center;
7+
overflow: hidden;
8+
background-color: #ffffff;
9+
}
10+
.animation-element {
11+
width: 200rpx;
12+
height: 200rpx;
13+
background-color: #1AAD19;
14+
}
15+
.animation-buttons {
16+
padding: 30rpx 50rpx 10rpx;
17+
width: 100%;
18+
height: 360rpx;
19+
box-sizing: border-box;
20+
}
21+
.animation-button {
22+
float: left;
23+
line-height: 2;
24+
width: 300rpx;
25+
margin: 15rpx 12rpx;
26+
}
27+
28+
.animation-button-reset {
29+
width: 620rpx;
30+
}

0 commit comments

Comments
 (0)