HarmonyOS鸿蒙Next《仿盒马》app开发技术分享回收金提现记录查询

HarmonyOS鸿蒙Next《仿盒马》app开发技术分享回收金提现记录查询

技术栈

Appgallery connect

开发准备

上一节我们实现了回收金提现的功能,并且成功展示了当前账户的支出列表,但是我们的提现相关的记录并没有很好的给用户做出展示,用户只知道当前账户提现扣款,并不知道回收金的去向,这一节我们就要实现回收金记录的查询添加、查询、展示

功能分析

要实现这些功能我们需要新建一张表,根据当前用户绑定的信息去填充对应的信息,把提现的银行卡,提现状态,提现时间,提现金额都先添加到表里,在用户进入提现记录页面之后,通过userid去查询当前用户的记录然后在列表里进行展示

代码实现

首先我们创建对应的提现记录表

{
  "objectTypeName": "withdrawal_record",
  "fields": [
    {"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {"fieldName": "user_id", "fieldType": "Integer", "notNull": true, "defaultValue": 0},
    {"fieldName": "bank_name", "fieldType": "String"},
    {"fieldName": "bank_num", "fieldType": "String"},
    {"fieldName": "creat_time", "fieldType": "String"},
    {"fieldName": "type_str", "fieldType": "String"},
    {"fieldName": "money", "fieldType": "Double"}
  ],
  "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"]}
  ]
}

我们生成对应的实体和db类之后,在提现成功的提交记录里,把我们表需要的信息添加进去

let record=new withdrawal_record()
record.id=Math.floor(Math.random() * 1000000)
record.user_id=this.user!.user_id
record.bank_name=this.bankList[0].bank_name
record.bank_num=this.bankList[0].bank_card
record.creat_time=this.year+"-"+this.month+"-"+this.day+" "+this.time
record.type_str='0'
record.money=this.moneyNum
let status = await databaseZone.upsert(record);

添加完成之后我们新建一个提现记录展示页面

@Entry
@Component
struct WithdrawalRecordPage {
  @State user: User|null=null
  build() {
    Column() {
      CommonTopBar({ title: "提现记录", alpha: 0, titleAlignment: TextAlign.Center ,backButton:true})
    }
    .backgroundColor("#F1F3F5")
    .height('100%')
    .width('100%')
  }
}

首先进行数据的查询

@State user: User|null=null
@State withdrawalRecordList:WithdrawalRecord[]=[]
async aboutToAppear(): Promise<void> {
  const value = await StorageUtils.getAll('user');
  if (value != "") {
    this.user = JSON.parse(value)
  }
  let databaseZone = cloudDatabase.zone('default');
  let condition = new cloudDatabase.DatabaseQuery(withdrawal_record);
  condition.equalTo("user_id", this.user?.user_id)
  let listData = await databaseZone.query(condition);
  let json = JSON.stringify(listData)
  let data: WithdrawalRecord[] = JSON.parse(json)
  if (data.length>0) {
    this.withdrawalRecordList=data
  }
}

然后把我们查询到的数据展示到列表组件中

List({space:10}) {
  ForEach(this.withdrawalRecordList,(item:WithdrawalRecord,index:number)=>{
    ListItem(){
      Column({space:10}) {
        Row(){
          Text(item.type_str=='0'?"提现成功":"提现中")
            .fontColor(item.type_str=='0'?Color.Green:Color.Black)
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
          Text("¥"+item.money+"")
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
            .fontColor(Color.Black)
        }
        .width('100%')
        .justifyContent(FlexAlign.SpaceBetween)
        Row(){
          Text(item.bank_name+" ("+item.bank_num+")")
            .fontColor(Color.Black)
            .fontSize(14)
            .fontWeight(FontWeight.Bold)
          Text(item.creat_time+"")
            .fontSize(14)
            .fontWeight(FontWeight.Bold)
            .fontColor(Color.Grey)
        }
        .width('100%')
        .justifyContent(FlexAlign.SpaceBetween)
      }
      .padding(10)
      .width('100%')
      .borderRadius(10)
      .backgroundColor(Color.White)
    }
  })
}
.padding(10)

更多关于HarmonyOS鸿蒙Next《仿盒马》app开发技术分享回收金提现记录查询的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

在HarmonyOS鸿蒙Next中实现《仿盒马》回收金提现记录查询功能,可采用以下技术方案:

  1. 使用ArkUI的List组件展示提现记录列表
  2. 数据层采用Preferences或关系型数据库存储提现记录
  3. 网络请求使用@ohos.net.http模块与后端交互
  4. 时间筛选功能可用DatePicker组件实现
  5. 状态管理推荐使用AppStorage进行全局状态共享

关键代码示例:

// 获取提现记录
async fetchWithdrawRecords() {
  let httpRequest = http.createHttp();
  let response = await httpRequest.request(
    "https://api.example.com/withdraw",
    { method: 'GET' }
  );
  this.records = JSON.parse(response.result);
}

更多关于HarmonyOS鸿蒙Next《仿盒马》app开发技术分享回收金提现记录查询的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个很好的HarmonyOS Next应用开发实践分享。从技术实现来看,您已经完整地实现了回收金提现记录的功能模块,包括:

  1. 数据库表设计合理,包含了必要的字段(user_id、bank_name、bank_num等)和索引
  2. 使用AppGallery Connect的云数据库服务进行数据存储和查询
  3. 实现了记录添加逻辑,在提现成功后自动创建记录
  4. 通过user_id查询当前用户的提现记录
  5. 使用List+ForEach高效展示记录列表
  6. 界面设计清晰,展示了提现状态、金额、银行信息和时间等关键信息

代码结构清晰,使用了TypeScript的强类型特性,并合理运用了HarmonyOS的UI组件(Column、Row、Text等)和状态管理(@State)。查询条件使用equalTo方法确保数据安全,只返回当前用户的记录。

可以考虑的优化点:

  1. 时间字段可以改用时间戳格式,便于排序和计算
  2. 添加分页查询功能,防止记录过多时性能问题
  3. 增加空状态提示,提升用户体验

整体实现符合HarmonyOS应用开发规范,是一个典型的数据驱动型功能模块实现范例。

回到顶部