forked from lxm_tools/flutter-picgo
feature:complete smms repo manage
This commit is contained in:
@@ -12,22 +12,38 @@ class SMMSApi {
|
||||
|
||||
static Future getProfile() async {
|
||||
var op = await oAuth();
|
||||
Response res = await NetUtils.getInstance().post(BASE_URL + 'profile', options: op);
|
||||
Response res =
|
||||
await NetUtils.getInstance().post(BASE_URL + 'profile', options: op);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
static Future upload(FormData formData) async {
|
||||
var op = await oAuth();
|
||||
Response res = await NetUtils.getInstance().post(BASE_URL + 'upload', data: formData, options: op);
|
||||
Response res = await NetUtils.getInstance()
|
||||
.post(BASE_URL + 'upload', data: formData, options: op);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
static Future delete(String hash) async {
|
||||
var op = await oAuth();
|
||||
Response res = await NetUtils.getInstance().get(BASE_URL + 'delete/' + hash ?? '', options: op);
|
||||
Response res = await NetUtils.getInstance()
|
||||
.get(BASE_URL + 'delete/' + hash ?? '', options: op);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
static Future deleteByPath(String path) async {
|
||||
var op = await oAuth();
|
||||
Response res = await NetUtils.getInstance().get(path, options: op);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
static Future getUploadHistory() async {
|
||||
var op = await oAuth();
|
||||
Response res = await NetUtils.getInstance()
|
||||
.get(BASE_URL + '/upload_history', options: op);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 获取配置中的Token
|
||||
static Future<Options> oAuth() async {
|
||||
try {
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_picgo/views/home.dart';
|
||||
import 'package:flutter_picgo/views/album_page/album_page.dart';
|
||||
import 'package:flutter_picgo/views/manage_page/smms_page/smms_repo_page.dart';
|
||||
import 'package:flutter_picgo/views/pb_setting_page/aliyun_page/aliyun_page.dart';
|
||||
import 'package:flutter_picgo/views/pb_setting_page/gitee_page/gitee_page.dart';
|
||||
import 'package:flutter_picgo/views/manage_page/gitee_page/gitee_repo_page.dart';
|
||||
@@ -87,6 +88,11 @@ var pbsettingSMMSHandler = new Handler(
|
||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) =>
|
||||
SMMSPage());
|
||||
|
||||
// SM.MS 仓库列表页面
|
||||
var pbsettingSMMSRepoHandler = new Handler(
|
||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) =>
|
||||
SMMSRepoPage());
|
||||
|
||||
// Gitee设置页面
|
||||
var pbsettingGiteeHandler = new Handler(
|
||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) =>
|
||||
|
||||
@@ -17,6 +17,7 @@ class Routes {
|
||||
// -----------------------------------
|
||||
// --------- smms ------------------
|
||||
static const String settingPbSMMS = '/setting/pb/smms';
|
||||
static const String settingPbSMMSRepo = '/setting/pb/smms/repo';
|
||||
// -----------------------------------
|
||||
// --------- gitee ------------------
|
||||
static const String settingPbGitee = '/setting/pb/gitee';
|
||||
@@ -62,5 +63,6 @@ class Routes {
|
||||
router.define(settingPbNiupic, handler: pbsettingNiupicHandler);
|
||||
router.define(settingPbLsky, handler: pbsettingLskyHandler);
|
||||
router.define(settingPbUpyun, handler: pbsettingUpyunHandler);
|
||||
router.define(settingPbSMMSRepo, handler: pbsettingSMMSRepoHandler);
|
||||
}
|
||||
}
|
||||
|
||||
138
lib/views/manage_page/smms_page/smms_repo_page.dart
Normal file
138
lib/views/manage_page/smms_page/smms_repo_page.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picgo/components/manage_item.dart';
|
||||
import 'package:flutter_picgo/model/smms_content.dart';
|
||||
import 'package:flutter_picgo/views/manage_page/base_loading_page_state.dart';
|
||||
import 'package:flutter_picgo/views/manage_page/smms_page/smms_repo_page_presenter.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class SMMSRepoPage extends StatefulWidget {
|
||||
@override
|
||||
_SMMSRepoPageState createState() => _SMMSRepoPageState();
|
||||
}
|
||||
|
||||
class _SMMSRepoPageState extends BaseLoadingPageState<SMMSRepoPage>
|
||||
implements SMMSRepoPageContract {
|
||||
String errorMsg;
|
||||
List<SMMSContent> contents = [];
|
||||
SMMSRepoPagePresenter _presenter;
|
||||
|
||||
_SMMSRepoPageState() {
|
||||
_presenter = SMMSRepoPagePresenter(this);
|
||||
}
|
||||
|
||||
@override
|
||||
AppBar get appBar => AppBar(
|
||||
title: Text('图床仓库'),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget buildEmtpy() {
|
||||
return Center(
|
||||
child: Text('数据空空如也噢'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildError() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
RaisedButton(
|
||||
color: Theme.of(context).accentColor,
|
||||
textColor: Colors.white,
|
||||
child: Text('刷新'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
this.state = LoadState.LOADING;
|
||||
// _presenter.doLoadContents(_path, _prePath);
|
||||
_presenter.doLoadContents();
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Text(this.errorMsg ?? '未知错误',
|
||||
style: TextStyle(color: Colors.grey[400])),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildLoading() {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
backgroundColor: Colors.transparent,
|
||||
valueColor: AlwaysStoppedAnimation(Colors.blue),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildSuccess() {
|
||||
return ListView.builder(
|
||||
itemCount: contents.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ManageItem(
|
||||
Key('$index'),
|
||||
contents[index].url,
|
||||
contents[index].filename,
|
||||
'${contents[index].size}k',
|
||||
FileContentType.FILE,
|
||||
onTap: () {
|
||||
launch(contents[index].url);
|
||||
},
|
||||
confirmDismiss: (direction) async {
|
||||
bool result = await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('确定删除吗'),
|
||||
content: Text('删除后无法恢复'),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('确定'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
}),
|
||||
],
|
||||
);
|
||||
});
|
||||
if (!(result ?? false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var del = await _presenter.doDeleteContents(contents[index].delete);
|
||||
return del;
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void loadError(String msg) {
|
||||
setState(() {
|
||||
this.state = LoadState.ERROR;
|
||||
this.errorMsg = msg;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void loadSuccess(List<SMMSContent> data) {
|
||||
if (data != null && data.length > 0) {
|
||||
setState(() {
|
||||
this.state = LoadState.SUCCESS;
|
||||
this.contents.clear();
|
||||
this.contents.addAll(data);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
this.state = LoadState.EMTPY;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_picgo/api/smms_api.dart';
|
||||
import 'package:flutter_picgo/model/smms_content.dart';
|
||||
|
||||
abstract class SMMSRepoPageContract {
|
||||
void loadSuccess(List<SMMSContent> data);
|
||||
|
||||
void loadError(String msg);
|
||||
}
|
||||
|
||||
class SMMSRepoPagePresenter {
|
||||
SMMSRepoPageContract _view;
|
||||
|
||||
SMMSRepoPagePresenter(this._view);
|
||||
|
||||
doLoadContents() async {
|
||||
try {
|
||||
var result = await SMMSApi.getUploadHistory();
|
||||
var resultmap = json.decode(result);
|
||||
if (resultmap["success"]) {
|
||||
_view.loadSuccess(resultmap['data']);
|
||||
} else {
|
||||
_view.loadError(resultmap['message'] ?? '未知错误');
|
||||
}
|
||||
} catch (e) {
|
||||
_view.loadError('$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> doDeleteContents(String path) async {
|
||||
try {
|
||||
var result = await SMMSApi.delete(path);
|
||||
var resultmap = json.decode(result);
|
||||
if (resultmap["success"]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_picgo/model/config.dart';
|
||||
import 'package:flutter_picgo/model/smms_config.dart';
|
||||
import 'package:flutter_picgo/resources/pb_type_keys.dart';
|
||||
import 'package:flutter_picgo/routers/application.dart';
|
||||
import 'package:flutter_picgo/routers/routers.dart';
|
||||
import 'package:flutter_picgo/utils/strings.dart';
|
||||
import 'package:flutter_picgo/views/pb_setting_page/base_pb_page_state.dart';
|
||||
|
||||
@@ -13,6 +16,7 @@ class SMMSPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SMMSPageState extends BasePBSettingPageState<SMMSPage> {
|
||||
|
||||
@override
|
||||
onLoadConfig(String config) {
|
||||
List<Config> configs = [];
|
||||
@@ -42,4 +46,15 @@ class _SMMSPageState extends BasePBSettingPageState<SMMSPage> {
|
||||
|
||||
@override
|
||||
String get title => 'SM.MS图床';
|
||||
|
||||
@override
|
||||
bool get isSupportManage => true;
|
||||
|
||||
@override
|
||||
handleManage() {
|
||||
Application.router.navigateTo(context,
|
||||
'${Routes.settingPbSMMSRepo}',
|
||||
transition: TransitionType.cupertino);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user