Commit fb94170a authored by 周远喜's avatar 周远喜

Merge branch 'iview2' of http://git.mes123.com/zhouyx/admin into iview2

parents fd2a45c6 1ee1ed61
......@@ -14,6 +14,7 @@ import menuSider from '@/menu/sider';
import { frameInRoutes } from '@/router/routes';
export default {
middleware: 'auth',
components: { MainLayout },
created() {
// 处理路由 得到每一级的路由设置
......
<template>
<div class="container">
<h1 v-if="error.statusCode === 404">Page not found</h1>
<h1 v-else>An error occurred</h1>
<nuxt-link to="/">Home page</nuxt-link>
</div>
</template>
<script>
export default {
props: ['error'],
// layout: 'blog' // you can set a custom layout for the error page
// watch:{
// error(v){
// debugger;
// if(v.statusCode==404){
// this.$router.push("/error/404");
// }
// }
// }
}
</script>
\ No newline at end of file
import util from '@/libs/util';
export default function ({ route, req, res, redirect, store }) {
var token = util.cookies.get('token');
if (!token) {
redirect("/account/login");
}
}
\ No newline at end of file
export default function ({ isHMR, app, store, route, params, error, redirect }) {
const defaultLocale = app.i18n.fallbackLocale
// If middleware is called from hot module replacement, ignore it
if (isHMR) { return }
// Get locale from params
const locale = params.lang || defaultLocale
if (!store.state.locales.includes(locale)) {
return error({ message: 'This page could not be found.', statusCode: 404 })
}
// Set locale
store.commit('SET_LANG', locale)
app.i18n.locale = store.state.locale
// If route is /<defaultLocale>/... -> redirect to /...
if (locale === defaultLocale && route.fullPath.indexOf('/' + defaultLocale) === 0) {
const toReplace = '^/' + defaultLocale + (route.fullPath.indexOf('/' + defaultLocale + '/') === 0 ? '/' : '')
const re = new RegExp(toReplace)
return redirect(
route.fullPath.replace(re, '/')
)
}
}
......@@ -26,6 +26,7 @@
<h1>总数:{{counter}}</h1>
<h2>admin,user{{this.$store.state.admin.user.counter}}</h2>
<Button @click="increment">+</Button>
<Button type="error" v-auth="['admin2']" @click="log">log</Button>
</div>
</div>
</div>
......@@ -47,6 +48,13 @@ export default {
},methods: {
increment () {
this.$store.commit('increment')
},
log(){
this.$log.push("这是一个错误!")
this.$log.capsule('iView', 'Success', this);
if (process.env.NODE_ENV === 'development'){
alert(123)
}
}
}
}
......
......@@ -2,7 +2,11 @@ import Vue from 'vue'
import ViewUI from 'view-design'
import VueI18n from 'vue-i18n';
import Languages from '@/i18n/locale';
// import VueDND from 'awe-dnd'
// 插件
import util from '@/libs/util';
import { includeArray } from '@/libs/system';
import VueDND from 'awe-dnd' //拖拽排序
// import iViewPro from '@/libs/iViewPro/iview-pro.min.js';
// import '@/libs/iViewPro/iview-pro.css';
import iViewPro from '../iview-pro/src/index.js';
......@@ -14,28 +18,83 @@ Vue.component("iLink", iLink)
//注入mock
require("../mock")
export default ({
app,
store
}) => {
Vue.use(VueI18n)
// Vue.use(VueDND)
app.i18n = new VueI18n({
locale: 'zh-CN',
messages: Languages
});
app.i18n.locale = "zh-CN"
Vue.use(ViewUI, {
// locale:'zh-CN',
i18n: (key, value) => app.i18n.t(key, value)
app,
store
}) => {
Vue.use(VueI18n)
Vue.use(VueDND)
app.i18n = new VueI18n({
locale: 'zh-CN',
messages: Languages
});
app.i18n.locale = "zh-CN"
Vue.use(ViewUI, {
// locale:'zh-CN',
i18n: (key, value) => app.i18n.t(key, value)
})
Vue.use(iViewPro);
Vue.prototype.$log = {
...util.log,
push(data) {
if (typeof data === 'string') {
// 如果传递来的数据是字符串
// 赋值给 message 字段
// 为了方便使用
// eg: this.$log.push('foo text')
store.dispatch('admin/log/push', {
message: data
});
} else if (typeof data === 'object') {
// 如果传递来的数据是对象
store.dispatch('admin/log/push', data);
}
}
}
Vue.config.errorHandler = function (error, instance, info) {
Vue.nextTick(() => {
// store 追加 log
store.dispatch('admin/log/push', {
message: `${info}: ${error.message}`,
type: 'error',
meta: {
error
// instance
}
});
// 只在开发模式下打印 log
if (process.env.NODE_ENV === 'development') {
util.log.capsule('iView Admin', 'ErrorHandler', 'error');
util.log.error('>>>>>> 错误信息 >>>>>>');
console.log(info);
util.log.error('>>>>>> Vue 实例 >>>>>>');
console.log(instance);
util.log.error('>>>>>> Error >>>>>>');
console.log(error)
}
})
Vue.use(iViewPro);
}
Vue.directive('auth',{
inserted (el, binding, vnode) {
const { value } = binding;
const access = store.state.admin.user.info.access;
// Vue.directive('paste', {
// bind(el, binding, vnode) {
// el.addEventListener('paste', function (event) { //这里直接监听元素的粘贴事件
// binding.value(event)
// })
// }
// })
// console.warn("this:",app.i18n.locale,app)
}
\ No newline at end of file
if (value && value instanceof Array && value.length && access && access.length) {
const isPermission = includeArray(value, access);
if (!isPermission) {
el.parentNode && el.parentNode.removeChild(el);
}
}
}
} )
// Vue.directive('paste', {
// bind(el, binding, vnode) {
// el.addEventListener('paste', function (event) { //这里直接监听元素的粘贴事件
// binding.value(event)
// })
// }
// })
// console.warn("this:",app.i18n.locale,app)
}
\ No newline at end of file
Markdown is supported
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