feat: 资料编辑
This commit is contained in:
@ -592,4 +592,10 @@ class Api {
|
||||
/// 直播间记录
|
||||
static const String liveRoomEntry =
|
||||
'${HttpString.liveBaseUrl}/xlive/web-room/v1/index/roomEntryAction';
|
||||
|
||||
/// 用户信息
|
||||
static const String accountInfo = '/x/member/web/account';
|
||||
|
||||
/// 更新用户信息
|
||||
static const String updateAccountInfo = '/x/member/web/update';
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:pilipala/models/video/later.dart';
|
||||
@ -537,4 +538,53 @@ class UserHttp {
|
||||
.toList()
|
||||
};
|
||||
}
|
||||
|
||||
static Future getAccountInfo() async {
|
||||
var res = await Request().get(
|
||||
Api.accountInfo,
|
||||
data: {'web_location': 333.33},
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'data': {},
|
||||
'mag': res.data['message'],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static Future updateAccountInfo({
|
||||
required String uname,
|
||||
required String sign,
|
||||
required String sex,
|
||||
required String birthday,
|
||||
}) async {
|
||||
var res = await Request().post(
|
||||
Api.updateAccountInfo,
|
||||
data: {
|
||||
'uname': uname,
|
||||
'usersign': sign,
|
||||
'sex': sex,
|
||||
'birthday': birthday,
|
||||
'csrf': await Request.getCsrf(),
|
||||
},
|
||||
options: Options(contentType: Headers.formUrlEncodedContentType),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'msg': '更新成功',
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/models/live/item.dart';
|
||||
@ -233,7 +232,7 @@ class ProfilePanel extends StatelessWidget {
|
||||
if (ctr.ownerMid == ctr.mid && ctr.ownerMid != -1) ...[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SmartDialog.showToast('功能开发中 💪');
|
||||
Get.toNamed('/mineEdit');
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.only(left: 80, right: 80),
|
||||
|
45
lib/pages/mine_edit/controller.dart
Normal file
45
lib/pages/mine_edit/controller.dart
Normal file
@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/user.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
class MineEditController extends GetxController {
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
final TextEditingController unameCtr = TextEditingController();
|
||||
final TextEditingController useridCtr = TextEditingController();
|
||||
final TextEditingController signCtr = TextEditingController();
|
||||
final TextEditingController birthdayCtr = TextEditingController();
|
||||
String? sex;
|
||||
dynamic userInfo;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
}
|
||||
|
||||
Future getAccountInfo() async {
|
||||
var res = await UserHttp.getAccountInfo();
|
||||
if (res['status']) {
|
||||
unameCtr.text = res['data']['uname'];
|
||||
useridCtr.text = res['data']['userid'];
|
||||
signCtr.text = res['data']['sign'];
|
||||
birthdayCtr.text = res['data']['birthday'];
|
||||
sex = res['data']['sex'];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future updateAccountInfo() async {
|
||||
var res = await UserHttp.updateAccountInfo(
|
||||
uname: unameCtr.text,
|
||||
sign: signCtr.text,
|
||||
sex: sex!,
|
||||
birthday: birthdayCtr.text,
|
||||
);
|
||||
SmartDialog.showToast(res['status'] ? res['msg'] : "更新失败:${res['msg']}");
|
||||
}
|
||||
}
|
4
lib/pages/mine_edit/index.dart
Normal file
4
lib/pages/mine_edit/index.dart
Normal file
@ -0,0 +1,4 @@
|
||||
library mine_edit;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
177
lib/pages/mine_edit/view.dart
Normal file
177
lib/pages/mine_edit/view.dart
Normal file
@ -0,0 +1,177 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
class MineEditPage extends StatefulWidget {
|
||||
const MineEditPage({super.key});
|
||||
|
||||
@override
|
||||
State<MineEditPage> createState() => _MineEditPageState();
|
||||
}
|
||||
|
||||
class _MineEditPageState extends State<MineEditPage> {
|
||||
final MineEditController ctr = Get.put(MineEditController());
|
||||
late Future _futureBuilderFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilderFuture = ctr.getAccountInfo();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('编辑资料'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: ((context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
if (snapshot.data['status']) {
|
||||
return Form(
|
||||
key: ctr.formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
// 用户头像
|
||||
// InkWell(
|
||||
// onTap: () {},
|
||||
// child: CircleAvatar(
|
||||
// radius: 50,
|
||||
// backgroundColor: Colors.transparent,
|
||||
// backgroundImage:
|
||||
// NetworkImage(ctr.userInfo.face), // 替换为实际的头像路径
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 24.0),
|
||||
// 昵称
|
||||
TextFormField(
|
||||
controller: ctr.unameCtr,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '昵称',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入昵称';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
// 用户名
|
||||
TextFormField(
|
||||
controller: ctr.useridCtr,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '用户名',
|
||||
border: OutlineInputBorder(),
|
||||
enabled: false,
|
||||
),
|
||||
readOnly: true,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
// 签名
|
||||
TextFormField(
|
||||
controller: ctr.signCtr,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '签名',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入签名';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
// 性别
|
||||
DropdownButtonFormField<String>(
|
||||
value: ctr.sex,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '性别',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: ['男', '女', '保密'].map((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (newValue) {
|
||||
ctr.sex = newValue;
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请选择性别';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
// 出生日期
|
||||
TextFormField(
|
||||
controller: ctr.birthdayCtr,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '出生日期',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
enabled: false,
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
// DateTime? pickedDate = await showDatePicker(
|
||||
// context: context,
|
||||
// initialDate: DateTime(1995, 12, 23),
|
||||
// firstDate: DateTime(1900),
|
||||
// lastDate: DateTime(2100),
|
||||
// );
|
||||
// if (pickedDate != null) {
|
||||
// ctr.birthdayCtr.text =
|
||||
// "${pickedDate.toLocal()}".split(' ')[0];
|
||||
// }
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请选择出生日期';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 30.0),
|
||||
// 提交按钮
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (ctr.formKey.currentState!.validate()) {
|
||||
// 处理表单提交
|
||||
ctr.updateAccountInfo();
|
||||
}
|
||||
},
|
||||
child: const Text('提交'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
})),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import 'package:pilipala/pages/message/like/index.dart';
|
||||
import 'package:pilipala/pages/message/reply/index.dart';
|
||||
import 'package:pilipala/pages/message/system/index.dart';
|
||||
import 'package:pilipala/pages/mine/index.dart';
|
||||
import 'package:pilipala/pages/mine_edit/index.dart';
|
||||
import 'package:pilipala/pages/opus/index.dart';
|
||||
import 'package:pilipala/pages/read/index.dart';
|
||||
import 'package:pilipala/pages/setting/pages/logs.dart';
|
||||
@ -196,6 +197,8 @@ class Routes {
|
||||
// 用户专栏
|
||||
CustomGetPage(
|
||||
name: '/memberArticle', page: () => const MemberArticlePage()),
|
||||
// 用户信息编辑
|
||||
CustomGetPage(name: '/mineEdit', page: () => const MineEditPage()),
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user