mirror of
https://gitee.com/openharmony/xts_tools
synced 2024-11-23 16:00:16 +00:00
仿应用示例-E适配API10语法
Signed-off-by: yuanyuecheng24298 <yuanyuecheng@openvalley.net>
This commit is contained in:
parent
4c1834279f
commit
a2dce15c68
@ -39,6 +39,7 @@ AppSampleE/src/main/ets/
|
||||
| |---Commodity.ts // 商品实体
|
||||
| |---LoginResult.ts // 登录信息实体
|
||||
| |---R.ts // 返回结果信息实体
|
||||
| |---Server.ts // 返回数据实体合集
|
||||
|---model
|
||||
│ |---NetworkModel.ts // 负责网络通信等操作
|
||||
|---pages
|
||||
|
@ -15,13 +15,14 @@
|
||||
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"compileSdkVersion": 11,
|
||||
"compatibleSdkVersion": 10,
|
||||
"signingConfigs": [
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compileSdkVersion": 10,
|
||||
"compatibleSdkVersion": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -16,7 +16,8 @@ import http from '@ohos.net.http';
|
||||
import Logger from '../utils/Logger';
|
||||
import Constant from '../utils/Constant';
|
||||
import NetworkModel from '../model/NetworkModel';
|
||||
|
||||
import LoginResult from '../data/LoginResult';
|
||||
import { BusinessInfo, CommentInfo } from '../data/Server'
|
||||
const TAG: string = '[BusinessController]';
|
||||
|
||||
export default class BusinessController {
|
||||
@ -29,16 +30,17 @@ export default class BusinessController {
|
||||
latitude: latitude
|
||||
};
|
||||
Logger.info(TAG, `getBusinessList extraData->${JSON.stringify(extraData)}`);
|
||||
let response = await this.networkModel.request(Constant.ACTION_BUSINESS_LIST, http.RequestMethod.GET, extraData, globalThis.userInfo.token);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
let response = await this.networkModel.request(Constant.ACTION_BUSINESS_LIST, http.RequestMethod.GET, extraData, userInfo.token);
|
||||
Logger.info(TAG, `getBusinessList response->${JSON.stringify(response)}`);
|
||||
// 拿到响应中服务端返回的数据
|
||||
Logger.info(TAG, `getBusinessList response.result->${JSON.stringify(response.result)}`);
|
||||
let data = response.result.toString();
|
||||
let data: string = response.result.toString();
|
||||
Logger.info(TAG, `getBusinessList data->${JSON.stringify(data)}`);
|
||||
// 将其转成Json数据
|
||||
let jsonData = JSON.parse(data);
|
||||
Logger.info(TAG, `getBusinessList jsonData->${JSON.stringify(jsonData)}`);
|
||||
let result = null; // 商家数据
|
||||
let result: BusinessInfo[] = []; // 商家数据
|
||||
if (jsonData && jsonData.result) {
|
||||
result = jsonData.result.records;
|
||||
}
|
||||
@ -51,16 +53,17 @@ export default class BusinessController {
|
||||
businessId: businessId
|
||||
};
|
||||
Logger.info(TAG, `getCommentList extraData->${JSON.stringify(extraData)}`);
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_Comment_LIST, http.RequestMethod.GET, extraData, globalThis.userInfo.token);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_Comment_LIST, http.RequestMethod.GET, extraData, userInfo.token);
|
||||
Logger.info(TAG, `getCommentList response->${JSON.stringify(response)}`);
|
||||
// 拿到响应中服务端返回的数据
|
||||
Logger.info(TAG, `getCommentList response.result->${JSON.stringify(response.result)}`);
|
||||
let data = response.result.toString();
|
||||
let data: string = response.result.toString();
|
||||
Logger.info(TAG, `getCommentList data->${JSON.stringify(data)}`);
|
||||
// 将其转成Json数据
|
||||
let jsonData = JSON.parse(data);
|
||||
Logger.info(TAG, `getCommentList jsonData->${JSON.stringify(jsonData)}`);
|
||||
let result = null; // 商家数据
|
||||
let result: CommentInfo[] = []; // 商家数据
|
||||
if (jsonData && jsonData.result) {
|
||||
result = jsonData.result.records;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import http from '@ohos.net.http';
|
||||
import Logger from '../utils/Logger';
|
||||
import Constant from '../utils/Constant';
|
||||
import NetworkModel from '../model/NetworkModel';
|
||||
import LoginResult from '../data/LoginResult';
|
||||
|
||||
const TAG: string = '[CommodityController]';
|
||||
|
||||
@ -28,7 +29,8 @@ export default class CommodityController {
|
||||
businessId: businessId
|
||||
};
|
||||
Logger.info(TAG, `getCommodityList extraData->${JSON.stringify(extraData)}`);
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_COMMODITY_LIST, http.RequestMethod.GET, extraData, globalThis.userInfo.token);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_COMMODITY_LIST, http.RequestMethod.GET, extraData, userInfo.token);
|
||||
Logger.info(TAG, `getCommodityList response->${JSON.stringify(response)}`);
|
||||
// 拿到响应中服务端返回的数据
|
||||
Logger.info(TAG, `getCommodityList response.result->${JSON.stringify(response.result)}`);
|
||||
@ -51,7 +53,8 @@ export default class CommodityController {
|
||||
id: commodityId
|
||||
};
|
||||
Logger.info(TAG, `getCommodityById extraData->${JSON.stringify(extraData)}`);
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_COMMODITY_DETAIL, http.RequestMethod.GET, extraData, globalThis.userInfo.token);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
let response = await this.networkModel.request(Constant.ACTION_GET_COMMODITY_DETAIL, http.RequestMethod.GET, extraData, userInfo.token);
|
||||
Logger.info(TAG, `getCommodityById response->${JSON.stringify(response)}`);
|
||||
// 拿到响应中服务端返回的数据
|
||||
Logger.info(TAG, `getCommodityById response.result->${JSON.stringify(response.result)}`);
|
||||
|
@ -16,6 +16,7 @@ import http from '@ohos.net.http';
|
||||
import Logger from '../utils/Logger';
|
||||
import Constant from '../utils/Constant';
|
||||
import NetworkModel from '../model/NetworkModel';
|
||||
import LoginResult from '../data/LoginResult';
|
||||
|
||||
const TAG: string = '[GroupBuyController]';
|
||||
|
||||
@ -29,7 +30,8 @@ export default class GroupBuyController {
|
||||
latitude: latitude
|
||||
};
|
||||
Logger.info(TAG, `GroupBuyList extraData->${JSON.stringify(extraData)}`);
|
||||
let response = await this.networkModel.request(Constant.ACTION_GROUP_BUY, http.RequestMethod.GET, extraData, globalThis.userInfo.token);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
let response = await this.networkModel.request(Constant.ACTION_GROUP_BUY, http.RequestMethod.GET, extraData, userInfo.token);
|
||||
Logger.info(TAG, `GroupBuyList response->${JSON.stringify(response)}`);
|
||||
// 拿到响应中服务端返回的数据
|
||||
Logger.info(TAG, `GroupBuyList response.result->${JSON.stringify(response.result)}`);
|
||||
|
91
sample/AppSampleE/entry/src/main/ets/data/Server.ts
Normal file
91
sample/AppSampleE/entry/src/main/ets/data/Server.ts
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 商家数据结构
|
||||
export interface BusinessInfo {
|
||||
id: string,
|
||||
name: string,
|
||||
cover: string,
|
||||
isOpen: boolean,
|
||||
address: string,
|
||||
longitude: string,
|
||||
latitude: string,
|
||||
distance: string,
|
||||
startTime: string,
|
||||
endTime: string,
|
||||
notice: string,
|
||||
startPrice: number,
|
||||
deliveryPrice: number,
|
||||
phoneNumber: number,
|
||||
score: string,
|
||||
monthlySale: string,
|
||||
perCapita: string,
|
||||
deliveryTime: string,
|
||||
ranking: string,
|
||||
createBy: string,
|
||||
createTime: string,
|
||||
updateBy?: string,
|
||||
updateTime?: string,
|
||||
delFlag: boolean
|
||||
}
|
||||
|
||||
// 商品数据结构
|
||||
export interface CommodityInfo {
|
||||
id: string,
|
||||
businessId: string,
|
||||
name: string,
|
||||
cover: string,
|
||||
price: string,
|
||||
salePrice: string,
|
||||
priceExplain: string,
|
||||
salesNumber: string,
|
||||
totalNumber: string,
|
||||
description: string,
|
||||
standards: string,
|
||||
weight: string,
|
||||
brand: string,
|
||||
breed: string,
|
||||
made: number,
|
||||
producer: string,
|
||||
qualityDate: string,
|
||||
packing: string,
|
||||
category: string,
|
||||
taste: string,
|
||||
keepType: string,
|
||||
createBy: string,
|
||||
createTime: string,
|
||||
updateBy?: string,
|
||||
updateTime?: string,
|
||||
delFlag: boolean
|
||||
}
|
||||
|
||||
// 评论数据结构
|
||||
export interface CommentInfo {
|
||||
id: string,
|
||||
businessId: string,
|
||||
userName: string,
|
||||
star: number,
|
||||
content: string,
|
||||
createBy?: string,
|
||||
createTime: string,
|
||||
updateBy?: string,
|
||||
updateTime?: string,
|
||||
delFlag: boolean
|
||||
}
|
||||
|
||||
export interface SelfPickUpInfo {
|
||||
name: string,
|
||||
address: string,
|
||||
distance: string
|
||||
}
|
@ -16,11 +16,13 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import hilog from '@ohos.hilog';
|
||||
import window from '@ohos.window';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
globalThis.abilityContext = this.context;
|
||||
AppStorage.setOrCreate('abilityContext', this.context)
|
||||
}
|
||||
|
||||
onDestroy() {
|
@ -17,6 +17,7 @@ import request from '@ohos.request';
|
||||
import webSocket from '@ohos.net.webSocket';
|
||||
import Logger from '../utils/Logger';
|
||||
import Constant from '../utils/Constant';
|
||||
import LoginResult from '../data/LoginResult';
|
||||
|
||||
const TAG: string = '[NetworkModel]';
|
||||
|
||||
@ -51,12 +52,13 @@ export default class NetworkModel {
|
||||
public uploadFile(action: string, fileName: string, callback): void {
|
||||
Logger.info(TAG, `upload file create action = ${action}, fileName = ${fileName}`);
|
||||
Logger.info(TAG, `upload url = ${Constant.URL + action}`);
|
||||
Logger.info(TAG, `upload token = ${globalThis.userInfo.token}`);
|
||||
let userInfo: LoginResult = AppStorage.get('userInfo')!
|
||||
Logger.info(TAG, `upload token = ${userInfo.token}`);
|
||||
let uploadTask: request.UploadTask;
|
||||
let uploadConfig = {
|
||||
url: Constant.URL + action,
|
||||
header: {
|
||||
'X-Access-Token': globalThis.userInfo.token, 'Content-Type': 'multipart/form-data'
|
||||
'X-Access-Token': userInfo.token, 'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
method: 'POST',
|
||||
files: [{
|
||||
@ -69,7 +71,7 @@ export default class NetworkModel {
|
||||
Logger.info(TAG, 'upload uploadConfig,' + JSON.stringify(uploadConfig));
|
||||
try {
|
||||
Logger.info(TAG, 'upload start');
|
||||
request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => {
|
||||
request.uploadFile(AppStorage.get('abilityContext')!, uploadConfig).then((data) => {
|
||||
uploadTask = data;
|
||||
Logger.info(TAG, 'upload end 1');
|
||||
uploadTask.on('complete', (taskState: Array<request.TaskState>) => {
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
import router from '@ohos.router';
|
||||
import geoLocationManager from '@ohos.geoLocationManager';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
import grantPermission from '../utils/PermissionUtils';
|
||||
import Logger from '../utils/Logger';
|
||||
|
||||
@ -28,7 +30,7 @@ struct Index {
|
||||
|
||||
// 获取定位服务
|
||||
getLocation(): void {
|
||||
let locationChange = (err, location: geoLocationManager.Location) => {
|
||||
let locationChange = (err: BusinessError, location: geoLocationManager.Location) => {
|
||||
if (err) {
|
||||
console.log('locationChanger: err=' + JSON.stringify(err));
|
||||
}
|
||||
@ -52,7 +54,7 @@ struct Index {
|
||||
await grantPermission().then(res => {
|
||||
this.getLocation();
|
||||
Logger.info(TAG, `权限申请成功 ${JSON.stringify(res)}`);
|
||||
}).catch(rej => {
|
||||
}).catch((rej: BusinessError) => {
|
||||
Logger.info(TAG, `权限申请失败 ${JSON.stringify(rej)}`);
|
||||
})
|
||||
}
|
||||
|
@ -16,8 +16,10 @@
|
||||
import router from '@ohos.router';
|
||||
import BusinessController from '../../controller/BusinessController';
|
||||
import CommodityController from '../../controller/CommodityController';
|
||||
import { BusinessInfo, CommodityInfo } from '../../data/Server';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = '[Buy]';
|
||||
|
||||
@ -26,29 +28,29 @@ const TAG: string = '[Buy]';
|
||||
struct Buy {
|
||||
private businessController: BusinessController = new BusinessController();
|
||||
private commodityController: CommodityController = new CommodityController();
|
||||
@State businessList: Array<any>[] = []; // 商家列表
|
||||
@State commodityList: Array<Array<any>[]> = []; // 商品列表
|
||||
@State businessList: Array<BusinessInfo> = []; // 商家列表
|
||||
@State commodityList: CommodityInfo[][] = []; // 商品列表
|
||||
@State longitude: string = getStringData($r('app.string.buy_longitude')); // 经度
|
||||
@State latitude: string = getStringData($r('app.string.buy_latitude')); // 纬度
|
||||
|
||||
aboutToAppear() {
|
||||
Logger.info(TAG, 'Buy aboutToAppear begin');
|
||||
// 商家列表
|
||||
this.businessController.getBusinessList(this.longitude, this.latitude).then(res => {
|
||||
this.businessController.getBusinessList(this.longitude, this.latitude).then((res: BusinessInfo[]) => {
|
||||
Logger.info(TAG, `aboutToAppear then res= ${JSON.stringify(res)}`);
|
||||
this.businessList = res;
|
||||
this.businessList.forEach((business, index) => {
|
||||
// 商品列表
|
||||
let businessId = business['id'];
|
||||
Logger.info(TAG, `commodityList then business= ${JSON.stringify(businessId)},index = ${index}`);
|
||||
this.commodityController.getCommodityList(businessId).then(res => {
|
||||
this.commodityController.getCommodityList(businessId).then((res: CommodityInfo[]) => {
|
||||
this.commodityList[index] = res;
|
||||
Logger.info(TAG, `commodityList then commodityList = ${JSON.stringify(this.commodityList)}`);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `commodityList catch err= ${err}`);
|
||||
})
|
||||
})
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `aboutToAppear catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
@ -60,7 +62,7 @@ struct Buy {
|
||||
Image($r('app.media.icon'))
|
||||
.height(24)
|
||||
.width(24)
|
||||
.id('back')
|
||||
.id('buyBack')
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
@ -129,7 +131,7 @@ struct Buy {
|
||||
|
||||
Scroll() {
|
||||
Column() {
|
||||
ForEach(this.businessList, (business, index) => {
|
||||
ForEach(this.businessList, (business: BusinessInfo, index) => {
|
||||
Row() {
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
@ -197,7 +199,7 @@ struct Buy {
|
||||
|
||||
Scroll() {
|
||||
Row() {
|
||||
ForEach(this.commodityList[index], (commodity) => {
|
||||
ForEach(this.commodityList[index], (commodity: CommodityInfo) => {
|
||||
Row() {
|
||||
Column() {
|
||||
Image($r('app.media.icon'))
|
||||
|
@ -14,9 +14,11 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import GroupBuyController from '../../controller/GroupBuyController';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { SelfPickUpInfo } from '../../data/Server'
|
||||
|
||||
const TAG: string = '[SelfPickUp]';
|
||||
|
||||
@ -24,17 +26,17 @@ const TAG: string = '[SelfPickUp]';
|
||||
@Component
|
||||
struct SelfPickUp {
|
||||
private groupBuyController: GroupBuyController = new GroupBuyController();
|
||||
@State selfPickUpList: Array<any>[] = []; // 站点列表
|
||||
@State selfPickUpList: Array<SelfPickUpInfo> = []; // 站点列表
|
||||
@State longitude: string = getStringData($r('app.string.buy_longitude')); // 经度
|
||||
@State latitude: string = getStringData($r('app.string.buy_latitude')); // 纬度
|
||||
|
||||
aboutToAppear() {
|
||||
Logger.info(TAG, 'aboutToAppear begin');
|
||||
this.groupBuyController.getGroupBuyList(this.longitude, this.latitude).then(res => {
|
||||
this.groupBuyController.getGroupBuyList(this.longitude, this.latitude).then((res: SelfPickUpInfo[]) => {
|
||||
Logger.info(TAG, `aboutToAppear then res= ${JSON.stringify(res)}`);
|
||||
this.selfPickUpList = res;
|
||||
Logger.info(TAG, `aboutToAppear forEach this.selfPickUpList= ${JSON.stringify(this.selfPickUpList)}`);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `aboutToAppear catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
@ -49,7 +51,7 @@ struct SelfPickUp {
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
.id('back')
|
||||
.id('selfPickUpBack')
|
||||
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
@ -111,7 +113,7 @@ struct SelfPickUp {
|
||||
|
||||
Scroll() {
|
||||
Column() {
|
||||
ForEach(this.selfPickUpList, (selfPickUp) => {
|
||||
ForEach(this.selfPickUpList, (selfPickUp: SelfPickUpInfo) => {
|
||||
Row() {
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
@ -180,7 +182,7 @@ struct SelfPickUp {
|
||||
.width('95%')
|
||||
.height('20%')
|
||||
.margin({ top: 24 })
|
||||
})
|
||||
}, (selfPickUp: SelfPickUpInfo) => JSON.stringify(selfPickUp))
|
||||
}
|
||||
.margin({ bottom: 150 })
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import LoginController from '../../controller/LoginController';
|
||||
import LoginResult from '../../data/LoginResult';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = '[Login]';
|
||||
|
||||
@ -171,14 +172,14 @@ struct Login {
|
||||
let data: LoginResult = res.data;
|
||||
Logger.info(TAG, `login success: ${JSON.stringify(data.token)}`);
|
||||
// 存储用户信息, 包括token
|
||||
globalThis.userInfo = data;
|
||||
AppStorage.setOrCreate('userInfo', data)
|
||||
// 跳转页面
|
||||
router.pushUrl({ url: 'pages/Index' });
|
||||
return;
|
||||
}
|
||||
Logger.info(TAG, `login failed: ${JSON.stringify(res)}`);
|
||||
}, 800);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `login err: ${JSON.stringify(err)}`);
|
||||
promptAction.showToast({ message: $r('app.string.Connection_timesout'), duration: 1000, bottom: 500 });
|
||||
})
|
||||
|
@ -15,8 +15,10 @@
|
||||
|
||||
import router from '@ohos.router';
|
||||
import BusinessController from '../../controller/BusinessController';
|
||||
import { BusinessInfo } from '../../data/Server';
|
||||
import Logger from '../../utils/Logger';
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = '[Business]';
|
||||
|
||||
@ -40,16 +42,16 @@ const TAG: string = '[Business]';
|
||||
@Component
|
||||
struct Business {
|
||||
private businessController: BusinessController = new BusinessController();
|
||||
@State businessList: Array<any>[] = []; // 商家列表
|
||||
@State businessList: Array<BusinessInfo> = []; // 商家列表
|
||||
@State longitude: string = getStringData($r('app.string.buy_longitude')); // 经度
|
||||
@State latitude: string = getStringData($r('app.string.buy_latitude')); // 纬度
|
||||
|
||||
aboutToAppear() {
|
||||
Logger.info(TAG, 'aboutToAppear begin');
|
||||
this.businessController.getBusinessList(this.longitude, this.latitude).then(res => {
|
||||
this.businessController.getBusinessList(this.longitude, this.latitude).then((res: BusinessInfo[]) => {
|
||||
Logger.info(TAG, `aboutToAppear then res= ${JSON.stringify(res)}`);
|
||||
this.businessList = res;
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `aboutToAppear catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
@ -118,7 +120,7 @@ struct Business {
|
||||
|
||||
Scroll() {
|
||||
Column() {
|
||||
ForEach(this.businessList, (business, index: number) => {
|
||||
ForEach(this.businessList, (business: BusinessInfo, index: number) => {
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
.width(125)
|
||||
|
@ -20,6 +20,8 @@ import CommodityController from '../../controller/CommodityController';
|
||||
import Logger from '../../utils/Logger';
|
||||
import Car from '../../data/Car'
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { CommentInfo, CommodityInfo } from '../../data/Server';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = '[Commodity]';
|
||||
const CAR_NUM = 1; // 初始化数量
|
||||
@ -41,15 +43,15 @@ struct Commodity {
|
||||
@State isLogin: boolean = false;
|
||||
@State money: number = 0;
|
||||
@State count: number = 0;
|
||||
@State commodityList: Array<any>[] = []; // 商品列表
|
||||
@State commentList: Array<any>[] = []; // 评论列表
|
||||
@State buyCarList: Array<Object> = []; // 购物车列表
|
||||
@State businessId: string = <string> router.getParams()['businessId'];
|
||||
@State businessName: string = <string> router.getParams()['businessName'];
|
||||
@State businessScore: string = <string> router.getParams()['businessScore'];
|
||||
@State businessSale: string = <string> router.getParams()['businessSale'];
|
||||
@State businessTime: string = <string> router.getParams()['businessTime'];
|
||||
@State businessRank: string = <string> router.getParams()['businessRank'];
|
||||
@State commodityList: Array<CommodityInfo> = []; // 商品列表
|
||||
@State commentList: Array<CommentInfo> = []; // 评论列表
|
||||
@State buyCarList: Array<Car> = []; // 购物车列表
|
||||
@State businessId: string = (router.getParams() as Record<string, Object>).businessId as string;
|
||||
@State businessName: string = (router.getParams() as Record<string, Object>).businessName as string;
|
||||
@State businessScore: string = (router.getParams() as Record<string, Object>).businessScore as string;
|
||||
@State businessSale: string = (router.getParams() as Record<string, Object>).businessSale as string;
|
||||
@State businessTime: string = (router.getParams() as Record<string, Object>).businessTime as string;
|
||||
@State businessRank: string = (router.getParams() as Record<string, Object>).businessRank as string;
|
||||
private commodityController: CommodityController = new CommodityController();
|
||||
private businessController: BusinessController = new BusinessController();
|
||||
|
||||
@ -65,7 +67,7 @@ struct Commodity {
|
||||
})
|
||||
}
|
||||
|
||||
addCar(name, price): void {
|
||||
addCar(name: string, price: number): void {
|
||||
let cars: Car = new Car();
|
||||
cars.name = name;
|
||||
cars.price = Number(price);
|
||||
@ -76,17 +78,17 @@ struct Commodity {
|
||||
aboutToAppear() {
|
||||
Logger.info(TAG, 'Commodity aboutToAppear');
|
||||
// 商品列表
|
||||
this.commodityController.getCommodityList(this.businessId).then(res => {
|
||||
this.commodityController.getCommodityList(this.businessId).then((res: CommodityInfo[]) => {
|
||||
this.commodityList = res;
|
||||
Logger.info(TAG, `commodityList then res= ${JSON.stringify(this.commodityList)}`);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `commodityList catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
// 商家评论列表
|
||||
this.businessController.getCommentList(this.businessId).then(res => {
|
||||
this.businessController.getCommentList(this.businessId).then((res: CommentInfo[]) => {
|
||||
this.commentList = res;
|
||||
Logger.info(TAG, `commentList then res= ${JSON.stringify(this.commentList)}`);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `commentList catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
@ -186,7 +188,7 @@ struct Commodity {
|
||||
TabContent() {
|
||||
Scroll() {
|
||||
Column() {
|
||||
ForEach(this.commodityList, (commodity, index) => {
|
||||
ForEach(this.commodityList, (commodity: CommodityInfo, index) => {
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
.width(150)
|
||||
@ -237,7 +239,7 @@ struct Commodity {
|
||||
this.money = this.money + Number(commodity.price);
|
||||
this.count++;
|
||||
if (this.buyCarList.length <= this.commentList.length && this.count === 1) {
|
||||
this.addCar(commodity.name, commodity.price);
|
||||
this.addCar(commodity.name, Number(commodity.price));
|
||||
} else {
|
||||
for (let index = 0; index < this.buyCarList.length; index++) {
|
||||
const element = this.buyCarList[index]['name'];
|
||||
@ -253,7 +255,7 @@ struct Commodity {
|
||||
break;
|
||||
} else {
|
||||
if (index == this.buyCarList.length - 1) {
|
||||
this.addCar(commodity.name, commodity.price);
|
||||
this.addCar(commodity.name, Number(commodity.price));
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
@ -284,7 +286,7 @@ struct Commodity {
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
}, (commodity: CommodityInfo) => JSON.stringify(commodity))
|
||||
}
|
||||
.margin({ bottom: 55 })
|
||||
}
|
||||
@ -335,7 +337,7 @@ struct Commodity {
|
||||
|
||||
Scroll() {
|
||||
Column() {
|
||||
ForEach(this.commentList, (comment, index) => {
|
||||
ForEach(this.commentList, (comment: CommentInfo) => {
|
||||
Column() {
|
||||
Row() {
|
||||
Image($r('app.media.icon'))
|
||||
|
@ -18,6 +18,8 @@ import CommodityController from '../../controller/CommodityController';
|
||||
import Logger from '../../utils/Logger';
|
||||
import com from '../../data/Commodity'
|
||||
import { getStringData } from '../../utils/ResourceDataHandle';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { CommodityInfo } from '../../data/Server';
|
||||
|
||||
const TAG: string = '[ProductDetails]';
|
||||
|
||||
@ -26,8 +28,8 @@ const TAG: string = '[ProductDetails]';
|
||||
struct ProductDetails { // 商品详情页面
|
||||
private CommodityController: CommodityController = new CommodityController();
|
||||
private com: com = new com();
|
||||
@State commodity: Object = undefined;
|
||||
@State commodityId: string = <string> router.getParams()['commodityId'];
|
||||
@State commodity: CommodityInfo | undefined = undefined;
|
||||
@State commodityId: string = (router.getParams() as Record<string, Object>).commodityId as string;
|
||||
@State name: string = '';
|
||||
@State description: string = '';
|
||||
@State standards: string = '';
|
||||
@ -37,7 +39,7 @@ struct ProductDetails { // 商品详情页面
|
||||
aboutToAppear() {
|
||||
Logger.info(TAG, 'ProductDetails aboutToAppear');
|
||||
Logger.info(TAG, 'ProductDetails this.commodityId' + this.commodityId);
|
||||
this.CommodityController.getCommodityById(this.commodityId).then(res => {
|
||||
this.CommodityController.getCommodityById(this.commodityId).then((res: CommodityInfo) => {
|
||||
Logger.info(TAG, 'ProductDetails getCommodityById');
|
||||
this.com.name = res.name;
|
||||
this.com.description = res.description;
|
||||
@ -53,7 +55,7 @@ struct ProductDetails { // 商品详情页面
|
||||
Logger.info(TAG, 'ProductDetails com===' + this.description);
|
||||
this.commodity = res;
|
||||
Logger.info(TAG, `ProductDetails then res= ${JSON.stringify(this.commodity)}`);
|
||||
}).catch(err => {
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.info(TAG, `ProductDetails catch err= ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
@ -68,7 +70,7 @@ struct ProductDetails { // 商品详情页面
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
})
|
||||
.id('back')
|
||||
.id('ProductDetailsBack')
|
||||
Blank()
|
||||
Image($r('app.media.icon'))
|
||||
.width(24)
|
||||
|
@ -16,8 +16,8 @@
|
||||
export default class Constant {
|
||||
|
||||
// URL
|
||||
public static readonly URL: string = 'http://192.168.18.165:8080/jeecg-boot';
|
||||
public static readonly ACTION_ON_MESSAGE_URL: string = 'ws://192.168.18.165:8080/jeecg-boot/websocket/';
|
||||
public static readonly URL: string = 'http://192.168.18.16:8080/jeecg-boot';
|
||||
public static readonly ACTION_ON_MESSAGE_URL: string = 'ws://192.168.18.16:8080/jeecg-boot/websocket/';
|
||||
public static readonly ACTION_SEND_MESSAGE: string = '/sys/message/sysMessageTemplate/sendMsg';
|
||||
public static readonly UPLOAD_URL: string = 'sampleE';
|
||||
public static readonly ACTION_LOGIN: string = '/sys/login';
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
|
||||
import type { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import bundleManager from '@ohos.bundle.bundleManager';
|
||||
import Logger from './Logger';
|
||||
|
||||
@ -47,7 +47,7 @@ export default async function grantPermission(): Promise<boolean> {
|
||||
}
|
||||
if (pems.length > 0) {
|
||||
Logger.info(TAG, 'grantPermission requestPermissionsFromUser :' + JSON.stringify(pems));
|
||||
let result = await atManager.requestPermissionsFromUser(globalThis.abilityContext, pems);
|
||||
let result = await atManager.requestPermissionsFromUser(AppStorage.get('abilityContext')!, pems);
|
||||
|
||||
let grantStatus: Array<number> = result.authResults;
|
||||
let length: number = grantStatus.length;
|
||||
|
@ -17,7 +17,7 @@ let context = getContext(this);
|
||||
|
||||
export function getStringData(resourceData: Resource):string {
|
||||
if (!resourceData) {
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
return context.resourceManager.getStringSync(resourceData.id);
|
||||
}
|
@ -19,7 +19,8 @@
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default"
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
@ -27,7 +28,7 @@
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ts",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:EntryAbility_label",
|
||||
|
@ -18,6 +18,7 @@ import { Driver, ON, MatchPattern } from '@ohos.UiTest';
|
||||
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import Logger from '../util/Logger';
|
||||
import { getString } from '../util/ResourceUtil'
|
||||
import { Callback } from '@ohos.base';
|
||||
|
||||
const DELAY_TIME = 1500;
|
||||
const delegator = abilityDelegatorRegistry.getAbilityDelegator();
|
||||
@ -47,38 +48,38 @@ async function checkAndClickByText(text: string, log: string) {
|
||||
}
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', function () {
|
||||
describe('ActsAbilityTest', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(async function () {
|
||||
beforeAll(async () => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
// 启动Ability
|
||||
})
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
})
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
it('assertContain', 0, async function () {
|
||||
it('assertContain', 0, async () => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
||||
|
||||
it(BUNDLE + 'StartAbility_001', 0, async function (done) {
|
||||
it(BUNDLE + 'StartAbility_001', 0, async (done: () => void) => {
|
||||
delegator.executeShellCommand('aa start -a EntryAbility -b com.samples.appsamplee');
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
done();
|
||||
})
|
||||
|
||||
it(BUNDLE + 'Login_001', 0, async function () {
|
||||
it(BUNDLE + 'Login_001', 0, async () => {
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
await checkAndClickById('login','Login');
|
||||
await driver.delayMs(4000);
|
||||
@ -86,7 +87,7 @@ export default function abilityTest() {
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
})
|
||||
|
||||
it(BUNDLE + 'Buy_001', 0, async function () {
|
||||
it(BUNDLE + 'Buy_001', 0, async () => {
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
await checkAndClickById('buy','Buy');
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
@ -98,7 +99,7 @@ export default function abilityTest() {
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
})
|
||||
|
||||
it(BUNDLE + 'HongTuan_001', 0, async function () {
|
||||
it(BUNDLE + 'HongTuan_001', 0, async () => {
|
||||
let driver: Driver = Driver.create();
|
||||
await driver.delayMs(DELAY_TIME);
|
||||
|
||||
|
@ -14,19 +14,21 @@
|
||||
*/
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import hilog from '@ohos.hilog';
|
||||
import { Hypium } from '@ohos/hypium';
|
||||
import testsuite from '../test/List.test';
|
||||
import window from '@ohos.window';
|
||||
|
||||
export default class TestAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
|
||||
var abilityDelegator: any
|
||||
let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||
var abilityDelegatorArguments: any
|
||||
let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
|
||||
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
|
||||
|
@ -19,11 +19,11 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
|
||||
var abilityDelegator = undefined
|
||||
var abilityDelegatorArguments = undefined
|
||||
|
||||
async function onAbilityCreateCallback() {
|
||||
const onAbilityCreateCallback = async() => {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
|
||||
}
|
||||
|
||||
async function addAbilityMonitorCallback(err: any) {
|
||||
const addAbilityMonitorCallback = async (err: any) => {
|
||||
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
{
|
||||
"hvigorVersion": "2.1.1",
|
||||
"hvigorVersion": "3.0.2",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "2.1.1"
|
||||
"@ohos/hvigor-ohos-plugin": "3.0.2"
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.6"
|
||||
"@ohos/hypium": "1.0.11"
|
||||
},
|
||||
"author": "",
|
||||
"name": "AppSampleE",
|
||||
|
Loading…
Reference in New Issue
Block a user