《伴时匣》app开发技术分享--用户登陆页静态(1)

简介: 大家好,今天给大家带来一个全新的鸿蒙应用,名字叫做伴时匣,意思就是一个陪伴度过时光的匣子,首先来介绍关于伴时匣的整个功能设想,首先呢,就是应用的功能,这个应用主要用来进行倒计时提醒的功能,在这里我们可以发布一些日子作为目标日

## 技术栈

Appgallery connect

开发准备

大家好,今天给大家带来一个全新的鸿蒙应用,名字叫做伴时匣,意思就是一个陪伴度过时光的匣子,首先来介绍关于伴时匣的整个功能设想,首先呢,就是应用的功能,这个应用主要用来进行倒计时提醒的功能,在这里我们可以发布一些日子作为目标日,通过设置正数倒数来展示我们设置的对应日子,大多数的应用同样也做得到这些,所以我们以用户为主导的思想肯定不仅限于此,我们还要实现关系的绑定,实现我们“伴”的主体思想,我们可以通过绑定已有的关系,查看不同角色之间我们创建的内容。这样我们就兼顾实现了个人,多人共同使用的一个场景。同时在app中还会实现留言功能,让我们的记录多一些小惊喜

功能分析

要实现这样一个应用,我们的技术选型标准就是需要有云端存储功能,并且实现不同设备的数据交互,并且保证数据的实时同步。所以在技术上我们选择使用云数据库来实现

功能开发

话不多说,现在我们就来开始我们伴时匣app的开发,首先我们要实现的是用户相关功能,有了用户,我们才能实现用户信息的处理,从而实现后续的其他功能

我们先进行表的创建

{
   
  "CloudDBZoneName": "casket",
  "objectTypeName": "user",
  "fields": [
    {
   "fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {
   "fieldName": "bind_user_id", "fieldType": "Integer"},
    {
   "fieldName": "bind_type", "fieldType": "Integer"},
    {
   "fieldName": "user_id", "fieldType": "Integer"},
    {
   "fieldName": "user_name", "fieldType": "String"},
    {
   "fieldName": "psw", "fieldType": "String"},
    {
   "fieldName": "nike_name", "fieldType": "String"},
    {
   "fieldName": "url", "fieldType": "String"},
    {
   "fieldName": "sex", "fieldType": "String"},
    {
   "fieldName": "birthday", "fieldType": "String"},
    {
   "fieldName": "phone", "fieldType": "String"}

  ],
  "indexes": [
    {
   "indexName": "field1Index", "indexList": [{
   "fieldName":"id","sortType":"ASC"}]}

  ],
  "permissions": [
    {
   "role": "World", "rights": ["Read", "Upsert", "Delete"]},
    {
   "role": "Authenticated", "rights": ["Read", "Upsert", "Delete"]},
    {
   "role": "Creator", "rights": ["Read", "Upsert", "Delete"]},
    {
   "role": "Administrator", "rights": ["Read", "Upsert", "Delete"]}
  ]
}

创建实体类


class User {
   
    id: number;
    bind_user_id: number;
    bind_type: number;
    user_id: number;
    user_name: string;
    psw: string;
    nike_name: string;
    url: string;
    sex: string;
    birthday: string;
    phone: string;

    constructor() {
   
    }


    setId(id: number): void {
   
        this.id = id;
    }

    getId(): number  {
   
        return this.id;
    }

    setBind_user_id(bind_user_id: number): void {
   
        this.bind_user_id = bind_user_id;
    }

    getBind_user_id(): number  {
   
        return this.bind_user_id;
    }

    setBind_type(bind_type: number): void {
   
        this.bind_type = bind_type;
    }

    getBind_type(): number  {
   
        return this.bind_type;
    }

    setUser_id(user_id: number): void {
   
        this.user_id = user_id;
    }

    getUser_id(): number  {
   
        return this.user_id;
    }

    setUser_name(user_name: string): void {
   
        this.user_name = user_name;
    }

    getUser_name(): string  {
   
        return this.user_name;
    }

    setPsw(psw: string): void {
   
        this.psw = psw;
    }

    getPsw(): string  {
   
        return this.psw;
    }

    setNike_name(nike_name: string): void {
   
        this.nike_name = nike_name;
    }

