mirror of
https://github.com/iczer/vue-antd-admin.git
synced 2025-04-05 06:17:43 +08:00
chore: optimize services model;🌟
This commit is contained in:
parent
d741904f50
commit
45d62e4860
3
.env
3
.env
@ -1,5 +1,6 @@
|
||||
VUE_APP_NAME=admin
|
||||
VUE_APP_NAME=Admin
|
||||
VUE_APP_ROUTES_KEY=admin.routes
|
||||
VUE_APP_PERMISSIONS_KEY=admin.permissions
|
||||
VUE_APP_ROLES_KEY=admin.roles
|
||||
VUE_APP_USER_KEY=admin.user
|
||||
VUE_APP_API_BASE_URL=http://api.iczer.com
|
||||
|
@ -1,5 +1 @@
|
||||
VUE_APP_NAME=admin
|
||||
VUE_APP_ROUTES_KEY=admin.routes
|
||||
VUE_APP_PERMISSIONS_KEY=admin.permissions
|
||||
VUE_APP_ROLES_KEY=admin.roles
|
||||
VUE_APP_USER_KEY=admin.user
|
||||
VUE_APP_API_BASE_URL=http://dev.iczer.com
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
<script>
|
||||
import {mapGetters} from 'vuex'
|
||||
import {logout} from '@/services'
|
||||
import {logout} from '@/services/user'
|
||||
|
||||
export default {
|
||||
name: 'HeaderAvatar',
|
||||
|
@ -7,8 +7,7 @@ const user = Mock.mock({
|
||||
address: '@CITY',
|
||||
position: '@POSITION'
|
||||
})
|
||||
|
||||
Mock.mock('/login', 'post', ({body}) => {
|
||||
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/login`, 'post', ({body}) => {
|
||||
let result = {}
|
||||
const {name, password} = JSON.parse(body)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Mock from 'mockjs'
|
||||
|
||||
Mock.mock('/routes', 'get', () => {
|
||||
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/routes`, 'get', () => {
|
||||
let result = {}
|
||||
result.code = 0
|
||||
result.data = [{
|
||||
|
@ -75,7 +75,7 @@
|
||||
|
||||
<script>
|
||||
import CommonLayout from '@/layouts/CommonLayout'
|
||||
import {login, getRoutesConfig} from '@/services'
|
||||
import {login, getRoutesConfig} from '@/services/user'
|
||||
import {setAuthorization} from '@/utils/request'
|
||||
import {loadRoutes} from '@/utils/routerUtil'
|
||||
import {mapMutations} from 'vuex'
|
||||
@ -112,9 +112,7 @@ export default {
|
||||
this.logging = false
|
||||
const loginRes = res.data
|
||||
if (loginRes.code >= 0) {
|
||||
const user = loginRes.data.user
|
||||
const permissions = loginRes.data.permissions
|
||||
const roles = loginRes.data.roles
|
||||
const {user, permissions, roles} = loginRes.data
|
||||
this.setUser(user)
|
||||
this.setPermissions(permissions)
|
||||
this.setRoles(roles)
|
||||
|
@ -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 = {
|
||||
LOGIN: `${BASE_URL}/login`,
|
||||
ROUTES: `${BASE_URL}/routes`
|
||||
|
@ -1,7 +1,5 @@
|
||||
import {login, logout, getRoutesConfig} from './user'
|
||||
import userService from './user'
|
||||
|
||||
export {
|
||||
login,
|
||||
logout,
|
||||
getRoutesConfig
|
||||
userService
|
||||
}
|
||||
|
@ -7,25 +7,28 @@ import {request, METHOD, removeAuthorization} from '@/utils/request'
|
||||
* @param password 账户密码
|
||||
* @returns {Promise<AxiosResponse<T>>}
|
||||
*/
|
||||
async function login(name, password) {
|
||||
export async function login(name, password) {
|
||||
return request(LOGIN, METHOD.POST, {
|
||||
name: name,
|
||||
password: password
|
||||
})
|
||||
}
|
||||
|
||||
async function getRoutesConfig() {
|
||||
export async function getRoutesConfig() {
|
||||
return request(ROUTES, METHOD.GET)
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
function logout() {
|
||||
export function logout() {
|
||||
localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
|
||||
localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
|
||||
localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
|
||||
removeAuthorization()
|
||||
}
|
||||
|
||||
export {login, logout, getRoutesConfig}
|
||||
export default {
|
||||
login,
|
||||
logout,
|
||||
getRoutesConfig
|
||||
}
|
||||
|
@ -2,8 +2,18 @@ let path = require('path')
|
||||
const ThemeColorReplacer = require('webpack-theme-color-replacer')
|
||||
const {getThemeColors, modifyVars} = require('./src/utils/themeUtil')
|
||||
const {resolveCss} = require('./src/utils/theme-color-replacer-extend')
|
||||
|
||||
module.exports = {
|
||||
devServer: {
|
||||
// proxy: {
|
||||
// '/api': { //此处要与 /services/api.js 中的 API_PROXY_PREFIX 值保持一致
|
||||
// target: process.env.VUE_APP_API_BASE_URL,
|
||||
// changeOrigin: true,
|
||||
// pathRewrite: {
|
||||
// '^/api': ''
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
},
|
||||
pluginOptions: {
|
||||
'style-resources-loader': {
|
||||
preProcessor: 'less',
|
||||
|
Loading…
x
Reference in New Issue
Block a user