- 首页 > it技术 > >
//index.js
const app = getApp()
var arr = new Array()
Page({
data: {
name: '',
age: '',
currentID: ' ',
answer: arr
},
ForName: function(e) {
this.setData({
name: e.detail.value
})
console.log('ForName :', this.data.name)
},
ForAge: function(e) {
this.setData({
age: e.detail.value
})
console.log('ForAge :', this.data.age)
},
btnChange: function(e) {
var name = this.data.name
var age = this.data.ag
const db = wx.cloud.database()
db.collection('user-info2').where({
name: name,
age: age
}).get({
success: res => {
if (res.data.length != 0) {
wx.showToast({
icon: 'success',
title: '登录成功!'
})
this.setData({
currentID: res.data[0]._id,
})
console.log("currentIDIndex", this.data.currentID)
wx.navigateTo({
url: '/pages/detail/detail?name=' + this.data.name + '¤tID=' + this.data.currentID
})
} else {
wx.showToast({
icon: 'none',
title: '登录失败!请先注册!'
})
}
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查找用户失败,请先注册!'
})
}
})
},
btn2Change: function() {
wx.navigateTo({
url: '/pages/registered/registered'
})
}
});
问卷调查
姓名
年龄
.tab {
display: flex;
flex-direction: column;
width: 90%;
height: 100px;
background-color: rgba(137, 156, 219, 0.623);
margin: 20px 15px 20px 15px;
font-size: 30px;
color: #fff;
/* text-align: center;
align-items: center;
*/
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.tab1 {
margin-top: 20px;
text-align: center;
}.container {
margin-top: 50px;
}/* .btn{
margin: 100px;
align-items: center;
} */.Name {
display: flex;
flex-direction: row;
margin-bottom: 10px;
}.Age {
display: flex;
flex-direction: row;
}.label {
margin-left: 30px;
}.input {
margin-left: 40px;
align-items: center;
}.btn1 {
margin-top: 100px;
background-color: rgba(137, 156, 219, 0.623);
/* color: rgba(137, 156, 219, 0.623);
*//* background-color: rgba(218, 112, 191, 0.658);
*/
}.btn2 {
margin-top: 10px;
}
// miniprogram/pages/registered/registered.js
var arr=new Array()
Page({
data: {
name: '',
age: '',
answer: arr
},
ForName: function (e) {
this.setData({
name: e.detail.value
})
console.log('ForName :', this.data.name)
},
ForAge: function (e) {
this.setData({
age: e.detail.value
})
console.log('ForAge :', this.data.age)
},
onAdd:function(e){
const db = wx.cloud.database()
db.collection('user-info2').add({
data: {
name: this.data.name,
age: this.data.age,
answer: this.data.answer
},
success: res => {
this.setData({
currentID: res._id
})
wx.showToast({
icon: 'success',
title:'注册成功!返回登录'
})
console.log('注册成功currentID', this.data.currentID)
wx.navigateBack({
url: '/pages/index/index?currentID=' + this.data.currentID
})
console.log("currentID", this.data.currentID)
},
fail: err => {
console.error('[数据库] [新增记录] 失败:', err)
}
})
}})
用户注册
姓名
年龄
/* registered.wxss */
.tab{
display: flex;
flex-direction: column;
width: 90%;
height:100px;
background-color:rgb(137, 156, 219, 0.623);
margin: 20px 15px 20px 15px;
font-size: 30px;
color: #fff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.tab1{
margin-top: 20px;
text-align: center;
}
.container{
margin-top: 50px;
}
/* .btn{
margin: 100px;
align-items: center;
} */
.Name{
display: flex;
flex-direction: row;
margin-bottom: 10px;
}
.Age{
display: flex;
flex-direction: row
}
.label{
margin-left: 30px;
}
.input{
margin-left: 40px;
align-items: center;
}
.btn1{
margin-top:100px;
color: rgba(170, 102, 130, 0.445);
/* background-color: rgba(218, 112, 191, 0.658);
*/ }
.btn2{
margin-top: 10px;
}
// detail.js
var ans = new Array(5);
Page({
data: {
question: [],
name: ' ',
answer: ans,
id: 0,
currentID: null
},
onLoad: function(options) {
this.setData({
name: options.name,
currentID: options.currentID
})
console.log("DetailoptionscurrentID", this.data.currentID)
// console.log("name", this.data.name, "currentID", this.data.currentID)
const db = wx.cloud.database()
db.collection('questions').get({
success: res => {
this.setData({
question: res.data,
})
console.log('[questions] [查询记录] 成功: ', res.data)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
}
})
},
last: function(e) {
if (this.data.id != 0) {
this.setData({
id: this.data.id - 1
})
}
},
next: function(e) {
if (this.data.id < 4) {
this.setData({
id: this.data.id + 1
})
}
},
radioChange: function(e) {
console.log("radioChange", e.detail.value);
},
submit: function(e) {
console.log("id", this.data.id)
console.log(e.detail.value);
// var ans = new Array(5);
var a = e.detail.value.answer;
var id = this.data.id;
ans[id] = a;
this.setData({
answer: ans,
})
console.log('当前的answer数组', this.data.answer);
},//把结果提交到云数据库
submitAnswerDB: function() {
const db = wx.cloud.database()
db.collection('user-info2').doc(this.data.currentID).update({
data: {
answer: this.data.answer
},
success: res => {
console.log("答案上传成功!", this.data.answer);
wx.navigateTo({
url: '/pages/finalPage/finalPage?currentID=' + this.data.currentID + '&answer=' + this.data.answer + '&name=' + this.data.name + '&age=' + this.data.age
})
},
fail: err => {
icon: 'none',
console.error('[数据库] [更新记录] 失败:', err)
}
})
},
})
亲爱的{{name}},感谢您填写问卷!class="swiper" current="{{id}}">
-item>
/* miniprogram/pages/detail/detail.wxss */.container {
margin-top: 50px;
height: 350px;
}.btn {
margin: 20px;
}.radio {
display: flex;
flex-direction: column;
color: rgb(128, 119, 119);
font-size: 14px;
margin-left: 20px;
}.label {
color: rgb(46, 43, 43);
}.radio-group {
display: flex;
flex-direction: column;
font-size: 30rpx;
text-indent: 14rpx;
margin-top: 40rpx;
}.radio {
display: flex;
flex-direction: row;
margin-bottom: 14rpx;
}.swiper {
height: 350px;
display: flex;
flex-direction: column;
/* justify-content: flex-start;
*/
margin-top: 20px;
}.btn-group {
margin-top: 20px;
display: flex;
flex-direction: row;
width: 90%;
margin: auto;
}.btn {
background-color: rgba(137, 156, 219, 0.623);
font-size: 12px;
}.btn-right {
background-color: rgba(214, 160, 187, 0.555);
font-size: 12px;
}.btn-left {
background-color: rgba(214, 160, 187, 0.555);
font-size: 12px;
}
// miniprogram/pages/finalPage.js
const db = wx.cloud.database()
Page({
data: {
final: [],
currentID: null,
question: [],
name: null
},
onLoad: function(options) {
this.setData({
currentID: options.currentID,
// answer: options.answer,
name: options.name
})
console.log("finalCurrentID", this.data.currentID )
db.collection('user-info2').where({
_id:this.data.currentID
}).get({
success: res => {
this.setData({
final:res.data
})
console.log('[数据库] [查询记录] 成功final: ', this.data.final)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
}
})
db.collection('questions').get({
success: res => {
this.setData({
question: res.data
})
console.log('[数据库] [查询记录] 成功answer: ', this.data.question)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
}
})
}
})
您的名字:{{item.name}}
您的年龄:{{item.age}}
{{item.answer }}
/* miniprogram/pages/finalPage.wxss */
.con{
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.one{
margin-left: 40px;
margin-top: 80px;
}
.name{
margin-bottom: 15px;
}
.age{
margin-bottom: 50px;
}
.two{
margin-left: 40px;
}
推荐阅读