删除逻辑bug --淦

邮箱登录
修改本地服务名称
This commit is contained in:
octopusYan 2022-04-24 14:40:46 +08:00
parent c1651beebd
commit 6a702a1f89
5 changed files with 52 additions and 26 deletions

View File

@ -63,7 +63,7 @@ public class ProxyConfig {
UDP, UDP,
STCP, STCP,
XTCP, XTCP,
;
} }
public static String getServerPath(String serverName) { public static String getServerPath(String serverName) {

View File

@ -113,7 +113,7 @@ public class TextValidate {
RegexValidator validator = new RegexValidator(message); RegexValidator validator = new RegexValidator(message);
validator.setRegexPattern("[a-zA-Z0-9_-]{" + min + "," + max + "}$"); validator.setRegexPattern("[\\w@-_\\.]{" + min + "," + max + "}$");
return validator; return validator;
} }

View File

@ -16,6 +16,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import okhttp3.Call;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.kordamp.ikonli.javafx.FontIcon; import org.kordamp.ikonli.javafx.FontIcon;
@ -162,8 +163,8 @@ public class LoginController extends BaseController<StackPane> implements Initia
// 添加文本校验 // 添加文本校验
accountTextField.getValidators().add(TextValidate.AccoountRequired); accountTextField.getValidators().add(TextValidate.AccoountRequired);
accountTextField.getValidators().add(TextValidate.AccoountValidator); // accountTextField.getValidators().add(TextValidate.AccoountValidator);
accountTextField.getValidators().add(TextValidate.getLengthValidator(6, 18, "账号")); accountTextField.getValidators().add(TextValidate.getLengthValidator(6, 25, "账号"));
passwordTextField.getValidators().add(TextValidate.PasswordRequired); passwordTextField.getValidators().add(TextValidate.PasswordRequired);
seePwdTextField.getValidators().add(TextValidate.PasswordRequired); seePwdTextField.getValidators().add(TextValidate.PasswordRequired);
@ -261,6 +262,11 @@ public class LoginController extends BaseController<StackPane> implements Initia
.api(Api.Login) .api(Api.Login)
.param(new LoginParam(accountTextField.getText(), tmpPwd.get())) .param(new LoginParam(accountTextField.getText(), tmpPwd.get()))
.request(new OnHttpListener<String>() { .request(new OnHttpListener<String>() {
@Override
public void onStart(Call call) {
Platform.runLater(() -> loginBtn.setDisable(true));
}
@Override @Override
public void onSucceed(String result) { public void onSucceed(String result) {
// 登录出错 // 登录出错
@ -288,6 +294,11 @@ public class LoginController extends BaseController<StackPane> implements Initia
public void onFail(Exception e) { public void onFail(Exception e) {
} }
@Override
public void onEnd(Call call) {
Platform.runLater(() -> loginBtn.setDisable(false));
}
}); });
} }

View File

@ -538,7 +538,7 @@ public class MainController extends BaseController<StackPane> implements Initial
ProxySetup setup = proxySetupModel.get(); ProxySetup setup = proxySetupModel.get();
// 整理服务设置 // 整理服务设置
String serverName = getAccount() + "_" + setup.getSort(); String serverName = setup.getProxy_name() + "_" + setup.getSort();
setup.setServer_name(ApplicatonStore.getUserToken() + "." + EncryptionUtil.MD5_16(serverName)); setup.setServer_name(ApplicatonStore.getUserToken() + "." + EncryptionUtil.MD5_16(serverName));
setup.setId(null); setup.setId(null);
setup.setRuning(false); setup.setRuning(false);
@ -724,7 +724,7 @@ public class MainController extends BaseController<StackPane> implements Initial
private void initProxyListView() { private void initProxyListView() {
ObservableList<ProxySetup> proxyList = proxyList(); ObservableList<ProxySetup> proxyList = proxyList();
for (ProxySetup proxy : proxyList.subList(proxyListView.getItems().size(), proxyList.size())) { for (ProxySetup proxy : proxyList) {
setProxyListView(proxyList.indexOf(proxy), proxy); setProxyListView(proxyList.indexOf(proxy), proxy);
} }
// 设置选中 // 设置选中
@ -745,29 +745,46 @@ public class MainController extends BaseController<StackPane> implements Initial
// 运行状态 // 运行状态
itemView.setStatus(setup.isRuning()); itemView.setStatus(setup.isRuning());
// 点击删除 // 点击删除
itemView.getDeleteBtn().setOnMouseClicked(event -> { itemView.getDeleteBtn().setOnMouseClicked(event -> deleteProxyListItem(itemView));
if(items.size() == 1) {
AlertUtil.error("最后一个连接不可删除!").show();
return;
}
// 关闭连接
if (proxyList().get(index).isRuning()) {
frpUtilMap.get(String.valueOf(index)).stop();
}
// 调用删除接口
if (setup.getId() != null) {
ProxyManager.delete(setup.getId());
}
// 列表删除
items.remove(itemView);
});
// 是否选中 // 是否选中
if (selectProxy() == index) itemView.getStyleClass().add(PROXY_LIST_ITEM_SELECT_CLASS); if (selectProxy() == index) itemView.getStyleClass().add(PROXY_LIST_ITEM_SELECT_CLASS);
// 添加 // 添加
if (isNew) items.add(index, itemView); if (isNew) items.add(index, itemView);
} }
private void deleteProxyListItem(ProxyListItemView itemView) {
ObservableList<ProxyListItemView> items = proxyListView.getItems();
int index = items.indexOf(itemView);
if (index < 0) return;
if (items.size() == 1) {
AlertUtil.error("最后一个连接不可删除!").show();
return;
}
ProxySetup setup = proxyList().get(index);
// 关闭连接
String key = String.valueOf(setup.getId());
FrpManager frpManager = frpUtilMap.get(key);
if (setup.isRuning() || frpManager != null) {
frpManager.stop();
frpUtilMap.remove(key);
}
// 调用删除接口
if (setup.getId() != null) {
ProxyManager.delete(setup.getId());
}
// 列表删除
items.remove(itemView);
proxyList().remove(setup);
// 重新选择
if (selectProxy() == index) {
proxyListView.getSelectionModel().select(-1);
proxyListView.getSelectionModel().select(index < items.size() ? index : items.size() - 1);
} else if (selectProxy() > index)
selectProxy(selectProxy() - 1);
}
/** /**
* 启动代理 * 启动代理
*/ */

View File

@ -174,7 +174,7 @@ public class FrpManager {
// 基础配置 // 基础配置
StringBuilder stringBuilder = new StringBuilder("["); StringBuilder stringBuilder = new StringBuilder("[");
// 服务名称 // 服务名称
StringBuilder serverName = new StringBuilder(ApplicatonStore.getAccount() + "_" + setup.getSort()); StringBuilder serverName = new StringBuilder(setup.getProxyName()).append("_").append(setup.getSort());
// p2p 服务名 // p2p 服务名
if (isp2p) { if (isp2p) {
if (setup.isProvider()) { if (setup.isProvider()) {
@ -184,8 +184,6 @@ public class FrpManager {
// 访问者 // 访问者
serverName = new StringBuilder(setup.getServerName()).append("_visitor"); serverName = new StringBuilder(setup.getServerName()).append("_visitor");
} }
} else {
serverName.append(ApplicatonStore.getAccount()).append("_").append(setup.getSort());
} }
stringBuilder.append(serverName).append("]\n"); stringBuilder.append(serverName).append("]\n");
stringBuilder.append("privilege_mode = true\n") stringBuilder.append("privilege_mode = true\n")