@yqg/permission 1.0.9 → 1.0.11-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ // useDraggable.js
2
+
3
+ import { ref, onBeforeUnmount, watch, onMounted } from 'vue';
4
+
5
+ export default function useDraggable(props: { top: any }, showModal: () => void) {
6
+ const currentTop = ref(0);
7
+ const isDragging = ref(false); // 是否正在拖拽
8
+ const startX = ref(0); // 鼠标按下时的X坐标
9
+ const initialX = ref(0); // 元素初始X坐标
10
+ const initialY = ref(0);
11
+ const dragElement = ref<any>(null);
12
+
13
+ watch(() => props.top, (newVal) => {
14
+ currentTop.value = newVal;
15
+ }, { immediate: true });
16
+
17
+ // 获取元素的初始位置
18
+ const getPosition = (el: HTMLElement) => {
19
+ const rect = el.getBoundingClientRect();
20
+ return {
21
+ x: rect.left,
22
+ y: rect.top
23
+ };
24
+ };
25
+
26
+ // 限制拖拽元素在屏幕内
27
+ const constrainToScreen = (clientX: number, clientY: number, el: HTMLElement) => {
28
+ const { innerWidth, innerHeight } = window;
29
+ const elRect = el.getBoundingClientRect();
30
+
31
+ const constrainedX = Math.min(Math.max(clientX, 0), innerWidth - elRect.width);
32
+ const constrainedY = Math.min(Math.max(clientY, 0), innerHeight - elRect.height);
33
+
34
+ return { x: constrainedX, y: constrainedY };
35
+ };
36
+
37
+ // 鼠标移动时的处理函数
38
+ const onMouseMove = (e: MouseEvent, el: HTMLElement) => {
39
+ if (!isDragging.value) return;
40
+
41
+ const { clientX, clientY } = e;
42
+ const { x, y } = constrainToScreen(clientX - startX.value + initialX.value, clientY - currentTop.value + initialY.value, el);
43
+
44
+ el.style.left = `${x}px`;
45
+ el.style.top = `${y}px`;
46
+
47
+ };
48
+
49
+ // 鼠标松开时的处理函数
50
+ const onMouseUp = (e: MouseEvent, el: HTMLElement) => {
51
+ if (!isDragging.value) return;
52
+
53
+ // 阻止点击事件触发
54
+ e.preventDefault(); // 阻止默认行为
55
+ e.stopPropagation(); // 阻止事件冒泡
56
+
57
+ // // 获取元素当前的位置
58
+ const { x: currentX, y: currentY } = getPosition(el);
59
+ if ( Math.abs(currentY - initialY.value) < 10 && Math.abs(currentX - initialX.value) < 10) {
60
+ showModal();
61
+ // 卸载拖拽
62
+ isDragging.value = false;
63
+
64
+ return;
65
+ }
66
+
67
+
68
+ isDragging.value = false;
69
+ const { clientY } = e;
70
+
71
+ // 在鼠标松开时设置x为初始位置,y为鼠标当前位置
72
+ const { x, y } = constrainToScreen(initialX.value, clientY - currentTop.value + initialY.value, el);
73
+ el.style.transition = 'all 0.3s';
74
+ el.style.left = `${x}px`;
75
+ el.style.top = `${y}px`;
76
+
77
+ // 清除事件监听
78
+ document.removeEventListener('mousemove', (e) => onMouseMove(e, el));
79
+ document.removeEventListener('mouseup', (e) => onMouseUp(e, el));
80
+ };
81
+
82
+ // 鼠标按下时的处理函数
83
+ const onMouseDown = (e: MouseEvent, el: HTMLElement) => {
84
+ isDragging.value = true;
85
+
86
+ // 阻止点击事件触发
87
+ e.preventDefault(); // 阻止默认行为
88
+ e.stopPropagation();
89
+
90
+ // 获取鼠标按下时的位置
91
+ startX.value = e.clientX;
92
+ currentTop.value = e.clientY;
93
+
94
+
95
+ // 获取元素的初始位置
96
+ const { x, y } = getPosition(el);
97
+ initialX.value = x;
98
+ initialY.value = y;
99
+ el.style.transition = 'none';
100
+
101
+ // 添加鼠标移动和鼠标松开事件监听
102
+ document.addEventListener('mousemove', (e) => onMouseMove(e, el));
103
+ document.addEventListener('mouseup', (e) => onMouseUp(e, el));
104
+ };
105
+
106
+ // 返回拖拽的绑定方法
107
+ const bindDraggable = () => {
108
+ onMounted(() => {
109
+ const el = dragElement.value?.$el;
110
+ if (el) {
111
+ el.addEventListener('mousedown', (e: MouseEvent) => onMouseDown(e, el));
112
+ }
113
+ });
114
+
115
+ onBeforeUnmount(() => {
116
+ const el = dragElement.value?.$el;
117
+ if (el) {
118
+ el.removeEventListener('mousedown', (e: MouseEvent) => onMouseDown(e, el));
119
+ }
120
+ });
121
+ };
122
+
123
+ bindDraggable();
124
+
125
+ return {
126
+ currentTop,
127
+ dragElement,
128
+ };
129
+ }
package/src/i18n/en-US.ts CHANGED
@@ -3,35 +3,34 @@ export default {
3
3
  applyPermission: '申请权限',
4
4
  applyReason: '申请理由',
5
5
  approvalProcess: '审批流程',
6
- applyReason1: '新入职员工申请',
7
- applyReason2: '项目需要',
8
- applyReason3: '数据查询与分析',
9
6
  applyReasonPlaceholder: '请尽可能详细描述申请理由',
10
7
  cancel: '取消',
11
8
  submit: '确定',
12
9
  close: '关闭',
13
10
  viewApprovalDetail: '查看审批详情',
14
- applyMore: '继续申请其他权限',
11
+ applyMore: '继续申请其他权限',
15
12
  successTips: '已提交申请,审批通过后可拥有相关权限',
16
13
  resoultTitle: '操作结果反馈',
17
14
  start: '发起',
18
15
  end: '结束',
19
- noNeed: '无需审批',
16
+ noNeed: '无需审批',
20
17
  adaptDepartment: '适用部门',
21
- noApprovalProcess: '无审批流程',
18
+ noApprovalProcess: '无审批流程',
22
19
  excessTips: '一次最多可申请{number}个权限',
23
20
  unavailableTips: '您暂无权限查看/操作该页面,请点击下方按钮进行申请',
24
21
  appliedTips: '权限已申请,正在{status}...',
25
22
  unapplyTips: '您暂无权限查看/操作该页面,且该页面中没有您可以申请的权限,',
26
- callManager: '如有需要请联系系统管理员',
27
- manager: '系统管理员',
23
+ callManager: '如有需要请联系系统管理员',
24
+ manager: '系统管理员',
28
25
  availableTime: '有效期',
29
- selectPlaceholder: '请选择权限点',
30
- reasonPlaceholder: '请输入申请理由',
31
- maxCountTips: '一次最多只可申请{count}个权限',
32
- maxLengthTips: '最多{length}个字符',
33
- lastDays: '{count}天后到期',
34
- taday: '今天到期',
26
+ selectPlaceholder: '请选择权限点',
27
+ reasonPlaceholder: '请输入申请理由',
28
+ maxCountTips: '一次最多只可申请{count}个权限',
29
+ maxLengthTips: '最多{length}个字符',
30
+ lastDays: '{count}天后到期',
31
+ taday: '今天到期',
32
+ clickToApply: '点击申请菜单',
33
+ noPermissionTips: '该菜单下暂无权限点',
35
34
  availiables: {
36
35
  SEVEN_DAYS: '7天',
37
36
  THIRTY_DAYS: '30天',
@@ -48,10 +47,10 @@ export default {
48
47
  PENDING: '审批中',
49
48
  NO: '不可申请',
50
49
  OWNER: '永久拥有',
51
- TEMP_OWNER: '临时拥有',
50
+ TEMP_OWNER: '临时拥有',
52
51
  },
53
- operationType: {
54
- QUERY: '查询',
55
- MANAGE: '操作',
56
- }
52
+ operationType: {
53
+ QUERY: '查询',
54
+ MANAGE: '操作',
55
+ }
57
56
  };
package/src/i18n/zh-CH.ts CHANGED
@@ -3,9 +3,6 @@ export default {
3
3
  applyPermission: '申请权限',
4
4
  applyReason: '申请理由',
5
5
  approvalProcess: '审批流程',
6
- applyReason1: '新入职员工申请',
7
- applyReason2: '项目需要',
8
- applyReason3: '数据查询与分析',
9
6
  applyReasonPlaceholder: '请尽可能详细描述申请理由',
10
7
  cancel: '取消',
11
8
  submit: '确定',
@@ -32,6 +29,8 @@ export default {
32
29
  maxLengthTips: '最多{length}个字符',
33
30
  lastDays: '{count}天后到期',
34
31
  taday: '今天到期',
32
+ clickToApply: '点击申请菜单',
33
+ noPermissionTips: '该菜单下暂无权限点',
35
34
  availiables: {
36
35
  SEVEN_DAYS: '7天',
37
36
  THIRTY_DAYS: '30天',
@@ -35,6 +35,7 @@ declare type LevelMapType = {
35
35
  [key in LevelType]: {
36
36
  color: string;
37
37
  text: string;
38
+ background: string;
38
39
  };
39
40
  };
40
41