Commit a30f21ad authored by zengchao's avatar zengchao
Browse files

-

parent ab4da671
<!--
* @Author: 一日看尽长安花
* @since: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: 一日看尽长安花
* @Description:
-->
<template> <template>
<div :class="{'hidden':hidden}" class="pagination-container"> <div :class="{ hidden: hidden }" class="pagination-container">
<el-pagination <el-pagination
:background="background" :background="background"
:current-page.sync="currentPage" :current-page.sync="currentPage"
...@@ -15,7 +22,7 @@ ...@@ -15,7 +22,7 @@
</template> </template>
<script> <script>
import { scrollTo } from '@/utils/scroll-to' import { scrollTo } from '@/utils/scroll-to';
export default { export default {
name: 'Pagination', name: 'Pagination',
...@@ -35,7 +42,7 @@ export default { ...@@ -35,7 +42,7 @@ export default {
pageSizes: { pageSizes: {
type: Array, type: Array,
default() { default() {
return [10, 20, 30, 50] return [10, 20, 30, 50];
} }
}, },
layout: { layout: {
...@@ -56,38 +63,38 @@ export default { ...@@ -56,38 +63,38 @@ export default {
} }
}, },
computed: { computed: {
currentPage: { currentPagge: {
get() { get() {
return this.page return this.page;
}, },
set(val) { set(val) {
this.$emit('update:page', val) this.$emit('update:page', val);
} }
}, },
pageSize: { pageSize: {
get() { get() {
return this.limit return this.limit;
}, },
set(val) { set(val) {
this.$emit('update:limit', val) this.$emit('update:limit', val);
} }
} }
}, },
methods: { methods: {
handleSizeChange(val) { handleSizeChange(val) {
this.$emit('pagination', { page: this.currentPage, limit: val }) this.$emit('pagination', { page: this.currentPage, limit: val });
if (this.autoScroll) { if (this.autoScroll) {
scrollTo(0, 800) scrollTo(0, 800);
} }
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
this.$emit('pagination', { page: val, limit: this.pageSize }) this.$emit('pagination', { page: val, limit: this.pageSize });
if (this.autoScroll) { if (this.autoScroll) {
scrollTo(0, 800) scrollTo(0, 800);
} }
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
......
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: your name
*/
import { constantRoutes } from '@/router'; import { constantRoutes } from '@/router';
import { getRoutes } from '@/api/role'; import { getRoutes } from '@/api/role';
import { default as asyncRoutesMap } from '@/router/maps/index'; import { default as asyncRoutesMap } from '@/router/maps/index';
import { import { deepClone, objectMerge } from '@/utils/index';
deepClone, import { isExists, isNotExists } from '@/utils/object-util';
objectMerge,
isNotNullAndNotUndefined,
} from '@/utils/index';
/** /**
* Use meta.role to determine if the current user has permission * Use meta.role to determine if the current user has permission
...@@ -39,10 +43,10 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -39,10 +43,10 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
// 从前端路由表中选出与当前后端路由信息相对应的那条路由信息 // 从前端路由表中选出与当前后端路由信息相对应的那条路由信息
for (let rm of routesMap) { for (let rm of routesMap) {
if ( if (
isNotNullAndNotUndefined(rm.name) && isExists(rm.name) &&
isNotNullAndNotUndefined(route.name) && isExists(route.name) &&
isNotNullAndNotUndefined(rm.path) && isExists(rm.path) &&
isNotNullAndNotUndefined(route.path) && isExists(route.path) &&
(rm.path === route.path || rm.name === route.name) (rm.path === route.path || rm.name === route.name)
) { ) {
// 优先path判断,是因为导航菜单的展开和收起是根据path判断的。 // 优先path判断,是因为导航菜单的展开和收起是根据path判断的。
...@@ -57,7 +61,7 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -57,7 +61,7 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
tempRoute.children = filterAsyncRoutes( tempRoute.children = filterAsyncRoutes(
tempRouteMap.children, tempRouteMap.children,
tempRoute.children, tempRoute.children,
roles, roles
); );
} }
// 以后台路由表优先,相同属性覆盖前台路由映射.除去路由路径交由前台控制 // 以后台路由表优先,相同属性覆盖前台路由映射.除去路由路径交由前台控制
...@@ -74,14 +78,14 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -74,14 +78,14 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
const state = { const state = {
routes: [], routes: [],
addRoutes: [], addRoutes: []
}; };
const mutations = { const mutations = {
SET_ROUTES: (state, routes) => { SET_ROUTES: (state, routes) => {
state.addRoutes = routes; state.addRoutes = routes;
state.routes = constantRoutes.concat(routes); state.routes = constantRoutes.concat(routes);
}, }
}; };
const actions = { const actions = {
...@@ -95,7 +99,7 @@ const actions = { ...@@ -95,7 +99,7 @@ const actions = {
accessedRoutes = filterAsyncRoutes( accessedRoutes = filterAsyncRoutes(
deepClone(asyncRoutesMap), deepClone(asyncRoutesMap),
asyncRoutes, asyncRoutes,
roles, roles
); );
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true }); accessedRoutes.push({ path: '*', redirect: '/404', hidden: true });
...@@ -106,12 +110,12 @@ const actions = { ...@@ -106,12 +110,12 @@ const actions = {
reject(error); reject(error);
}); });
}); });
}, }
}; };
export default { export default {
namespaced: true, namespaced: true,
state, state,
mutations, mutations,
actions, actions
}; };
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-10-11 17:40:57
* @LastEditTime: 2019-10-12 09:24:07
* @LastEditors: Please set LastEditors
*/
/**
* @description: obj不存在。由于js存在undefined 和 null两种特殊的数据类型,认为从空间和引用指向上,只要有一个不存在则判断为不存在。
* @param {Object}
* @return {Boolean}
*/
export function isExists(obj) {
return void 0 === obj || null === obj;
}
/**
* @description: obj存在
* @param {Object}
* @return {Boolean}
*/
export function isNotExists(obj) {
return !isExists(obj);
}
import axios from 'axios' /*
import { MessageBox, Message } from 'element-ui' * @Description: In User Settings Edit
import store from '@/store' * @Author: your name
import { getToken } from '@/utils/auth' * @Date: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: your name
*/
import axios from 'axios';
import { MessageBox, Message } from 'element-ui';
import store from '@/store';
import { getToken } from '@/utils/auth';
// 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
// withCredentials: true, // send cookies when cross-domain requests // withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout timeout: 5000 // request timeout
}) });
// request interceptor // request interceptor
service.interceptors.request.use( service.interceptors.request.use(
...@@ -19,16 +26,16 @@ service.interceptors.request.use( ...@@ -19,16 +26,16 @@ service.interceptors.request.use(
// let each request carry token // let each request carry token
// ['Authorization'] see to MDN explain about "HTTP Authorization" // ['Authorization'] see to MDN explain about "HTTP Authorization"
// please modify it according to the actual situation // please modify it according to the actual situation
config.headers['Authorization'] = getToken() config.headers['Authorization'] = getToken();
} }
return config return config;
}, },
error => { error => {
// do something with request error // do something with request error
console.log('request err => ' + error) // for debug console.log('request err => ' + error); // for debug
return Promise.reject(error) return Promise.reject(error);
} }
) );
// response interceptor // response interceptor
service.interceptors.response.use( service.interceptors.response.use(
...@@ -43,7 +50,7 @@ service.interceptors.response.use( ...@@ -43,7 +50,7 @@ service.interceptors.response.use(
* You can also judge the status by HTTP Status Code * You can also judge the status by HTTP Status Code
*/ */
response => { response => {
const res = response.data const res = response.data;
// if the custom code is not 20000, it is judged as an error. // if the custom code is not 20000, it is judged as an error.
if (res.code !== 200) { if (res.code !== 200) {
...@@ -51,7 +58,7 @@ service.interceptors.response.use( ...@@ -51,7 +58,7 @@ service.interceptors.response.use(
message: res.message || 'Error', message: res.message || 'Error',
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) });
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014) { if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
...@@ -66,24 +73,24 @@ service.interceptors.response.use( ...@@ -66,24 +73,24 @@ service.interceptors.response.use(
} }
).then(() => { ).then(() => {
store.dispatch('user/resetToken').then(() => { store.dispatch('user/resetToken').then(() => {
location.reload() location.reload();
}) });
}) });
} }
return Promise.reject(new Error(res.message || 'Error')) return Promise.reject(new Error(res.message || 'Error'));
} else { } else {
return res return res;
} }
}, },
error => { error => {
console.log('response err ==> ' + error) // for debug console.log('response err ==> ' + error); // for debug
Message({ Message({
message: error.message, message: error.message,
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) });
return Promise.reject(error) return Promise.reject(error);
} }
) );
export default service export default service;
/*
* @Description: 字符串工具类
* @Author: 一日看尽长安花
* @Date: 2019-10-11 17:40:47
* @LastEditTime: 2019-10-12 09:36:33
* @LastEditors: Please set LastEditors
*/
import { isExists, isNotExists } from '@/utils/object-util';
import { isString, trim } from 'lodash';
/**
* @description: 字符串为空串
* @param {Object}
* @return {Boolean}
*/
export function isBlank(str) {
if (isNotExists(str)) {
if (isString(str)) {
if (trim(str).length === 0) {
return true;
} else {
return false;
}
} else {
throw 'str is not string type';
}
} else {
throw 'str is null';
}
}
/**
* @description: 字符串不为空串
* @param {Object}
* @return {Boolean}
*/
export function isNotBlank(str) {
if (isNotExists(str)) {
if (isString(str)) {
if (trim(str).length > 0) {
return true;
} else {
return false;
}
} else {
throw 'str is not string type';
}
} else {
throw 'str is null';
}
}
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