HarmonyOS 应用开发体验-二

举报
tea_year 发表于 2024/02/29 23:17:25 2024/02/29
【摘要】 1、 技术相关使用语言: Js体验内容: 2、 展示效果与代码理解Html<div class="container"> <list class="list"> <list-item for="{{contactList}}" class="list-item" onfocus="listFocus({{$idx}})" onclick...



1、 技术相关


使用语言: Js

体验内容


2、 展示效果与代码理解


Html

<div class="container">
    <list class="list">
        <list-item for="{{contactList}}" class="list-item" onfocus="listFocus({{$idx}})"                   onclick="clickItem({{$idx}})">
            <image src="{{$item.image}}" class="list-image"></image>
            <div class="content">
                <text class="list-text">
                    {{$item.name}}
                </text>
                <text class="list-text" focusable="true">
                    {{$item.phone}}
                </text>
            </div>
            <image class="right-image" src="/common/right.png">
            </image>
        </list-item>
    </list>
    <div class="detail-container">
        <image class="detail-image" src="{{detailObj.image}}">
        </image>
        <text class="detail-name">
            {{detailObj.name}}
        </text>
        <text class="detail-phone">
            phone : {{detailObj.phone}}
        </text>
    </div>
    <dialog id="detailDialog" class="dialog-main" if="{{isPhoneDevice}}" @cancel="dialogCancel">
        <div class="dialog-div">
            <image src="{{detailObj.image}}" class="avatar"></image>
            <div class="input-box">
                <div class="flex-row">
                    <label class="label" target="name">名字</label>
                    <input id="name" class="input" type="text" value="{{name}}" @change="changeName">
                    </input>
                </div>
                <div class="flex-row">
                    <label class="label" target="phone">电话</label>
                    <input id="phone" class="input" type="text" value="{{phone}}" @change="changePhone">
                    </input>
               </div>
            </div>
            <div class="inner-btn">
                <button class="btn" type="text"  onclick="cancel">取消</button>
                <button class="btn" type="text"  onclick="confirm">确认</button>
            </div>
        </div>
    </dialog>
</div>

Css

.container {

  display: flex;

  flex-direction: row;

  justify-content: flex-start;

}

.list {

  margin-right: 14px;

  width: 100%;

}

.content {

  display: flex;

  flex-direction: column;

  justify-content: center;

  flex: 1;

  overflow: hidden;

}

.flex-row {

  display: flex;

  flex-direction: row;

  align-items: center;

  width: 200px;

}

@media screen and (device-type: tv) {

  .list {

    width: 50%;

    padding-right: 24px;

    padding-left: 24px;

  }

}

.list-item {

  height: 64px;

  margin: 0 14px;

  display: flex;

  flex-direction: row;

  align-items: center;

}

@media screen and (device-type: wearable) {

  .list-item {

    height: 80px;

  }

  .content {

    color:#ffffff;

  }

}

@media screen and (device-type: tv) {

  .list-item {

    height: 64px;

    border-radius: 8px;

    padding-left: 24px;

    background-color: #2c2c2c;

    display: flex;

    flex-direction: row;

    align-items: center;

    margin: 5px 0;

  }

  .content {

    color: #b4b4b4;

  }

}

.list-image {

  height: 46px;

  width: 46px;

}

.list-text {

  margin-left: 16px;

  font-size: 14px;

  white-space: nowrap;

  text-overflow: ellipsis;

  overflow: hidden;

  flex: 1;

}

.detail-container {

  width: 0;

  height: 0;

  overflow: hidden;

  color: #b4b4b4;

}

.right-image {

  width: 0px;

  height: 0px;

}

@media screen and (device-type: phone) {

  .right-image {

    width: 30px;

    height: 30px;

  }

}

@media screen and (device-type: tv) {

  .detail-container {

    position: absolute;

    right: 14px;

    top: 50%;

    width: 50%;

    height: 100%;

    transform: translateY(-50%);

    display: flex;

    flex-direction: column;

    justify-content: center;

    align-items: center;

  }

  .detail-image {

    height: 100px;

    width: 100px;

  }

  .detail-name,

  .detail-phone {

    margin-top: 12px;

    font-size: 20px;

    white-space: nowrap;

    text-overflow: ellipsis;

    text-align: center;

    max-height: 2rem;

    overflow: hidden;

    width: 100%;

  }

}

.dialog-div {

  width: 280px;

  background-color: #fff;

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: space-between;

}

.input-box {

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;

  padding: 0 50px;

}

.inner-btn {

  width: 200px;

  height: 40px;

  margin-top: 10px;

  display: flex;

  justify-content: space-around;

  align-items: center;

}

.btn {

  font-size: 15px;

  background: none;

  border: none;

  color: #1460f7;

}

.label {

  width: 40px;

  font-size: 16px;
}
.input {
  font-size: 16px;
  line-height: 32px;
  width: 160px;
  border: none;
  border-bottom: 1px solid #c8c8c8;
}
.avatar {
  width: 150px;
  height: 150px;
  margin: 20px;
}


JAVAScript

const HEAD_IMAGE = ["/common/head0.png", "/common/head1.png", "/common/head2.png", "/common/head3.png", "/common/head4.png"];




export default {

    //数据字段定义

    contactList: [

        {

            image: HEAD_IMAGE[0],

            name: "Alan",

            phone: "020-00000000"

        },

        {

            image: HEAD_IMAGE[2],

            name: "Bob",

            phone: "020-11111111"

        },

        {

            image: HEAD_IMAGE[3],

            name: "Carl",

            phone: "0755-33333333"

        },

        {

            image: HEAD_IMAGE[4],

            name: "David",

            phone: "19876543210"

        },

        {

            image: HEAD_IMAGE[0],

            name: "Alan",

            phone: "020-00000000"

        },

        {

            image: HEAD_IMAGE[1],

            name: "Bob",

            phone: "020-11111111"

        },

        {

            image: HEAD_IMAGE[2],

            name: "Carl",

            phone: "12345678910"

        },

        {

            image: HEAD_IMAGE[3],

            name: "David",

            phone: "19876543210"

        },

        {

            image: HEAD_IMAGE[4],

            name: "Alan",

            phone: "020-00000000"

        },

        {

            image: HEAD_IMAGE[0],

            name: "Bob",

            phone: "020-11111111"

        },

        {

            image: HEAD_IMAGE[1],

            name: "Carl",

            phone: "12345678910"

        },

        {

            image: HEAD_IMAGE[2],

            name: "David",

            phone: "19876543210"

        },

        {

            image: HEAD_IMAGE[3],

            name: "Alan",

            phone: "020-00000000"

        },

        {

            image: HEAD_IMAGE[4],

            name: "Bob",

            phone: "020-11111111"

        },

        {

            image: HEAD_IMAGE[0],

            name: "Carl",

            phone: "12345678910"

        },

        {

            image: HEAD_IMAGE[1],

            name: "David",

            phone: "19876543210"

        }

    ],

    //只做数据字段定义

    isPhoneDevice: false,

    name: "",

    phone: "",

    detailObj: {

        image: "",

        name: "",

        phone: ""

    },

}



3、 相关可以升级问题如下


第1, 手机跳出的二级页面点取消就不会保存修改的信息,点确认就会保存,还有怎么关掉这个页面,实现这些的代码在哪里或者是怎么实现的?


第2, 电视点击小图但右边的大图也会更新,实现这个逻辑的代码在哪?


第3, 就是js最后两段代码是有固定格式还是有方法技巧的?



【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。