实训第三天

该博客主要介绍了建立小程序相关文件夹与文件的内容,包含 app.json 的页面、窗口、底部导航栏等配置,还展示了 index.js、index.wxml、index.wxss 等文件的代码,以及 map.js、map.wxml、mine.js、mine.wxml 等文件的代码修改与功能实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

建立相关文件夹与文件

app.json

{

"pages": [

"pages/index/index",

"pages/logs/logs",

"pages/aa/aa",

"pages/bb/bb",

"pages/mine/mine",

"pages/map/map"

],

"window": {

"backgroundTextStyle": "light",

"navigationBarBackgroundColor": "#ddd",

"navigationBarTitleText": "一剑天涯",

"navigationBarTextStyle": "white",

"enablePullDownRefresh": true,

"backgroundColor": "#000000"

},

"tabBar": {

"color": "#000000",

"selectedColor": "#6A5ACD",

"list": [

{

"pagePath": "pages/index/index",

"text": "首页",

"iconPath": "image/timg2.png",

"selectedIconPath": "image/timg.jpg"

},

{

"pagePath": "pages/map/map",

"text": "地图",

"iconPath": "image/aa.jpg",

"selectedIconPath": "image/aa2.jpg"

},

{

"pagePath": "pages/bb/bb",

"text": "购物车",

"iconPath": "image/buy1.png",

"selectedIconPath": "image/buy.jpg"

},

{

"pagePath": "pages/mine/mine",

"text": "我的",

"iconPath": "image/my1.jpg",

"selectedIconPath": "image/my2.png"

}

]

},

"sitemapLocation": "sitemap.json"

}

 

index.js

//index.js

//获取应用实例

const app = getApp()

 

Page({

data: {

ay:"你好",

name:"\名字:黑暗之魂3 全境封锁 古墓丽影\n 杀出重围:人类分裂 黑手党3",

flag:true,

imageurl:[{

url:"../../image/1.jpg"

}, {

url: "../../image/2.jpg"

}, {

url: "../../image/3.jpg"

}, {

url: "../../image/4.jpg"

}, {

url: "../../image/5.jpg"

},

],

obj:{

name:"华为mate20pro",

index:0,

price:5000,

},

index:"10"

},

ya:function(){

console.log(this.data.flag);

//更改属性

this.setData({

flag:!this.data.flag

})

},

onLoad: function () {

//获取手机信息

wx.getSystemInfo({

success: function (res) {

console.log(res)

},

})

}

})

 

index.wxml

<!--index.wxml-->

 

<swiper indicator-dots="true" indicator-color="#fff" indicator-active-color="#ff0000" autoplay="ture" circular="true" interval="5000" skip-hidden-item-layout="true">

<block wx:for="{{imageurl}}" wx:key="{{index}}">

<swiper-item>

<image src='{{item.url}}' style='width:100%;height:100%'></image>

</swiper-item>

</block>

</swiper>

<text id='{{id}}' wx:if="{{flag}}">{{ay}}</text>

<view class='name'><image src="../../image/name.jpg" style='width:87px;height:66px;' wx:if="{{!flag}}"></image></view>

<text wx:if="{{!flag}}">{{name}}</text>

<button bindtap='ya' style='width:30%'>点一点</button>

<view wx:for="{{imageurl}}" wx:key="{{i}}"

wx:for-index="i" wx:for-item="val">{{i}}{{val.url}}</view>

<template name="msgItem">

<view>

<text> {{index}}: {{msg}} </text>

<text> Time: {{time}} </text>

</view>

</template>

<text wx:if="{{index==10 ? true : false}}">序号 手机型号 价格</text>

<!--定义模板-->

<template name="model">

<view>

{{index}} {{name}}

<text>{{price}}</text>

</view>

</template>

<!--引用模板-->

<template is="model" data="{{...obj}}"></template>

<!--导入模板-->

<import src="../aa/aa.wxml"/>

<template is="aa" data="{{...obj}}"/>

 

index.wxss

/**index.wxss**/

.name{

display:flex;

justify-content: center;

 

}

在map.js中以下类加入

data: {

longitude:0,

latitude:0,

windowHeight: 0

},

onReady: function () {

console.log(this)

},

onShow: function () {

var _this = this;

wx.getLocation({

success: function(res) {

console.log(res)

_this.setData({

longitude: res.longitude,

latitude: res.latitude

})

}

})

wx.getSystemInfo({

success: function (res) {

console.log(res)

_this.setData({

windowHeight: res.windowHeight

})

},

})

},

 

map.wxml

<!--pages/map/map.wxml-->

