《仿盒马》app开发技术分享-- 旧物回收页(提交云端)(42)

简介: 上一节我们已经实现了地址,留言,取件时间的选择,以及静态的预估重量。现在我们需要把预估重量创建出来,从云端去获取,以应对后续的其他业务逻辑,以及回收订单的创建

技术栈

Appgallery connect

开发准备

上一节我们已经实现了地址,留言,取件时间的选择,以及静态的预估重量。现在我们需要把预估重量创建出来,从云端去获取,以应对后续的其他业务逻辑,以及回收订单的创建

功能分析

预估重量列表的实现首先需要创建对应的表和数据源,然后在页面打开的时候从云端查询出对应的数据,展示到我们创建的静态列表中,然后我们创建订单,把页面中的数据放置到创建的订单创建表中

代码实现

首先我们创建对应的表

{
   
  "objectTypeName": "weight_info",
  "fields": [
    {
   "fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {
   "fieldName": "weight_id", "fieldType": "Integer"},
    {
   "fieldName": "weight", "fieldType": "String"},
    {
   "fieldName": "txt", "fieldType": "String"},
    {
   "fieldName": "integral", "fieldType": "Double"},
    {
   "fieldName": "money", "fieldType": "Double"}
  ],
  "indexes": [
    {
   "indexName": "field1IndexId", "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类

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

class weight_info extends cloudDatabase.DatabaseObject {
   
  public id: number;
  public weight_id: number;
  public weight: string;
  public txt: string;
  public integral: number;
  public money: number;

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

export {
    weight_info };




class WeightInfo {
   
    id: number;
    weight_id: number;
    weight: string;
    txt: string;
    integral: number;
    money: number;

    constructor() {
   
    }

    getFieldTypeMap():  Map<string, string> {
   
        let fieldTypeMap = new Map<string, string>();
        fieldTypeMap.set('id', 'Integer');
        fieldTypeMap.set('weight_id', 'Integer');
        fieldTypeMap.set('weight', 'String');
        fieldTypeMap.set('txt', 'String');
        fieldTypeMap.set('integral', 'Double');
        fieldTypeMap.set('money', 'Double');
        return fieldTypeMap;
    }

    getClassName(): string {
   
        return 'weight_info';
    }

    getPrimaryKeyList(): string[] {
   
        let primaryKeyList: string[] = [];
        primaryKeyList.push('id');
        return primaryKeyList;
    }

    getIndexList(): string[] {
   
        let indexList: string[] = [];
        indexList.push('id');
        return indexList;
    }

    getEncryptedFieldList(): string[] {
   
        let encryptedFieldList: string[] = [];
        return encryptedFieldList;
    }

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

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

    setWeight_id(weight_id: number): void {
   
        this.weight_id = weight_id;
    }

    getWeight_id(): number  {
   
        return this.weight_id;
    }

    setWeight(weight: string): void {
   
        this.weight = weight;
    }

    getWeight(): string  {
   
        return this.weight;
    }

    setTxt(txt: string): void {
   
        this.txt = txt;
    }

    getTxt(): string  {
   
        return this.txt;
    }

    setIntegral(integral: number): void {
   
        this.integral = integral;
    }

    getIntegral(): number  {
   
        return this.integral;
    }

    setMoney(money: number): void {
   
        this.money = money;
    }

    getMoney(): number  {
   
        return this.money;
    }

    static parseFrom(inputObject: any): WeightInfo {
   
        let result = new WeightInfo();
        if (!inputObject) {
   
            return result;
        }
        if (inputObject.id) {
   
            result.id = inputObject.id;
        }
        if (inputObject.weight_id) {
   
            result.weight_id = inputObject.weight_id;
        }
        if (inputObject.weight) {
   
            result.weight = inputObject.weight;
        }
        if (inputObject.txt) {
   
            result.txt = inputObject.txt;
        }
        if (inputObject.integral) {
   
            result.integral = inputObject.integral;
        }
        if (inputObject.money) {
   
            result.money = inputObject.money;
        }
        return result;
    }
}

export {
    WeightInfo };

在页面打开后获取云端的数据

 @State weightList:WeightInfo[]=[]
  @State weightInfo:WeightInfo|null=null
async aboutToAppear(): Promise<void> {
   
    const value = await StorageUtils.getAll('user');
    if (value != "") {
   
      this.user = JSON.parse(value)
    }
    let condition = new cloudDatabase.DatabaseQuery(weight_info);
    let listData = await databaseZone.query(condition);
    let json = JSON.stringify(listData)
    let weightInfo:WeightInfo[]= JSON.parse(json)
    this.weightList=weightInfo
    hilog.info(0x0000, 'testTag', `Succeeded in querying data, result: ${
   weightInfo}`);
    this.flag=true
  }

添加对应的数据到提交信息表

Text("预约呼叫")
              .width('95%')
              .height(45)
              .fontSize(16)
              .fontWeight(FontWeight.Bold)
              .borderRadius(5)
              .backgroundColor("#fff84f4f")
              .textAlign(TextAlign.Center)
              .margin({
   top:15})
              .onClick(async ()=>{
   
                let recyclePushInfo=new recycle_info()
                recyclePushInfo.id=Math.floor(Math.random() * 1000000);
                recyclePushInfo.user_id=this.user!.user_id
                recyclePushInfo.nike_name=this.addressInfo!.nikeName
                recyclePushInfo.phone=this.addressInfo!.phone
                recyclePushInfo.address=this.addressInfo!.address
                recyclePushInfo.day=this.formatCurrent()
                recyclePushInfo.start_time=this.formatCurrentDate()
                recyclePushInfo.end_time=this.formatCurrentEndDate()
                recyclePushInfo.weight_id=String(this.weightInfo!.weight_id)
                if (this.remark!='') {
   
                  recyclePushInfo.msg=this.remark
                }
                recyclePushInfo.create_time=this.formatCurrentCreatTime()
                recyclePushInfo.express_code=this.generate16DigitRandom()
                recyclePushInfo.express_people="骑士阿三"
                recyclePushInfo.express_company="中国邮政(默认)"
                recyclePushInfo.order_type=0
                recyclePushInfo.logistics_id=10
                let num = await databaseZone.upsert(recyclePushInfo);
                hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${
   num}`);
                if (num>0) {
   
                  showToast("下单成功")
                }
              })

到这里我们就实现了提交云端数据的功能

相关文章
|
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字)
2152 0