3 Star 23 Fork 10

冯文议 / vue-admin-pro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Vue Admin Pro

基于iView-Admin,最懂后端程序员的后台管理系统,View UI 4.7.0

Vue Admin Pro,这是一个简单的后端管理系统,适用于后端程序员写一写简单的后端管理系统,逻辑较简单,也不涉及权限只有简单的登录Token认证。

预览

2020,再次优化了登录页,增加了校验

重写登录页面

预览图 https://images.fengwenyi.com/1247653275613884417

目录

.
├── LICENSE
├── README.md   // 说明
├── cypress.json
├── images      // github图片说明
│   └── login.png // 登录图
├── package.json  // 依赖包
├── public
│   ├── favicon.png  // 浏览器图标
│   └── index.html   // 首页index代码
├── src
│   ├── App.vue     // App
│   ├── api           // 与服务器交互的接口存放位置
│   │   ├── data.js   // 数据接口示例
│   │   └── login.js  // 登录/登出 接口
│   ├── assets        // 资源 字体,图片,图标等
│   │   ├── fonts     // 字体
│   │   ├── icons     // 图标
│   │   └── images    // 图片
│   ├── components    // 组件
│   │   ├── charts
│   │   ├── common
│   │   ├── common-icon
│   │   ├── count-to
│   │   ├── cropper
│   │   ├── drag-drawer
│   │   ├── drag-list
│   │   ├── editor
│   │   ├── icons
│   │   ├── info-card
│   │   ├── login-form  // 登录表单组件
│   │   ├── main
│   │   ├── markdown
│   │   ├── parent-view
│   │   ├── paste-editor
│   │   ├── split-pane
│   │   ├── tables       // table组件
│   │   └── tree-select
│   ├── config           // 配置
│   │   └── index.js
│   ├── directive
│   │   ├── directives.js
│   │   ├── index.js
│   │   └── module
│   ├── index.less        // index的样式文件
│   ├── libs                // 库
│   │   ├── api.request.js  // api
│   │   ├── axios.js        // axios
│   │   ├── excel.js
│   │   ├── render-dom.js
│   │   ├── tools.js
│   │   └── util.js
│   ├── locale              // 国际化
│   │   ├── index.js
│   │   └── lang            // 多语言
│   ├── main.js             // main
│   ├── mock                // 模拟后端接口
│   │   ├── data
│   │   ├── data.js         // 数据接口
│   │   ├── index.js        // index
│   │   ├── login.js        // 登录接口
│   │   └── user.js         // 用户接口
│   ├── plugin
│   │   ├── error-store
│   │   └── index.js
│   ├── router              // 路由
│   │   ├── before-close.js
│   │   ├── index.js        // 路由策略
│   │   └── routers.js      // 路由配置
│   ├── store               // 全局存储
│   │   ├── index.js        // index
│   │   └── module          // Module
│   └── view                // 前端页面
│       ├── Home            // 首页
│       ├── Login           // 登录页
│       └── Table           // 表单也示例
├── tests
│   ├── e2e
│   │   ├── plugins
│   │   ├── specs
│   │   └── support
│   └── unit
│       └── HelloWorld.spec.js
└── vue.config.js           // vue 配置

登录

路径:

src/api/login.js

内容:

import axios from '@/libs/api.request'

/**
 * 登录
 * @param account
 * @param password
 * @returns {http.ClientRequest | ClientHttp2Stream | * | never | AxiosPromise<any>}
 */
export const login = (account, password) => {
  const data = {
    account,
    password
  }
  return axios.request({
    url: 'auth/login',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8'
    },
    data: data
  })
}

/**
 * 退出登录
 * @param token
 * @returns {http.ClientRequest | ClientHttp2Stream | * | never | AxiosPromise<any>}
 */
export const logout = (token) => {
  const data = {}
  return axios.request({
    url: 'auth/logout',
    method: 'get',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': token
    },
    data: data
  })
}

接口写法

import com.fengwenyi.vueadminproapi.entity.Login;
import net.iutil.ApiResult;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 认证
 * @author Erwin Feng
 * @since 2019-06-08 10:21
 */
@RestController
@RequestMapping(value = "/auth",
        consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AuthController {

    @PostMapping("/login")
    public ApiResult login(@RequestBody Login login) {
        String account = login.getAccount();
        String password = login.getPassword();
        if (StringUtils.isEmpty(account))
            return ApiResult.error().setCode(10001).setMsg("账号不能为空");
        if (StringUtils.isEmpty(password))
            return ApiResult.error().setCode(10002).setMsg("密码不能为空");
        if (!account.equals("admin"))
            return ApiResult.error().setCode(10003).setMsg("账号不存在");
        if (!password.equals("admin@1234"))
            return ApiResult.error().setCode(10004).setMsg("密码不正确");
        Map<String, String> map = new HashMap<>();
        map.put("token", UUID.randomUUID().toString());
        map.put("uid", UUID.randomUUID().toString());
        return ApiResult.success(map);
    }

    @GetMapping("/logout")
    public ApiResult logout(@RequestHeader String token) {
        return ApiResult.success();
    }

}

接口示例

点此处传送门

token

token格式推荐:uid_token

在API请求的时候如何携带发起请求?

如下示例:

import axios from '@/libs/api.request'
import { getToken } from '@/libs/util'

export const data = (d1, d2) => {
  const data = {
    d1,
    d2
  }
  return axios.request({
    url: 'auth/login',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: data
  })
}

API请求

重新封装API接口请求

sess request.js

示例

import request from '@/libs/request'

export function apiDataTest (data) {
  const param = JSON.stringify(data)
  return request({
    url: '/data/test',
    method: 'post',
    data: param
  })
}

配置:

export default {
  // ...
  /**
   * 接口请求配置
   */
  api: {
    /**
     * header配置
     */
    header: {
      /**
       * 是否携带token(当token存在时)
       */
      token: true,
      /**
       * 自定义token key
       */
      tokenKey: 'token',
      /**
       * 是否采用JSON方式提交
       */
      json: true
    }
  }
}

接口示例代码:

DataController.java

package com.fengwenyi.vueadminproapi.controller;

import lombok.extern.slf4j.Slf4j;
import net.iutil.ApiResult;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author Erwin Feng
 * @since 2019-07-29 09:31
 */
@Slf4j
@RestController
@RequestMapping(value = "/data",
        consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DataController {

    @PostMapping("/test")
    public ApiResult test(@RequestHeader String token, @RequestBody Object data) {
        log.info("token: {}", token);
        log.info("data: {}", data);
        return ApiResult.success("这是服务响应的数据-test");
    }

}

资料

MIT License Copyright (c) 2017-2022 Vue Admin Pro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

【停止维护】基于iView-Admin,进行简化,为后端程序员量身打造的极简后端管理系统 展开 收起
Vue 等 5 种语言
MIT
取消

发行版 (3)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/fengwenyi/vue-admin-pro.git
git@gitee.com:fengwenyi/vue-admin-pro.git
fengwenyi
vue-admin-pro
vue-admin-pro
master

搜索帮助