yuzhilin

feat:意图框架接入

@@ -55,7 +55,7 @@ export struct WdWebLocalComponent { @@ -55,7 +55,7 @@ export struct WdWebLocalComponent {
55 .mixedMode(MixedMode.All) 55 .mixedMode(MixedMode.All)
56 .onlineImageAccess(true) 56 .onlineImageAccess(true)
57 .enableNativeEmbedMode(true) 57 .enableNativeEmbedMode(true)
58 - .layoutMode(WebLayoutMode.FIT_CONTENT) 58 + // .layoutMode(WebLayoutMode.FIT_CONTENT)
59 // .nestedScroll({ scrollForward: NestedScrollMode.SELF_FIRST, scrollBackward: NestedScrollMode.PARENT_FIRST }) 59 // .nestedScroll({ scrollForward: NestedScrollMode.SELF_FIRST, scrollBackward: NestedScrollMode.PARENT_FIRST })
60 .height(this.webHeight) 60 .height(this.webHeight)
61 .onPageBegin((event) => { 61 .onPageBegin((event) => {
  1 +import { insightIntent } from '@kit.IntentsKit';
1 import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean'; 2 import { BottomNavDTO, CompDTO, TopNavDTO } from 'wdBean';
2 import { SpConstants } from 'wdConstant'; 3 import { SpConstants } from 'wdConstant';
3 import { DisplayUtils, LazyDataSource, Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit'; 4 import { DisplayUtils, LazyDataSource, Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit';
@@ -8,6 +9,7 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent @@ -8,6 +9,7 @@ import { FirstTabTopSearchComponent } from '../search/FirstTabTopSearchComponent
8 import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils'; 9 import { AssignChannelParam } from 'wdRouter/src/main/ets/utils/HomeChannelUtils';
9 import { PeopleShipMainComponent } from '../peopleShip/PeopleShipMainComponent'; 10 import { PeopleShipMainComponent } from '../peopleShip/PeopleShipMainComponent';
10 import { channelSkeleton } from '../skeleton/channelSkeleton'; 11 import { channelSkeleton } from '../skeleton/channelSkeleton';
  12 +import { common } from '@kit.AbilityKit';
11 13
12 14
13 const TAG = 'TopNavigationComponent'; 15 const TAG = 'TopNavigationComponent';
@@ -37,6 +39,7 @@ export struct TopNavigationComponent { @@ -37,6 +39,7 @@ export struct TopNavigationComponent {
37 // 顶导当前选中/焦点下标 39 // 顶导当前选中/焦点下标
38 @State currentTopNavSelectedIndex: number = 0; 40 @State currentTopNavSelectedIndex: number = 0;
39 @State currentTopNavName: string = ''; 41 @State currentTopNavName: string = '';
  42 + @State currentTopNavItem: TopNavDTO = {} as TopNavDTO
40 // 顶导数据 43 // 顶导数据
41 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] 44 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = []
42 @State compList: LazyDataSource<CompDTO> = new LazyDataSource(); 45 @State compList: LazyDataSource<CompDTO> = new LazyDataSource();
@@ -58,6 +61,8 @@ export struct TopNavigationComponent { @@ -58,6 +61,8 @@ export struct TopNavigationComponent {
58 @Prop @Watch('onAutoRefresh') autoRefresh: number = 0 61 @Prop @Watch('onAutoRefresh') autoRefresh: number = 0
59 // 传递给page的自动刷新通知 62 // 传递给page的自动刷新通知
60 @State autoRefresh2Page: number = 0 63 @State autoRefresh2Page: number = 0
  64 + //保存当前导航选中时的时间戳 意图开始时间
  65 + @State executedStartTime: number = new Date().getTime()
61 // 当前底导index 66 // 当前底导index
62 @State navIndex: number = 0 67 @State navIndex: number = 0
63 @State animationDuration: number = 0 68 @State animationDuration: number = 0
@@ -167,6 +172,7 @@ export struct TopNavigationComponent { @@ -167,6 +172,7 @@ export struct TopNavigationComponent {
167 this.currentTopNavSelectedIndex = index 172 this.currentTopNavSelectedIndex = index
168 this.currentTopNavName = this.myChannelList[index].name 173 this.currentTopNavName = this.myChannelList[index].name
169 } 174 }
  175 + this.currentTopNavItem = this.myChannelList[this.currentTopNavSelectedIndex]
170 } 176 }
171 177
172 isBroadcast(item: TopNavDTO) { 178 isBroadcast(item: TopNavDTO) {
@@ -184,6 +190,49 @@ export struct TopNavigationComponent { @@ -184,6 +190,49 @@ export struct TopNavigationComponent {
184 return item.channelType === 3 190 return item.channelType === 3
185 } 191 }
186 192
  193 + //意图共享
  194 + topNavInsightIntentShare(item: TopNavDTO){
  195 + let tapNavIntent: insightIntent.InsightIntent = {
  196 + intentName: 'ViewColumn',
  197 + intentVersion: '1.0.1',
  198 + identifier: '52dac3b0-6520-4974-81e5-25f0879449b5',
  199 + intentActionInfo: {
  200 + actionMode: 'EXPECTED',
  201 + currentPercentage: 50,
  202 + executedTimeSlots: {
  203 + executedEndTime: new Date().getTime(),
  204 + executedStartTime: this.executedStartTime
  205 + }
  206 + },
  207 + intentEntityInfo: {
  208 + entityName: 'ViewColumn',
  209 + entityId: String(item.pageId) || '',
  210 + displayName: item.name,
  211 + logoURL: 'https://www-file.huawei.com/-/media/corporate/images/home/logo/huawei_logo.png',
  212 + rankingHint: 99,
  213 + isPublicData: true
  214 + }
  215 + }
  216 +
  217 + try {
  218 + let context = getContext(this) as common.UIAbilityContext;
  219 + // 共享数据
  220 + insightIntent.shareIntent(context, [tapNavIntent], (error) => {
  221 + if (error?.code) {
  222 + // 处理业务逻辑错误
  223 + console.error(`shareIntent failed, error.code: ${error?.code}, error.message: ${error?.message}`);
  224 + return;
  225 + }
  226 + // 执行正常业务
  227 + console.log('shareIntent succeed');
  228 + });
  229 + } catch (error) {
  230 + // 处理异常
  231 + console.error(`error.code: ${error?.code}, error.message: ${error?.message}`);
  232 + }
  233 + }
  234 +
  235 +
187 build() { 236 build() {
188 Column() { 237 Column() {
189 // 顶部搜索、日报logo、早晚报 238 // 顶部搜索、日报logo、早晚报
@@ -278,7 +327,11 @@ export struct TopNavigationComponent { @@ -278,7 +327,11 @@ export struct TopNavigationComponent {
278 if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) && 327 if (!this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) &&
279 !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index]) 328 !this.isLayout(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index])
280 ) { 329 ) {
  330 + //在 tab 切换之前意图共享
  331 + // this.topNavInsightIntentShare(this.currentTopNavItem)
  332 +
281 this.currentTopNavSelectedIndex = index; 333 this.currentTopNavSelectedIndex = index;
  334 + this.currentTopNavItem = this.myChannelList[index]
282 } 335 }
283 if (this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index])) { 336 if (this.isBroadcast(this._currentNavIndex === 0 ? this.myChannelList[index] : this.topNavList[index])) {
284 // 跳转到播报页面 337 // 跳转到播报页面
@@ -416,9 +469,11 @@ export struct TopNavigationComponent { @@ -416,9 +469,11 @@ export struct TopNavigationComponent {
416 this.changeByClick = true 469 this.changeByClick = true
417 this.tabsController.changeIndex(index) 470 this.tabsController.changeIndex(index)
418 } 471 }
  472 +
419 }) 473 })
420 } 474 }
421 475
  476 +
422 aboutToAppear() { 477 aboutToAppear() {
423 //处理新闻tab顶导频道数据 478 //处理新闻tab顶导频道数据
424 this.topNavListHandle() 479 this.topNavListHandle()
  1 +import { insightIntent, InsightIntentExecutor } from '@kit.AbilityKit';
  2 +import { window } from '@kit.ArkUI';
  3 +import { BusinessError } from '@kit.BasicServicesKit';
  4 +
  5 +/**
  6 + * 意图调用
  7 + */
  8 +export default class InsightIntentExecutorImpl extends InsightIntentExecutor {
  9 + private static readonly ViewColumn = 'ViewColumn';
  10 + /**
  11 + * override 执行前台UIAbility意图
  12 + *
  13 + * @param name 意图名称
  14 + * @param param 意图参数
  15 + * @param pageLoader 窗口
  16 + * @returns 意图调用结果
  17 + */
  18 + onExecuteInUIAbilityForegroundMode(name: string, param: Record<string, Object>, pageLoader: window.WindowStage):
  19 + Promise<insightIntent.ExecuteResult> {
  20 + // 根据意图名称分发处理逻辑
  21 + switch (name) {
  22 + case InsightIntentExecutorImpl.ViewColumn:
  23 + return this.jumpToView(param, pageLoader);
  24 + default:
  25 + break;
  26 + }
  27 + return Promise.resolve({
  28 + code: -1,
  29 + result: {
  30 + message: 'unknown intent'
  31 + }
  32 + } as insightIntent.ExecuteResult)
  33 + }
  34 + /**
  35 + * 实现跳转新闻页面功能
  36 + *
  37 + * @param param 意图参数
  38 + * @param pageLoader 窗口
  39 + */
  40 + private jumpToView(param: Record<string, Object>, pageLoader: window.WindowStage): Promise<insightIntent.ExecuteResult> {
  41 + return new Promise((resolve, reject) => {
  42 + // TODO 实现意图调用,loadContent的入参为歌曲落地页路径,例如:pages/SongPage
  43 + pageLoader.loadContent('pages/MainPage')
  44 + .then(() => {
  45 + let entityId: string = (param.items as Array<object>)?.[0]?.['entityId'];
  46 + // TODO 调用成功的情况,此处可以打印日志
  47 + resolve({
  48 + code: 0,
  49 + result: {
  50 + message: 'Intent execute success'
  51 + }
  52 + });
  53 + })
  54 + .catch((err: BusinessError) => {
  55 + // TODO 调用失败的情况
  56 + resolve({
  57 + code: -1,
  58 + result: {
  59 + message: 'Intent execute failed'
  60 + }
  61 + })
  62 + });
  63 + })
  64 + }
  65 +}
  1 +{
  2 + "insightIntents": [
  3 + {
  4 + "intentName": "ViewColumn",
  5 + "domain": "",
  6 + "intentVersion": "1.0.1",
  7 + "srcEntry": "./ets/utils/InsightIntentExecutorImpl.ets",
  8 + "uiAbility": {
  9 + "ability": "EntryAbility",
  10 + "executeMode": [
  11 + "background",
  12 + "foreground"
  13 + ]
  14 + }
  15 + }
  16 + ]
  17 +}