@yqg/permission 1.0.10 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yqg/permission",
3
- "version": "1.0.10",
3
+ "version": "1.0.11-alpha.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "type": "module",
package/src/App.vue CHANGED
@@ -21,7 +21,7 @@ const permissions = reactive([
21
21
  // const permissions = reactive(['CRANE.BUSINESS.QUERY', 'RANE.BUSINESS.CREATE', 'CRANE.BUSINESS.UPDATE', 'CRANE.BUSINESS.DELETE']);
22
22
  const changeColor = () => {
23
23
  color.value = color.value === '#f00' ? '#1677ff' : '#f00';
24
- }
24
+ }
25
25
  const changeLocale = () => {
26
26
  locale.value = locale.value === 'zh-CN' ? 'en-US' : 'zh-CN';
27
27
  }
@@ -38,44 +38,40 @@ const changeLocale = () => {
38
38
  <!-- 03541 -->
39
39
  <!-- 02124 -->
40
40
  <!-- 05184 -->
41
- <yqg-permission
41
+ <yqg-permission
42
42
  :permissions="permissions"
43
43
  workNumber="05184"
44
- businessCode="CRANE"
45
44
  :color="color"
46
45
  :locale="locale"
47
46
  @onSuccess="() => {console.log('成功')}"
48
47
  >
49
48
  </yqg-permission>
50
49
  </div>
51
- <!-- <data class="case-card">
50
+ <data class="case-card">
52
51
  <div>2:文字组件</div>
53
- <yqg-permission
54
- :permissions="permissions"
55
- businessCode="CRANE"
52
+ <yqg-permission
53
+ :permissions="[]"
56
54
  :color="color"
57
55
  workNumber="02124"
58
- type="text"
56
+ type="icon"
59
57
  >
60
58
  </yqg-permission>
61
59
  </data>
62
- -->
63
60
 
64
-
61
+
65
62
  <!-- <div class="case-card">
66
63
  <div>3:自定义</div>
67
- <yqg-permission
64
+ <yqg-permission
68
65
  :permissions="permissions"
69
- businessCode="CRANE"
70
66
  :color="color"
71
67
  workNumber="02124"
72
- locale="zh-CN"
68
+ locale="zh-CN"
73
69
  type="custom"
74
70
  >
75
71
  <div style="color: red;" slot="custom">自定义按钮</div>
76
72
  </yqg-permission>
77
73
  </div> -->
78
-
74
+
79
75
  </div>
80
76
 
81
77
  </template>
Binary file
@@ -18,7 +18,11 @@
18
18
  :label="t('applyPermission')"
19
19
  name="roleIds"
20
20
  :rules="[{ required: true, message: t('selectPlaceholder')}]">
21
+ <span v-if="!permissionList.length">
22
+ {{t('noPermissionTips')}}
23
+ </span>
21
24
  <CheckboxGroup
25
+ v-else
22
26
  v-model:value="formState.roleIds"
23
27
  style="display: block;"
24
28
  @change="onChangeHandler"
@@ -48,14 +52,6 @@
48
52
  :placeholder="t('applyReasonPlaceholder')"
49
53
  :auto-size="{ minRows: 2, maxRows: 5 }">
50
54
  </Textarea>
51
- <div style="margin-top: 4px;">
52
- <Tag
53
- :bordered="false"
54
- style="cursor: pointer;"
55
- v-for="item in reasons"
56
- @click="addReasonHandler(item)"
57
- :key="item">{{ item }}</Tag>
58
- </div>
59
55
  </FormItem>
60
56
 
61
57
  <FormItem :label="t('approvalProcess')">
@@ -82,7 +78,6 @@
82
78
  FormItem,
83
79
  CheckboxGroup,
84
80
  Textarea,
85
- Tag,
86
81
  message
87
82
  } from 'ant-design-vue';
88
83
  import SuccessModal from './success-modal.vue';
@@ -92,12 +87,6 @@
92
87
  import('./checkbox-item.vue')
93
88
  );
94
89
 
