移到新目錄(gogs) 並優化 login 及上傳圖片機制
This commit is contained in:
+23
-6
@@ -8,8 +8,8 @@ import './auth_manager.dart'; // 確保路徑正確
|
||||
|
||||
// API 相關常數
|
||||
const String BASE_IP = "https://api.gex.com.tw:8033";
|
||||
const String API_ENDPOINT = "xapi/v1/eis_demo/checklogin/2/";
|
||||
const String API_URL = "$BASE_IP/$API_ENDPOINT";
|
||||
//const String API_ENDPOINT = "xapi/v1/eis_demo/checklogin/2/";
|
||||
//const String API_URL = "$BASE_IP/$API_ENDPOINT";
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
@@ -22,6 +22,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
// 用於獲取輸入框內容
|
||||
final TextEditingController _userController = TextEditingController(text: '120102'); // 預設帳號
|
||||
final TextEditingController _pwdController = TextEditingController(text: 'gex123'); // 預設密碼
|
||||
final TextEditingController _compController = TextEditingController(text: 'demo'); // [新增] 預設值
|
||||
|
||||
bool _isLoading = false;
|
||||
String? _errorMessage;
|
||||
@@ -33,7 +34,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
// 登入邏輯,模擬您的 JS logon() 函數
|
||||
Future<void> _logon() async {
|
||||
if (_userController.text.isEmpty || _pwdController.text.isEmpty) {
|
||||
if (_userController.text.isEmpty || _pwdController.text.isEmpty || _compController.text.isEmpty) {
|
||||
setState(() {
|
||||
_errorMessage = '請輸入帳號和密碼';
|
||||
});
|
||||
@@ -60,8 +61,12 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
try {
|
||||
// 執行 POST 請求。使用 application/x-www-form-urlencoded 格式
|
||||
// [關鍵] 動態組合登入 API 網址,取代固定的 eis_demo
|
||||
final String comp = _compController.text.trim().toLowerCase();
|
||||
final String loginUrl = "$BASE_IP/xapi/v1/eis_$comp/checklogin/2/";
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(API_URL),
|
||||
Uri.parse(loginUrl),
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@@ -82,7 +87,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
: null;
|
||||
|
||||
if (token != null && token.isNotEmpty) {
|
||||
await AuthManager.saveLoginInfo(token, userId); // 呼叫 AuthManager 儲存 Token
|
||||
await AuthManager.saveLoginInfo(token, userId, comp); // 呼叫 AuthManager 儲存 Token
|
||||
} else {
|
||||
print("警告: 登入成功但未收到 Token,將不儲存。");
|
||||
}
|
||||
@@ -126,6 +131,18 @@ class _LoginPageState extends State<LoginPage> {
|
||||
const Icon(Icons.lock_open, size: 80, color: Colors.blue),
|
||||
const SizedBox(height: 48.0),
|
||||
|
||||
// 公司別輸入框
|
||||
TextField(
|
||||
controller: _compController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '公司代號',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.person),
|
||||
),
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
|
||||
// 帳號輸入框
|
||||
TextField(
|
||||
controller: _userController,
|
||||
@@ -149,7 +166,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
onSubmitted: (_) => _logon(), // 允許按 Enter 鍵登入
|
||||
),
|
||||
const SizedBox(height: 24.0),
|
||||
const SizedBox(height: 16.0),
|
||||
|
||||
// 錯誤訊息顯示
|
||||
if (_errorMessage != null)
|
||||
|
||||
Reference in New Issue
Block a user