提交 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,10 +214,10 @@ ...@@ -214,10 +214,10 @@
<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的组件
...@@ -225,35 +225,35 @@ export default { ...@@ -225,35 +225,35 @@ export default {
EchartWeather, // 天气 EchartWeather, // 天气
Email Email
}, },
name: "Article", name: 'Article',
data() { data () {
return { return {
msgDrawTitle:'~邮件沟通~', msgDrawTitle: '~邮件沟通~',
direction:'rtl', direction: 'rtl',
drawObj: { drawObj: {
show:false show: false
}, },
// baseurl: '/api/', // baseurl: '/api/',
baseurl: "/api/", baseurl: '/api/',
// baseurl: "http://yongma16.xyz/", // baseurl: "http://yongma16.xyz/",
msg: "内容", msg: '内容',
commmentSlogan: "评论区", commmentSlogan: '评论区',
day_challenge: "训练营", day_challenge: '训练营',
challenge_data: [ challenge_data: [
"css挑战", 'css挑战',
"websocket聊天", 'websocket聊天',
"echarts地图配置", 'echarts地图配置',
"vue3测试平台", 'vue3测试平台',
"更新中", '更新中'
], ],
md_data: [], md_data: [],
md_title: [], md_title: [],
the_title: "", the_title: '',
sear_page: 0, sear_page: 0,
index_page: 0, index_page: 0,
data: ["threejs加载模型"], data: ['threejs加载模型'],
slogan: "记忆碎片", slogan: '记忆碎片',
tabPosition: "left", tabPosition: 'left',
weather_title: [], weather_title: [],
weather_high: [], weather_high: [],
weather_low: [], weather_low: [],
...@@ -261,9 +261,9 @@ export default { ...@@ -261,9 +261,9 @@ export default {
article_loc: 0, article_loc: 0,
challenge_loc: -1, challenge_loc: -1,
topshow: false, topshow: false,
userImg: "", userImg: '',
username: "匿名", username: '匿名',
articleCommit: "评论区", articleCommit: '评论区',
// 分页实现 page1 page2 指向数组 // 分页实现 page1 page2 指向数组
pageAnalys: {}, pageAnalys: {},
currentPage: 1, currentPage: 1,
...@@ -273,100 +273,100 @@ export default { ...@@ -273,100 +273,100 @@ export default {
pageArray: [6, 8, 10], pageArray: [6, 8, 10],
postcomment: { postcomment: {
articleId: undefined, articleId: undefined,
articleCommit: null, articleCommit: null
}, },
articleId: [], // 文章的id articleId: [] // 文章的id
}; }
}, },
watch: { watch: {
topshow: function (newvalue, oldvalue) { topshow: function (newvalue, oldvalue) {
if (newvalue === true) { if (newvalue === true) {
document.getElementById("topiconid").style.display = "none"; document.getElementById('topiconid').style.display = 'none'
} else { } else {
document.getElementById("topiconid").style.display = "block"; document.getElementById('topiconid').style.display = 'block'
}
} }
}, },
beforeDestroy () {
window.removeEventListener('onload', this.topvisible())
}, },
beforeDestroy() { mounted () {
window.removeEventListener("onload", this.topvisible()); this.initPageSpliteFun()
}, window.addEventListener('onload', this.topvisible())
mounted() {
this.initPageSpliteFun();
window.addEventListener("onload", this.topvisible());
}, },
methods: { methods: {
initPageSpliteFun() { initPageSpliteFun () {
this.splitLength = this.pageArray[0]; this.splitLength = this.pageArray[0]
}, },
handleSizeChange(val) { handleSizeChange (val) {
// 转到第一页md_title // 转到第一页md_title
let that = this; let that = this
that.pageAnalysFun(that.pageAnalys.allTitle, val); // 触发修改 that.pageAnalysFun(that.pageAnalys.allTitle, val) // 触发修改
}, },
handleCurrentChange(val) { handleCurrentChange (val) {
let that = this; let that = this
// 触发md_title的修改 // 触发md_title的修改
that.currentPage = val; that.currentPage = val
that.pageAnalysFun(that.pageAnalys.allTitle); // 触发修改 that.pageAnalysFun(that.pageAnalys.allTitle) // 触发修改
}, },
pageAnalysFun(allTitleArray, selectListLength) { pageAnalysFun (allTitleArray, selectListLength) {
let that = this; let that = this
that.total = allTitleArray.length; // 总数 that.total = allTitleArray.length // 总数
let splitLength = that.splitLength; let splitLength = that.splitLength
if (!selectListLength) { if (!selectListLength) {
that.splitLength = that.splitLength; that.splitLength = that.splitLength
} else { } else {
this.currentPage = 1; this.currentPage = 1
that.splitLength = selectListLength; // 划分长度 that.splitLength = selectListLength // 划分长度
} }
splitLength = that.splitLength; splitLength = that.splitLength
let splitNum = Math.ceil(that.total / splitLength); // 向上取整 let splitNum = Math.ceil(that.total / splitLength) // 向上取整
that.pageAnalys.childNum = splitNum; // 子数组个数 that.pageAnalys.childNum = splitNum // 子数组个数
that.pageAnalys.allTitle = allTitleArray; // 所有标题 that.pageAnalys.allTitle = allTitleArray // 所有标题
that.pageAnalys.titleArray = new Array(); // 子数组个数 that.pageAnalys.titleArray = new Array() // 子数组个数
let locSplit = 0; let locSplit = 0
let locLength = splitLength; // 每一页的条数 let locLength = splitLength // 每一页的条数
while (splitNum--) { while (splitNum--) {
// 循环获取子数组 // 循环获取子数组
if (splitNum >= 1) { if (splitNum >= 1) {
let childArray = []; let childArray = []
for ( for (
let temp = locSplit; let temp = locSplit;
temp < locLength && temp < that.total; temp < locLength && temp < that.total;
++temp, ++locSplit ++temp, ++locSplit
) { ) {
childArray.push(that.pageAnalys.allTitle[temp]); childArray.push(that.pageAnalys.allTitle[temp])
} }
that.pageAnalys.titleArray.push(childArray); that.pageAnalys.titleArray.push(childArray)
locLength += splitLength; // 分割数组长度后移 locLength += splitLength // 分割数组长度后移
} else { } else {
// 最后一个数组 // 最后一个数组
let childArray = []; let childArray = []
for (let temp = locSplit; temp < that.total; ++temp) { for (let temp = locSplit; temp < that.total; ++temp) {
childArray.push(that.pageAnalys.allTitle[temp]); childArray.push(that.pageAnalys.allTitle[temp])
} }
that.pageAnalys.titleArray.push(childArray); that.pageAnalys.titleArray.push(childArray)
break; break
} }
} }
try { try {
that.md_title = that.pageAnalys.titleArray[this.currentPage - 1]; that.md_title = that.pageAnalys.titleArray[this.currentPage - 1]
} catch (e) { } catch (e) {
throw Error(e); throw Error(e)
} }
}, },
increment: function () { increment: function () {
this.$store.commit("increment"); this.$store.commit('increment')
}, },
topvisible: function () { topvisible: function () {
let dom = document.getElementById("hometitle"); let dom = document.getElementById('hometitle')
this.topshow = this.elementIsVisibleInViewport(dom); this.topshow = this.elementIsVisibleInViewport(dom)
setTimeout(this.topvisible); setTimeout(this.topvisible)
}, },
elementIsVisibleInViewport: function (el, partiallyVisible = false) { elementIsVisibleInViewport: function (el, partiallyVisible = false) {
try { try {
if (el && el.getBoundingClientRect instanceof Function) { if (el && el.getBoundingClientRect instanceof Function) {
const { top, left, bottom, right } = el.getBoundingClientRect(); const { top, left, bottom, right } = el.getBoundingClientRect()
return partiallyVisible return partiallyVisible
? ((top > 0 && top < innerHeight) || ? ((top > 0 && top < innerHeight) ||
(bottom > 0 && bottom < innerHeight)) && (bottom > 0 && bottom < innerHeight)) &&
...@@ -375,129 +375,129 @@ export default { ...@@ -375,129 +375,129 @@ export default {
: 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]' &&
...@@ -82,52 +81,51 @@ ...@@ -82,52 +81,51 @@
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) (parent.children || (parent.children = [])).push(item)
} else { } else {
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级 // 如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
val.push(item) 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 { } else {
return (x[key] - y[key]) * (isAsc ? 1 : -1) return (x[key] - y[key]) * (isAsc ? 1 : -1)
} }
} }
} }
\ No newline at end of file
...@@ -6,7 +6,7 @@ import JsCookie from 'js-cookie' ...@@ -6,7 +6,7 @@ import JsCookie from 'js-cookie'
* @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
} }
...@@ -18,20 +18,19 @@ export function setCookie(name = 'default', value, cookieSetting) { ...@@ -18,20 +18,19 @@ export function setCookie(name = 'default', value, cookieSetting) {
* @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}`)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册