95
- const reasons = [
96
- t('applyReason1'),
97
- t('applyReason2'),
98
- t('applyReason3'),
99
- ]
100
-
101
90
  const props = defineProps({
102
91
  permissionList: {
103
92
  type: Array as () => PermissionType[],
@@ -132,18 +121,6 @@
132
121
  applyReason: '',
133
122
  submitWorkNumber: submitWorkNumber.value,
134
123
  });
135
-
136
- const addReasonHandler = (item: string) => {
137
- if (formState.applyReason.includes(item)) {
138
- return;
139
- }
140
- if (!formState.applyReason || formState.applyReason.endsWith('、')) {
141
- formState.applyReason += item;
142
- } else {
143
- formState.applyReason += `、${item}`;
144
- }
145
- formRef.value.validateFields(['applyReason']);
146
- }
147
124
 
148
125
  const handleOk = async() => {
149
126
  if (formState.roleIds.length > 5) {
@@ -1,18 +1,18 @@
1
1
  <template>
2
2
  <div class="crane-checkbox-line">
3
- <Checkbox
3
+ <Checkbox
4
4
  :value="item.roleId"
5
5
  :disabled="['OWNER', 'PENDING', 'NO'].includes(props.item.businessApplyType)"
6
6
  @change="onCheck">
7
7
  <div class="crane-flex-center crane-checkbox-label">
8
8
  <Tag
9
- v-if="item.securityLevel"
10
- :bordered="false"
11
- :color="levelMap[item.securityLevel].color"
9
+ v-if="item.securityLevel"
10
+ :bordered="false"
11
+ :style="{color: levelMap[item.securityLevel].color, background: levelMap[item.securityLevel].background}"
12
12
  class="crane-tag-position">
13
13
  {{ levelMap[item.securityLevel].text }}
14
14
  </Tag>
15
-
15
+
16
16
  <span>{{t(`operationType.${item.operationType}`)}}|
17
17
  </span>
18
18
  <Popover>
@@ -22,8 +22,8 @@
22
22
  <span class="crane-text-overflow">{{ item.name }}</span>
23
23
  </Popover>
24
24
  <Tag
25
- v-if="item.businessApplyType && item.businessApplyType !== 'TEMP_OWNER'"
26
- :bordered="false"
25
+ v-if="item.businessApplyType && item.businessApplyType !== 'TEMP_OWNER'"
26
+ :bordered="false"
27
27
  class="crane-tag-position crane-margin-left-4 crane-margin-right-0"
28
28
  :class="['PENDING', 'TEMP_OWNER'].includes(item.businessApplyType) ? '' : 'crane-disabled-color'">
29
29
  {{ statusMap[item.businessApplyType] }}
@@ -34,14 +34,14 @@
34
34
  <span v-else>{{ t('taday') }}</span>
35
35
  </template>
36
36
  <Tag
37
- v-if="item.businessApplyType === 'TEMP_OWNER'"
38
- :bordered="false"
37
+ v-if="item.businessApplyType === 'TEMP_OWNER'"
38
+ :bordered="false"
39
39
  class="crane-tag-position crane-margin-left-4 crane-margin-right-0"
40
40
  :class="['PENDING'].includes(item.businessApplyType) ? '' : 'crane-disabled-color'">
41
41
  {{ statusMap[item.businessApplyType] }}
42
42
  </Tag>
43
43
  </Popover>
44
-
44
+
45
45
  </div>
46
46
  </Checkbox>
47
47
 
@@ -88,16 +88,19 @@
88
88
 
89
89
  const levelMap:LevelMapType = {
90
90
  L1: {
91
- color: 'green',
92
- text: t('levels.L1')
91
+ color: '#1AA83B',
92
+ text: t('levels.L1'),
93
+ background: '#E3F9E9',
93
94
  },
94
95
  L2: {
95
- color: 'orange',
96
- text: t('levels.L2')
97
- },
96
+ color: '#F37D1C',
97
+ text: t('levels.L2'),
98
+ background: '#FFE4BA'
99
+ },
98
100
  L3: {
99
- color: 'red',
100
- text: t('levels.L3')
101
+ color: '#F2494B',
102
+ text: t('levels.L3'),
103
+ background: '#FDCDC5'
101
104
  },
102
105
  };
103
106
 
@@ -155,7 +158,7 @@
155
158
  }
156
159
  .crane-checkbox-line {
157
160
  margin-bottom: 12px;
158
- display: flex;
161
+ display: flex;
159
162
  align-items: center;
160
163
  }
161
164
  .crane-checkbox-line:last-child {
@@ -166,8 +169,8 @@
166
169
  }
167
170
  .crane-tag-position {
168
171
  margin-right: 4px;
169
- font-size: 10px;
170
- padding: 2px 4px;
172
+ font-size: 10px;
173
+ padding: 2px 4px;
171
174
  line-height: 12px;
172
175
  font-weight: 500;
173
176
  }
@@ -194,5 +197,5 @@
194
197
  overflow: hidden;
195
198
  text-overflow: ellipsis
196
199
  }
197
-
200
+
198
201
  </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <contextHolder></contextHolder>
2
+ <contextHolder></contextHolder>
3
3
  </template>
4
4
  <script lang="ts" setup>
5
5
  import { createVNode } from 'vue';
@@ -1,6 +1,5 @@
1
1
  <template>
2
2
  <ConfigProvider
3
- v-if="allPermissions.length"
4
3
  prefixCls="yqg-permission"
5
4
  :theme="{
6
5
  token: {
@@ -9,10 +8,22 @@
9
8
  }"
10
9
  >
11
10
  <div class="crane-wraper">
