first commit for opensource

first commit for opensource
This commit is contained in:
supowang
2019-09-16 13:19:50 +08:00
parent 08ab013b8e
commit edb2879617
6303 changed files with 5472815 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
//app.js
App({
globalData: {
// 腾讯云物联网开发平台explorer中获取 产品ID和设备名称
productId: "U2LPAXBT2C", // 产品ID
deviceName: "royye_light", // 设备名称
// 腾讯云控制台-访问管理-访问密钥-API密钥管理中获取 SecretId, secretKey
secretId: "AKIDxZ2LTTi84eaR3OfS8hnfxd4JHzQatFpF",
secretKey: "UigMrA9rJXUCeoiBQP8dsJuJ6sYzmNjs",
// 接口 Region 字段
region: "ap-guangzhou",
// 云开发的环境名称。此处需要替换为云开发创建的环境名称
env: "tos-demo"
},
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
// env 参数说明:
// env 参数决定接下来小程序发起的云开发调用wx.cloud.xxx会默认请求到哪个云环境的资源
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// 如不填则使用默认环境(第一个创建的环境)
env: this.globalData.env,
traceUser: true,
})
}
}
})

View File

@@ -0,0 +1,13 @@
{
"pages": [
"pages/index/index"
],
"window": {
"backgroundColor": "#F6F6F6",
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#F6F6F6",
"navigationBarTitleText": "智能灯云开发Demo",
"navigationBarTextStyle": "black"
},
"sitemapLocation": "sitemap.json"
}

View File

@@ -0,0 +1,156 @@
/**app.wxss**/
.container {
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
}
button {
background: initial;
}
button:focus{
outline: 0;
}
button::after{
border: none;
}
page {
background: #f6f6f6;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.userinfo, .uploader, .tunnel {
margin-top: 40rpx;
height: 140rpx;
width: 100%;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.1);
border-left: none;
border-right: none;
display: flex;
flex-direction: row;
align-items: center;
transition: all 300ms ease;
}
.userinfo-avatar {
width: 100rpx;
height: 100rpx;
margin: 20rpx;
border-radius: 50%;
background-size: cover;
background-color: white;
}
.userinfo-avatar:after {
border: none;
}
.userinfo-nickname {
font-size: 32rpx;
color: #007aff;
background-color: white;
background-size: cover;
}
.userinfo-nickname::after {
border: none;
}
.uploader, .tunnel {
height: auto;
padding: 0 0 0 40rpx;
flex-direction: column;
align-items: flex-start;
box-sizing: border-box;
}
.uploader-text, .tunnel-text {
width: 100%;
line-height: 52px;
font-size: 34rpx;
color: #007aff;
}
.uploader-container {
width: 100%;
height: 400rpx;
padding: 20rpx 20rpx 20rpx 0;
display: flex;
align-content: center;
justify-content: center;
box-sizing: border-box;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.uploader-image {
width: 100%;
height: 360rpx;
}
.tunnel {
padding: 0 0 0 40rpx;
}
.tunnel-text {
position: relative;
color: #222;
display: flex;
flex-direction: row;
align-content: center;
justify-content: space-between;
box-sizing: border-box;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.tunnel-text:first-child {
border-top: none;
}
.tunnel-switch {
position: absolute;
right: 20rpx;
top: -2rpx;
}
.disable {
color: #888;
}
.service {
position: fixed;
right: 40rpx;
bottom: 40rpx;
width: 140rpx;
height: 140rpx;
border-radius: 50%;
background: linear-gradient(#007aff, #0063ce);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
display: flex;
align-content: center;
justify-content: center;
transition: all 300ms ease;
}
.service-button {
position: absolute;
top: 40rpx;
}
.service:active {
box-shadow: none;
}
.request-text {
padding: 20rpx 0;
font-size: 24rpx;
line-height: 36rpx;
word-break: break-all;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -0,0 +1,123 @@
const app = getApp()
Page({
data: {
client: null,
deviceData: {},
items: [
{ name: '红色', value: 0, color: "red"},
{ name: '绿色', value: 1, color: "green" },
{ name: '蓝色', value: 2, color: "blue" },
]
},
onLoad: function (options) {
console.log("index onLoad")
if (!app.globalData.productId) {
wx.showToast({
title: "产品ID不能为空",
icon: 'none',
duration: 3000
})
return
} else if (!app.globalData.deviceName) {
wx.showToast({
title: "设备名称不能为空",
icon: 'none',
duration: 3000
})
return
} else if (!app.globalData.secretId) {
wx.showToast({
title: "访问密钥SecretId不能为空",
icon: 'none',
duration: 3000
})
return
} else if (!app.globalData.secretKey) {
wx.showToast({
title: "访问密钥SecretKey不能为空",
icon: 'none',
duration: 3000
})
return
}
this.setData({
productId: app.globalData.productId,
deviceName: app.globalData.deviceName,
})
this.queryDeviceData()
},
queryDeviceData()
{
wx.showLoading()
let queryData = {
productId: app.globalData.productId,
deviceName: app.globalData.deviceName,
secretId: app.globalData.secretId,
secretKey: app.globalData.secretKey,
region: app.globalData.region,
}
console.log(queryData);
wx.cloud.callFunction({
name: 'query',
data: queryData,
success: res => {
wx.showToast({
title: '调用成功',
})
let deviceData = JSON.parse(res.result.Data)
this.setData({
deviceData: deviceData
})
console.log("result:", deviceData)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '调用失败',
})
console.error('[云函数] [iotexplorer] 调用失败:', err)
}
})
},
controlDeviceData(e) {
wx.showLoading()
let data = e.detail.value
if (data.power_switch == true) {
data.power_switch = 1
} else {
data.power_switch = 0
}
console.log('form data', data)
let controlData = {
productId: app.globalData.productId,
deviceName: app.globalData.deviceName,
secretId: app.globalData.secretId,
secretKey: app.globalData.secretKey,
region: app.globalData.region,
data: JSON.stringify(data),
}
console.log(controlData);
wx.cloud.callFunction({
name: 'control',
data: controlData,
success: res => {
wx.showToast({
title: '调用成功',
})
console.log(res.result)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '调用失败:' + err,
})
console.error('[云函数] [iotexplorer] 调用失败:', err)
}
})
},
})

