diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..115cc02 --- /dev/null +++ b/.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/.gitignore b/.gitignore new file mode 100644 index 0000000..14ea590 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Windows +[Dd]esktop.ini +Thumbs.db +$RECYCLE.BIN/ + +# macOS +.DS_Store +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes + +# Node.js +node_modules/ diff --git a/app.js b/app.js new file mode 100644 index 0000000..1ed57c4 --- /dev/null +++ b/app.js @@ -0,0 +1,19 @@ +// 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: { + userInfo: null + } +}) diff --git a/app.json b/app.json new file mode 100644 index 0000000..e1d58d9 --- /dev/null +++ b/app.json @@ -0,0 +1,22 @@ +{ + "pages": [ + "pages/welcome/welcome", + "pages/call_roll/call_roll", + "pages/function/function", + "pages/class_manage/class_manage", + "pages/add_stu/add_stu", + "pages/class_message/class_message", + "pages/record/record", + "pages/index/index", + "pages/logs/logs" + ], + "window": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "Weixin", + "navigationBarBackgroundColor": "#ffffff" + }, + "style": "v2", + "componentFramework": "glass-easel", + "sitemapLocation": "sitemap.json", + "lazyCodeLoading": "requiredComponents" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..75f4fde --- /dev/null +++ b/app.wxss @@ -0,0 +1 @@ +/**app.wxss**/ diff --git a/pages/add_stu/add_stu.js b/pages/add_stu/add_stu.js new file mode 100644 index 0000000..5451af8 --- /dev/null +++ b/pages/add_stu/add_stu.js @@ -0,0 +1,157 @@ +// pages/addStudent/addStudent.js +Page({ + data: { + className:"K班", + input: "", + students:[ + + ] + }, + + onLoad: function(options) { + console.log(options); + // options 参数包含了从上一个页面传递过来的数据 + const receivedClassName = options.className; // 获取传递过来的 className,默认为空字符串 + + // 更新页面的数据 + this.setData({ + className: receivedClassName // 将接收到的 className 赋值给页面的 data 属性 + }); + console.log(this.data.className); + }, + + //获取输入框内容 + onInput: function(e) { + console.log(e.detail.value) + this.setData({ + input: e.detail.value//保存输入 + }); + }, + + // Excel文件导入 + importExcel: function() { + const that = this; + wx.chooseMessageFile({ + count: 1, // 默认为1,设置选择文件的数量 + type: 'file', + extension: ['xlsx'], // 指定文件的后缀名 + success(res) { + const tempFiles = res.tempFiles; // 临时文件路径 + const filePath = tempFiles[0].path; // 获取文件的路径 + console.log(tempFiles); + that.readExcel(filePath); // 读取文件内容 + }, + fail(err) { + console.error('选择文件失败:', err); + } + }); + }, + + // 读取Excel文件内容 + readExcel(filePath) { + // 可以使用微信小程序的API或将文件上传到服务器解析 + const that = this; + wx.uploadFile({ + url: '暂无', // 你的服务器上传地址 + filePath: filePath, + name: 'file', + success: uploadRes => { + // 假设服务器返回解析后的 JSON 数据 + const data = JSON.parse(uploadRes.data); + that.addStudents(data.students); + }, + fail: uploadErr => { + console.error('文件上传失败:', uploadErr); + } + }); + }, + + // 将解析后的学生数据添加到现有数组中 + addStudents(newStudents) { + const currentStudents = this.data.students; + const allStudents = currentStudents.concat(newStudents); // 合并数组 + this.setData({ + students: allStudents + }); + }, + + //点击输入框提示可以输入 + focus: function(){ + wx.showToast({ + title: '可以开始输入了', + icon: 'none', + duration: 2000 + }); + }, + + cantNull: function(){ + wx.showToast({ + title: '输入框不可为空', + icon: 'none', + duration: 2000 + }); + }, + + addProcess: function(){ + if(this.data.input != ""){ + //分割字符串为数组 + let firstArray = this.data.input.split("|"); + console.log(firstArray); + let secondArray = firstArray.map(str => str.split(" ")); + console.log(secondArray) + //遍历secondArray + secondArray.forEach(subArray => { + // 结构法从子数组中提取id和name + //等同于 const id = subArray[0]; const name = subArray[1]; + const { [0]: id, [1]: name } = subArray; + + // 创建一个新的对象来存储这些信息 + const newStu = { + id: id, + name: name, + point: 10, + clazz: this.data.className, + }; + const isDuplicate = this.data.students.some(stu => stu.id === id); + if(!isDuplicate){ + // 将新对象发送到后端服务器 + const classstu = newStu; + //classstu.className = this.data.className;//此时 classstu = {id:"102201",name:"Jhon", className:`${this.data.className}` } + wx.request({ + url: 'http://192.168.152.1:8090/student/set', + method: 'POST', // 请求方法,通常是POST用于发送数据 + header: { + 'Content-Type': 'application/json' // 设置请求头,指定数据格式为JSON + }, + data: newStu, // 要发送的数据,这里直接传入对象,wx.request会自动将其转换为JSON字符串(后端接收json字符串) + success: function(res) { + // 处理后端返回的响应 + console.log('请求成功', res.data); + // 根据需要更新小程序页面的数据或执行其他操作 + }, + fail: function(err) { + // 处理请求失败的情况 + console.error('请求失败', err); + // 可以向用户显示错误信息或执行其他错误处理操作 + } + }); + // 将新对象添加到data.stu数组中 + this.setData({ + ['students[' + this.data.students.length + ']']: newStu //直接将新对象加在数组后面 + }); + } else { + console.log('id重复:${id}'); + } + }) + console.log(this.data.students); + } else { + this.cantNull(); + } + }, + + goToclass_manage: function(){ + wx.navigateTo({ + url: '/pages/class_manage/class_manage' + }); + } +}); \ No newline at end of file diff --git a/pages/add_stu/add_stu.json b/pages/add_stu/add_stu.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/add_stu/add_stu.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/add_stu/add_stu.wxml b/pages/add_stu/add_stu.wxml new file mode 100644 index 0000000..8676f44 --- /dev/null +++ b/pages/add_stu/add_stu.wxml @@ -0,0 +1,12 @@ + + + + + 添加学生 + (添加学生学号 姓名用“|”隔开) +