diff --git a/Roll_Students/.eslintrc.js b/Roll_Students/.eslintrc.js new file mode 100644 index 0000000..115cc02 --- /dev/null +++ b/Roll_Students/.eslintrc.js @@ -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: {}, +} diff --git a/Roll_Students/app.js b/Roll_Students/app.js new file mode 100644 index 0000000..049d405 --- /dev/null +++ b/Roll_Students/app.js @@ -0,0 +1,45 @@ +// app.js +App({ + onLaunch() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + }, + globalData: { + students: [ + { name: '张三', avatar: '/assets/img/Fairy/fairy (1).png', score:19, id:1000, index:1 }, + { name: '李四', avatar: '/assets/img/Fairy/fairy (2).png', score:17, id:1001, index:2 }, + { name: '王五', avatar: '/assets/img/Fairy/fairy (3).png', score:14, id:1002, index:3 }, + { name: '赵六', avatar: '/assets/img/Fairy/fairy (4).png', score:12, id:1003, index:4 }, + { name: '周无', avatar: '/assets/img/Fairy/fairy (5).png', score:12, id:1004, index:5 }, + { name: '程七', avatar: '/assets/img/Fairy/fairy (6).png', score:9, id:1005, index:6 }, + { name: '刘大大', avatar: '/assets/img/Fairy/fairy (7).png', score:9, id:1006, index:7 }, + { name: '王乐康', avatar: '/assets/img/Fairy/fairy (8).png', score:8, id:1007, index:8 }, + { name: '段问蕾', avatar: '/assets/img/Fairy/fairy (9).png', score:7, id:1008, index:9 }, + { name: '贾伦', avatar: '/assets/img/Fairy/fairy (10).png', score:4, id:1009, index:10 }, + { name: '李书易', avatar: '/assets/img/Fairy/fairy (11).png', score:3, id:1010, index:11 }, + { name: '胡心', avatar: '/assets/img/Fairy/fairy (12).png', score:1, id:1011, index:12 }, + { name: '李天泽', avatar: '/assets/img/Fairy/fairy (13).png', score:-1, id:1012, index:13 }, + { name: '列亿枫', avatar: '/assets/img/Fairy/fairy (14).png', score:0, id:1013, index:14 }, + { name: '周乐心', avatar: '/assets/img/Fairy/fairy (15).png', score:-2, id:1014, index:15 }, + { name: '胡小小', avatar: '/assets/img/Fairy/fairy (16).png', score:2, id:1015, index:16 }, + { name: '王滢', avatar: '/assets/img/Fairy/fairy (17).png', score:1, id:1016, index:17 }, + { name: "傅彭", avatar: '/assets/img/Fairy/fairy (18).png', score:21, id:1017, index:18 }, + { name: "丁璧容", avatar: '/assets/img/Fairy/fairy (19).png', score:3, id:1018, index:19 }, + { name: "赵丽", avatar: '/assets/img/Fairy/fairy (20).png', score:25, id:1019, index:20 }, + { name: "李恺", avatar: '/assets/img/Fairy/fairy (21).png', score:9, id:1020, index:21 }, + { name: "王笑天", avatar: '/assets/img/Fairy/fairy (22).png', score:8, id:1021, index:22 }, + { name: "庞蕊", avatar: '/assets/img/Fairy/fairy (23).png', score:0, id:1022, index:23 }, + { name: "李四", avatar: '/assets/img/Fairy/fairy (24).png', score:0, id:1023, index:24 }, + { name: "吴无五", avatar: '/assets/img/Fairy/fairy (25).png', score:0, id:1024, index:25 } + ] + } +}) diff --git a/Roll_Students/app.json b/Roll_Students/app.json new file mode 100644 index 0000000..4f58d7f --- /dev/null +++ b/Roll_Students/app.json @@ -0,0 +1,49 @@ +{ + "entryPagePath": "pages/lodding/lodding", + "pages": [ + "pages/lodding/lodding", + "pages/AddClass/AddClass", + "pages/RollClass/RollClass", + "pages/setting/setting", + "pages/studentList/studentList", + "pages/studentRanking/studentRanking", + "pages/startNaming/startNaming" + ], + "window": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "学生点名系统", + "navigationBarBackgroundColor": "#ffffff" + }, + + "tabBar": { + "color": "#000000", + "selectedColor": "#0F40F5", + "backgroundColor": "#ffffff", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/AddClass/AddClass", + "text": "班级", + "iconPath": "/assets/img/nav/nav1-1.png", + "selectedIconPath": "/assets/img/nav/nav1-2.png" + }, + { + "pagePath": "pages/RollClass/RollClass", + "text": "课堂", + "iconPath": "/assets/img/nav/nav2-1.png", + "selectedIconPath": "/assets/img/nav/nav2-2.png" + }, + { + "pagePath": "pages/setting/setting", + "text": "设置", + "iconPath": "/assets/img/nav/nav3-1.png", + "selectedIconPath": "/assets/img/nav/nav3-2.png" + } + ] + }, + + "style": "v2", + "componentFramework": "glass-easel", + "sitemapLocation": "sitemap.json", + "lazyCodeLoading": "requiredComponents" +} diff --git a/Roll_Students/app.wxss b/Roll_Students/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/Roll_Students/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/Roll_Students/assets/example.xlsx b/Roll_Students/assets/example.xlsx new file mode 100644 index 0000000..acc698b Binary files /dev/null and b/Roll_Students/assets/example.xlsx differ diff --git a/Roll_Students/assets/img/AddClass/icon1_1.png b/Roll_Students/assets/img/AddClass/icon1_1.png new file mode 100644 index 0000000..8055586 Binary files /dev/null and b/Roll_Students/assets/img/AddClass/icon1_1.png differ diff --git a/Roll_Students/assets/img/AddClass/icon1_2.png b/Roll_Students/assets/img/AddClass/icon1_2.png new file mode 100644 index 0000000..c446df6 Binary files /dev/null and b/Roll_Students/assets/img/AddClass/icon1_2.png differ diff --git a/Roll_Students/assets/img/AddClass/img1_1.jpg b/Roll_Students/assets/img/AddClass/img1_1.jpg new file mode 100644 index 0000000..ff156e1 Binary files /dev/null and b/Roll_Students/assets/img/AddClass/img1_1.jpg differ diff --git a/Roll_Students/assets/img/AddClass/img1_2.jpg b/Roll_Students/assets/img/AddClass/img1_2.jpg new file mode 100644 index 0000000..cf8ba50 Binary files /dev/null and b/Roll_Students/assets/img/AddClass/img1_2.jpg differ diff --git a/Roll_Students/assets/img/AddClass/img1_3.jpg b/Roll_Students/assets/img/AddClass/img1_3.jpg new file mode 100644 index 0000000..9c1f17d Binary files /dev/null and b/Roll_Students/assets/img/AddClass/img1_3.jpg differ diff --git a/Roll_Students/assets/img/AddClass/img1_4.jpg b/Roll_Students/assets/img/AddClass/img1_4.jpg new file mode 100644 index 0000000..2a80fa1 Binary files /dev/null and b/Roll_Students/assets/img/AddClass/img1_4.jpg differ diff --git a/Roll_Students/assets/img/Fairy/fairy (1).png b/Roll_Students/assets/img/Fairy/fairy (1).png new file mode 100644 index 0000000..a71029a Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (1).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (10).png b/Roll_Students/assets/img/Fairy/fairy (10).png new file mode 100644 index 0000000..68062e3 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (10).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (11).png b/Roll_Students/assets/img/Fairy/fairy (11).png new file mode 100644 index 0000000..43f25d0 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (11).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (12).png b/Roll_Students/assets/img/Fairy/fairy (12).png new file mode 100644 index 0000000..ed63841 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (12).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (13).png b/Roll_Students/assets/img/Fairy/fairy (13).png new file mode 100644 index 0000000..08a09fd Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (13).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (14).png b/Roll_Students/assets/img/Fairy/fairy (14).png new file mode 100644 index 0000000..350dba4 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (14).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (15).png b/Roll_Students/assets/img/Fairy/fairy (15).png new file mode 100644 index 0000000..e09c173 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (15).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (16).png b/Roll_Students/assets/img/Fairy/fairy (16).png new file mode 100644 index 0000000..abd99ee Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (16).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (17).png b/Roll_Students/assets/img/Fairy/fairy (17).png new file mode 100644 index 0000000..ca9335c Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (17).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (18).png b/Roll_Students/assets/img/Fairy/fairy (18).png new file mode 100644 index 0000000..eef4a0c Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (18).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (19).png b/Roll_Students/assets/img/Fairy/fairy (19).png new file mode 100644 index 0000000..6b4a742 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (19).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (2).png b/Roll_Students/assets/img/Fairy/fairy (2).png new file mode 100644 index 0000000..7e4515b Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (2).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (20).png b/Roll_Students/assets/img/Fairy/fairy (20).png new file mode 100644 index 0000000..96578f5 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (20).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (21).png b/Roll_Students/assets/img/Fairy/fairy (21).png new file mode 100644 index 0000000..801c408 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (21).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (22).png b/Roll_Students/assets/img/Fairy/fairy (22).png new file mode 100644 index 0000000..7caf93e Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (22).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (23).png b/Roll_Students/assets/img/Fairy/fairy (23).png new file mode 100644 index 0000000..367f4d1 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (23).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (24).png b/Roll_Students/assets/img/Fairy/fairy (24).png new file mode 100644 index 0000000..2a8e978 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (24).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (25).png b/Roll_Students/assets/img/Fairy/fairy (25).png new file mode 100644 index 0000000..7badffd Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (25).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (26).png b/Roll_Students/assets/img/Fairy/fairy (26).png new file mode 100644 index 0000000..1bbde9c Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (26).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (27).png b/Roll_Students/assets/img/Fairy/fairy (27).png new file mode 100644 index 0000000..cf29ec9 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (27).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (28).png b/Roll_Students/assets/img/Fairy/fairy (28).png new file mode 100644 index 0000000..0c13826 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (28).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (29).png b/Roll_Students/assets/img/Fairy/fairy (29).png new file mode 100644 index 0000000..61c51b0 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (29).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (3).png b/Roll_Students/assets/img/Fairy/fairy (3).png new file mode 100644 index 0000000..a770049 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (3).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (30).png b/Roll_Students/assets/img/Fairy/fairy (30).png new file mode 100644 index 0000000..f4ea030 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (30).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (4).png b/Roll_Students/assets/img/Fairy/fairy (4).png new file mode 100644 index 0000000..2a6b490 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (4).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (5).png b/Roll_Students/assets/img/Fairy/fairy (5).png new file mode 100644 index 0000000..c32e411 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (5).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (6).png b/Roll_Students/assets/img/Fairy/fairy (6).png new file mode 100644 index 0000000..d43644c Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (6).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (7).png b/Roll_Students/assets/img/Fairy/fairy (7).png new file mode 100644 index 0000000..e2aa010 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (7).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (8).png b/Roll_Students/assets/img/Fairy/fairy (8).png new file mode 100644 index 0000000..11ce92f Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (8).png differ diff --git a/Roll_Students/assets/img/Fairy/fairy (9).png b/Roll_Students/assets/img/Fairy/fairy (9).png new file mode 100644 index 0000000..7f9e2a2 Binary files /dev/null and b/Roll_Students/assets/img/Fairy/fairy (9).png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_1.png b/Roll_Students/assets/img/RollClass/RollClass1_1.png new file mode 100644 index 0000000..e0b7214 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_1.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_2.png b/Roll_Students/assets/img/RollClass/RollClass1_2.png new file mode 100644 index 0000000..3a3412e Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_2.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_3.png b/Roll_Students/assets/img/RollClass/RollClass1_3.png new file mode 100644 index 0000000..fd31bb7 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_3.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_4.png b/Roll_Students/assets/img/RollClass/RollClass1_4.png new file mode 100644 index 0000000..896ea7b Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_4.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_5.png b/Roll_Students/assets/img/RollClass/RollClass1_5.png new file mode 100644 index 0000000..323beaa Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_5.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass1_6.png b/Roll_Students/assets/img/RollClass/RollClass1_6.png new file mode 100644 index 0000000..bfb50ad Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass1_6.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass2_1.png b/Roll_Students/assets/img/RollClass/RollClass2_1.png new file mode 100644 index 0000000..dba15b1 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass2_1.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass2_2.png b/Roll_Students/assets/img/RollClass/RollClass2_2.png new file mode 100644 index 0000000..7dfe036 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass2_2.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass3_1.png b/Roll_Students/assets/img/RollClass/RollClass3_1.png new file mode 100644 index 0000000..de33b9f Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass3_1.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass3_2.png b/Roll_Students/assets/img/RollClass/RollClass3_2.png new file mode 100644 index 0000000..60184e6 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass3_2.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass3_3.png b/Roll_Students/assets/img/RollClass/RollClass3_3.png new file mode 100644 index 0000000..35057dc Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass3_3.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass4_1.png b/Roll_Students/assets/img/RollClass/RollClass4_1.png new file mode 100644 index 0000000..eb38ce8 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass4_1.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass4_2.png b/Roll_Students/assets/img/RollClass/RollClass4_2.png new file mode 100644 index 0000000..7a4affb Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass4_2.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass4_3.png b/Roll_Students/assets/img/RollClass/RollClass4_3.png new file mode 100644 index 0000000..8026b28 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass4_3.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass4_4.png b/Roll_Students/assets/img/RollClass/RollClass4_4.png new file mode 100644 index 0000000..366beac Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass4_4.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_1.png b/Roll_Students/assets/img/RollClass/RollClass5_1.png new file mode 100644 index 0000000..96a307e Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_1.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_2.png b/Roll_Students/assets/img/RollClass/RollClass5_2.png new file mode 100644 index 0000000..5c16e00 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_2.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_3.png b/Roll_Students/assets/img/RollClass/RollClass5_3.png new file mode 100644 index 0000000..fad677f Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_3.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_4.png b/Roll_Students/assets/img/RollClass/RollClass5_4.png new file mode 100644 index 0000000..4c56d0c Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_4.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_5.png b/Roll_Students/assets/img/RollClass/RollClass5_5.png new file mode 100644 index 0000000..2fee6b8 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_5.png differ diff --git a/Roll_Students/assets/img/RollClass/RollClass5_6.png b/Roll_Students/assets/img/RollClass/RollClass5_6.png new file mode 100644 index 0000000..d144be1 Binary files /dev/null and b/Roll_Students/assets/img/RollClass/RollClass5_6.png differ diff --git a/Roll_Students/assets/img/lodding/lodding1.png b/Roll_Students/assets/img/lodding/lodding1.png new file mode 100644 index 0000000..5d30ffe Binary files /dev/null and b/Roll_Students/assets/img/lodding/lodding1.png differ diff --git a/Roll_Students/assets/img/lodding/lodding2.png b/Roll_Students/assets/img/lodding/lodding2.png new file mode 100644 index 0000000..3a926e4 Binary files /dev/null and b/Roll_Students/assets/img/lodding/lodding2.png differ diff --git a/Roll_Students/assets/img/nav/nav1-1.png b/Roll_Students/assets/img/nav/nav1-1.png new file mode 100644 index 0000000..0553594 Binary files /dev/null and b/Roll_Students/assets/img/nav/nav1-1.png differ diff --git a/Roll_Students/assets/img/nav/nav1-2.png b/Roll_Students/assets/img/nav/nav1-2.png new file mode 100644 index 0000000..95c4ee7 Binary files /dev/null and b/Roll_Students/assets/img/nav/nav1-2.png differ diff --git a/Roll_Students/assets/img/nav/nav2-1.png b/Roll_Students/assets/img/nav/nav2-1.png new file mode 100644 index 0000000..b106712 Binary files /dev/null and b/Roll_Students/assets/img/nav/nav2-1.png differ diff --git a/Roll_Students/assets/img/nav/nav2-2.png b/Roll_Students/assets/img/nav/nav2-2.png new file mode 100644 index 0000000..0af4767 Binary files /dev/null and b/Roll_Students/assets/img/nav/nav2-2.png differ diff --git a/Roll_Students/assets/img/nav/nav3-1.png b/Roll_Students/assets/img/nav/nav3-1.png new file mode 100644 index 0000000..d56369f Binary files /dev/null and b/Roll_Students/assets/img/nav/nav3-1.png differ diff --git a/Roll_Students/assets/img/nav/nav3-2.png b/Roll_Students/assets/img/nav/nav3-2.png new file mode 100644 index 0000000..d63a81a Binary files /dev/null and b/Roll_Students/assets/img/nav/nav3-2.png differ diff --git a/Roll_Students/assets/img/setting/setting1.png b/Roll_Students/assets/img/setting/setting1.png new file mode 100644 index 0000000..f341fa1 Binary files /dev/null and b/Roll_Students/assets/img/setting/setting1.png differ diff --git a/Roll_Students/assets/img/setting/setting2.png b/Roll_Students/assets/img/setting/setting2.png new file mode 100644 index 0000000..5846a80 Binary files /dev/null and b/Roll_Students/assets/img/setting/setting2.png differ diff --git a/Roll_Students/assets/img/setting/setting3.png b/Roll_Students/assets/img/setting/setting3.png new file mode 100644 index 0000000..691d20d Binary files /dev/null and b/Roll_Students/assets/img/setting/setting3.png differ diff --git a/Roll_Students/assets/img/setting/setting4.png b/Roll_Students/assets/img/setting/setting4.png new file mode 100644 index 0000000..a8b7389 Binary files /dev/null and b/Roll_Students/assets/img/setting/setting4.png differ diff --git a/Roll_Students/pages/AddClass/AddClass.js b/Roll_Students/pages/AddClass/AddClass.js new file mode 100644 index 0000000..ccd8218 --- /dev/null +++ b/Roll_Students/pages/AddClass/AddClass.js @@ -0,0 +1,136 @@ +Page({ + onCardTap: function() { + wx.switchTab({ + url: '/pages/RollClass/RollClass', + }) + }, + + data: { + cards: [], // 班级数据数组,存储当前已有的班级 + modalVisible1: false, // 控制浮窗1的显隐状态 + modalVisible2: false, // 控制浮窗2的显隐状态 + modalVisible3: false, // 控制浮窗3的显隐状态 + modalVisible4: false, // 控制浮窗4的显隐状态 + className: '', // 存储输入的班级名称(浮窗1) + fileName: '' // 存储选择的文件名(浮窗2) + }, + + // 点击加号按钮后触发,显示浮窗 + onAddCard() { + this.setData({ + modalVisible1: true // 设置浮窗可见 + }); + }, + + // 处理输入框的输入事件,更新班级名称 + onInput(e) { + this.setData({ + className: e.detail.value // 更新输入的班级名称为用户输入 + }); + }, + + // 浮窗1确认按钮的点击事件处理 + onConfirm1() { + this.setData({ + modalVisible1: false, // 隐藏浮窗 + modalVisible2: true //显示浮窗2 + }); + }, + + // 浮窗1取消按钮的点击事件处理 + onCancel1() { + this.setData({ + modalVisible1: false, // 隐藏浮窗 + className: null // 重置输入框内容 + }); + }, + + // 浮窗2选择文件的处理函数 + onSelectFile() { + wx.chooseMessageFile({ + count: 1, + type: 'file', + success: (res) => { + const filePath = res.tempFiles[0].path; // 依然使用相对路径 + this.setData({ + fileName: filePath.split('/').pop() // 取文件名部分 + }); + console.log("选中的文件路径:", filePath); // 可以在这里使用相对路径进行后续处理 + }, + fail: (err) => { + console.error("选择文件失败:", err); + } + }); + }, + + // 浮窗2确认按钮的点击事件处理 + onConfirm2() { + // 处理确认逻辑 + console.log('确认导入文件:', this.data.fileName); + this.setData({ + modalVisible2: false, // 隐藏浮窗 + fileName:null, + modalVisible3: true //显示浮窗3 + }); + }, + + // 浮窗2取消按钮的点击事件处理 + onCancel2() { + this.setData({ + modalVisible2: false, // 隐藏浮窗 + className:null, + fileName: null // 清空选择的文件 + }); + }, + + // 浮窗3确认按钮的点击事件处理 + onConfirm3() { + const { className, cards } = this.data; + + // 检查班级名是否已存在 + const classExists = cards.some(card => card.name === className); + + if (classExists) { + // 如果班级名已经存在,弹出错误提示或进行其他处理 + this.setData({ + modalVisible3:false, + modalVisible4:true, + className:null, + fileName: null + }); + return; // 结束函数执行 + } + + // 创建新班级对象 + const newCard = { + name: className || '新课程', // 使用用户输入的班级名,如果为空则默认 + studentCount: 30, + creationDate: new Date().toLocaleDateString() // 当前日期 + }; + + // 更新数据状态 + this.setData({ + cards: [...cards, newCard], // 将新卡片加入数组 + modalVisible3: false, // 隐藏浮窗 + className:null, + fileName: null + }); + }, + + // 浮窗3取消按钮的点击事件处理 + onCancel3(){ + this.setData({ + modalVisible3:false, + className:null, + fileName: null + }); + }, + + onCancel4(){ + this.setData({ + modalVisible4:false, + className:null, + fileName: null + }); + } +}); \ No newline at end of file diff --git a/Roll_Students/pages/AddClass/AddClass.json b/Roll_Students/pages/AddClass/AddClass.json new file mode 100644 index 0000000..49037f6 --- /dev/null +++ b/Roll_Students/pages/AddClass/AddClass.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "班级列表", + "navigationBarBackgroundColor": "#F5F8F9", + "backgroundColor": "#eeeeee", + "navigationBarTextStyle": "black", + "usingComponents": {} +} diff --git a/Roll_Students/pages/AddClass/AddClass.wxml b/Roll_Students/pages/AddClass/AddClass.wxml new file mode 100644 index 0000000..ec255d4 --- /dev/null +++ b/Roll_Students/pages/AddClass/AddClass.wxml @@ -0,0 +1,110 @@ + + + + + + + 人工智能 + + 班级人数:100 + 创建日期:2024/10/1 + + + + + + + + + Linux实践 + + 班级人数:100 + 创建日期:2024/10/1 + + + + + + + + + 操作系统 + + 班级人数:100 + 创建日期:2024/10/1 + + + + + + + + + + + {{item.name}} + + 班级人数:{{item.studentCount}} + 创建日期:{{item.creationDate}} + + + + + + + + + + + + + + + + + + + + + + diff --git a/Roll_Students/pages/AddClass/AddClass.wxss b/Roll_Students/pages/AddClass/AddClass.wxss new file mode 100644 index 0000000..c52a76b --- /dev/null +++ b/Roll_Students/pages/AddClass/AddClass.wxss @@ -0,0 +1,180 @@ +.container { + display: flex; + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + align-items: center; + height: 100vh; + background-color: #f5f8f9; + padding-top:20rpx; +} + +.class-card { + background-color: #f5f8f9; + padding: 20rpx; + margin-top: 20rpx; /* 每个卡片上方的间距 */ + border-radius: 20rpx; + box-shadow: 4rpx 4rpx 6rpx rgba(64, 149, 229, 0.85); + display: flex; + justify-content: space-between; + align-items: center; + border: 2rpx solid rgba(29,70,157,1); + width: 600rpx; + height: 100rpx; +} + +.class-image{ + width:80rpx; + height: 80rpx; + border-radius: 10rpx; + margin-right: 20rpx; +} + +.class-info{ + white-space: pre; + flex:1; /* 意味着该元素可以占用容器中所有可用的空间。 */ +} + +.class-name { + font-size: 36rpx; + font-weight: bold; +} + +.class-details { + font-size: 24rpx; + color: #888888; + display: flex; /* 使子元素以行内显示 */ + gap:20rpx; +} + +.arrow { + width: 16px; + height: 16px; +} + +.add-button { + padding:0; + margin: 0; + flex:none; + position: fixed; /* 固定在视口 */ + bottom: 75rpx; /* 距离底部20rpx */ + right: 75rpx; /* 距离右侧20rpx */ + width: 100rpx; /* 按钮宽度 */ + height: 100rpx; /* 按钮高度 */ + background-color: #f5f8f9; /*按钮颜色*/ + border: none; /* 去掉默认边框 */ + display:flex; + justify-content: center; /* 图片在按钮内部水平居中 */ + align-items: center; /* 图片在按钮内部垂直居中 */ + box-sizing: border-box; +} + +/* 图片样式 */ +.add-image { + width: 100rpx; /* 图片宽度 */ + height: 100rpx; /* 图片高度 */ +} + +/* 浮窗的覆盖层 通用 */ +.modal { + position: fixed; /* 绝对定位以覆盖整个视口 */ + left: 0; + top: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); /* 背景为半透明黑色 */ + display: flex; /* 使用flex布局 */ + justify-content: center; /* 居中对齐内容 */ + align-items: center; /* 垂直居中对齐 */ +} + +/* 浮窗内容 通用 */ +.modal-content { + background-color: #4095e5; /* 浮窗的背景颜色 */ + padding: 40rpx 20rpx; /* 内边距 */ + border-radius: 20rpx; /* 圆角 */ + width: 80%; /* 浮窗宽度为视口的80% */ + max-width: 500rpx; /* 最大宽度为500rpx */ +} + +/* 浮窗标题 通用 */ +.modal-title { + color: white; + font-weight: bold; + font-size: 46rpx; /* 字体大小 */ + margin-top: 30rpx; + margin-bottom: 30rpx; + text-shadow: 4rpx 4rpx 6rpx rgba(0, 0, 0, 0.4); +} + +/* 输入框样式 */ +.input-box { + width: 90%; /* 输入框宽度占满父容器 */ + margin-top: 10rpx; /* 上方留出间隙 */ + padding: 25rpx; /* 内边距 */ + border: none; /* 去掉边框 */ + border-bottom: 2rpx solid #fff; /* 底部边框 */ + border-radius: 20rpx; /* 圆角 */ + background-color: #fff; /* 背景颜色 */ + color: black; /* 字体颜色 */ + box-shadow: 4rpx 4rpx 6rpx rgba(0, 0, 0, 0.4); +} + +/* 设置 placeholder 的颜色 */ +.input-box::-webkit-input-placeholder { + color: #888888; /* 输入框班级名称的颜色 */ +} + +/* 浮窗按钮容器 通用 */ +.modal-buttons { + display: flex; /* 使用flex布局 */ + justify-content: space-between; /* 按钮间隔均匀 */ + margin-top: 20rpx; /* 上方留出空间 */ + gap:50rpx; /* 设置按钮之间的间距 */ + margin-left: 50rpx; + margin-right: 50rpx; +} + +/* 确认、取消按钮样式 通用 */ +.confirm-button, .cancel-button { + background-color: white; /* 按钮背景颜色 */ + color: #0014b7; /* 按钮文字颜色 */ + flex: 1; /* 等宽 */ + padding: 10rpx; /* 内边距 */ + border: none; /* 去掉默认边框 */ + border-radius: 20rpx; /* 圆角 */ + margin-left: 10rpx; /* 按钮间距 */ + box-shadow: 4rpx 4rpx 6rpx rgba(0, 0, 0, 0.4); +} + +/* 文件选择部分 */ +.file-selection { + display: flex; /* 使用flex布局 */ + align-items: center; /* 垂直居中 */ + margin-bottom: 10rpx; /* 底部留出一些间距 */ +} + +/* 选择文件按钮样式 */ +.select-file-button { + background-color: white; /* 按钮背景颜色 */ + color: #0014b7; /* 按钮文字颜色 */ + padding: 15rpx; /* 内边距 */ + border: none; /* 去掉默认边框 */ + font-size: 30rpx; + width: 200rpx; + border-radius: 20rpx; /* 圆角 */ + margin-right: 20rpx; /* 按钮与文件名之间的间距 */ + box-shadow: 4rpx 4rpx 6rpx rgba(0, 0, 0, 0.4); + box-sizing: border-box; /* 包含边距和内边距 */ +} + +/* 文件名的显示样式 */ +.file-name { + color: white; /* 文字颜色 */ +} + +/* 分隔线样式 */ +.divider { + height: 4rpx; /* 分隔线高度 */ + background-color: #0014b7; /* 分隔线颜色 */ + margin: 10rpx 0; /* 上下留出一些间距 */ +} \ No newline at end of file diff --git a/Roll_Students/pages/RollClass/RollClass.js b/Roll_Students/pages/RollClass/RollClass.js new file mode 100644 index 0000000..f281c8e --- /dev/null +++ b/Roll_Students/pages/RollClass/RollClass.js @@ -0,0 +1,19 @@ +Page({ + onStudentList() { + wx.navigateTo({ + url: '/pages/studentList/studentList', + }); + }, + + onStudentRanking() { + wx.navigateTo({ + url: '/pages/studentRanking/studentRanking', + }); + }, + + onStartNaming() { + wx.navigateTo({ + url: '/pages/startNaming/startNaming', + }); + } +}); diff --git a/Roll_Students/pages/RollClass/RollClass.json b/Roll_Students/pages/RollClass/RollClass.json new file mode 100644 index 0000000..a3e1807 --- /dev/null +++ b/Roll_Students/pages/RollClass/RollClass.json @@ -0,0 +1,5 @@ +{ + "navigationBarBackgroundColor": "#F5F8F9", + "navigationBarTitleText": "学生点名", + "usingComponents": {} +} \ No newline at end of file diff --git a/Roll_Students/pages/RollClass/RollClass.wxml b/Roll_Students/pages/RollClass/RollClass.wxml new file mode 100644 index 0000000..e37ce64 --- /dev/null +++ b/Roll_Students/pages/RollClass/RollClass.wxml @@ -0,0 +1,23 @@ + + + + 学生名单 + + + + + + + 学生排名 + + + + + + + + 开始点名 + + + + diff --git a/Roll_Students/pages/RollClass/RollClass.wxss b/Roll_Students/pages/RollClass/RollClass.wxss new file mode 100644 index 0000000..161eabe --- /dev/null +++ b/Roll_Students/pages/RollClass/RollClass.wxss @@ -0,0 +1,47 @@ +.container { + display: flex; + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + align-items: center; + height: 100vh; + background-color: #f5f8f9; + padding-top:20rpx; +} + +.menu-item { + cursor: pointer; /* 鼠标悬停时显示为指针 */ + background-color: #f5f8f9; + padding: 20rpx; + margin-top: 20rpx; /* 每个卡片上方的间距 */ + border-radius: 20rpx; + box-shadow: 4rpx 4rpx 6rpx rgba(64, 149, 229, 0.85); + display: flex; + justify-content: space-between; + align-items: center; + border: 1px solid rgba(29,70,157,1); + width: 600rpx; + height: 100rpx; +} + +.icon { + width: 75rpx; /* 图标大小 */ + height: 75rpx; /* 图标大小 */ + margin-right: 10rpx; /* 图标与文本之间的间距 */ +} + +.menu-text { + font-size: 32rpx; /* 文本字体大小 */ + font-weight: bold; + flex: 1; /* 使文本占据剩余空间 */ +} + +.additional-icon { + width: 120rpx; /* 调整大小 */ + height: 120rpx; /* 调整大小 */ + margin-left: 20rpx; /* 添加间距 */ +} + +.arrow { + width: 48rpx; /* 箭头图标大小 */ + height: 48rpx; /* 箭头图标大小 */ +} diff --git a/Roll_Students/pages/index/index.js b/Roll_Students/pages/index/index.js new file mode 100644 index 0000000..a8d6aa5 --- /dev/null +++ b/Roll_Students/pages/index/index.js @@ -0,0 +1,49 @@ +// index.js +const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0' + +Page({ + data: { + motto: 'Hello World', + userInfo: { + avatarUrl: defaultAvatarUrl, + nickName: '', + }, + hasUserInfo: false, + canIUseGetUserProfile: wx.canIUse('getUserProfile'), + canIUseNicknameComp: wx.canIUse('input.type.nickname'), + }, + bindViewTap() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onChooseAvatar(e) { + const { avatarUrl } = e.detail + const { nickName } = this.data.userInfo + this.setData({ + "userInfo.avatarUrl": avatarUrl, + hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, + }) + }, + onInputChange(e) { + const nickName = e.detail.value + const { avatarUrl } = this.data.userInfo + this.setData({ + "userInfo.nickName": nickName, + hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, + }) + }, + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + console.log(res) + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + }, +}) diff --git a/Roll_Students/pages/index/index.json b/Roll_Students/pages/index/index.json new file mode 100644 index 0000000..b55b5a2 --- /dev/null +++ b/Roll_Students/pages/index/index.json @@ -0,0 +1,4 @@ +{ + "usingComponents": { + } +} \ No newline at end of file diff --git a/Roll_Students/pages/index/index.wxml b/Roll_Students/pages/index/index.wxml new file mode 100644 index 0000000..0721ba0 --- /dev/null +++ b/Roll_Students/pages/index/index.wxml @@ -0,0 +1,27 @@ + + + + + + + + 昵称 + + + + + + 请使用2.10.4及以上版本基础库 + + + + {{userInfo.nickName}} + + + + {{motto}} + + + diff --git a/Roll_Students/pages/index/index.wxss b/Roll_Students/pages/index/index.wxss new file mode 100644 index 0000000..1ebed4b --- /dev/null +++ b/Roll_Students/pages/index/index.wxss @@ -0,0 +1,62 @@ +/**index.wxss**/ +page { + height: 100vh; + display: flex; + flex-direction: column; +} +.scrollarea { + flex: 1; + overflow-y: hidden; +} + +.userinfo { + display: flex; + flex-direction: column; + align-items: center; + color: #aaa; + width: 80%; +} + +.userinfo-avatar { + overflow: hidden; + width: 128rpx; + height: 128rpx; + margin: 20rpx; + border-radius: 50%; +} + +.usermotto { + margin-top: 200px; +} + +.avatar-wrapper { + padding: 0; + width: 56px !important; + border-radius: 8px; + margin-top: 40px; + margin-bottom: 40px; +} + +.avatar { + display: block; + width: 56px; + height: 56px; +} + +.nickname-wrapper { + display: flex; + width: 100%; + padding: 16px; + box-sizing: border-box; + border-top: .5px solid rgba(0, 0, 0, 0.1); + border-bottom: .5px solid rgba(0, 0, 0, 0.1); + color: black; +} + +.nickname-label { + width: 105px; +} + +.nickname-input { + flex: 1; +} diff --git a/Roll_Students/pages/lodding/lodding.js b/Roll_Students/pages/lodding/lodding.js new file mode 100644 index 0000000..11b3205 --- /dev/null +++ b/Roll_Students/pages/lodding/lodding.js @@ -0,0 +1,8 @@ +Page({ + startApp() { + // 页面跳转到首页或其他功能页 + wx.switchTab({ + url: '/pages/AddClass/AddClass', + }); + } +}); diff --git a/Roll_Students/pages/lodding/lodding.json b/Roll_Students/pages/lodding/lodding.json new file mode 100644 index 0000000..157066c --- /dev/null +++ b/Roll_Students/pages/lodding/lodding.json @@ -0,0 +1,6 @@ +{ + "navigationBarTextStyle": "black", + "navigationBarTitleText": "学生点名系统", + "navigationBarBackgroundColor": "#ffffff", + "usingComponents": {} +} \ No newline at end of file diff --git a/Roll_Students/pages/lodding/lodding.wxml b/Roll_Students/pages/lodding/lodding.wxml new file mode 100644 index 0000000..ad219bd --- /dev/null +++ b/Roll_Students/pages/lodding/lodding.wxml @@ -0,0 +1,22 @@ + + + + + + + + 学生点 + 名系统 + + + + + + + + + + + + + diff --git a/Roll_Students/pages/lodding/lodding.wxss b/Roll_Students/pages/lodding/lodding.wxss new file mode 100644 index 0000000..46d9208 --- /dev/null +++ b/Roll_Students/pages/lodding/lodding.wxss @@ -0,0 +1,100 @@ +/* 页面整体布局 */ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + background-color: #93d2f3; +} + +/* 图片容器,使用相对定位 */ +.image-container { + display: flex; + justify-content: center; + align-items: center; + position: relative; + width: 100%; +} + +/* 背景图片 */ +.background-image { + width: 597.3rpx; + height: 320rpx; + opacity: 0; + animation: fadeIn 200ms ease-in forwards; + animation-delay: 400ms; +} + +/* 文字样式,竖向排列 */ +.overlay-text { + white-space: pre; /* 保留文本中的空格 */ + writing-mode: vertical-lr; /* 让文字竖向排列 */ + text-orientation: upright; /* 保持文字正方向 */ + font-size: 137.4rpx; /* 设定文字大小 */ + line-height: 1.5; /* 调整行高,使文字之间有间距 */ + color: white; /* 文字颜色 */ + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); /* 让文字垂直水平居中 */ + text-shadow: 3.8rpx 7.6rpx 11.5rpx #1d469d; + font-weight: bold; + opacity: 0; /*初始透明读*/ + animation: fadeIn 400ms ease-in forwards; +} + + +/* 页面整体布局 */ +.container { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; /* 使容器高度为视口高度 */ + background-color: #93d2f3; /* 背景颜色 */ +} + +/* 图片容器,使用相对定位 */ +.image-container2 { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + position: relative; /* 为绝对定位的子元素提供相对定位 */ + width: 100%; +} + +/* 背景图片 */ +.background-image2 { + width: 597.3rpx; + height: 862.6rpx; + opacity: 0; + animation: fadeIn 200ms ease-in forwards; + animation-delay: 600ms; +} + +/* 按钮样式 */ +.image-button { + position: absolute; /* 使按钮相对于父容器绝对定位 */ + top: 50%; /* 使按钮垂直居中 */ + left: 50%; /* 使按钮水平居中 */ + transform: translate(-50%, -50%); /* 精确居中 */ +} + +/* 按钮样式 */ +.start-button { + background-color: #4095e5; + color: white; + font-size: 76.3rpx; + border-radius: 40rpx; + box-shadow: 6rpx 4rpx 6rpx #0f40f5; + opacity: 0; + animation: fadeIn 200ms ease-in forwards; + animation-delay: 600ms; +} + +@keyframes fadeIn{ + to{ + opacity: 1; /*最终透明度*/ + } +} \ No newline at end of file diff --git a/Roll_Students/pages/logs/logs.js b/Roll_Students/pages/logs/logs.js new file mode 100644 index 0000000..85f6aac --- /dev/null +++ b/Roll_Students/pages/logs/logs.js @@ -0,0 +1,18 @@ +// logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad() { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return { + date: util.formatTime(new Date(log)), + timeStamp: log + } + }) + }) + } +}) diff --git a/Roll_Students/pages/logs/logs.json b/Roll_Students/pages/logs/logs.json new file mode 100644 index 0000000..b55b5a2 --- /dev/null +++ b/Roll_Students/pages/logs/logs.json @@ -0,0 +1,4 @@ +{ + "usingComponents": { + } +} \ No newline at end of file diff --git a/Roll_Students/pages/logs/logs.wxml b/Roll_Students/pages/logs/logs.wxml new file mode 100644 index 0000000..85cf1bf --- /dev/null +++ b/Roll_Students/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log.date}} + + diff --git a/Roll_Students/pages/logs/logs.wxss b/Roll_Students/pages/logs/logs.wxss new file mode 100644 index 0000000..33f9d9e --- /dev/null +++ b/Roll_Students/pages/logs/logs.wxss @@ -0,0 +1,16 @@ +page { + height: 100vh; + display: flex; + flex-direction: column; +} +.scrollarea { + flex: 1; + overflow-y: hidden; +} +.log-item { + margin-top: 20rpx; + text-align: center; +} +.log-item:last-child { + padding-bottom: env(safe-area-inset-bottom); +} diff --git a/Roll_Students/pages/setting/setting.js b/Roll_Students/pages/setting/setting.js new file mode 100644 index 0000000..fea7970 --- /dev/null +++ b/Roll_Students/pages/setting/setting.js @@ -0,0 +1,3 @@ +// pages/setting/setting.js +Page({ +}) \ No newline at end of file diff --git a/Roll_Students/pages/setting/setting.json b/Roll_Students/pages/setting/setting.json new file mode 100644 index 0000000..5b4ef57 --- /dev/null +++ b/Roll_Students/pages/setting/setting.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "设置", + "navigationBarBackgroundColor": "#F5F8F9", + "backgroundColor": "#eeeeee", + "navigationBarTextStyle": "black", + "usingComponents": {} +} \ No newline at end of file diff --git a/Roll_Students/pages/setting/setting.wxml b/Roll_Students/pages/setting/setting.wxml new file mode 100644 index 0000000..450108b --- /dev/null +++ b/Roll_Students/pages/setting/setting.wxml @@ -0,0 +1,24 @@ + + + + 昵称 + + + + + 个人信息 + + + + + + 意见反馈 + + + + + + 关于我们 + + + diff --git a/Roll_Students/pages/setting/setting.wxss b/Roll_Students/pages/setting/setting.wxss new file mode 100644 index 0000000..ffa37d2 --- /dev/null +++ b/Roll_Students/pages/setting/setting.wxss @@ -0,0 +1,60 @@ +.container { + display: flex; + flex-direction: column; /* 列布局 */ + justify-content: flex-start; /* 从顶部开始对齐 */ + align-items: center; /* 水平居中 */ + height: 100vh; + background-color: #f5f8f9; /* 背景颜色 */ + padding-top: 0; +} + +.profile { + display: flex; /* 横向布局 */ + align-items: center; /* 垂直居中 */ + border-bottom: 1rpx solid #3480FF; /* 下边框 */ + width: 80%; +} + +.profile-image { + width: 136rpx; /* 头像大小 */ + height: 136rpx; /* 头像大小 */ + border-radius: 50%; /* 圆形头像 */ + margin-right: 15rpx; /* 头像与昵称之间的间距 */ +} + +.nickname { + margin-top: 30rpx; + font-size: 36rpx; /* 昵称字 */ + font-weight: bold; /* 加粗 */ +} + +.menu-item { + display: flex; /* 横向布局 */ + align-items: center; /* 垂直居中 */ + padding: 20rpx; /* 内边距 */ + border-bottom: 1rpx solid #3480FF; /* 下边框 */ + width: 80%; /* 宽度 80% 填满容器 */ + cursor: pointer; /* 鼠标悬停时显示为指针 */ + justify-content: space-between; /* 让文本与箭头两端对齐 */ + margin: 8rpx; +} + +.icon { + color:#f5f8f9; + width: 48rpx; + height: 48rpx; + margin-right: 10rpx; /* 图标与文本之间的间距 */ + margin-bottom: 8rpx; +} + +.menu-text { + margin-left: 20rpx; + flex: 1; /* 使文本占据剩余空间 */ + font-size: 28rpx; /* 文本字体大小 */ +} + +.arrow { + color:#f5f8f9; + width: 36rpx; /* 箭头图标大小 */ + height: 36rpx; +} diff --git a/Roll_Students/pages/startNaming/startNaming.js b/Roll_Students/pages/startNaming/startNaming.js new file mode 100644 index 0000000..20ef0f3 --- /dev/null +++ b/Roll_Students/pages/startNaming/startNaming.js @@ -0,0 +1,233 @@ +Page({ + data:{ + modalVisible1:false, + modalVisible2:false, + modalVisible3:false, + modalVisible4:false, + modalVisible5:false, + modalVisible6:false, + scoreModalVisible: false, + name:'', + score:'', + studentCount: "", // 存储输入的学生人数 + dice:0, // 默认模式 + diceImage:'/assets/img/RollClass/RollClass5_1.png', // 初始骰子图像 + roll_or_request:0, + selectedStudents: [], // 用于存储随机选择的学生 + currentStudentIndex: null, // 当前选中学生的索引 + query: '', + foundStudent: null, // 存储找到的学生 + students: [] + }, + onLoad() { + const app = getApp(); + this.setData({ + students: app.globalData.students // 设置全局数据 + }); + // console.log(this.data.students); // 检查此时的学生数据 + }, + + onAbout(){ + this.setData({ + modalVisible1:true, + }) + }, + + onAdd(){ + this.setData({ + modalVisible2:true, + }); + }, + + onRank(){ + wx.navigateTo({ + url: '/pages/studentRanking/studentRanking', + }); + }, + + onRoll(){ + this.setData({ + modalVisible4:true + }); + }, + + onRollCall() { + this.setData({ + modalVisible3:true, + roll_or_request:0 + }); + }, + + onRequest() { + this.setData({ + modalVisible3:true, + roll_or_request:1 + }); + }, + + // 加分 + addScore(event){ + const index = event.currentTarget.dataset.index; // 获取点击的学生索引 + this.setData({ + currentStudentIndex: index, // 保存当前学生索引 + modalVisible5:true + }) + }, + // 浮窗 + closeModal(){ + this.setData({ + modalVisible1:false, + modalVisible2:false, + modalVisible3:false, + modalVisible4:false, + modalVisible5:false, + modalVisible6:false, + name:'', + score:'', + studentCount:"" + }) + }, + + // 浮窗2 + onInputName(event) { + this.setData({ + name: event.detail.value + }); + }, + + onInputScore(event) { + this.setData({ + score: parseInt(event.detail.value) || 0 // 确保总是为数字 + }); + }, + + // 查询加分 + onConfirm2() { + const { name, score, students } = this.data; + + // 判断输入是否为数字 + const isNumeric = !isNaN(name) && name.trim() !== ''; + + // 查找学生 + const foundStudent = students.find(student => { + return isNumeric ? student.id === parseInt(name) : student.name === name; + }); + + if (foundStudent) { + foundStudent.score += score; // 修改找到的学生的分数 + + this.setData({ + students: [...students], // 更新页面的学生数据 + scoreInfo: { // 设置要显示的分数信息 + name: foundStudent.name, + id: foundStudent.id, + score: foundStudent.score + }, + scoreModalVisible: true // 显示分数弹窗 + }); + + console.log("更新后的学生数据:", foundStudent); + + // 获取全局变量并更新 + const app = getApp(); + app.globalData.students = [...students]; // 将修改后的数据同步到全局 + + } + else { + // 没有找到学生时显示错误弹窗 + this.setData({ + modalVisible6: true + }); + } + + // console.log("姓名:", this.data.name); + // console.log("得分:", this.data.score); + + // 重置输入框和隐藏弹窗 + this.setData({ + name: '', + score: '', + modalVisible2: false + }); + }, + + + // 浮窗3 + onInputNum(event){ + this.setData({ + studentCount:event.detail.value + }); + }, + + onConfirm3() { + const { studentCount, students } = this.data; + + if (studentCount > students.length) { + wx.showToast({ title: '人数超出范围', icon: 'none' }); + return; + } + + // 随机选择学生 + const selectedStudents = this.getRandomStudents(students, studentCount); + this.setData({ + selectedStudents,studentCount: '', // 清空输入框 + modalVisible3: false // 关闭弹窗 + }); + + console.log("随机选择的学生:", selectedStudents); // 打印随机选择的学生 + }, + + // 随机选择学生函数 + getRandomStudents(students, count) { + const shuffled = students.sort(() => 0.5 - Math.random()); // 打乱数组 + return shuffled.slice(0, count); // 选择前 count 个学生 + }, + + // 浮窗4 投掷骰子 + onRollDice() { + console.log("投掷骰子按钮被点击"); + // 生成1-6随机数 + const rolledValue = Math.floor(Math.random()*6)+1; + this.setData({ + dice: rolledValue, + diceImage: `/assets/img/RollClass/RollClass5_${rolledValue}.png`, // 更新图像 + }); + }, + + // 浮窗5 加分 处理分数按钮点击 + onScoreChange(event) { + const scoreChange = parseFloat(event.currentTarget.dataset.score); + const { currentStudentIndex, selectedStudents } = this.data; + + if (currentStudentIndex != null) { + selectedStudents[currentStudentIndex].score += scoreChange; // 增加分数 + + // 获取全局变量 + const app = getApp(); + const students = app.globalData.students; + students[currentStudentIndex].score = selectedStudents[currentStudentIndex].score; // 更新全局数据 + + this.setData({ + selectedStudents, + modalVisible5: false, // 关闭加分弹窗 + scoreInfo: { + name: selectedStudents[currentStudentIndex].name, + id: selectedStudents[currentStudentIndex].id, + score: selectedStudents[currentStudentIndex].score + }, + scoreModalVisible: true // 显示得分弹窗 + }); + + console.log("更新后的分数:", selectedStudents[currentStudentIndex].score); + } + }, + + + // 浮窗7 得分信息 + closeScoreModal() { + this.setData({ + scoreModalVisible: false // 隐藏得分弹窗 + }); + } + +}); diff --git a/Roll_Students/pages/startNaming/startNaming.json b/Roll_Students/pages/startNaming/startNaming.json new file mode 100644 index 0000000..2f44553 --- /dev/null +++ b/Roll_Students/pages/startNaming/startNaming.json @@ -0,0 +1,5 @@ +{ + "navigationBarBackgroundColor": "#F5F8F9", + "navigationBarTitleText": "开始点名", + "usingComponents": {} +} \ No newline at end of file diff --git a/Roll_Students/pages/startNaming/startNaming.wxml b/Roll_Students/pages/startNaming/startNaming.wxml new file mode 100644 index 0000000..a8a3650 --- /dev/null +++ b/Roll_Students/pages/startNaming/startNaming.wxml @@ -0,0 +1,111 @@ + + + + + + + + {{item.name}} + {{item.id}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Roll_Students/pages/startNaming/startNaming.wxss b/Roll_Students/pages/startNaming/startNaming.wxss new file mode 100644 index 0000000..c7bfa2e --- /dev/null +++ b/Roll_Students/pages/startNaming/startNaming.wxss @@ -0,0 +1,231 @@ +.container { + display: flex; + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + align-items: center; + height: 100vh; + background-color: #f5f8f9; + padding-top:20rpx; +} + +.header { + display: flex; /* 横向布局 */ + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + padding: 10rpx; /* 内边距 */ + width: 100%; + height: 950rpx; + background-color: #ffffff; /* 内容背景颜色 */ + border-radius: 40rpx; /* 圆角效果 */ + border:2rpx solid #bbbbbb; + box-shadow: 0 6rpx 15rpx rgba(0, 0, 0, 0.2); /* 轻微阴影 */ +} + +.header-content{ + display: flex; /* 横向布局 */ + flex-direction: row; +} + +.parent-container{ + width: 650rpx; +} + +.grid-container { + width: 90%; + flex: 1; /* 使内容区填满剩余空间 */ + padding: 20rpx; /* 内边距 */ + border-radius: 10rpx; /* 圆角效果 */ + display: grid; /* 使用 Grid 布局 */ + grid-template-columns: repeat(3, 1fr); /* 三列 */ + gap: 50rpx; /* 项目之间的间距 */ + max-height: 900rpx; /* 设置最大高度 */ + overflow-y: auto; /* 允许垂直滚动 */ +} + +.student-card { + background-color: #93d2f3; /* 背景颜色 */ + border: 2px solid #0014b7; /* 边框颜色 */ + display: flex; + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + align-items: center; + border-radius: 10rpx; /* 圆角 */ + padding: 20rpx; /* 内边距 */ + text-align: center; /* 文本居中 */ + height: 140rpx; +} + +.student-avatar { + width: 80rpx; /* 头像大小 */ + height: 80rpx; /* 头像大小 */ +} + +.student-name { + font-size: 26rpx; /* 名字字体大小 */ + color: white; /* 名字颜色 */ + font-weight: bold; +} + +.header-icon{ + margin-top: 10rpx; + margin-bottom: 10rpx; + display: flex; + flex-direction: column; + height: 930rpx; +} + +.icon { + width: 48rpx; /* 图标大小 */ + height: 48rpx; /* 图标大小 */ + margin-top: 20rpx; + margin-left: 20rpx; /* 左间距 */ + margin-right: 20rpx; +} + +.footer { + display: flex; /* 横向布局 */ + justify-content: space-around; /* 均匀分布 */ + flex-direction: column; + padding: 10rpx; /* 内边距 */ +} + +.button { + background-color: #4095e5; /* 按钮背景颜色 */ + color: white; /* 按钮字体颜色 */ + border-radius: 20rpx; /* 按钮圆角 */ + margin-top: 50rpx; + height: 90rpx; /* 按钮高度 */ + display: flex; /* 使用 Flexbox 布局 */ + align-items: center; /* 垂直居中 */ + justify-content: center; /* 水平居中 */ + box-shadow: 4rpx 4rpx 6rpx #888888; +} + + +.floating-icon { + position: absolute; /* 浮动图标绝对定位 */ + bottom: 365rpx; /* 距离底部 */ + right: 95rpx; /* 距离右侧 */ + width: 75rpx; /* 图标大小 */ + height: 75rpx; /* 图标大小 */ + border-radius: 20rpx; + box-shadow: 4rpx 4rpx 6rpx #888888; +} + +/* 浮窗部分 */ +.modal { /* 通用 */ + position: fixed; /* 绝对定位以覆盖整个视口 */ + left: 0; + top: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); /* 背景为半透明黑色 */ + display: flex; /* 使用flex布局 */ + justify-content: center; /* 居中对齐内容 */ + align-items: center; /* 垂直居中对齐 */ +} + +.modal-content { /* 通用 */ + background-color: #ffffff; /* 浮窗的背景颜色 */ + border-radius: 20rpx; /* 圆角 */ + border:blue; + padding: 60rpx; /* 内边距 */ + width: 50%; +} + +.modal-title { + font-size: 32rpx; /* 标题字体大小 */ + margin-bottom: 25rpx; /* 下边距 */ + font-weight: bold; +} + +.modal-description { + font-size: 26rpx; /* 描述字体大小 */ + margin-bottom: 20rpx; /* 下边距 */ +} + +/* 浮窗2&3 */ +.input-field { + border: 1rpx solid #4095e5; /* 边框颜色 */ + border-radius: 10rpx; /* 圆角 */ + padding: 20rpx; /* 内边距 */ + margin-bottom: 20rpx; /* 下边距 */ + width: 90%; /* 输入框宽度 */ + font-size: 26rpx; /* 字体大小 */ +} + +.modal-button-container { + display: flex; /* 横向布局 */ + justify-content: center; /* 居中对齐,可以用 flex-start 或 flex-end 代替 */ + gap:60rpx; +} + +.modal-button { + background-color: #4095e5; /* 按钮背景颜色 */ + color: white; /* 按钮字体颜色 */ + border-radius: 10rpx; /* 按钮圆角 */ + padding: 10rpx; /* 内边距 */ + flex: 1; /* 使按钮占据可用空间 */ + box-shadow: 4rpx 4rpx 6rpx rgba(0, 0, 0, 0.2); +} + +/* 浮窗4 */ +.floating-title { + font-size: 24px; /* 标题字体大小 */ + margin-bottom: 20px; /* 下边距 */ + text-align: center; /* 居中 */ +} + +.dice-container { + display: flex; /* 水平布局 */ + justify-content: center; /* 水平居中 */ + align-items: center; /* 垂直居中 */ + margin-bottom: 20px; /* 下边距 */ +} + +.dice { + width: 100px; /* 骰子宽度 */ + height: 100px; /* 骰子高度 */ + border: 1px solid #4095e5; /* 骰子边框颜色 */ + border-radius: 10px; /* 圆角效果 */ + display: flex; /* 水平布局 */ + align-items: center; /* 垂直居中 */ + justify-content: center; /* 水平居中 */ + box-shadow: 0 0 10rpx #4095e5; +} + +.dot { + width: 60px; /* 图片大小 */ + height: 60px; /* 图片大小 */ +} + +/* 浮窗5 得分 */ +.modal-background{ + position: absolute; /* 绝对定位的背景 */ + left: 0; + top: 0; + right: 0; + bottom: 0; +} + +.button-container { + display: flex; /* 横向布局 */ + flex-direction: column; /* 垂直排列 */ +} + +.score-button { + background-color: #0014b7; /* 按钮背景颜色 */ + color: white; /* 字体颜色 */ + border-radius: 10rpx; /* 圆角 */ + padding: 15rpx; /* 按钮内边距 */ + margin: 6rpx 0; /* 上下间距 */ + font-size: 28rpx; /* 字体大小 */ + width: 100rpx; + box-shadow: 3rpx 3rpx 6rpx rgba(0, 0, 0, 0.4); +} + +/* 浮窗6 查询不到该学生 */ +.modal-text{ + font-weight: bold; + font-size: 36rpx; +} diff --git a/Roll_Students/pages/studentList/studentList.js b/Roll_Students/pages/studentList/studentList.js new file mode 100644 index 0000000..cfc67cd --- /dev/null +++ b/Roll_Students/pages/studentList/studentList.js @@ -0,0 +1,91 @@ +Page({ + data: { + students: [], + modalVisible: false, + modalVisible1:false, + foundStudent: null, // 存储查询到的学生 + searchValue: '' + }, + + onLoad() { + const app = getApp(); + let students = app.globalData.students || []; // 获取全局数据 + + // 按照id排序 从小到大 + students = students.sort((a, b) => a.id - b.id) + + this.setData({ + students: students + }); + + // console.log("按照id排序", this.data.students); + }, + + // 发现图标被点击 + onIconClick() { + // console.log("图标被点击了!"); + wx.navigateTo({ + url: '/pages/somePage/somePage', // 跳转到某个页面 + }); + }, + + // 打开弹窗 + openModal() { + this.setData({ + modalVisible: true + }); + }, + + // 监听输入框内容 + onInput(event) { + this.setData({ + searchValue: event.detail.value + }); + }, + + onSearch() { + // console.log("点击查询按钮"); + const { searchValue, students } = this.data; + + // 判断输入是否为数字 + const isNumeric = !isNaN(searchValue) && searchValue.trim() !== ''; + + // 查找学生 + const foundStudent = students.find(student => { + return isNumeric ? student.id === parseInt(searchValue) : student.name === searchValue; + }); + + // 更新查询结果 + this.setData({ + foundStudent: foundStudent, // 保存找到的学生 + searchValue: "", + modalVisible: false // 关闭弹窗 + }); + + // 可以在此处添加一个提示 + if (foundStudent) { + // console.log("找到的学生:", foundStudent); + } else { + this.setData({ + modalVisible1:true + }); + } + }, + + // 返回总人数页面 + closeFound(){ + this.setData({ + foundStudent: null + }) + }, + + closeModal(){ + this.setData({ + foundStudent: null, + modalVisible: false, + modalVisible1: false + }); + } + +}); + diff --git a/Roll_Students/pages/studentList/studentList.json b/Roll_Students/pages/studentList/studentList.json new file mode 100644 index 0000000..0540512 --- /dev/null +++ b/Roll_Students/pages/studentList/studentList.json @@ -0,0 +1,6 @@ +{ + "navigationBarBackgroundColor": "#F5F8F9", + "navigationBarTitleText": "学生名单", + "usingComponents": { + } +} \ No newline at end of file diff --git a/Roll_Students/pages/studentList/studentList.wxml b/Roll_Students/pages/studentList/studentList.wxml new file mode 100644 index 0000000..edf7093 --- /dev/null +++ b/Roll_Students/pages/studentList/studentList.wxml @@ -0,0 +1,53 @@ + + + 总人数:25 + + + + + + 序号 + 姓名 + 学号 + + + + + + {{foundStudent.index}} + {{foundStudent.name}} + {{foundStudent.id}} + + + + + + + {{item.index}} + {{item.name}} + {{item.id}} + + + + + + + + + + + + diff --git a/Roll_Students/pages/studentList/studentList.wxss b/Roll_Students/pages/studentList/studentList.wxss new file mode 100644 index 0000000..fb11c8a --- /dev/null +++ b/Roll_Students/pages/studentList/studentList.wxss @@ -0,0 +1,130 @@ +.container { + display: flex; + flex-direction: column; + justify-content: flex-start; /* 让元素从容器的顶部开始对齐 */ + align-items: center; + height: 100vh; + background-color: #f5f8f9; + padding-top:20rpx; +} + +.text-cell { + display: flex; /* 使用 Flexbox */ + justify-content: center; /* 水平居中 */ + align-items: center; /* 垂直居中 */ + position: relative; /* 为子元素设置相对定位 */ + padding: 10rpx; /* 内边距 */ +} + +.total { + font-size: 36rpx; /* 字体大小 */ + font-weight: bold; + margin-bottom: 10rpx; /* 下边距 */ +} + +.icon { + width: 54rpx; /* 图标大小 */ + height: 54rpx; /* 图标大小 */ + position: absolute; /* 绝对定位图标 */ + right: 60rpx; /* 居右显示于 container 的右侧 */ + top: 10rpx; +} + +.table-container { + width: 85%; + max-height: 100vh; /* 设置最大高度 */ + overflow-y: auto; /* 允许竖直滚动 */ + border-radius: 20rpx; /* 圆角 */ +} + +.table-header { + display: flex; /* 横向布局 */ + background-color: #4095e5; /* 表头背景 */ + font-weight: bold; + color: white; /* 表头文字颜色 */ + position: sticky; + top: 0; + z-index: 10; +} + +.header-cell { + flex: 1; /* 平均分配宽度 */ + padding: 10rpx; /* 内边距 */ + text-align: center; /* 中心对齐 */ +} + +.table-content { + max-height: 90vh; /* 内容区的最大高度,比容器小,以保证有空间进行滚动 */ +} + +.table-row { + display: flex; /* 横向布局 */ + border-bottom: 1rpx solid #e0e0e0; /* 下边框 */ +} + +.row-cell { + flex: 1; /* 平均分配宽度 */ + padding: 15rpx; /* 内边距 */ + text-align: center; /* 中心对齐 */ +} + +/* 弹窗 */ +.modal { + position: fixed; /* 绝对定位以覆盖整个视口 */ + left: 0; + top: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */ + display: flex; /* 使用 Flexbox */ + justify-content: center; /* 水平居中 */ + align-items: center; /* 垂直居中 */ + z-index: 1000; /* 在最上层 */ +} + +.modal-content { + display: flex; /* 水平布局 */ + align-items: center; /* 垂直居中 */ + background-color: #ffffff; /* 背景颜色 */ + border-radius: 20rpx; /* 圆角 */ + padding: 20rpx; /* 内边距 */ + width: 80%; /* 可调节宽度 */ + max-width: 500rpx; /* 最大宽度 */ + border: 2rpx solid #4095e5; /* 边框颜色 */ +} + +.modal-background{ + position: absolute; /* 绝对定位的背景 */ + left: 0; + top: 0; + right: 0; + bottom: 0; +} + +.search-input { + flex: 1; /* 输入框占据剩余空间 */ + border: none; /* 去掉边框 */ + font-size: 32rpx; /* 字体大小 */ + padding: 10rpx; /* 内边距 */ +} + +.search-button { + background: transparent; /* 透明背景 */ + border: none; /* 去掉边框 */ + padding: 0; /* 去掉内边距 */ + margin-left: 10rpx; /* 控制按钮与输入框的间距 */ + display: flex; /* 为了方便图标在按钮中居中显示 */ + align-items: center; /* 垂直居中 */ +} + +.search-icon { + width: 36rpx; /* 图标大小 */ + height: 36rpx; /* 图标大小 */ + cursor: pointer; /* 鼠标悬停时显示为指针 */ +} + +.modal-text{ + padding: 15rpx; + font-weight: bold; + font-size: 36rpx; +} \ No newline at end of file diff --git a/Roll_Students/pages/studentRanking/studentRanking.js b/Roll_Students/pages/studentRanking/studentRanking.js new file mode 100644 index 0000000..f864c4f --- /dev/null +++ b/Roll_Students/pages/studentRanking/studentRanking.js @@ -0,0 +1,31 @@ +Page({ + data: { + students:[], + rankings: [] + }, + + onLoad() { + const app = getApp(); + let students = app.globalData.students || []; // 获取全局数据 + + // 根据 score 排序并取前 10 位 + students = students.sort((a, b) => b.score - a.score).slice(0, 10); + + // 添加 rank 属性 + students.forEach((student, index) => { + student.rank = index + 1; // 设置排名,索引加 1 + }); + + // 获取前 10 位中的后 7 位(即4到10) + const rankings = students.slice(3, 10); // 从索引 3 开始取到索引 10(不包括10) + + this.setData({ + students: students, // 设置前 10 位学生 + rankings: rankings // 设置后 7 位学生 + }); + + // console.log("前 10 位学生:", this.data.students); // 调试时打印前 10 位学生数据 + // console.log("后 7 位学生:", this.data.rankings); // 调试时打印后 7 位学生数据 + } + +}); diff --git a/Roll_Students/pages/studentRanking/studentRanking.json b/Roll_Students/pages/studentRanking/studentRanking.json new file mode 100644 index 0000000..595d3fd --- /dev/null +++ b/Roll_Students/pages/studentRanking/studentRanking.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "排行榜", + "navigationBarBackgroundColor": "#F5F8F9", + "backgroundColor": "#eeeeee", + "navigationBarTextStyle": "black", + "usingComponents": {} +} \ No newline at end of file diff --git a/Roll_Students/pages/studentRanking/studentRanking.wxml b/Roll_Students/pages/studentRanking/studentRanking.wxml new file mode 100644 index 0000000..42caa15 --- /dev/null +++ b/Roll_Students/pages/studentRanking/studentRanking.wxml @@ -0,0 +1,42 @@ + + + + 周榜 + 月榜 + 年榜 + + + + + + + + {{students[1].name}} + {{students[1].score}} + + + + + {{students[0].name}} + {{students[0].score}} + + + + + {{students[2].name}} + {{students[2].score}} + + + + + + + + + {{item.rank}} + + {{item.name}} + {{item.score}} + + + \ No newline at end of file diff --git a/Roll_Students/pages/studentRanking/studentRanking.wxss b/Roll_Students/pages/studentRanking/studentRanking.wxss new file mode 100644 index 0000000..a575f50 --- /dev/null +++ b/Roll_Students/pages/studentRanking/studentRanking.wxss @@ -0,0 +1,185 @@ +.container { + background-color: #1352c3; /* 背景颜色 */ + padding: 20rpx; /* 内边距 */ + color: white; /* 字体颜色 */ +} + +.header { + display: flex; /* 横向布局 */ + flex-direction: column; /* 垂直排列 */ + align-items: center; /* 向中居中 */ + margin-top: 20rpx; +} + +.tabs { + display: flex; /* 横向排列 */ + margin-bottom: 20rpx; /* 下边距 */ + border: 2rpx solid white; + border-radius: 20rpx; + font-weight: bold; +} + +.tab { + padding: 10rpx 20rpx; /* 内边距 */ + cursor: pointer; /* 鼠标悬停时显示为指针 */ + border-left: 2rpx solid white; + text-align: center; + width:150rpx; +} + +.tab.active { + background-color: #1684fc; /* 激活状态的背景颜色 */ + border-radius: 20rpx 0rpx 0rpx 20rpx; /* 圆角 */ + text-align: center; + width:150rpx; +} + +.ranking-container { + display: flex; /* 横向排列 */ + flex-direction:row; + justify-content: center; /* 居中对齐 */ + margin-top: 20rpx; /* 上边距 */ + height: 300rpx; + width: 600rpx; + align-items: flex-end; +} + +.rank-item { + background-color: white; /* 排名框背景颜色 */ + border-radius: 10rpx; /* 圆角 */ + padding: 10rpx; /* 内边距 */ + margin: 0 10rpx; /* 水平间距 */ + display: flex; /* 横向布局 */ + flex-direction: column; /* 垂直排列 */ + align-items: center; /* 水平居中 */ + width: 200rpx; /* 固定宽度 */ + height: 600rpx; /* 固定高度 */ +} + +.rank-item-first{ + display: flex; /* 横向排列 */ + flex-direction: column; /* 垂直排列 */ + align-items: center; /* 水平居中 */ + width: 200rpx; /* 固定宽度 */ + height: 300rpx; /* 固定高度 */ + background-color: #fff; + border-radius: 40rpx 40rpx 0rpx 0rpx; + box-shadow: 4rpx 4rpx 8rpx #797979; + margin-bottom: 10rpx; +} + +.rank-item-second{ + display: flex; /* 横向排列 */ + flex-direction: column; /* 垂直排列 */ + align-items: center; /* 水平居中 */ + width: 200rpx; /* 固定宽度 */ + height: 250rpx; /* 固定高度 */ + background-color: #fff; + border-radius: 40rpx 0rpx 0rpx 40rpx; + box-shadow: 4rpx 4rpx 8rpx #797979; + margin-bottom: 10rpx; +} + +.rank-item-third{ + display: flex; /* 横向排列 */ + flex-direction: column; /* 垂直排列 */ + align-items: center; /* 水平居中 */ + width: 200rpx; /* 固定宽度 */ + height: 225rpx; /* 固定高度 */ + background-color: #fff; + border-radius: 0rpx 40rpx 40rpx 0rpx; + box-shadow: 4rpx 4rpx 8rpx #797979; + margin-bottom: 10rpx; +} + +.crown-icon1 { + width: 80rpx; /* 冠军图标大小 */ + height: 80rpx; /* 冠军图标大小 */ + margin-bottom: 15rpx; /* 下边距 */ +} + +.crown-icon2 { + width: 70rpx; /* 冠军图标大小 */ + height: 70rpx; /* 冠军图标大小 */ + margin-bottom: 5rpx; /* 下边距 */ +} + +.crown-icon3 { + width: 65rpx; /* 冠军图标大小 */ + height: 65rpx; /* 冠军图标大小 */ +} + +.head-icon1{ + width: 100rpx; + height: 100rpx; + margin-bottom: 10rpx; /* 下边距 */ +} + +.head-icon2{ + width: 85rpx; + height: 85rpx; + margin-bottom: 5rpx; /* 下边距 */ +} + +.head-icon3{ + width: 80rpx; + height: 80rpx; + margin-bottom: 5rpx; /* 下边距 */ +} + +.name { + font-size: 28rpx; /* 名字字体大小 */ + font-weight: bold; + color: #999999; +} + +.score { + color: #f63e3d; /* 成绩颜色 */ + font-size: 26rpx; /* 成绩字体大小 */ + font-weight: bold; +} + +.container2 { + width: 750rpx; +} + +.ranking-list { + background-color: white; /* 列表背景 */ + border-radius: 10rpx; /* 圆角效果 */ + display:flex; + flex-direction:column; + align-items: center; /* 垂直居中 */ +} + +.rank-item { + display: flex; /* 横向布局 */ + flex-direction: row; + align-items: center; /* 垂直居中 */ + justify-content: space-between; /* 在行内两端对齐 */ + border-radius: 0; + border-bottom: 1rpx solid #1352c3; /* 下边框 */ + width:80%; + height: 100rpx; + font-size: 36rpx; /* 字体大小 */ +} + +.rank { + color: #999999; /* 排名颜色 */ +} + +.icon { + margin: 40rpx; + width: 80rpx; /* 图标大小 */ + height: 80rpx; /* 图标大小 */ +} + +.name { + flex: 1; /* 名字占用剩余空间 */ + text-align: left; /* 向左对齐 */ +} + +.score { + flex: 0 0 0rpx; /* 固定宽度显示分数 */ + font-size: 36rpx; + color: #f63e3d; /* 分数颜色 */ +} diff --git a/Roll_Students/project.config.json b/Roll_Students/project.config.json new file mode 100644 index 0000000..4274374 --- /dev/null +++ b/Roll_Students/project.config.json @@ -0,0 +1,28 @@ +{ + "compileType": "miniprogram", + "libVersion": "trial", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "coverView": true, + "es6": true, + "postcss": true, + "minified": true, + "enhance": true, + "showShadowRootInWxmlPanel": true, + "packNpmRelationList": [], + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + } + }, + "condition": {}, + "editorSetting": { + "tabIndent": "auto", + "tabSize": 2 + }, + "appid": "wx25ff0c2b98fa2d60" +} \ No newline at end of file diff --git a/Roll_Students/project.private.config.json b/Roll_Students/project.private.config.json new file mode 100644 index 0000000..e528a75 --- /dev/null +++ b/Roll_Students/project.private.config.json @@ -0,0 +1,8 @@ +{ + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "Roll_Students", + "setting": { + "compileHotReLoad": true + }, + "libVersion": "3.5.8" +} \ No newline at end of file diff --git a/Roll_Students/sitemap.json b/Roll_Students/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/Roll_Students/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/Roll_Students/utils/util.js b/Roll_Students/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/Roll_Students/utils/util.js @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} + +module.exports = { + formatTime +} diff --git a/myproject/__pycache__/manage.cpython-310.pyc b/myproject/__pycache__/manage.cpython-310.pyc new file mode 100644 index 0000000..af1afd4 Binary files /dev/null and b/myproject/__pycache__/manage.cpython-310.pyc differ diff --git a/myproject/app01/__init__.py b/myproject/app01/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/app01/__pycache__/__init__.cpython-310.pyc b/myproject/app01/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..989ab11 Binary files /dev/null and b/myproject/app01/__pycache__/__init__.cpython-310.pyc differ diff --git a/myproject/app01/__pycache__/admin.cpython-310.pyc b/myproject/app01/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..ba393dc Binary files /dev/null and b/myproject/app01/__pycache__/admin.cpython-310.pyc differ diff --git a/myproject/app01/__pycache__/apps.cpython-310.pyc b/myproject/app01/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..9891df8 Binary files /dev/null and b/myproject/app01/__pycache__/apps.cpython-310.pyc differ diff --git a/myproject/app01/__pycache__/models.cpython-310.pyc b/myproject/app01/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..aa5dbd9 Binary files /dev/null and b/myproject/app01/__pycache__/models.cpython-310.pyc differ diff --git a/myproject/app01/__pycache__/views.cpython-310.pyc b/myproject/app01/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..3c415b4 Binary files /dev/null and b/myproject/app01/__pycache__/views.cpython-310.pyc differ diff --git a/myproject/app01/admin.py b/myproject/app01/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/myproject/app01/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/myproject/app01/apps.py b/myproject/app01/apps.py new file mode 100644 index 0000000..5d75966 --- /dev/null +++ b/myproject/app01/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class App01Config(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "app01" diff --git a/myproject/app01/excelfile/5班.xlsx b/myproject/app01/excelfile/5班.xlsx new file mode 100644 index 0000000..c34b240 Binary files /dev/null and b/myproject/app01/excelfile/5班.xlsx differ diff --git a/myproject/app01/excelfile/7班.xlsx b/myproject/app01/excelfile/7班.xlsx new file mode 100644 index 0000000..c34b240 Binary files /dev/null and b/myproject/app01/excelfile/7班.xlsx differ diff --git a/myproject/app01/excelfile/test_file.csv b/myproject/app01/excelfile/test_file.csv new file mode 100644 index 0000000..2491363 --- /dev/null +++ b/myproject/app01/excelfile/test_file.csv @@ -0,0 +1 @@ +some,data \ No newline at end of file diff --git a/myproject/app01/excelfile/嵌入式系统.xlsx b/myproject/app01/excelfile/嵌入式系统.xlsx new file mode 100644 index 0000000..c34b240 Binary files /dev/null and b/myproject/app01/excelfile/嵌入式系统.xlsx differ diff --git a/myproject/app01/excelfile/软工学生名单.xlsx b/myproject/app01/excelfile/软工学生名单.xlsx new file mode 100644 index 0000000..5899b13 Binary files /dev/null and b/myproject/app01/excelfile/软工学生名单.xlsx differ diff --git a/myproject/app01/migrations/0001_initial.py b/myproject/app01/migrations/0001_initial.py new file mode 100644 index 0000000..d40c82d --- /dev/null +++ b/myproject/app01/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2 on 2024-10-05 17:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Student", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=32)), + ("sid", models.CharField(max_length=20)), + ("credit", models.FloatField()), + ("class_name", models.CharField(max_length=32)), + ("probability", models.FloatField()), + ("max", models.FloatField()), + ("min", models.FloatField()), + ], + ), + ] diff --git a/myproject/app01/migrations/__init__.py b/myproject/app01/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/app01/migrations/__pycache__/0001_initial.cpython-310.pyc b/myproject/app01/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..46fd563 Binary files /dev/null and b/myproject/app01/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/myproject/app01/migrations/__pycache__/__init__.cpython-310.pyc b/myproject/app01/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..a6de7d4 Binary files /dev/null and b/myproject/app01/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/myproject/app01/models.py b/myproject/app01/models.py new file mode 100644 index 0000000..c0356e1 --- /dev/null +++ b/myproject/app01/models.py @@ -0,0 +1,181 @@ +from django.db import models + +# Create your models here. + +from django.db import models +from django.db.models import Model, Max, Min +import random +from django.db.models import F + +class Student(models.Model): + name = models.CharField(max_length=32) + sid = models.CharField(max_length=20) + credit = models.FloatField() + class_name = models.CharField(max_length=32) + probability = models.FloatField() + max = models.FloatField() + min = models.FloatField() + + + def prob(self,class_name,credit): #由积分求概率 + stu = Student.objects.filter(class_name=class_name) + credits = [student.credit for student in stu] + max_credit = max(credits) + min_credit = max(credits) + if max_credit == min_credit: + return 1 + else: + return (credit - min_credit)/(max_credit - min_credit) + + def callstu(self,class_name,num,mode): #点名的函数,输入要点的人数,返回这些人的学号姓名,不重复,(基础模式) + sts = Student.objects.filter(class_name=class_name) + probabilities = [] + if mode == 1 or mode == 2: #基础模式和得分加倍的筛选概率不变 + probabilities = [student.probability for student in sts] + elif mode == 3 : #三五成群 + for s1 in sts: + if (int(s1.credit) % 3 == 0 or int(s1.credit) % 5 == 0) and s1.credit != 0: + probabilities.append(2*s1.probability) + else: + probabilities.append(s1.probability) + else: #六六大顺 + for s1 in sts: + if int(s1.credit) % 6 == 0 and s1.credit != 0: + probabilities.append(2*s1.probability) + else: + probabilities.append(s1.probability) + if probabilities: + max_probability = max(probabilities) + min_probability = min(probabilities) + else: + max_probability = -1 + min_probability = -1 + if num > sts.count(): + data = {'message':0} + return data + else: + result = {} + if mode == 1 or mode == 2: + time = 0 #筛选出一个学生需要生成的随机数的次数 (刚开始比较稀疏,要避免一直不能完成抽取条件的情况)设置上限为10 + while len(result) < num: #基础模式和得分加倍模式 + if time == 10: #当为了筛选一个人而生成了10次随机数后,由于太浪费时间,直接筛选剩下的人 + flag = 0 + while flag == 0: + s = sts.order_by('?').first() + if s.sid not in result: + result[s.name] = s.sid + time = 0 + flag += 1 + else: + random_probability = random.uniform(min_probability, max_probability) + time += 1 + s = sts.filter(probability__gte = random_probability).order_by('?').first() + if s.sid not in result: + result[s.name] = s.sid + time = 0 #当筛选出一个的时候,为下一次的筛选置为0 + elif mode == 3: #三五成群 + time = 0 # 筛选出一个学生需要生成的随机数的次数 (刚开始比较稀疏,要避免一直不能完成抽取条件的情况)设置上限为10 + while len(result) < num: #一个随机数就选出一个学生 + if time == 10: + flag = 0 + while flag == 0: + s = sts.order_by('?').first() + if s.sid not in result: + result[s.name] = s.sid + time = 0 + flag += 1 + else: + random_probability = random.uniform(min_probability, max_probability) + # print(random_probability) + ss1 = [student for student in sts if ( int(student.credit) % 5 == 0 + or int(student.credit) % 3 == 0 )and student.probability > random_probability/2] + ss2 =[student for student in sts if student.credit > random_probability] + ss = list(set(ss1+ss2)) + random_student = random.choice(ss) + if random_student.id not in result: + result[random_student.name] = random_student.sid + time = 0 + print(result) + elif mode == 4: #六六大顺 + time = 0 # 筛选出一个学生需要生成的随机数的次数 (刚开始比较稀疏,要避免一直不能完成抽取条件的情况)设置上限为10 + while len(result) < num: #一个随机数就选出一个学生 + if time == 10: + flag = 0 + while flag == 0: + s = sts.order_by('?').first() + if s.sid not in result: + result[s.name] = s.sid + time = 0 + flag += 1 + else: + random_probability = random.uniform(min_probability, max_probability) + ss1 = [student for student in sts if int(student.credit) % 6 == 0 and student.probability > random_probability/2] + ss2 = [student for student in sts if student.credit > random_probability] + ss = list(set(ss1+ss2)) + random_student = random.choice(ss) + if random_student.id not in result: + result[random_student.name] = random_student.sid + time = 0 + data = {'message':1, + 'result':result} + return data + + def updateinfor (self,point,class_name,sid,style): #更新积分和概率 + if style == 1 : + point = point + if style == 2 : + point = point * 2 + #先改变该学生的积分值 + current_s = Student.objects.filter(class_name=class_name, sid=sid).first() + current_credit = current_s.credit + current_s.credit = current_credit + point + current_s.save() + #查找最新的最大或最小值,与原来写在表中的上次更新的最大值和最小值做对比 + max_credit = Student.objects.filter(class_name=class_name).aggregate(max_credit=Max('credit'))['max_credit'] + min_credit = Student.objects.filter(class_name=class_name).aggregate(min_credit=Min('credit'))['min_credit'] + s = Student.objects.filter(class_name=class_name).first() #找未更新的值 + max_credit0 = s.max + min_credit0 = s.min + fm = max_credit - min_credit #最新的分母 + #如果不影响2个最值,仅改变单个学生的概率 + if max_credit == max_credit0 and min_credit == min_credit0: + if fm == 0: + prob = 1.0 + else: + prob = 1 - (current_s.credit - min_credit)/fm + current_s.probability = prob # 直接设置字段的值 + current_s.save() # 调用 save 方法保存更改 + + #影响积分最大值和最小值其中的一个时,所有学生的概率都需要改变,先将最新的最大值和最小值写入数据库 + else: + #将最新的最大值和最小值写入数据库 + sts = Student.objects.filter(class_name=class_name) + sts.update(min = min_credit, max = max_credit) + #更新所有学生的概率 + if fm == 0 : + sts.update(probability = 1.0) + else: + sts.update(probability = (1 - (F('credit') - min_credit)/fm)) + +#耗时最大,性能改进前的代码 + def updateinfor (self,point,class_name,sid,style): #更新积分和概率 + if style == 1 : + point = point + if style == 2 : + point = point * 2 + #先改变该学生的积分值 + current_s = Student.objects.filter(class_name=class_name, sid=sid).first() + current_credit = current_s.credit + current_s.credit = current_credit + point + current_s.save() + #查找最新的最大或最小值,与原来写在表中的上次更新的最大值和最小值做对比 + max_credit = Student.objects.filter(class_name=class_name).aggregate(max_credit=Max('credit'))['max_credit'] + min_credit = Student.objects.filter(class_name=class_name).aggregate(min_credit=Min('credit'))['min_credit'] + fm = max_credit - min_credit #最新的分母 + sts = Student.objects.filter(class_name=class_name) + sts.update(min=min_credit, max=max_credit) + # 更新所有学生的概率 + if fm == 0: + sts.update(probability=1.0) + else: + sts.update(probability=(1 - (F('credit') - min_credit) / fm)) \ No newline at end of file diff --git a/myproject/app01/tests.py b/myproject/app01/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/myproject/app01/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/myproject/app01/views.py b/myproject/app01/views.py new file mode 100644 index 0000000..72546fe --- /dev/null +++ b/myproject/app01/views.py @@ -0,0 +1,152 @@ +import os +from openpyxl import load_workbook +# Create your views here. +import random +from django.http import JsonResponse + +from .models import Student + +def save_file(file, save_directory): + file_path = os.path.join(save_directory, file.name) + with open(file_path, 'wb+') as destination: + for chunk in file.chunks(): + destination.write(chunk) + return file_path + +def getinformation(request): + if request.method == 'POST': + try: + class_name = request.POST.get('class_name') + file = request.FILES.get('file') + if file and class_name: + if Student.objects.filter(class_name=class_name).first(): # 如果表中已经有该班级 + response_data = {'message': 0, 'error': '该班级已创建'} + return JsonResponse(response_data,json_dumps_params={'ensure_ascii': False}) + else: + current_dir = os.path.dirname(os.path.abspath(__file__)) + save_directory = os.path.join(current_dir, 'excelfile') + if not os.path.exists(save_directory): + os.makedirs(save_directory) + file_path = save_file(file, save_directory) + wb = load_workbook(file_path) + ws = wb.active + for row in ws.iter_rows(min_row=2, values_only=True): + sid, name = row[0], row[1] + Student.objects.create(sid=sid, name=name, class_name=class_name, credit=0.0, + probability=1.0,max = 0 , min = 0) + response_data = {'message': 1 , 'total': ws.max_row-1} + return JsonResponse(response_data,json_dumps_params={'ensure_ascii': False}) + else: + response_data = { + 'message': 0, + 'error': '缺少必要的参数' + } + return JsonResponse(response_data,json_dumps_params={'ensure_ascii': False}) + except Exception as e: + response_data = { + 'message': 0, + 'error': str(e) + } + return JsonResponse(response_data) + else: + response_data = { + 'message': 0, + 'error': '请求方法错误' + } + return JsonResponse(response_data,json_dumps_params={'ensure_ascii': False}) + + +def call_students(request): #前端点击点名按钮向后端发送请求 + if request.method == 'POST': + try: + class_name = request.POST.get('class_name') #班级名称 + num0 = request.POST.get('num') #本次点名的人数 + mode0 = request.POST.get('mode') + result = {} + if class_name and num0 and mode0: + num = int(num0) + mode = int(mode0) + s = Student() # 创建一个实例 + result = s.callstu(class_name, num, mode) + response_data = result #成功返回 + else: + response_data = { + 'message': 0, + 'error': '缺少必要的参数' + } + except Exception as e: + response_data = { + 'message': 0, + 'error': str(e) + } + else: + response_data = { + 'message': 0, + 'error': '请求方法错误' + } + return JsonResponse(response_data) + +def updatetable(request): + if request.method == 'POST': + try: + point = float(request.POST.get('point')) + class_name = request.POST.get('class_name') #班级名称 + sid = request.POST.get('sid') #本次点名的学生学号 + style = int(request.POST.get('style')) + if point and class_name and sid and style: + s = Student() # 创建一个实例 + s.updateinfor(point, class_name,sid, style) + response_data = {'message': 1} + else: + response_data = {'message': 0,'error': '缺少必要的参数'} + except Exception as e: + response_data = {'message': 0,'error': str(e)} + else: + response_data = {'message': 0,'error': '请求方法错误'} + return JsonResponse(response_data) + +import random +from django.http import JsonResponse + +def choosestyle(request): + if request.method == 'POST': + random_number = random.choice([1, 2, 3, 4, 5, 6]) + return JsonResponse({'number': random_number}) # 将数字包装在字典中 + else: + response_data = {'error': '请求方法错误'} + return JsonResponse(response_data) + +from django.db.models import Window, F +from django.db.models.functions import Rank + + +def show_information (request): + if request.method == 'POST': + try: + class_name = request.POST.get('class_name') # 班级名称 + sid = request.POST.get('sid') # 本次想查询的学生学号 + order = request.POST.get('order') #前端返回的序号 + response_data = {'message': 0} + if class_name and sid: + class_students = Student.objects.filter(class_name=class_name).annotate( + rank=Window( + expression=Rank(), + order_by=F('credit').desc() + ) + ).order_by('credit') + # 查找特定学生的排名 + student_rank = None + name = None + for student in class_students: + if student.sid == sid: + student_rank = student.rank + name = student.name + break + response_data = {'order':order,'class_name': class_name,'name':name,'sid':sid,'student_rank':student_rank} + else: + response_data = {'message':0,'error':'缺少必要的参数'} + except Exception as e: + response_data = {'message': 0, 'error': str(e)} + else: + response_data = {'message': 0, 'error': '请求方法错误'} + return JsonResponse(response_data) \ No newline at end of file diff --git a/myproject/manage.py b/myproject/manage.py new file mode 100644 index 0000000..893db8e --- /dev/null +++ b/myproject/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/myproject/myproject/__init__.py b/myproject/myproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/myproject/__pycache__/__init__.cpython-310.pyc b/myproject/myproject/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..a68df38 Binary files /dev/null and b/myproject/myproject/__pycache__/__init__.cpython-310.pyc differ diff --git a/myproject/myproject/__pycache__/settings.cpython-310.pyc b/myproject/myproject/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..45b0f61 Binary files /dev/null and b/myproject/myproject/__pycache__/settings.cpython-310.pyc differ diff --git a/myproject/myproject/__pycache__/urls.cpython-310.pyc b/myproject/myproject/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..7afd8dc Binary files /dev/null and b/myproject/myproject/__pycache__/urls.cpython-310.pyc differ diff --git a/myproject/myproject/__pycache__/wsgi.cpython-310.pyc b/myproject/myproject/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..2cc0426 Binary files /dev/null and b/myproject/myproject/__pycache__/wsgi.cpython-310.pyc differ diff --git a/myproject/myproject/asgi.py b/myproject/myproject/asgi.py new file mode 100644 index 0000000..bf9a1a7 --- /dev/null +++ b/myproject/myproject/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for myproject project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + +application = get_asgi_application() diff --git a/myproject/myproject/settings.py b/myproject/myproject/settings.py new file mode 100644 index 0000000..e6fa989 --- /dev/null +++ b/myproject/myproject/settings.py @@ -0,0 +1,135 @@ +""" +Django settings for myproject project. + +Generated by 'django-admin startproject' using Django 4.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-klu4il1-gzuan***r%r5$yygd$jwpgpol#3@_r#qb$^m3j1^kn" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "app01.apps.App01Config" +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + # "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "myproject.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "myproject.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": 'mywork', ##数据库名字 + "USER": 'root', #账户名,默认 + "PASSWORD": 'mysql123456', + "HOST": '127.0.0.1', #本机 + "PORT": '3306', + } +} +# DATABASES = { +# "default": { +# "ENGINE": "django.db.backends.sqlite3", +# "NAME": BASE_DIR / "db.sqlite3", +# } +# } + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/myproject/myproject/urls.py b/myproject/myproject/urls.py new file mode 100644 index 0000000..7e06b31 --- /dev/null +++ b/myproject/myproject/urls.py @@ -0,0 +1,41 @@ +""" +URL configuration for myproject project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from app01 import views +urlpatterns = [ + path("admin/", admin.site.urls), + + path("get/information/", views.getinformation,name='get_information'), + #post请求,班级名称 'class_name' ,文件 'file' + #后端会返回一个json文件,当'message' = 1时,是成功建立 + #重复导入名字相同的文件会返回'message' = 0,该班级已经创建 + + path("call/students/", views.call_students,name='call_students'), #点名/提问函数 + #post请求, + # 班级名称'class_name', 点名人数'num',模式'mode'(1-基础模式,2-得分加倍,3-三五成群,4-六六大顺) + #后端会返回学生的姓名,学号 + + path("update/table/",views.updatetable), #对数据库中的学生积分和概率的更新函数 + #post请求 + #班级名称'class_name',本次得分‘point’,该学生的学号'sid',加分模式'style'(1-正常加分,2-加分或扣分*2) + + path("choose/style/",views.choosestyle,name = 'choose_style'), #骰子 + #post请求 后端直接返回一个1-6之间的随机数 + + path("show/information/",views.show_information,name='show_information'), +] diff --git a/myproject/myproject/wsgi.py b/myproject/myproject/wsgi.py new file mode 100644 index 0000000..39aedb4 --- /dev/null +++ b/myproject/myproject/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for myproject project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + +application = get_wsgi_application() diff --git a/myproject/test/__init__.py b/myproject/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/test/__pycache__/__init__.cpython-310.pyc b/myproject/test/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..a11e147 Binary files /dev/null and b/myproject/test/__pycache__/__init__.cpython-310.pyc differ diff --git a/myproject/test/__pycache__/test_all.cpython-310.pyc b/myproject/test/__pycache__/test_all.cpython-310.pyc new file mode 100644 index 0000000..da90232 Binary files /dev/null and b/myproject/test/__pycache__/test_all.cpython-310.pyc differ diff --git a/myproject/test/__pycache__/test_call_students.cpython-310.pyc b/myproject/test/__pycache__/test_call_students.cpython-310.pyc new file mode 100644 index 0000000..185f8e4 Binary files /dev/null and b/myproject/test/__pycache__/test_call_students.cpython-310.pyc differ diff --git a/myproject/test/__pycache__/test_choosestyle.cpython-310.pyc b/myproject/test/__pycache__/test_choosestyle.cpython-310.pyc new file mode 100644 index 0000000..4f91eed Binary files /dev/null and b/myproject/test/__pycache__/test_choosestyle.cpython-310.pyc differ diff --git a/myproject/test/__pycache__/test_getinformation.cpython-310.pyc b/myproject/test/__pycache__/test_getinformation.cpython-310.pyc new file mode 100644 index 0000000..ccddf00 Binary files /dev/null and b/myproject/test/__pycache__/test_getinformation.cpython-310.pyc differ diff --git a/myproject/test/__pycache__/test_show_information.cpython-310.pyc b/myproject/test/__pycache__/test_show_information.cpython-310.pyc new file mode 100644 index 0000000..82c9aac Binary files /dev/null and b/myproject/test/__pycache__/test_show_information.cpython-310.pyc differ diff --git a/myproject/test/test_all.py b/myproject/test/test_all.py new file mode 100644 index 0000000..521f2d1 --- /dev/null +++ b/myproject/test/test_all.py @@ -0,0 +1,173 @@ +import requests +import time +import json +import random +import cProfile + + +#一、创建班级,导入2个班级 +url = 'http://127.0.0.1:8000/get/information/' +class_name1 = '嵌入式系统' +file_path1 = 'C:/Users/Lenovo/Desktop/嵌入式系统.xlsx' + +with open(file_path1, 'rb') as f: + file1 = {'file': f} + data1 = {'class_name': class_name1} + response1 = requests.post(url, files=file1, data=data1) + print(response1.text) + +time.sleep(6) + +class_name2 = '软件工程' +file_path2 = 'C:/Users/Lenovo/Desktop/软工学生名单.xlsx' + +with open(file_path2, 'rb') as f: + file2 = {'file': f} + data2 = {'class_name': class_name2} + response2 = requests.post(url, files=file2, data=data2) + print(response2.text) + +time.sleep(6) + +#二、选择软件工程班级进行课前点名,此处点3个人 +url_call = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确 +data_call = { + 'class_name': '软件工程', + 'num': 3, + 'mode': 0 #点名使用正常模式 +} +response_call = requests.post(url_call, data=data_call) +print(response_call.text) + +time.sleep(3) + +res = response_call.json() +result = res.get('result', {}) +url_update = 'http://127.0.0.1:8000/update/table/' +#有到加1分,没到扣一分 +for name, student_id in result.items(): + print(student_id) + point = random.choice([1, -1]) + data_update = { + 'point': point, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + time.sleep(2) + +#三、上课提问,一个一个提问,问了之后直接加分,选择三五成群的模式,提问完直接加分,提问3次 +data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 3 +} +response_call1 = requests.post(url_call, data=data_call) +print(response_call1.text) +res = response_call1.json() +result = res.get('result', {}) +student_ids = list(result.values()) +student_id = student_ids[0] +data_update = { + 'point': 3, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } +response0 = requests.post(url_update, data=data_update) +print(response0.text) +time.sleep(5) + +data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 2 +} +response_call1 = requests.post(url_call, data=data_call) +print(response_call1.text) +res = response_call1.json() +result = res.get('result', {}) +student_ids = list(result.values()) +student_id = student_ids[0] +data_update = { + 'point': -5, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } +response0 = requests.post(url_update, data=data_update) +print(response0.text) +time.sleep(5) + +data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 2 #点名使用正常模式 +} +response_call1 = requests.post(url_call, data=data_call) +print(response_call1.text) +res = response_call1.json() +result = res.get('result', {}) +student_ids = list(result.values()) +student_id = student_ids[0] +data_update = { + 'point': 2, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } +response0 = requests.post(url_update, data=data_update) +print(response0.text) +time.sleep(5) + +#课堂主动回答问题,2人,自己加分 +data_update = { + 'point': 2, + 'class_name': '软件工程', + 'sid':102201216 , + 'style': 1 + } +response0 = requests.post(url_update, data=data_update) +print(response0.text) +time.sleep(5) +data_update = { + 'point': 6, + 'class_name': '软件工程', + 'sid':102201203 , + 'style': 1 + } +response0 = requests.post(url_update, data=data_update) +print(response0.text) +time.sleep(2) + +#查看排名 2人 +url_show = 'http://127.0.0.1:8000/show/information/' # 确保 URL 正确 + +data = { + 'order':1, + 'class_name': '软件工程', + 'sid':102201539 , +} +response = requests.post(url_show, data=data) +data1 = response.json() +print(response.text) +time.sleep(2) +data = { + 'order':1, + 'class_name': '软件工程', + 'sid':102201529 , +} +response = requests.post(url_show, data=data) +data1 = response.json() +print(response.text) + + + + + + + + + diff --git a/myproject/test/test_all_c.py b/myproject/test/test_all_c.py new file mode 100644 index 0000000..ff683ff --- /dev/null +++ b/myproject/test/test_all_c.py @@ -0,0 +1,168 @@ +import requests +import time +import json +import random +import cProfile + + +def test_all_c(): + # 一、创建班级,导入2个班级 + url = 'http://127.0.0.1:8000/get/information/' + class_name1 = '嵌入式系统' + file_path1 = 'C:/Users/Lenovo/Desktop/嵌入式系统.xlsx' + + with open(file_path1, 'rb') as f: + file1 = {'file': f} + data1 = {'class_name': class_name1} + response1 = requests.post(url, files=file1, data=data1) + print(response1.text) + + #time.sleep(6) + + class_name2 = '软件工程' + file_path2 = 'C:/Users/Lenovo/Desktop/软工学生名单.xlsx' + + with open(file_path2, 'rb') as f: + file2 = {'file': f} + data2 = {'class_name': class_name2} + response2 = requests.post(url, files=file2, data=data2) + print(response2.text) + + #time.sleep(6) + + # 二、选择软件工程班级进行课前点名,此处点3个人 + url_call = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确 + data_call = { + 'class_name': '软件工程', + 'num': 3, + 'mode': 0 # 点名使用正常模式 + } + response_call = requests.post(url_call, data=data_call) + print(response_call.text) + + #time.sleep(3) + + res = response_call.json() + result = res.get('result', {}) + url_update = 'http://127.0.0.1:8000/update/table/' + # 有到加1分,没到扣一分 + for name, student_id in result.items(): + print(student_id) + point = random.choice([1, -1]) + data_update = { + 'point': point, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + # time.sleep(2) + + # 三、上课提问,一个一个提问,问了之后直接加分,选择三五成群的模式,提问完直接加分,提问3次 + data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 3 + } + response_call1 = requests.post(url_call, data=data_call) + print(response_call1.text) + res = response_call1.json() + result = res.get('result', {}) + student_ids = list(result.values()) + student_id = student_ids[0] + data_update = { + 'point': 3, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + # time.sleep(5) + + data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 3 + } + response_call1 = requests.post(url_call, data=data_call) + print(response_call1.text) + res = response_call1.json() + result = res.get('result', {}) + student_ids = list(result.values()) + student_id = student_ids[0] + data_update = { + 'point': -5, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + #time.sleep(5) + + data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 3 + } + response_call1 = requests.post(url_call, data=data_call) + print(response_call1.text) + res = response_call1.json() + result = res.get('result', {}) + student_ids = list(result.values()) + student_id = student_ids[0] + data_update = { + 'point': 2, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + #time.sleep(5) + + # 课堂主动回答问题,2人,自己加分 + data_update = { + 'point': 2, + 'class_name': '软件工程', + 'sid': 102201216, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + #time.sleep(5) + data_update = { + 'point': 6, + 'class_name': '软件工程', + 'sid': 102201203, + 'style': 1 + } + response0 = requests.post(url_update, data=data_update) + print(response0.text) + #time.sleep(2) + + # 查看排名 2人 + url_show = 'http://127.0.0.1:8000/show/information/' # 确保 URL 正确 + + data = { + 'order': 1, + 'class_name': '软件工程', + 'sid': 102201539, + } + response = requests.post(url_show, data=data) + data1 = response.json() + print(response.text) + #time.sleep(2) + data = { + 'order': 1, + 'class_name': '软件工程', + 'sid': 102201529, + } + response = requests.post(url_show, data=data) + data1 = response.json() + print(response.text) + +if __name__ == '__main__': + cProfile.run('test_all_c()','test_all_c.txt') \ No newline at end of file diff --git a/myproject/test/test_call_students.py b/myproject/test/test_call_students.py new file mode 100644 index 0000000..1af2a6c --- /dev/null +++ b/myproject/test/test_call_students.py @@ -0,0 +1,79 @@ +# import requests +# url = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确 +# +# data = { +# 'class_name': '7班', +# 'num': 2, +# 'mode': 0 +# } +# response = requests.post(url, data=data) +# print(response.text) + +from django.test import TestCase +from django.urls import reverse +from app01.models import Student +class CallStudentsTestCase(TestCase): + def setUp(self): + # 创建一些测试数据 + Student.objects.create(name='学生1', sid='001', credit=0.0, class_name='测试班级1', probability=1, max=0.0, min=0.0) + Student.objects.create(name='学生2', sid='002', credit=0.0, class_name='测试班级1', probability=1, max=0.0, min=0.0) + + def test_call_students_with_valid_post_request(self): + # 测试带有有效参数的POST请求 + url = reverse('call_students') + data = { + 'class_name': '测试班级1', + 'num': 2, + 'mode': 1 + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, 200) + + def test_call_students_with_get_request(self): + # 测试GET请求 + url = reverse('call_students') + response = self.client.get(url) + self.assertEqual(response.status_code, 200) # 或者是200,视图处理决定 + self.assertIn('error', response.json()) + + def test_call_students_without_class_name(self): + # 测试参数缺少班级名称的POST请求 + url = reverse('call_students') + data = { + 'num': 2, + 'mode': 1 + } + response = self.client.post(url, data) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '缺少必要的参数') + + def test_call_students_without_num(self): + # 测试参数缺少数量的POST请求 + url = reverse('call_students') + data = { + 'class_name': '测试班级1', + 'mode': 1 + } + response = self.client.post(url, data) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '缺少必要的参数') + + def test_call_students_without_mode(self): + # 测试参数缺少模式的POST请求 + url = reverse('call_students') + data = { + 'class_name': '测试班级1', + 'num': 2 + } + response = self.client.post(url, data) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '缺少必要的参数') + + + diff --git a/myproject/test/test_choosestyle.py b/myproject/test/test_choosestyle.py new file mode 100644 index 0000000..bb8d222 --- /dev/null +++ b/myproject/test/test_choosestyle.py @@ -0,0 +1,25 @@ +# import requests +# import json +# +# url = 'http://127.0.0.1:8000/choose/style/' # 确保 URL 正确 +# response = requests.post(url) +# print(response.text) + + + +from django.test import TestCase +from django.urls import reverse +from django.http import JsonResponse +import random + +class ChooseStyleTestCase(TestCase): + def test_choosestyle_with_post_request(self): + # 测试有效的POST请求 + url = reverse('choose_style') # 确保名称与 urls.py 中定义的一致 + response = self.client.post(url) + self.assertEqual(response.status_code, 200) + self.assertTrue('error' not in response.json()) + self.assertIn(response.json()['number'], [1, 2, 3, 4, 5, 6]) + + + diff --git a/myproject/test/test_getinformation.py b/myproject/test/test_getinformation.py new file mode 100644 index 0000000..e87fb0b --- /dev/null +++ b/myproject/test/test_getinformation.py @@ -0,0 +1,94 @@ +# import requests +# import json +# url = 'http://127.0.0.1:8000/get/information/' +# class_name = '5班' +# file_path = 'C:/Users/Lenovo/Desktop/5班.xlsx' +# +# with open(file_path, 'rb') as f: +# files = {'file': f} +# data = {'class_name': class_name} +# response = requests.post(url, files=files, data=data) +# print(response.text) + +from django.test import TestCase +from django.urls import reverse +from django.core.files.uploadedfile import SimpleUploadedFile +from app01.models import Student +class GetInformationTestCase(TestCase): + def setUp(self): + # 创建测试用的班级 + Student.objects.create( + name='测试学生1', + sid='001', + credit=3.5, + class_name='测试班级1', + probability=0.9, + max=0.0, + min=0.0 + ) + + def test_getinformation_with_wrong_file(self): + # 测试带有不同格式文件的POST请求 + url = reverse('get_information') + class_name = '测试班级2' + file_content = b'some,data' # CSV文件内容 + file = SimpleUploadedFile('test_file.csv', file_content, content_type='text/csv') + data = {'class_name': class_name, 'file': file} + response = self.client.post(url, data) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + + def test_getinformation_without_file(self): + url = reverse('get_information') + class_name = '测试班级' + response = self.client.post(url, {'class_name': class_name}) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertIn('缺少必要的参数', response.json()['error']) + + def test_getinformation_class_name(self): + # 测试没有班级名称的POST请求 + url = reverse('get_information') + file_content = b'some,data' # excel文件内容 + file = SimpleUploadedFile('test_file.xlsx', file_content, content_type='text/xlsx') + response = self.client.post(url, {'file': file}) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertIn('缺少必要的参数', response.json()['error']) + + def test_getinformation_with_empty_file(self): + # 测试上传空文件的POST请求 + url = reverse('get_information') + class_name = '测试班级' + file = SimpleUploadedFile('test_file.xlsx', b'', content_type='text/xlsx') + response = self.client.post(url, {'class_name': class_name}, FILES={'file': file}) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertIn('缺少必要的参数', response.json()['error']) + + def test_getinformation_not_post(self): + url = reverse('get_information') + response = self.client.get(url) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertIn('error', response.json()) + + def test_getinformation_with_put_request(self): + # 测试PUT请求 + url = reverse('get_information') + response = self.client.put(url) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) + self.assertIn('error', response.json()) + + def test_getinformation_with_delete_request(self): + # 测试DELETE请求 + url = reverse('get_information') + response = self.client.delete(url) + # 检查响应状态码和内容 + self.assertEqual(response.status_code, 200) # 或者是200,视图处理决定 + self.assertIn('error', response.json()) diff --git a/myproject/test/test_profile.py b/myproject/test/test_profile.py new file mode 100644 index 0000000..a20c468 --- /dev/null +++ b/myproject/test/test_profile.py @@ -0,0 +1,129 @@ +import requests +import time +import json +import random +import cProfile + +from test.test_all import response_call + + +def getinformation_t (url,class_name,file_path): + with open(file_path, 'rb') as f: + file = {'file': f} + data = {'class_name': class_name} + response = requests.post(url, files=file, data=data) + print(response.text) + +def call_students_t (url,data_call): + response_call = requests.post(url, data=data_call) + print(response_call.text) + return response_call + +def updatetable_t (url,data_update): + response_update = requests.post(url, data=data_update) + print(response_update.text) + +def show_information_t (url,data_show): + response_show = requests.post(url, data=data_show) + print(response_show.text) + +def main (): + #一、导入2个班级 + url = 'http://127.0.0.1:8000/get/information/' + class_name1 = '嵌入式系统' + file_path1 = 'C:/Users/Lenovo/Desktop/嵌入式系统.xlsx' + getinformation_t(url,class_name1,file_path1) + + class_name2 = '软件工程' + file_path2 = 'C:/Users/Lenovo/Desktop/软工学生名单.xlsx' + getinformation_t(url,class_name2,file_path2) + + #课前点名,举例3个 + url_call = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确 + data_call = { + 'class_name': '软件工程', + 'num': 3, + 'mode': 1 # 点名使用正常模式 + } + response_call = call_students_t(url_call,data_call) + res = response_call.json() + result = res.get('result', {}) + url_update = 'http://127.0.0.1:8000/update/table/' + # 有到加1分,没到扣一分 + for name, student_id in result.items(): + print(student_id) + point = random.choice([1, -1]) + data_update = { + 'point': point, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + updatetable_t(url_update,data_update) + # 三、上课提问,一个一个提问,问了之后直接加分,选择三五成群的模式,提问完直接加分,提问3次 + i = 0 + while i < 3: + data_call = { + 'class_name': '软件工程', + 'num': 1, + 'mode': 3 + } + response_call1 = call_students_t(url_call, data_call) + res = response_call1.json() + result = res.get('result', {}) + student_ids = list(result.values()) + if not student_ids: + continue + i += 1 + student_id = student_ids[0] + data_update = { + 'point': 6, + 'class_name': '软件工程', + 'sid': student_id, + 'style': 1 + } + updatetable_t(url_update, data_update) + + #四、课堂主动回答问题 + data_update = { + 'point': 6, + 'class_name': '软件工程', + 'sid': 102201203, + 'style': 1 + } + updatetable_t(url_update, data_update) + data_update = { + 'point': 2, + 'class_name': '软件工程', + 'sid': 102201216, + 'style': 1 + } + updatetable_t(url_update, data_update) + + #五、教师查看2(#`O′)学生的排名 + url_show = 'http://127.0.0.1:8000/show/information/' + data_show = { + 'order': 1, + 'class_name': '软件工程', + 'sid': 102201539, + } + show_information_t(url_show,data_show) + data = { + 'order': 1, + 'class_name': '软件工程', + 'sid': 102201529, + } + show_information_t(url_show,data) + +if __name__ == '__main__': + #cProfile.run('main()','test_total0.txt') + main() + + + + + + + + + diff --git a/myproject/test/test_show_information.py b/myproject/test/test_show_information.py new file mode 100644 index 0000000..2ea486e --- /dev/null +++ b/myproject/test/test_show_information.py @@ -0,0 +1,72 @@ +# import requests +# import json +# +# url = 'http://127.0.0.1:8000/show/information/' # 确保 URL 正确 +# +# data = { +# 'order':1, +# 'class_name': '软件工程', +# 'sid':102201539 , +# } +# +# response = requests.post(url, data=data) +# data1 = response.json() +# print(response.text) + +from django.test import TestCase +from django.urls import reverse +from app01.models import Student +from django.db.models import Window, F +from django.db.models.functions import Rank +class ShowInformationTestCase(TestCase): + def setUp(self): + # 创建一些测试数据 + Student.objects.create(name='学生1', sid='001', credit=0.0, class_name='测试班级1', probability=1, max=0.0, min=0.0) + Student.objects.create(name='学生2', sid='002', credit=0.0, class_name='测试班级1', probability=1, max=0.0, min=0.0) + + def test_show_information(self): + # 测试带有有效参数的POST请求 + url = reverse('show_information') + data = { + 'class_name': '测试班级1', + 'sid': '001', + 'order': '1' + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['sid'], '001') + self.assertEqual(response.json()['name'], '学生1') + self.assertEqual(response.json()['student_rank'], 1) + + def test_show_information_with_get_request(self): + # 测试GET请求 + url = reverse('show_information') + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '请求方法错误') + + def test_show_information_without_class_name(self): + # 测试缺少班级的请求 + url = reverse('show_information') + data = { + 'sid': '001', + 'order': '1' + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '缺少必要的参数') + + def test_show_information_without_sid(self): + # 测试缺少学号的请求 + url = reverse('show_information') + data = { + 'class_name':'测试班级1', + 'order': '1' + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['message'], 0) + self.assertEqual(response.json()['error'], '缺少必要的参数') + diff --git a/myproject/test/test_updatetable.py b/myproject/test/test_updatetable.py new file mode 100644 index 0000000..f7a04c3 --- /dev/null +++ b/myproject/test/test_updatetable.py @@ -0,0 +1,14 @@ +import requests +import json + +url = 'http://127.0.0.1:8000/update/table/' # 确保 URL 正确 + +data = { + 'point':1.5, + 'class_name': '软工学生名单', + 'sid':102201529 , + 'style':2 +} + +response = requests.post(url, data=data) +print(response.text) \ No newline at end of file