wangliang_wd

Merge branch 'main' of http://192.168.1.42/developOne/harmonyPool into main

* 'main' of http://192.168.1.42/developOne/harmonyPool:
  版面-电子报版面按住图片出现阴影绘制区域优化
  fix: 1)无网络,点击预告直播间和正在直播直播间,预期提示“网络出小差了,请检查网络后重试”,实际进入黑色页面
  feat: 1)人民号--关注频道,稿件线,和删除冗余调用冗余接口
  ref |> 统一优化跳转详情页detailPageType
  ref |> 早晚报桌面组件跳转App页面处理
  ref |> 早晚报桌面组件图片显示相关逻辑
  feat: 1)人民号--关注频道ui
Showing 24 changed files with 519 additions and 122 deletions
... ... @@ -68,3 +68,7 @@ export { FastClickUtil } from './src/main/ets/utils/FastClickUtil';
// export { PublicPopupDialogView } from "./src/main/ets/pubComps/dialog/PublicPopupDialogView"
export { PublicDialogManager, CloseAction } from "./src/main/ets/pubComps/dialog/PublicDialogManager"
export { CrptoUtils } from "./src/main/ets/utils/CrptoUtils"
export { FileUtils } from "./src/main/ets/utils/FileUtils"
\ No newline at end of file
... ...
import cryptoFramework from '@ohos.security.cryptoFramework';
import buffer from '@ohos.buffer';
export class CrptoUtils {
static md5(message: string) : Promise<string> {
return CrptoUtils.mdFunc(message, 'MD5')
}
static mdFunc(message: string, algoName: string = 'MD5'): Promise<string> {
return new Promise<string>(async (reslove, fail) => {
try {
let md = cryptoFramework.createMd(algoName);
// 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制
await md.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) });
let mdResult = await md.digest();
// console.info('Md result:' + mdResult.data);
// const string = mdResult.data.map((charCode, index, array) => {
// return String.fromCharCode(charCode)
// }).join("")
let string = "";
for (let i = 0; i < mdResult.data.length; i++) {
string += mdResult.data[i].toString(16).padStart(2, "0")
}
// const string = mdResult.data.join('')
reslove(string)
} catch (e) {
fail(e)
}
})
}
}
... ...
import fs from '@ohos.file.fs';
import { BusinessError } from '@kit.BasicServicesKit';
export class FileUtils {
// 文件是否存在,忽略错误
static fileExsit(path: string) : Promise<boolean> {
return new Promise((reslove, fail) => {
fs.stat(path).then(() => {
reslove(true)
}).catch((error: BusinessError) => {
if (error.code = 13900002) {
reslove(false)
} else {
reslove(true)
}
})
});
}
static makeDirIfNotExsit(path: string) : Promise<void> {
return new Promise((reslove, fail) => {
fs.stat(path).then(() => {
reslove()
}).catch((error: BusinessError) => {
if (error.code = 13900002) {
fs.mkdirSync(path)
}
reslove()
})
})
}
}
\ No newline at end of file
... ...
... ... @@ -49,9 +49,9 @@ export function registerRouter() {
// })
Action2Page.register("JUMP_DETAIL_PAGE", (action: Action) => {
if (action.params?.detailPageType == 2 || action.params?.detailPageType == 6) {
if (action.params?.detailPageType == 2) {
return WDRouterPage.detailPlayLiveCommon
} else if (action.params?.detailPageType == 7 || action.params?.detailPageType == 8) {
} else if (action.params?.detailPageType == 1) {
return WDRouterPage.detailVideoListPage
} else if (action.params?.detailPageType == 9) {
//图集详情页
... ... @@ -59,16 +59,19 @@ export function registerRouter() {
} else if (action.params?.detailPageType == 14 || action.params?.detailPageType == 15) {
//动态详情页
return WDRouterPage.dynamicDetailPage
} else if (action.params?.detailPageType == 17) {
return WDRouterPage.multiPictureDetailPage
} else if (action.params?.detailPageType == 13) {
return WDRouterPage.audioDetail
} else if (action.params?.detailPageType == 18) {
} else if (action.params?.detailPageType == 30) {
return WDRouterPage.themeListPage
} else if (action.params?.detailPageType == 8) {
return WDRouterPage.imageTextDetailPage
}
//TODO: 以下两个最好改为pageID方式,以上都是有具体内容类型 对应详情页面
else if (action.params?.detailPageType == 18) {
return WDRouterPage.multiPictureListPage
} else if (action.params?.detailPageType == 19) {
return WDRouterPage.videoPlayPage
}else if (action.params?.detailPageType == 30) {
return WDRouterPage.themeListPage
}
return WDRouterPage.detailPlayVodPage
})
... ...
... ... @@ -3,6 +3,7 @@ import App from '@system.app'
import { Action, Params } from 'wdBean/Index'
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
import { Logger } from 'wdKit/Index'
import { ContentType } from '../common/ContentType'
import { WDRouterRule } from '../router/WDRouterRule'
import { ProcessUtils } from './ProcessUtils'
... ... @@ -111,13 +112,13 @@ export class AppInnerLink {
}
private static contentTypeWithType(type?: string) : number | undefined {
switch (type) {
case "video": return 1
case "dynamic": return 14
case "live": return 2
case "audio": return 13
case "picture": return 9
case "article": return 8
case "ask": return 16
case "video": return ContentType.Video
case "dynamic": return ContentType.DynamicImageText
case "live": return ContentType.Live
case "audio": return ContentType.Audio
case "picture": return ContentType.Pictures
case "article": return ContentType.ImageText
case "ask": return ContentType.Ask
}
return
}
... ...
import { Action, ContentDTO, Params, PhotoListBean, commentInfo } from 'wdBean';
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO';
import { Logger, SPHelper } from 'wdKit';
import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit';
import { StringUtils } from 'wdKit/src/main/ets/utils/StringUtils';
import { WDRouterRule, WDRouterPage } from '../../../../Index';
import { ContentConstants, SpConstants } from 'wdConstant';
... ... @@ -84,6 +84,13 @@ export class ProcessUtils {
Logger.error(TAG, "processPage, objectType is empty");
return;
}
// 网络出小差了,请检查网络后重试
let netStatus = NetworkUtil.isNetConnected()
if(!netStatus){
ToastUtils.shortToast('网络出小差了,请检查网络后重试')
return
}
let type = content.objectType;
if (typeof type == "number") {
type = `${type}`
... ... @@ -304,7 +311,7 @@ export class ProcessUtils {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 7,
detailPageType: 1,
contentID: content?.objectId,
extra: {
relType: content?.relType,
... ... @@ -382,7 +389,7 @@ export class ProcessUtils {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 17,
detailPageType: 9,
contentID: content?.objectId,
extra: {
relType: content?.relType,
... ...
... ... @@ -10,16 +10,13 @@ export interface Params {
// 详情页类型
// 1.点播详情页
// 2.直播详情页
// 3.图文详情页
// 4.全民播详情页
// 5.欢喜详情页
// 6.挂件详情页
// 7.沉浸式竖屏详情页
// 8.专辑竖屏详情页
// 13.音频详情页
// 17.多图(图集)详情页
// 18.大图列表页
// 19.单个视频播放页
// 8.图文详情页
// 9.多图(图集)详情页
// 14和15 动态详情页
// 13 音频详情页
// 30 金刚位
// 18.大图列表页 - 图片预览 ------ 需要变更待定
// 19.单个视频播放页 - 视频播放 ----- 需要变更待定
detailPageType?: number; // 详情页类型
liveStyle?: number; // 直播类型:0横屏,1竖屏
creatorId?: string; //号主id
... ...
... ... @@ -25,6 +25,7 @@ import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index';
*/
@Component
export struct CardParser {
@State pageId: string = '';
@State pageName: string = '';
@State contentDTO: ContentDTO = new ContentDTO();
... ...
... ... @@ -45,8 +45,6 @@ export struct CompParser {
aboutToAppear(): void {
console.log('CompParser', JSON.stringify(this.compDTO))
this.pageName = this.pageModel.pageInfo.name
// 轮播图屏蔽音频类型稿件
... ...
... ... @@ -13,6 +13,10 @@ export struct ENewspaperItemComponent {
private startY: number = 0
private itemBeanClicked: NewspaperPositionItemBean = {} as NewspaperPositionItemBean
@State isShowSkeleton: boolean = true
@State contentWidth: number = 0
@State contentHeight: number = 0
@Consume itemPicWidth: number
@Consume itemPicHeight: number
aboutToAppear(): void {
for (let index = 0; index < this.newspaperListItemBean.items.length; index++) {
... ... @@ -33,23 +37,28 @@ export struct ENewspaperItemComponent {
newsSkeleton()
.visibility(this.isShowSkeleton ? Visibility.Visible : Visibility.None)
Image(this.newspaperListItemBean.pagePic)
.width('100%')
.onComplete(() => {
.width(px2vp(this.itemPicWidth))
.height(px2vp(this.itemPicHeight))
.onComplete((event) => {
if (event?.loadingStatus == 1) {
this.contentWidth = event?.contentWidth
this.contentHeight = event?.contentHeight
}
this.isShowSkeleton = false
})
.objectFit(ImageFit.Contain)
.objectFit(ImageFit.Fill)
.visibility(this.isShowSkeleton ? Visibility.None : Visibility.Visible)
if (this.contentWidth !== 0) {
Canvas(this.context)
.width('100%')
.height('100%')
.width(px2vp(this.contentWidth))
.height(px2vp(this.contentHeight))
.backgroundColor(Color.Transparent)
.onReady(() => {
})
}
}
.padding({ top:14, right: 10, bottom: 14, left: 10 })
.margin({ left: 10, right: 10 })
.backgroundColor(Color.White)
.width('100%')
.onTouch((event: TouchEvent) => {
... ... @@ -59,6 +68,7 @@ export struct ENewspaperItemComponent {
this.startX = x;
this.startY = y;
let points: number[][] = this.getArea(x, y, this.newspaperListItemBean.items);
console.log("event.points", JSON.stringify(points))
if (points && points.length > 2) {
let path = new Path2D();
path.moveTo(px2vp(points[0][0]), px2vp(points[0][1]));
... ...
... ... @@ -21,8 +21,10 @@ export struct ENewspaperPageComponent {
private windowClass?: window.Window;
private displayTool = display.getDefaultDisplaySync()
private screenWidth: number = 0
private picWidth: number = 0
@State picWidth: number = 0
@State picHeight: number = 0
@Provide itemPicWidth: number = 0
@Provide itemPicHeight: number = 0
@State newspaperListBean: NewspaperListBean = {} as NewspaperListBean
@Provide @Watch('onCurrentPageNumUpdated') currentPageNum: string = '01'
@State pageDialogShow: boolean = false
... ... @@ -131,13 +133,19 @@ export struct ENewspaperPageComponent {
this.screenWidth = this.windowClass?.getWindowProperties()?.windowRect.width
console.log('ENewspaperPageComponent this.screenWidth', this.screenWidth)
// 2000折叠屏 TODO DeviceUtil 方法完善了换判断条件
this.ratio = this.screenWidth > 2000 ? '60%' : '100%'
this.ratio = this.screenWidth > 2000 ? '50%' : '100%'
//获取宽高尺寸
this.picWidth = this.screenWidth - vp2px(52)
// Swiper .margin({ left: 10, right: 10 })
this.picWidth = this.screenWidth - vp2px(20)
let screenHeight = this.displayTool.height;
// bottomSafeHeight 底导高度 topSafeHeight 顶导高度 44 顶部高度 60 底部高度
let height = screenHeight - this.bottomSafeHeight - this.topSafeHeight - vp2px(44) - vp2px(60)
// newspaper_shadow 49 高度 e_newspaper_content 59 margin top
let height = screenHeight - this.bottomSafeHeight - this.topSafeHeight - vp2px(44) - vp2px(60) - vp2px(49) -vp2px(59)
this.picHeight = height
let ratio = this.ratio == '100%' ? 1 : 0.5
this.picWidth = this.picWidth * ratio
this.picHeight = this.picHeight
// 默认日期
const date = new Date()
const month = date.getMonth() + 1
... ... @@ -168,7 +176,10 @@ export struct ENewspaperPageComponent {
this.windowClass?.on('windowSizeChange', () => {
this.screenWidth = this.windowClass?.getWindowProperties()?.windowRect.width || this.displayTool.width
// 2000折叠屏 TODO DeviceUtil 方法完善了换判断条件
this.ratio = this.screenWidth > 2000 ? '60%' : '100%'
this.ratio = this.screenWidth > 2000 ? '50%' : '100%'
let ratio = this.ratio == '100%' ? 1 : 0.5
this.picWidth = this.screenWidth - vp2px(20)
this.picWidth = this.picWidth * ratio
});
}
... ... @@ -248,7 +259,7 @@ export struct ENewspaperPageComponent {
.id('news_skeleton_id')
.width('100%')
.height(px2vp(this.picHeight) + 32)
.margin({ top: 35, left: 10, right: 10 })
.margin({ top: 59, left: 10, right: 10 })
}
if (this.newspaperListBean && this.newspaperListBean.list && this.newspaperListBean.list.length > 0) {
... ... @@ -259,16 +270,15 @@ export struct ENewspaperPageComponent {
}
.itemSpace(10)
.index(this.swiperIndex)
.width(this.ratio)
// newspaper_shadow 44 高度 e_newspaper_content 35 margin top
.height(px2vp(this.picHeight) - 44 - 35)
.width(px2vp(this.picWidth))
.height(px2vp(this.picHeight))
.vertical(true)
.autoPlay(false)
.cachedCount(1)
.indicator(false)
.loop(false)
.displayCount(1)
.margin({ top: 35, left: 10, right: 10 })
.margin({ top: 59, left: 10, right: 10 })
.id('e_newspaper_content')
.alignRules({
top: { anchor: "e_newspaper_top", align: VerticalAlign.Bottom },
... ... @@ -298,6 +308,7 @@ export struct ENewspaperPageComponent {
'滑动查看下一版')
.fontColor(Color.White)
.fontSize($r('app.float.font_size_14'))
.lineHeight(20)
Image($r('app.media.icon_next_page'))
.width($r('app.float.vp_16'))
.height($r('app.float.vp_16'))
... ... @@ -305,7 +316,7 @@ export struct ENewspaperPageComponent {
Visibility.Visible)
}
.justifyContent(FlexAlign.Center)
.margin({ top: $r('app.float.margin_16') })
.margin({ top: 17 })
.alignRules({
top: { anchor: "e_newspaper_shadow", align: VerticalAlign.Bottom },
middle: { anchor: "__container__", align: HorizontalAlign.Center }
... ... @@ -434,10 +445,15 @@ export struct ENewspaperPageComponent {
}
private async getNewspaperList() {
// ENewspaperItemComponent .padding({ top:14, right: 10, bottom: 14, left: 10 })
// 计算图片的内容宽高
let ratio = this.ratio == '100%' ? 1 : 0.6
this.itemPicWidth = this.picWidth * ratio - vp2px(20)
this.itemPicHeight = this.picHeight - vp2px(28)
try {
if (NetworkUtil.isNetConnected()) {
let listBean =
await NewspaperViewModel.getNewspaperList(this.calendarDate, this.picWidth + 'x' + this.picHeight)
await NewspaperViewModel.getNewspaperList(this.calendarDate, this.itemPicWidth + 'x' + this.itemPicHeight)
this.newspaperListBean = listBean;
} else {
this.showToastTip('网络出小差了,请检查网络后重试')
... ...
... ... @@ -116,7 +116,7 @@ export struct Card17Component {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 17,
detailPageType: 9,
contentID: this.contentDTO.objectId,
extra: {
relType: this.contentDTO.relType,
... ...
... ... @@ -21,27 +21,27 @@ import { FollowListDetailItem } from '../../viewmodel/FollowListDetailItem';
import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
import PageModel from '../../viewmodel/PageModel';
import PageAdModel from '../../viewmodel/PageAdvModel';
import PageHelper from '../../viewmodel/PageHelper';
import { PeopleShipAttentionContentListTopComponent } from './PeopleShipAttentionContentListTopComponent'
import { CardParser } from '../CardParser'
import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData';
import PageFollowHelper from '../../viewmodel/PageFollowHelper';
const TAG = 'PeopleShipMainComponent';
/**
* 人民号 --- 关注
*/
@Component
export struct PeopleShipMainComponent {
@State private pageModel: PageModel = new PageModel();
@State private pageAdvModel: PageAdModel = new PageAdModel();
// 自动刷新通知
@Prop @Watch('onAutoRefresh') autoRefresh: number = 0
navIndex: number = 0;
pageId: string = "";
channelId: string = "";
@Link @Watch('onChange') currentTopNavSelectedIndex: number
private scroller: Scroller = new Scroller()
// private scroller: Scroller = new Scroller()
private listScroller: Scroller = new Scroller()
@State rmhList: RmhRecommendDTO[] = []
@Provide rmhSelectedList: string[] = []
@State viewType: ViewType = ViewType.LOADING
... ... @@ -56,7 +56,6 @@ export struct PeopleShipMainComponent {
@State private currentPage: number = 1
@State private isLoading: boolean = false
@State private loadTime: string = ''
// 页面展示监听
@Consume @Watch('onPageShowChange') pageShow: number
@State private pageAttentionChange: boolean = false
... ... @@ -86,7 +85,7 @@ export struct PeopleShipMainComponent {
if (this.followList.length == 0) {
CustomPullToRefresh({
alldata: this.rmhList,
scroller: this.scroller,
scroller: this.listScroller,
hasMore: false,
customList: () => {
this.ListLayout()
... ... @@ -96,7 +95,7 @@ export struct PeopleShipMainComponent {
this.getData(resolve)
},
})
}else {
} else {
CustomPullToRefresh({
alldata: this.attentionList,
scroller: this.listScroller,
... ... @@ -108,19 +107,19 @@ export struct PeopleShipMainComponent {
this.currentPage = 1
this.getData(resolve)
},
onLoadMore:(resolve)=> {
onLoadMore: (resolve) => {
if (this.hasMore === false) {
if(resolve) {
if (resolve) {
resolve('')
}
return
}
if(!this.isLoading && this.hasMore){
if (!this.isLoading && this.hasMore) {
//加载分页数据
this.currentPage++;
this.getAttentionContentListData(resolve)
}else {
if(resolve) {
} else {
if (resolve) {
resolve('')
}
}
... ... @@ -137,14 +136,17 @@ export struct PeopleShipMainComponent {
@Builder
ListLayout() {
Scroll(this.scroller) {
// 推荐人民号
List({ scroller: this.listScroller }) {
// 头部关注列表
ListItem() {
PeopleShipRecommendComponent({
rmhList: this.rmhList,
oneKeyFollow: this.oneKeyFollow,
changeButton: this.changeButton
})
}
}
.edgeEffect(EdgeEffect.None)
.scrollBar(BarState.Off)
.width('100%')
... ... @@ -153,16 +155,21 @@ export struct PeopleShipMainComponent {
@Builder
ListAttentionLayout() {
List({scroller: this.listScroller}){
List({ scroller: this.listScroller }) {
// 头部关注列表
ListItem(){
ListItem() {
PeopleShipAttentionContentListTopComponent({
followList: this.followList
})
}
ForEach(this.attentionList, (item: ContentDTO) => {
ListItem() {
CardParser({compDTO:new CompDTO, contentDTO: item })
Column(){
CardParser({ compDTO: new CompDTO, contentDTO: item })
Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
}.width('100%')
}.width("100%")
.backgroundColor(Color.Transparent)
... ... @@ -193,7 +200,8 @@ export struct PeopleShipMainComponent {
}
onChange() {
if (this.navIndex === this.currentTopNavSelectedIndex && (this.viewType == ViewType.LOADING || this.pageAttentionChange)) {
if (this.navIndex === this.currentTopNavSelectedIndex &&
(this.viewType == ViewType.LOADING || this.pageAttentionChange)) {
this.getData();
}
}
... ... @@ -221,7 +229,6 @@ export struct PeopleShipMainComponent {
this.getRmhRecommendInfo(resolve)
} else {
this.followList = []
// this.followList = followInfo.list
this.followList.push(...followInfo.list)
this.attentionList = []
this.currentPage = 1
... ... @@ -343,7 +350,7 @@ export struct PeopleShipMainComponent {
if (resolve) {
if (this.currentPage == 1 && isTop) {
resolve('已更新至最新')
}else {
} else {
resolve('')
}
}
... ... @@ -357,12 +364,13 @@ export struct PeopleShipMainComponent {
// 说是首页必须要调用
async getInitData() {
Logger.debug('PeopleShipMainComponent', `getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
Logger.debug('PeopleShipMainComponent',
`getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
this.pageModel.pageId = this.pageId;
this.pageModel.groupId = this.pageId;
this.pageModel.channelId = this.channelId;
this.pageModel.currentPage = 1;
PageHelper.getInitData(this.pageModel, this.pageAdvModel)
PageFollowHelper.getInitData(this.pageModel)
}
// 点击一键关注
... ... @@ -388,7 +396,7 @@ export struct PeopleShipMainComponent {
// 获取列表数据
let objects = new AttentionBatchDTO()
this.rmhList.forEach((element: RmhRecommendDTO) => {
if ( this.rmhSelectedList.indexOf(element.creatorId) != -1) {
if (this.rmhSelectedList.indexOf(element.creatorId) != -1) {
const creator = new CreatorDTO(element.userType, element.userId, element.creatorId)
objects.creators.push(creator)
}
... ... @@ -413,7 +421,7 @@ export struct PeopleShipMainComponent {
// 页面展示监听
onPageShowChange() {
if (this.navIndex === this.currentTopNavSelectedIndex && this.pageAttentionChange ) {
if (this.navIndex === this.currentTopNavSelectedIndex && this.pageAttentionChange) {
this.getData()
}
}
... ...
... ... @@ -56,7 +56,6 @@ export struct PeopleShipRecommendComponent {
.width('100%')
.alignSelf(ItemAlign.Start)
.margin({
top: '-50vp',
bottom: '10vp'
})
... ...
... ... @@ -294,11 +294,12 @@ export struct SearchResultContentComponent {
CardParser({compDTO:new CompDTO, contentDTO: item })
}
if (index != this.data.totalCount() - 1) {
Divider()
.width('100%')
.height('1lpx')
.color($r('app.color.color_F5F5F5'))
.strokeWidth('1lpx')
Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
// Divider()
// .width('100%')
// .height('1lpx')
// .color($r('app.color.color_F5F5F5'))
// .strokeWidth('1lpx')
}
}
}
... ...
import { CompDTO, ContentDTO, InteractDataDTO, LiveReviewDTO, LiveRoomDataBean, PageDTO, PageInfoDTO } from 'wdBean';
import { CompStyle, ViewType } from 'wdConstant/Index';
import { CollectionUtils, DateTimeUtils, LazyDataSource, Logger, NetworkUtil, StringUtils, ToastUtils } from 'wdKit';
import { closeRefresh } from '../utils/PullDownRefresh';
import PageModel from './PageModel';
import PageViewModel from './PageViewModel';
import { promptAction } from '@kit.ArkUI';
import { CompAdvBean } from 'wdBean/src/main/ets/bean/adv/AdvsRuleBean';
import PageAdModel from './PageAdvModel';
import { ArrayList } from '@kit.ArkTS';
import { WDViewDefaultType } from '../components/view/EmptyComponent';
import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean';
import { BaseDTO } from 'wdBean/src/main/ets/bean/component/BaseDTO';
import { viewBlogInsightIntentShare, ActionMode } from '../utils/InsightIntentShare'
import { common } from '@kit.AbilityKit';
import { CacheData } from 'wdNetwork/Index';
import { closeLoadMore } from '../utils/PullUpLoadMore';
const TAG = 'PageHelper';
/**
* 处理返回后的数据
*/
export class PageFollowHelper {
private refreshUIEnd(pageModel: PageModel, isRefreshSuccess: boolean) {
if (pageModel.loadStrategy != 2) {
return
}
closeRefresh(pageModel, isRefreshSuccess)
}
/**
* 进页面请求数据
*/
async getInitData(pageModel: PageModel) {
pageModel.loadStrategy = 1
let netStatus = NetworkUtil.isNetConnected()
if (netStatus) {
this.getPageInfo(pageModel)
} else if (pageModel.compList.size() > 0) {
// 加载缓存数据了,不用无网络提示
} else {
pageModel.viewType = ViewType.EMPTY;
pageModel.emptyType = WDViewDefaultType.WDViewDefaultType_NoNetwork;
}
}
getPageInfo(pageModel: PageModel) {
pageModel.currentPage = 1;
Logger.debug(TAG, 'getPageInfo')
PageViewModel.getPageInfo(pageModel.pageId).then(pageInfo => {
Logger.debug(TAG, 'getPageInfo back: ' + JSON.stringify(pageInfo))
if (pageInfo == null) {
pageModel.viewType = ViewType.EMPTY;
pageModel.emptyType = WDViewDefaultType.WDViewDefaultType_NoContent1;
return;
}
pageModel.pageInfo = pageInfo;
Logger.debug(TAG, 'getPageInfo go on')
}).catch(() => {
this.refreshUIEnd(pageModel, false)
if (this.isPageLoaded(pageModel)) {
return
}
pageModel.viewType = ViewType.EMPTY;
pageModel.emptyType = WDViewDefaultType.WDViewDefaultType_ContentFailed;
})
}
private isPageLoaded(pageModel: PageModel) {
if (pageModel.compList.size() > 0) {
return true
}
return false
}
}
let pageHelper = new PageFollowHelper();
export default pageHelper as PageFollowHelper;
\ No newline at end of file
... ...
... ... @@ -4,7 +4,7 @@ import { ContentType } from 'wdRouter/Index';
export class DeepLinkUtil {
private static DEEP_LINK_PREFIX = "rmrbapp:rmrb.app/openwith"
private static DEEP_LINK_PREFIX = "rmrbapp://rmrb.app/openwith"
static generateDeepLinkWithConent(content: ContentDetailDTO): string {
... ... @@ -23,7 +23,7 @@ export class DeepLinkUtil {
private static generate(contentType: number, contentId?: string, relId?: string, link?: string): string {
let deeplink = DeepLinkUtil.DEEP_LINK_PREFIX
let pubParam = `&contentId=${contentId}}&relId=${relId}&skipType=1`
let pubParam = `&contentId=${contentId}&relId=${relId}&skipType=1`
let type: ContentType = Number(contentType)
switch (type) {
... ... @@ -38,7 +38,7 @@ export class DeepLinkUtil {
deeplink += "?type=article&subType=h5"
deeplink += "&url=" + encodeURIComponent(link)
} else {
deeplink += "type=article&subType=h5_template_article"
deeplink += "?type=article&subType=h5_template_article"
}
break
case ContentType.DynamicImageText:
... ...
import { formBindingData, FormExtensionAbility, formInfo, formProvider } from '@kit.FormKit';
import { Want } from '@kit.AbilityKit';
import { Logger, NetworkManager, SPHelper, StringUtils } from 'wdKit/Index';
import { FileUtils, Logger, NetworkManager, SPHelper, StringUtils } from 'wdKit/Index';
import { BusinessError } from '@kit.BasicServicesKit';
import { FormDataType, NewspaperDataFetcher } from './NewspaperDataFetcher';
import { NewspaperDataFetcher } from './NewspaperDataFetcher';
import { JSON } from '@kit.ArkTS';
import { FormNewspaperPaperType } from '../dailynewspaperwidget/common/NewspaperWidgetData';
import { FormNewspaperData, FormNewspaperPaperType } from '../dailynewspaperwidget/common/NewspaperWidgetData';
import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index';
import fs from '@ohos.file.fs';
const TAG = "DailyNewspaperFormAbility"
export default class DailyNewspaperFormAbility extends FormExtensionAbility {
lastDatas: Record<string, FormNewspaperData> = {}
onAddForm(want: Want) {
Logger.debug(TAG, "onAddForm with " + JSON.stringify(want))
... ... @@ -20,18 +23,11 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
let isTempCard = want.parameters[formInfo.FormParam.TEMPORARY_KEY] as boolean
if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化
Logger.debug(TAG, "开始刷新数据");
NewspaperDataFetcher.refreshDailyPaper().then((data) => {
let formData = formBindingData.createFormBindingData(data);
formProvider.updateForm(formId, formData).catch((err: BusinessError) => {
Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
});
})
this.fetchAndRefreshData(formId)
}
}
let obj: FormDataType = {}
let obj: FormNewspaperData = {} as FormNewspaperData
obj.paperType = FormNewspaperPaperType.unknown
let formData = formBindingData.createFormBindingData(obj);
return formData;
... ... @@ -45,13 +41,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
onUpdateForm(formId: string) {
// 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
Logger.debug(TAG, 'onUpdateForm ' + formId);
NewspaperDataFetcher.refreshDailyPaper().then((data) => {
let formData = formBindingData.createFormBindingData(data);
formProvider.updateForm(formId, formData).catch((err: BusinessError) => {
Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
});
})
this.initApp()
this.fetchAndRefreshData(formId)
}
onFormEvent(formId: string, message: string) {
... ... @@ -61,7 +53,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
onRemoveForm(formId: string) {
// 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
Logger.debug(TAG, 'onRemoveForm');
Logger.debug(TAG, 'onRemoveForm / formId: ' + formId);
let data = this.lastDatas[formId]
NewspaperDataFetcher.closeFilesWith(data)
}
// onConfigurationUpdate(config: Configuration) {
... ... @@ -75,6 +69,32 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
return formInfo.FormState.READY;
}
fetchAndRefreshData(formId: string) {
Logger.debug(TAG, "开始刷新数据");
NewspaperDataFetcher.refreshDailyPaper().then(async (data) => {
let formData = formBindingData.createFormBindingData(data);
formProvider.updateForm(formId, formData).then(() => {
this.lastDatas[formId] = data
}).catch((err: BusinessError) => {
Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
});
let fileDir = this.context.getApplicationContext().filesDir + "/widget-daily-newspaper"
await FileUtils.makeDirIfNotExsit(fileDir)
NewspaperDataFetcher.dealWithPictures(data, formId, fileDir, (data) => {
Logger.debug(TAG, `refresh ui with new pictuers`);
let formData = formBindingData.createFormBindingData(data);
formProvider.updateForm(formId, formData).then(() => {
this.lastDatas[formId] = data
}).catch((err: BusinessError) => {
Logger.error(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
});
})
})
}
initApp() {
// KV存储
SPHelper.init(this.context);
... ...
import { CompInfoBean, ContentDTO, PageInfoBean } from 'wdBean/Index';
import { MorningEveningViewModel } from 'wdComponent/Index';
import { Logger } from 'wdKit/Index';
import { CrptoUtils, FileUtils, Logger } from 'wdKit/Index';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork/Index';
import { DeepLinkUtil } from 'wdShare/Index'
import { FormNewspaperPaperType, FormNewspaperPaperInfo, FormNewspaperPaperContent } from "../dailynewspaperwidget/common/NewspaperWidgetData"
import { FormNewspaperPaperType, FormNewspaperPaperInfo, FormNewspaperPaperContent,
FormNewspaperData } from "../dailynewspaperwidget/common/NewspaperWidgetData"
import { http } from '@kit.NetworkKit';
import fs from '@ohos.file.fs';
import { BusinessError } from '@kit.BasicServicesKit';
import { JSON } from '@kit.ArkTS';
const TAG = "NewspaperDataFetcher"
export type FormDataType = Record<string, FormNewspaperPaperType | FormNewspaperPaperInfo | FormNewspaperPaperContent[]>
// export type FormDataType = Record<string, FormNewspaperPaperType | FormNewspaperPaperInfo | FormNewspaperPaperContent[]>
export class NewspaperDataFetcher {
public static async refreshDailyPaper(): Promise<FormDataType> {
return new Promise<FormDataType>(async (reslove, fail) => {
public static async refreshDailyPaper(): Promise<FormNewspaperData> {
return new Promise<FormNewspaperData>(async (reslove, fail) => {
let data: FormDataType = { 'paperType': FormNewspaperPaperType.unknown }
let data: FormNewspaperData = new FormNewspaperData()
data.paperInfo = { showLeftImage: false }
try {
let page: PageInfoBean = await MorningEveningViewModel.getDailyPaperTopic()
data.paperType = page.topicInfo?.frontFlag || FormNewspaperPaperType.unknown
data.paperType = page.topicInfo?.topicPattern || FormNewspaperPaperType.unknown
let currentTime = new Date().getTime()
let compInfo = await MorningEveningViewModel.getMorningEveningCompInfo(
... ... @@ -29,7 +34,7 @@ export class NewspaperDataFetcher {
page.topicInfo?.topicId
)
if (page.topicInfo.frontLinkObject) {
if (page.topicInfo?.frontFlag && page.topicInfo.frontLinkObject) {
data.paperInfo.showLeftImage = true
data.paperInfo.leftImageUrl = page.topicInfo.frontLinkObject.coverUrl
data.paperInfo.leftTitle = page.topicInfo.frontLinkObject.title
... ... @@ -60,7 +65,7 @@ export class NewspaperDataFetcher {
})
}
static fakeData(): FormDataType {
static fakeData(): FormNewspaperData {
let data : FormNewspaperPaperContent = {
title: "标题标题标题标题标题标题标题标题",
coverUrl: "https://"
... ... @@ -72,6 +77,135 @@ export class NewspaperDataFetcher {
leftTitle: "leftTitleleftTitleleftTitleleftTitleleftTitleleftTitle"
},
"paperContents": [data, data, data]
} as FormNewspaperData
}
static dealWithPictures(data: FormNewspaperData, formId: string ,tempDir: string, refreshCallback:(data: FormNewspaperData) => void) {
let donwloadCount = data.paperContents.filter((value) => {
return value.coverUrl && value.coverUrl.length > 0
}).length
let fileFDs: Record<string, string | number> = {};
if (data.paperInfo.leftImageUrl) {
donwloadCount += 1
CrptoUtils.md5(data.paperInfo.leftImageUrl).then((md5String) => {
const fileName = formId + "file" + md5String;
const filePath = tempDir + "/" + fileName
NewspaperDataFetcher.downloadUrlToPath(data.paperInfo.leftImageUrl!, filePath).then(() => {
let file = fs.openSync(filePath)
fileFDs[fileName] = file.fd
data.paperInfo.localLeftImageFileName = fileName
data.formImages = fileFDs
if (--donwloadCount == 0) { refreshCallback(data) }
}).catch((e : BusinessError) => {
Logger.debug(TAG, "download file failed.");
if (--donwloadCount == 0) { refreshCallback(data) }
})
}).catch((e: BusinessError) => {
if (--donwloadCount == 0) { refreshCallback(data) }
})
}
for (let index = 0; index < data.paperContents.length; index++) {
const content = data.paperContents[index];
if (!content.coverUrl || content.coverUrl.length == 0) {
continue
}
CrptoUtils.md5(content.coverUrl).then((md5String) => {
const fileName = formId + "file" + md5String;
const filePath = tempDir + "/" + fileName
NewspaperDataFetcher.downloadUrlToPath(content.coverUrl!, filePath).then(() => {
Logger.debug(TAG, "open file for display ");
let file = fs.openSync(filePath)
fileFDs[fileName] = file.fd
data.paperContents[index].localCoverFileName = fileName
data.formImages = fileFDs
if (--donwloadCount == 0) { refreshCallback(data) }
}).catch((e : BusinessError) => {
Logger.debug(TAG, "download file failed." + JSON.stringify(e));
if (--donwloadCount == 0) { refreshCallback(data) }
})
}).catch((e: BusinessError) => {
if (--donwloadCount == 0) { refreshCallback(data) }
})
}
}
static closeFilesWith(data?: FormNewspaperData) {
if (data && data.formImages) {
for (const obj of Object.entries(data.formImages)) {
const fileName = obj[0]
let fd: number = obj[1] as number
fs.close(fd)
}
}
}
static downloadUrlToPath(url: string, toFilePath: string): Promise<void> {
Logger.debug(TAG, "will donwload url:" + url + " ======> " + toFilePath);
return new Promise((reslove, fail) => {
FileUtils.fileExsit(toFilePath).then((exsit: boolean) => {
if (exsit) {
Logger.debug(TAG, "file is exsit. " + toFilePath);
reslove()
return
}
NewspaperDataFetcher.downloadUrlToPathWithout(url, toFilePath).then(() => {
reslove()
}).catch((e: BusinessError) => {
fail(e)
})
}).catch((e: BusinessError) => {
NewspaperDataFetcher.downloadUrlToPathWithout(url, toFilePath).then(() => {
reslove()
}).catch((e: BusinessError) => {
fail(e)
})
})
})
}
static downloadUrlToPathWithout(url: string, toFilePath: string): Promise<void> {
Logger.debug(TAG, "will donwload url:" + url + " ======> " + toFilePath);
return new Promise((reslove, fail) => {
let httpRequest = http.createHttp()
httpRequest.request(url, (err, data) => {
if (!err && data.responseCode == http.ResponseCode.OK) {
let imgFile = fs.openSync(toFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
let wroteLength = 0
fs.write(imgFile.fd, data.result as ArrayBuffer).then((writeLen: number) => {
Logger.debug(TAG, "write data to file succeed and size is:" + writeLen);
wroteLength = writeLen
}).catch((err: BusinessError) => {
Logger.error(TAG, "write data to file failed with error message: " + err.message + ", error code: " + err.code);
}).finally(() => {
fs.closeSync(imgFile);
httpRequest.destroy()
wroteLength > 0 ? reslove() : fail("failed")
});
return
}
httpRequest.destroy()
fail("failed")
});
})
}
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,8 @@ export class FormNewspaperPaperInfo {
showLeftImage: boolean = false
leftImageUrl?: string
localLeftImageFileName?: ResourceStr // 传递图片用
localLeftImageFileFD? : number // 传递图片用
leftTitle?: string
leftDeepLink?: string
... ... @@ -20,5 +22,15 @@ export class FormNewspaperPaperInfo {
export class FormNewspaperPaperContent {
title: string = ""
coverUrl?: string
localCoverFileName?: ResourceStr // 传递图片用
localCoverFileFD? : number // 传递图片用
deepLink: string = ""
}
export class FormNewspaperData {
paperType: FormNewspaperPaperType = FormNewspaperPaperType.unknown
paperInfo: FormNewspaperPaperInfo = {} as FormNewspaperPaperInfo
paperContents: FormNewspaperPaperContent[] = []
formImages: Record<string, string | number> = {}
}
\ No newline at end of file
... ...
... ... @@ -43,8 +43,8 @@ struct DailyNewspaperWidgetCard {
@Builder leftImageView() {
Stack({ alignContent: Alignment.Bottom }) {
Image(this.paperInfo.leftImageUrl)
// Image($r("app.media.desktop_card_comp_place_holder_16_9"))
Image("memory://" + this.paperInfo.localLeftImageFileName)
// Image(this.paperInfo.leftImageUrl)
.alt($r("app.media.desktop_card_comp_place_holder_16_9"))
.objectFit(ImageFit.Cover)
.aspectRatio(87/116)
... ... @@ -109,8 +109,8 @@ struct ContentCellView {
bottom: this.hasImage ? 0 : 6})
if (this.hasImage) {
Image(this.content.coverUrl)
// Image($r("app.media.desktop_card_comp_place_holder_3_4"))
Image("memory://" + this.content.localCoverFileName)
// Image(this.content.coverUrl)
.alt($r("app.media.desktop_card_comp_place_holder_3_4"))
.objectFit(ImageFit.Cover)
.height(40)
... ... @@ -151,14 +151,12 @@ function jumpWithDeepLink(deepLink: string, component: Object) {
if (deepLink.length == 0) {
return
}
const deepLinkKey: string = NewspaperWidgetCommon.JumpParam.DeepLinkKey
const fromDailyNewspaperKey: string = NewspaperWidgetCommon.JumpParam.FromNewspaperWidgetKey
postCardAction(component, {
action: NewspaperWidgetCommon.PosterCardAction.ActionRouter,
abilityName: NewspaperWidgetCommon.PosterCardAction.MainAbilityName,
params: {
deepLinkKey: deepLink,
fromDailyNewspaperKey: true
"newspaper.widget.jump.deeplink": deepLink,
"newspaper.widget.jump.fromNewspaperWidget": 1
}
});
}
\ No newline at end of file
... ...
... ... @@ -53,7 +53,7 @@ export struct BottomNavigationComponent {
// 自动刷新触发(双击tab自动刷新)
@State autoRefresh: number = 0
// 顶导数据,从接口获取 TODO 顶导业务逻辑没看懂,暂时不替换顶导list。频道管理数据待梳理
@State topNavMap: Record<string, TopNavDTO[]> = {}
// @State topNavMap: Record<string, TopNavDTO[]> = {}
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`);
... ...
... ... @@ -12,13 +12,14 @@ import { DeviceUtil,
UmengStats } from 'wdKit/Index'
import { LoginModule } from 'wdLogin/Index'
import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index'
import { registerRouter } from 'wdRouter/Index'
import { AppInnerLink, registerRouter } from 'wdRouter/Index'
import { TrackingModule } from 'wdTracking/Index'
import { JSON } from '@kit.ArkTS'
import app from '@system.app'
import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index'
import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife'
import { webview } from '@kit.ArkWeb'
import { NewspaperWidgetCommon } from '../dailynewspaperwidget/common/NewspaperWidgetCommon'
const TAG = "[StartupManager]"
... ... @@ -26,6 +27,7 @@ const TAG = "[StartupManager]"
export class StartupManager {
private context?: common.UIAbilityContext
private lastStartupWant?: Want
private constructor() {
}
... ... @@ -74,10 +76,14 @@ export class StartupManager {
// 通知栏点击后启动
GetuiPush.sharedInstance().onWant(want)
Logger.debug(TAG, "App onCreate: finised")
this.lastStartupWant = want
}
appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
GetuiPush.sharedInstance().onNewWant(want)
this.dealWithDeepLink(want)
}
appOnDestory() {
... ... @@ -124,6 +130,10 @@ export class StartupManager {
//TODO:
// 提前初始化webview
webview.WebviewController.initializeWebEngine()
if (this.lastStartupWant && this.dealWithDeepLink(this.lastStartupWant)) {
this.lastStartupWant = undefined
}
resolve()
})
}
... ... @@ -195,4 +205,20 @@ export class StartupManager {
private initOthers() {
}
private dealWithDeepLink(want: Want): boolean {
if (!want.parameters) {
return false
}
let deepLink = want.parameters[NewspaperWidgetCommon.JumpParam.DeepLinkKey] as string
if (deepLink && deepLink.length) {
AppInnerLink.jumpWithLink(deepLink)
return true
}
return false
}
}
... ...
... ... @@ -14,8 +14,8 @@
"isDynamic": true,
"isDefault": true,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"scheduledUpdateTime": "18:26",
"updateDuration": 4,
"defaultDimension": "2*4",
"supportDimensions": [
"2*4"
... ...