Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit b5e70a70
authored
2025-12-18 15:38:39 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
调整 AppVersion 和 H5Version 的规则
1 parent
63c84756
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
16 deletions
lib/config/constant.dart
lib/config/evn_config.dart → lib/config/env_config.dart
lib/data/repositories/message/upload_file.dart
lib/main.dart
lib/services/local_server_service.dart
lib/ui/pages/web_page.dart
lib/config/constant.dart
View file @
b5e70a7
import
'package:appframe/config/e
vn
_config.dart'
;
import
'package:appframe/config/e
nv
_config.dart'
;
class
Constant
{
/// local server 相关
...
...
@@ -50,10 +50,10 @@ class Constant {
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// app 版本号规则
static
const
String
appVersion
=
'1.0.2512165'
;
static
const
String
appVersion
=
EnvConfig
.
version
;
/// H5的起始终最低版本号规则
static
const
String
h5Version
=
'1
.0.0'
;
static
String
h5Version
=
'0
.0.0'
;
/// H5的版本号存储的key
static
const
String
h5VersionKey
=
'h5_version'
;
...
...
@@ -63,7 +63,8 @@ class Constant {
/// H5版本号配置文件地址
static
const
String
configUrl
=
EnvConfig
.
env
==
'dev'
?
'https://bxe-obs.banxiaoer.com/conf/xeapp_conf_dev.json'
?
'https://bxe-obs.banxiaoer.com/fronts/material/xehybrid/assets/develop/xeapp_conf_dev.json'
// ? 'https://bxe-obs.banxiaoer.com/conf/xeapp_conf_dev.json'
// ? 'http://192.168.2.177/xeapp_conf_dev.json'
:
'https://bxe-obs.banxiaoer.com/conf/xeapp_conf_pro.json'
;
...
...
lib/config/e
vn
_config.dart
→
lib/config/e
nv
_config.dart
View file @
b5e70a7
class
EnvConfig
{
static
const
String
env
=
String
.
fromEnvironment
(
'env'
,
defaultValue:
'dev'
);
static
const
String
version
=
String
.
fromEnvironment
(
'version'
,
defaultValue:
'0.0.0'
);
static
bool
isDev
()
{
return
env
==
'dev'
;
}
...
...
lib/data/repositories/message/upload_file.dart
View file @
b5e70a7
import
'dart:convert'
;
import
'dart:io'
;
import
'package:appframe/config/e
vn
_config.dart'
;
import
'package:appframe/config/e
nv
_config.dart'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/services/api_service.dart'
;
...
...
lib/main.dart
View file @
b5e70a7
import
'dart:convert'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/env_config.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/services/im_service.dart'
;
import
'package:archive/archive.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'app.dart'
;
...
...
@@ -9,10 +15,48 @@ void main() async {
WidgetsFlutterBinding
.
ensureInitialized
();
await
setupLocator
();
// IM SDK 初始化
await
_initH5Version
();
await
_initImSdk
();
runApp
(
const
App
());
}
Future
<
void
>
_initH5Version
()
async
{
// 1 读取保存的H5版本
var
h5Version
=
getIt
.
get
<
SharedPreferences
>().
getString
(
Constant
.
h5VersionKey
);
if
(
h5Version
!=
null
&&
h5Version
.
isNotEmpty
)
{
Constant
.
h5Version
=
h5Version
;
return
;
}
// 2 读取基准包
try
{
String
path
=
EnvConfig
.
isDev
()
?
"assets/base-dev.zip"
:
"assets/base-pro.zip"
;
final
byteData
=
await
rootBundle
.
load
(
path
);
final
archive
=
ZipDecoder
().
decodeBytes
(
byteData
.
buffer
.
asUint8List
());
// 查找 package.json 文件
for
(
final
file
in
archive
)
{
if
(
file
.
name
==
'package.json'
)
{
// 将内容转换成字符串
final
content
=
utf8
.
decode
(
file
.
content
as
List
<
int
>);
var
json
=
jsonDecode
(
content
);
var
h5Version
=
json
[
'version'
]
??
Constant
.
h5Version
;
Constant
.
h5Version
=
h5Version
;
getIt
.
get
<
SharedPreferences
>().
setString
(
Constant
.
h5ShowVersionKey
,
h5Version
);
return
;
}
}
}
catch
(
e
)
{
Constant
.
h5Version
=
'0.0.0'
;
getIt
.
get
<
SharedPreferences
>().
setString
(
Constant
.
h5ShowVersionKey
,
'0.0.0'
);
debugPrint
(
e
.
toString
());
}
}
Future
<
void
>
_initImSdk
()
async
{
if
(
Constant
.
needIM
)
{
await
getIt
.
get
<
ImService
>().
initSdk
();
}
runApp
(
const
App
());
}
lib/services/local_server_service.dart
View file @
b5e70a7
...
...
@@ -3,6 +3,7 @@ import 'dart:convert';
import
'dart:io'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/env_config.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/utils/zip_util.dart'
;
import
'package:flutter/services.dart'
;
...
...
@@ -180,13 +181,7 @@ class LocalServerService {
var
dir
=
await
getApplicationSupportDirectory
();
var
distFilePath
=
'
${dir.path}
/
${Constant.h5DistDir}
/
$version
.zip'
;
if
(!(
await
File
(
distFilePath
).
exists
()))
{
distFilePath
=
'assets/
$version
.zip'
;
// 判断 assets 中的文件是否存在?抛出异常代表不存在
try
{
await
rootBundle
.
load
(
distFilePath
);
}
catch
(
e
)
{
distFilePath
=
'assets/dist.zip'
;
}
distFilePath
=
EnvConfig
.
isDev
()
?
"assets/base-dev.zip"
:
"assets/base-pro.zip"
;
}
// 解压
await
ZipUtil
.
extractZipFile
(
distFilePath
,
outputDirectory
);
...
...
lib/ui/pages/web_page.dart
View file @
b5e70a7
import
'package:appframe/bloc/web_cubit.dart'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/e
vn
_config.dart'
;
import
'package:appframe/config/e
nv
_config.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:flutter/material.dart'
;
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment