4
0
mirror of https://github.com/iczer/vue-antd-admin.git synced 2025-04-05 19:42:00 +08:00

chore: optimize services model;🌟

This commit is contained in:
iczer 2020-08-08 21:51:18 +08:00
parent d741904f50
commit 45d62e4860
10 changed files with 33 additions and 26 deletions

3
.env
View File

@ -1,5 +1,6 @@
VUE_APP_NAME=admin VUE_APP_NAME=Admin
VUE_APP_ROUTES_KEY=admin.routes VUE_APP_ROUTES_KEY=admin.routes
VUE_APP_PERMISSIONS_KEY=admin.permissions VUE_APP_PERMISSIONS_KEY=admin.permissions
VUE_APP_ROLES_KEY=admin.roles VUE_APP_ROLES_KEY=admin.roles
VUE_APP_USER_KEY=admin.user VUE_APP_USER_KEY=admin.user
VUE_APP_API_BASE_URL=http://api.iczer.com

View File

@ -1,5 +1 @@
VUE_APP_NAME=admin VUE_APP_API_BASE_URL=http://dev.iczer.com
VUE_APP_ROUTES_KEY=admin.routes
VUE_APP_PERMISSIONS_KEY=admin.permissions
VUE_APP_ROLES_KEY=admin.roles
VUE_APP_USER_KEY=admin.user

View File

@ -24,7 +24,7 @@
<script> <script>
import {mapGetters} from 'vuex' import {mapGetters} from 'vuex'
import {logout} from '@/services' import {logout} from '@/services/user'
export default { export default {
name: 'HeaderAvatar', name: 'HeaderAvatar',

View File

@ -7,8 +7,7 @@ const user = Mock.mock({
address: '@CITY', address: '@CITY',
position: '@POSITION' position: '@POSITION'
}) })
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/login`, 'post', ({body}) => {
Mock.mock('/login', 'post', ({body}) => {
let result = {} let result = {}
const {name, password} = JSON.parse(body) const {name, password} = JSON.parse(body)

View File

@ -1,6 +1,6 @@
import Mock from 'mockjs' import Mock from 'mockjs'
Mock.mock('/routes', 'get', () => { Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/routes`, 'get', () => {
let result = {} let result = {}
result.code = 0 result.code = 0
result.data = [{ result.data = [{

View File

@ -75,7 +75,7 @@
<script> <script>
import CommonLayout from '@/layouts/CommonLayout' import CommonLayout from '@/layouts/CommonLayout'
import {login, getRoutesConfig} from '@/services' import {login, getRoutesConfig} from '@/services/user'
import {setAuthorization} from '@/utils/request' import {setAuthorization} from '@/utils/request'
import {loadRoutes} from '@/utils/routerUtil' import {loadRoutes} from '@/utils/routerUtil'
import {mapMutations} from 'vuex' import {mapMutations} from 'vuex'
@ -112,9 +112,7 @@ export default {
this.logging = false this.logging = false
const loginRes = res.data const loginRes = res.data
if (loginRes.code >= 0) { if (loginRes.code >= 0) {
const user = loginRes.data.user const {user, permissions, roles} = loginRes.data
const permissions = loginRes.data.permissions
const roles = loginRes.data.roles
this.setUser(user) this.setUser(user)
this.setPermissions(permissions) this.setPermissions(permissions)
this.setRoles(roles) this.setRoles(roles)

View File

@ -1,5 +1,7 @@
// const BASE_URL = 'http://localhost:8080' your service base url //跨域代理前缀
const BASE_URL = '' // mock base url // const API_PROXY_PREFIX='/api'
// const BASE_URL = process.env.NODE_ENV === 'production' ? process.env.VUE_APP_API_BASE_URL : API_PROXY_PREFIX
const BASE_URL = process.env.VUE_APP_API_BASE_URL
module.exports = { module.exports = {
LOGIN: `${BASE_URL}/login`, LOGIN: `${BASE_URL}/login`,
ROUTES: `${BASE_URL}/routes` ROUTES: `${BASE_URL}/routes`

View File

@ -1,7 +1,5 @@
import {login, logout, getRoutesConfig} from './user' import userService from './user'
export { export {
login, userService
logout,
getRoutesConfig
} }

View File

@ -7,25 +7,28 @@ import {request, METHOD, removeAuthorization} from '@/utils/request'
* @param password 账户密码 * @param password 账户密码
* @returns {Promise<AxiosResponse<T>>} * @returns {Promise<AxiosResponse<T>>}
*/ */
async function login(name, password) { export async function login(name, password) {
return request(LOGIN, METHOD.POST, { return request(LOGIN, METHOD.POST, {
name: name, name: name,
password: password password: password
}) })
} }
async function getRoutesConfig() { export async function getRoutesConfig() {
return request(ROUTES, METHOD.GET) return request(ROUTES, METHOD.GET)
} }
/** /**
* 退出登录 * 退出登录
*/ */
function logout() { export function logout() {
localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY) localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY) localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
localStorage.removeItem(process.env.VUE_APP_ROLES_KEY) localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
removeAuthorization() removeAuthorization()
} }
export default {
export {login, logout, getRoutesConfig} login,
logout,
getRoutesConfig
}

View File

@ -2,8 +2,18 @@ let path = require('path')
const ThemeColorReplacer = require('webpack-theme-color-replacer') const ThemeColorReplacer = require('webpack-theme-color-replacer')
const {getThemeColors, modifyVars} = require('./src/utils/themeUtil') const {getThemeColors, modifyVars} = require('./src/utils/themeUtil')
const {resolveCss} = require('./src/utils/theme-color-replacer-extend') const {resolveCss} = require('./src/utils/theme-color-replacer-extend')
module.exports = { module.exports = {
devServer: {
// proxy: {
// '/api': { //此处要与 /services/api.js 中的 API_PROXY_PREFIX 值保持一致
// target: process.env.VUE_APP_API_BASE_URL,
// changeOrigin: true,
// pathRewrite: {
// '^/api': ''
// }
// }
// }
},
pluginOptions: { pluginOptions: {
'style-resources-loader': { 'style-resources-loader': {
preProcessor: 'less', preProcessor: 'less',