第一次基础实现

main
“2825089624@qq.com” 4 months ago
parent 84cf70b338
commit 768be3f8f6

@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

@ -0,0 +1,12 @@
# 云开发 quickstart
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
## 参考文档
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)

@ -0,0 +1,21 @@
// app.js
App({
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力');
} else {
wx.cloud.init({
// env 参数说明:
// env 参数决定接下来小程序发起的云开发调用wx.cloud.xxx会默认请求到哪个云环境的资源
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// 如不填则使用默认环境(第一个创建的环境)
env: 'xiongchangding-1g3rqdct5b84e492',
traceUser: true,
});
}
this.globalData = {
chosen_index: 1
};
}
});

@ -0,0 +1,24 @@
{
"pages": [
"pages/1/1",
"pages/3/3",
"pages/2/2",
"pages/4/4",
"pages/5-1/5-1",
"pages/52/52",
"pages/53/53",
"pages/54/54",
"pages/42/42",
"pages/31/31",
"pages/index/index"
],
"window": {
"backgroundColor": "#F6F6F6",
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#F6F6F6",
"navigationBarTitleText": "云开发-点名系统",
"navigationBarTextStyle": "black"
},
"sitemapLocation": "sitemap.json",
"style": "v2"
}

@ -0,0 +1,60 @@
// miniprogram/components/cloudTipModal/index.js
const { isMac } = require('../../envList.js');
Component({
/**
* 页面的初始数据
*/
data: {
showUploadTip: false,
tipText: isMac ? 'sh ./uploadCloudFunction.sh' : './uploadCloudFunction.bat'
},
properties: {
showUploadTipProps: Boolean
},
observers: {
showUploadTipProps: function(showUploadTipProps) {
this.setData({
showUploadTip: showUploadTipProps
});
}
},
methods: {
onCheckEnv(){
wx.showLoading({
title: '',
});
wx.cloud
.callFunction({
name: 'quickstartFunctions',
data: {
type: 'getOpenId',
},
})
.then(() => {
wx.hideLoading();
this.setData({
showUploadTip: !this.data.showUploadTip
});
})
.catch((e) => {
// 报错信息提示环境不存在
wx.hideLoading();
if(e.message.includes('env not exists') || e.message.includes('Environment not found') || e.message.includes('env check invalid be filterd')){
wx.showToast({
title: '环境未找到',
icon: 'error',
duration: 2000
})
}
});
},
onCheckEnvCancel(){
this.setData({
showUploadTip: !this.data.showUploadTip
});
},
}
});

@ -0,0 +1,4 @@
{
"usingComponents": {},
"component": true
}

@ -0,0 +1,14 @@
<!--miniprogram/components/cloudTipModal/index.wxml-->
<!-- wx:if="{{showUploadTip}}" -->
<view class="install_tip" wx:if="{{showUploadTip}}">
<view class="install_tip_back"></view>
<view class="install_tip_detail">
<view class="install_tip_detail_title">云开发环境未找到</view>
<view class="install_tip_detail_tip">请点击上方「云开发」按钮,开通云开发环境后重试。</view>
<view class="install_tip_detail_tip">如果已经开通云开发请检查环境ID与 `miniprogram/app.js` 中的 `env` 参数是否一致。</view>
<view class="install_tip_detail_buttons">
<view bindtap="onCheckEnv" class="install_tip_detail_button install_tip_detail_button_primary">重新检测</view>
<view bindtap="onCheckEnvCancel" class="install_tip_detail_button">取消</view>
</view>
</view>
</view>

@ -0,0 +1,54 @@
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
top: 65%;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: left;
}
.install_tip_detail_buttons {
padding-top: 50rpx;
display: flex;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 40%;
text-align: center;
height: 90rpx;
line-height: 90rpx;
border-radius: 10rpx;
margin: 0 auto;
}
.install_tip_detail_button_primary {
background-color: #07C160;
color: #fff;
}

@ -0,0 +1,39 @@
Component({
data: {
modalVisible: false,
tipText: '云开发>云模板>模板中心',
},
properties: {
installModulePageTitleProps: String,
modalVisibleProps: Boolean,
tipTextProps: String,
installModuleNameProps: String,
},
observers: {
modalVisibleProps: function (modalVisibleProps) {
this.setData({
modalVisible: modalVisibleProps,
});
},
tipTextProps: function (tipTextProps) {
this.setData({
tipText: tipTextProps,
});
},
},
methods: {
hideModal() {
if (this.data.modalVisible) {
this.setData({
modalVisible: false,
});
}
},
onViewDetail() {
this.hideModal();
wx.navigateTo({
url: `/pages/cloudbaseModuleInstallTips/index?moduleName=${this.properties.installModuleNameProps}&title=${this.properties.installModulePageTitleProps}`,
});
},
},
});

