@jetlinks-web/components 2.0.2 → 2.0.4-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.
Files changed (245) hide show
  1. package/es/AMap/Map.js +125 -0
  2. package/es/AMap/index.js +2 -0
  3. package/es/AMap/util.js +56 -0
  4. package/es/BadgeStatus/Badge.js +54 -0
  5. package/es/BadgeStatus/color.js +21 -0
  6. package/es/BadgeStatus/index.js +3 -0
  7. package/es/CardSelect/CardSelect.js +123 -0
  8. package/es/CardSelect/index.js +2 -0
  9. package/es/CheckButton/CheckButton.js +120 -0
  10. package/es/CheckButton/index.js +2 -0
  11. package/es/CheckButton/style/index.css +37 -0
  12. package/es/CheckButton/style/index.less +40 -0
  13. package/es/ConfigProvider/context.js +12 -0
  14. package/es/ConfigProvider/index.js +31 -0
  15. package/es/Echarts/Echarts.js +47 -0
  16. package/es/Echarts/index.js +2 -0
  17. package/es/Ellipsis/Ellipsis.js +184 -0
  18. package/es/Ellipsis/index.js +2 -0
  19. package/es/Ellipsis/style/index.css +17 -0
  20. package/es/Ellipsis/style/index.less +20 -0
  21. package/es/Empty/Empty.js +56 -0
  22. package/es/Empty/image.js +2 -0
  23. package/es/Empty/index.js +2 -0
  24. package/es/FullPage/FullPage.js +31 -0
  25. package/es/FullPage/index.js +2 -0
  26. package/es/Icon/icon.js +42 -0
  27. package/{src/Icon/index.ts → es/Icon/index.js} +2 -3
  28. package/es/MonacoEditor/Monaco.js +238 -0
  29. package/es/MonacoEditor/index.js +2 -0
  30. package/es/PermissionButton/index.js +117 -0
  31. package/es/ProLayout/Basic/BasicLayout.js +259 -0
  32. package/es/ProLayout/Basic/Header.js +97 -0
  33. package/es/ProLayout/PageContainer/index.js +324 -0
  34. package/es/ProLayout/PageContainer/typings.js +1 -0
  35. package/es/ProLayout/RouteContext.js +22 -0
  36. package/es/ProLayout/SiderMenu/BaseMenu.js +285 -0
  37. package/es/ProLayout/SiderMenu/SiderMenu.js +278 -0
  38. package/es/ProLayout/SiderMenu/index.js +2 -0
  39. package/es/ProLayout/SiderMenu/typings.js +1 -0
  40. package/es/ProLayout/TopHeader/index.js +163 -0
  41. package/es/ProLayout/defaultSettings.js +66 -0
  42. package/{src/ProLayout/index.ts → es/ProLayout/index.js} +4 -6
  43. package/{src → es}/ProLayout/style/default.less +1 -1
  44. package/es/ProLayout/style/index.js +1 -0
  45. package/es/ProLayout/typings.js +1 -0
  46. package/es/ProLayout/util.js +61 -0
  47. package/es/ProTable/index.js +411 -0
  48. package/es/ProTable/proTableTypes.js +11 -0
  49. package/es/ProTable/style/index.css +65 -0
  50. package/es/ProTable/style/index.js +1 -0
  51. package/{src → es}/ProTable/style/index.less +92 -92
  52. package/es/Scrollbar/Bar.js +114 -0
  53. package/es/Scrollbar/Scrollbar.js +212 -0
  54. package/es/Scrollbar/Thumb.js +189 -0
  55. package/es/Scrollbar/constants.js +1 -0
  56. package/es/Scrollbar/index.js +2 -0
  57. package/es/Scrollbar/scrollbarProps.js +100 -0
  58. package/es/Scrollbar/thumbProps.js +10 -0
  59. package/es/Scrollbar/util.js +30 -0
  60. package/es/Search/Advanced/History.js +183 -0
  61. package/es/Search/Advanced/SaveHistory.js +153 -0
  62. package/es/Search/Advanced/index.js +520 -0
  63. package/es/Search/Item.js +497 -0
  64. package/es/Search/Search.js +249 -0
  65. package/es/Search/hooks/index.js +1 -0
  66. package/es/Search/hooks/useSearchItems.js +40 -0
  67. package/es/Search/index.js +4 -0
  68. package/es/Search/setting.js +91 -0
  69. package/es/Search/style/Item.less +33 -0
  70. package/es/Search/style/Search.less +179 -0
  71. package/es/Search/style/index.js +2 -0
  72. package/es/Search/typing.js +1 -0
  73. package/es/Search/util.js +234 -0
  74. package/es/ValueItem/ValueItem.js +233 -0
  75. package/es/ValueItem/index.js +2 -0
  76. package/es/ValueItem/util.js +16 -0
  77. package/es/index.js +24 -0
  78. package/es/style/index.js +3 -0
  79. package/es/style/variable.css +0 -0
  80. package/{src → es}/style/variable.less +2 -4
  81. package/es/style.js +5 -0
  82. package/lib/AMap/Map.js +125 -0
  83. package/lib/AMap/index.js +9 -0
  84. package/lib/AMap/util.js +62 -0
  85. package/lib/BadgeStatus/Badge.js +54 -0
  86. package/lib/BadgeStatus/color.js +27 -0
  87. package/lib/BadgeStatus/index.js +22 -0
  88. package/lib/CardSelect/CardSelect.js +123 -0
  89. package/lib/CardSelect/index.js +9 -0
  90. package/lib/CheckButton/CheckButton.js +120 -0
  91. package/lib/CheckButton/index.js +9 -0
  92. package/lib/CheckButton/style/index.css +37 -0
  93. package/lib/CheckButton/style/index.less +40 -0
  94. package/lib/ConfigProvider/context.js +19 -0
  95. package/lib/ConfigProvider/index.js +37 -0
  96. package/lib/Echarts/Echarts.js +47 -0
  97. package/lib/Echarts/index.js +9 -0
  98. package/lib/Ellipsis/Ellipsis.js +184 -0
  99. package/lib/Ellipsis/index.js +9 -0
  100. package/lib/Ellipsis/style/index.css +17 -0
  101. package/lib/Ellipsis/style/index.less +20 -0
  102. package/lib/Empty/Empty.js +56 -0
  103. package/lib/Empty/image.js +8 -0
  104. package/lib/Empty/index.js +9 -0
  105. package/lib/FullPage/FullPage.js +31 -0
  106. package/lib/FullPage/index.js +9 -0
  107. package/lib/Icon/icon.js +52 -0
  108. package/lib/Icon/index.js +9 -0
  109. package/lib/MonacoEditor/Monaco.js +238 -0
  110. package/lib/MonacoEditor/index.js +9 -0
  111. package/lib/PermissionButton/index.js +124 -0
  112. package/lib/ProLayout/Basic/BasicLayout.js +268 -0
  113. package/lib/ProLayout/Basic/BasicLayout.less +66 -0
  114. package/lib/ProLayout/Basic/Header.js +103 -0
  115. package/lib/ProLayout/Basic/Header.less +8 -0
  116. package/lib/ProLayout/PageContainer/index.js +327 -0
  117. package/lib/ProLayout/PageContainer/index.less +103 -0
  118. package/lib/ProLayout/PageContainer/typings.js +5 -0
  119. package/lib/ProLayout/RouteContext.js +28 -0
  120. package/lib/ProLayout/SiderMenu/BaseMenu.js +290 -0
  121. package/lib/ProLayout/SiderMenu/SiderMenu.js +287 -0
  122. package/lib/ProLayout/SiderMenu/index.js +20 -0
  123. package/lib/ProLayout/SiderMenu/index.less +212 -0
  124. package/lib/ProLayout/SiderMenu/typings.js +5 -0
  125. package/lib/ProLayout/TopHeader/index.js +168 -0
  126. package/lib/ProLayout/TopHeader/index.less +174 -0
  127. package/lib/ProLayout/defaultSettings.js +72 -0
  128. package/lib/ProLayout/index.js +16 -0
  129. package/lib/ProLayout/style/default.less +4 -0
  130. package/lib/ProLayout/style/index.js +3 -0
  131. package/lib/ProLayout/style/style.less +7 -0
  132. package/lib/ProLayout/typings.js +5 -0
  133. package/lib/ProLayout/util.js +72 -0
  134. package/lib/ProTable/index.js +417 -0
  135. package/lib/ProTable/proTableTypes.js +17 -0
  136. package/lib/ProTable/style/index.css +65 -0
  137. package/lib/ProTable/style/index.js +3 -0
  138. package/lib/ProTable/style/index.less +92 -0
  139. package/lib/Scrollbar/Bar.js +114 -0
  140. package/lib/Scrollbar/Scrollbar.js +212 -0
  141. package/lib/Scrollbar/Thumb.js +189 -0
  142. package/lib/Scrollbar/constants.js +7 -0
  143. package/lib/Scrollbar/index.js +9 -0
  144. package/{src/Scrollbar/scrollbar.ts → lib/Scrollbar/scrollbarProps.js} +106 -108
  145. package/lib/Scrollbar/thumbProps.js +16 -0
  146. package/lib/Scrollbar/util.js +37 -0
  147. package/lib/Search/Advanced/History.js +183 -0
  148. package/lib/Search/Advanced/SaveHistory.js +153 -0
  149. package/lib/Search/Advanced/index.js +520 -0
  150. package/lib/Search/Item.js +497 -0
  151. package/lib/Search/Search.js +249 -0
  152. package/lib/Search/hooks/index.js +16 -0
  153. package/lib/Search/hooks/useSearchItems.js +47 -0
  154. package/lib/Search/index.js +16 -0
  155. package/lib/Search/setting.js +97 -0
  156. package/lib/Search/style/Item.less +33 -0
  157. package/lib/Search/style/Search.less +179 -0
  158. package/lib/Search/style/index.js +4 -0
  159. package/lib/Search/typing.js +5 -0
  160. package/lib/Search/util.js +241 -0
  161. package/lib/ValueItem/ValueItem.js +233 -0
  162. package/lib/ValueItem/index.js +9 -0
  163. package/lib/ValueItem/util.js +22 -0
  164. package/lib/index.js +158 -0
  165. package/lib/style/components.less +3 -0
  166. package/lib/style/index.js +4 -0
  167. package/lib/style/variable.css +0 -0
  168. package/lib/style/variable.less +2 -0
  169. package/lib/style.js +7 -0
  170. package/package.json +123 -13
  171. package/index.ts +0 -64
  172. package/src/AMap/Map.vue +0 -110
  173. package/src/AMap/index.ts +0 -1
  174. package/src/AMap/util.ts +0 -56
  175. package/src/BadgeStatus/Badge.vue +0 -41
  176. package/src/BadgeStatus/color.ts +0 -25
  177. package/src/BadgeStatus/index.ts +0 -4
  178. package/src/CardSelect/CardSelect.vue +0 -136
  179. package/src/CardSelect/index.ts +0 -3
  180. package/src/CheckButton/CheckButton.vue +0 -146
  181. package/src/CheckButton/index.md +0 -27
  182. package/src/CheckButton/index.ts +0 -3
  183. package/src/ConfigProvider/context.ts +0 -17
  184. package/src/ConfigProvider/index.tsx +0 -42
  185. package/src/Echarts/Echarts.vue +0 -43
  186. package/src/Echarts/index.ts +0 -3
  187. package/src/Ellipsis/Ellipsis.vue +0 -182
  188. package/src/Ellipsis/index.ts +0 -3
  189. package/src/Empty/Empty.vue +0 -43
  190. package/src/Empty/image.ts +0 -3
  191. package/src/Empty/index.ts +0 -2
  192. package/src/FullPage/FullPage.vue +0 -30
  193. package/src/FullPage/index.ts +0 -3
  194. package/src/Icon/icon.tsx +0 -40
  195. package/src/MonacoEditor/Monaco.vue +0 -242
  196. package/src/MonacoEditor/index.md +0 -26
  197. package/src/MonacoEditor/index.ts +0 -2
  198. package/src/PermissionButton/index.tsx +0 -110
  199. package/src/ProLayout/Basic/BasicLayout.tsx +0 -392
  200. package/src/ProLayout/Basic/Header.tsx +0 -115
  201. package/src/ProLayout/PageContainer/index.tsx +0 -441
  202. package/src/ProLayout/PageContainer/typings.ts +0 -56
  203. package/src/ProLayout/RouteContext.ts +0 -87
  204. package/src/ProLayout/SiderMenu/BaseMenu.tsx +0 -296
  205. package/src/ProLayout/SiderMenu/SiderMenu.tsx +0 -320
  206. package/src/ProLayout/SiderMenu/index.ts +0 -2
  207. package/src/ProLayout/SiderMenu/typings.ts +0 -49
  208. package/src/ProLayout/TopHeader/index.tsx +0 -210
  209. package/src/ProLayout/defaultSettings.ts +0 -106
  210. package/src/ProLayout/style/index.ts +0 -1
  211. package/src/ProLayout/typings.ts +0 -87
  212. package/src/ProLayout/util.ts +0 -64
  213. package/src/ProTable/index.md +0 -53
  214. package/src/ProTable/index.tsx +0 -551
  215. package/src/ProTable/proTableTypes.ts +0 -70
  216. package/src/ProTable/style/index.ts +0 -1
  217. package/src/Scrollbar/Bar.vue +0 -75
  218. package/src/Scrollbar/Scrollbar.vue +0 -260
  219. package/src/Scrollbar/Thumb.vue +0 -163
  220. package/src/Scrollbar/constants.ts +0 -10
  221. package/src/Scrollbar/index.ts +0 -4
  222. package/src/Scrollbar/thumb.ts +0 -16
  223. package/src/Scrollbar/util.ts +0 -38
  224. package/src/Search/Advanced/History.vue +0 -140
  225. package/src/Search/Advanced/SaveHistory.vue +0 -108
  226. package/src/Search/Advanced/index.vue +0 -435
  227. package/src/Search/Item.vue +0 -525
  228. package/src/Search/Search.vue +0 -398
  229. package/src/Search/hooks/index.ts +0 -1
  230. package/src/Search/hooks/useSearchItems.ts +0 -68
  231. package/src/Search/index.md +0 -57
  232. package/src/Search/index.ts +0 -5
  233. package/src/Search/setting.ts +0 -55
  234. package/src/Search/typing.ts +0 -76
  235. package/src/Search/util.ts +0 -263
  236. package/src/ValueItem/ValueItem.vue +0 -192
  237. package/src/ValueItem/index.ts +0 -3
  238. package/src/ValueItem/util.ts +0 -16
  239. package/src/style/index.ts +0 -3
  240. /package/{src → es}/ProLayout/Basic/BasicLayout.less +0 -0
  241. /package/{src → es}/ProLayout/Basic/Header.less +0 -0
  242. /package/{src → es}/ProLayout/PageContainer/index.less +0 -0
  243. /package/{src → es}/ProLayout/SiderMenu/index.less +0 -0
  244. /package/{src → es}/ProLayout/TopHeader/index.less +0 -0
  245. /package/{src → es}/ProLayout/style/style.less +0 -0