12
- <template v-if="type==='text'">
13
- <TypographyLink @click="showModal">{{t('permissionApply')}}</TypographyLink>
11
+ <template v-if="type === comType.ICON">
12
+ <FloatButton
13
+ ref="dragElement"
14
+ type="primary"
15
+ :tooltip="t('clickToApply')"
16
+ :style="{
17
+ right,
18
+ top: currentTop,
19
+ }"
20
+ >
21
+ <template #icon>
22
+ <img :src="applyIconUrl" />
23
+ </template>
24
+ </FloatButton>
14
25
  </template>
15
- <template v-else-if="type==='custom'">
26
+ <template v-else-if="type===comType.CUSTOM">
16
27
  <div @click="showModal">
17
28
  <slot name="custom"/>
18
29
  </div>
@@ -84,12 +95,14 @@
84
95
  </ConfigProvider>
85
96
  </template>
86
97
  <script lang="ts" setup>
87
- import { ref, defineAsyncComponent, computed, watchEffect, watch} from 'vue';
88
- import { Button, ConfigProvider, TypographyLink, Popover , message} from 'ant-design-vue';
98
+ import { ref, defineAsyncComponent, computed, watchEffect, watch } from 'vue';
99
+ import { Button, ConfigProvider, Popover , message, FloatButton} from 'ant-design-vue';
89
100
  import applyUrl from '@/assets/applying.png';
101
+ import applyIconUrl from '@/assets/apply.png';
90
102
  import noauthority from '@/assets/noauthority.png';
91
103
  import Http from '../axios/index';
92
104
  import t from '../utils';
105
+ import useDraggable from '../hooks/useDragable';
93
106
 
94
107
  const STATUS_MAP = {
95
108
  DEFAULT: 'DEFAULT',
@@ -97,6 +110,12 @@
97
110
  NO: 'NO',
98
111
  } as const;
99
112
 
113
+ const comType = {
114
+ ICON: 'icon',
115
+ DEFAULT: 'default',
116
+ CUSTOM: 'custom',
117
+ };
118
+
100
119
  // 重置 message 类名,避免被全局样式覆盖
101
120
  message.config({prefixCls: 'yqg-permission-message'});
102
121
 
@@ -113,10 +132,6 @@
113
132
  type: [String, Array<String>],
114
133
  default: []
115
134
  },
116
- businessCode: {
117
- type: String,
118
- default: ''
119
- },
120
135
  locale: {
121
136
  type: String,
122
137
  default: 'zh-CN'
@@ -129,16 +144,28 @@
129
144
  type: String,
130
145
  default: 'default'
131
146
  },
147
+ right: {
148
+ type: String,
149
+ default: '100px'
150
+ },
151
+ top: {
152
+ type: String,
153
+ default: '100px'
154
+ }
132
155
  });
156
+
133
157
 
134
158
  const open = ref(false);
135
159
  const curApproving = ref<PermissionType>();
136
160
  let permissionList = ref<PermissionListType>([]);
161
+
162
+
163
+
137
164
  let curStatus = ref<Record<string, any>>({
138
165
  imageUrl: noauthority,
139
166
  status: '',
140
167
  })
141
-
168
+
142
169
  const allPermissions = computed(() => {
143
170
  if (Array.isArray(props.permissions)) {
144
171
  return props.permissions;
@@ -147,10 +174,19 @@
147
174
  return props.permissions.split(',');
148
175
  });
149
176
 
177
+ const businessCode = computed(() => {
178
+ const code = allPermissions.value[0] || '';
179
+ if (!code) return '';
180
+
181
+ return code.split('.')[0];
182
+ })
183
+
150
184
  const formatPermissionsData = (data: PermissionListType) => {
151
185
  const arr:PermissionListType = [];
152
186
  const flattenData = (list: PermissionListType) => {
153
187
  list.forEach((item) => {
188
+ // 去掉名字中第一个.前面的字符串,会有多个.
189
+ item.name = item.name.replace(/^[^.]+\./, '');
154
190
  if (item.children) {
155
191
  flattenData(item.children);
156
192
  } else {
@@ -218,13 +254,12 @@
218
254
  };
219
255
 
220
256
  const getPermissions = async () => {
221
- const { businessCode, workNumber } = props;
257
+ const { workNumber } = props;
222
258
  const permissions = allPermissions.value;
223
259
 
224
- if (!permissions?.length || !businessCode || !workNumber) return;
260
+ if (!permissions?.length || !workNumber) return;
225
261
 
226
262
  const params = {
227
- businessCode,
228
263
  workNumber,
229
264
  features: permissions.toString(),
230
265
  };
@@ -240,6 +275,8 @@
240
275
  open.value = !open.value;
241
276
  };
242
277
 
278
+ const { currentTop, dragElement } = useDraggable(props, showModal);
279
+
243
280
  watchEffect(getPermissions);
244
281
 
245
282
  watch(() => props.locale, (cur, pre) => {
@@ -264,3 +301,4 @@
264
301
  }
265
302
  </style>
266
303
 
304
+ ../hooks/useDragable
@@ -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