@ -0,0 +1,4 @@
{
"usingComponents": {},
"component": true
}

@ -0,0 +1,11 @@
<!-- miniprogram/components/cloudTipModal/index.wxml -->
<view class="install_tip" wx:if="{{ modalVisible }}">
<view class="install_tip_back" bindtap="hideModal" />
<view class="install_tip_detail">
<view class="install_tip_detail_title">体验前需安装云模板</view>
<view class="install_tip_detail_tip">请按照以下路径安装对应云模板</view>
<view class="install_tip_detail_shell">{{ tipText }}</view>
<view bindtap="onViewDetail" class="install_tip_detail_button">查看详情{{ installModuleName }}</view>
</view>
</view>

@ -0,0 +1,57 @@
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
top: 60%;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: center;
}
.install_tip_detail_shell {
margin: 70rpx 0;
display: flex;
justify-content: center;
}
.install_tip_detail_copy {
color: #546488;
margin-left: 10rpx;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 60%;
text-align: center;
height: 90rpx;
line-height: 90rpx;
border-radius: 10rpx;
margin: 0 auto;
}

@ -0,0 +1,24 @@
// components/cloudbaseModuleInstallPath/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
installModuleName: String,
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
}
})

@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

@ -0,0 +1 @@
<view class="tip">可以在“云开发>云模板>模板中心>{{installModuleName}}”找到该模板</view>

@ -0,0 +1,7 @@
.tip {
font-size: 23rpx;
color: rgba(0, 0, 0, 0.5);
width: 90%;
text-align: center;
margin: 30rpx auto 0 auto;
}

@ -0,0 +1,21 @@
Component({
data: {
modalVisible: false,
},
properties: {
visible: Boolean,
imageSrc: String,
},
observers: {
visible: function (visible) {
this.setData({
modalVisible: visible
});
},
},
methods: {
onClose() {
this.setData({ modalVisible: false });
}
}
});

@ -0,0 +1,4 @@
{
"usingComponents": {},
"component": true
}

@ -0,0 +1,8 @@
<view class="modal_container" wx:if="{{ modalVisible }}">
<view class="icon_close" bind:tap="onClose">
<view>X</view>
</view>
<view class="image_container">
<image class="code_img" src="{{ imageSrc }}" />
</view>
</view>

@ -0,0 +1,95 @@
.modal_container {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
width: 100%;
height: 100%;
}
.icon_close {
position: fixed;
right: 40rpx;
top: 40rpx;
width: 70rpx;
height: 70rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
/* background-color: #07c160; */
background-color: rgba(0,0,0,0.7);
color: white;
font-size: 32rpx;
font-weight: bold;
}
.code_img {
width: 400rpx;
height: 400rpx;
margin-top: 50%;
margin-left: 50%;
transform: translateX(-50%);
border-radius: 30rpx;
}
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
top: 60%;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: center;
}
.install_tip_detail_shell {
margin: 70rpx 0;
display: flex;
justify-content: center;
}
.install_tip_detail_copy {
color: #546488;
margin-left: 10rpx;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 60%;
text-align: center;
height: 90rpx;
line-height: 90rpx;
border-radius: 10rpx;
margin: 0 auto;
}

