Merge branch 'xinnan-tech:main' into main

This commit is contained in:
lovelyyoshino 2025-05-19 09:59:58 +08:00 committed by GitHub
commit b9f3b0d169
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 1527 additions and 428 deletions

View file

@ -28,6 +28,8 @@
<captcha.version>1.6.2</captcha.version> <captcha.version>1.6.2</captcha.version>
<guava.version>33.0.0-jre</guava.version> <guava.version>33.0.0-jre</guava.version>
<liquibase-core.version>4.20.0</liquibase-core.version> <liquibase-core.version>4.20.0</liquibase-core.version>
<aliyun-sms-version>4.1.0</aliyun-sms-version>
<okio-version>3.4.0</okio-version>
</properties> </properties>
<dependencies> <dependencies>
@ -37,6 +39,7 @@
<classifier>jakarta</classifier> <classifier>jakarta</classifier>
<version>${shiro.version}</version> <version>${shiro.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.shiro</groupId> <groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId> <artifactId>shiro-spring</artifactId>
@ -201,6 +204,18 @@
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
</dependency> </dependency>
<!-- 阿里云短信sdk -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>${aliyun-sms-version}</version>
</dependency>
<!-- 阿里云短信sdk使用的okio:1.15.0版本有安全漏洞:GHSA-w33c-445m-f8w7 现在升级成3.4.0安全版本-->
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>${okio-version}</version>
</dependency>
</dependencies> </dependencies>
<!-- 阿里云maven仓库 --> <!-- 阿里云maven仓库 -->

View file

@ -153,6 +153,46 @@ public interface Constant {
} }
} }
/**
* 系统短信
*/
enum SysMSMParam {
/**
* 阿里云授权keyID
*/
ALIYUN_SMS_ACCESS_KEY_ID("aliyun.sms.access_key_id"),
/**
* 阿里云授权密钥
*/
ALIYUN_SMS_ACCESS_KEY_SECRET("aliyun.sms.access_key_secret"),
/**
* 阿里云短信签名
*/
ALIYUN_SMS_SIGN_NAME("aliyun.sms.sign_name"),
/**
* 阿里云短信模板
*/
ALIYUN_SMS_SMS_CODE_TEMPLATE_CODE("aliyun.sms.sms_code_template_code"),
/**
* 单号码最大短信发送条数
*/
SYSTEM_SMS_MAX_SEND_COUNT("system.sms.max_send_count"),
/**
* 是否开启手机注册
*/
SYSTEM_ENABLE_MOBILE_REGISTER("system.enable_mobile_register");
private String value;
SysMSMParam(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
/** /**
* 数据状态 * 数据状态
*/ */
@ -199,7 +239,7 @@ public interface Constant {
/** /**
* 版本号 * 版本号
*/ */
public static final String VERSION = "0.4.3"; public static final String VERSION = "0.4.4";
/** /**
* 无效固件URL * 无效固件URL

View file

@ -20,7 +20,7 @@ public interface ErrorCode {
int ACCOUNT_DISABLE = 10005; int ACCOUNT_DISABLE = 10005;
int IDENTIFIER_NOT_NULL = 10006; int IDENTIFIER_NOT_NULL = 10006;
int CAPTCHA_ERROR = 10007; int CAPTCHA_ERROR = 10007;
int SUB_MENU_EXIST = 10008; int PHONE_NOT_NULL = 10008;
int PASSWORD_ERROR = 10009; int PASSWORD_ERROR = 10009;
int SUPERIOR_DEPT_ERROR = 10011; int SUPERIOR_DEPT_ERROR = 10011;

View file

@ -1,7 +1,13 @@
package xiaozhi.common.exception; package xiaozhi.common.exception;
import java.util.List;
import java.util.Objects;
import org.apache.shiro.authz.UnauthorizedException; import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException; import org.springframework.web.servlet.resource.NoResourceFoundException;
@ -60,4 +66,15 @@ public class RenExceptionHandler {
return new Result<Void>().error(404, "资源不存在"); return new Result<Void>().error(404, "资源不存在");
} }
@ExceptionHandler(MethodArgumentNotValidException.class)
public Result<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
String errorMsg = allErrors.stream()
.filter(Objects::nonNull)
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.findFirst()
.orElse("");
return new Result<Void>().error(400, errorMsg);
}
} }

View file

@ -117,4 +117,26 @@ public class RedisKeys {
public static String getAgentAudioIdKey(String uuid) { public static String getAgentAudioIdKey(String uuid) {
return "agent:audio:id:" + uuid; return "agent:audio:id:" + uuid;
} }
/**
* 获取短信验证码的缓存key
*/
public static String getSMSValidateCodeKey(String phone) {
return "sms:Validate:Code:" + phone;
}
/**
* 获取短信验证码最后发送时间的缓存key
*/
public static String getSMSLastSendTimeKey(String phone) {
return "sms:Validate:Code:" + phone + ":last_send_time";
}
/**
* 获取短信验证码今日发送次数的缓存key
*/
public static String getSMSTodayCountKey(String phone) {
return "sms:Validate:Code:" + phone + ":today_count";
}
} }

View file

@ -1,6 +1,7 @@
package xiaozhi.common.service.impl; package xiaozhi.common.service.impl;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -18,6 +19,7 @@ import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@ -45,6 +47,12 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
* @param params 分页查询参数 * @param params 分页查询参数
* @param defaultOrderField 默认排序字段 * @param defaultOrderField 默认排序字段
* @param isAsc 排序方式 * @param isAsc 排序方式
* @see xiaozhi.common.constant.Constant
* params.put(Constant.PAGE, "1");
* params.put(Constant.LIMIT, "10");
* params.put(Constant.ORDER_FIELD, "field"); // 单个字段
* params.put(Constant.ORDER_FIELD, List.of("field1", "field2")); // 多个字段
* params.put(Constant.ORDER, "asc");
*/ */
protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) { protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) {
// 分页参数 // 分页参数
@ -65,29 +73,35 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
params.put(Constant.PAGE, page); params.put(Constant.PAGE, page);
// 排序字段 // 排序字段
String orderField = (String) params.get(Constant.ORDER_FIELD); Object orderField = params.get(Constant.ORDER_FIELD);
String order = (String) params.get(Constant.ORDER); String order = (String) params.get(Constant.ORDER);
// 前端字段排序 List<String> orderFields = new ArrayList<>();
if (StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)) {
if (Constant.ASC.equalsIgnoreCase(order)) { // 处理排序字段
return page.addOrder(OrderItem.asc(orderField)); if (orderField instanceof String) {
orderFields.add((String) orderField);
} else if (orderField instanceof List) {
orderFields.addAll((List<String>) orderField);
}
// 有排序字段则排序
if (CollectionUtils.isNotEmpty(orderFields)) {
if (StringUtils.isNotBlank(order) && Constant.ASC.equalsIgnoreCase(order)) {
return page.addOrder(OrderItem.ascs(orderFields.toArray(new String[0])));
} else { } else {
return page.addOrder(OrderItem.desc(orderField)); return page.addOrder(OrderItem.descs(orderFields.toArray(new String[0])));
} }
} }
// 没有排序字段,则不排序 // 没有排序字段,使用默认排序
if (StringUtils.isBlank(defaultOrderField)) { if (StringUtils.isNotBlank(defaultOrderField)) {
return page;
}
// 默认排序
if (isAsc) { if (isAsc) {
page.addOrder(OrderItem.asc(defaultOrderField)); page.addOrder(OrderItem.asc(defaultOrderField));
} else { } else {
page.addOrder(OrderItem.desc(defaultOrderField)); page.addOrder(OrderItem.desc(defaultOrderField));
} }
}
return page; return page;
} }

View file

@ -2,6 +2,7 @@ package xiaozhi.common.validator;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -45,4 +46,32 @@ public class ValidatorUtils {
throw new RenException(constraint.getMessage()); throw new RenException(constraint.getMessage());
} }
} }
/**
* 国际手机号正则表达式
* 要求必须带国际区号,格式:+[国家代码][手机号]
* 例如:
* - +8613800138000
* - +12345678900
* - +447123456789
*/
private static final String INTERNATIONAL_PHONE_REGEX = "^\\+[1-9]\\d{0,3}[1-9]\\d{4,14}$";
/**
* 校验手机号是否有效
* 要求必须带国际区号,格式:+[国家代码][手机号]
* 例如:+8613800138000
*
* @param phone 手机号
* @return boolean
*/
public static boolean isValidPhone(String phone) {
if (phone == null || phone.isEmpty()) {
return false;
}
// 验证必须带国际区号的手机号格式
Pattern pattern = Pattern.compile(INTERNATIONAL_PHONE_REGEX);
return pattern.matcher(phone).matches();
}
} }

View file

@ -0,0 +1,68 @@
package xiaozhi.modules.model.controller;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import xiaozhi.common.page.PageData;
import xiaozhi.common.utils.Result;
import xiaozhi.common.validator.group.UpdateGroup;
import xiaozhi.modules.model.dto.ModelProviderDTO;
import xiaozhi.modules.model.service.ModelProviderService;
@AllArgsConstructor
@RestController
@RequestMapping("/models/provider")
@Tag(name = "模型供应器")
public class ModelProviderController {
private final ModelProviderService modelProviderService;
@GetMapping
@Operation(summary = "获取模型供应器列表")
@RequiresPermissions("sys:role:superAdmin")
public Result<PageData<ModelProviderDTO>> getListPage(ModelProviderDTO modelProviderDTO,
@RequestParam(required = true, defaultValue = "0") String page,
@RequestParam(required = true, defaultValue = "10") String limit) {
return new Result<PageData<ModelProviderDTO>>()
.ok(modelProviderService.getListPage(modelProviderDTO, page, limit));
}
@PostMapping
@Operation(summary = "新增模型供应器")
@RequiresPermissions("sys:role:superAdmin")
public Result<ModelProviderDTO> add(@RequestBody @Validated ModelProviderDTO modelProviderDTO) {
ModelProviderDTO resp = modelProviderService.add(modelProviderDTO);
return new Result<ModelProviderDTO>().ok(resp);
}
@PutMapping
@Operation(summary = "修改模型供应器")
@RequiresPermissions("sys:role:superAdmin")
public Result<ModelProviderDTO> edit(@RequestBody @Validated(UpdateGroup.class) ModelProviderDTO modelProviderDTO) {
ModelProviderDTO resp = modelProviderService.edit(modelProviderDTO);
return new Result<ModelProviderDTO>().ok(resp);
}
@PostMapping("/delete")
@Operation(summary = "删除模型供应器")
@RequiresPermissions("sys:role:superAdmin")
@Parameter(name = "ids", description = "ID数组", required = true)
public Result<Void> delete(@RequestBody List<String> ids) {
modelProviderService.delete(ids);
return new Result<>();
}
}

View file

@ -8,29 +8,37 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import xiaozhi.common.validator.group.UpdateGroup;
@Data @Data
@Schema(description = "模型供应器/商") @Schema(description = "模型供应器/商")
public class ModelProviderDTO implements Serializable { public class ModelProviderDTO implements Serializable {
// @Schema(description = "主键")
// @Schema(description = "主键") @NotBlank(message = "id不能为空", groups = UpdateGroup.class)
// private Long id; private String id;
@Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)")
@NotBlank(message = "modelType不能为空")
private String modelType; private String modelType;
@Schema(description = "供应器类型") @Schema(description = "供应器类型")
@NotBlank(message = "providerCode不能为空")
private String providerCode; private String providerCode;
@Schema(description = "供应器名称") @Schema(description = "供应器名称")
@NotBlank(message = "name不能为空")
private String name; private String name;
@Schema(description = "供应器字段列表(JSON格式)") @Schema(description = "供应器字段列表(JSON格式)")
@TableField(typeHandler = JacksonTypeHandler.class) @TableField(typeHandler = JacksonTypeHandler.class)
@NotBlank(message = "fields(JSON格式)不能为空")
private String fields; private String fields;
@Schema(description = "排序") @Schema(description = "排序")
@NotNull(message = "sort不能为空")
private Integer sort; private Integer sort;
@Schema(description = "更新者") @Schema(description = "更新者")

View file

@ -3,10 +3,8 @@ package xiaozhi.modules.model.entity;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -30,7 +28,6 @@ public class ModelProviderEntity {
private String name; private String name;
@Schema(description = "供应器字段列表(JSON格式)") @Schema(description = "供应器字段列表(JSON格式)")
@TableField(typeHandler = JacksonTypeHandler.class)
private String fields; private String fields;
@Schema(description = "排序") @Schema(description = "排序")

View file

@ -2,8 +2,8 @@ package xiaozhi.modules.model.service;
import java.util.List; import java.util.List;
import xiaozhi.common.page.PageData;
import xiaozhi.modules.model.dto.ModelProviderDTO; import xiaozhi.modules.model.dto.ModelProviderDTO;
import xiaozhi.modules.model.entity.ModelProviderEntity;
public interface ModelProviderService { public interface ModelProviderService {
@ -11,11 +11,15 @@ public interface ModelProviderService {
List<ModelProviderDTO> getListByModelType(String modelType); List<ModelProviderDTO> getListByModelType(String modelType);
ModelProviderDTO add(ModelProviderEntity modelProviderEntity); ModelProviderDTO add(ModelProviderDTO modelProviderDTO);
ModelProviderDTO edit(ModelProviderEntity modelProviderEntity); ModelProviderDTO edit(ModelProviderDTO modelProviderDTO);
void delete(); void delete(String id);
void delete(List<String> id);
PageData<ModelProviderDTO> getListPage(ModelProviderDTO modelProviderDTO, String page, String limit);
List<ModelProviderDTO> getList(String modelType, String provideCode); List<ModelProviderDTO> getList(String modelType, String provideCode);
} }

View file

@ -1,19 +1,29 @@
package xiaozhi.modules.model.service.impl; package xiaozhi.modules.model.service.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.hutool.json.JSONArray;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import xiaozhi.common.constant.Constant;
import xiaozhi.common.exception.RenException;
import xiaozhi.common.page.PageData;
import xiaozhi.common.service.impl.BaseServiceImpl; import xiaozhi.common.service.impl.BaseServiceImpl;
import xiaozhi.common.user.UserDetail;
import xiaozhi.common.utils.ConvertUtils; import xiaozhi.common.utils.ConvertUtils;
import xiaozhi.modules.model.dao.ModelProviderDao; import xiaozhi.modules.model.dao.ModelProviderDao;
import xiaozhi.modules.model.dto.ModelProviderDTO; import xiaozhi.modules.model.dto.ModelProviderDTO;
import xiaozhi.modules.model.entity.ModelProviderEntity; import xiaozhi.modules.model.entity.ModelProviderEntity;
import xiaozhi.modules.model.service.ModelProviderService; import xiaozhi.modules.model.service.ModelProviderService;
import xiaozhi.modules.security.user.SecurityUser;
@Service @Service
@AllArgsConstructor @AllArgsConstructor
@ -32,18 +42,78 @@ public class ModelProviderServiceImpl extends BaseServiceImpl<ModelProviderDao,
} }
@Override @Override
public ModelProviderDTO add(ModelProviderEntity modelProviderEntity) { public PageData<ModelProviderDTO> getListPage(ModelProviderDTO modelProviderDTO, String page, String limit) {
return null;
Map<String, Object> params = new HashMap<String, Object>();
params.put(Constant.PAGE, page);
params.put(Constant.LIMIT, limit);
params.put(Constant.ORDER_FIELD, List.of("model_type", "sort"));
params.put(Constant.ORDER, "asc");
IPage<ModelProviderEntity> pageParam = getPage(params, null, true);
QueryWrapper<ModelProviderEntity> wrapper = new QueryWrapper<ModelProviderEntity>();
if (StringUtils.isNotBlank(modelProviderDTO.getModelType())) {
wrapper.eq("model_type", modelProviderDTO.getModelType());
}
if (StringUtils.isNotBlank(modelProviderDTO.getName())) {
wrapper.and(w -> w.like("name", modelProviderDTO.getName())
.or()
.like("provider_code", modelProviderDTO.getName()));
}
return getPageData(modelProviderDao.selectPage(pageParam, wrapper), ModelProviderDTO.class);
}
public static void main(String[] args) {
String jsonString = "\"[]\"";
JSONArray jsonArray = new JSONArray(jsonString);
System.out.println("字符串转 JSONArray: " + jsonArray.toString());
} }
@Override @Override
public ModelProviderDTO edit(ModelProviderEntity modelProviderEntity) { public ModelProviderDTO add(ModelProviderDTO modelProviderDTO) {
return null; UserDetail user = SecurityUser.getUser();
modelProviderDTO.setCreator(user.getId());
modelProviderDTO.setUpdater(user.getId());
modelProviderDTO.setCreateDate(new Date());
modelProviderDTO.setUpdateDate(new Date());
// 去除Fields左右的双引号
modelProviderDTO.setFields(modelProviderDTO.getFields());
ModelProviderEntity entity = ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderEntity.class);
if (modelProviderDao.insert(entity) == 0) {
throw new RenException("新增数据失败");
}
return ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderDTO.class);
} }
@Override @Override
public void delete() { public ModelProviderDTO edit(ModelProviderDTO modelProviderDTO) {
UserDetail user = SecurityUser.getUser();
modelProviderDTO.setUpdater(user.getId());
modelProviderDTO.setUpdateDate(new Date());
if (modelProviderDao
.updateById(ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderEntity.class)) == 0) {
throw new RenException("修改数据失败");
}
return ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderDTO.class);
}
@Override
public void delete(String id) {
if (modelProviderDao.deleteById(id) == 0) {
throw new RenException("删除数据失败");
}
}
@Override
public void delete(List<String> ids) {
if (modelProviderDao.deleteBatchIds(ids) == 0) {
throw new RenException("删除数据失败");
}
} }
@Override @Override