<view >

<map longitude='{{longitude}}' latitude='{{latitude}}'

scale='14' style='width:100%;height:{{ windowHeight}}px'show-location="true"></map>

</view>

 

mine.js中改变

 

data: {

model:"",

system:"",

windowHeight:0 ,

windowWidth: 0

},

onLoad: function (options) {

console.log(this)

},

onReady: function () {

var _this = this;

wx.getSystemInfo({

success: function (res) {

console.log(res)

_this.setData({

model: res.model,

system: res.system,

windowHeight: res.windowHeight,

windowWidth: res.windowWidth

})

},

})

},

 

mine.wxml

<!--pages/mine/mine.wxml-->

<text>手机型号{{model}}\n</text>

<text>手机系统{{system}}\n</text>

<text>手机高度{{windowHeight}}px\n</text>

<text>手机宽度{{windowWidth}}px</text>

 

 

 

### 学生信息管理系统 Java 实训 第三天日志 示例 #### ### 1. 系统功能扩展与优化 在学生信息管理系统的开发中,第三天的主要任务是扩展系统的功能模块并进行性能优化。新增了多用户权限管理和批量导入学生信息的功能。通过设计`RoleService`类实现了对不同角色(如管理员、教师和学生)的权限控制[^1]。代码示例如下: ```java @Service public class RoleService { @Autowired private RoleMapper roleMapper; public List<String> getPermissionsByRole(String role) { return roleMapper.selectPermissions(role); } } ``` 此外,为了支持批量导入学生信息,引入了Apache POI库来处理Excel文件的读取和解析。以下为实现批量导入的核心代码: ```java public void importStudentsFromExcel(String filePath) throws IOException { FileInputStream file = new FileInputStream(new File(filePath)); Workbook workbook = new XSSFWorkbook(file); Sheet sheet = workbook.getSheetAt(0); for (Row row : sheet) { if (row.getRowNum() == 0) continue; // 跳过表头 Student student = new Student(); student.setName(row.getCell(0).getStringCellValue()); student.setGender(row.getCell(1).getStringCellValue()); student.setMajor(row.getCell(2).getStringCellValue()); studentMapper.insertStudent(student); } workbook.close(); file.close(); } ``` #### ### 2. 数据安全与验证机制 为了提高系统的安全性,实施了输入数据的校验机制,并使用Spring Security框架增强了用户认证和授权功能。通过配置`WebSecurityConfigurerAdapter`类,确保只有经过身份验证的用户才能访问敏感操作[^2]。示例代码如下: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") // 限制管理员页面访问 .antMatchers("/teacher/**").hasRole("TEACHER") // 限制教师页面访问 .anyRequest().authenticated() .and() .formLogin().permitAll() .and() .logout().permitAll(); } } ``` #### ### 3. 用户界面改进 在前端界面的设计上,采用Swing构建了更加友好的图形化用户界面(GUI)。通过增加搜索框和分页功能,提升了用户体验。以下是实现分页查询的代码片段: ```java public List<Student> getStudentsByPage(int page, int pageSize) { int offset = (page - 1) * pageSize; return studentMapper.selectStudentsByPage(offset, pageSize); } ``` 同时,还添加了导出功能,允许用户将查询结果导出为PDF或Excel格式。使用iText库生成PDF文件的示例如下: ```java public void exportToPdf(List<Student> students, String outputPath) throws DocumentException, IOException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(outputPath)); document.open(); PdfPTable table = new PdfPTable(3); // 创建表格 table.addCell("姓名"); table.addCell("性别"); table.addCell("专业"); for (Student student : students) { table.addCell(student.getName()); table.addCell(student.getGender()); table.addCell(student.getMajor()); } document.add(table); document.close(); } ``` #### ### 4. 性能优化与测试 针对系统性能进行了全面优化,包括数据库索引的创建和SQL语句的优化。通过JUnit编写了详细的单元测试用例,确保各模块的功能正确性。例如,对批量导入功能的测试代码如下: ```java @Test public void testImportStudentsFromExcel() throws IOException { String filePath = "students.xlsx"; studentService.importStudentsFromExcel(filePath); List<Student> importedStudents = studentMapper.selectAllStudents(); assertNotNull(importedStudents); assertTrue(importedStudents.size() > 0); } ``` #### ### 5. 总结与反思 通过实训第三天的工作,进一步完善了学生信息管理系统的功能模块,特别是在多用户权限管理和数据安全性方面取得了显著进展[^3]。未来的工作重点将放在系统的部署和上线准备上,同时继续优化用户体验。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值