@ -0,0 +1,6 @@
const envList = [];
const isMac = false;
module.exports = {
envList,
isMac
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="8px" height="14px" viewBox="0 0 8 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>☀ iOS/☀ 图标/线型/icons_outlined_arrow@3x</title>
<g id="控件" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" fill-opacity="0.3">
<g id="4.列表/z.覆盖层/右边/箭头" transform="translate(-334.000000, -21.000000)" fill="#000000">
<g id="☀-iOS/☀-图标/线型/icons_outlined_arrow" transform="translate(332.000000, 16.000000)">
<path d="M2.45405845,6.58064919 L3.51471863,5.51998901 L9.29361566,11.298886 C9.68374096,11.6890113 9.6872014,12.318069 9.29361566,12.7116547 L3.51471863,18.4905518 L2.45405845,17.4298916 L7.87867966,12.0052704 L2.45405845,6.58064919 Z" id="Combined-Shape"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 906 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6.95693 15.75H19.5V6H4.5V17.7974L6.95693 15.75ZM3.73808 20.3849C3.44499 20.6292 3 20.4208 3 20.0392V6C3 5.17157 3.67157 4.5 4.5 4.5H19.5C20.3284 4.5 21 5.17157 21 6V15.75C21 16.5784 20.3284 17.25 19.5 17.25H7.5L3.73808 20.3849Z" fill="black" fill-opacity="0.9"/>
</svg>

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.0911 17.4C11.0911 16.9029 11.494 16.5 11.9911 16.5C12.4881 16.5 12.8911 16.9029 12.8911 17.4C12.8911 17.8971 12.4881 18.3 11.9911 18.3C11.494 18.3 11.0911 17.8971 11.0911 17.4Z" fill="black" fill-opacity="0.9"/>
<path d="M11.9911 6.00915C9.98467 6.00915 8.35363 7.64019 8.35363 9.64665H9.85363C9.85363 8.46862 10.8131 7.50915 11.9911 7.50915C13.1692 7.50915 14.1286 8.46862 14.1286 9.64665C14.1286 10.4533 13.4619 11.2621 12.5917 11.6156L12.5878 11.6172C11.7935 11.945 11.2412 12.7262 11.2412 13.6387V15H12.7412V13.6387C12.7412 13.3474 12.9142 13.106 13.1585 13.0044C14.3995 12.4993 15.6286 11.248 15.6286 9.64665C15.6286 7.64019 13.9976 6.00915 11.9911 6.00915Z" fill="black" fill-opacity="0.9"/>
<path d="M22.4912 12C22.4912 6.20101 17.7902 1.5 11.9912 1.5C6.19222 1.5 1.49121 6.20101 1.49121 12C1.49121 17.799 6.19222 22.5 11.9912 22.5C17.7902 22.5 22.4912 17.799 22.4912 12ZM20.9912 12C20.9912 16.9706 16.9618 21 11.9912 21C7.02065 21 2.99121 16.9706 2.99121 12C2.99121 7.02944 7.02065 3 11.9912 3C16.9618 3 20.9912 7.02944 20.9912 12Z" fill="black" fill-opacity="0.9"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.5002 12C16.5002 14.4853 14.4855 16.5 12.0002 16.5C9.51497 16.5 7.50025 14.4853 7.50025 12C7.50025 9.51472 9.51497 7.5 12.0002 7.5C14.4855 7.5 16.5002 9.51472 16.5002 12ZM15.0002 12C15.0002 10.3431 13.6571 9 12.0002 9C10.3434 9 9.00025 10.3431 9.00025 12C9.00025 13.6569 10.3434 15 12.0002 15C13.6571 15 15.0002 13.6569 15.0002 12Z" fill="black" fill-opacity="0.9"/>
<path d="M12.0002 1.875L21.0935 6.9375V17.0625L12.0002 22.125L2.90698 17.0625V6.9375L12.0002 1.875ZM4.40698 7.8192V16.1808L12.0002 20.4082L19.5935 16.1808V7.8192L12.0002 3.59179L4.40698 7.8192Z" fill="black" fill-opacity="0.9"/>
</svg>

After

Width:  |  Height:  |  Size: 711 B

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3.43993 20.5601C3.72112 20.8413 4.10234 20.9995 4.5 21H19.5C19.8977 20.9995 20.2789 20.8413 20.5601 20.5601C20.8413 20.2789 20.9995 19.8977 21 19.5V12.75H19.5V19.5H4.5V4.5H11.25V3H4.5C4.10234 3.00054 3.72112 3.15874 3.43993 3.43993C3.15874 3.72112 3.00054 4.10234 3 4.5V19.5C3.00054 19.8977 3.15874 20.2789 3.43993 20.5601Z" fill="black" fill-opacity="0.9"/>
<path d="M13.5 4.5V3H20.25C20.6642 3 21 3.33579 21 3.75V10.5H19.5V5.5605L13.0605 12L12 10.9395L18.4395 4.5H13.5Z" fill="black" fill-opacity="0.9"/>
</svg>

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

@ -0,0 +1,66 @@
// pages/1/1.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,19 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/logo.png" style="width: 100%;" >
</image>
<view style="height: 100rpx;">
</view>
<button type="default" ><navigator url="../2/2" open-type="redirect">点击进入</navigator>
</button>
<view style="height: 50rpx;">
</view>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 300rpx;
background-color:white;
}

