HarmonyOS:GridObjectSortComponent(两个Grid之间网格元素交换)

一、概述

网格对象的编辑排序是用于网格对象的编辑、拖动排序、新增和删除。

说明

该组件从API Version 11开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

二、导入模块

复制代码
import { GridObjectSortComponent, GridObjectSortComponentItem, GridObjectSortComponentOptions, GridObjectSortComponentType } from '@kit.ArkUI'

三、子组件

四、属性

不支持通用属性。

五、GridObjectSortComponent

GridObjectSortComponent({options: GridObjectSortComponentOptions, dataList: Array, onSave: (select: Array, unselect: Array) => void, onCancel: () => void })

装饰器类型: @Component

元服务API: 从API version 12开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

名称 类型 必填 装饰器类型 说明
options GridObjectSortComponentOptions @Prop 组件配置信息。
dataList Array<GridObjectSortComponentItem> - 传入的数据,最大长度为50,数据长度超过50,只会取前50的数据。
onSave (select: Array, unselect: Array<GridObjectSortComponentItem>) => void - 保存编辑排序的回调函数,返回编辑后的数据。
onCancel () => void - 取消保存数据的回调。

六、GridObjectSortComponentOptions

元服务API: 从API version 12开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

名称 类型 必填 说明
type GridObjectSortComponentType 组件展示形态:文字|图片+文字。 默认:GridObjectSortComponentType.text。
imageSize number | Resource 图片的尺寸,单位vp。 取值范围:大于等于0。 默认值:56vp。
normalTitle ResourceStr 未编辑状态下显示的标题。 默认值:频道。
showAreaTitle ResourceStr 展示区域标题,第一个子标题。 默认值:长按拖动排序。
addAreaTitle ResourceStr 添加区域标题,第二个子标题。 默认值:点击添加。
editTitle ResourceStr 编辑状态下头部标题显示。 默认值:编辑。

七、GridObjectSortComponentType

元服务API: 从API version 12开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

名称 说明
IMAGE_TEXT 'image_text' 图片文字类型。
TEXT 'text' 文字类型。

八、GridObjectSortComponentItem

元服务API: 从API version 12开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

名称 类型 必填 说明
id number | string 数据id序号,不可重复。 默认值:空字符串。
text ResourceStr 显示文本信息。
selected boolean 是否已经被添加,添加:true,未添加:false。
url ResourceStr GridObjectSortComponentType类型为IMAGE_TEXT时,需要传入图片地址。
order number 顺序序号。 取值范围:大于等于0。 默认值:0。

九、事件

不支持通用事件。

十、示例

网格对象的编辑排序组件基础用法,涉及对组件配置信息初始化,数据初始化,保存、取消方法的使用。
效果图

示例TestGridObjectSortComponent.ets代码

复制代码
import { GridObjectSortComponent, GridObjectSortComponentItem, GridObjectSortComponentOptions, GridObjectSortComponentType } from '@kit.ArkUI'

@Entry
@Component
struct TestGridObjectSortComponent {
  // 组件数据初始化
  @State dataList: GridObjectSortComponentItem[] = [
    {
      id: 0,
      url: $r('sys.media.ohos_save_button_filled'),
      text: '下载',
      selected: true,
      order: 3
    },
    {
      id: 1,
      url: $r('sys.media.ohos_ic_public_web'),
      text: '网路',
      selected: true,
      order: 9
    },
    {
      id: 2,
      url: $r('sys.media.ohos_ic_public_video'),
      text: '视频',
      selected: false,
      order: 1
    }
  ]

  // 组件配置信息初始化
  @State option: GridObjectSortComponentOptions = {
    type: GridObjectSortComponentType.IMAGE_TEXT,
    imageSize: 45,
    normalTitle: '菜单',
    editTitle: '编辑',
    showAreaTitle: '长按拖动排序',
    addAreaTitle: '点击添加'
  }

  build() {
    Column() {
      GridObjectSortComponent({
        options: this.option,
        dataList: this.dataList,
        // 保存编辑排序的回调函数,返回编辑后的数据。
        onSave: (
          select: Array<GridObjectSortComponentItem>,
          unselect: Array<GridObjectSortComponentItem>
        ) => {
          // save ToDo
          console.log("保存编辑排序的回调函数 onSave")
        },
        // 取消保存数据的回调。
        onCancel: () =>{
          // cancel ToDo
          console.log("取消保存数据的回调 onCancel")
        }
      })
    }
  }
}
相关推荐
键盘鼓手苏苏1 天前
Flutter 三方库 p2plib 的鸿蒙化适配指南 - 实现高性能的端到端(P2P)加密通讯、支持分布式节点发现与去中心化数据流传输实战
flutter·harmonyos·鸿蒙·openharmony
加农炮手Jinx1 天前
Flutter for OpenHarmony:postgrest 直接访问 PostgreSQL 数据库的 RESTful 客户端(Supabase 核心驱动) 深度解析与鸿蒙适配指南
数据库·flutter·华为·postgresql·restful·harmonyos·鸿蒙
加农炮手Jinx1 天前
Flutter 组件 heart 适配鸿蒙 HarmonyOS 实战:分布式心跳监控,构建全场景保活检测与链路哨兵架构
flutter·harmonyos·鸿蒙·openharmony
钛态1 天前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
王码码20351 天前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
王码码20351 天前
Flutter 三方库 dns_client 的鸿蒙化适配指南 - 告别 DNS 劫持、探索 DNS-over-HTTPS (DoH) 技术、构建安全的鸿蒙网络请求环境
flutter·harmonyos·鸿蒙·openharmony·dns_client
键盘鼓手苏苏1 天前
Flutter 组件 highlighter 适配鸿蒙 HarmonyOS 实战:高性能语法高亮,构建大规模代码分析与文本染色架构
flutter·harmonyos·鸿蒙·openharmony
国医中兴1 天前
Flutter 三方库 langchain_google 的鸿蒙化适配指南 - 链接 Gemini 智慧中枢、LangChain AI 实战、鸿蒙级智能应用专家
flutter·langchain·harmonyos
左手厨刀右手茼蒿1 天前
Flutter for OpenHarmony: Flutter 三方库 shamsi_date 助力鸿蒙应用精准适配波斯历法(中东出海必备)
android·flutter·ui·华为·自动化·harmonyos
雷帝木木1 天前
Flutter 三方库 http_client_interceptor 的鸿蒙化适配指南 - 实现原生 HttpClient 的全量请求拦截、支持端侧动态 Headers 注入与网络流量审计实战
flutter·harmonyos·鸿蒙·openharmony·http_client_interceptor