View file

@ -80,6 +80,7 @@ public class ShiroConfig {
filterMap.put("/doc.html", "anon"); filterMap.put("/doc.html", "anon");
filterMap.put("/favicon.ico", "anon"); filterMap.put("/favicon.ico", "anon");
filterMap.put("/user/captcha", "anon"); filterMap.put("/user/captcha", "anon");
filterMap.put("/user/smsVerification", "anon");
filterMap.put("/user/login", "anon"); filterMap.put("/user/login", "anon");
filterMap.put("/user/pub-config", "anon"); filterMap.put("/user/pub-config", "anon");
filterMap.put("/user/register", "anon"); filterMap.put("/user/register", "anon");

View file

@ -2,6 +2,7 @@ package xiaozhi.modules.security.controller;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -24,13 +25,18 @@ import xiaozhi.common.utils.Result;
import xiaozhi.common.validator.AssertUtils; import xiaozhi.common.validator.AssertUtils;
import xiaozhi.common.validator.ValidatorUtils; import xiaozhi.common.validator.ValidatorUtils;
import xiaozhi.modules.security.dto.LoginDTO; import xiaozhi.modules.security.dto.LoginDTO;
import xiaozhi.modules.security.dto.SmsVerificationDTO;
import xiaozhi.modules.security.password.PasswordUtils; import xiaozhi.modules.security.password.PasswordUtils;
import xiaozhi.modules.security.service.CaptchaService; import xiaozhi.modules.security.service.CaptchaService;
import xiaozhi.modules.security.service.SysUserTokenService; import xiaozhi.modules.security.service.SysUserTokenService;
import xiaozhi.modules.security.user.SecurityUser; import xiaozhi.modules.security.user.SecurityUser;
import xiaozhi.modules.sys.dto.PasswordDTO; import xiaozhi.modules.sys.dto.PasswordDTO;
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
import xiaozhi.modules.sys.dto.SysUserDTO; import xiaozhi.modules.sys.dto.SysUserDTO;
import xiaozhi.modules.sys.service.SysDictDataService;
import xiaozhi.modules.sys.service.SysParamsService;
import xiaozhi.modules.sys.service.SysUserService; import xiaozhi.modules.sys.service.SysUserService;
import xiaozhi.modules.sys.vo.SysDictDataItem;
/** /**
* 登录控制层 * 登录控制层
@ -43,24 +49,43 @@ public class LoginController {
private final SysUserService sysUserService; private final SysUserService sysUserService;
private final SysUserTokenService sysUserTokenService; private final SysUserTokenService sysUserTokenService;
private final CaptchaService captchaService; private final CaptchaService captchaService;
private final SysParamsService sysParamsService;
private final SysDictDataService sysDictDataService;
@GetMapping("/captcha") @GetMapping("/captcha")
@Operation(summary = "验证码") @Operation(summary = "验证码")
public void captcha(HttpServletResponse response, String uuid) throws IOException { public void captcha(HttpServletResponse response, String uuid) throws IOException {
// uuid不能为空 // uuid不能为空
AssertUtils.isBlank(uuid, ErrorCode.IDENTIFIER_NOT_NULL); AssertUtils.isBlank(uuid, ErrorCode.IDENTIFIER_NOT_NULL);
// 生成验证码 // 生成验证码
captchaService.create(response, uuid); captchaService.create(response, uuid);
} }
@PostMapping("/smsVerification")
@Operation(summary = "短信验证码")
public Result<Void> smsVerification(@RequestBody SmsVerificationDTO dto) {
// 验证图形验证码
boolean validate = captchaService.validate(dto.getCaptchaId(), dto.getCaptcha(), true);
if (!validate) {
throw new RenException("图形验证码错误");
}
Boolean isMobileRegister = sysParamsService
.getValueObject(Constant.SysMSMParam.SYSTEM_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
if (!isMobileRegister) {
throw new RenException("没有开启手机注册,没法使用短信验证码功能");
}
// 发送短信验证码
captchaService.sendSMSValidateCode(dto.getPhone());
return new Result<>();
}
@PostMapping("/login") @PostMapping("/login")
@Operation(summary = "登录") @Operation(summary = "登录")
public Result<TokenDTO> login(@RequestBody LoginDTO login) { public Result<TokenDTO> login(@RequestBody LoginDTO login) {
// 验证是否正确输入验证码 // 验证是否正确输入验证码
boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha()); boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha(), true);
if (!validate) { if (!validate) {
throw new RenException("验证码错误,请重新获取"); throw new RenException("图形验证码错误,请重新获取");
} }
// 按照用户名获取用户 // 按照用户名获取用户
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername()); SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
@ -81,11 +106,29 @@ public class LoginController {
if (!sysUserService.getAllowUserRegister()) { if (!sysUserService.getAllowUserRegister()) {
throw new RenException("当前不允许普通用户注册"); throw new RenException("当前不允许普通用户注册");
} }
// 验证是否正确输入验证码 // 是否开启手机注册
boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha()); Boolean isMobileRegister = sysParamsService
if (!validate) { .getValueObject(Constant.SysMSMParam.SYSTEM_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
throw new RenException("验证码错误,请重新获取"); boolean validate;
if (isMobileRegister) {
// 验证用户是否是手机号码
boolean validPhone = ValidatorUtils.isValidPhone(login.getUsername());
if (!validPhone) {
throw new RenException("用户名不是手机号码,请重新输入");
} }
// 验证短信验证码是否正常
validate = captchaService.validateSMSValidateCode(login.getUsername(), login.getMobileCaptcha(), false);
if (!validate) {
throw new RenException("手机验证码错误,请重新获取");
}
} else {
// 验证是否正确输入验证码
validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha(), true);
if (!validate) {
throw new RenException("图形验证码错误,请重新获取");
}
}
// 按照用户名获取用户 // 按照用户名获取用户
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername()); SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
if (userDTO != null) { if (userDTO != null) {
@ -96,7 +139,6 @@ public class LoginController {
userDTO.setPassword(login.getPassword()); userDTO.setPassword(login.getPassword());
sysUserService.save(userDTO); sysUserService.save(userDTO);
return new Result<>(); return new Result<>();
} }
@GetMapping("/info") @GetMapping("/info")
@ -118,12 +160,50 @@ public class LoginController {
return new Result<>(); return new Result<>();
} }
@PutMapping("/retrieve-password")
@Operation(summary = "找回密码")
public Result<?> retrievePassword(@RequestBody RetrievePasswordDTO dto) {
// 是否开启手机注册
Boolean isMobileRegister = sysParamsService
.getValueObject(Constant.SysMSMParam.SYSTEM_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
if (!isMobileRegister) {
throw new RenException("没有开启手机注册,没法使用找回密码功能");
}
// 判断非空
ValidatorUtils.validateEntity(dto);
// 验证用户是否是手机号码
boolean validPhone = ValidatorUtils.isValidPhone(dto.getPhone());
if (!validPhone) {
throw new RenException("用户名不是手机号码,无法提供找回密码服务");
}
// 按照用户名获取用户
SysUserDTO userDTO = sysUserService.getByUsername(dto.getPhone());
if (userDTO == null) {
throw new RenException("用户名或验证码错误");
}
// 验证短信验证码是否正常
boolean validate = captchaService.validateSMSValidateCode(dto.getPhone(), dto.getCode(), false);
// 判断是否通过验证
if (!validate) {
throw new RenException("用户名或验证码错误");
}
sysUserService.changePasswordDirectly(userDTO.getId(), dto.getPassword());
return new Result<>();
}
@GetMapping("/pub-config") @GetMapping("/pub-config")
@Operation(summary = "公共配置") @Operation(summary = "公共配置")
public Result<Map<String, Object>> pubConfig() { public Result<Map<String, Object>> pubConfig() {
Map<String, Object> config = new HashMap<>(); Map<String, Object> config = new HashMap<>();
config.put("enableMobileRegister", sysParamsService
.getValueObject(Constant.SysMSMParam.SYSTEM_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class));
config.put("version", Constant.VERSION); config.put("version", Constant.VERSION);
config.put("allowUserRegister", sysUserService.getAllowUserRegister()); config.put("allowUserRegister", sysUserService.getAllowUserRegister());
List<SysDictDataItem> list = sysDictDataService.getDictDataByType("MOBILE_AREA");
config.put("mobileAreaList", list);
return new Result<Map<String, Object>>().ok(config); return new Result<Map<String, Object>>().ok(config);
} }
} }

View file

@ -25,6 +25,9 @@ public class LoginDTO implements Serializable {
@NotBlank(message = "{sysuser.captcha.require}") @NotBlank(message = "{sysuser.captcha.require}")
private String captcha; private String captcha;
@Schema(description = "手机验证码")
private String mobileCaptcha;
@Schema(description = "唯一标识") @Schema(description = "唯一标识")
@NotBlank(message = "{sysuser.uuid.require}") @NotBlank(message = "{sysuser.uuid.require}")
private String captchaId; private String captchaId;

View file

@ -0,0 +1,28 @@
package xiaozhi.modules.security.dto;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/**
* 短信验证码请求DTO
*/
@Data
@Schema(description = "短信验证码请求")
public class SmsVerificationDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "手机号码")
@NotBlank(message = "{sysuser.username.require}")
private String phone;
@Schema(description = "验证码")
@NotBlank(message = "{sysuser.captcha.require}")
private String captcha;
@Schema(description = "唯一标识")
@NotBlank(message = "{sysuser.uuid.require}")
private String captchaId;
}

View file

@ -21,7 +21,25 @@ public interface CaptchaService {
* *
* @param uuid uuid * @param uuid uuid
* @param code 验证码 * @param code 验证码
* @param delete 是否删除验证码
* @return true:成功 false:失败 * @return true:成功 false:失败
*/ */
boolean validate(String uuid, String code); boolean validate(String uuid, String code, Boolean delete);
/**
* 发送短信验证码
*
* @param phone 手机
*/
void sendSMSValidateCode(String phone);
/**
* 验证短信验证码
*
* @param phone 手机
* @param code 验证码
* @param delete 是否删除验证码
* @return true:成功 false:失败
*/
boolean validateSMSValidateCode(String phone, String code, Boolean delete);
} }

View file

