mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-12 21:53:48 +08:00
v1.0.4
This commit is contained in:
11
smart-admin-web/src/directives/directives.js
Normal file
11
smart-admin-web/src/directives/directives.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import draggable from './module/draggable';
|
||||
import clipboard from './module/clipboard';
|
||||
import privilege from './module/privilege';
|
||||
|
||||
const directives = {
|
||||
draggable,
|
||||
clipboard,
|
||||
privilege
|
||||
};
|
||||
|
||||
export default directives;
|
||||
31
smart-admin-web/src/directives/index.js
Normal file
31
smart-admin-web/src/directives/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import directive from './directives';
|
||||
|
||||
const importDirective = Vue => {
|
||||
/**
|
||||
* 拖拽指令 v-draggable="options"
|
||||
* options = {
|
||||
* trigger: /这里传入作为拖拽触发器的CSS选择器/,
|
||||
* body: /这里传入需要移动容器的CSS选择器/,
|
||||
* recover: /拖动结束之后是否恢复到原来的位置/
|
||||
* }
|
||||
*/
|
||||
Vue.directive('draggable', directive.draggable);
|
||||
/**
|
||||
* clipboard指令 v-draggable="options"
|
||||
* options = {
|
||||
* value: /在输入框中使用v-model绑定的值/,
|
||||
* success: /复制成功后的回调/,
|
||||
* error: /复制失败后的回调/
|
||||
* }
|
||||
*/
|
||||
Vue.directive('clipboard', directive.clipboard);
|
||||
/**
|
||||
* privilege指令 v-privilege="options"
|
||||
* options = {
|
||||
* value: /当前按钮的唯一权限识别/,
|
||||
* }
|
||||
*/
|
||||
Vue.directive('privilege', directive.privilege);
|
||||
};
|
||||
|
||||
export default importDirective;
|
||||
30
smart-admin-web/src/directives/module/clipboard.js
Normal file
30
smart-admin-web/src/directives/module/clipboard.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import Clipboard from 'clipboard';
|
||||
export default {
|
||||
bind: (el, binding) => {
|
||||
const clipboard = new Clipboard(el, {
|
||||
text: () => binding.value.value
|
||||
});
|
||||
el.__success_callback__ = binding.value.success;
|
||||
el.__error_callback__ = binding.value.error;
|
||||
clipboard.on('success', e => {
|
||||
const callback = el.__success_callback__;
|
||||
callback && callback(e);
|
||||
});
|
||||
clipboard.on('error', e => {
|
||||
const callback = el.__error_callback__;
|
||||
callback && callback(e);
|
||||
});
|
||||
el.__clipboard__ = clipboard;
|
||||
},
|
||||
update: (el, binding) => {
|
||||
el.__clipboard__.text = () => binding.value.value;
|
||||
el.__success_callback__ = binding.value.success;
|
||||
el.__error_callback__ = binding.value.error;
|
||||
},
|
||||
unbind: (el, binding) => {
|
||||
delete el.__success_callback__;
|
||||
delete el.__error_callback__;
|
||||
el.__clipboard__.destroy();
|
||||
delete el.__clipboard__;
|
||||
}
|
||||
};
|
||||
42
smart-admin-web/src/directives/module/draggable.js
Normal file
42
smart-admin-web/src/directives/module/draggable.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { on } from '@/lib/util';
|
||||
export default {
|
||||
inserted: (el, binding, vnode) => {
|
||||
let triggerDom = document.querySelector(binding.value.trigger);
|
||||
triggerDom.style.cursor = 'move';
|
||||
let bodyDom = document.querySelector(binding.value.body);
|
||||
let pageX = 0;
|
||||
let pageY = 0;
|
||||
let transformX = 0;
|
||||
let transformY = 0;
|
||||
let canMove = false;
|
||||
const handleMousedown = e => {
|
||||
let transform = /\(.*\)/.exec(bodyDom.style.transform);
|
||||
if (transform) {
|
||||
transform = transform[0].slice(1, transform[0].length - 1);
|
||||
let splitxy = transform.split('px, ');
|
||||
transformX = parseFloat(splitxy[0]);
|
||||
transformY = parseFloat(splitxy[1].split('px')[0]);
|
||||
}
|
||||
pageX = e.pageX;
|
||||
pageY = e.pageY;
|
||||
canMove = true;
|
||||
};
|
||||
const handleMousemove = e => {
|
||||
let xOffset = e.pageX - pageX + transformX;
|
||||
let yOffset = e.pageY - pageY + transformY;
|
||||
if (canMove)
|
||||
{bodyDom.style.transform = `translate(${xOffset}px, ${yOffset}px)`;}
|
||||
};
|
||||
const handleMouseup = e => {
|
||||
canMove = false;
|
||||
};
|
||||
on(triggerDom, 'mousedown', handleMousedown);
|
||||
on(document, 'mousemove', handleMousemove);
|
||||
on(document, 'mouseup', handleMouseup);
|
||||
},
|
||||
update: (el, binding, vnode) => {
|
||||
if (!binding.value.recover) return;
|
||||
let bodyDom = document.querySelector(binding.value.body);
|
||||
bodyDom.style.transform = '';
|
||||
}
|
||||
};
|
||||
23
smart-admin-web/src/directives/module/privilege.js
Normal file
23
smart-admin-web/src/directives/module/privilege.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// 页面内按钮过滤
|
||||
import store from '@/store/index';
|
||||
export default {
|
||||
inserted: function (el, binding, vnode) {
|
||||
// 获取当前路由name
|
||||
// 如果页面为同一模块下的子页面则取最上级权限
|
||||
let routeName = vnode.context.$route.meta.group
|
||||
? vnode.context.$route.meta.group
|
||||
: vnode.context.$route.name;
|
||||
// 超级管理员
|
||||
if (store.state.user.userLoginInfo.isSuperMan) {
|
||||
return true;
|
||||
}
|
||||
// 获取功能点权限
|
||||
let functionList = store.state.user.privilegeFunctionPointsMap.get(routeName);
|
||||
// 有权限
|
||||
if (functionList && functionList.includes(binding.value)) {
|
||||
|
||||
} else {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user