跳到主要内容

2 篇博文 含有标签「uniapp」

查看所有标签

uniapp发布H5后PC file协议打开,禁用模拟移动端显示

· 阅读需 1 分钟
xuenhua

uniapp发布H5后PC file协议打开,禁用模拟移动端显示

"h5" : {
"template" : "template.h5.html",//PC预览时提示扫码二维码查看,删除后直接显示
"devServer" : {
"https" : false
},
"router" : {
"base" : "/h5/"
// "base" : "",//file协议
// "mode" : "hash"//file协议
}
// "publicPath" : "./"//file协议
},

unicloud云函数操作数据库

· 阅读需 2 分钟
xuenhua

创建数据库

db_init.json

{
"temperature": {
"data": []
}
}

添加记录

'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ' + event)
const mydb = uniCloud.database();
const userCollection = mydb.collection('temperature');
let temperature=event.temperature;

const currentTime=new Date();

//const currentTime = new Date().toISOString();
let month=currentTime.getMonth()+1;
let riqi=currentTime.getFullYear() + '-' + month + '-' + currentTime.getDate();
let hours=currentTime.getHours()+8;
let minutes=currentTime.getMinutes();
let seconds=currentTime.getSeconds();
let currentTimeStr = riqi+" "+hours+":"+minutes+":"+seconds;

let AM_PM = "" +((hours >= 12) ? "PM " : "AM " );

let checkRecorded = await userCollection.where({
riqi: riqi,
ampm:AM_PM
}).get();
const recordInfo = {
riqi:riqi,
ampm:AM_PM,
time:currentTimeStr,
temperature:temperature
};
if (checkRecorded.data && checkRecorded.data.length > 0) {
return {
code: -1,
errCode: 'Recorded',
msg: '今天已经记录'
}
}else{
let updateResult = await userCollection.add(recordInfo);
return {
code: 0,
msg: '记录添加成功'
}
}
};

获取数据列表

'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ' + event)
const mydb = uniCloud.database();
const userCollection = mydb.collection('temperature');

let res = await userCollection.orderBy("riqi", "desc").get();

console.log(res);
//返回数据给客户端
return res;
};

按照id查询

'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ' + event)
const mydb = uniCloud.database();
const userCollection = mydb.collection('temperature');
let id=event._id;

let res = await userCollection.where({"_id":id}).get();

console.log(res);
//返回数据给客户端
return res;
};

删除数据

'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ' + event)
const mydb = uniCloud.database();
const userCollection = mydb.collection('temperature');
let id = event._id;
console.log("-------"+id)
let res = await userCollection.where({"_id": id}).remove();
//返回数据给客户端
return {
code: 0,
msg: '记录删除成功'
};
};