@ -1,6 +1,7 @@
package xiaozhi.modules.security.service.impl; package xiaozhi.modules.security.service.impl;
import java.io.IOException; import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -14,9 +15,13 @@ import com.wf.captcha.base.Captcha;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import xiaozhi.common.constant.Constant;
import xiaozhi.common.exception.RenException;
import xiaozhi.common.redis.RedisKeys; import xiaozhi.common.redis.RedisKeys;
import xiaozhi.common.redis.RedisUtils; import xiaozhi.common.redis.RedisUtils;
import xiaozhi.modules.security.service.CaptchaService; import xiaozhi.modules.security.service.CaptchaService;
import xiaozhi.modules.sms.service.SmsService;
import xiaozhi.modules.sys.service.SysParamsService;
/** /**
* 验证码 * 验证码
@ -25,6 +30,10 @@ import xiaozhi.modules.security.service.CaptchaService;
public class CaptchaServiceImpl implements CaptchaService { public class CaptchaServiceImpl implements CaptchaService {
@Resource @Resource
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Resource
private SmsService smsService;
@Resource
private SysParamsService sysParamsService;
@Value("${renren.redis.open}") @Value("${renren.redis.open}")
private boolean open; private boolean open;
/** /**
@ -51,12 +60,12 @@ public class CaptchaServiceImpl implements CaptchaService {
} }
@Override @Override
public boolean validate(String uuid, String code) { public boolean validate(String uuid, String code, Boolean delete) {
if (StringUtils.isBlank(code)) { if (StringUtils.isBlank(code)) {
return false; return false;
} }
// 获取验证码 // 获取验证码
String captcha = getCache(uuid); String captcha = getCache(uuid, delete);
// 效验成功 // 效验成功
if (code.equalsIgnoreCase(captcha)) { if (code.equalsIgnoreCase(captcha)) {
@ -66,21 +75,98 @@ public class CaptchaServiceImpl implements CaptchaService {
return false; return false;
} }
@Override
public void sendSMSValidateCode(String phone) {
// 检查发送间隔
String lastSendTimeKey = RedisKeys.getSMSLastSendTimeKey(phone);
String lastSendTime = (String) redisUtils.get(lastSendTimeKey);
if (lastSendTime != null) {
long lastSendTimeLong = Long.parseLong(lastSendTime);
long currentTime = System.currentTimeMillis();
long timeDiff = currentTime - lastSendTimeLong;
if (timeDiff < 60000) {
throw new RenException("发送太频繁,请" + (60000 - timeDiff) / 1000 + "秒后再试");
}
}
// 检查今日发送次数
String todayCountKey = RedisKeys.getSMSTodayCountKey(phone);
Integer todayCount = (Integer) redisUtils.get(todayCountKey);
if (todayCount == null) {
todayCount = 0;
}
// 获取最大发送次数限制
Integer maxSendCount = sysParamsService.getValueObject(
Constant.SysMSMParam.SYSTEM_SMS_MAX_SEND_COUNT.getValue(),
Integer.class);
if (maxSendCount == null) {
maxSendCount = 5; // 默认值
}
if (todayCount >= maxSendCount) {
throw new RenException("今日发送次数已达上限");
}
String key = RedisKeys.getSMSValidateCodeKey(phone);
String validateCodes = generateValidateCode(6);
// 设置验证码
setCache(key, validateCodes);
// 设置最后发送时间(60秒)
redisUtils.set(lastSendTimeKey, String.valueOf(System.currentTimeMillis()), 60);
// 更新今日发送次数
if (todayCount == 0) {
// 如果是今天第一次发送,设置24小时过期
redisUtils.set(todayCountKey, 1, RedisUtils.DEFAULT_EXPIRE);
} else {
redisUtils.set(todayCountKey, todayCount + 1, RedisUtils.DEFAULT_EXPIRE);
}
// 发送验证码短信
smsService.sendVerificationCodeSms(phone, validateCodes);
}
@Override
public boolean validateSMSValidateCode(String phone, String code, Boolean delete) {
String key = RedisKeys.getSMSValidateCodeKey(phone);
return validate(key, code, delete);
}
/**
* 生成指定数量的随机数验证码
*
* @param length 数量
* @return 随机码
*/
private String generateValidateCode(Integer length) {
String chars = "0123456789"; // 字符范围可以自定义:数字
Random random = new Random();
StringBuilder code = new StringBuilder();
for (int i = 0; i < length; i++) {
code.append(chars.charAt(random.nextInt(chars.length())));
}
return code.toString();
}
private void setCache(String key, String value) { private void setCache(String key, String value) {
if (open) { if (open) {
key = RedisKeys.getCaptchaKey(key); key = RedisKeys.getCaptchaKey(key);
// 设置5分钟过期
redisUtils.set(key, value, 300); redisUtils.set(key, value, 300);
} else { } else {
localCache.put(key, value); localCache.put(key, value);
} }
} }
private String getCache(String key) { private String getCache(String key, Boolean delete) {
if (open) { if (open) {
key = RedisKeys.getCaptchaKey(key); key = RedisKeys.getCaptchaKey(key);
String captcha = (String) redisUtils.get(key); String captcha = (String) redisUtils.get(key);
// 删除验证码 // 删除验证码
if (captcha != null) { if (captcha != null && delete) {
redisUtils.delete(key); redisUtils.delete(key);
} }

View file

@ -0,0 +1,17 @@
package xiaozhi.modules.sms.service;
/**
* 短信服务的方法定义接口
*
* @author zjy
* @since 2025-05-12
*/
public interface SmsService {
/**
* 发送验证码短信
* @param phone 手机号码
* @param VerificationCode 验证码
*/
void sendVerificationCodeSms(String phone, String VerificationCode) ;
}

View file

@ -0,0 +1,70 @@
package xiaozhi.modules.sms.service.imp;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import xiaozhi.common.constant.Constant;
import xiaozhi.common.exception.RenException;
import xiaozhi.modules.sms.service.SmsService;
import xiaozhi.modules.sys.service.SysParamsService;
@Service
@AllArgsConstructor
@Slf4j
public class ALiYunSmsService implements SmsService {
private final SysParamsService sysParamsService;
@Override
public void sendVerificationCodeSms(String phone, String VerificationCode) {
Client client = createClient();
String SignName = sysParamsService.getValue(Constant.SysMSMParam
.ALIYUN_SMS_SIGN_NAME.getValue(),true);
String TemplateCode = sysParamsService.getValue(Constant.SysMSMParam
.ALIYUN_SMS_SMS_CODE_TEMPLATE_CODE.getValue(),true);
try {
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setSignName(SignName)
.setTemplateCode(TemplateCode)
.setPhoneNumbers(phone)
.setTemplateParam(String.format("{\"code\":\"%s\"}", VerificationCode));
RuntimeOptions runtime = new RuntimeOptions();
// 复制代码运行请自行打印 API 的返回值
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
log.info("发送短信响应的requestID: {}", sendSmsResponse.getBody().getRequestId());
} catch (Exception e) {
// 错误 message
log.error(e.getMessage());
throw new RenException("短信发送失败");
}
}
/**
* 创建阿里云连接
* @return 返回连接对象
*/
private Client createClient(){
String ACCESS_KEY_ID = sysParamsService.getValue(Constant.SysMSMParam
.ALIYUN_SMS_ACCESS_KEY_ID.getValue(),true);
String ACCESS_KEY_SECRET = sysParamsService.getValue(Constant.SysMSMParam
.ALIYUN_SMS_ACCESS_KEY_SECRET.getValue(),true);
try {
Config config = new Config()
.setAccessKeyId(ACCESS_KEY_ID)
.setAccessKeySecret(ACCESS_KEY_SECRET);
// 配置 Endpoint。中国站请使用dysmsapi.aliyuncs.com
config.endpoint = "dysmsapi.aliyuncs.com";
return new Client(config);
}catch (Exception e){
// 错误 message
log.error(e.getMessage());
throw new RenException("短信连接建立失败");
}
}
}

View file

@ -0,0 +1,30 @@
package xiaozhi.modules.sys.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.io.Serializable;
/**
* 找回密码DTO
*/
@Data
@Schema(description = "找回密码")
public class RetrievePasswordDTO implements Serializable {
@Schema(description = "手机号码")
@NotBlank(message = "{sysuser.password.require}")
private String phone;
@Schema(description = "验证码")
@NotBlank(message = "{sysuser.password.require}")
private String code;
@Schema(description = "新密码")
@NotBlank(message = "{sysuser.password.require}")
private String password;
}

View file

@ -159,7 +159,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
params.put(Constant.LIMIT, dto.getLimit()); params.put(Constant.LIMIT, dto.getLimit());
IPage<SysUserEntity> page = baseDao.selectPage( IPage<SysUserEntity> page = baseDao.selectPage(
getPage(params, "id", true), getPage(params, "id", true),
new QueryWrapper<SysUserEntity>().eq(StringUtils.isNotBlank(dto.getMobile()), "username", new QueryWrapper<SysUserEntity>().like(StringUtils.isNotBlank(dto.getMobile()), "username",
dto.getMobile())); dto.getMobile()));
// 循环处理page获取回来的数据,返回需要的字段 // 循环处理page获取回来的数据,返回需要的字段
List<AdminPageUserVO> list = page.getRecords().stream().map(user -> { List<AdminPageUserVO> list = page.getRecords().stream().map(user -> {

View file

@ -32,7 +32,7 @@ INSERT INTO `ai_model_config` VALUES ('TTS_EdgeTTS', 'TTS', 'EdgeTTS', 'Edge语
INSERT INTO `ai_model_config` VALUES ('TTS_DoubaoTTS', 'TTS', 'DoubaoTTS', '豆包语音合成', 0, 1, '{\"type\": \"doubao\", \"api_url\": \"https://openspeech.bytedance.com/api/v1/tts\", \"voice\": \"BV001_streaming\", \"output_dir\": \"tmp/\", \"authorization\": \"Bearer;\", \"appid\": \"\", \"access_token\": \"\", \"cluster\": \"volcano_tts\"}', NULL, NULL, 2, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_DoubaoTTS', 'TTS', 'DoubaoTTS', '豆包语音合成', 0, 1, '{\"type\": \"doubao\", \"api_url\": \"https://openspeech.bytedance.com/api/v1/tts\", \"voice\": \"BV001_streaming\", \"output_dir\": \"tmp/\", \"authorization\": \"Bearer;\", \"appid\": \"\", \"access_token\": \"\", \"cluster\": \"volcano_tts\"}', NULL, NULL, 2, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_CosyVoiceSiliconflow', 'TTS', 'CosyVoiceSiliconflow', '硅基流动语音合成', 0, 1, '{\"type\": \"siliconflow\", \"model\": \"FunAudioLLM/CosyVoice2-0.5B\", \"voice\": \"FunAudioLLM/CosyVoice2-0.5B:alex\", \"output_dir\": \"tmp/\", \"access_token\": \"\", \"response_format\": \"wav\"}', NULL, NULL, 3, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_CosyVoiceSiliconflow', 'TTS', 'CosyVoiceSiliconflow', '硅基流动语音合成', 0, 1, '{\"type\": \"siliconflow\", \"model\": \"FunAudioLLM/CosyVoice2-0.5B\", \"voice\": \"FunAudioLLM/CosyVoice2-0.5B:alex\", \"output_dir\": \"tmp/\", \"access_token\": \"\", \"response_format\": \"wav\"}', NULL, NULL, 3, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_CozeCnTTS', 'TTS', 'CozeCnTTS', 'Coze中文语音合成', 0, 1, '{\"type\": \"cozecn\", \"voice\": \"7426720361733046281\", \"output_dir\": \"tmp/\", \"access_token\": \"\", \"response_format\": \"wav\"}', NULL, NULL, 4, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_CozeCnTTS', 'TTS', 'CozeCnTTS', 'Coze中文语音合成', 0, 1, '{\"type\": \"cozecn\", \"voice\": \"7426720361733046281\", \"output_dir\": \"tmp/\", \"access_token\": \"\", \"response_format\": \"wav\"}', NULL, NULL, 4, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_FishSpeech', 'TTS', 'FishSpeech', 'FishSpeech语音合成', 0, 1, '{\"type\": \"fishspeech\", \"output_dir\": \"tmp/\", \"response_format\": \"wav\", \"reference_id\": null, \"reference_audio\": [\"/tmp/test.wav\"], \"reference_text\": [\"你弄来这些吟词宴曲来看,还是这些混话来欺负我。\"], \"normalize\": true, \"max_new_tokens\": 1024, \"chunk_length\": 200, \"top_p\": 0.7, \"repetition_penalty\": 1.2, \"temperature\": 0.7, \"streaming\": false, \"use_memory_cache\": \"on\", \"seed\": 1, \"channels\": 1, \"rate\": 44100, \"api_key\": \"\", \"api_url\": \"http://127.0.0.1:8080/v1/tts\"}', NULL, NULL, 5, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_FishSpeech', 'TTS', 'FishSpeech', 'FishSpeech语音合成', 0, 1, '{\"type\": \"fishspeech\", \"output_dir\": \"tmp/\", \"response_format\": \"wav\", \"reference_id\": null, \"reference_audio\": [\"/tmp/test.wav\"], \"reference_text\": [\"你弄来这些吟词宴曲来看,还是这些混话来欺负我。\"], \"normalize\": true, \"max_new_tokens\": 1024, \"chunk_length\": 200, \"top_p\": 0.7, \"repetition_penalty\": 1.2, \"temperature\": 0.7, \"streaming\": false, \"use_memory_cache\": \"on\", \"seed\": null, \"channels\": 1, \"rate\": 44100, \"api_key\": \"\", \"api_url\": \"http://127.0.0.1:8080/v1/tts\"}', NULL, NULL, 5, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_GPT_SOVITS_V2', 'TTS', 'GPT_SOVITS_V2', 'GPT-SoVITS V2', 0, 1, '{\"type\": \"gpt_sovits_v2\", \"url\": \"http://127.0.0.1:9880/tts\", \"output_dir\": \"tmp/\", \"text_lang\": \"auto\", \"ref_audio_path\": \"caixukun.wav\", \"prompt_text\": \"\", \"prompt_lang\": \"zh\", \"top_k\": 5, \"top_p\": 1, \"temperature\": 1, \"text_split_method\": \"cut0\", \"batch_size\": 1, \"batch_threshold\": 0.75, \"split_bucket\": true, \"return_fragment\": false, \"speed_factor\": 1.0, \"streaming_mode\": false, \"seed\": -1, \"parallel_infer\": true, \"repetition_penalty\": 1.35, \"aux_ref_audio_paths\": []}', NULL, NULL, 6, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_GPT_SOVITS_V2', 'TTS', 'GPT_SOVITS_V2', 'GPT-SoVITS V2', 0, 1, '{\"type\": \"gpt_sovits_v2\", \"url\": \"http://127.0.0.1:9880/tts\", \"output_dir\": \"tmp/\", \"text_lang\": \"auto\", \"ref_audio_path\": \"caixukun.wav\", \"prompt_text\": \"\", \"prompt_lang\": \"zh\", \"top_k\": 5, \"top_p\": 1, \"temperature\": 1, \"text_split_method\": \"cut0\", \"batch_size\": 1, \"batch_threshold\": 0.75, \"split_bucket\": true, \"return_fragment\": false, \"speed_factor\": 1.0, \"streaming_mode\": false, \"seed\": -1, \"parallel_infer\": true, \"repetition_penalty\": 1.35, \"aux_ref_audio_paths\": []}', NULL, NULL, 6, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_GPT_SOVITS_V3', 'TTS', 'GPT_SOVITS_V3', 'GPT-SoVITS V3', 0, 1, '{\"type\": \"gpt_sovits_v3\", \"url\": \"http://127.0.0.1:9880\", \"output_dir\": \"tmp/\", \"text_language\": \"auto\", \"refer_wav_path\": \"caixukun.wav\", \"prompt_language\": \"zh\", \"prompt_text\": \"\", \"top_k\": 15, \"top_p\": 1.0, \"temperature\": 1.0, \"cut_punc\": \"\", \"speed\": 1.0, \"inp_refs\": [], \"sample_steps\": 32, \"if_sr\": false}', NULL, NULL, 7, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_GPT_SOVITS_V3', 'TTS', 'GPT_SOVITS_V3', 'GPT-SoVITS V3', 0, 1, '{\"type\": \"gpt_sovits_v3\", \"url\": \"http://127.0.0.1:9880\", \"output_dir\": \"tmp/\", \"text_language\": \"auto\", \"refer_wav_path\": \"caixukun.wav\", \"prompt_language\": \"zh\", \"prompt_text\": \"\", \"top_k\": 15, \"top_p\": 1.0, \"temperature\": 1.0, \"cut_punc\": \"\", \"speed\": 1.0, \"inp_refs\": [], \"sample_steps\": 32, \"if_sr\": false}', NULL, NULL, 7, NULL, NULL, NULL, NULL);
INSERT INTO `ai_model_config` VALUES ('TTS_MinimaxTTS', 'TTS', 'MinimaxTTS', 'MiniMax语音合成', 0, 1, '{\"type\": \"minimax\", \"output_dir\": \"tmp/\", \"group_id\": \"\", \"api_key\": \"你的api_key\", \"model\": \"speech-01-turbo\", \"voice_id\": \"female-shaonv\"}', NULL, NULL, 8, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_MinimaxTTS', 'TTS', 'MinimaxTTS', 'MiniMax语音合成', 0, 1, '{\"type\": \"minimax\", \"output_dir\": \"tmp/\", \"group_id\": \"\", \"api_key\": \"你的api_key\", \"model\": \"speech-01-turbo\", \"voice_id\": \"female-shaonv\"}', NULL, NULL, 8, NULL, NULL, NULL, NULL);

View file

@ -0,0 +1,59 @@
-- 添加手机短信注册功能的需要的参数
delete from sys_params where id in (601, 602, 610, 611, 612, 613);
INSERT INTO sys_params
(id, param_code, param_value, value_type, param_type, remark, creator, create_date, updater, update_date)
VALUES
(601, 'system.enable_mobile_register', 'false', 'boolean', 1, '是否开启手机注册', NULL, NULL, NULL, NULL),
(602, 'system.sms.max_send_count', '10', 'number', 1, '单号码单日最大短信发送条数', NULL, NULL, NULL, NULL),
(610, 'aliyun.sms.access_key_id', '', 'string', 1, '阿里云平台access_key', NULL, NULL, NULL, NULL),
(611, 'aliyun.sms.access_key_secret', '', 'string', 1, '阿里云平台access_key_secret', NULL, NULL, NULL, NULL),
(612, 'aliyun.sms.sign_name', '', 'string', 1, '阿里云短信签名', NULL, NULL, NULL, NULL),
(613, 'aliyun.sms.sms_code_template_code', '', 'string', 1, '阿里云短信模板', NULL, NULL, NULL, NULL);
-- 增加手机区域字典
-- 插入固件类型字典类型
delete from `sys_dict_type` where `id` = 102;
INSERT INTO `sys_dict_type` (`id`, `dict_type`, `dict_name`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
(102, 'MOBILE_AREA', '手机区域', '手机区域字典', 0, 1, NOW(), 1, NOW());
-- 插入固件类型字典数据
delete from `sys_dict_data` where `dict_type_id` = 102;
INSERT INTO `sys_dict_data` (`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
(102001, 102, '中国大陆', '+86', '中国大陆', 1, 1, NOW(), 1, NOW()),
(102002, 102, '中国香港', '+852', '中国香港', 2, 1, NOW(), 1, NOW()),
(102003, 102, '中国澳门', '+853', '中国澳门', 3, 1, NOW(), 1, NOW()),
(102004, 102, '中国台湾', '+886', '中国台湾', 4, 1, NOW(), 1, NOW()),
(102005, 102, '美国/加拿大', '+1', '美国/加拿大', 5, 1, NOW(), 1, NOW()),
(102006, 102, '英国', '+44', '英国', 6, 1, NOW(), 1, NOW()),
(102007, 102, '法国', '+33', '法国', 7, 1, NOW(), 1, NOW()),
(102008, 102, '意大利', '+39', '意大利', 8, 1, NOW(), 1, NOW()),
(102009, 102, '德国', '+49', '德国', 9, 1, NOW(), 1, NOW()),
(102010, 102, '波兰', '+48', '波兰', 10, 1, NOW(), 1, NOW()),
(102011, 102, '瑞士', '+41', '瑞士', 11, 1, NOW(), 1, NOW()),
(102012, 102, '西班牙', '+34', '西班牙', 12, 1, NOW(), 1, NOW()),
(102013, 102, '丹麦', '+45', '丹麦', 13, 1, NOW(), 1, NOW()),
(102014, 102, '马来西亚', '+60', '马来西亚', 14, 1, NOW(), 1, NOW()),
(102015, 102, '澳大利亚', '+61', '澳大利亚', 15, 1, NOW(), 1, NOW()),
(102016, 102, '印度尼西亚', '+62', '印度尼西亚', 16, 1, NOW(), 1, NOW()),
(102017, 102, '菲律宾', '+63', '菲律宾', 17, 1, NOW(), 1, NOW()),
(102018, 102, '新西兰', '+64', '新西兰', 18, 1, NOW(), 1, NOW()),
(102019, 102, '新加坡', '+65', '新加坡', 19, 1, NOW(), 1, NOW()),
(102020, 102, '泰国', '+66', '泰国', 20, 1, NOW(), 1, NOW()),
(102021, 102, '日本', '+81', '日本', 21, 1, NOW(), 1, NOW()),
(102022, 102, '韩国', '+82', '韩国', 22, 1, NOW(), 1, NOW()),
(102023, 102, '越南', '+84', '越南', 23, 1, NOW(), 1, NOW()),
(102024, 102, '印度', '+91', '印度', 24, 1, NOW(), 1, NOW()),
(102025, 102, '巴基斯坦', '+92', '巴基斯坦', 25, 1, NOW(), 1, NOW()),
(102026, 102, '尼日利亚', '+234', '尼日利亚', 26, 1, NOW(), 1, NOW()),
(102027, 102, '孟加拉国', '+880', '孟加拉国', 27, 1, NOW(), 1, NOW()),
(102028, 102, '沙特阿拉伯', '+966', '沙特阿拉伯', 28, 1, NOW(), 1, NOW()),
(102029, 102, '阿联酋', '+971', '阿联酋', 29, 1, NOW(), 1, NOW()),
(102030, 102, '巴西', '+55', '巴西', 30, 1, NOW(), 1, NOW()),
(102031, 102, '墨西哥', '+52', '墨西哥', 31, 1, NOW(), 1, NOW()),
(102032, 102, '智利', '+56', '智利', 32, 1, NOW(), 1, NOW()),
(102033, 102, '阿根廷', '+54', '阿根廷', 33, 1, NOW(), 1, NOW()),
(102034, 102, '埃及', '+20', '埃及', 34, 1, NOW(), 1, NOW()),
(102035, 102, '南非', '+27', '南非', 35, 1, NOW(), 1, NOW()),
(102036, 102, '肯尼亚', '+254', '肯尼亚', 36, 1, NOW(), 1, NOW()),
(102037, 102, '坦桑尼亚', '+255', '坦桑尼亚', 37, 1, NOW(), 1, NOW()),
(102038, 102, '哈萨克斯坦', '+7', '哈萨克斯坦', 38, 1, NOW(), 1, NOW());

View file

@ -114,6 +114,13 @@ databaseChangeLog:
- sqlFile: - sqlFile:
encoding: utf8 encoding: utf8
path: classpath:db/changelog/202505091409.sql path: classpath:db/changelog/202505091409.sql
- changeSet:
id: 202505141132
author: zjy
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202505141132.sql
- changeSet: - changeSet:
id: 202505091555 id: 202505091555
author: whosmyqueen author: whosmyqueen

View file

@ -9,6 +9,7 @@
10005=\u8D26\u53F7\u5DF2\u88AB\u505C\u7528 10005=\u8D26\u53F7\u5DF2\u88AB\u505C\u7528
10006=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A 10006=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A
10007=\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E 10007=\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E
10008=\u624B\u673A\u53F7\u7801\u4E0D\u53EF\u4EE5\u4E3A\u7A7A
10009=\u539F\u5BC6\u7801\u4E0D\u6B63\u786E 10009=\u539F\u5BC6\u7801\u4E0D\u6B63\u786E
10010=\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E,\u60A8\u8FD8\u6709\u53EF\u4EE5\u5C1D\u8BD5{0}\u6B21 10010=\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E,\u60A8\u8FD8\u6709\u53EF\u4EE5\u5C1D\u8BD5{0}\u6B21
10011=\u4E0A\u7EA7\u90E8\u95E8\u9009\u62E9\u9519\u8BEF 10011=\u4E0A\u7EA7\u90E8\u95E8\u9009\u62E9\u9519\u8BEF

View file

@ -0,0 +1,58 @@
package xiaozhi.modules.sys;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import lombok.extern.slf4j.Slf4j;
import xiaozhi.modules.security.controller.LoginController;
import xiaozhi.modules.security.dto.LoginDTO;
import xiaozhi.modules.security.dto.SmsVerificationDTO;
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
@Slf4j
@SpringBootTest
@ActiveProfiles("dev")
class loginControllerTest {
@Autowired
LoginController loginController;
@Test
public void testRegister() {
LoginDTO loginDTO = new LoginDTO();
loginDTO.setUsername("手机号码");
loginDTO.setPassword("密码");
loginDTO.setCaptcha("123456");
loginController.register(loginDTO);
}
@Test
public void testSmsVerification() {
try {
SmsVerificationDTO smsVerificationDTO = new SmsVerificationDTO();
smsVerificationDTO.setPhone("手机号码");
smsVerificationDTO.setCaptchaId("123456");
smsVerificationDTO.setCaptcha("123456");
loginController.smsVerification(smsVerificationDTO);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Test
public void testRetrievePassword() {
try {
RetrievePasswordDTO retrievePasswordDTO = new RetrievePasswordDTO();
retrievePasswordDTO.setCode("123456");
retrievePasswordDTO.setPhone("手机号码");
retrievePasswordDTO.setPassword("密码");
loginController.retrievePassword(retrievePasswordDTO);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

View file

@ -20,6 +20,7 @@ function sendRequest() {
return { return {
_sucCallback: null, _sucCallback: null,
_failCallback: null, _failCallback: null,
_networkFailCallback: null,
_method: 'GET', _method: 'GET',
_data: {}, _data: {},
_header: { 'content-type': 'application/json; charset=utf-8' }, _header: { 'content-type': 'application/json; charset=utf-8' },
@ -36,7 +37,7 @@ function sendRequest() {
headers: this._header, headers: this._header,
responseType: this._responseType responseType: this._responseType
}).then((res) => { }).then((res) => {
const error = httpHandlerError(res, this._failCallback); const error = httpHandlerError(res, this._failCallback, this._networkFailCallback);
if (error) { if (error) {
return return
} }
@ -47,7 +48,7 @@ function sendRequest() {
}).catch((res) => { }).catch((res) => {
// 打印失败响应 // 打印失败响应
console.log('catch', res) console.log('catch', res)
httpHandlerError(res, this._failCallback) httpHandlerError(res, this._failCallback, this._networkFailCallback)
}) })
return this return this
}, },
@ -59,6 +60,10 @@ function sendRequest() {
this._failCallback = callback this._failCallback = callback
return this return this
}, },
'networkFail'(callback) {
this._networkFailCallback = callback
return this
},
'url'(url) { 'url'(url) {
if (url) { if (url) {
url = url.replaceAll('$', '/') url = url.replaceAll('$', '/')
@ -95,11 +100,11 @@ function sendRequest() {
/** /**
* Info 请求完成后返回信息 * Info 请求完成后返回信息
* callBack 回调函数 * failCallback 回调函数
* errTip 自定义错误信息 * networkFailCallback 回调函数
*/ */
// 在错误处理函数中添加日志 // 在错误处理函数中添加日志
function httpHandlerError(info, callBack) { function httpHandlerError(info, failCallback, networkFailCallback) {
/** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */ /** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */
let networkError = false let networkError = false
@ -110,13 +115,17 @@ function httpHandlerError(info, callBack) {
store.commit('clearAuth'); store.commit('clearAuth');
goToPage(Constant.PAGE.LOGIN, true); goToPage(Constant.PAGE.LOGIN, true);
return true return true
} else {
if (failCallback) {
failCallback(info)
} else { } else {
showDanger(info.data.msg) showDanger(info.data.msg)
}
return true return true
} }
} }
if (callBack) { if (networkFailCallback) {
callBack(info) networkFailCallback(info)
} else { } else {
showDanger(`网络请求出现了错误【${info.status}】`) showDanger(`网络请求出现了错误【${info.status}】`)
} }

View file

@ -18,7 +18,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('请求失败:', err) console.error('请求失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getUserList(callback) this.getUserList(callback)
@ -34,7 +34,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除失败:', err) console.error('删除失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.deleteUser(id, callback) this.deleteUser(id, callback)
@ -50,7 +50,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('重置密码失败:', err) console.error('重置密码失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.resetUserPassword(id, callback) this.resetUserPassword(id, callback)
@ -72,7 +72,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取参数列表失败:', err) console.error('获取参数列表失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getParamsList(params, callback) this.getParamsList(params, callback)
@ -89,7 +89,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('添加参数失败:', err) console.error('添加参数失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.addParam(data, callback) this.addParam(data, callback)
@ -106,7 +106,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新参数失败:', err) console.error('更新参数失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.updateParam(data, callback) this.updateParam(data, callback)
@ -123,7 +123,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除参数失败:', err) console.error('删除参数失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.deleteParam(ids, callback) this.deleteParam(ids, callback)

View file

@ -12,7 +12,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAgentList(callback); this.getAgentList(callback);
}); });
@ -28,7 +28,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.addAgent(agentName, callback); this.addAgent(agentName, callback);
}); });
@ -43,7 +43,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.deleteAgent(agentId, callback); this.deleteAgent(agentId, callback);
}); });
@ -58,7 +58,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取配置失败:', err); console.error('获取配置失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getDeviceConfig(agentId, callback); this.getDeviceConfig(agentId, callback);
@ -75,7 +75,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.updateAgentConfig(agentId, configData, callback); this.updateAgentConfig(agentId, configData, callback);
}); });
@ -90,7 +90,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取模板失败:', err); console.error('获取模板失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAgentTemplate(callback); this.getAgentTemplate(callback);
@ -107,7 +107,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAgentSessions(agentId, params, callback); this.getAgentSessions(agentId, params, callback);
}); });
@ -122,7 +122,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAgentChatHistory(agentId, sessionId, callback); this.getAgentChatHistory(agentId, sessionId, callback);
}); });
@ -137,7 +137,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAudioId(audioId, callback); this.getAudioId(audioId, callback);
}); });

View file

@ -11,7 +11,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取设备列表失败:', err); console.error('获取设备列表失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getAgentBindDevices(agentId, callback); this.getAgentBindDevices(agentId, callback);
@ -28,7 +28,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('解绑设备失败:', err); console.error('解绑设备失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.unbindDevice(device_id, callback); this.unbindDevice(device_id, callback);
@ -44,7 +44,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('绑定设备失败:', err); console.error('绑定设备失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.bindDevice(agentId, deviceCode, callback); this.bindDevice(agentId, deviceCode, callback);
@ -59,7 +59,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新OTA状态失败:', err) console.error('更新OTA状态失败:', err)
this.$message.error(err.msg || '更新OTA状态失败') this.$message.error(err.msg || '更新OTA状态失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {

View file

@ -18,7 +18,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取字典类型列表失败:', err) console.error('获取字典类型列表失败:', err)
this.$message.error(err.msg || '获取字典类型列表失败') this.$message.error(err.msg || '获取字典类型列表失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -36,7 +36,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取字典类型详情失败:', err) console.error('获取字典类型详情失败:', err)
this.$message.error(err.msg || '获取字典类型详情失败') this.$message.error(err.msg || '获取字典类型详情失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -55,7 +55,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('新增字典类型失败:', err) console.error('新增字典类型失败:', err)
this.$message.error(err.msg || '新增字典类型失败') this.$message.error(err.msg || '新增字典类型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -74,7 +74,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新字典类型失败:', err) console.error('更新字典类型失败:', err)
this.$message.error(err.msg || '更新字典类型失败') this.$message.error(err.msg || '更新字典类型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -93,7 +93,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除字典类型失败:', err) console.error('删除字典类型失败:', err)
this.$message.error(err.msg || '删除字典类型失败') this.$message.error(err.msg || '删除字典类型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -119,7 +119,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取字典数据列表失败:', err) console.error('获取字典数据列表失败:', err)
this.$message.error(err.msg || '获取字典数据列表失败') this.$message.error(err.msg || '获取字典数据列表失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -137,7 +137,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取字典数据详情失败:', err) console.error('获取字典数据详情失败:', err)
this.$message.error(err.msg || '获取字典数据详情失败') this.$message.error(err.msg || '获取字典数据详情失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -156,7 +156,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('新增字典数据失败:', err) console.error('新增字典数据失败:', err)
this.$message.error(err.msg || '新增字典数据失败') this.$message.error(err.msg || '新增字典数据失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -175,7 +175,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新字典数据失败:', err) console.error('更新字典数据失败:', err)
this.$message.error(err.msg || '更新字典数据失败') this.$message.error(err.msg || '更新字典数据失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -194,7 +194,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除字典数据失败:', err) console.error('删除字典数据失败:', err)
this.$message.error(err.msg || '删除字典数据失败') this.$message.error(err.msg || '删除字典数据失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -217,7 +217,7 @@ export default {
reject(new Error(res.data?.msg || '获取字典数据列表失败')) reject(new Error(res.data?.msg || '获取字典数据列表失败'))
} }
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取字典数据列表失败:', err) console.error('获取字典数据列表失败:', err)
reject(err) reject(err)
}).send() }).send()

View file

@ -18,7 +18,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取模型列表失败:', err) console.error('获取模型列表失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getModelList(params, callback) this.getModelList(params, callback)
@ -34,7 +34,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res.data?.data || []) callback(res.data?.data || [])
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取供应器列表失败:', err) console.error('获取供应器列表失败:', err)
this.$message.error('获取供应器列表失败') this.$message.error('获取供应器列表失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -65,7 +65,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('新增模型失败:', err) console.error('新增模型失败:', err)
this.$message.error(err.msg || '新增模型失败') this.$message.error(err.msg || '新增模型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -82,7 +82,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除模型失败:', err) console.error('删除模型失败:', err)
this.$message.error(err.msg || '删除模型失败') this.$message.error(err.msg || '删除模型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -100,7 +100,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getModelNames(modelType, modelName, callback); this.getModelNames(modelType, modelName, callback);
}); });
@ -118,7 +118,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail(() => { .networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getModelVoices(modelId, voiceName, callback); this.getModelVoices(modelId, voiceName, callback);
}); });
@ -133,7 +133,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取模型配置失败:', err) console.error('获取模型配置失败:', err)
this.$message.error(err.msg || '获取模型配置失败') this.$message.error(err.msg || '获取模型配置失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -150,7 +150,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新模型状态失败:', err) console.error('更新模型状态失败:', err)
this.$message.error(err.msg || '更新模型状态失败') this.$message.error(err.msg || '更新模型状态失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -173,7 +173,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新模型失败:', err); console.error('更新模型失败:', err);
this.$message.error(err.msg || '更新模型失败'); this.$message.error(err.msg || '更新模型失败');
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
@ -190,12 +190,119 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('设置默认模型失败:', err) console.error('设置默认模型失败:', err)
this.$message.error(err.msg || '设置默认模型失败') this.$message.error(err.msg || '设置默认模型失败')
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.setDefaultModel(id, callback) this.setDefaultModel(id, callback)
}) })
}).send() }).send()
} },
/**
* 获取模型配置列表(支持查询参数)
* @param {Object} params - 查询参数对象,例如 { name: 'test', modelType: 1 }
* @param {Function} callback - 回调函数
*/
getModelProvidersPage(params, callback) {
// 构建查询参数
const queryParams = new URLSearchParams();
if (params.name) queryParams.append('name', params.name);
if (params.modelType !== undefined) queryParams.append('modelType', params.modelType);
if (params.page !== undefined) queryParams.append('page', params.page);
if (params.limit !== undefined) queryParams.append('limit', params.limit);
RequestService.sendRequest()
.url(`${getServiceUrl()}/models/provider?${queryParams.toString()}`)
.method('GET')
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail((err) => {
this.$message.error(err.msg || '获取供应器列表失败');
RequestService.reAjaxFun(() => {
this.getModelProviders(params, callback);
});
}).send();
},
/**
* 新增模型供应器配置
* @param {Object} params - 请求参数对象,例如 { modelType: '1', providerCode: '1', name: '1', fields: '1', sort: 1 }
* @param {Function} callback - 成功回调函数
*/
addModelProvider(params, callback) {
const postData = {
modelType: params.modelType || '',
providerCode: params.providerCode || '',
name: params.name || '',
fields: JSON.stringify(params.fields || []),
sort: params.sort || 0
};
RequestService.sendRequest()
.url(`${getServiceUrl()}/models/provider`)
.method('POST')
.data(postData)
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail((err) => {
console.error('新增模型供应器失败:', err)
this.$message.error(err.msg || '新增模型供应器失败')
RequestService.reAjaxFun(() => {
this.addModelProvider(params, callback);
});
}).send();
},
/**
* 更新模型供应器配置
* @param {Object} params - 请求参数对象,例如 { id: '111', modelType: '1', providerCode: '1', name: '1', fields: '1', sort: 1 }
* @param {Function} callback - 成功回调函数
*/
updateModelProvider(params, callback) {
const putData = {
id: params.id || '',
modelType: params.modelType || '',
providerCode: params.providerCode || '',
name: params.name || '',
fields: JSON.stringify(params.fields || []),
sort: params.sort || 0
};
RequestService.sendRequest()
.url(`${getServiceUrl()}/models/provider`)
.method('PUT')
.data(putData)
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail((err) => {
this.$message.error(err.msg || '更新模型供应器失败')
RequestService.reAjaxFun(() => {
this.updateModelProvider(params, callback);
});
}).send();
},
// 删除
deleteModelProviderByIds(ids, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/models/provider/delete`)
.method('POST')
.data(ids)
.success((res) => {
RequestService.clearRequestTime()
callback(res);
})
.networkFail((err) => {
this.$message.error(err.msg || '删除模型供应器失败')
RequestService.reAjaxFun(() => {
this.deleteModelProviderByIds(ids, callback)
})
}).send()
},
} }

View file

@ -12,7 +12,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取OTA固件列表失败:', err); console.error('获取OTA固件列表失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getOtaList(params, callback); this.getOtaList(params, callback);
@ -28,7 +28,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取OTA固件信息失败:', err); console.error('获取OTA固件信息失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getOtaInfo(id, callback); this.getOtaInfo(id, callback);
@ -45,7 +45,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('保存OTA固件信息失败:', err); console.error('保存OTA固件信息失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.saveOta(entity, callback); this.saveOta(entity, callback);
@ -62,7 +62,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('更新OTA固件信息失败:', err); console.error('更新OTA固件信息失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.updateOta(id, entity, callback); this.updateOta(id, entity, callback);
@ -78,7 +78,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除OTA固件失败:', err); console.error('删除OTA固件失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.deleteOta(id, callback); this.deleteOta(id, callback);
@ -97,7 +97,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('上传固件文件失败:', err); console.error('上传固件文件失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.uploadFirmware(file, callback); this.uploadFirmware(file, callback);
@ -113,7 +113,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取下载链接失败:', err); console.error('获取下载链接失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getDownloadUrl(id, callback); this.getDownloadUrl(id, callback);

View file

@ -1,4 +1,4 @@
import {getServiceUrl} from '../api'; import { getServiceUrl } from '../api';
import RequestService from '../httpRequest'; import RequestService from '../httpRequest';
export default { export default {
@ -18,7 +18,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res.data || []); callback(res.data || []);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取音色列表失败:', err); console.error('获取音色列表失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getVoiceList(params, callback); this.getVoiceList(params, callback);
@ -42,7 +42,7 @@ export default {
.success((res) => { .success((res) => {
callback(res.data); callback(res.data);
}) })
.fail((err) => { .networkFail((err) => {
console.error('保存音色失败:', err); console.error('保存音色失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.saveVoice(params, callback); this.saveVoice(params, callback);
@ -59,7 +59,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('删除音色失败:', err); console.error('删除音色失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.deleteVoice(ids, callback); this.deleteVoice(ids, callback);
@ -82,7 +82,7 @@ export default {
.success((res) => { .success((res) => {
callback(res.data); callback(res.data);
}) })
.fail((err) => { .networkFail((err) => {
console.error('修改音色失败:', err); console.error('修改音色失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.updateVoice(params, callback); this.updateVoice(params, callback);

View file

@ -4,7 +4,7 @@ import RequestService from '../httpRequest'
export default { export default {
// 登录 // 登录
login(loginForm, callback) { login(loginForm, callback, failCallback) {
RequestService.sendRequest() RequestService.sendRequest()
.url(`${getServiceUrl()}/user/login`) .url(`${getServiceUrl()}/user/login`)
.method('POST') .method('POST')
@ -13,7 +13,11 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail(() => { .fail((err) => {
RequestService.clearRequestTime()
failCallback(err)
})
.networkFail(() => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.login(loginForm, callback) this.login(loginForm, callback)
}) })
@ -34,12 +38,32 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { // 添加错误参数 .networkFail((err) => { // 添加错误参数
}).send() }).send()
}, },
// 发送短信验证码
sendSmsVerification(data, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/user/smsVerification`)
.method('POST')
.data(data)
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
RequestService.clearRequestTime()
failCallback(err)
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.sendSmsVerification(data, callback, failCallback)
})
}).send()
},
// 注册账号 // 注册账号
register(registerForm, callback) { register(registerForm, callback, failCallback) {
RequestService.sendRequest() RequestService.sendRequest()
.url(`${getServiceUrl()}/user/register`) .url(`${getServiceUrl()}/user/register`)
.method('POST') .method('POST')
@ -48,7 +72,14 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail(() => { .fail((err) => {
RequestService.clearRequestTime()
failCallback(err)
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.register(registerForm, callback, failCallback)
})
}).send() }).send()
}, },
// 保存设备配置 // 保存设备配置
@ -61,7 +92,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('保存配置失败:', err); console.error('保存配置失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.saveDeviceConfig(device_id, configData, callback); this.saveDeviceConfig(device_id, configData, callback);
@ -77,7 +108,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
callback(res) callback(res)
}) })
.fail((err) => { .networkFail((err) => {
console.error('接口请求失败:', err) console.error('接口请求失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getUserInfo(callback) this.getUserInfo(callback)
@ -97,7 +128,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
successCallback(res); successCallback(res);
}) })
.fail((error) => { .networkFail((error) => {
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.changePassword(oldPassword, newPassword, successCallback, errorCallback); this.changePassword(oldPassword, newPassword, successCallback, errorCallback);
}); });
@ -115,7 +146,7 @@ export default {
RequestService.clearRequestTime() RequestService.clearRequestTime()
successCallback(res); successCallback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('修改用户状态失败:', err) console.error('修改用户状态失败:', err)
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.changeUserStatus(status, userIds) this.changeUserStatus(status, userIds)
@ -131,7 +162,7 @@ export default {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .networkFail((err) => {
console.error('获取公共配置失败:', err); console.error('获取公共配置失败:', err);
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.getPubConfig(callback); this.getPubConfig(callback);

View file

@ -1,5 +1,6 @@
<template> <template>
<el-dialog :visible="visible" @update:visible="handleVisibleChange" width="57%" center custom-class="custom-dialog" :show-close="false" class="center-dialog"> <el-dialog :visible="visible" @update:visible="handleVisibleChange" width="57%" center custom-class="custom-dialog"
:show-close="false" class="center-dialog">
<div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;"> <div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;">
<div style="font-size: 30px; color: #3d4566; margin-top: -15px; margin-bottom: 20px; text-align: center;"> <div style="font-size: 30px; color: #3d4566; margin-top: -15px; margin-bottom: 20px; text-align: center;">
@ -10,15 +11,15 @@
<el-form :model="form" label-width="100px" :rules="rules" ref="form" class="custom-form"> <el-form :model="form" label-width="100px" :rules="rules" ref="form" class="custom-form">
<div style="display: flex; gap: 20px; margin-bottom: 20px;"> <div style="display: flex; gap: 20px; margin-bottom: 20px;">
<el-form-item label="类别" prop="model_type" style="flex: 1;"> <el-form-item label="类别" prop="modelType" style="flex: 1;">
<el-select v-model="form.model_type" placeholder="请选择类别" class="custom-input-bg" style="width: 100%;"> <el-select v-model="form.modelType" placeholder="请选择类别" class="custom-input-bg" style="width: 100%;">
<el-option v-for="item in modelTypes" :key="item.value" :label="item.label" :value="item.value"> <el-option v-for="item in modelTypes" :key="item.value" :label="item.label" :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="供应器编码" prop="provider_code" style="flex: 1;"> <el-form-item label="供应器编码" prop="providerCode" style="flex: 1;">
<el-input v-model="form.provider_code" placeholder="请输入供应器编码" class="custom-input-bg"></el-input> <el-input v-model="form.providerCode" placeholder="请输入供应器编码" class="custom-input-bg"></el-input>
</el-form-item> </el-form-item>
</div> </div>
@ -27,20 +28,24 @@
<el-input v-model="form.name" placeholder="请输入供应器名称" class="custom-input-bg"></el-input> <el-input v-model="form.name" placeholder="请输入供应器名称" class="custom-input-bg"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="排序" prop="sort" style="flex: 1;"> <el-form-item label="排序" prop="sort" style="flex: 1;">
<el-input-number v-model="form.sort" :min="0" controls-position="right" class="custom-input-bg" style="width: 100%;"></el-input-number> <el-input-number v-model="form.sort" :min="0" controls-position="right" class="custom-input-bg"
style="width: 100%;"></el-input-number>
</el-form-item> </el-form-item>
</div> </div>
<div style="font-size: 20px; font-weight: bold; color: #3d4566; margin-bottom: 15px;"> <div style="font-size: 20px; font-weight: bold; color: #3d4566; margin-bottom: 15px;">
字段配置 字段配置
<div style="display: inline-block; float: right;"> <div style="display: inline-block; float: right;">
<el-button type="primary" @click="addField" size="small" style="background: #5bc98c; border: none;" :disabled="hasIncompleteFields"> <el-button type="primary" @click="addField" size="small" style="background: #5bc98c; border: none;"
:disabled="hasIncompleteFields">
添加 添加
</el-button> </el-button>
<el-button type="primary" @click="toggleSelectAllFields" size="small" style="background: #5f70f3; border: none; margin-left: 10px;"> <el-button type="primary" @click="toggleSelectAllFields" size="small"
style="background: #5f70f3; border: none; margin-left: 10px;">
{{ isAllFieldsSelected ? '取消全选' : '全选' }} {{ isAllFieldsSelected ? '取消全选' : '全选' }}
</el-button> </el-button>
<el-button type="danger" @click="batchRemoveFields" size="small" style="background: red; border: none; margin-left: 10px;"> <el-button type="danger" @click="batchRemoveFields" size="small"
style="background: red; border: none; margin-left: 10px;">
批量删除 批量删除
</el-button> </el-button>
</div> </div>
@ -135,9 +140,9 @@ export default {
return { return {
saving: false, saving: false,
rules: { rules: {
model_type: [{required: true, message: '请选择类别', trigger: 'change'}], modelType: [{ required: true, message: '请选择类别', trigger: 'change' }],
provider_code: [{required: true, message: '请输入供应器编码', trigger: 'blur'}], providerCode: [{ required: true, message: '请输入供应器编码', trigger: 'blur' }],
name: [{required: true, message: '请输入供应器名称', trigger: 'blur'}] name: [{ required: true, message: '请输入供应器名称', trigger: 'blur' }]
}, },
isAllFieldsSelected: false, isAllFieldsSelected: false,
tableKey: 0 // 用于强制表格重新渲染 tableKey: 0 // 用于强制表格重新渲染
@ -419,11 +424,12 @@ export default {
display: none; display: none;
} }
.el-table th, .el-table td { .el-table th,
.el-table td {
padding: 8px 0; padding: 8px 0;
} }
.el-button.is-circle{ .el-button.is-circle {
border-radius: 2px; border-radius: 2px;
} }
</style> </style>

View file

@ -136,3 +136,67 @@ export function getUUID() {
}) })
} }
/**
* 验证手机号格式
* @param {string} mobile 手机号
* @param {string} areaCode 区号
* @returns {boolean}
*/
export function validateMobile(mobile, areaCode) {
// 移除所有非数字字符
const cleanMobile = mobile.replace(/\D/g, '');
// 根据不同区号使用不同的验证规则
switch (areaCode) {
case '+86': // 中国大陆
return /^1[3-9]\d{9}$/.test(cleanMobile);
case '+852': // 中国香港
return /^[569]\d{7}$/.test(cleanMobile);
case '+853': // 中国澳门
return /^6\d{7}$/.test(cleanMobile);
case '+886': // 中国台湾
return /^9\d{8}$/.test(cleanMobile);
case '+1': // 美国/加拿大
return /^[2-9]\d{9}$/.test(cleanMobile);
case '+44': // 英国
return /^7[1-9]\d{8}$/.test(cleanMobile);
case '+81': // 日本
return /^[7890]\d{8}$/.test(cleanMobile);
case '+82': // 韩国
return /^1[0-9]\d{7}$/.test(cleanMobile);
case '+65': // 新加坡
return /^[89]\d{7}$/.test(cleanMobile);
case '+61': // 澳大利亚
return /^[4578]\d{8}$/.test(cleanMobile);
case '+49': // 德国
return /^1[5-7]\d{8}$/.test(cleanMobile);
case '+33': // 法国
return /^[67]\d{8}$/.test(cleanMobile);
case '+39': // 意大利
return /^3[0-9]\d{8}$/.test(cleanMobile);
case '+34': // 西班牙
return /^[6-9]\d{8}$/.test(cleanMobile);
case '+55': // 巴西
return /^[1-9]\d{10}$/.test(cleanMobile);
case '+91': // 印度
return /^[6-9]\d{9}$/.test(cleanMobile);
case '+971': // 阿联酋
return /^[5]\d{8}$/.test(cleanMobile);
case '+966': // 沙特阿拉伯
return /^[5]\d{8}$/.test(cleanMobile);
case '+880': // 孟加拉国
return /^1[3-9]\d{8}$/.test(cleanMobile);
case '+234': // 尼日利亚
return /^[789]\d{9}$/.test(cleanMobile);
case '+254': // 肯尼亚
return /^[17]\d{8}$/.test(cleanMobile);
case '+255': // 坦桑尼亚
return /^[67]\d{8}$/.test(cleanMobile);
case '+7': // 哈萨克斯坦
return /^[67]\d{9}$/.test(cleanMobile);
default:
// 其他国际号码:至少5位,最多15位
return /^\d{5,15}$/.test(cleanMobile);
}
}

View file

@ -48,8 +48,7 @@
<el-table ref="dictDataTable" :data="dictDataList" style="width: 100%" <el-table ref="dictDataTable" :data="dictDataList" style="width: 100%"
v-loading="dictDataLoading" element-loading-text="拼命加载中" v-loading="dictDataLoading" element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading" element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.7)" element-loading-background="rgba(255, 255, 255, 0.7)" class="data-table"
class="data-table"
header-row-class-name="table-header"> header-row-class-name="table-header">
<el-table-column label="选择" align="center" width="55"> <el-table-column label="选择" align="center" width="55">
<template slot-scope="scope"> <template slot-scope="scope">
@ -546,6 +545,7 @@ export default {
:deep(.el-table__body-wrapper) { :deep(.el-table__body-wrapper) {
max-height: calc(var(--table-max-height) - 40px); max-height: calc(var(--table-max-height) - 40px);
overflow-y: auto;
} }
:deep(.el-table__body) { :deep(.el-table__body) {

View file

@ -1,13 +1,14 @@
<template> <template>
<div class="welcome"> <div class="welcome">
<HeaderBar/> <HeaderBar />
<div class="operation-bar"> <div class="operation-bar">
<h2 class="page-title">供应器管理</h2> <h2 class="page-title">供应器管理</h2>
<div class="right-operations"> <div class="right-operations">
<el-dropdown trigger="click" @command="handleSelectModelType" @visible-change="handleDropdownVisibleChange"> <el-dropdown trigger="click" @command="handleSelectModelType" @visible-change="handleDropdownVisibleChange">
<el-button class="category-btn"> <el-button class="category-btn">
类别筛选 {{ selectedModelTypeLabel }}<i class="el-icon-arrow-down el-icon--right" :class="{ 'rotate-down':DropdownVisible }"></i> 类别筛选 {{ selectedModelTypeLabel }}<i class="el-icon-arrow-down el-icon--right"
:class="{ 'rotate-down': DropdownVisible }"></i>
</el-button> </el-button>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item command="">全部</el-dropdown-item> <el-dropdown-item command="">全部</el-dropdown-item>
@ -16,7 +17,8 @@
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<el-input placeholder="请输入供应器名称查询" v-model="searchName" class="search-input" @keyup.enter.native="handleSearch" clearable/> <el-input placeholder="请输入供应器名称查询" v-model="searchName" class="search-input" @keyup.enter.native="handleSearch"
clearable />
<el-button class="btn-search" @click="handleSearch">搜索</el-button> <el-button class="btn-search" @click="handleSearch">搜索</el-button>
</div> </div>
</div> </div>
@ -27,18 +29,20 @@
<el-card class="provider-card" shadow="never"> <el-card class="provider-card" shadow="never">
<el-table ref="providersTable" :data="filteredProvidersList" class="transparent-table" v-loading="loading" <el-table ref="providersTable" :data="filteredProvidersList" class="transparent-table" v-loading="loading"
element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.7)" element-loading-background="rgba(255, 255, 255, 0.7)" :header-cell-class-name="headerCellClassName">
:header-cell-class-name="headerCellClassName">
<el-table-column label="选择" align="center" width="120"> <el-table-column label="选择" align="center" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox v-model="scope.row.selected"></el-checkbox> <el-checkbox v-model="scope.row.selected"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="类别" prop="model_type" align="center" width="200">
<el-table-column label="类别" prop="modelType" align="center" width="200">
<template slot="header" slot-scope="scope"> <template slot="header" slot-scope="scope">
<el-dropdown trigger="click" @command="handleSelectModelType" @visible-change="isDropdownOpen = $event"> <el-dropdown trigger="click" @command="handleSelectModelType"
@visible-change="isDropdownOpen = $event">
<span class="dropdown-trigger" :class="{ 'active': isDropdownOpen }"> <span class="dropdown-trigger" :class="{ 'active': isDropdownOpen }">
类别{{ selectedModelTypeLabel }} <i class="dropdown-arrow" :class="{ 'is-active': isDropdownOpen }"></i> 类别{{ selectedModelTypeLabel }} <i class="dropdown-arrow"
:class="{ 'is-active': isDropdownOpen }"></i>
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item command="">全部</el-dropdown-item> <el-dropdown-item command="">全部</el-dropdown-item>
@ -49,12 +53,12 @@
</el-dropdown> </el-dropdown>
</template> </template>
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="getModelTypeTag(scope.row.model_type)"> <el-tag :type="getModelTypeTag(scope.row.modelType)">
{{ getModelTypeLabel(scope.row.model_type) }} {{ getModelTypeLabel(scope.row.modelType) }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="供应器编码" prop="provider_code" align="center" width="150"></el-table-column> <el-table-column label="供应器编码" prop="providerCode" align="center" width="150"></el-table-column>
<el-table-column label="名称" prop="name" align="center"></el-table-column> <el-table-column label="名称" prop="name" align="center"></el-table-column>
<el-table-column label="字段配置" align="center"> <el-table-column label="字段配置" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
@ -97,7 +101,8 @@
<button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev"> <button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev">
上一页 上一页
</button> </button>
<button v-for="page in visiblePages" :key="page" class="pagination-btn" :class="{ active: page === currentPage }" @click="goToPage(page)"> <button v-for="page in visiblePages" :key="page" class="pagination-btn"
:class="{ active: page === currentPage }" @click="goToPage(page)">
{{ page }} {{ page }}
</button> </button>
<button class="pagination-btn" :disabled="currentPage === pageCount" @click="goNext"> <button class="pagination-btn" :disabled="currentPage === pageCount" @click="goNext">
@ -112,33 +117,35 @@
</div> </div>
<!-- 新增/编辑供应器对话框 --> <!-- 新增/编辑供应器对话框 -->
<provider-dialog :title="dialogTitle" :visible.sync="dialogVisible" :form="providerForm" :model-types="modelTypes" @submit="handleSubmit" @cancel="dialogVisible = false"/> <provider-dialog :title="dialogTitle" :visible.sync="dialogVisible" :form="providerForm" :model-types="modelTypes"
@submit="handleSubmit" @cancel="dialogVisible = false" />
<el-footer> <el-footer>
<version-footer/> <version-footer />
</el-footer> </el-footer>
</div> </div>
</template> </template>
<script> <script>
import Api from "@/apis/api";
import HeaderBar from "@/components/HeaderBar.vue"; import HeaderBar from "@/components/HeaderBar.vue";
import ProviderDialog from "@/components/ProviderDialog.vue"; import ProviderDialog from "@/components/ProviderDialog.vue";
import VersionFooter from "@/components/VersionFooter.vue"; import VersionFooter from "@/components/VersionFooter.vue";
export default { export default {
components: {HeaderBar, ProviderDialog, VersionFooter}, components: { HeaderBar, ProviderDialog, VersionFooter },
data() { data() {
return { return {
searchName: "", searchName: "",
searchModelType: "", searchModelType: "",
providersList: [], providersList: [],
modelTypes: [ modelTypes: [
{value: "ASR", label: "语音识别"}, { value: "ASR", label: "语音识别" },
{value: "TTS", label: "语音合成"}, { value: "TTS", label: "语音合成" },
{value: "LLM", label: "大语言模型"}, { value: "LLM", label: "大语言模型" },
{value: "Intent", label: "意图识别"}, { value: "Intent", label: "意图识别" },
{value: "Memory", label: "记忆模块"}, { value: "Memory", label: "记忆模块" },
{value: "VAD", label: "语音活动检测"} { value: "VAD", label: "语音活动检测" }
], ],
currentPage: 1, currentPage: 1,
loading: false, loading: false,
@ -152,8 +159,8 @@ export default {
sensitive_keys: ["api_key", "personal_access_token", "access_token", "token", "secret", "access_key_secret", "secret_key"], sensitive_keys: ["api_key", "personal_access_token", "access_token", "token", "secret", "access_key_secret", "secret_key"],
providerForm: { providerForm: {
id: null, id: null,
model_type: "", modelType: "",
provider_code: "", providerCode: "",
name: "", name: "",
fields: [], fields: [],
sort: 0 sort: 0
@ -189,123 +196,50 @@ export default {
return pages; return pages;
}, },
filteredProvidersList() { filteredProvidersList() {
let list = this.providersList.filter(item => { return this.providersList;
const nameMatch = item.name.toLowerCase().includes(this.searchName.toLowerCase());
const typeMatch = !this.searchModelType || item.model_type === this.searchModelType;
return nameMatch && typeMatch;
});
list.sort((a, b) => a.sort - b.sort); // let list = this.providersList.filter(item => {
// const nameMatch = item.name.toLowerCase().includes(this.searchName.toLowerCase());
// const typeMatch = !this.searchModelType || item.model_type === this.searchModelType;
// return nameMatch && typeMatch;
// });
// 分页处理 // list.sort((a, b) => a.sort - b.sort);
const start = (this.currentPage - 1) * this.pageSize;
return list.slice(start, start + this.pageSize); // // 分页处理
// const start = (this.currentPage - 1) * this.pageSize;
// return list.slice(start, start + this.pageSize);
} }
}, },
methods: { methods: {
fetchProviders() { fetchProviders() {
this.loading = true; this.loading = true;
// 模拟API请求延迟 Api.model.getModelProvidersPage(
setTimeout(() => { {
page: this.currentPage,
limit: this.pageSize,
name: this.searchName,
modelType: this.searchModelType
},
({ data }) => {
this.loading = false; this.loading = false;
if (data.code === 0) {
// 模拟数据 - 从数据库结构中提取 this.providersList = data.data.list.map(item => {
this.providersList = [ return {
{ ...item,
id: "SYSTEM_ASR_DoubaoASR", selected: false,
model_type: "ASR", fields: JSON.parse(item.fields)
provider_code: "doubao", };
name: "火山引擎语音识别", });
fields: JSON.parse('[{"key": "appid", "type": "string", "label": "应用ID"}, {"key": "access_token", "type": "string", "label": "访问令牌"}, {"key": "cluster", "type": "string", "label": "集群"}, {"key": "output_dir", "type": "string", "label": "输出目录"}]'), this.total = data.data.total;
sort: 3, } else {
selected: false this.$message.error({
}, message: data.msg || '获取参数列表失败'
{ });
id: "SYSTEM_ASR_FunASR",
model_type: "ASR",
provider_code: "fun_local",
name: "FunASR语音识别",
fields: JSON.parse('[{"key": "model_dir", "type": "string", "label": "模型目录"}, {"key": "output_dir", "type": "string", "label": "输出目录"}]'),
sort: 1,
selected: false
},
{
id: "SYSTEM_LLM_openai",
model_type: "LLM",
provider_code: "openai",
name: "OpenAI接口",
fields: JSON.parse('[{"key": "base_url", "type": "string", "label": "基础URL"}, {"key": "model_name", "type": "string", "label": "模型名称"}, {"key": "api_key", "type": "string", "label": "API密钥"}, {"key": "temperature", "type": "number", "label": "温度"}, {"key": "max_tokens", "type": "number", "label": "最大令牌数"}]'),
sort: 1,
selected: false
},
{
id: "SYSTEM_TTS_edge",
model_type: "TTS",
provider_code: "edge",
name: "Edge TTS",
fields: JSON.parse('[{"key": "voice", "type": "string", "label": "音色"}, {"key": "output_dir", "type": "string", "label": "输出目录"}]'),
sort: 1,
selected: false
},
{
id: "SYSTEM_Memory_mem0ai",
model_type: "Memory",
provider_code: "mem0ai",
name: "Mem0AI记忆",
fields: JSON.parse('[{"key": "api_key", "type": "string", "label": "API密钥"}]'),
sort: 1,
selected: false
},
{
id: "SYSTEM_VAD_SileroVAD",
model_type: "VAD",
provider_code: "silero",
name: "SileroVAD语音活动检测",
fields: JSON.parse('[{"key": "threshold", "type": "number", "label": "检测阈值"}, {"key": "model_dir", "type": "string", "label": "模型目录"}, {"key": "min_silence_duration_ms", "type": "number", "label": "最小静音时长"}]'),
sort: 1,
selected: false
},
{
id: "SYSTEM_Intent_nointent",
model_type: "Intent",
provider_code: "nointent",
name: "无意图识别",
fields: [],
sort: 1,
selected: false
},
{
id: "SYSTEM_TTS_aliyun",
model_type: "TTS",
provider_code: "aliyun",
name: "阿里云TTS",
fields: JSON.parse('[{"key": "output_dir", "type": "string", "label": "输出目录"}, {"key": "appkey", "type": "string", "label": "应用密钥"}, {"key": "token", "type": "string", "label": "访问令牌"}, {"key": "voice", "type": "string", "label": "音色"}, {"key": "access_key_id", "type": "string", "label": "访问密钥ID"}, {"key": "access_key_secret", "type": "string", "label": "访问密钥密码"}]'),
sort: 9,
selected: false
},
{
id: "SYSTEM_LLM_coze",
model_type: "LLM",
provider_code: "coze",
name: "Coze接口",
fields: JSON.parse('[{"key": "bot_id", "type": "string", "label": "机器人ID"}, {"key": "user_id", "type": "string", "label": "用户ID"}, {"key": "personal_access_token", "type": "string", "label": "个人访问令牌"}]'),
sort: 6,
selected: false
},
{
id: "SYSTEM_TTS_TencentTTS",
model_type: "TTS",
provider_code: "tencent",
name: "腾讯语音合成",
fields: JSON.parse('[{"key": "appid", "type": "string", "label": "应用ID"}, {"key": "secret_id", "type": "string", "label": "Secret ID"}, {"key": "secret_key", "type": "string", "label": "Secret Key"}, {"key": "output_dir", "type": "string", "label": "输出目录"}, {"key": "region", "type": "string", "label": "区域"}, {"key": "voice", "type": "string", "label": "音色ID"}]'),
sort: 5,
selected: false
} }
]; }
);
this.total = this.providersList.length;
}, 500);
}, },
handleSearch() { handleSearch() {
this.currentPage = 1; this.currentPage = 1;
@ -326,8 +260,8 @@ export default {
this.dialogTitle = "新增供应器"; this.dialogTitle = "新增供应器";
this.providerForm = { this.providerForm = {
id: null, id: null,
model_type: "", modelType: "",
provider_code: "", providerCode: "",
name: "", name: "",
fields: [], fields: [],
sort: 0 sort: 0
@ -342,43 +276,36 @@ export default {
}; };
this.dialogVisible = true; this.dialogVisible = true;
}, },
handleSubmit({form, done}) { handleSubmit({ form, done }) {
this.loading = true; this.loading = true;
setTimeout(() => {
this.loading = false;
if (form.id) { if (form.id) {
// 模拟编辑操作 // 编辑
const index = this.providersList.findIndex(p => p.id === form.id); Api.model.updateModelProvider(form, ({ data }) => {
if (index !== -1) {
this.providersList.splice(index, 1, { if (data.code === 0) {
...form, this.fetchProviders(); // 刷新表格
fields: typeof form.fields === 'string' ? JSON.parse(form.fields) : form.fields
});
this.$message.success({ this.$message.success({
message: "修改成功", message: "修改成功",
showClose: true showClose: true
}); });
} }
} else {
// 模拟新增操作
const newId = `SYSTEM_${form.model_type}_${form.provider_code}`;
this.providersList.unshift({
...form,
id: newId,
fields: typeof form.fields === 'string' ? JSON.parse(form.fields) : form.fields,
selected: false
}); });
this.total += 1; } else {
// 新增
Api.model.addModelProvider(form, ({ data }) => {
if (data.code === 0) {
this.fetchProviders(); // 刷新表格
this.$message.success({ this.$message.success({
message: "新增成功", message: "新增成功",
showClose: true showClose: true
}); });
this.total += 1;
} }
});
}
this.loading = false;
this.dialogVisible = false; this.dialogVisible = false;
done && done(); done && done();
}, 500);
}, },
deleteSelectedProviders() { deleteSelectedProviders() {
const selectedRows = this.providersList.filter(row => row.selected); const selectedRows = this.providersList.filter(row => row.selected);
@ -398,17 +325,26 @@ export default {
this.$confirm(`确定要删除选中的${providerCount}个供应器吗?`, '警告', { this.$confirm(`确定要删除选中的${providerCount}个供应器吗?`, '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning',
}).then(() => { }).then(() => {
const ids = providers.map(provider => provider.id); const ids = providers.map(provider => provider.id);
// 模拟删除操作 Api.model.deleteModelProviderByIds(ids, ({ data }) => {
this.providersList = this.providersList.filter(p => !ids.includes(p.id)); if (data.code === 0) {
this.total = this.providersList.length;
this.isAllSelected = false;
this.fetchProviders(); // 刷新表格
this.$message.success({ this.$message.success({
message: `成功删除${providerCount}个供应器`, message: `成功删除${providerCount}个参数`,
showClose: true showClose: true
}); });
} else {
this.$message.error({
message: data.msg || '删除失败,请重试',
showClose: true
});
}
});
}).catch(() => { }).catch(() => {
this.$message({ this.$message({
type: 'info', type: 'info',
@ -434,6 +370,7 @@ export default {
return typeItem ? typeItem.label : type; return typeItem ? typeItem.label : type;
}, },
isSensitiveField(fieldKey) { isSensitiveField(fieldKey) {
if (typeof fieldKey !== 'string') return false;
return this.sensitive_keys.some(key => return this.sensitive_keys.some(key =>
fieldKey.toLowerCase().includes(key.toLowerCase()) fieldKey.toLowerCase().includes(key.toLowerCase())
); );
@ -443,7 +380,7 @@ export default {
this.currentPage = 1; this.currentPage = 1;
this.fetchProviders(); this.fetchProviders();
}, },
headerCellClassName({columnIndex}) { headerCellClassName({ columnIndex }) {
if (columnIndex === 0) { if (columnIndex === 0) {
return "custom-selection-header"; return "custom-selection-header";
} }
@ -461,6 +398,7 @@ export default {
}, },
goNext() { goNext() {
if (this.currentPage < this.pageCount) { if (this.currentPage < this.pageCount) {
console.log("this.currentPage", this.currentPage);
this.currentPage++; this.currentPage++;
this.fetchProviders(); this.fetchProviders();
} }
@ -552,7 +490,7 @@ export default {
flex-direction: column; flex-direction: column;
} }
.el-card{ .el-card {
border: none; border: none;
} }
@ -563,6 +501,7 @@ export default {
flex-direction: column; flex-direction: column;
box-shadow: none; box-shadow: none;
overflow: hidden; overflow: hidden;
::v-deep .el-card__body { ::v-deep .el-card__body {
padding: 15px; padding: 15px;
display: flex; display: flex;
@ -748,7 +687,7 @@ export default {
padding-bottom: 16px; padding-bottom: 16px;
} }
& + tr { &+tr {
margin-top: 10px; margin-top: 10px;
} }
} }
@ -918,6 +857,7 @@ export default {
.el-icon-arrow-down { .el-icon-arrow-down {
transition: transform 0.3s ease; transition: transform 0.3s ease;
} }
.dropdown-trigger { .dropdown-trigger {
font-size: 14px; font-size: 14px;
color: #303133; color: #303133;

View file

@ -66,20 +66,7 @@
cursor: pointer; cursor: pointer;
color: #fff; color: #fff;
line-height: 35px; line-height: 35px;
margin: 35px 15px 15px; margin: 15px 30px 15px 30px;
}
.code-send {
width: 70px;
height: 32px;
border-radius: 10px;
background: #e6ebff;
line-height: 32px;
font-weight: 400;
font-size: 14px;
color: #5778ff;
flex-shrink: 0;
cursor: pointer;
} }
.input-box { .input-box {

View file

@ -20,10 +20,27 @@
</div> </div>
</div> </div>
<div style="padding: 0 30px;"> <div style="padding: 0 30px;">
<!-- 用户名登录 -->
<template v-if="!isMobileLogin">
<div class="input-box"> <div class="input-box">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/username.png" /> <img loading="lazy" alt="" class="input-icon" src="@/assets/login/username.png" />
<el-input v-model="form.username" placeholder="请输入用户名" /> <el-input v-model="form.username" placeholder="请输入用户名" />
</div> </div>
</template>
<!-- 手机号登录 -->
<template v-else>
<div class="input-box">
<div style="display: flex; align-items: center; width: 100%;">
<el-select v-model="form.areaCode" style="width: 220px; margin-right: 10px;">
<el-option v-for="item in mobileAreaList" :key="item.key" :label="`${item.name} (${item.key})`"
:value="item.key" />
</el-select>
<el-input v-model="form.mobile" placeholder="请输入手机号码" />
</div>
</div>
</template>
<div class="input-box"> <div class="input-box">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/password.png" /> <img loading="lazy" alt="" class="input-icon" src="@/assets/login/password.png" />
<el-input v-model="form.password" placeholder="请输入密码" type="password" /> <el-input v-model="form.password" placeholder="请输入密码" type="password" />
@ -42,6 +59,19 @@
</div> </div>
</div> </div>
<div class="login-btn" @click="login">登录</div> <div class="login-btn" @click="login">登录</div>
<!-- 登录方式切换按钮 -->
<div class="login-type-container">
<el-tooltip content="手机号码登录" placement="bottom">
<el-button :type="isMobileLogin ? 'primary' : 'default'" icon="el-icon-mobile" circle
@click="switchLoginType('mobile')"></el-button>
</el-tooltip>
<el-tooltip content="用户名登录" placement="bottom">
<el-button :type="!isMobileLogin ? 'primary' : 'default'" icon="el-icon-user" circle
@click="switchLoginType('username')"></el-button>
</el-tooltip>
</div>
<div style="font-size: 14px;color: #979db1;"> <div style="font-size: 14px;color: #979db1;">
登录即同意 登录即同意
<div style="display: inline-block;color: #5778FF;cursor: pointer;">《用户协议》</div> <div style="display: inline-block;color: #5778FF;cursor: pointer;">《用户协议》</div>
@ -60,7 +90,7 @@
<script> <script>
import Api from '@/apis/api'; import Api from '@/apis/api';
import VersionFooter from '@/components/VersionFooter.vue'; import VersionFooter from '@/components/VersionFooter.vue';
import { getUUID, goToPage, showDanger, showSuccess } from '@/utils'; import { getUUID, goToPage, showDanger, showSuccess, validateMobile } from '@/utils';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
export default { export default {
@ -70,7 +100,9 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
allowUserRegister: state => state.pubConfig.allowUserRegister allowUserRegister: state => state.pubConfig.allowUserRegister,
enableMobileRegister: state => state.pubConfig.enableMobileRegister,
mobileAreaList: state => state.pubConfig.mobileAreaList
}) })
}, },
data() { data() {
@ -80,15 +112,21 @@ export default {
username: '', username: '',
password: '', password: '',
captcha: '', captcha: '',
captchaId: '' captchaId: '',
areaCode: '+86',
mobile: ''
}, },
captchaUuid: '', captchaUuid: '',
captchaUrl: '' captchaUrl: '',
isMobileLogin: false
} }
}, },
mounted() { mounted() {
this.fetchCaptcha(); this.fetchCaptcha();
this.$store.dispatch('fetchPubConfig'); this.$store.dispatch('fetchPubConfig').then(() => {
// 根据配置决定默认登录方式
this.isMobileLogin = this.enableMobileRegister;
});
}, },
methods: { methods: {
fetchCaptcha() { fetchCaptcha() {
@ -110,6 +148,17 @@ export default {
} }
}, },
// 切换登录方式
switchLoginType(type) {
this.isMobileLogin = type === 'mobile';
// 清空表单
this.form.username = '';
this.form.mobile = '';
this.form.password = '';
this.form.captcha = '';
this.fetchCaptcha();
},
// 封装输入验证逻辑 // 封装输入验证逻辑
validateInput(input, message) { validateInput(input, message) {
if (!input.trim()) { if (!input.trim()) {
@ -120,10 +169,21 @@ export default {
}, },
async login() { async login() {
// 验证用户名 if (this.isMobileLogin) {
// 手机号登录验证
if (!validateMobile(this.form.mobile, this.form.areaCode)) {
showDanger('请输入正确的手机号码');
return;
}
// 拼接手机号作为用户名
this.form.username = this.form.areaCode + this.form.mobile;
} else {
// 用户名登录验证
if (!this.validateInput(this.form.username, '用户名不能为空')) { if (!this.validateInput(this.form.username, '用户名不能为空')) {
return; return;
} }
}
// 验证密码 // 验证密码
if (!this.validateInput(this.form.password, '密码不能为空')) { if (!this.validateInput(this.form.password, '密码不能为空')) {
return; return;
@ -135,12 +195,13 @@ export default {
this.form.captchaId = this.captchaUuid this.form.captchaId = this.captchaUuid
Api.user.login(this.form, ({ data }) => { Api.user.login(this.form, ({ data }) => {
if (data.code === 0) {
showSuccess('登录成功!'); showSuccess('登录成功!');
this.$store.commit('setToken', JSON.stringify(data.data)); this.$store.commit('setToken', JSON.stringify(data.data));
goToPage('/home'); goToPage('/home');
} else { }, (err) => {
showDanger(data.msg || '登录失败'); showDanger(err.data.msg || '登录失败')
if (err.data != null && err.data.msg != null && err.data.msg.indexOf('图形验证码') > -1) {
this.fetchCaptcha()
} }
}) })
@ -157,4 +218,25 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import './auth.scss'; // 添加这行引用</style> @import './auth.scss';
.login-type-container {
margin: 10px 20px;
}
:deep(.el-button--primary) {
background-color: #5778ff;
border-color: #5778ff;
&:hover,
&:focus {
background-color: #4a6ae8;
border-color: #4a6ae8;
}
&:active {
background-color: #3d5cd6;
border-color: #3d5cd6;
}
}
</style>

View file

@ -23,12 +23,50 @@
</div> </div>
<div style="padding: 0 30px;"> <div style="padding: 0 30px;">
<!-- 用户名输入框 --> <form @submit.prevent="register">
<div class="input-box"> <!-- 用户名/手机号输入框 -->
<div class="input-box" v-if="!enableMobileRegister">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/username.png" /> <img loading="lazy" alt="" class="input-icon" src="@/assets/login/username.png" />
<el-input v-model="form.username" placeholder="请输入用户名" /> <el-input v-model="form.username" placeholder="请输入用户名" />
</div> </div>
<!-- 手机号注册部分 -->
<template v-if="enableMobileRegister">
<div class="input-box">
<div style="display: flex; align-items: center; width: 100%;">
<el-select v-model="form.areaCode" style="width: 220px; margin-right: 10px;">
<el-option v-for="item in mobileAreaList" :key="item.key" :label="`${item.name} (${item.key})`"
:value="item.key" />
</el-select>
<el-input v-model="form.mobile" placeholder="请输入手机号码" />
</div>
</div>
<div style="display: flex; align-items: center; margin-top: 20px; width: 100%; gap: 10px;">
<div class="input-box" style="width: calc(100% - 130px); margin-top: 0;">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/shield.png" />
<el-input v-model="form.captcha" placeholder="请输入验证码" style="flex: 1;" />
</div>
<img loading="lazy" v-if="captchaUrl" :src="captchaUrl" alt="验证码"
style="width: 150px; height: 40px; cursor: pointer;" @click="fetchCaptcha" />
</div>
<!-- 手机验证码 -->
<div style="display: flex; align-items: center; margin-top: 20px; width: 100%; gap: 10px;">
<div class="input-box" style="width: calc(100% - 130px); margin-top: 0;">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/phone.png" />
<el-input v-model="form.mobileCaptcha" placeholder="请输入手机验证码" style="flex: 1;" maxlength="6" />
</div>
<el-button type="primary" class="send-captcha-btn" :disabled="!canSendMobileCaptcha"
@click="sendMobileCaptcha">
<span>
{{ countdown > 0 ? `${countdown}秒后重试` : '发送验证码' }}
</span>
</el-button>
</div>
</template>
<!-- 密码输入框 --> <!-- 密码输入框 -->
<div class="input-box"> <div class="input-box">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/password.png" /> <img loading="lazy" alt="" class="input-icon" src="@/assets/login/password.png" />
@ -42,7 +80,8 @@
</div> </div>
<!-- 验证码部分保持相同 --> <!-- 验证码部分保持相同 -->
<div style="display: flex; align-items: center; margin-top: 20px; width: 100%; gap: 10px;"> <div v-if="!enableMobileRegister"
style="display: flex; align-items: center; margin-top: 20px; width: 100%; gap: 10px;">
<div class="input-box" style="width: calc(100% - 130px); margin-top: 0;"> <div class="input-box" style="width: calc(100% - 130px); margin-top: 0;">
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/shield.png" /> <img loading="lazy" alt="" class="input-icon" src="@/assets/login/shield.png" />
<el-input v-model="form.captcha" placeholder="请输入验证码" style="flex: 1;" /> <el-input v-model="form.captcha" placeholder="请输入验证码" style="flex: 1;" />
@ -55,6 +94,7 @@
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #5778ff;margin-top: 20px;"> <div style="font-weight: 400;font-size: 14px;text-align: left;color: #5778ff;margin-top: 20px;">
<div style="cursor: pointer;" @click="goToLogin">已有账号?立即登录</div> <div style="cursor: pointer;" @click="goToLogin">已有账号?立即登录</div>
</div> </div>
</form>
</div> </div>
<!-- 修改按钮文本 --> <!-- 修改按钮文本 -->
@ -81,7 +121,7 @@
<script> <script>
import Api from '@/apis/api'; import Api from '@/apis/api';
import VersionFooter from '@/components/VersionFooter.vue'; import VersionFooter from '@/components/VersionFooter.vue';
import { getUUID, goToPage, showDanger, showSuccess } from '@/utils'; import { getUUID, goToPage, showDanger, showSuccess, validateMobile } from '@/utils';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
export default { export default {
@ -91,8 +131,13 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
allowUserRegister: state => state.pubConfig.allowUserRegister allowUserRegister: state => state.pubConfig.allowUserRegister,
}) enableMobileRegister: state => state.pubConfig.enableMobileRegister,
mobileAreaList: state => state.pubConfig.mobileAreaList
}),
canSendMobileCaptcha() {
return this.countdown === 0 && validateMobile(this.form.mobile, this.form.areaCode);
}
}, },
data() { data() {
return { return {
@ -101,9 +146,14 @@ export default {
password: '', password: '',
confirmPassword: '', confirmPassword: '',
captcha: '', captcha: '',
captchaId: '' captchaId: '',
areaCode: '+86',
mobile: '',
mobileCaptcha: ''
}, },
captchaUrl: '' captchaUrl: '',
countdown: 0,
timer: null
} }
}, },
mounted() { mounted() {
@ -141,12 +191,69 @@ export default {
} }
return true; return true;
}, },
// 发送手机验证码
sendMobileCaptcha() {
if (!validateMobile(this.form.mobile, this.form.areaCode)) {
showDanger('请输入正确的手机号码');
return;
}
// 验证图形验证码
if (!this.validateInput(this.form.captcha, '请输入图形验证码')) {
return;
}
// 清除可能存在的旧定时器
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
// 开始倒计时
this.countdown = 60;
this.timer = setInterval(() => {
if (this.countdown > 0) {
this.countdown--;
} else {
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
// 调用发送验证码接口
Api.user.sendSmsVerification({
phone: this.form.areaCode + this.form.mobile,
captcha: this.form.captcha,
captchaId: this.form.captchaId
}, (res) => {
showSuccess('验证码发送成功');
}, (err) => {
showDanger(err.data.msg || '验证码发送失败');
this.countdown = 0;
this.fetchCaptcha();
});
},
// 注册逻辑 // 注册逻辑
register() { register() {
// 验证用户名 if (this.enableMobileRegister) {
// 手机号注册验证
if (!validateMobile(this.form.mobile, this.form.areaCode)) {
showDanger('请输入正确的手机号码');
return;
}
if (!this.form.mobileCaptcha) {
showDanger('请输入手机验证码');
return;
}
} else {
// 用户名注册验证
if (!this.validateInput(this.form.username, '用户名不能为空')) { if (!this.validateInput(this.form.username, '用户名不能为空')) {
return; return;
} }
}
// 验证密码 // 验证密码
if (!this.validateInput(this.form.password, '密码不能为空')) { if (!this.validateInput(this.form.password, '密码不能为空')) {
return; return;
@ -160,26 +267,50 @@ export default {
return; return;
} }
if (this.enableMobileRegister) {
this.form.username = this.form.areaCode + this.form.mobile
}
Api.user.register(this.form, ({ data }) => { Api.user.register(this.form, ({ data }) => {
if (data.code === 0) {
showSuccess('注册成功!') showSuccess('注册成功!')
goToPage('/login') goToPage('/login')
} else { }, (err) => {
showDanger(data.msg || '注册失败') showDanger(err.data.msg || '注册失败')
if (err.data != null && err.data.msg != null && err.data.msg.indexOf('图形验证码') > -1) {
this.fetchCaptcha() this.fetchCaptcha()
} }
}) })
setTimeout(() => {
this.fetchCaptcha()
}, 1000)
}, },
goToLogin() { goToLogin() {
goToPage('/login') goToPage('/login')
} }
},
beforeDestroy() {
if (this.timer) {
clearInterval(this.timer);
}
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import './auth.scss'; // 修改为导入新建的SCSS文件</style> @import './auth.scss';
.send-captcha-btn {
margin-right: -5px;
min-width: 100px;
height: 40px;
line-height: 40px;
border-radius: 4px;
font-size: 14px;
background: rgb(87, 120, 255);
border: none;
padding: 0px;
&:disabled {
background: #c0c4cc;
cursor: not-allowed;
}
}
</style>

View file

@ -4,7 +4,7 @@ from loguru import logger
from config.config_loader import load_config from config.config_loader import load_config
from config.settings import check_config_file from config.settings import check_config_file
SERVER_VERSION = "0.4.3" SERVER_VERSION = "0.4.4"
def get_module_abbreviation(module_name, module_dict): def get_module_abbreviation(module_name, module_dict):

View file

@ -130,7 +130,7 @@ class TTSProvider(TTSProviderBase):
"yes", "yes",
) )
self.use_memory_cache = config.get("use_memory_cache", "on") self.use_memory_cache = config.get("use_memory_cache", "on")
self.seed = config.get("seed") or None self.seed = int(config.get("seed")) if config.get("seed") else None
self.api_url = config.get("api_url", "http://127.0.0.1:8080/v1/tts") self.api_url = config.get("api_url", "http://127.0.0.1:8080/v1/tts")
def generate_filename(self, extension=".wav"): def generate_filename(self, extension=".wav"):