ops-console v1.0.2 (versionCode 8) 源码入库

This commit is contained in:
txh
2026-09-03 18:01:05 +08:00
commit 685fff27c8
170 changed files with 53049 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,258 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../models/store_info.dart';
import '../../../services/api_client.dart';
import '../../../services/org_service.dart';
import '../../../utils/formatters.dart';
import '../../../utils/i10n.dart';
/// 公司介绍 - 门店列表入口页。
///
/// 以门店列表形式展示各门店,支持按关键字搜索门店;点击门店进入该门店的
/// 公司介绍内容页(按内容类型分类呈现)。
class IntroStoreListPage extends ConsumerStatefulWidget {
const IntroStoreListPage({super.key});
@override
ConsumerState<IntroStoreListPage> createState() => _IntroStoreListPageState();
}
class _IntroStoreListPageState extends ConsumerState<IntroStoreListPage> {
final _orgService = OrgService();
final _searchController = TextEditingController();
List<StoreInfo> _allStores = [];
List<StoreInfo> _stores = [];
bool _loading = false;
String? _error;
String _keyword = '';
@override
void initState() {
super.initState();
_loadData();
}
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
Future<void> _loadData() async {
setState(() {
_loading = true;
_error = null;
});
try {
final items = await _orgService.getMyStores();
if (!mounted) return;
_allStores = items;
_applyFilter();
setState(() => _loading = false);
} catch (e) {
if (!mounted) return;
setState(() {
_error = formatApiError(e, fallback: '门店加载失败,请稍后重试');
_loading = false;
});
}
}
void _applyFilter() {
final keyword = _keyword.trim().toLowerCase();
if (keyword.isEmpty) {
_stores = List.of(_allStores);
} else {
_stores = _allStores
.where((s) => s.name.toLowerCase().contains(keyword))
.toList();
}
// 与门店管理页保持一致:按创建时间倒序(最新的排最前面)。
_stores.sort((a, b) {
if (a.createTime != null && b.createTime != null) {
return b.createTime!.compareTo(a.createTime!);
}
if (a.createTime == null && b.createTime != null) return 1;
if (a.createTime != null && b.createTime == null) return -1;
return b.orgId.compareTo(a.orgId);
});
}
void _onSearch() {
setState(() {
_keyword = _searchController.text;
_applyFilter();
});
}
void _onStoreTap(StoreInfo store) {
context.push('/admin/intro/store-content/${store.orgId}', extra: store);
}
@override
Widget build(BuildContext context) {
final t = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(title: Text(t.introCategoryTitle)),
body: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: t.searchStoreHint,
prefixIcon: const Icon(Icons.search),
suffixIcon: _searchController.text.isEmpty
? null
: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
_searchController.clear();
setState(() {
_keyword = '';
_applyFilter();
});
},
),
),
onSubmitted: (_) => _onSearch(),
),
),
Expanded(child: _buildBody()),
],
),
);
}
Widget _buildBody() {
final t = AppLocalizations.of(context);
if (_loading && _stores.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
if (_error != null && _stores.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('${t.loadFailed}:$_error'),
const SizedBox(height: 8),
FilledButton.tonal(
onPressed: _loadData,
child: Text(t.retry),
),
],
),
);
}
if (_stores.isEmpty) {
return RefreshIndicator(
onRefresh: _loadData,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [
const SizedBox(height: 200),
Center(child: Text(t.noData)),
],
),
);
}
return RefreshIndicator(
onRefresh: _loadData,
child: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _stores.length,
itemBuilder: (context, index) {
final store = _stores[index];
return _StoreListTile(
store: store,
onTap: () => _onStoreTap(store),
);
},
),
);
}
}
/// 门店列表项:复用门店管理页的视觉风格。
class _StoreListTile extends StatelessWidget {
const _StoreListTile({required this.store, required this.onTap});
final StoreInfo store;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final t = AppLocalizations.of(context);
final isDisabled = store.status == 1;
final statusColor = isDisabled ? Colors.grey : Colors.green;
return Card(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: ListTile(
onTap: onTap,
title: Row(
children: [
Expanded(
child: Text(
store.name,
style: theme.textTheme.titleSmall
?.copyWith(fontWeight: FontWeight.bold),
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: statusColor.withOpacity(0.15),
borderRadius: BorderRadius.circular(999),
border: Border.all(color: statusColor.withOpacity(0.6)),
),
child: Text(
isDisabled ? t.statusDisabled : t.statusNormal,
style: TextStyle(
color: statusColor,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
],
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
if (store.address.isNotEmpty)
_infoLine(context, Icons.location_on, store.address),
if (store.contactPhone.isNotEmpty)
_infoLine(context, Icons.phone, store.contactPhone),
if (store.expireTime != null)
_infoLine(
context,
Icons.event,
'${t.expireTime}:${Formatters.formatDateTime(store.expireTime!)}',
),
],
),
trailing: const Icon(Icons.chevron_right),
),
);
}
Widget _infoLine(BuildContext context, IconData icon, String text) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 1),
child: Row(
children: [
Icon(icon, size: 14, color: Theme.of(context).colorScheme.outline),
const SizedBox(width: 4),
Expanded(child: Text(text, style: const TextStyle(fontSize: 13))),
],
),
);
}
}