@ -0,0 +1,145 @@
// pages/2/2.js
const db = wx.cloud.database(); // 获取数据库实例
const app = getApp(); // 获取全局应用实例
Page({
async selectRandomIndexAndSetChosen() {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 加载中的提示文字
mask: true // 防止触摸穿透
});
const score_list = []; // 用于存储所有数据的score
const index_list = []; // 用于存储所有数据的index
const MAX_LIMIT = 20; // 每次获取数据的最大数量
try {
// 获取所有数据并存入score_list和index_list
const total = await db.collection('demolist').count().then(res => res.total);
const batchTimes = Math.ceil(total / MAX_LIMIT);
const tasks = [];
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('demolist').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get().then(res => {
res.data.forEach(item => {
score_list.push(item.score);
index_list.push(item.index);
});
});
tasks.push(promise);
}
await Promise.all(tasks); // 等待所有数据请求完成
// 根据score_list中的值生成权重
const maxScore = 60;
const weights = score_list.map(score => maxScore - score);
// 计算权重总和
const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
// 生成一个介于 0 和 totalWeight 之间的随机数
const randomWeight = Math.random() * totalWeight;
// 根据随机数选择index
let cumulativeWeight = 0;
for (let i = 0; i < weights.length; i++) {
cumulativeWeight += weights[i];
if (randomWeight <= cumulativeWeight) {
// 将选中的 index 赋值给 app.js 中的 chosen_index 变量
getApp().globalData.chosen_index = index_list[i];
console.log('选中的 index:', index_list[i]);
// 隐藏加载动画
wx.hideLoading();
// 跳转到 pages/3/3 页面
wx.redirectTo({
url: '../3/3'
});
return; // 跳转后结束函数
}
}
} catch (error) {
console.error('获取数据失败:', error);
// 如果出错也隐藏加载动画
wx.hideLoading();
}
},
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// selectRandomIndexAndSetChosen()
// .then(() => {
// console.log('index 已成功赋值给 chosen_index');
// })
// .catch(err => {
// console.error('获取数据失败:', err);
// });
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,19 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/xinyuu.png" style="width: 100%;" >
</image>
<view style="height: 100rpx;">
</view>
<button type="default" bind:tap="selectRandomIndexAndSetChosen">开始抽点
</button>
<view style="height: 50rpx;">
</view>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 300rpx;
background-color:white;
}

@ -0,0 +1,162 @@
// pages/3/3.js
const db = wx.cloud.database();
const app = getApp(); // 获取全局应用实例
Page({
data: {
dataobj: undefined
},
async updateScoreForIndex_j1() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 1; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../31/31'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
async updateScoreForIndex_fu1() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score - 1; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../42/42'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,30 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/shenpan.jpg" style="width: 100%;" >
</image>
<view style="height: 100rpx;">
</view>
<view>姓名:{{dataobj.name}}</view>
<view>学号:{{dataobj.xuehao}}</view>
<view >
分数:{{dataobj.score}}
</view>
<view style="height: 100rpx;">
该同学到了吗
</view>
<button type="default" bind:tap="updateScoreForIndex_j1">是</button>
<view style="height: 50rpx;">
</view>
<button type="default" bind:tap="updateScoreForIndex_fu1">否</button>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 150rpx;
background-color:white;
}

@ -0,0 +1,162 @@
// pages/3/3.js
const db = wx.cloud.database();
const app = getApp(); // 获取全局应用实例
Page({
data: {
dataobj: undefined
},
async updateScoreForIndex_j05() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 0.5; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../4/4'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
async updateScoreForIndex_jian1() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score - 1; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../42/42'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,31 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/shenpan.jpg" style="width: 100%;" >
</image>
<view style="height: 100rpx;">
</view>
<view>姓名:{{dataobj.name}}</view>
<view>学号:{{dataobj.xuehao}}</view>
<view>
分数:{{dataobj.score}}
</view>
<view style="height: 100rpx;">
积分加1但是请重复刚才的问题
</view>
<button type="default" bind:tap="updateScoreForIndex_j05">我记得</button>
<view style="height: 50rpx;">
</view>
<button type="default" bind:tap="updateScoreForIndex_jian1">忘了
</button>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 150rpx;
background-color:white;
}

@ -0,0 +1,250 @@
// pages/4/4.js
const db = wx.cloud.database(); // 获取数据库实例
const app = getApp(); // 获取全局应用实例
Page({
async updateScoreForIndex_05() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 0.5; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../5-1/5-1'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
async updateScoreForIndex_1() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 1; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../52/52'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
async updateScoreForIndex_2() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 2; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../53/53'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
async updateScoreForIndex_3() {
try {
// 显示加载动画
wx.showLoading({
title: '加载中...', // 可以自定义加载中的提示文字
mask: true // 是否显示透明蒙层,防止触摸穿透
});
// 查找 index 为 chosen_index 的记录
const res = await db.collection('demolist').where({ index: app.globalData.chosen_index }).get();
const data = res.data;
if (data.length === 0) {
console.log('没有找到 index 为 chosen_index 的数据');
wx.hideLoading(); // 隐藏加载动画
return;
}
const record = data[0];
const newScore = record.score + 3; // 更新后的 score 值
// 更新记录中的 score 属性
await db.collection('demolist').doc(record._id).update({
data: {
score: newScore
}
});
console.log(`更新成功,新的 score 值为:${newScore}`);
// 数据更新成功后隐藏加载动画并跳转
wx.hideLoading();
wx.redirectTo({
url: '../54/54'
});
} catch (error) {
console.error('更新失败:', error);
wx.hideLoading(); // 如果出错也隐藏加载动画
}
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 页面的初始数据
*/
data: {
dataobj: undefined
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,33 @@
<!--pages/4/4.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/shenpan.jpg" style="width: 100%;" >
</image>
<view>姓名:{{dataobj.name}}</view>
<view>学号:{{dataobj.xuehao}}</view>
<view>
分数:{{dataobj.score}}
</view>
<view style="height: 200rpx;">
积分加0.5但是请回答这个问题
</view>
<button type="default" bind:tap="updateScoreForIndex_05">不会,嘴硬</button>
<view style="height: 50rpx;">
</view>
<button type="default" bind:tap="updateScoreForIndex_1">看我操作</button>
<view style="height: 50rpx;">
</view>
<button type="default" bind:tap="updateScoreForIndex_2">包会的</button>
<view style="height: 50rpx;">
</view>
<button type="default" bind:tap="updateScoreForIndex_3">恭喜,完美回答</button>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 100rpx;
background-color:white;
}

@ -0,0 +1,85 @@
// pages/42/42.js
const db = wx.cloud.database();
const app = getApp(); // 获取全局应用实例
Page({
data: {
dataobj: undefined
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 页面的初始数据
*/
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,27 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/shenpaizhang.jpg" style="width: 100%;" >
</image>
<view style="height: 50rpx;">
减一分
</view>
<view>姓名:{{dataobj.name}}</view>
<view>学号:{{dataobj.xuehao}}</view>
<view >
分数:{{dataobj.score}}
</view>
<button type="default"><navigator url="../2/2" open-type="redirect">有请下一位</navigator>
</button>
<view style="height: 50rpx;">
</view>
<button type="default" ><navigator url="../1/1" open-type="redirect">结束本次点名</navigator>
</button>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 100rpx;
background-color:white;
}

@ -0,0 +1,83 @@
// pages/5-1/5-1.js
const db = wx.cloud.database();
const app = getApp(); // 获取全局应用实例
Page({
data: {
dataobj: undefined
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

@ -0,0 +1,26 @@
<!--pages/news.wxml-->
<view class="box">
<text>
</text>
</view>
<!-- <navigator url="../logs/logs" open-type="navigate">点我跳转 -->
<!-- </navigator> -->
<image src="../../image/cuizi.png" style="width: 100%;" >
</image>
<view style="height: 50rpx;">
虽然加0.5分
</view>
<view>姓名:{{dataobj.name}}</view>
<view>学号:{{dataobj.xuehao}}</view>
<view >
分数:{{dataobj.score}}
</view>
<button type="default"><navigator url="../2/2" open-type="redirect">有请下一位</navigator>
</button>
<view style="height: 50rpx;">
</view>
<button type="default" ><navigator url="../1/1" open-type="redirect">结束本次点名</navigator>
</button>

@ -0,0 +1,6 @@
/* pages/1/1.wxss */
.box{
width: auto;
height: 100rpx;
background-color:white;
}

@ -0,0 +1,82 @@
// pages/52/52.js
const db = wx.cloud.database();
const app = getApp(); // 获取全局应用实例
Page({
data: {
dataobj: undefined
},
get_data() {
const chosenIndex = app.globalData.chosen_index; // 获取 chosen_index
db.collection("demolist").where({ index: chosenIndex }).get({
success: res => {
console.log(res);
if (res.data.length > 0) {
this.setData({
dataobj: res.data[0]
}, () => {
console.log(this.data.dataobj);
});
} else {
console.log("没有数据");
}
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.get_data()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

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

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save