提交 b749238a 编写于 作者: yma16's avatar yma16

perf:按需引入element echarts 路由懒加载

上级 b805e45a
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
"stage-2" "stage-2"
], ],
"plugins": [ "plugins": [
"transform-vue-jsx",
"transform-runtime",
[ [
"component", "component",
{ {
"libraryName": "element-ui", "libraryName": "element-ui",
"styleLibraryName": "theme-chalk" "styleLibraryName": "theme-chalk"
} }
] ],
"transform-vue-jsx",
"transform-runtime"
], ],
"env": { "env": {
"test": { "test": {
......
...@@ -58,26 +58,22 @@ module.exports = { ...@@ -58,26 +58,22 @@ module.exports = {
// https://vue-loader.vuejs.org/en/options.html#cachebusting // https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true, cacheBusting: true,
cssSourceMap: false, cssSourceMap: true,
}, },
build: { build: {
// Template for index.html // Template for index.html
index: path.resolve(__dirname, "../dist/index.html"), index: path.resolve(__dirname, "../dist/index.html"),
// Paths // Paths
assetsRoot: path.resolve(__dirname, "../dist"), assetsRoot: path.resolve(__dirname, "../dist"),
assetsSubDirectory: "myblog_static", assetsSubDirectory: "myblog_static",
assetsPublicPath: "./", assetsPublicPath: "./",
/** /**
* Source Maps * Source Maps
*/ */
productionSourceMap: false, productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production // https://webpack.js.org/configuration/devtool/#production
devtool: "#source-map", devtool: "#source-map",
// Gzip off by default as many popular myblog_static hosts such as // Gzip off by default as many popular myblog_static hosts such as
// Surge or Netlify already gzip all myblog_static assets for you. // Surge or Netlify already gzip all myblog_static assets for you.
// Before setting to `true`, make sure to: // Before setting to `true`, make sure to:
......
...@@ -187,9 +187,6 @@ export default { ...@@ -187,9 +187,6 @@ export default {
.post(this.baseUrl + 'count/add/', { .post(this.baseUrl + 'count/add/', {
ip: clientIp ip: clientIp
}) })
.then((res) => {
console.log(res)
})
.catch((e) => { .catch((e) => {
throw Error(e) throw Error(e)
}) })
...@@ -210,7 +207,6 @@ export default { ...@@ -210,7 +207,6 @@ export default {
}, },
handleOpen (key, keyPath) { handleOpen (key, keyPath) {
console.log(key, keyPath)
if (key === '3') { if (key === '3') {
this.chat_flag = true this.chat_flag = true
this.onlineWebsocket() // 调用跳转 this.onlineWebsocket() // 调用跳转
......
...@@ -214,290 +214,290 @@ ...@@ -214,290 +214,290 @@
<script> <script>
import Email from '@/components/email/Email' import Email from '@/components/email/Email'
import VueMarkdown from "vue-markdown"; import VueMarkdown from 'vue-markdown'
import ArticleComment from "@/comment/ArticleComment"; import ArticleComment from '@/comment/ArticleComment'
import EchartWeather from "@/weather/EchartWeather"; import EchartWeather from '@/weather/EchartWeather'
import axios from "axios"; import axios from 'axios'
export default { export default {
components: { components: {
VueMarkdown, // 显示markdown的组件 VueMarkdown, // 显示markdown的组件
ArticleComment, // 子组件评论 ArticleComment, // 子组件评论
EchartWeather, // 天气 EchartWeather, // 天气
Email Email
},
name: "Article",
data() {
return {
msgDrawTitle:'~邮件沟通~',
direction:'rtl',
drawObj: {
show:false
},
// baseurl: '/api/',
baseurl: "/api/",
// baseurl: "http://yongma16.xyz/",
msg: "内容",
commmentSlogan: "评论区",
day_challenge: "训练营",
challenge_data: [
"css挑战",
"websocket聊天",
"echarts地图配置",
"vue3测试平台",
"更新中",
],
md_data: [],
md_title: [],
the_title: "",
sear_page: 0,
index_page: 0,
data: ["threejs加载模型"],
slogan: "记忆碎片",
tabPosition: "left",
weather_title: [],
weather_high: [],
weather_low: [],
toTopIsShow: false,
article_loc: 0,
challenge_loc: -1,
topshow: false,
userImg: "",
username: "匿名",
articleCommit: "评论区",
// 分页实现 page1 page2 指向数组
pageAnalys: {},
currentPage: 1,
splitLength: 6, // 划分条数
total: 0,
pageSize: 4,
pageArray: [6, 8, 10],
postcomment: {
articleId: undefined,
articleCommit: null,
},
articleId: [], // 文章的id
};
},
watch: {
topshow: function (newvalue, oldvalue) {
if (newvalue === true) {
document.getElementById("topiconid").style.display = "none";
} else {
document.getElementById("topiconid").style.display = "block";
}
}, },
}, name: 'Article',
beforeDestroy() { data () {
window.removeEventListener("onload", this.topvisible()); return {
}, msgDrawTitle: '~邮件沟通~',
mounted() { direction: 'rtl',
this.initPageSpliteFun(); drawObj: {
window.addEventListener("onload", this.topvisible()); show: false
}, },
methods: { // baseurl: '/api/',
initPageSpliteFun() { baseurl: '/api/',
this.splitLength = this.pageArray[0]; // baseurl: "http://yongma16.xyz/",
}, msg: '内容',
handleSizeChange(val) { commmentSlogan: '评论区',
// 转到第一页md_title day_challenge: '训练营',
let that = this; challenge_data: [
that.pageAnalysFun(that.pageAnalys.allTitle, val); // 触发修改 'css挑战',
}, 'websocket聊天',
handleCurrentChange(val) { 'echarts地图配置',
let that = this; 'vue3测试平台',
// 触发md_title的修改 '更新中'
that.currentPage = val; ],
that.pageAnalysFun(that.pageAnalys.allTitle); // 触发修改 md_data: [],
md_title: [],
the_title: '',
sear_page: 0,
index_page: 0,
data: ['threejs加载模型'],
slogan: '记忆碎片',
tabPosition: 'left',
weather_title: [],
weather_high: [],
weather_low: [],
toTopIsShow: false,
article_loc: 0,
challenge_loc: -1,
topshow: false,
userImg: '',
username: '匿名',
articleCommit: '评论区',
// 分页实现 page1 page2 指向数组
pageAnalys: {},
currentPage: 1,
splitLength: 6, // 划分条数
total: 0,
pageSize: 4,
pageArray: [6, 8, 10],
postcomment: {
articleId: undefined,
articleCommit: null
},
articleId: [] // 文章的id
}
}, },
pageAnalysFun(allTitleArray, selectListLength) { watch: {
let that = this; topshow: function (newvalue, oldvalue) {
that.total = allTitleArray.length; // 总数 if (newvalue === true) {
let splitLength = that.splitLength; document.getElementById('topiconid').style.display = 'none'
if (!selectListLength) { } else {
that.splitLength = that.splitLength; document.getElementById('topiconid').style.display = 'block'
} else { }
this.currentPage = 1;
that.splitLength = selectListLength; // 划分长度
}
splitLength = that.splitLength;
let splitNum = Math.ceil(that.total / splitLength); // 向上取整
that.pageAnalys.childNum = splitNum; // 子数组个数
that.pageAnalys.allTitle = allTitleArray; // 所有标题
that.pageAnalys.titleArray = new Array(); // 子数组个数
let locSplit = 0;
let locLength = splitLength; // 每一页的条数
while (splitNum--) {
// 循环获取子数组
if (splitNum >= 1) {
let childArray = [];
for (
let temp = locSplit;
temp < locLength && temp < that.total;
++temp, ++locSplit
) {
childArray.push(that.pageAnalys.allTitle[temp]);
}
that.pageAnalys.titleArray.push(childArray);
locLength += splitLength; // 分割数组长度后移
} else {
// 最后一个数组
let childArray = [];
for (let temp = locSplit; temp < that.total; ++temp) {
childArray.push(that.pageAnalys.allTitle[temp]);
}
that.pageAnalys.titleArray.push(childArray);
break;
} }
}
try {
that.md_title = that.pageAnalys.titleArray[this.currentPage - 1];
} catch (e) {
throw Error(e);
}
}, },
increment: function () { beforeDestroy () {
this.$store.commit("increment"); window.removeEventListener('onload', this.topvisible())
}, },
topvisible: function () { mounted () {
let dom = document.getElementById("hometitle"); this.initPageSpliteFun()
this.topshow = this.elementIsVisibleInViewport(dom); window.addEventListener('onload', this.topvisible())
setTimeout(this.topvisible);
}, },
elementIsVisibleInViewport: function (el, partiallyVisible = false) { methods: {
try { initPageSpliteFun () {
if (el && el.getBoundingClientRect instanceof Function) { this.splitLength = this.pageArray[0]
const { top, left, bottom, right } = el.getBoundingClientRect(); },
return partiallyVisible handleSizeChange (val) {
? ((top > 0 && top < innerHeight) || // 转到第一页md_title
let that = this
that.pageAnalysFun(that.pageAnalys.allTitle, val) // 触发修改
},
handleCurrentChange (val) {
let that = this
// 触发md_title的修改
that.currentPage = val
that.pageAnalysFun(that.pageAnalys.allTitle) // 触发修改
},
pageAnalysFun (allTitleArray, selectListLength) {
let that = this
that.total = allTitleArray.length // 总数
let splitLength = that.splitLength
if (!selectListLength) {
that.splitLength = that.splitLength
} else {
this.currentPage = 1
that.splitLength = selectListLength // 划分长度
}
splitLength = that.splitLength
let splitNum = Math.ceil(that.total / splitLength) // 向上取整
that.pageAnalys.childNum = splitNum // 子数组个数
that.pageAnalys.allTitle = allTitleArray // 所有标题
that.pageAnalys.titleArray = new Array() // 子数组个数
let locSplit = 0
let locLength = splitLength // 每一页的条数
while (splitNum--) {
// 循环获取子数组
if (splitNum >= 1) {
let childArray = []
for (
let temp = locSplit;
temp < locLength && temp < that.total;
++temp, ++locSplit
) {
childArray.push(that.pageAnalys.allTitle[temp])
}
that.pageAnalys.titleArray.push(childArray)
locLength += splitLength // 分割数组长度后移
} else {
// 最后一个数组
let childArray = []
for (let temp = locSplit; temp < that.total; ++temp) {
childArray.push(that.pageAnalys.allTitle[temp])
}
that.pageAnalys.titleArray.push(childArray)
break
}
}
try {
that.md_title = that.pageAnalys.titleArray[this.currentPage - 1]
} catch (e) {
throw Error(e)
}
},
increment: function () {
this.$store.commit('increment')
},
topvisible: function () {
let dom = document.getElementById('hometitle')
this.topshow = this.elementIsVisibleInViewport(dom)
setTimeout(this.topvisible)
},
elementIsVisibleInViewport: function (el, partiallyVisible = false) {
try {
if (el && el.getBoundingClientRect instanceof Function) {
const { top, left, bottom, right } = el.getBoundingClientRect()
return partiallyVisible
? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) && (bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < innerWidth) || ((left > 0 && left < innerWidth) ||
(right > 0 && right < innerWidth)) (right > 0 && right < innerWidth))
: top >= 0 && : top >= 0 &&
left >= 0 && left >= 0 &&
bottom <= innerHeight && bottom <= innerHeight &&
right <= innerWidth; right <= innerWidth
} }
} catch (r) { } catch (r) {
throw Error(r); throw Error(r)
} }
}, },
li_errorClass: function () {}, li_errorClass: function () {},
cssPage: function (index) { cssPage: function (index) {
this.challenge_loc = index; this.challenge_loc = index
let name = this.challenge_data[index]; let name = this.challenge_data[index]
switch (name) { switch (name) {
case "css挑战": case 'css挑战':
this.$router this.$router
.push({ .push({
path: "/css", path: '/css'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "echarts地图配置": case 'echarts地图配置':
this.$router this.$router
.push({ .push({
path: "/home", path: '/home'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "websocket聊天": case 'websocket聊天':
this.$router this.$router
.push({ .push({
path: "/onlinewebsocket", path: '/onlinewebsocket'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
break; break
case "vue3测试平台": case 'vue3测试平台':
window.open("http://yongma16.xyz/emoji_api/"); window.open('http://yongma16.xyz/emoji_api/')
break; break
default: default:
break; break
} }
}, },
open_message: function () { open_message: function () {
this.$notify({ // this.$notify({
title: "欢迎合作", // title: '欢迎合作',
message: "邮箱:1432448610@qq.com", // message: '邮箱:1432448610@qq.com',
position: "bottom-right", // position: 'bottom-right'
}); // })
}, },
openDraw() { openDraw () {
this.drawObj.show = true; this.drawObj.show = true
}, },
toTop: function () { toTop: function () {
location.href = "#home"; // 定位 location.href = '#home' // 定位
document.getElementById("mainappid").scrollTop = 0; document.getElementById('mainappid').scrollTop = 0
}, // 返回天气相当于返回顶部 }, // 返回天气相当于返回顶部
getCommentsFromArticle(id) { getCommentsFromArticle (id) {
this.$refs.commentRef.getComments(id); // 触发子组件的方法 this.$refs.commentRef.getComments(id) // 触发子组件的方法
}, },
getArticles: function (page) { getArticles: function (page) {
let that = this; // this指向转化 let that = this // this指向转化
that.article_loc = page; that.article_loc = page
// 查找文章id 从1开始 // 查找文章id 从1开始
that.postcomment.articleId = that.postcomment.articleId =
that.articleId[ that.articleId[
parseInt(page + (that.currentPage - 1) * that.splitLength) parseInt(page + (that.currentPage - 1) * that.splitLength)
]; ]
// 提交数据 page从0开始 // 提交数据 page从0开始
axios axios
.post(that.baseurl + "article/index/", { .post(that.baseurl + 'article/index/', {
value: page + (that.currentPage - 1) * that.splitLength, value: page + (that.currentPage - 1) * that.splitLength
// 传入索引 // 传入索引
}) })
.then((res) => { .then((res) => {
if (res.data.code === 1) { if (res.data.code === 1) {
let respdata = res.data; let respdata = res.data
let content = respdata.article; let content = respdata.article
that.md_data = []; // 清空 that.md_data = [] // 清空
content.map((o) => { content.map((o) => {
that.md_data.push(o); // 传入一个文章 that.md_data.push(o) // 传入一个文章
}); })
that.the_title = respdata.the_title; that.the_title = respdata.the_title
} else if (res.data.code === 0) { } else if (res.data.code === 0) {
// alter("失败!") // alter("失败!")
that.$message.error("失败"); that.$message.error('失败')
} }
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
that.getCommentsFromArticle(that.postcomment.articleId); that.getCommentsFromArticle(that.postcomment.articleId)
}
}, },
}, created: function () {
created: function () {
// 初始化 // 初始化
let that = this; let that = this
axios axios
.get(that.baseurl + "article/index/") .get(that.baseurl + 'article/index/')
.then((res) => { .then((res) => {
let resdata = res.data; let resdata = res.data
let content = resdata.article; // 传递过来的文章 进行处理 let content = resdata.article // 传递过来的文章 进行处理
let title = resdata.title; let title = resdata.title
that.articleId = resdata.articleObjectId; that.articleId = resdata.articleObjectId
that.postcomment.articleId = resdata.articleId; that.postcomment.articleId = resdata.articleId
this.$refs.commentRef.getComments(that.postcomment.articleId); // 触发子组件的方法 this.$refs.commentRef.getComments(that.postcomment.articleId) // 触发子组件的方法
content.map((o) => { content.map((o) => {
that.md_data.push(o); that.md_data.push(o)
}); })
let titleAllArray = title.map((o) => { let titleAllArray = title.map((o) => {
return o; return o
}); })
that.the_title = resdata.the_title; that.the_title = resdata.the_title
this.pageAnalysFun(titleAllArray); // 分页 this.pageAnalysFun(titleAllArray) // 分页
}) })
.catch((r) => { .catch((r) => {
throw Error(r); throw Error(r)
}); // get log }) // get log
}, }
}; }
</script> </script>
<style scoped> <style scoped>
......
// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。 // 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core' import * as echarts from 'echarts/core'
// 引入柱状图图表,图表后缀都为 Chart // 引入柱状图图表,图表后缀都为 Chart
import { BarChart, LineChart, MapChart, GraphChart, PieChart} from 'echarts/charts' import { BarChart, LineChart, MapChart, GraphChart, PieChart} from 'echarts/charts'
// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component // 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
import { import {
...@@ -8,15 +9,14 @@ import { ...@@ -8,15 +9,14 @@ import {
TooltipComponent, TooltipComponent,
GridComponent, GridComponent,
DatasetComponent, DatasetComponent,
TransformComponent TransformComponent,
ToolboxComponent
} from 'echarts/components' } from 'echarts/components'
// 标签自动布局,全局过渡动画等特性 // 标签自动布局,全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features' import { LabelLayout, UniversalTransition } from 'echarts/features'
// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步 // 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import Vue from 'vue'
// 注册必须的组件 // 注册必须的组件
echarts.use([ echarts.use([
TitleComponent, TitleComponent,
...@@ -31,9 +31,10 @@ echarts.use([ ...@@ -31,9 +31,10 @@ echarts.use([
PieChart, PieChart,
LabelLayout, LabelLayout,
UniversalTransition, UniversalTransition,
CanvasRenderer CanvasRenderer,
ToolboxComponent
]) ])
const importEchartsComponents = () => { const importEchartsComponents = (Vue) => {
Vue.prototype.$echarts = echarts// 绑定echarts Vue.prototype.$echarts = echarts// 绑定echarts
} }
export default importEchartsComponents export default importEchartsComponents
import Vue from 'vue'
import { import {
Container, Container,
Header, Header,
...@@ -20,11 +19,12 @@ import { ...@@ -20,11 +19,12 @@ import {
FormItem, FormItem,
Avatar, Avatar,
Link, Link,
Notification, Loading,
Loading Pagination,
Alert
} from 'element-ui' } from 'element-ui'
const importElementComponents = () => { const importElementComponents = (Vue) => {
Vue.use(Container) Vue.use(Container)
Vue.use(Header) Vue.use(Header)
Vue.use(Main) Vue.use(Main)
...@@ -44,10 +44,11 @@ const importElementComponents = () => { ...@@ -44,10 +44,11 @@ const importElementComponents = () => {
Vue.use(MenuItemGroup) Vue.use(MenuItemGroup)
Vue.use(Avatar) Vue.use(Avatar)
Vue.use(Link) Vue.use(Link)
Vue.use(Notification)
Vue.use(Loading) Vue.use(Loading)
Vue.use(Pagination)
Vue.use(Alert)
Vue.prototype.$message = Message Vue.prototype.$message = Message
Vue.prototype.$notify = Notification // Vue.prototype.$notify = Notification
} }
export default importElementComponents export default importElementComponents
// The Vue build version to load with the `import` command // The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue' import Vue from 'vue'
import './plugins/axios'
import App from './App' import App from './App'
import 'element-ui/lib/theme-chalk/index.css'
import cookies from 'vue-cookies' import cookies from 'vue-cookies'
import 'github-markdown-css/github-markdown.css'
import hljs from 'highlight.js' import hljs from 'highlight.js'
import 'highlight.js/styles/github.css' import {router, useRouter} from './router'
import router from './router'
import importElementComponents from './importElement' import importElementComponents from './importElement'
import importEchartsComponents from './importEchartsComponents' import importEchartsComponents from './importEchartsComponents'
// 路由
useRouter(Vue)
// 按需引入elementui // 按需引入elementui
importElementComponents() importElementComponents(Vue)
//按需引入echarts // 按需引入echarts
importEchartsComponents() importEchartsComponents(Vue)
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(cookies) Vue.use(cookies)
// Vue.use(hljs) // Vue.use(hljs)
Vue.directive('highlight', function(el) { Vue.directive('highlight', function (el) {
const blocks = el.querySelectorAll('pre code') const blocks = el.querySelectorAll('pre code')
blocks.forEach(block => { blocks.forEach(block => {
hljs.highlightBlock(block) hljs.highlightBlock(block)
}) })
}) })
// Vue.prototype.http = axios;
Vue.prototype.$cookies = cookies Vue.prototype.$cookies = cookies
Vue.prototype.$cookies.set("user_session", "null") Vue.prototype.$cookies.set('user_session', 'null')
new Vue({ new Vue({
el: '#app', el: '#app',
......
import Vue from 'vue' // import Nprogress from 'nprogress'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css' import 'nprogress/nprogress.css'
// import { getToken } from '@/utils/auth' // import { getToken } from '@/utils/auth'
import { isEmpty } from '@/utils' import { isEmpty } from '@/utils'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
// import Router from 'vue-router'
import store from '@/store' import store from '@/store'
// store const Article = () => import('@/components/Article')
import Article from '@/components/Article' const Login = () => import('@/components/Login')
import Login from '@/components/Login' const Register = () => import('@/components/Register')
import Register from '@/components/Register' const Onlinewebsocket = () => import('@/components/Onlinewebsocket')
import Onlinewebsocket from '@/components/Onlinewebsocket' const Home = () => import('@/components/Home')
import Home from '@/components/Home' const Bilicom = () => import('@/components/Bilicom')
import Bilicom from '@/components/Bilicom' const Mavoneditor = () => import('@/components/Mavoneditor')
import Mavoneditor from '@/components/Mavoneditor' const GrilShow = () => import('@/components/GrilShow')
const Csslearn = () => import('@/components/Csslearn')
import GrilShow from '@/components/GrilShow'
import Csslearn from '@/components/Csslearn'
Vue.use(VueRouter)
const defaultRoutes = [ const defaultRoutes = [
{ {
path: '/', path: '/',
name: 'Article', name: 'Article',
component: Article component: Article,
hidden: true
}, },
{ {
path: '/login', path: '/login',
name: 'Login', name: 'Login',
component: Login component: Login,
hidden: true
}, },
{ {
path: '/register', path: '/register',
name: 'Register', name: 'Register',
component: Register component: Register,
hidden: true
}, },
{ {
path: '/home', path: '/home',
name: 'Home', name: 'Home',
component: Home component: Home,
hidden: true
}, },
{ {
path: '/onlinewebsocket', path: '/onlinewebsocket',
name: 'Onlinewebsocket', name: 'Onlinewebsocket',
component: Onlinewebsocket component: Onlinewebsocket,
hidden: true
}, },
{ {
path: '/bilicom', path: '/bilicom',
name: 'Bilicom', name: 'Bilicom',
component: Bilicom component: Bilicom,
hidden: true
}, },
{ {
path: '/mavoneditor', path: '/mavoneditor',
name: 'Mavoneditor', name: 'Mavoneditor',
component: Mavoneditor component: Mavoneditor,
hidden: true
}, },
{ {
path: '/gril', path: '/gril',
name: 'grilshow', name: 'grilshow',
component: GrilShow component: GrilShow,
hidden: true
}, },
{ {
path: '/css', path: '/css',
name: 'css', name: 'css',
component: Csslearn component: Csslearn,
hidden: true
} }
] ]
let routes = [ let routes = [
...defaultRoutes ...defaultRoutes
// ...modulesRoutes,
// ...errorRoutes,
// ...dashboardRouters
] ]
const originalPush = VueRouter.prototype.push const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) { VueRouter.prototype.push = function push (location) {
return originalPush.call(this, location).catch((err) => err) return originalPush.call(this, location).catch((err) => err)
} }
// 路由
const router = new VueRouter({ const router = new VueRouter({
routes routes
}) })
...@@ -113,8 +114,12 @@ router.beforeEach(async (to, from, next) => { ...@@ -113,8 +114,12 @@ router.beforeEach(async (to, from, next) => {
} }
}) })
router.afterEach((to, from) => { // router.afterEach((to, from) => {
Nprogress.done() // Nprogress.done()
}) // })
const useRouter = (Vue) => {
Vue.use(VueRouter)
}
export default router export {router, useRouter}
import { getCookie, setCookie, removeCookie } from './util.cookies.js' import { getCookie, setCookie, removeCookie } from './util.cookies.js'
const TOKEN_KEY = 'token' const TOKEN_KEY = 'token'
/** /**
* 获取tonken * 获取tonken
*/ */
export function getToken() { export function getToken () {
return getCookie(TOKEN_KEY) return getCookie(TOKEN_KEY)
} }
export function setToken(token, optins) { export function setToken (token, optins) {
return setCookie(TOKEN_KEY, token, optins) return setCookie(TOKEN_KEY, token, optins)
} }
export function removeToken() { export function removeToken () {
return removeCookie(TOKEN_KEY) return removeCookie(TOKEN_KEY)
} }
export function isEmpty(obj, allowBlank = false) { export function isEmpty (obj, allowBlank = false) {
if (isNull(obj)) return true if (isNull(obj)) return true
if (isArray(obj)) return obj.length === 0 if (isArray(obj)) return obj.length === 0
if (isString(obj)) return !(allowBlank || obj.length > 0) if (isString(obj)) return !(allowBlank || obj.length > 0)
if (isObject(obj)) return isEmptyObject(obj) if (isObject(obj)) return isEmptyObject(obj)
for (var key in obj) for (var key in obj) { if (obj.hasOwnProperty(key)) return false }
if (obj.hasOwnProperty(key)) return false return obj === undefined || (!allowBlank ? obj === '' : false)
return obj === undefined || (!allowBlank ? obj === '' : false) }
} /**
/**
* 判断是否不为空 * 判断是否不为空
* @param {*} obj * @param {*} obj
*/ */
export function isNotEmpty(obj, allowBlank = false) { export function isNotEmpty (obj, allowBlank = false) {
return !isEmpty(obj, allowBlank) return !isEmpty(obj, allowBlank)
} }
export function isEmptyObject(obj) { export function isEmptyObject (obj) {
if (!obj) return true if (!obj) return true
for (const name in obj) { for (const name in obj) {
return false return false
} }
return true return true
} }
export function isNotEmptyObject(obj) { export function isNotEmptyObject (obj) {
return isNotEmptyObject(obj) return isNotEmptyObject(obj)
} }
/** /**
* 是否是对象 * 是否是对象
* @param {*} input * @param {*} input
*/ */
export function isObject(input) { export function isObject (input) {
return Object.prototype.toString.call(input) === '[object Object]' return Object.prototype.toString.call(input) === '[object Object]'
} }
/** /**
* 是否是数组 * 是否是数组
* @param {*} input * @param {*} input
*/ */
export function isArray(input) { export function isArray (input) {
return ( return (
input instanceof Array || input instanceof Array ||
Object.prototype.toString.call(input) === '[object Array]' Object.prototype.toString.call(input) === '[object Array]'
) )
} }
export function isDate(input) { export function isDate (input) {
return ( return (
input instanceof Date || input instanceof Date ||
Object.prototype.toString.call(input) === '[object Date]' Object.prototype.toString.call(input) === '[object Date]'
) )
} }
export function isNumber(input) { export function isNumber (input) {
return ( return (
input instanceof Number || input instanceof Number ||
Object.prototype.toString.call(input) === '[object Number]' Object.prototype.toString.call(input) === '[object Number]'
) )
} }
export function isString(input) { export function isString (input) {
return ( return (
input instanceof String || input instanceof String ||
Object.prototype.toString.call(input) === '[object String]' Object.prototype.toString.call(input) === '[object String]'
) )
} }
export function isBoolean(input) { export function isBoolean (input) {
return typeof input === 'boolean' return typeof input === 'boolean'
} }
export function isFunction(input) { export function isFunction (input) {
return typeof input === 'function' return typeof input === 'function'
} }
export function isNull(input) { export function isNull (input) {
return input === undefined || input === null return input === undefined || input === null
} }
export function isPlainObject(obj) { export function isPlainObject (obj) {
if ( if (
obj && obj &&
Object.prototype.toString.call(obj) === '[object Object]' && Object.prototype.toString.call(obj) === '[object Object]' &&
obj.constructor === Object && obj.constructor === Object &&
!hasOwnProperty.call(obj, 'constructor') !hasOwnProperty.call(obj, 'constructor')
) { ) {
var key var key
for (var k in obj) { for (var k in obj) {
key = k key = k
} }
return key === undefined || hasOwnProperty.call(obj, key) return key === undefined || hasOwnProperty.call(obj, key)
} }
return false return false
} }
/** /**
* 转树形 * 转树形
*/ */
export function toTree(data) { export function toTree (data) {
// 删除 所有 children,以防止多次调用 // 删除 所有 children,以防止多次调用
data.forEach(function(item) { data.forEach(function (item) {
delete item.children delete item.children
}) })
// 将数据存储为 以 id 为 KEY 的 map 索引数据列 // 将数据存储为 以 id 为 KEY 的 map 索引数据列
var map = {} var map = {}
data.forEach(function(item) { data.forEach(function (item) {
map[item.id] = item map[item.id] = item
}) })
var val = [] var val = []
data.forEach(function(item) { data.forEach(function (item) {
// 以当前遍历项,的pid,去map对象中找到索引的id // 以当前遍历项,的pid,去map对象中找到索引的id
var parent = map[item.parentId] var parent = map[item.parentId]
// 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中 // 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
if (parent) {; if (parent) {
(parent.children || (parent.children = [])).push(item) ;
} else { (parent.children || (parent.children = [])).push(item)
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级 } else {
val.push(item) // 如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
} val.push(item)
}) }
return val })
} return val
/** }
/**
* 通用排序 * 通用排序
*/ */
export function sortExp(key, isAsc) { export function sortExp (key, isAsc) {
return function(x, y) { return function (x, y) {
if (isNaN(key)) { if (isNaN(key)) {
if (x[key] > y[key]) { if (x[key] > y[key]) {
return 1 * (isAsc ? 1 : -1); return 1 * (isAsc ? 1 : -1)
} else if (x[key] < y[key]) {
} else if (x[key] < y[key]) { return -1 * (isAsc ? 1 : -1)
return -1 * (isAsc ? 1 : -1); } else {
} else { return 0
return 0; }
} } else {
return (x[key] - y[key]) * (isAsc ? 1 : -1)
} else { }
return (x[key] - y[key]) * (isAsc ? 1 : -1) }
} }
}
}
\ No newline at end of file
import JsCookie from 'js-cookie' import JsCookie from 'js-cookie'
/** /**
* *
* @param {String} name 名称 * @param {String} name 名称
* @param {*} value 值 * @param {*} value 值
* @param {Object} cookieSetting 配置 * @param {Object} cookieSetting 配置
*/ */
export function setCookie(name = 'default', value, cookieSetting) { export function setCookie (name = 'default', value, cookieSetting) {
const currentCookieSetting = { const currentCookieSetting = {
expires: 1 expires: 1
} }
...@@ -14,24 +14,23 @@ export function setCookie(name = 'default', value, cookieSetting) { ...@@ -14,24 +14,23 @@ export function setCookie(name = 'default', value, cookieSetting) {
JsCookie.set(`VBI-${name}`, value, currentCookieSetting) JsCookie.set(`VBI-${name}`, value, currentCookieSetting)
} }
/** /**
* *
* @param {String} name * @param {String} name
*/ */
export function getCookie (name = 'default') {
export function getCookie(name = 'default') {
return JsCookie.get(`VBI-${name}`) return JsCookie.get(`VBI-${name}`)
} }
/** /**
* 获取全部cookie * 获取全部cookie
*/ */
export function getCookieAll() { export function getCookieAll () {
return JsCookie.get() return JsCookie.get()
} }
/** /**
* *
* @param {String} name 名称 * @param {String} name 名称
*/ */
export function removeCookie(name) { export function removeCookie (name) {
return JsCookie.remove(`VBI-${name}`) return JsCookie.remove(`VBI-${name}`)
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册