    getNike_name(): string  {
   
        return this.nike_name;
    }

    setUrl(url: string): void {
   
        this.url = url;
    }

    getUrl(): string  {
   
        return this.url;
    }

    setSex(sex: string): void {
   
        this.sex = sex;
    }

    getSex(): string  {
   
        return this.sex;
    }

    setBirthday(birthday: string): void {
   
        this.birthday = birthday;
    }

    getBirthday(): string  {
   
        return this.birthday;
    }

    setPhone(phone: string): void {
   
        this.phone = phone;
    }

    getPhone(): string  {
   
        return this.phone;
    }

}

export {
    User };

创建db类


import {
    cloudDatabase } from '@kit.CloudFoundationKit';

class user extends cloudDatabase.DatabaseObject {
   
  public id: number;
  public bind_user_id: number;
  public bind_type: number;
  public user_id: number;
  public user_name: string;
  public psw: string;
  public nike_name: string;
  public url: string;
  public sex: string;
  public birthday: string;
  public phone: string;

  public naturalbase_ClassName(): string {
   
    return 'user';
  }
}

export {
    user };

然后我们先来实现一个基础的登陆页面

import promptAction from '@ohos.promptAction';
import {
    router } from '@kit.ArkUI';
import {
    CommonTopBar } from '../widget/CommonTopBar';


@Entry
@Component
struct LoginPage {
   

  aboutToAppear(){
   
  }
  @State acc:string = ''
  @State psw:string = ''
  controller: TextInputController = new TextInputController()

  async login(): Promise<void>{
   
    if (this.acc===''&&this.psw==='') {
   
      promptAction.showToast({
   message:"请输入账号或密码"})
      return
    }else {
   

    }
  }



  build() {
   
    Column({
   space:20}) {
   
      CommonTopBar({
    title: "登录", alpha: 0, titleAlignment: TextAlign.Center ,backButton:false})
      Column() {
   
        Image($r("app.media.logo"))
          .width(120).height(120).borderRadius(60)

        TextInput({
   text:this.acc,
          placeholder: '请输入账号'
        })
          .backgroundColor("#f6f6f6")
          .placeholderColor("#ff999595")
          .fontColor("#333333")
          .maxLength(11)
          .type(InputType.Number)
          .onChange((value: String) => {
   
            this.acc = value.toString()
          }).margin(20)

        TextInput({
   text:this.psw,
          placeholder: '请输入密码'
        })
          .backgroundColor("#f6f6f6")
          .placeholderColor("#ff999595")
          .fontColor("#333333")
          .type(InputType.Password)
          .onChange((value: String) => {
   
            this.psw = value.toString()
          }).margin(20)

        Row() {
   
          Text('用户注册')
            .fontColor("#ff65c8ee")
            .fontSize(14)
            .margin(30)
            .onClick(()=>{
   
              router.pushUrl({
   url:'pages/user/RegisterPage'})
            })

        }
        .width('100%')
        .justifyContent(FlexAlign.End)



        Button('登陆',{
   type:ButtonType.Capsule,stateEffect:false})
          .onClick(()=>{
   
            this.login()
          })
          .fontColor(Color.White)
          .width('80%')
          .height(40)
          .backgroundColor("#ff65c8ee")
      }
      .width('100%')}
    .height('100%')
    .backgroundColor('#FFFFFF')
    .justifyContent(FlexAlign.Start)



  }
}

到这里我们就实现了用户的静态登陆页

相关文章
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8071 2
|
11天前
|
域名解析 人工智能 Linux
|
21天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
18566 64
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全
|
10天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1507 5
|
8天前
|
云安全 数据采集 人工智能
|
16天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2652 8
|
9天前
|
Web App开发 缓存 安全
巨魔商店 TrollStore 安装教程(2026):免电脑在线安装与全机型安装器矩阵_iOS巨魔安装
巨魔商店(TrollStore)是iOS 14–17.0(特定版本)的永久签名工具,无需越狱,利用CoreTrust漏洞实现IPA签名长期有效,彻底告别7天重签。支持免电脑在线安装(TrollHelperOTA),适配多机型/系统组合,开源免费,安全可控。(239字)
2151 0