@@ -1,242 +0,0 @@
1
- <!-- 代码编辑器 -->
2
- <template>
3
- <div ref="dom" class="j-monaco-editor"></div>
4
- </template>
5
-
6
- <script setup>
7
- import {
8
- ref,
9
- onMounted,
10
- watch,
11
- onUnmounted,
12
- toRaw,
13
- nextTick
14
- } from 'vue';
15
- import * as monaco from 'monaco-editor';
16
- import { omit } from 'lodash-es';
17
-
18
- const props = defineProps({
19
- modelValue: [String, Number],
20
- theme: {type: String, default: 'vs-dark'},
21
- language: {type: String, default: 'json'},
22
- codeTips: {type: Array, default: () => []},
23
- init: {type: Function, default: undefined},
24
- registrationTips: {type: Object, default: () => ({})},
25
- registrationTypescript: {type: Object, default: () => ({})},
26
- blurFormat: {type: Boolean, default: true},
27
- readOnly: {type: Boolean, default: false},
28
- options: {type: Object, default: () => ({})},
29
- });
30
-
31
- const emit = defineEmits([
32
- 'update:modelValue',
33
- 'blur',
34
- 'focus',
35
- 'change',
36
- 'errorChange',
37
- ]);
38
-
39
- const dom = ref();
40
-
41
- const instance = ref();
42
-
43
- const monacoProviderRef = ref();
44
- const monacoTypescriptProviderRef = ref();
45
-
46
- // codeTipItem.dispose() // 销毁自定义提示
47
-
48
- const handleSuggestions = (suggestions, range) => {
49
- return Array.isArray(suggestions)
50
- ? suggestions.map((item) => ({...item, range}))
51
- : [];
52
- };
53
-
54
- const disposeRegister = () => {
55
- monacoProviderRef.value?.dispose();
56
- monacoProviderRef.value = null;
57
- };
58
- /**
59
- * 代码提示注册
60
- */
61
- const registerCompletionItemProvider = () => {
62
- disposeRegister();
63
- if (monaco.languages && props.registrationTips?.suggestions) {
64
- const {name, suggestions} = props.registrationTips;
65
- monacoProviderRef.value =
66
- monaco.languages.registerCompletionItemProvider(name || 'json', {
67
- provideCompletionItems: function (model, position) {
68
- const word = model.getWordUntilPosition(position); // 获取提示代码范围位置
69
- const range = {
70
- startLineNumber: position.lineNumber,
71
- endLineNumber: position.lineNumber,
72
- startColumn: word.startColumn,
73
- endColumn: word.endColumn,
74
- };
75
-
76
- return {
77
- suggestions: handleSuggestions(suggestions, range),
78
- };
79
- },
80
- });
81
- }
82
- };
83
-
84
- const disposeTypescript = () => {
85
- monacoTypescriptProviderRef.value?.dispose();
86
- monacoTypescriptProviderRef.value = null;
87
- };
88
-
89
- const registerTypescript = () => {
90
- disposeTypescript();
91
- if (monaco.languages && props.registrationTypescript?.typescript) {
92
- const {name, typescript} = props.registrationTypescript;
93
- monacoTypescriptProviderRef.value =
94
- monaco.languages.typescript.javascriptDefaults.addExtraLib(
95
- typescript,
96
- );
97
- }
98
- };
99
-
100
- /**
101
- * 代码格式化
102
- */
103
- const editorFormat = () => {
104
- if (!instance.value) return;
105
- toRaw(instance.value).getAction('editor.action.formatDocument')?.run();
106
- if (props.hasOwnProperty('readOnly')) {
107
- setTimeout(() => {
108
- toRaw(instance.value).updateOptions({
109
- readOnly: props.readOnly !== false,
110
- });
111
- }, 100);
112
- }
113
- };
114
-
115
- monaco.editor.onDidChangeMarkers(([uri]) => {
116
- const markers = monaco.editor.getModelMarkers({resource: uri});
117
- emit('errorChange', markers);
118
- });
119
-
120
- onMounted(async () => {
121
- const _model = monaco.editor.createModel(props.modelValue, props.language);
122
-
123
- instance.value = monaco.editor.create(dom.value, {
124
- model: _model,
125
- tabSize: 2,
126
- automaticLayout: true,
127
- scrollBeyondLastLine: false,
128
- theme: props.theme, // 主题色: vs(默认高亮), vs-dark(黑色), hc-black(高亮黑色)
129
- formatOnPaste: true,
130
- ...(omit(props.options, ['readOnly']) || {}),
131
- });
132
-
133
- instance.value.onDidChangeModelContent(() => {
134
- //
135
- const value = toRaw(instance.value).getValue();
136
- nextTick(() => {
137
- emit('update:modelValue', value);
138
- emit('change', value);
139
- });
140
- });
141
-
142
- instance.value.onDidBlurEditorText(() => {
143
- emit('blur');
144
- if (props.blurFormat) {
145
- editorFormat();
146
- }
147
- });
148
-
149
- instance.value.onDidFocusEditorText(() => {
150
- emit('focus');
151
- });
152
-
153
- if (props.modelValue) {
154
- setTimeout(() => {
155
- editorFormat();
156
- }, 200);
157
- }
158
-
159
- props.init?.(instance.value, monaco);
160
- });
161
-
162
- /**
163
- * 光标位置插入内容
164
- * @param {String} val
165
- * @param position
166
- */
167
- const insert = (val, position) => {
168
- if (!instance.value) return;
169
- const _position = position || toRaw(instance.value).getPosition();
170
- const value = toRaw(instance.value).getValue();
171
-
172
- if (position && position.lineNumber) {
173
- toRaw(instance.value).setPosition(position);
174
- }
175
-
176
- toRaw(instance.value).executeEdits(value, [
177
- {
178
- range: new monaco.Range(
179
- _position?.lineNumber,
180
- _position?.column,
181
- _position?.lineNumber,
182
- _position?.column,
183
- ),
184
- text: val,
185
- },
186
- ]);
187
- };
188
-
189
- watch(
190
- () => props.modelValue,
191
- (val) => {
192
- if (
193
- !instance.value ||
194
- (instance.value &&
195
- props.modelValue === toRaw(instance.value).getValue())
196
- )
197
- return;
198
- // setValue之前获取光标位置
199
- const position = toRaw(instance.value).getPosition();
200
-
201
- // setValue之后光标位置改变
202
- toRaw(instance.value).setValue(val);
203
- // 设置光标位置为setValue之前的位置
204
- toRaw(instance.value).setPosition(position);
205
-
206
- editorFormat();
207
- },
208
- );
209
-
210
- watch(
211
- () => JSON.stringify(props.registrationTips),
212
- () => {
213
- registerCompletionItemProvider();
214
- },
215
- {immediate: true},
216
- );
217
-
218
- watch(
219
- () => JSON.stringify(props.registrationTypescript),
220
- () => {
221
- registerTypescript();
222
- },
223
- {immediate: true},
224
- );
225
-
226
- onUnmounted(() => {
227
- disposeRegister();
228
- disposeTypescript();
229
- toRaw(instance.value).editor?.dispose?.();
230
- });
231
-
232
- defineExpose({
233
- editorFormat,
234
- insert,
235
- });
236
- </script>
237
- <style lang="less" scoped>
238
- .j-monaco-editor {
239
- min-height: 50px;
240
- height: 100%;
241
- }
242
- </style>
@@ -1,26 +0,0 @@
1
- ---
2
- category: Components
3
- type: 数据录入
4
- title: MonacoEditor
5
- subtitle: 代码编辑器
6
- cols: 1
7
- cover: https://gw.alipayobjects.com/zos/alicdn/xS9YEJhfe/Input.svg
8
- ---
9
-
10
- ## API
11
-
12
- > 在 vite 项目中使用需要安装[`vite-plugin-monaco-editor`](https://github.com/vdesjs/vite-plugin-monaco-editor), 并在 vite.config.ts 中配置
13
-
14
- ### MonacoEditor
15
-
16
- | 参数 | 说明 | 类型 | 默认值 | 版本 |
17
- | --- |-----------------------------------------------------------| --- | --- | --- |
18
- | value(v-model) | 编辑器内容 | string | | |
19
- | theme | 主题色: vs(默认高亮), vs-dark(黑色), hc-black(高亮黑色) | string | | |
20
- | language | 编辑器支持的语言: json, css, html, typescript, javascript, vue | string | | |
21
- | 参数 | 说明 | 类型 | 默认值 | 版本 |
22
- | -------------- | --------------------------------------------------------- | ------ | ------ | ---- |
23
- | value(v-model) | 编辑器内容 | string | | |
24
- | theme | 主题色: vs(默认高亮), vs-dark(黑色), hc-black(高亮黑色) | string | | |
25
- | language | 编辑器支持的语言: json, css, html, typescript, javascript, vue | string | | |
26
-
@@ -1,2 +0,0 @@
1
- import Monaco from './Monaco.vue';
2
- export default Monaco;
@@ -1,110 +0,0 @@
1
- import { h, defineComponent, computed } from "vue";
2
- import type { PropType, CSSProperties, ExtractPropTypes } from 'vue'
3
- import { Button, Tooltip, Popconfirm } from 'ant-design-vue'
4
- import { PopconfirmProps, TooltipProps } from "ant-design-vue/es";
5
- import { omit } from "lodash-es";
6
- import { buttonProps } from "ant-design-vue/es/button/button";
7
- import { usePermission } from '@jetlinks-web/hooks'
8
-
9
- type PermissionType = string | Array<string> | boolean
10
-
11
- const definedProps = {
12
- tooltip: {
13
- type: Object as PropType<TooltipProps>,
14
- },
15
- popConfirm: {
16
- type: Object as PropType<PopconfirmProps>,
17
- },
18
- hasPermission: {
19
- type: [String, Array, Boolean] as PropType<PermissionType>,
20
- default: undefined
21
- },
22
- style: {
23
- type: Object as PropType<CSSProperties>
24
- },
25
- noPermissionTitle: {
26
- type: String
27
- },
28
- ...omit(buttonProps(), 'icon')
29
- }
30
-
31
- type DefinedPropsType = Partial<ExtractPropTypes<typeof definedProps>>
32
-
33
- const PermissionButton = defineComponent({
34
- name: 'PermissionButton',
35
- // @ts-ignore
36
- slots: ['button', 'icon'],
37
- props: definedProps,
38
- setup(props, {slots}) {
39
-
40
- const {popConfirm, tooltip} = props
41
- const {hasPerm} = usePermission(props.hasPermission as PermissionType)
42
-
43
- const permission = computed(() => {
44
- if (!props.hasPermission || props.hasPermission === true) {
45
- return true
46
- }
47
- return hasPerm.value
48
- })
49
-
50
- const isPermission = computed(() => {
51
- if ('hasPermission' in props && permission.value) {
52
- return 'disabled' in props ? props.disabled : false
53
- }
54
- return true
55
- })
56
-
57
- const hasPopConfirm = computed(() => !!popConfirm) // 是否包含确认弹窗
58
- const hasTooltip = computed(() => !!tooltip) // 是否包含文字提示
59
-
60
- return () => {
61
- const {popConfirm, tooltip, hasPermission, noPermissionTitle, ...buttonProps} = props
62
-
63
- const button = !slots.button ?
64
- h(Button,
65
- {
66
- ...buttonProps,
67
- disabled: isPermission.value,
68
- },
69
- {
70
- default: () => slots?.default?.(),
71
- icon: () => slots?.icon?.()
72
- }) :
73
- slots.button()
74
-
75
- // 文字提示
76
- const _tooltip = tooltip ? h(Tooltip, Object.assign(tooltip, {disabled: isPermission.value}), {default: () => button}) : undefined
77
-
78
- // 无权限
79
- const noPermissionButton = !permission.value ? h(Tooltip, {title: noPermissionTitle || '暂无权限,请联系管理员'}, {default: () => button}) : undefined
80
-
81
- // 二次确认
82
- const _popConfirm = popConfirm ?
83
- h(Popconfirm,
84
- Object.assign(
85
- {overlayStyle: {width: '220px'}},
86
- popConfirm,
87
- {
88
- disabled: !permission.value || buttonProps.disabled
89
- }
90
- ),
91
- {default: () => tooltip ? _tooltip : button})
92
- : undefined
93
-
94
- if (permission.value) {
95
- if (hasPopConfirm.value) {
96
- return _popConfirm
97
- }
98
-
99
- if (hasTooltip.value) {
100
- return _tooltip
101
- }
102
-
103
- return button
104
- }
105
- return noPermissionButton
106
- }
107
- }
108
- })
109
-
110
- export default PermissionButton