李志伟 3 gadus atpakaļ
vecāks
revīzija
a03ef0b52d

+ 1
- 0
lib/pages/Login/index.dart Parādīt failu

@@ -86,6 +86,7 @@ class _Login extends State<Login> {
86 86
             Fluttertoast.showToast(msg: '登录成功!');
87 87
             Get.offNamed('/home');
88 88
           }).catchError((err) {
89
+            print(err);
89 90
             Fluttertoast.showToast(msg: err);
90 91
           });
91 92
         } else {

+ 1
- 0
lib/pages/index.dart Parādīt failu

@@ -10,4 +10,5 @@ export 'machineryDetail/index.dart';
10 10
 export 'machineryMap/index.dart';
11 11
 export 'bankList/index.dart';
12 12
 export 'addBankCard/index.dart';
13
+export 'userInfo/index.dart';
13 14
 

+ 0
- 1
lib/pages/machineryMap/index.dart Parādīt failu

@@ -13,7 +13,6 @@ class MachineryMap extends BasicPage {
13 13
 
14 14
   @override
15 15
   void beforeShow() {
16
-    // TODO: implement beforeShow
17 16
     super.beforeShow();
18 17
     if (Get.arguments != null) {
19 18
       getMachineryDetail(Get.arguments['id'], {

+ 6
- 2
lib/pages/main/index.dart Parādīt failu

@@ -41,6 +41,9 @@ class Main extends BasicPage {
41 41
       Get.toNamed('/bankList');
42 42
     // }
43 43
   }
44
+  void goUserInfo(){
45
+    Get.toNamed('/userInfo');
46
+  }
44 47
 
45 48
   @override
46 49
   Widget builder(BuildContext context) {
@@ -225,6 +228,7 @@ class Main extends BasicPage {
225 228
                         EdgeInsets.symmetric(horizontal: 15.w, vertical: 0),
226 229
                     child: Column(
227 230
                       children: [
231
+
228 232
                         MyCell(
229 233
                           head: Image.asset(
230 234
                             'images/main/account.png',
@@ -234,7 +238,7 @@ class Main extends BasicPage {
234 238
                             '账号与安全',
235 239
                             style: TextStyle(
236 240
                               fontSize: 17.sp,
237
-                              color: Color(0xff333333),
241
+                              color: const Color(0xff333333),
238 242
                               fontWeight: FontWeight.bold,
239 243
                             ),
240 244
                           ),
@@ -242,7 +246,7 @@ class Main extends BasicPage {
242 246
                             'images/main/goto.png',
243 247
                             width: 10.w,
244 248
                           ),
245
-                          onClick: () {},
249
+                          onClick: () {goUserInfo();},
246 250
                         ),
247 251
                         MyCell(
248 252
                           head: Image.asset(

+ 260
- 0
lib/pages/userInfo/index.dart Parādīt failu

@@ -0,0 +1,260 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:flutter_screenutil/flutter_screenutil.dart';
3
+import 'package:fluttertoast/fluttertoast.dart';
4
+import 'package:get/get.dart';
5
+import 'package:worker_client/models/app.dart';
6
+import 'package:worker_client/models/entities/person.dart';
7
+import 'package:worker_client/services/user.dart';
8
+import 'package:worker_client/widgets/MyButton/index.dart';
9
+import 'package:worker_client/widgets/layout/BasicPage.dart';
10
+
11
+class UserInfo extends BasicPage {
12
+  UserInfo({Key? key}) : super(key: key);
13
+
14
+  AppController store = AppController.t;
15
+  late String name;
16
+  late String phone;
17
+  late TextEditingController _cName;
18
+  late TextEditingController _cPhone;
19
+
20
+  @override
21
+  void beforeShow() {
22
+    // TODO: implement beforeShow
23
+    super.beforeShow();
24
+    _cName = TextEditingController(text: store.user().nickName.toString());
25
+    _cPhone = TextEditingController(text: store.user().phone.toString());
26
+    name = store.user().nickName.toString();
27
+    phone = store.user().phone.toString();
28
+  }
29
+  RegExp exp = RegExp(r'^1[3456789]\d{9}$');
30
+
31
+  void handleOk() {
32
+    if (name == '' && phone == '') {
33
+      Fluttertoast.showToast(msg: '请输入您需要修改的信息');
34
+      return;
35
+    } else if (phone != '' && !exp.hasMatch(phone)) {
36
+      Fluttertoast.showToast(msg: '请输入正确的手机号');
37
+      return;
38
+    } else {
39
+      updateInfo(store.user().personId.toString(), {
40
+        ...store.user().toJson(),
41
+        'nickName': name,
42
+        'phone': phone
43
+      }).then((value) {
44
+        Fluttertoast.showToast(msg: '修改成功');
45
+        store.user(Person.fromJson(value));
46
+        Get.offNamed('/main');
47
+      });
48
+    }
49
+  }
50
+
51
+  @override
52
+  Widget builder(BuildContext context) {
53
+    naviTitle = '个人信息';
54
+    return Container(
55
+      padding: EdgeInsets.all(15.w),
56
+      decoration: const BoxDecoration(color: Colors.white),
57
+      child: Column(
58
+        children: [
59
+          Container(
60
+            width: 345.w,
61
+            height: 92.h,
62
+            alignment: Alignment.centerLeft,
63
+            decoration: BoxDecoration(color: Colors.white, boxShadow: [
64
+              BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
65
+            ]),
66
+            child: store.user().avatar != null
67
+                ? Container(
68
+                    clipBehavior: Clip.hardEdge,
69
+                    decoration: BoxDecoration(
70
+                        borderRadius: BorderRadius.all(Radius.circular(31.w))),
71
+                    child: Image.network(
72
+                      store.user().avatar.toString(),
73
+                      width: 62.w,
74
+                      height: 62.w,
75
+                    ),
76
+                  )
77
+                : Image.asset(
78
+                    'images/main/defaultAvatar.png',
79
+                    width: 62.w,
80
+                    height: 62.w,
81
+                  ),
82
+          ),
83
+          Container(
84
+              width: 345.w,
85
+              alignment: Alignment.centerLeft,
86
+              margin: EdgeInsets.only(top: 40.h),
87
+              decoration: BoxDecoration(color: Colors.white, boxShadow: [
88
+                BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
89
+              ]),
90
+              child: Column(
91
+                crossAxisAlignment: CrossAxisAlignment.start,
92
+                children: [
93
+                  Text(
94
+                    '用户名:',
95
+                    style: TextStyle(
96
+                        color: const Color(0xFF333333),
97
+                        letterSpacing: 2,
98
+                        fontSize: 17.sp,
99
+                        fontWeight: FontWeight.bold),
100
+                  ),
101
+                  Container(
102
+                    height: 54.h,
103
+                    alignment: Alignment.centerLeft,
104
+                    child: store.user().userName != null
105
+                        ? Text(
106
+                            store.user().userName.toString(),
107
+                            style: TextStyle(
108
+                                color: const Color(0xFF333333),
109
+                                fontSize: 17.sp,
110
+                                fontWeight: FontWeight.bold),
111
+                          )
112
+                        : const Text(''),
113
+                  ),
114
+                ],
115
+              )),
116
+          Container(
117
+            width: 345.w,
118
+            alignment: Alignment.centerLeft,
119
+            margin: EdgeInsets.only(top: 40.h),
120
+            decoration: BoxDecoration(color: Colors.white, boxShadow: [
121
+              BoxShadow(color: const Color(0x1f000000), offset: Offset(0, 1.w))
122
+            ]),
123
+            child: Column(
124
+              crossAxisAlignment: CrossAxisAlignment.start,
125
+              children: [
126
+                Text(
127
+                  '姓名:',
128
+                  style: TextStyle(
129
+                      color: const Color(0xFF333333),
130
+                      fontSize: 17.sp,
131
+                      fontWeight: FontWeight.bold,
132
+                      letterSpacing: 2),
133
+                ),
134
+                Container(
135
+                  height: 54.h,
136
+                  alignment: Alignment.centerLeft,
137
+                  child: Row(
138
+                    children: [
139
+                      Expanded(
140
+                        flex: 1,
141
+                        child: TextField(
142
+                          controller: _cName,
143
+                          style: TextStyle(
144
+                              fontSize: 17.sp,
145
+                              fontWeight: FontWeight.bold,
146
+                              color: const Color(0xff333333)),
147
+                          decoration: const InputDecoration(
148
+                            isCollapsed: true,
149
+                            hintText: '请输入您的姓名',
150
+                            counterText: '', //去掉右下角的东西
151
+                            border: InputBorder.none,
152
+                            floatingLabelBehavior: FloatingLabelBehavior.never,
153
+                          ),
154
+                          onChanged: (val) {
155
+                            name = val;
156
+                          },
157
+                        ),
158
+                      ),
159
+                      GestureDetector(
160
+                        behavior: HitTestBehavior.opaque,
161
+                        onTap: () {
162
+                          name = '';
163
+                          _cName.clear();
164
+                        },
165
+                        child: Container(
166
+                          width: 50.w,
167
+                          alignment: Alignment.center,
168
+                          child: Image.asset(
169
+                            'images/main/cancel.png',
170
+                            width: 18.w,
171
+                          ),
172
+                        ),
173
+                      )
174
+                    ],
175
+                  ),
176
+                ),
177
+              ],
178
+            ),
179
+          ),
180
+          Container(
181
+            width: 345.w,
182
+            alignment: Alignment.centerLeft,
183
+            margin: EdgeInsets.only(top: 40.h),
184
+            decoration: BoxDecoration(color: Colors.white, boxShadow: [
185
+              BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
186
+            ]),
187
+            child: Column(
188
+              crossAxisAlignment: CrossAxisAlignment.start,
189
+              children: [
190
+                Text(
191
+                  '手机号:',
192
+                  style: TextStyle(
193
+                      color: const Color(0xFF333333),
194
+                      letterSpacing: 2,
195
+                      fontSize: 17.sp,
196
+                      fontWeight: FontWeight.bold),
197
+                ),
198
+                Container(
199
+                  height: 54.h,
200
+                  alignment: Alignment.centerLeft,
201
+                  child: Row(
202
+                    children: [
203
+                      Expanded(
204
+                        flex: 1,
205
+                        child: TextField(
206
+                          //赋初值
207
+                          controller: _cPhone,
208
+                          maxLength: 11,
209
+                          keyboardType: TextInputType.number,
210
+                          style: TextStyle(
211
+                              fontSize: 17.sp,
212
+                              fontWeight: FontWeight.bold,
213
+                              color: const Color(0xff333333)),
214
+                          decoration: const InputDecoration(
215
+                            isCollapsed: true,
216
+                            hintText: '请输入您的手机号',
217
+                            counterText: '', //去掉右下角的东西
218
+                            border: InputBorder.none,
219
+                            floatingLabelBehavior: FloatingLabelBehavior.never,
220
+                          ),
221
+                          onChanged: (val) {
222
+                            phone = val;
223
+                          },
224
+                        ),
225
+                      ),
226
+                      GestureDetector(
227
+                        behavior: HitTestBehavior.opaque,
228
+                        onTap: () {
229
+                          phone = '';
230
+                          _cPhone.clear();
231
+                        },
232
+                        child: Container(
233
+                          width: 50.w,
234
+                          alignment: Alignment.center,
235
+                          child: Image.asset(
236
+                            'images/main/cancel.png',
237
+                            width: 18.w,
238
+                          ),
239
+                        ),
240
+                      ),
241
+                    ],
242
+                  ),
243
+                ),
244
+              ],
245
+            ),
246
+          ),
247
+          const Spacer(),
248
+          MyButton(
249
+              text: '保存',
250
+              type: 0,
251
+              pwith: 30.w,
252
+              disable: false,
253
+              onClick: () {
254
+                handleOk();
255
+              })
256
+        ],
257
+      ),
258
+    );
259
+  }
260
+}

+ 1
- 0
lib/routes/pages.dart Parādīt failu

@@ -21,4 +21,5 @@ List<GetPage> pages=[
21 21
   GetPage(name: '/machineryMap', page: () => MachineryMap()),
22 22
   GetPage(name: '/bankList', page: () => BankListPages()),
23 23
   GetPage(name: '/addBankCard', page: () => AddBankPage()),
24
+  GetPage(name: '/userInfo', page: () => UserInfo()),
24 25
 ];

+ 12
- 0
lib/services/user.dart Parādīt failu

@@ -26,3 +26,15 @@ Future userLogin(String userName, String password) async {
26 26
 Future getCurrent() async {
27 27
   return request('/person/current');
28 28
 }
29
+/**
30
+ * 修改个人信息
31
+ * @param {*}
32
+ * @returns
33
+ */
34
+
35
+Future updateInfo(String id, Map data) async {
36
+  return request('/person/${id}', options: Options(method: 'PUT'), data: data)
37
+      .catchError((error) => {
38
+            Fluttertoast.showToast(msg: error.error['message']),
39
+          });
40
+}

+ 4
- 3
lib/widgets/MyButton/index.dart Parādīt failu

@@ -6,19 +6,20 @@ import '../GradientButton.dart';
6 6
 
7 7
 class MyButton extends StatelessWidget {
8 8
   final String text;
9
-  //type 1 绿色 2 黄色
9
+  //type 0 绿色 1 黄色
10 10
   final int type;
11 11
   //true 有结束动画 false 无变化
12 12
   final bool disable;
13 13
   //点击事件
14 14
   final GestureTapCallback onClick;
15
+  final double? pwith;
15 16
 
16 17
   MyButton(
17 18
       {Key? key,
18 19
       required this.text,
19 20
       required this.type,
20 21
       required this.disable,
21
-      required this.onClick})
22
+      required this.onClick, this.pwith})
22 23
       : super(key: key);
23 24
 
24 25
   List<GradientModel> Glist=[
@@ -29,7 +30,7 @@ class MyButton extends StatelessWidget {
29 30
   Widget build(BuildContext context) {
30 31
     return Container(
31 32
       margin: EdgeInsets.fromLTRB(0, 12.5.h, 0, 9.h),
32
-      width: 315.w,
33
+      width: 315.w+(pwith??0),
33 34
       height: 49.h,
34 35
       child: GradientButton(
35 36
           colors: [Glist[type].beginColor,Glist[type].endColor],