微信登录版

This commit is contained in:
qianlile
2021-08-28 11:30:34 +08:00
parent 7af68fee6b
commit 33aecb6bda
432 changed files with 13362 additions and 0 deletions

View File

@@ -0,0 +1,189 @@
// miniprogram/pages/4Gswitch/index.js
const { request } = require('../../API/request')
Page({
/**
* 页面的初始数据
*/
data: {
deviceInfo:{},
deviceId:null,
lightStatus:null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setNavigate();
try {
this.getLastPageData();
} catch (error) {
console.log(error);
}
this.isShared(options);
},
checkLogin(){
const isLogin = wx.getStorageSync('isLogin') || false;
const that = this;
if (!isLogin) {
wx.showModal({
cancelColor: '#ff0000',
cancelText: '取消',
confirmColor: '#6149f6',
confirmText: '登录',
content: '检测到您还未登录,是否授权登录?',
showCancel: true,
title: '登录授权',
success: (result) => {
if (result.confirm) {
wx.showLoading({
title: '正在登录'
});
wx.getUserProfile({
desc:'用以展示您的头像和昵称等信息',
success(res){
console.log(res);
wx.setStorageSync('userInfo',JSON.parse(res.rawData));
wx.setStorageSync('isLogin',true);
},
complete(){
wx.hideLoading();
},
fail(err){
if (err.errMsg == 'getUserProfile:fail auth deny') {
wx.showToast({
title: '授权取消',
icon:'error'
})
}
}
})
}else if(result.cancel){
wx.switchTab({
url: '/pages/my/my',
})
}
}
})
}
},
setNavigate(){
wx.setNavigationBarTitle({
title: '4G开关',
});
wx.setNavigationBarColor({
backgroundColor: '#4271f1',
frontColor: '#ffffff',
});
},
getLastPageData(){
const eventChannel = this.getOpenerEventChannel();
const that = this;
eventChannel.on('getDeviceInfo',async (data)=>{
that.setData({
deviceId:data
})
})
},
async getDeviceDetail(){
let deviceId = this.data.deviceId;
const res = await request(`system/device/getDeviceInfoByDeviceId?deviceId=${deviceId}`,'get');
console.log(res);
if (res.code === 200) {
this.setData({
deviceInfo:res.data,
lightStatus:res.data.lightStatus
})
}
},
async lightPower(){
let lightStatus = this.data.lightStatus;
let deviceInfo = this.data.deviceInfo;
if (!deviceInfo.isOnline) {
wx.showToast({
title: '设备离线',
icon:'error',
mask:true
});
return;
}
if(lightStatus){
var res = await request('system/device/control','post',{
deviceNum:deviceInfo.deviceNum,
cmd:'off'
})
}else if(!lightStatus){
var res = await request('system/device/control','post',{
deviceNum:deviceInfo.deviceNum,
cmd:'on'
})
}
if (res.code === 200) {
this.setData({ lightStatus:!lightStatus })
}
},
//打开分享的页面
async isShared(options){
if (options.hasOwnProperty('deviceInfo')) {
this.checkLogin();
const deviceInfo = JSON.parse(options.deviceInfo);
this.setData({
deviceInfo
})
const res = await request('system/device/bindDevice','post',{
deviceNum:deviceInfo.deviceNum,
deviceName:deviceInfo.deviceName,
categoryId:deviceInfo.categoryId,
remark:deviceInfo.remark
});
const result = await request(`system/status/new/${deviceInfo.deviceId}`,'GET');
this.setData({
power:result.data.lightStatus,
isOnline:result.data.isOnline
});
}
},
lookDetail(e){
wx.navigateTo({
url: '/pages/deviceDetail/index',
success: (result) => {
result.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info);
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getDeviceDetail();
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (e) {
return {
title:"我分享了一个设备。",
path:`/pages/4Gswitch/index?deviceInfo=${JSON.stringify(e.target.dataset.info)}&&isShare=1`,
imageUrl:'/icons/smart.jpg'
}
}
})

View File

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@@ -0,0 +1,32 @@
<!--miniprogram/pages/4Gswitch/index.wxml-->
<view class="name">
<text style="margin-right:15rpx">{{ deviceInfo.deviceName }}</text>
<view>
<van-tag mark type="success">{{ deviceInfo.categoryName }}</van-tag>
</view>
</view>
<view>
<view class="outside" style="{{(lightStatus == true) ?'background-image: radial-gradient(#6149f6 10%,#b0e6ff 100%)':'background-color: #dadada;'}}">
<view class="inside" bindtap="lightPower">
<image wx:if="{{ lightStatus == false }}" class="switch" src="/icons/switch_off.png"></image>
<image wx:if="{{ lightStatus == true }}" class="switch" src="/icons/switch_on.png"></image>
</view>
</view>
<view class="power">
<text>开关状态:</text>
<text wx:if="{{ lightStatus == true }}" style="color:#0000ff">开</text>
<text wx:if="{{ lightStatus == false }}" style="color:#ff0000">关</text>
</view>
</view>
<view class="bottom">
<view class="bottom-item">
<image src="/icons/share.png"></image>
<text>分享</text>
<button class="share" open-type="share" data-info = "{{ deviceInfo }}"></button>
</view>
<view class="bottom-item" bindtap="lookDetail" data-info="{{ deviceInfo }}">
<image src="/icons/detail.png"></image>
<text>详情</text>
</view>
</view>

View File

@@ -0,0 +1,77 @@
/* miniprogram/pages/4Gswitch/index.wxss */
page{
background-color: #ffffff;
}
.name{
width: 60%;
margin: 15vh auto 30rpx;
text-align: center;
font-size: 42rpx;
}
.outside{
margin: 50rpx auto;
width: 60vw;
height: 60vw;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
/* border: 1rpx solid #666; */
}
.inside{
width: 80%;
height: 80%;
border-radius: 50%;
background-color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 0 8rpx #bfbfbf;
}
.inside:active{
transform: translateY(5rpx);
}
.switch{
width: 25%;
height: 25%;
}
.power{
width: 60%;
margin: 30rpx auto;
text-align: center;
font-size: larger;
}
.bottom{
position: fixed;
bottom: 0;
left: 0;
width: 100vw;
height: 100rpx;
display: flex;
}
.bottom-item{
position: relative;
flex: 1;
display: flex;
justify-content: center;
align-items: center;
background-color: #4271f1;
border: 1rpx solid #bfbfbf;
color: #ffffff;
}
.bottom-item>image{
width: 44rpx;
height: 44rpx;
margin: 0 10rpx;
}
.bottom-item:active{
background-color: #0044ff;
}
.share{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}