背景:
前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,里面丰富的内容大家自己加,本期案例 仅供参考
先上本期效果图 ,里面图片自行替换
效果图1完整代码案例如下:
- Index
import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { EventMyItem } from './EventMyItem';
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Column() {
Text($r('app.string.EntryAbility_label')).fontSize(20).margin({ bottom: 10 })
List({ space: 6 }) {
ForEach(['清单一:“温暖治愈系” 收藏清单',
'清单二:“经典怀旧风” 收藏清单',
'清单三:“流行动感派” 收藏清单',
'清单四:“民谣情怀” 收藏清单',
'清单五:“影视原声集” 收藏清单',
], (item: string) => {
ListItem() {
EventMyItem({ title: item })
}
})
}
}
.alignItems(HorizontalAlign.Start)
.height('100%')
.padding(8)
.width('100%')
.margin({ top: 40 })
}
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
this.loginWithHuaweiID();
}
/**
* Sample code for using HUAWEI ID to log in to atomic service.
* According to the Atomic Service Review Guide, when a atomic service has an account system,
* the option to log in with a HUAWEI ID must be provided.
* The following presets the atomic service to use the HUAWEI ID silent login function.
* To enable the atomic service to log in successfully using the HUAWEI ID, please refer
* to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.
*/
private loginWithHuaweiID() {
// Create a login request and set parameters
let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
// Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
loginRequest.forceLogin = false;
// Execute login request
let controller = new authentication.AuthenticationController();
controller.executeRequest(loginRequest).then((data) => {
let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;
// Send authCode to the backend in exchange for uni