Commit afdf4eec authored by trumansdo's avatar trumansdo
Browse files

确定路由表应该由后端生成,前端应该存有一份路由名的映射关系

parent f2544d0e
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>admin-console</artifactId> <artifactId>admin-console</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent> <parent>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin</artifactId> <artifactId>admin</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin-core</artifactId> <artifactId>admin-core</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
</dependency> </dependency>
<dependency>
<dependency> <groupId>mysql</groupId>
<groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId>
<artifactId>mysql-connector-java</artifactId> <version>8.0.17</version>
<version>8.0.17</version> </dependency>
</dependency> <dependency>
</dependencies> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.1.7.RELEASE</version>
</dependency>
</dependencies>
</project> </project>
...@@ -47,271 +47,266 @@ import com.ibeetl.admin.core.web.JsonResult; ...@@ -47,271 +47,266 @@ import com.ibeetl.admin.core.web.JsonResult;
/** /**
* 用户管理接口 * 用户管理接口
* *
* @author xiandafu * @author xiandafu
*/ */
@Controller @Controller
public class UserConsoleController { public class UserConsoleController {
private final Log log = LogFactory.getLog(this.getClass()); private final Log log = LogFactory.getLog(this.getClass());
private static final String MODEL = "/admin/user"; private static final String MODEL = "/admin/user";
@Autowired @Autowired
UserConsoleService userConsoleService; UserConsoleService userConsoleService;
@Autowired @Autowired
CorePlatformService platformService; CorePlatformService platformService;
@Autowired @Autowired
RoleConsoleService roleConsoleService; RoleConsoleService roleConsoleService;
@Autowired @Autowired
OrgConsoleService orgConsoleService; OrgConsoleService orgConsoleService;
@Autowired @Autowired
FileService fileService; FileService fileService;
/* 页面 */ /* 页面 */
@GetMapping(MODEL + "/index.do") @GetMapping(MODEL + "/index.do")
@Function("user") @Function("user")
public ModelAndView index() { public ModelAndView index() {
ModelAndView view = new ModelAndView("/admin/user/index.html"); ModelAndView view = new ModelAndView("/admin/user/index.html");
view.addObject("search", UserQuery.class.getName()); view.addObject("search", UserQuery.class.getName());
return view; return view;
} }
@GetMapping(MODEL + "/edit.do") @GetMapping(MODEL + "/edit.do")
@Function("user.edit") @Function("user.edit")
public ModelAndView edit(String id) { public ModelAndView edit(String id) {
ModelAndView view = new ModelAndView("/admin/user/edit.html"); ModelAndView view = new ModelAndView("/admin/user/edit.html");
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
view.addObject("user", user); view.addObject("user", user);
return view; return view;
} }
@GetMapping(MODEL + "/add.do") @GetMapping(MODEL + "/add.do")
@Function("user.add") @Function("user.add")
public ModelAndView add() { public ModelAndView add() {
ModelAndView view = new ModelAndView("/admin/user/add.html"); ModelAndView view = new ModelAndView("/admin/user/add.html");
return view; return view;
} }
@GetMapping(MODEL + "/changePassword.do") @GetMapping(MODEL + "/changePassword.do")
@Function("user.add") @Function("user.add")
public ModelAndView changePassword(Long id) { public ModelAndView changePassword(Long id) {
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
ModelAndView view = new ModelAndView("/admin/user/changePassword.html"); ModelAndView view = new ModelAndView("/admin/user/changePassword.html");
view.addObject("user", user); view.addObject("user", user);
return view; return view;
} }
@GetMapping(MODEL + "/role/list.do") @GetMapping(MODEL + "/role/list.do")
@Function("user.role") @Function("user.role")
public ModelAndView userRoleIndex(Long id) { public ModelAndView userRoleIndex(Long id) {
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
ModelAndView view = new ModelAndView("/admin/user/userRole.html"); ModelAndView view = new ModelAndView("/admin/user/userRole.html");
view.addObject("search", UserRoleQuery.class.getName()); view.addObject("search", UserRoleQuery.class.getName());
view.addObject("user", user); view.addObject("user", user);
return view; return view;
} }
@GetMapping(MODEL + "/role/add.do") @GetMapping(MODEL + "/role/add.do")
@Function("user.role") @Function("user.role")
public ModelAndView userRoleAdd(Long id) { public ModelAndView userRoleAdd(Long id) {
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
ModelAndView view = new ModelAndView("/admin/user/userRoleAdd.html"); ModelAndView view = new ModelAndView("/admin/user/userRoleAdd.html");
view.addObject("user", user); view.addObject("user", user);
return view; return view;
} }
/* Json */ /* Json */
@PostMapping(MODEL + "/delete.json") @PostMapping(MODEL + "/delete.json")
@Function("user.delete") @Function("user.delete")
@ResponseBody @ResponseBody
public JsonResult delete(String ids) { public JsonResult delete(String ids) {
List<Long> dels = ConvertUtil.str2longs(ids); List<Long> dels = ConvertUtil.str2longs(ids);
userConsoleService.batchDelSysUser(dels); userConsoleService.batchDelSysUser(dels);
return JsonResult.success(); return JsonResult.success();
} }
@PostMapping(MODEL + "/update.json") @PostMapping(MODEL + "/update.json")
@Function("user.update") @Function("user.update")
@ResponseBody @ResponseBody
public JsonResult update(@Validated(ValidateConfig.UPDATE.class) CoreUser user) { public JsonResult update(@Validated(ValidateConfig.UPDATE.class) CoreUser user) {
boolean success = userConsoleService.updateTemplate(user); boolean success = userConsoleService.updateTemplate(user);
if (success) { if (success) {
this.platformService.clearFunctionCache(); this.platformService.clearFunctionCache();
return JsonResult.success(); return JsonResult.success();
} else { } else {
return JsonResult.failMessage("保存失败!"); return JsonResult.failMessage("保存失败!");
} }
} }
@PostMapping(MODEL + "/add.json") @PostMapping(MODEL + "/add.json")
@Function("user.add") @Function("user.add")
@ResponseBody @ResponseBody
public JsonResult<Long> add(@Validated(ValidateConfig.ADD.class) CoreUser user) { public JsonResult<Long> add(@Validated(ValidateConfig.ADD.class) CoreUser user) {
if (!platformService.isAllowUserName(user.getCode())) { if (!platformService.isAllowUserName(user.getCode())) {
return JsonResult.failMessage("不允许的注册名字 " + user.getCode()); return JsonResult.failMessage("不允许的注册名字 " + user.getCode());
} }
user.setCreateTime(new Date()); user.setCreateTime(new Date());
userConsoleService.saveUser(user); userConsoleService.saveUser(user);
return JsonResult.success(user.getId()); return JsonResult.success(user.getId());
} }
@PostMapping(MODEL + "/view.json") @PostMapping(MODEL + "/view.json")
@ResponseBody @ResponseBody
@Function("user.query") @Function("user.query")
public JsonResult<CoreUser> view(Long id) { public JsonResult<CoreUser> view(Long id) {
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
return JsonResult.success(user); return JsonResult.success(user);
} }
@PostMapping(MODEL + "/list.json") @PostMapping(MODEL + "/list.json")
@Function("user.query") @Function("user.query")
@ResponseBody @ResponseBody
public JsonResult<PageQuery<CoreUser>> index(UserQuery condtion) { public JsonResult<PageQuery<CoreUser>> index(UserQuery condtion) {
PageQuery<CoreUser> page = condtion.getPageQuery(); PageQuery<CoreUser> page = condtion.getPageQuery();
userConsoleService.queryByCondtion(page); userConsoleService.queryByCondtion(page);
return JsonResult.success(page); return JsonResult.success(page);
} }
@PostMapping(MODEL + "/list/condition.json") @PostMapping(MODEL + "/list/condition.json")
@Function("user.query") @Function("user.query")
@ResponseBody @ResponseBody
public JsonResult<List<Map<String, Object>>> indexCondtion() { public JsonResult<List<Map<String, Object>>> indexCondtion() {
List<Map<String, Object>> list = AnnotationUtil.getInstance().getAnnotations(Query.class, UserQuery.class); List<Map<String, Object>> list = AnnotationUtil.getInstance().getAnnotations(Query.class, UserQuery.class);
return JsonResult.success(list); return JsonResult.success(list);
} }
@PostMapping(MODEL + "/disable.json") @PostMapping(MODEL + "/disable.json")
@Function("user.disable") @Function("user.disable")
@ResponseBody @ResponseBody
public JsonResult disableUser(String ids) { public JsonResult disableUser(String ids) {
List<Long> dels = ConvertUtil.str2longs(ids); List<Long> dels = ConvertUtil.str2longs(ids);
userConsoleService.batchUpdateUserState(dels, GeneralStateEnum.DISABLE); userConsoleService.batchUpdateUserState(dels, GeneralStateEnum.DISABLE);
for (Long id : dels) { for (Long id : dels) {
CoreUser user = userConsoleService.queryById(id); CoreUser user = userConsoleService.queryById(id);
this.platformService.restUserSession(user.getCode()); this.platformService.restUserSession(user.getCode());
} }
return JsonResult.success(); return JsonResult.success();
} }
/** /**
* 启用用户操作 * 启用用户操作
* *
* @return * @return
*/ */
@PostMapping(MODEL + "/enable.json") @PostMapping(MODEL + "/enable.json")
@Function("user.enable") @Function("user.enable")
@ResponseBody @ResponseBody
public JsonResult enableUser(String ids) { public JsonResult enableUser(String ids) {
List<Long> enables = ConvertUtil.str2longs(ids); List<Long> enables = ConvertUtil.str2longs(ids);
userConsoleService.batchUpdateUserState(enables, GeneralStateEnum.ENABLE); userConsoleService.batchUpdateUserState(enables, GeneralStateEnum.ENABLE);
return JsonResult.success(); return JsonResult.success();
} }
/** /**
* 管理员重置用户密码 * 管理员重置用户密码
* *
* @return * @return
*/ */
@PostMapping(MODEL + "/changePassword.json") @PostMapping(MODEL + "/changePassword.json")
@Function("user.reset") @Function("user.reset")
@ResponseBody @ResponseBody
public JsonResult changePassword(Long id, String password) { public JsonResult changePassword(Long id, String password) {
userConsoleService.resetPassword(id, password); userConsoleService.resetPassword(id, password);
return new JsonResult().success(); return new JsonResult().success();
} }
/** /**
* 用户所有授权角色列表 * 用户所有授权角色列表
* *
* @param id * @param id 用户id
* 用户id * @return
* @return */
*/ @PostMapping(MODEL + "/role/list.json")
@PostMapping(MODEL + "/role/list.json") @Function("user.role")
@Function("user.role") @ResponseBody
@ResponseBody public JsonResult<List<CoreUserRole>> getRoleList(UserRoleQuery roleQuery) {
public JsonResult<List<CoreUserRole>> getRoleList(UserRoleQuery roleQuery) { List<CoreUserRole> list = userConsoleService.getUserRoles(roleQuery);
List<CoreUserRole> list = userConsoleService.getUserRoles(roleQuery); return JsonResult.success(list);
return JsonResult.success(list); }
}
/**
/** * 用户添加授权角色页
* 用户添加授权角色页 *
* * @return
* @return */
*/ @PostMapping(MODEL + "/role/add.json")
@PostMapping(MODEL + "/role/add.json") @Function("user.role")
@Function("user.role") @ResponseBody
@ResponseBody public JsonResult saveUserRole(@Validated CoreUserRole userRole) {
public JsonResult saveUserRole(@Validated CoreUserRole userRole) { userRole.setCreateTime(new Date());
userRole.setCreateTime(new Date()); this.userConsoleService.saveUserRole(userRole);
this.userConsoleService.saveUserRole(userRole); this.platformService.clearFunctionCache();
this.platformService.clearFunctionCache(); return JsonResult.success(userRole.getId());
return JsonResult.success(userRole.getId());
}
}
/**
/** * 删除用户角色授权
* 删除用户角色授权 *
* * @return
* @return */
*/ @PostMapping(MODEL + "/role/delete.json")
@PostMapping(MODEL + "/role/delete.json") @Function("user.role")
@Function("user.role") @ResponseBody
@ResponseBody public JsonResult delUserRole(String ids) {
public JsonResult delUserRole(String ids) { List<Long> dels = ConvertUtil.str2longs(ids);
List<Long> dels = ConvertUtil.str2longs(ids);
userConsoleService.deleteUserRoles(dels);
userConsoleService.deleteUserRoles(dels); this.platformService.clearFunctionCache();
this.platformService.clearFunctionCache(); return JsonResult.success();
return JsonResult.success(); }
}
@PostMapping(MODEL + "/excel/export.json")
@PostMapping(MODEL + "/excel/export.json") @Function("user.export")
@Function("user.export") @ResponseBody
@ResponseBody public JsonResult<String> export(HttpServletResponse response, UserQuery condtion) {
public JsonResult<String> export(HttpServletResponse response,UserQuery condtion) { String excelTemplate = "excelTemplates/admin/user/user_collection_template.xls";
String excelTemplate ="excelTemplates/admin/user/user_collection_template.xls"; PageQuery<CoreUser> page = condtion.getPageQuery();
PageQuery<CoreUser> page = condtion.getPageQuery(); //取出全部符合条件的
//取出全部符合条件的 page.setPageSize(Integer.MAX_VALUE);
page.setPageSize(Integer.MAX_VALUE); page.setPageNumber(1);
page.setPageNumber(1); page.setTotalRow(Integer.MAX_VALUE);
page.setTotalRow(Integer.MAX_VALUE); List<UserExcelExportData> users = userConsoleService.queryExcel(page);
List<UserExcelExportData> users =userConsoleService.queryExcel(page); try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) {
try(InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) { if (is == null) {
if(is==null) { throw new PlatformException("模板资源不存在:" + excelTemplate);
throw new PlatformException("模板资源不存在:"+excelTemplate); }
} FileItem item = fileService.createFileTemp("user_collection.xls");
FileItem item = fileService.createFileTemp("user_collection.xls"); OutputStream os = item.openOutpuStream();
OutputStream os = item.openOutpuStream(); Context context = new Context();
Context context = new Context();
context.putVar("users", users); context.putVar("users", users);
JxlsHelper.getInstance().processTemplate(is, os, context); JxlsHelper.getInstance().processTemplate(is, os, context);
//下载参考FileSystemContorller //下载参考FileSystemContorller
return JsonResult.success(item.getPath()); return JsonResult.success(item.getPath());
} catch (IOException e) { } catch (IOException e) {
throw new PlatformException(e.getMessage()); throw new PlatformException(e.getMessage());
} }
} }
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>admin-core</artifactId> <artifactId>admin-core</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent> <parent>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin</artifactId> <artifactId>admin</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
...@@ -11,109 +11,109 @@ ...@@ -11,109 +11,109 @@
</parent> </parent>
<properties> <properties>
<maven.test.skip>true</maven.test.skip> <maven.test.skip>true</maven.test.skip>
<druid.version>1.1.10</druid.version> <druid.version>1.1.10</druid.version>
<lombok.version>1.18.2</lombok.version> <lombok.version>1.18.2</lombok.version>
<disruptor.version>3.4.2</disruptor.version> <disruptor.version>3.4.2</disruptor.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId> <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId> <artifactId>spring-boot-starter-cache</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>beetl-framework-starter</artifactId> <artifactId>beetl-framework-starter</artifactId>
<version>1.2.13.RELEASE</version> <version>1.2.13.RELEASE</version>
</dependency> </dependency>
<!-- Log4j2 异步支持 --> <!-- Log4j2 异步支持 -->
<dependency> <dependency>
<groupId>com.lmax</groupId> <groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId> <artifactId>disruptor</artifactId>
<version>${disruptor.version}</version> <version>${disruptor.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.session</groupId> <groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId> <artifactId>spring-session-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>${lombok.version}</version> <version>${lombok.version}</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId> <artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version> <version>${druid.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
</dependency> </dependency>
<dependency> <!--<dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>-->
<!-- <dependency> <!-- <dependency>
<groupId>com.oracle</groupId> <groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId> <artifactId>ojdbc6</artifactId>
<version>11.2.0</version> <version>11.2.0</version>
</dependency> --> </dependency> -->
<dependency> <dependency>
<groupId>org.jxls</groupId> <groupId>org.jxls</groupId>
<artifactId>jxls-reader</artifactId> <artifactId>jxls-reader</artifactId>
<version>2.0.3</version> <version>2.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jxls</groupId> <groupId>org.jxls</groupId>
<artifactId>jxls</artifactId> <artifactId>jxls</artifactId>
<version>2.4.3</version> <version>2.4.3</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>logback-core</artifactId> <artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jxls</groupId> <groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId> <artifactId>jxls-poi</artifactId>
<version>1.0.14</version> <version>1.0.14</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.3.2</version> <version>3.3.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>
<version>3.17</version> <version>3.17</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>3.17</version> <version>3.17</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -64,8 +64,8 @@ public class CustomErrorController extends AbstractErrorController { ...@@ -64,8 +64,8 @@ public class CustomErrorController extends AbstractErrorController {
//后台打印日志信息方方便查错 //后台打印日志信息方方便查错
log.info(status+":"+message+filedErrors, cause); log.error(status+":"+message+filedErrors, cause);
log.info("requestPath"+":"+requestPath); log.error("requestPath"+":"+requestPath);
response.setStatus(status); response.setStatus(status);
......
...@@ -40,7 +40,7 @@ public class IndexController { ...@@ -40,7 +40,7 @@ public class IndexController {
@PostMapping("/login.do") @PostMapping("/user/login")
public ModelAndView login(String code, String password) { public ModelAndView login(String code, String password) {
UserLoginInfo info = userService.login(code, password); UserLoginInfo info = userService.login(code, password);
if (info == null) { if (info == null) {
......
# just a flag # just a flag
ENV = 'development' ENV = 'development'
# base api # base api 用于axios 配置中的baseURL,是服务器地址。
# 在这里是webpack-dev-server启动的地址,然后通过webpack-dev-server的proxy代理到我们的后台服务器
# 仅限开发环境,生产环境要用NGINX仅限代理
VUE_APP_BASE_API = '/dev-api' VUE_APP_BASE_API = '/dev-api'
VUE_APP_SERVER_HOST = 'http://127.0.0.1:9527/mock'
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable, # vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
# to control whether the babel-plugin-dynamic-import-node plugin is enabled. # to control whether the babel-plugin-dynamic-import-node plugin is enabled.
......
...@@ -2,12 +2,30 @@ module.exports = { ...@@ -2,12 +2,30 @@ module.exports = {
root: true, root: true,
env: { env: {
node: true browser: true,
node: true,
es6: true
}, },
extends: ['plugin:vue/essential', '@vue/prettier'], extends: [
// 各种eslint检查的规则 'plugin:vue/essential',
'plugin:prettier/recommended',
'eslint:recommended'
],
plugins: ['vue'],
// 各种eslint检查的规则
rules: { rules: {
'prettier/prettier': [
'off',
{
singleQuote: true,
trailingComma: 'none',
bracketSpacing: true,
jsxBracketSameLine: true,
parser: 'flow',
semi: false
}
],
'no-console': 'off', 'no-console': 'off',
'no-debugger': 'off', 'no-debugger': 'off',
'no-unused-vars': 'off', 'no-unused-vars': 'off',
...@@ -20,7 +38,50 @@ module.exports = { ...@@ -20,7 +38,50 @@ module.exports = {
allowTemplateLiterals: true allowTemplateLiterals: true
} }
], ],
'jsx-quotes': [2, 'prefer-single'] 'jsx-quotes': [2, 'prefer-single'],
// 缩进为2个空格
'vue/html-indent': [
'error',
2,
{
attribute: 1,
alignAttributesVertically: true,
ignores: []
}
],
'vue/max-attributes-per-line': [
2,
{
singleline: 10,
multiline: {
max: 1,
allowFirstLine: false
}
}
],
'vue/html-self-closing': 'off',
'vue/name-property-casing': ['error', 'PascalCase'],
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// 关闭检测函数名称和调用它的左括号之间的空格
// 'func-call-spacing': 'off',
// 缩进为2个空格
indent: ['error', 2],
// 关闭检测未使用的变量
'no-unused-vars': 'off',
// 对象展开时总是要添加逗号,一行时行末不需要逗号
// 'comma-dangle': ['error', 'always-multiline'],
// 关闭禁用无效标签
'no-tabs': 'off',
// 关闭空行检测
'no-multiple-empty-lines': 'off',
// 关闭模板字符串检测
'no-template-curly-in-string': 'off',
'no-console': 'off',
// 禁止添加分号
semi: ['error', 'never']
}, },
parserOptions: { parserOptions: {
...@@ -37,4 +98,4 @@ module.exports = { ...@@ -37,4 +98,4 @@ module.exports = {
], ],
extends: ['plugin:vue/essential', '@vue/prettier'] extends: ['plugin:vue/essential', '@vue/prettier']
}; }
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
"eslint": "5.15.3", "eslint": "5.15.3",
"eslint-plugin-prettier": "^3.1.0", "eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-vue": "5.2.2", "eslint-plugin-vue": "5.2.2",
"eslint-config-prettier": "^6.1.0",
"prettier-eslint-cli": "^5.0.0",
"prettier": "^1.18.2", "prettier": "^1.18.2",
"html-webpack-plugin": "3.2.0", "html-webpack-plugin": "3.2.0",
"husky": "1.3.1", "husky": "1.3.1",
......
...@@ -38,7 +38,7 @@ router.beforeEach(async(to, from, next) => { ...@@ -38,7 +38,7 @@ router.beforeEach(async(to, from, next) => {
// generate accessible routes map based on roles // generate accessible routes map based on roles
const accessRoutes = await store.dispatch('permission/generateRoutes', roles) const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
debugger
// dynamically add accessible routes // dynamically add accessible routes
router.addRoutes(accessRoutes) router.addRoutes(accessRoutes)
......
...@@ -3,389 +3,7 @@ import Router from 'vue-router' ...@@ -3,389 +3,7 @@ import Router from 'vue-router'
Vue.use(Router) Vue.use(Router)
/* Layout */ import constantRoutes from './route_map'
import Layout from '@/layout'
/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'
/**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
*
* hidden: true if set true, item will not show in the sidebar(default is false)
* alwaysShow: true if set true, will always show the root menu
* if not set alwaysShow, when item has more than one children route,
* it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor'] control the page roles (you can set multiple roles)
title: 'title' the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name' the icon show in the sidebar
noCache: true if set true, the page will no be cached(default is false)
affix: true if set true, the tag will affix in the tags-view
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
}
*/
/**
* constantRoutes
* a base page that does not have permission requirements
* all roles can be accessed
*/
export const constantRoutes = [
{
path: '/redirect',
component: Layout,
hidden: true,
children: [
{
path: '/redirect/:path*',
component: () => import('@/views/redirect/index')
}
]
},
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/auth-redirect',
component: () => import('@/views/login/auth-redirect'),
hidden: true
},
{
path: '/404',
component: () => import('@/views/error-page/404'),
hidden: true
},
{
path: '/401',
component: () => import('@/views/error-page/401'),
hidden: true
},
{
path: '/',
component: Layout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
component: () => import('@/views/dashboard/index'),
name: 'Dashboard',
meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
}
]
},
{
path: '/documentation',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/documentation/index'),
name: 'Documentation',
meta: { title: 'Documentation', icon: 'documentation', affix: true }
}
]
},
{
path: '/guide',
component: Layout,
redirect: '/guide/index',
children: [
{
path: 'index',
component: () => import('@/views/guide/index'),
name: 'Guide',
meta: { title: 'Guide', icon: 'guide', noCache: true }
}
]
},
{
path: '/profile',
component: Layout,
redirect: '/profile/index',
hidden: true,
children: [
{
path: 'index',
component: () => import('@/views/profile/index'),
name: 'Profile',
meta: { title: 'Profile', icon: 'user', noCache: true }
}
]
}
]
/**
* asyncRoutes
* the routes that need to be dynamically loaded based on user roles
*/
export const asyncRoutes = [
{
path: '/permission',
component: Layout,
redirect: '/permission/page',
alwaysShow: true, // will always show the root menu
name: 'Permission',
meta: {
title: 'Permission',
icon: 'lock',
roles: ['admin', 'editor'] // you can set roles in root nav
},
children: [
{
path: 'page',
component: () => import('@/views/permission/page'),
name: 'PagePermission',
meta: {
title: 'Page Permission',
roles: ['admin'] // or you can only set roles in sub nav
}
},
{
path: 'directive',
component: () => import('@/views/permission/directive'),
name: 'DirectivePermission',
meta: {
title: 'Directive Permission'
// if do not set roles, means: this page does not require permission
}
},
{
path: 'role',
component: () => import('@/views/permission/role'),
name: 'RolePermission',
meta: {
title: 'Role Permission',
roles: ['admin']
}
}
]
},
{
path: '/icon',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/icons/index'),
name: 'Icons',
meta: { title: 'Icons', icon: 'icon', noCache: true }
}
]
},
/** when your routing map is too long, you can split it into small modules **/
componentsRouter,
chartsRouter,
nestedRouter,
tableRouter,
{
path: '/example',
component: Layout,
redirect: '/example/list',
name: 'Example',
meta: {
title: 'Example',
icon: 'example'
},
children: [
{
path: 'create',
component: () => import('@/views/example/create'),
name: 'CreateArticle',
meta: { title: 'Create Article', icon: 'edit' }
},
{
path: 'edit/:id(\\d+)',
component: () => import('@/views/example/edit'),
name: 'EditArticle',
meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
hidden: true
},
{
path: 'list',
component: () => import('@/views/example/list'),
name: 'ArticleList',
meta: { title: 'Article List', icon: 'list' }
}
]
},
{
path: '/tab',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/tab/index'),
name: 'Tab',
meta: { title: 'Tab', icon: 'tab' }
}
]
},
{
path: '/error',
component: Layout,
redirect: 'noRedirect',
name: 'ErrorPages',
meta: {
title: 'Error Pages',
icon: '404'
},
children: [
{
path: '401',
component: () => import('@/views/error-page/401'),
name: 'Page401',
meta: { title: '401', noCache: true }
},
{
path: '404',
component: () => import('@/views/error-page/404'),
name: 'Page404',
meta: { title: '404', noCache: true }
}
]
},
{
path: '/error-log',
component: Layout,
children: [
{
path: 'log',
component: () => import('@/views/error-log/index'),
name: 'ErrorLog',
meta: { title: 'Error Log', icon: 'bug' }
}
]
},
{
path: '/excel',
component: Layout,
redirect: '/excel/export-excel',
name: 'Excel',
meta: {
title: 'Excel',
icon: 'excel'
},
children: [
{
path: 'export-excel',
component: () => import('@/views/excel/export-excel'),
name: 'ExportExcel',
meta: { title: 'Export Excel' }
},
{
path: 'export-selected-excel',
component: () => import('@/views/excel/select-excel'),
name: 'SelectExcel',
meta: { title: 'Export Selected' }
},
{
path: 'export-merge-header',
component: () => import('@/views/excel/merge-header'),
name: 'MergeHeader',
meta: { title: 'Merge Header' }
},
{
path: 'upload-excel',
component: () => import('@/views/excel/upload-excel'),
name: 'UploadExcel',
meta: { title: 'Upload Excel' }
}
]
},
{
path: '/zip',
component: Layout,
redirect: '/zip/download',
alwaysShow: true,
name: 'Zip',
meta: { title: 'Zip', icon: 'zip' },
children: [
{
path: 'download',
component: () => import('@/views/zip/index'),
name: 'ExportZip',
meta: { title: 'Export Zip' }
}
]
},
{
path: '/pdf',
component: Layout,
redirect: '/pdf/index',
children: [
{
path: 'index',
component: () => import('@/views/pdf/index'),
name: 'PDF',
meta: { title: 'PDF', icon: 'pdf' }
}
]
},
{
path: '/pdf/download',
component: () => import('@/views/pdf/download'),
hidden: true
},
{
path: '/theme',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/theme/index'),
name: 'Theme',
meta: { title: 'Theme', icon: 'theme' }
}
]
},
{
path: '/clipboard',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/clipboard/index'),
name: 'ClipboardDemo',
meta: { title: 'Clipboard', icon: 'clipboard' }
}
]
},
{
path: 'external-link',
component: Layout,
children: [
{
path: 'https://github.com/PanJiaChen/vue-element-admin',
meta: { title: 'External Link', icon: 'link' }
}
]
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({ const createRouter = () => new Router({
// mode: 'history', // require service support // mode: 'history', // require service support
......
/*
路由映射表,由路由名映射确定。
需要大改菜单表
*/
/* Layout */
import Layout from '@/layout'
/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'
/**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
*
* hidden: true if set true, item will not show in the sidebar(default is false)
* alwaysShow: true if set true, will always show the root menu
* if not set alwaysShow, when item has more than one children route,
* it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor'] control the page roles (you can set multiple roles)
title: 'title' the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name' the icon show in the sidebar
noCache: true if set true, the page will no be cached(default is false)
affix: true if set true, the tag will affix in the tags-view
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
}
*/
/**
* constantRoutes
* a base page that does not have permission requirements
* all roles can be accessed
*/
export const constantRoutes = [
{
path: '/redirect',
component: Layout,
hidden: true,
children: [
{
path: '/redirect/:path*',
component: () => import('@/views/redirect/index')
}
]
},
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/auth-redirect',
component: () => import('@/views/login/auth-redirect'),
hidden: true
},
{
path: '/404',
component: () => import('@/views/error-page/404'),
hidden: true
},
{
path: '/401',
component: () => import('@/views/error-page/401'),
hidden: true
},
{
path: '/',
component: Layout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
component: () => import('@/views/dashboard/index'),
name: 'Dashboard',
meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
}
]
},
{
path: '/documentation',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/documentation/index'),
name: 'Documentation',
meta: { title: 'Documentation', icon: 'documentation', affix: false }
}
]
},
{
path: '/guide',
component: Layout,
redirect: '/guide/index',
children: [
{
path: 'index',
component: () => import('@/views/guide/index'),
name: 'Guide',
meta: { title: 'Guide', icon: 'guide', noCache: true }
}
]
},
{
path: '/profile',
component: Layout,
redirect: '/profile/index',
hidden: true,
children: [
{
path: 'index',
component: () => import('@/views/profile/index'),
name: 'Profile',
meta: { title: 'Profile', icon: 'user', noCache: true }
}
]
}
]
/**
* asyncRoutes
* the routes that need to be dynamically loaded based on user roles
*/
export const asyncRoutes = [
{
path: '/permission',
component: Layout,
redirect: '/permission/page',
alwaysShow: true, // will always show the root menu
name: 'Permission',
meta: {
title: 'Permission',
icon: 'lock',
roles: ['admin', 'editor'] // you can set roles in root nav
},
children: [
{
path: 'page',
component: () => import('@/views/permission/page'),
name: 'PagePermission',
meta: {
title: 'Page Permission',
roles: ['admin'] // or you can only set roles in sub nav
}
},
{
path: 'directive',
component: () => import('@/views/permission/directive'),
name: 'DirectivePermission',
meta: {
title: 'Directive Permission'
// if do not set roles, means: this page does not require permission
}
},
{
path: 'role',
component: () => import('@/views/permission/role'),
name: 'RolePermission',
meta: {
title: 'Role Permission',
roles: ['admin']
}
}
]
},
{
path: '/icon',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/icons/index'),
name: 'Icons',
meta: { title: 'Icons', icon: 'icon', noCache: true }
}
]
},
/** when your routing map is too long, you can split it into small modules **/
componentsRouter,
chartsRouter,
nestedRouter,
tableRouter,
{
path: '/example',
component: Layout,
redirect: '/example/list',
name: 'Example',
meta: {
title: 'Example',
icon: 'example'
},
children: [
{
path: 'create',
component: () => import('@/views/example/create'),
name: 'CreateArticle',
meta: { title: 'Create Article', icon: 'edit' }
},
{
path: 'edit/:id(\\d+)',
component: () => import('@/views/example/edit'),
name: 'EditArticle',
meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
hidden: true
},
{
path: 'list',
component: () => import('@/views/example/list'),
name: 'ArticleList',
meta: { title: 'Article List', icon: 'list' }
}
]
},
{
path: '/tab',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/tab/index'),
name: 'Tab',
meta: { title: 'Tab', icon: 'tab' }
}
]
},
{
path: '/error',
component: Layout,
redirect: 'noRedirect',
name: 'ErrorPages',
meta: {
title: 'Error Pages',
icon: '404'
},
children: [
{
path: '401',
component: () => import('@/views/error-page/401'),
name: 'Page401',
meta: { title: '401', noCache: true }
},
{
path: '404',
component: () => import('@/views/error-page/404'),
name: 'Page404',
meta: { title: '404', noCache: true }
}
]
},
{
path: '/error-log',
component: Layout,
children: [
{
path: 'log',
component: () => import('@/views/error-log/index'),
name: 'ErrorLog',
meta: { title: 'Error Log', icon: 'bug' }
}
]
},
{
path: '/excel',
component: Layout,
redirect: '/excel/export-excel',
name: 'Excel',
meta: {
title: 'Excel',
icon: 'excel'
},
children: [
{
path: 'export-excel',
component: () => import('@/views/excel/export-excel'),
name: 'ExportExcel',
meta: { title: 'Export Excel' }
},
{
path: 'export-selected-excel',
component: () => import('@/views/excel/select-excel'),
name: 'SelectExcel',
meta: { title: 'Export Selected' }
},
{
path: 'export-merge-header',
component: () => import('@/views/excel/merge-header'),
name: 'MergeHeader',
meta: { title: 'Merge Header' }
},
{
path: 'upload-excel',
component: () => import('@/views/excel/upload-excel'),
name: 'UploadExcel',
meta: { title: 'Upload Excel' }
}
]
},
{
path: '/zip',
component: Layout,
redirect: '/zip/download',
alwaysShow: true,
name: 'Zip',
meta: { title: 'Zip', icon: 'zip' },
children: [
{
path: 'download',
component: () => import('@/views/zip/index'),
name: 'ExportZip',
meta: { title: 'Export Zip' }
}
]
},
{
path: '/pdf',
component: Layout,
redirect: '/pdf/index',
children: [
{
path: 'index',
component: () => import('@/views/pdf/index'),
name: 'PDF',
meta: { title: 'PDF', icon: 'pdf' }
}
]
},
{
path: '/pdf/download',
component: () => import('@/views/pdf/download'),
hidden: true
},
{
path: '/theme',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/theme/index'),
name: 'Theme',
meta: { title: 'Theme', icon: 'theme' }
}
]
},
{
path: '/clipboard',
component: Layout,
children: [
{
path: 'index',
component: () => import('@/views/clipboard/index'),
name: 'ClipboardDemo',
meta: { title: 'Clipboard', icon: 'clipboard' }
}
]
},
{
path: 'external-link',
component: Layout,
children: [
{
path: 'https://github.com/PanJiaChen/vue-element-admin',
meta: { title: 'External Link', icon: 'link' }
}
]
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]
import { asyncRoutes, constantRoutes } from '@/router' import { constantRoutes } from '@/router'
import { getRoutes } from '@/api/role'
/** /**
* Use meta.role to determine if the current user has permission * Use meta.role to determine if the current user has permission
...@@ -48,15 +49,20 @@ const mutations = { ...@@ -48,15 +49,20 @@ const mutations = {
const actions = { const actions = {
generateRoutes({ commit }, roles) { generateRoutes({ commit }, roles) {
return new Promise(resolve => { return new Promise((resolve, reject) => {
let accessedRoutes getRoutes()
if (roles.includes('admin')) { .then(response => {
accessedRoutes = asyncRoutes || [] let accessedRoutes,
} else { asyncRoutes = response.data
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
} accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
commit('SET_ROUTES', accessedRoutes) debugger
resolve(accessedRoutes) commit('SET_ROUTES', accessedRoutes)
resolve(accessedRoutes)
})
.catch(error => {
reject(error)
})
}) })
} }
} }
......
...@@ -33,57 +33,63 @@ const actions = { ...@@ -33,57 +33,63 @@ const actions = {
login({ commit }, userInfo) { login({ commit }, userInfo) {
const { username, password } = userInfo const { username, password } = userInfo
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login({ username: username.trim(), password: password }).then(response => { login({ username: username.trim(), password: password })
const { data } = response .then(response => {
commit('SET_TOKEN', data.token) const { data } = response
setToken(data.token) commit('SET_TOKEN', data.token)
resolve() setToken(data.token)
}).catch(error => { resolve()
reject(error) })
}) .catch(error => {
reject(error)
})
}) })
}, },
// get user info // get user info
getInfo({ commit, state }) { getInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo(state.token).then(response => { getInfo(state.token)
const { data } = response .then(response => {
const { data } = response
if (!data) {
reject('Verification failed, please Login again.') if (!data) {
} reject('Verification failed, please Login again.')
}
const { roles, name, avatar, introduction } = data
const { roles, name, avatar, introduction } = data
// roles must be a non-empty array
if (!roles || roles.length <= 0) { // roles must be a non-empty array
reject('getInfo: roles must be a non-null array!') if (!roles || roles.length <= 0) {
} reject('getInfo: roles must be a non-null array!')
}
commit('SET_ROLES', roles)
commit('SET_NAME', name) commit('SET_ROLES', roles)
commit('SET_AVATAR', avatar) commit('SET_NAME', name)
commit('SET_INTRODUCTION', introduction) commit('SET_AVATAR', avatar)
resolve(data) commit('SET_INTRODUCTION', introduction)
}).catch(error => { resolve(data)
reject(error) })
}) .catch(error => {
reject(error)
})
}) })
}, },
// user logout // user logout
logout({ commit, state }) { logout({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
logout(state.token).then(() => { logout(state.token)
commit('SET_TOKEN', '') .then(() => {
commit('SET_ROLES', []) commit('SET_TOKEN', '')
removeToken() commit('SET_ROLES', [])
resetRouter() removeToken()
resolve() resetRouter()
}).catch(error => { resolve()
reject(error) })
}) .catch(error => {
reject(error)
})
}) })
}, },
...@@ -110,7 +116,9 @@ const actions = { ...@@ -110,7 +116,9 @@ const actions = {
resetRouter() resetRouter()
// generate accessible routes map based on roles // generate accessible routes map based on roles
const accessRoutes = await dispatch('permission/generateRoutes', roles, { root: true }) const accessRoutes = await dispatch('permission/generateRoutes', roles, {
root: true
})
// dynamically add accessible routes // dynamically add accessible routes
router.addRoutes(accessRoutes) router.addRoutes(accessRoutes)
......
...@@ -3,9 +3,6 @@ import { MessageBox, Message } from 'element-ui' ...@@ -3,9 +3,6 @@ import { MessageBox, Message } from 'element-ui'
import store from '@/store' import store from '@/store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
const axiosUrl =
process.env.NODE_ENV === 'development' ? 'localhost:8080' : 'localhost' // request host
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
......
<template> <template>
<div class="login-container"> <div class="login-container">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left"> <el-form
ref="loginForm"
:model="loginForm"
:rules="loginRules"
class="login-form"
autocomplete="on"
label-position="left"
>
<div class="title-container"> <div class="title-container">
<h3 class="title">用户登录</h3> <h3 class="title">用户登录</h3>
</div> </div>
...@@ -21,7 +27,12 @@ ...@@ -21,7 +27,12 @@
/> />
</el-form-item> </el-form-item>
<el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual> <el-tooltip
v-model="capsTooltip"
content="Caps lock is On"
placement="right"
manual
>
<el-form-item prop="password"> <el-form-item prop="password">
<span class="svg-container"> <span class="svg-container">
<svg-icon icon-class="password" /> <svg-icon icon-class="password" />
...@@ -40,18 +51,31 @@ ...@@ -40,18 +51,31 @@
@keyup.enter.native="handleLogin" @keyup.enter.native="handleLogin"
/> />
<span class="show-pwd" @click="showPwd"> <span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" /> <svg-icon
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
/>
</span> </span>
</el-form-item> </el-form-item>
</el-tooltip> </el-tooltip>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button> <el-button
:loading="loading"
type="primary"
style="width:100%;margin-bottom:30px;"
@click.native.prevent="handleLogin"
>
Login
</el-button>
<div style="position:relative"> <div style="position:relative">
<div class="tips"> <div class="tips">
<span /> <span />
</div> </div>
<el-button class="thirdparty-button" type="primary" @click="showDialog=true"> <el-button
class="thirdparty-button"
type="primary"
@click="showDialog = true"
>
Or connect with Or connect with
</el-button> </el-button>
</div> </div>
...@@ -59,9 +83,9 @@ ...@@ -59,9 +83,9 @@
<el-dialog title="Or connect with" :visible.sync="showDialog"> <el-dialog title="Or connect with" :visible.sync="showDialog">
本地环境无法模拟,请合并到线上环境再测试!! 本地环境无法模拟,请合并到线上环境再测试!!
<br> <br />
<br> <br />
<br> <br />
<social-sign /> <social-sign />
</el-dialog> </el-dialog>
</div> </div>
...@@ -95,8 +119,12 @@ export default { ...@@ -95,8 +119,12 @@ export default {
password: '111111' password: '111111'
}, },
loginRules: { loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }], username: [
password: [{ required: true, trigger: 'blur', validator: validatePassword }] { required: true, trigger: 'blur', validator: validateUsername }
],
password: [
{ required: true, trigger: 'blur', validator: validatePassword }
]
}, },
passwordType: 'password', passwordType: 'password',
capsTooltip: false, capsTooltip: false,
...@@ -134,7 +162,10 @@ export default { ...@@ -134,7 +162,10 @@ export default {
methods: { methods: {
checkCapslock({ shiftKey, key } = {}) { checkCapslock({ shiftKey, key } = {}) {
if (key && key.length === 1) { if (key && key.length === 1) {
if (shiftKey && (key >= 'a' && key <= 'z') || !shiftKey && (key >= 'A' && key <= 'Z')) { if (
(shiftKey && (key >= 'a' && key <= 'z')) ||
(!shiftKey && (key >= 'A' && key <= 'Z'))
) {
this.capsTooltip = true this.capsTooltip = true
} else { } else {
this.capsTooltip = false this.capsTooltip = false
...@@ -158,9 +189,13 @@ export default { ...@@ -158,9 +189,13 @@ export default {
this.$refs.loginForm.validate(valid => { this.$refs.loginForm.validate(valid => {
if (valid) { if (valid) {
this.loading = true this.loading = true
this.$store.dispatch('user/login', this.loginForm) this.$store
.dispatch('user/login', this.loginForm)
.then(() => { .then(() => {
this.$router.push({ path: this.redirect || '/', query: this.otherQuery }) this.$router.push({
path: this.redirect || '/',
query: this.otherQuery
})
this.loading = false this.loading = false
}) })
.catch(() => { .catch(() => {
...@@ -206,8 +241,8 @@ export default { ...@@ -206,8 +241,8 @@ export default {
/* 修复input 背景不协调 和光标变色 */ /* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */ /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
$bg:#283443; $bg: #283443;
$light_gray:#fff; $light_gray: #fff;
$cursor: #fff; $cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) { @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
...@@ -250,9 +285,9 @@ $cursor: #fff; ...@@ -250,9 +285,9 @@ $cursor: #fff;
</style> </style>
<style lang="scss" scoped> <style lang="scss" scoped>
$bg:#2d3a4b; $bg: #2d3a4b;
$dark_gray:#889aa4; $dark_gray: #889aa4;
$light_gray:#eee; $light_gray: #eee;
.login-container { .login-container {
min-height: 100%; min-height: 100%;
......
...@@ -31,7 +31,7 @@ module.exports = { ...@@ -31,7 +31,7 @@ module.exports = {
productionSourceMap: false, productionSourceMap: false,
devServer: { devServer: {
port: port, port: port,
open: true, open: false,
overlay: { overlay: {
warnings: false, warnings: false,
errors: true errors: true
...@@ -40,7 +40,7 @@ module.exports = { ...@@ -40,7 +40,7 @@ module.exports = {
// change xxx-api/login => mock/login // change xxx-api/login => mock/login
// detail: https://cli.vuejs.org/config/#devserver-proxy // detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: { [process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:${port}/mock`, target: process.env.VUE_APP_SERVER_HOST,
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: '' ['^' + process.env.VUE_APP_BASE_API]: ''
......
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.ibeetl</groupId> <groupId>com.ibeetl</groupId>
<artifactId>admin</artifactId> <artifactId>admin</artifactId>
...@@ -34,32 +34,18 @@ ...@@ -34,32 +34,18 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
</dependency> <optional>true</optional>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter-integration</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId> <artifactId>spring-boot-starter-quartz</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment