当前位置: 首页> 娱乐> 八卦 > 网页界面设计的原则_unity3d培训班多少钱_阿里云免费域名_seo常见的优化技术

网页界面设计的原则_unity3d培训班多少钱_阿里云免费域名_seo常见的优化技术

时间:2025/8/4 12:02:50来源:https://blog.csdn.net/hashiqimiya/article/details/147655411 浏览次数:0次
网页界面设计的原则_unity3d培训班多少钱_阿里云免费域名_seo常见的优化技术

关系型数据库地址:C:\Users\ASUS\AppData\Local\Temp\HuaweiDevEcoStudioDatabases\rdb

#注册页面register.ets

import dataRdb from '@ohos.data.rdb'const STORE_CONFIG = {name: 'weather4.db'
}
const TABLE_NAME = 'weather_info'
const SQL_CREATE_TABLE = `CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT NOT NULL,password TEXT NOT NULL)
`
async function createTable(context) {try {const store = await dataRdb.getRdbStore(context, STORE_CONFIG, 1)await store.executeSql(SQL_CREATE_TABLE)console.info(`✅ 表 ${TABLE_NAME} 创建成功`)} catch (err) {console.error(`❌ 创建表失败: ${JSON.stringify(err)}`)console.error('错误详情:', err)}
}@Entry
@Component
struct WeatherInsertPage {@State username: string = ''@State password: string = ''async insertuser() {const context = getContext(this)createTable(context)const rdbStore = await dataRdb.getRdbStore(context, { name: 'weather4.db' }, 1)const valueBucket: dataRdb.ValuesBucket = {username: this.username,password: this.password,}try {let rowId = await rdbStore.insert('weather_info', valueBucket)console.info(`✅ 插入成功,行ID: ${rowId}`)} catch (err) {console.error(`❌ 插入失败: ${JSON.stringify(err)}`)}}build() {Column() {Text('用户注册').fontSize(26).fontWeight(FontWeight.Bold).margin({ bottom: 20 })TextInput({ placeholder: '请输入用户名', text: this.username }).onChange(value => this.username = value).margin(10)TextInput({ placeholder: '请输入密码', text: this.password }).onChange(value => this.password = value).type(InputType.Password).margin(10)Button('注册').margin(10).onClick(() => this.insertuser())}.padding(20)}
}

#登录页面项目login.ets

import dataRdb from '@ohos.data.rdb'const STORE_CONFIG = {name: 'weather4.db'
}
const TABLE_NAME = 'weather_info'// 建表语句
const SQL_CREATE_TABLE = `CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT NOT NULL,password TEXT NOT NULL)
`// 创建数据表
async function createTable(context) {const store = await dataRdb.getRdbStore(context, STORE_CONFIG, 1)await store.executeSql(SQL_CREATE_TABLE)
}// 查询用户是否存在
async function checkLogin(context, username: string, password: string): Promise<boolean> {const store = await dataRdb.getRdbStore(context, STORE_CONFIG, 1)const predicates = new dataRdb.RdbPredicates(TABLE_NAME).equalTo('username', username).equalTo('password', password)const resultSet = await store.query(predicates, ['id'])const hasRow = resultSet.goToFirstRow()resultSet.close()return hasRow
}// UI 页面
@Entry
@Component
struct LoginPage {@State username: string = ''@State password: string = ''@State message: string = ''async aboutToAppear() {const context = getContext(this)await createTable(context) // 页面加载时确保表存在}async login() {const context = getContext(this)const success = await checkLogin(context, this.username, this.password)if (success) {this.message = '✅ 登录成功'} else {this.message = '❌ 用户名或密码错误'}}build() {Column() {Text('用户登录').fontSize(26).fontWeight(FontWeight.Bold).margin({ bottom: 20 })TextInput({ placeholder: '请输入用户名', text: this.username }).onChange(value => this.username = value).margin(10)TextInput({ placeholder: '请输入密码', text: this.password }).onChange(value => this.password = value).type(InputType.Password).margin(10)Button('登录').margin(10).onClick(() => this.login())Text(this.message).fontSize(16).margin(10).fontColor(Color.Red)}.padding(20)}
}

运行结果:

注册页面:

登录页面

关键字:网页界面设计的原则_unity3d培训班多少钱_阿里云免费域名_seo常见的优化技术

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: