From 63608b878b62c281a0812a3677f157c654d9ea2e Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Thu, 25 Jan 2024 15:43:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=95=86=E5=9F=8EURL?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3=E7=9B=B8=E5=85=B3=EF=BC=88?= =?UTF-8?q?=E9=A2=84=E5=8F=91=E5=B8=83=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/appRouters.dart | 6 ++- star_lock/lib/mine/mall/lockMall_entity.dart | 43 +++++++++++++++++++ star_lock/lib/mine/mall/lockMall_logic.dart | 38 ++++++++++++++++ .../{mall_page.dart => lockMall_page.dart} | 15 +++---- star_lock/lib/mine/mall/lockMall_state.dart | 8 ++++ star_lock/lib/network/api.dart | 5 ++- star_lock/lib/network/api_provider.dart | 26 +++++------ star_lock/lib/network/api_repository.dart | 14 +++--- 8 files changed, 126 insertions(+), 29 deletions(-) create mode 100644 star_lock/lib/mine/mall/lockMall_entity.dart create mode 100644 star_lock/lib/mine/mall/lockMall_logic.dart rename star_lock/lib/mine/mall/{mall_page.dart => lockMall_page.dart} (75%) create mode 100644 star_lock/lib/mine/mall/lockMall_state.dart diff --git a/star_lock/lib/appRouters.dart b/star_lock/lib/appRouters.dart index 69ae1e8f..a91cb89f 100644 --- a/star_lock/lib/appRouters.dart +++ b/star_lock/lib/appRouters.dart @@ -145,7 +145,7 @@ import 'mine/gateway/addGateway/selectGatewayTypeNextTip/selectGatewayTypeNextTi import 'mine/gateway/gatewayConnectionLock/gatewayConnectionLockList_page.dart'; import 'mine/gateway/gatewayDetail/gatewayDetail_page.dart'; import 'mine/gateway/gatewayList/gatewayList_page.dart'; -import 'mine/mall/mall_page.dart'; +import 'mine/mall/lockMall_page.dart'; import 'mine/message/messageDetail/messageDetail_page.dart'; import 'mine/message/messageList/messageList_page.dart'; import 'mine/mine/starLockMine_page.dart'; @@ -1021,6 +1021,8 @@ abstract class AppRouters { GetPage(name: Routers.videoSlotPage, page: (() => const VideoSlotPage())), GetPage(name: Routers.liveVideoPage, page: (() => const LiveVideoPage())), GetPage(name: Routers.faceDetailPage, page: (() => const FaceDetailPage())), - GetPage(name: Routers.messageDetailPage, page: (() => const MessageDetailPage())), + GetPage( + name: Routers.messageDetailPage, + page: (() => const MessageDetailPage())), ]; } diff --git a/star_lock/lib/mine/mall/lockMall_entity.dart b/star_lock/lib/mine/mall/lockMall_entity.dart new file mode 100644 index 00000000..c1a9d8eb --- /dev/null +++ b/star_lock/lib/mine/mall/lockMall_entity.dart @@ -0,0 +1,43 @@ +class LockMallDataEntity { + int? errorCode; + String? description; + String? errorMsg; + Data? data; + + LockMallDataEntity( + {this.errorCode, this.description, this.errorMsg, this.data}); + + LockMallDataEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + data = json['data'] != null ? Data.fromJson(json['data']) : null; + } + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + if (this.data != null) { + data['data'] = this.data!.toJson(); + } + return data; + } +} + +class Data { + String? url; + + Data({this.url}); + + Data.fromJson(Map json) { + url = json['url']; + } + + Map toJson() { + final Map data = {}; + data['url'] = url; + return data; + } +} diff --git a/star_lock/lib/mine/mall/lockMall_logic.dart b/star_lock/lib/mine/mall/lockMall_logic.dart new file mode 100644 index 00000000..6cb9aef5 --- /dev/null +++ b/star_lock/lib/mine/mall/lockMall_logic.dart @@ -0,0 +1,38 @@ +import 'package:star_lock/mine/mall/lockMall_entity.dart'; +import 'package:star_lock/mine/mall/lockMall_state.dart'; +import 'package:star_lock/network/api_repository.dart'; + +import '../../tools/baseGetXController.dart'; + +class LockMallLogic extends BaseGetXController { + final LockMallState state = LockMallState(); + + //获取商城跳转地址 + Future getMallURLRequest() async { + LockMallDataEntity entity = await ApiRepository.to.getMallURLData(); + if (entity.errorCode!.codeIsSuccessful) { + state.lockMallUrl.value = entity.data!.url!; + state.mallWebView.loadRequest(Uri.parse(state.lockMallUrl.value)); + } + } + + @override + Future onReady() async { + print("ready home"); + super.onReady(); + } + + @override + void onInit() { + print("init home"); + super.onInit(); + + getMallURLRequest(); + } + + @override + void onClose() { + print("close home"); + super.onClose(); + } +} diff --git a/star_lock/lib/mine/mall/mall_page.dart b/star_lock/lib/mine/mall/lockMall_page.dart similarity index 75% rename from star_lock/lib/mine/mall/mall_page.dart rename to star_lock/lib/mine/mall/lockMall_page.dart index 74caff76..37cc9364 100644 --- a/star_lock/lib/mine/mall/mall_page.dart +++ b/star_lock/lib/mine/mall/lockMall_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_colors.dart'; +import 'package:star_lock/mine/mall/lockMall_logic.dart'; import 'package:star_lock/tools/titleAppBar.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -14,21 +15,19 @@ class LockMallPage extends StatefulWidget { } class _LockMallPageState extends State { - late WebViewController _webViewController; + final logic = Get.put(LockMallLogic()); + final state = Get.find().state; + @override void initState() { super.initState(); - - _webViewController = WebViewController() - ..setJavaScriptMode(JavaScriptMode.unrestricted); } @override Widget build(BuildContext context) { // FIXME 如果未登录状态,应先跳转登录页 // FIXME url应该使用接口获取,接口名称 “获取商城跳转地址:/mall/getUrl“ POST请求,无参数,需要登录 - String url = 'https://ge.mall.star-lock.cn/quick_login?id=4&key=1ffb9d37109b8351ebb04ccfcca02c8e'; - _webViewController.loadRequest(Uri.parse(url)); + // String url = 'https://ge.mall.star-lock.cn/quick_login?id=4&key=1ffb9d37109b8351ebb04ccfcca02c8e'; return Scaffold( resizeToAvoidBottomInset: false, backgroundColor: const Color(0xFFFFFFFF), @@ -37,12 +36,12 @@ class _LockMallPageState extends State { haveBack: true, backgroundColor: AppColors.mainColor, ), - body: WebViewWidget(controller: _webViewController)); + body: WebViewWidget(controller: state.mallWebView)); } String getWebTitle() { String webTitleStr = TranslationLoader.lanKeys!.shoppingCart!.tr; - _webViewController.getTitle().then((result) { + state.mallWebView.getTitle().then((result) { webTitleStr = result!; }); return webTitleStr; diff --git a/star_lock/lib/mine/mall/lockMall_state.dart b/star_lock/lib/mine/mall/lockMall_state.dart new file mode 100644 index 00000000..2ad6312d --- /dev/null +++ b/star_lock/lib/mine/mall/lockMall_state.dart @@ -0,0 +1,8 @@ +import 'package:get/get.dart'; +import 'package:webview_flutter/webview_flutter.dart'; + +class LockMallState { + var lockMallUrl = "".obs; + late WebViewController mallWebView = WebViewController() + ..setJavaScriptMode(JavaScriptMode.unrestricted); +} diff --git a/star_lock/lib/network/api.dart b/star_lock/lib/network/api.dart index d6475e72..fa8dd208 100644 --- a/star_lock/lib/network/api.dart +++ b/star_lock/lib/network/api.dart @@ -1,6 +1,6 @@ abstract class Api { - // static String baseAddress = "https://pre.lock.star-lock.cn"; //预发布环境 - static String baseAddress = "https://dev.lock.star-lock.cn"; //联调环境 + static String baseAddress = "https://pre.lock.star-lock.cn"; //预发布环境 + // static String baseAddress = "https://dev.lock.star-lock.cn"; //联调环境 // static String baseAddress = "http://192.168.1.15:8022"; //谢总本地 // static String baseAddress = "https://ge.lock.star-lock.cn"; //葛工开发环境地址 @@ -113,6 +113,7 @@ abstract class Api { final String updateFaceUserInfoURL = '/face/update'; // 更新人脸信息--有效期、名称 final String deleteFaceURL = '/face/delete'; // 删除人脸 final String clearFaceURL = '/face/clear'; // 清空人脸 + final String getMallURL = '/mall/getUrl'; // 获取商城跳转地址 final String getICCardListURL = '/identityCard/list'; // IC卡列表 final String addICCardURL = '/identityCard/add'; // 添加IC卡 diff --git a/star_lock/lib/network/api_provider.dart b/star_lock/lib/network/api_provider.dart index 523bf532..22d71d9d 100644 --- a/star_lock/lib/network/api_provider.dart +++ b/star_lock/lib/network/api_provider.dart @@ -1110,6 +1110,9 @@ class ApiProvider extends BaseProvider { 'lockId': lockId, })); + // 获取商城跳转地址 + Future getMallURLData() => post(getMallURL.toUrl, jsonEncode({})); + // 获取IC卡列表 Future getICCardListData( String lockId, String pageNo, String pageSize, String searchStr) => @@ -1494,20 +1497,19 @@ class ApiProvider extends BaseProvider { jsonEncode({"deviceId": deviceId, "deviceType": deviceType})); // 消息列表 - Future messageListLoadData(String pageNo, String pageSize) => - post(messageListURL.toUrl, - jsonEncode({ - 'pageNo': pageNo, - 'pageSize': pageSize, - })); + Future messageListLoadData(String pageNo, String pageSize) => post( + messageListURL.toUrl, + jsonEncode({ + 'pageNo': pageNo, + 'pageSize': pageSize, + })); // 读取消息 - Future readMessageLoadData(String messageId) => - post(readMessageURL.toUrl, - jsonEncode({ - 'id': messageId, - })); - + Future readMessageLoadData(String messageId) => post( + readMessageURL.toUrl, + jsonEncode({ + 'id': messageId, + })); } extension ExtensionString on String { diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index ad3ac511..08a5cac0 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -8,6 +8,7 @@ import 'package:star_lock/main/lockDetail/face/addFace/addFace_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/KeyDetailEntity.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart'; +import 'package:star_lock/mine/mall/lockMall_entity.dart'; import 'package:star_lock/mine/minePersonInfo/minePersonInfoEditAccount/minePersonInfoEditAccount/mineUnbindPhoneOrEmail_entity.dart'; import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart'; import 'package:star_lock/mine/minePersonInfo/minePersonInfoSetSafetyProblem/minePersonInfoSetSafetyProblem_entity.dart'; @@ -1250,6 +1251,12 @@ class ApiRepository { return LoginEntity.fromJson(res.body); } + // 获取商城跳转地址 + Future getMallURLData() async { + final res = await apiProvider.getMallURLData(); + return LockMallDataEntity.fromJson(res.body); + } + // 获取Ic卡列表 Future getICCardListData({ required String lockId, @@ -1505,10 +1512,8 @@ class ApiRepository { } // 消息列表 - Future messageListLoadData({ - required String pageNo, - required String pageSize - }) async { + Future messageListLoadData( + {required String pageNo, required String pageSize}) async { final res = await apiProvider.messageListLoadData(pageNo, pageSize); return MessageListEntity.fromJson(res.body); } @@ -1520,5 +1525,4 @@ class ApiRepository { final res = await apiProvider.readMessageLoadData(messageId); return MessageListEntity.fromJson(res.body); } - }