View File

@@ -0,0 +1,57 @@
<view style="display:flex; flex-direction:column; align-items:center;">
<image style="width:80px; height:80px;" src="../../images/led.png" mode="cover"></image>
</view>
<view class="body">
<view style="font-weight: bold;">
设备信息
</view>
<view class="box">
<view class="cell">
<view class="status-left">产品ID</view>
<view class="status-right">{{productId}}</view>
</view>
<view class="cell">
<view class="status-left">设备名称</view>
<view class="status-right">{{deviceName}}</view>
</view>
</view>
<text>\n</text>
<form bindsubmit="controlDeviceData">
<view style="display:flex; flex-direction:row; justify-content: space-between;">
<view style="font-weight: bold;">
智能灯云开发Demo
</view>
<view>
<button type="primary" size="mini" bindtap="queryDeviceData">查询</button>
<button style="margin-left:20rpx" type="primary" size="mini" form-type="submit">发送</button>
</view>
</view>
<view class="box">
<view class="cell">
<view>开关</view>
<view>
<switch name="power_switch" checked="{{deviceData.power_switch.Value}}" />
</view>
</view>
<view class="cell">
<view>颜色</view>
<view>
<radio-group name="color">
<label style="color:{{item.color}}" class="radio" wx:for="{{items}}" wx:key="unique" wx:for-index="idx">
<radio color="{{item.color}}" value="{{item.value}}" checked="{{idx == deviceData.color.Value}}" />{{item.name}}
</label>
</radio-group>
</view>
</view>
<view class="cell">
<view>亮度</view>
<view style="width:80%">
<slider name="brightness" min="0" max="100" value="{{deviceData.brightness.Value}}" show-value/>
</view>
</view>
</view>
</form>
</view>

View File

@@ -0,0 +1,16 @@
.body {
margin: 10rpx 20rpx;
}
.box {
padding: 0rpx 20rpx;
border-top: 2px solid #000;
}
.cell {
margin-top: 10rpx;
margin-bottom: 40rpx;
display: flex;
justify-content: space-between;
align-items: center;
}

View File

@@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}