张善主

Merge remote-tracking branch 'origin/main'

Showing 24 changed files with 138 additions and 126 deletions
... ... @@ -34,6 +34,8 @@ export class SpConstants{
//定位相关
static LOCATION_CITY_NAME = "location_city_name" //定位
static LOCATION_CITY_CODE = "location_city_code" //定位
static LOCATION_PROVINCE_CODE = "location_province_code" //定位,省份code
static LOCATION_DISTRICT_CODE = "location_district_code" //定位,区县,返回9位,如:合肥-瑶海区-310115114
static LOCATION_PERMISSION_REFUSE = "location_permission_refuse" //定位
//启动页数据存储key
... ...
import data_preferences from '@ohos.data.preferences';
import { Logger } from './Logger';
const TAG = 'SPHelper'
/**
* sp存储
*
* 单例模式
* TODO 新增内存存储,避免频繁sp获取
*/
// SPHelper.default.get("key1", "defValue1").then((value1) => {
// this.message = value1.toString();
// })
// let value2: string = await SPHelper.default.get("key2", "defValue2");
// this.message = result;
export class SPHelper {
private static context: Context;
private static spFilename: string = '__SPHelper';
... ... @@ -51,7 +45,11 @@ export class SPHelper {
saveSync(key: string, value: data_preferences.ValueType) {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
preferences.putSync(key, value)
preferences.flush() // todo:Asynchronously
preferences.flush().then(() => {
Logger.debug(TAG, 'saveSync flush success')
}).catch((error: object) => {
Logger.debug(TAG, 'saveSync flush failed: ' + JSON.stringify(error))
});
}
async get(key: string, defValue: data_preferences.ValueType): Promise<data_preferences.ValueType> {
... ... @@ -86,7 +84,11 @@ export class SPHelper {
deleteSync(key: string) {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
preferences.deleteSync(key)
preferences.flush(); // todo:Asynchronously
preferences.flush().then(() => {
Logger.debug(TAG, 'deleteSync flush success')
}).catch((error: object) => {
Logger.debug(TAG, 'deleteSync flush failed: ' + JSON.stringify(error))
});
}
async clearSync() {
... ... @@ -98,12 +100,6 @@ export class SPHelper {
});
}
// clearSync() {
// let preferences: data_preferences.Preferences = this.getVideoPreferencesSync()
// preferences.clearSync()
// preferences.flush()
// }
public getPreferences() {
let preferences = data_preferences.getPreferences(SPHelper.context, SPHelper.spFilename);
return preferences;
... ...
... ... @@ -25,15 +25,14 @@ export class HttpParams {
headers['imei'] = DeviceUtil.clientId()
headers['Accept-Language'] = 'zh'
headers['timestamp'] = DateTimeUtils.getTimeStamp() + ''
headers['mpassid'] = 'ZbHTMeTsfaYDAHqt8ZHIzcPs'
HttpParams.setLocationHeader(headers)
// // TODO 判断是否登录
headers['RMRB-X-TOKEN'] = HttpUtils.getXToken()
if (HttpUtils.getXToken() != '') {
headers['cookie'] = 'RMRB-X-TOKEN=' + HttpUtils.getXToken()
}
if (HttpUtils.isLogin()) {
headers['RMRB-X-TOKEN'] = HttpUtils.getUserToken()
headers['cookie'] = 'RMRB-X-TOKEN=' + HttpUtils.getUserToken()
headers['userId'] = HttpUtils.getUserId()
headers['userType'] = HttpUtils.getUserType()
headers['mpassid'] = 'ZbHTMeTsfaYDAHqt8ZHIzcPs'
}
HttpParams.addSpecialHeaders(headers);
return headers;
}
... ...
... ... @@ -46,10 +46,6 @@ export class HttpUrlUtils {
*/
static readonly INTERACT_EXECUTELIKE: string = "/api/rmrb-interact/interact/zh/c/like/executeLike";
/**
* 收藏、取消收藏
*/
static readonly INTERACT_EXECUTECOLLECTRECORD: string = "/api/rmrb-interact/interact/zh/c/collect/executeCollcetRecord";
/**
* 关注号主
*/
static readonly INTERACT_ACCENTION_OPERATION: string = "/api/rmrb-interact/interact/zh/c/attention/operation";
... ...
import { SpConstants } from 'wdConstant/Index';
import { DeviceUtil, SPHelper, StringUtils } from 'wdKit/Index';
import { HttpParams } from '../http/HttpCommonParams';
import { HttpRequest } from '../http/HttpRequest';
const TAG: string = '[HttpUtils]'
... ... @@ -9,27 +8,6 @@ const TAG: string = '[HttpUtils]'
* http相关工具类,对外暴露
*/
export class HttpUtils {
private static userId = ''
private static userType = ''
private static token = ''
/**
* 添加公共参数,如登录后,添加登录信息
*/
static addCommonHeader() {
HttpRequest.addGlobalHeaderProvider(() => {
let headers: Record<string, string> = {};
return headers;
})
}
/**
* 添加公共参数,如登出后,移除登录信息
*/
static removeCommonHeader() {
}
static getRefreshToken() {
let refreshToken = SPHelper.default.getSync(SpConstants.USER_REFRESH_TOKEN, "")
if (StringUtils.isNotEmpty(refreshToken)) {
... ... @@ -49,25 +27,27 @@ export class HttpUtils {
* 定位,城市code
*/
public static getCityCode(): string {
// TODO
// 城市编码
return '340100';
return SPHelper.default.getSync(SpConstants.LOCATION_CITY_CODE, '') as string
}
/**
* 定位,省份code
*/
public static getProvinceCode(): string {
// TODO
return '340000';
return SPHelper.default.getSync(SpConstants.LOCATION_PROVINCE_CODE, '') as string
}
/**
* 定位,地区code
*/
public static getDistrictCode(): string {
// TODO
return '340103';
let districtCode = SPHelper.default.getSync(SpConstants.LOCATION_DISTRICT_CODE, '') as string
if (districtCode === '') {
return districtCode
}
// 截取前6位,如返回310115114,需要310115 (上海浦东)
return districtCode.substring(0, 6);
}
public static getImei(): string {
... ... @@ -75,43 +55,22 @@ export class HttpUtils {
}
public static getUserId(): string {
// TODO 对接登录
if (StringUtils.isNotEmpty(HttpUtils.userId)) {
return HttpUtils.userId
}
HttpUtils.userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
return HttpUtils.userId;
return SPHelper.default.getSync(SpConstants.USER_ID, "") as string
}
public static getUserType(): string {
if (StringUtils.isNotEmpty(HttpUtils.userType)) {
return HttpUtils.userType
}
HttpUtils.userType = SPHelper.default.getSync(SpConstants.USER_Type, "") as string
return HttpUtils.userType;
return SPHelper.default.getSync(SpConstants.USER_Type, "") as string
}
static getXToken(): string {
if (StringUtils.isNotEmpty(HttpUtils.token)) {
return HttpUtils.token
}
HttpUtils.token = SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN, "") as string
if (StringUtils.isNotEmpty(HttpUtils.token)) {
return HttpUtils.token
}
return ''
}
public static setUserId(userId: string) {
// TODO 优化赋值
HttpUtils.userId = userId;
static getUserToken(): string {
return SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN, "") as string
}
public static setUserType(userType: string) {
HttpUtils.userType = userType;
public static isLogin(): boolean {
let token = HttpUtils.getUserToken()
if (token == null || token == undefined || token.length <= 0) {
return false
}
public static setUserToken(token: string) {
HttpUtils.token = token;
return true
}
}
\ No newline at end of file
... ...
... ... @@ -2,11 +2,11 @@
* 批查接口查询互动相关数据,返回数据bean
*/
export interface InteractDataDTO {
collectNum: number | String;
commentNum: number | String;
collectNum: number | string;
commentNum: number | string;
contentId: string;
contentType: number;
likeNum: number | String;
likeNum: number | string;
readNum: number;
shareNum: number;
}
\ No newline at end of file
... ...
... ... @@ -38,7 +38,7 @@ export struct ImageAndTextPageComponent {
@State interactData: InteractDataDTO = {} as InteractDataDTO
@State isPageEnd: boolean = false
@State publishTime: string = ''
@State publishCommentModel: publishCommentModel = {} as publishCommentModel
@State publishCommentModel: publishCommentModel = new publishCommentModel()
build() {
Column() {
... ... @@ -142,7 +142,10 @@ export struct ImageAndTextPageComponent {
//底部交互区
if (this.contentDetailData?.length) {
OperRowListView({ contentDetailData: this.contentDetailData[0] })
OperRowListView({
contentDetailData: this.contentDetailData[0],
publishCommentModel: this.publishCommentModel
})
}
}
... ...
... ... @@ -152,6 +152,8 @@ export struct MorningEveningPaperComponent {
if (imageSource) {
this.pickColor(imageSource)
} else {
this.mixedBgColor = this.pageInfoBean.backgroundColor
}
}
... ...
... ... @@ -3,10 +3,12 @@
*/
import { RmhInfoDTO } from 'wdBean'
import { CommonConstants } from 'wdConstant/Index';
import { DateTimeUtils } from 'wdKit';
@Component
export struct RmhTitle {
@Prop rmhInfo: RmhInfoDTO
@Prop publishTime: string | undefined
build() {
Flex() {
... ... @@ -29,6 +31,15 @@ export struct RmhTitle {
.fontColor($r('app.color.color_222222'))
.fontWeight(600)
.alignSelf(ItemAlign.Start)
Row() {
if (this.publishTime) {
Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.publishTime)))
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
Image($r('app.media.point'))
.width(16)
.height(16)
}
Text(this.rmhInfo.rmhDesc)
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
... ... @@ -36,6 +47,7 @@ export struct RmhTitle {
.alignSelf(ItemAlign.Start)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
}
Blank()
if (this.rmhInfo.cnIsAttention) {
... ...
... ... @@ -20,7 +20,7 @@ export struct Card12Component {
Column() {
// rmh信息
if (this.contentDTO.rmhInfo) {
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
}
// 标题
if (this.contentDTO.newsTitle) {
... ...
... ... @@ -52,7 +52,7 @@ export struct Card14Component {
Column() {
// rmh信息
if (this.contentDTO.rmhInfo) {
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
}
// 左标题,右图
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween }) {
... ...
... ... @@ -58,7 +58,7 @@ export struct Card15Component {
build() {
Column() {
// rmh信息
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
//新闻标题
if (this.contentDTO.newsTitle) {
Text(this.contentDTO.newsTitle)
... ...
... ... @@ -25,7 +25,7 @@ export struct Card16Component {
Column() {
// rmh信息
if (this.contentDTO.rmhInfo) {
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
}
// 标题
if (this.contentDTO.newsTitle) {
... ...
... ... @@ -77,7 +77,7 @@ export struct Card19Component {
build() {
Column() {
// rmh信息
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
// 标题
if (this.contentDTO.newsTitle) {
Text(this.contentDTO.newsTitle)
... ...
... ... @@ -50,7 +50,7 @@ export struct Card20Component {
build() {
Column() {
// rmh信息
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
// 标题
if (this.contentDTO.newsTitle) {
Text(this.contentDTO.newsTitle)
... ...
... ... @@ -16,7 +16,7 @@ export struct Card21Component {
build() {
Column() {
// 顶部 rmh信息
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo })
RmhTitle({ rmhInfo: this.contentDTO.rmhInfo, publishTime: this.contentDTO.publishTime })
// 中间内容
Grid() {
GridItem() {
... ...
... ... @@ -6,7 +6,7 @@ import { ProcessUtils } from 'wdRouter';
import { HttpUtils } from 'wdNetwork/Index';
/**
* 小视频横划
* 直播预约
* Zh_Single_Row-02
*/
const TAG = 'Zh_Single_Row-03'
... ... @@ -42,7 +42,7 @@ export struct ZhSingleRow03 {
Row() {
Flex({justifyContent: FlexAlign.SpaceBetween}){
Row() {
Text(item.liveInfo.liveStartTime.split(' ')[0].slice(5))
Text(item.liveInfo.liveStartTime.split(' ')[0].slice(5).split('-').join('月')+'日')
.margin({right: 6})
.fontColor(0x000000)
.fontSize(13)
... ...
... ... @@ -390,6 +390,33 @@ export struct PaperSingleColumn999CardView {
private item: ContentDTO = {} as ContentDTO;
private index: number = -1;
getPublishTime(): string {
const publishTimestamp = parseInt(this.item?.publishTime)
const currentTime = Date.now(); // 当前时间戳
// 计算差异
const timeDifference = currentTime - publishTimestamp;
// 转换为分钟、小时和天
const minutes = Math.floor(timeDifference / (1000 * 60));
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
// 根据时间差返回对应的字符串
let result: string;
if (minutes < 60) {
result = `${minutes}分钟前`;
} else if (hours < 24) {
result = `${hours}小时前`;
} else {
result = `${days}天前`;
}
console.log(result);
return result
}
build() {
Column() {
Text(this.item?.newsTitle)
... ... @@ -429,14 +456,33 @@ export struct PaperSingleColumn999CardView {
}
if (this.item?.visitorComment) {
Row() {
Text(this.item?.visitorComment + "评")
Row() {
Text(this.item?.source)
.fontSize(12)
.fontColor(Color.Gray)
.margin({ left: 22 })
Image($r('app.media.point'))
.width(16)
.height(16)
.margin({ top: 10, bottom: 10 })
Text(this.getPublishTime())
.fontSize(12)
.fontColor(Color.Gray)
Text(this.item?.visitorComment + "评")
.fontSize(12)
.fontColor(Color.Gray)
.margin({ left: 6 })
}
.justifyContent(FlexAlign.Start)
Image($r('app.media.icon_forward'))
.width(16)
.height(16)
.margin({ left: 10, right: 22, top: 10, bottom: 10 })
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
right: { anchor: '__container__', align: HorizontalAlign.End }
})
}.width(CommonConstants.FULL_PARENT)
.justifyContent(FlexAlign.SpaceBetween)
}
... ...
... ... @@ -40,11 +40,11 @@ const TAG = 'OperRowListView';
export struct OperRowListView {
@Prop contentDetailData: ContentDetailDTO // 稿件详情
@State operationButtonList: string[] = ['comment', 'like', 'collect', 'share'] // 组件展示条件
@Prop publishCommentModel: publishCommentModel
// @State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
@State interactData: InteractDataDTO = {} as InteractDataDTO
@State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
@State likeBean: Record<string, string> = {}
@State publishCommentModel: publishCommentModel = new publishCommentModel()
async aboutToAppear() {
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
... ... @@ -62,13 +62,13 @@ export struct OperRowListView {
console.info(TAG, 'contentDetailData----', JSON.stringify(this.contentDetailData))
console.info(TAG, 'likeBean----', JSON.stringify(this.likeBean))
// 评论需要数据
this.publishCommentModel.targetId = this.contentDetailData.newsId + ''
/* this.publishCommentModel.targetId = this.contentDetailData.newsId + ''
this.publishCommentModel.targetRelId = this.contentDetailData.reLInfo?.relId + ''
this.publishCommentModel.targetTitle = this.contentDetailData.newsTitle + ''
this.publishCommentModel.targetRelType = this.contentDetailData.reLInfo?.relType + ''
this.publishCommentModel.targetRelObjectId = this.contentDetailData.reLInfo?.relObjectId + ''
this.publishCommentModel.keyArticle = this.contentDetailData.keyArticle + ''
this.publishCommentModel.targetType = this.contentDetailData.newsType + ''
this.publishCommentModel.targetType = this.contentDetailData.newsType + ''*/
}
build() {
... ... @@ -232,7 +232,6 @@ export struct OperRowListView {
}
PageRepository.postExecuteCollectRecord(params).then(res => {
// console.log(TAG, '收藏、取消收藏', 'toggleLikeStatus==',)
if (this.newsStatusOfUser) {
this.newsStatusOfUser.collectStatus = this.newsStatusOfUser?.collectStatus === 1 ? 0 : 1
this.queryContentInteractCount()
... ... @@ -258,8 +257,10 @@ export struct OperRowListView {
this.interactData.collectNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.collectNum)
this.interactData.commentNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.commentNum)
// 评论组件需要数据
if (Number.parseInt(this.interactData.commentNum) > Number.parseInt(this.publishCommentModel.totalCommentNumer)) {
this.publishCommentModel.totalCommentNumer = this.interactData.commentNum + '' || '0'
}
}
// console.log(TAG, '获取互动点赞等数据===', JSON.stringify(res))
console.log(TAG, 'this.interactData', JSON.stringify(this.interactData))
})
... ...
... ... @@ -283,7 +283,7 @@ export class PageRepository {
* @returns
*/
static postExecuteCollectRecord(params: postExecuteCollectRecordParams): Promise<ResponseDTO> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_EXECUTECOLLECTRECORD
let url = HttpUrlUtils.getExecuteCollcetUrl()
return WDHttp.post(url, params)
}
... ...
... ... @@ -29,9 +29,6 @@ export class LogoutViewModel{
SPHelper.default.saveSync(SpConstants.USER_Type, '')
SPHelper.default.saveSync(SpConstants.USER_NAME, '')
SPHelper.default.saveSync(SpConstants.USER_PHONE, '')
HttpUtils.setUserId("")
HttpUtils.setUserType("")
HttpUtils.setUserToken('')
UserDataLocal.clearUserData()
}
}
\ No newline at end of file
... ...
... ... @@ -288,7 +288,7 @@ export class ContentDetailRequest {
* @returns
*/
static postExecuteCollectRecord(params: postExecuteCollectRecordParams): Promise<ResponseDTO> {
let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_EXECUTECOLLECTRECORD
let url = HttpUrlUtils.getExecuteCollcetUrl()
return WDHttp.post(url, params)
}
... ...
... ... @@ -9,8 +9,6 @@ import { ResponseDTO } from 'wdNetwork/Index';
* 系统定位服务实现
* */
export class HWLocationUtils {
static LOCATION: Permissions = 'ohos.permission.LOCATION'
static APPROXIMATELY_LOCATION: Permissions = 'ohos.permission.APPROXIMATELY_LOCATION'
... ... @@ -115,17 +113,23 @@ export class HWLocationUtils {
if (cityName == name) {
return
}
let code = await HWLocationUtils.getCityCode(data[0].administrativeArea, data[0].subAdministrativeArea)
if (code) {
// code=[省份code,城市code]
let code: string[] = await HWLocationUtils.getCityCode(data[0].administrativeArea, data[0].subAdministrativeArea)
if (code && code.length >= 2) {
SPHelper.default.save(SpConstants.LOCATION_CITY_NAME, cityName)
SPHelper.default.save(SpConstants.LOCATION_CITY_CODE, code)
SPHelper.default.save(SpConstants.LOCATION_PROVINCE_CODE, code[0])
SPHelper.default.save(SpConstants.LOCATION_CITY_CODE, code[1])
}
if (data[0].descriptions && data[0].descriptions.length > 1) {
// 保存区县code,9位数字
let districtCode = data[0].descriptions[1] || ''
SPHelper.default.save(SpConstants.LOCATION_DISTRICT_CODE, districtCode)
}
}
}
})
}
//取消定位
static cancelLocation() {
// geoLocationManager.off('locationChange')
... ... @@ -143,10 +147,14 @@ export class HWLocationUtils {
if (bean.code == 0 && bean.data) {
for (let i = 0; i < bean.data.length; i++) {
if (bean.data[i].label == administrativeArea) {
let str:string[] = []
let provinceCode = bean.data[i].code
str[0] = provinceCode
for (let j = 0; j < bean.data[i].children.length; j++) {
if (bean.data[i].children[j].label == cityName) {
Logger.debug("huaw" + bean.data[i].children[j].code)
return bean.data[i].children[j].code
str[1] = bean.data[i].children[j].code
return str
}
}
}
... ... @@ -155,7 +163,7 @@ export class HWLocationUtils {
}
}
return ''
return []
}
// 通过省份code获取省份名称
... ...
... ... @@ -55,9 +55,6 @@ export class LoginViewModel {
SPHelper.default.saveSync(SpConstants.USER_STATUS, data.status)
SPHelper.default.saveSync(SpConstants.USER_Type, data.userType)
SPHelper.default.saveSync(SpConstants.USER_NAME, data.userName)
HttpUtils.setUserId(data.id+"")
HttpUtils.setUserType(data.userType+"")
HttpUtils.setUserToken(data.jwtToken)
success(data)
}).catch((error:string) => {
fail(error)
... ... @@ -85,9 +82,6 @@ export class LoginViewModel {
SPHelper.default.saveSync(SpConstants.USER_STATUS, data.status)
SPHelper.default.saveSync(SpConstants.USER_Type, data.userType)
SPHelper.default.saveSync(SpConstants.USER_NAME, data.userName)
HttpUtils.setUserId(data.id+"")
HttpUtils.setUserType(data.userType+"")
HttpUtils.setUserToken(data.jwtToken)
success(data)
}).catch((value: string) => {
fail(value)
... ... @@ -163,9 +157,6 @@ export class LoginViewModel {
SPHelper.default.saveSync(SpConstants.USER_STATUS, '')
SPHelper.default.saveSync(SpConstants.USER_Type, '')
SPHelper.default.saveSync(SpConstants.USER_NAME, '')
HttpUtils.setUserId("")
HttpUtils.setUserType("")
HttpUtils.setUserToken('')
success(data)
}).catch((message: string) => {
fail(message)
... ...