@yqg/permission 1.2.0 → 1.3.0-alpha.0

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 (45) hide show
  1. package/README.md +50 -38
  2. package/dist/apply-modal-CpmDDWWV.js +12865 -0
  3. package/dist/category-selector-BQ0-kg3o.js +1275 -0
  4. package/dist/index-D_0ZQip-.js +2972 -0
  5. package/dist/index-wLkVeDMW.js +5040 -0
  6. package/dist/index.js +2 -2
  7. package/dist/permission-item-Df_aagL1.js +1266 -0
  8. package/dist/{yqg-permission-Bxzu3bMl.js → yqg-permission-BjVCs5lN.js} +3483 -3538
  9. package/dist/yqg-permission.umd.js +250 -0
  10. package/package.json +13 -3
  11. package/plugins/alioss.ts +237 -0
  12. package/src/App.vue +7 -8
  13. package/src/assets/category.png +0 -0
  14. package/src/axios/index.ts +6 -1
  15. package/src/components/apply-modal.vue +254 -157
  16. package/src/components/category-selector.vue +130 -0
  17. package/src/components/permission-item.vue +230 -0
  18. package/src/components/success-modal.vue +4 -4
  19. package/src/components/yqg-permission.vue +23 -110
  20. package/src/hooks/useAttributesCache.ts +21 -0
  21. package/src/hooks/useCategory.ts +21 -0
  22. package/src/hooks/useDragable.ts +9 -10
  23. package/src/hooks/useFormat.ts +50 -0
  24. package/src/hooks/useStatus.ts +82 -0
  25. package/src/i18n/zh-CH.ts +9 -2
  26. package/src/main.ts +2 -0
  27. package/src/typings/index.d.ts +40 -7
  28. package/src/utils/index.ts +9 -0
  29. package/src/yqg-permission/index.ts +13 -1
  30. package/vite.config.ts +18 -2
  31. package/dist/apply-modal-BBqMmKS2.js +0 -8742
  32. package/dist/checkbox-item-CFWhXmMU.js +0 -4991
  33. package/dist/index-BAGvIeoy.js +0 -6164
  34. package/dist/index.umd.cjs +0 -259
  35. package/dist_/345/211/257/346/234/254/apply-modal-Bgd3UWf-.js +0 -8739
  36. package/dist_/345/211/257/346/234/254/card.png +0 -0
  37. package/dist_/345/211/257/346/234/254/checkbox-item-DiIgFuBE.js +0 -4988
  38. package/dist_/345/211/257/346/234/254/dialog.png +0 -0
  39. package/dist_/345/211/257/346/234/254/image.png +0 -0
  40. package/dist_/345/211/257/346/234/254/index-CUS1Jydp.js +0 -6164
  41. package/dist_/345/211/257/346/234/254/index.js +0 -5
  42. package/dist_/345/211/257/346/234/254/index.umd.cjs +0 -259
  43. package/dist_/345/211/257/346/234/254/yqg-permission-ChMRXqi6.js +0 -14944
  44. package/src/assets/apply.png +0 -0
  45. package/src/components/checkbox-item.vue +0 -201
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yqg/permission",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-alpha.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "type": "module",
@@ -11,7 +11,10 @@
11
11
  "scripts": {
12
12
  "build": "vue-tsc -b && vite build",
13
13
  "dev": "vite",
14
- "preview": "vite preview"
14
+ "preview": "vite preview",
15
+ "demo:build": "vue-tsc -b && STAGE=test vite build",
16
+ "prod:build": "vue-tsc -b && STAGE=prod vite build"
17
+
15
18
  },
16
19
  "devDependencies": {
17
20
  "@ant-design/icons-vue": "^7.0.1",
@@ -29,6 +32,13 @@
29
32
  "vite": "^5.4.9",
30
33
  "vite-plugin-css-injected-by-js": "^3.5.2",
31
34
  "vue": "^3.5.12",
32
- "vue-tsc": "^2.1.8"
35
+ "vue-tsc": "^2.1.8",
36
+ "@alicloud/cdn20180510": "3.1.2",
37
+ "@alicloud/openapi-client": "0.4.12",
38
+ "@originjs/vite-plugin-commonjs": "1.0.3",
39
+ "@yqg/max-utils": "^1.0.2",
40
+ "ali-oss": "6.17.1",
41
+ "chalk": "5.3.0",
42
+ "ora": "5.4.1"
33
43
  }
34
44
  }
@@ -0,0 +1,237 @@
1
+ // vite-plugin-alioss.ts
2
+ import { PluginOption, UserConfig, ResolvedConfig } from 'vite';
3
+ import CdnClient, {
4
+ PushObjectCacheRequest,
5
+ RefreshObjectCachesRequest,
6
+ } from '@alicloud/cdn20180510';
7
+ import { Config } from '@alicloud/openapi-client';
8
+ import OSS from 'ali-oss';
9
+ import { join } from 'path';
10
+ import { URL } from 'url';
11
+ import { lodash as _, logger, ora } from '@yqg/max-utils';
12
+ import chalk from 'chalk';
13
+
14
+ type AliOSSConfig = {
15
+ cdnDir: string;
16
+ htmlDir?: string;
17
+ cdnRetry?: boolean;
18
+ };
19
+
20
+ export default function viteAliossPlugin(options: AliOSSConfig): PluginOption {
21
+ let viteConfig: ResolvedConfig;
22
+ let filterFields: string[] = [];
23
+ const aliyunBucketMap = Object.fromEntries(
24
+ Object.entries({
25
+ feat: [
26
+ 'fintopia-web',
27
+ 'https://static-ali.yangqianguan.com',
28
+ 'oss-cn-beijing',
29
+ ],
30
+ prod: [
31
+ 'fintopia-web',
32
+ 'https://static-ali.yangqianguan.com',
33
+ 'oss-cn-beijing',
34
+ ],
35
+ test: [
36
+ 'fintopia-web-test',
37
+ 'https://static-ali-test.yangqianguan.com',
38
+ 'oss-cn-beijing',
39
+ ],
40
+ }).map(([stage, [name, origin, region, endpoint]]) => [
41
+ stage,
42
+ { name, origin, region, endpoint },
43
+ ]),
44
+ );
45
+
46
+ return {
47
+ name: 'vite-plugin-alioss',
48
+ enforce: 'post',
49
+ apply: "build",
50
+ // 配置解析钩子
51
+ config() {
52
+ const STAGE = process.env.STAGE as 'test' | 'prod';
53
+ if (!STAGE) {
54
+ console.warn(chalk.yellow('缺少环境变量 STAGE,将跳过阿里云 CDN 上传'));
55
+ return;
56
+ }
57
+
58
+ // 设置 publicPath
59
+ const bucket = aliyunBucketMap[STAGE];
60
+ if (bucket && options?.cdnDir) {
61
+ return {
62
+ base: `${bucket.origin}/${options.cdnDir}`
63
+ } as UserConfig;
64
+ }
65
+ },
66
+
67
+ // 获取解析后的 Vite 配置
68
+ configResolved(config) {
69
+ viteConfig = config;
70
+ },
71
+
72
+ generateBundle(_, bundle) {
73
+ // 会多次执行
74
+ if(_.format === 'umd') {
75
+ filterFields = Object.keys(bundle);
76
+ }
77
+ },
78
+
79
+ // 构建完成钩子
80
+ async closeBundle() {
81
+ const STAGE = process.env.STAGE as 'test' | 'prod';
82
+ if (!STAGE || options?.cdnRetry) {
83
+ console.log(chalk.yellow('跳过阿里云 CDN 上传'));
84
+ return;
85
+ }
86
+
87
+ const { cdnDir } = options || {
88
+ cdnDir: '',
89
+ };
90
+
91
+ if (cdnDir) {
92
+ if (cdnDir.startsWith('/')) {
93
+ console.log(chalk.yellow('cdnDir禁止以/开头'));
94
+ process.exit(1);
95
+ }
96
+ if (!cdnDir.endsWith('/')) {
97
+ console.log(chalk.yellow('cdnDir必须以/结尾'));
98
+ process.exit(1);
99
+ }
100
+ }
101
+
102
+ const aliyunAccessKeyId =
103
+ process.env.aliyunAccessKeyId || 'LTAI5tLcBNEBRLkfak9nRA1M';
104
+ const aliyunAccessKeySecret =
105
+ process.env.aliyunAccessKeySecret || 'wxIkk2dd56IsibD6bBCeEma7QFqdi1';
106
+
107
+ // 初始化 OSS 客户端
108
+ const aliyunBucket = aliyunBucketMap[STAGE];
109
+ if (!aliyunBucket) {
110
+ console.log(chalk.yellow(
111
+ `阿里云Bucket配置不存在, 当前环境是${STAGE} 目前支持的stage有: ${Object.keys(
112
+ aliyunBucketMap,
113
+ ).join(', ')}`,
114
+ ));
115
+ process.exit(1);
116
+ }
117
+ const { region, origin: cdnOrigin, endpoint } = aliyunBucket;
118
+
119
+ const aliossConfig = {
120
+ region,
121
+ accessKeyId: aliyunAccessKeyId,
122
+ accessKeySecret: aliyunAccessKeySecret,
123
+ bucket: aliyunBucket.name,
124
+ secure: true,
125
+ timeout: 1800000,
126
+ endpoint,
127
+ };
128
+
129
+ const outDir = viteConfig.build.outDir;
130
+ console.log(outDir, 'OutDir');
131
+ const outputPath = join(process.cwd(), outDir);
132
+ const maxRetries = 3;
133
+
134
+ logger.info('alioss', '开始上传cdn资源', '🚀');
135
+ const putBatchSize = 50;
136
+ const fileChunks = _.chunk(filterFields, putBatchSize);
137
+ logger.info(`上传配置信息: ${JSON.stringify(aliossConfig, null, 2)}`);
138
+ logger.info(`上传文件数量: ${filterFields.length}`);
139
+ logger.info(`上传文件分批数量: ${fileChunks.length}`);
140
+ logger.info(`上传文件分批大小: ${putBatchSize}`);
141
+ logger.info(`上传文件最大重试次数: ${maxRetries}`);
142
+
143
+ const spinner = ora({
144
+ prefixText: 'alioss.upload',
145
+ spinner: 'aesthetic',
146
+ }).start('开始上传cdn资源');
147
+
148
+ async function uploadFileWithRetry(
149
+ client,
150
+ filename,
151
+ retries = maxRetries,
152
+ ) {
153
+ const key = join(cdnDir, filename);
154
+ const localFile = join(outputPath, filename);
155
+ console.log(localFile, "localFile");
156
+
157
+ for (let attempt = 1; attempt <= retries; attempt++) {
158
+ const attemptText = attempt === 1 ? '' : ` (重试 ${attempt})`;
159
+ try {
160
+ logger.info(`上传中 ${filename} ${attemptText}...`);
161
+ await client.put(key, localFile);
162
+ logger.info(`上传完成 ${filename} ${attemptText}`);
163
+ return;
164
+ } catch (error) {
165
+ logger.info(`上传失败 ${filename} ${attemptText}`);
166
+ if (attempt === retries) {
167
+ logger.error(`最大重试次数后阿里云上传失败 ${filename}`);
168
+ process.exit(1);
169
+ }
170
+ logger.info(`重试上传 ${filename} ${attemptText}...`);
171
+ }
172
+ }
173
+ }
174
+
175
+ for (const key in fileChunks) {
176
+ if (Object.prototype.hasOwnProperty.call(fileChunks, key)) {
177
+ const chunk = fileChunks[key];
178
+ spinner.info(
179
+ `第${+key + 1}/${fileChunks.length}批上传 - ${chunk.length} 个文件`,
180
+ );
181
+ const client = new OSS(aliossConfig);
182
+
183
+ await Promise.all(
184
+ chunk.map((filename) => uploadFileWithRetry(client, filename)),
185
+ );
186
+ spinner.info(`第${+key + 1}/${fileChunks.length}批上传完成`);
187
+ }
188
+ }
189
+
190
+ spinner.succeed('上传cdn资源完成');
191
+ const cdnClient = new CdnClient.default(new Config({
192
+ accessKeyId: aliyunAccessKeyId,
193
+ accessKeySecret: aliyunAccessKeySecret,
194
+ regionId: region,
195
+ }));
196
+
197
+ const validAssetUrls = filterFields.map(
198
+ (filename: string) => `${cdnOrigin}/${cdnDir}${filename}`,
199
+ );
200
+ const cdnHostname = new URL(cdnOrigin).hostname;
201
+ const batchSize = 100;
202
+ let start = 0;
203
+ while (start < validAssetUrls.length) {
204
+ const cdnUrls = validAssetUrls.slice(start, start + batchSize);
205
+
206
+ const cdnUrlPaths = cdnUrls.map((assetPath) =>
207
+ join(cdnHostname, cdnDir, assetPath),
208
+ );
209
+ const objectPath = cdnUrlPaths.join('\n');
210
+ // refresh
211
+ const refreshReq = new RefreshObjectCachesRequest({ objectPath });
212
+ logger.info('开始刷新cdn缓存');
213
+ try {
214
+ await cdnClient.refreshObjectCaches(refreshReq);
215
+ logger.info('刷新cdn缓存成功');
216
+ } catch (err) {
217
+ logger.error('刷新cdn缓存失败', err);
218
+ throw err;
219
+ }
220
+
221
+ const request = new PushObjectCacheRequest({ objectPath });
222
+ logger.info('开始推送cdn缓存');
223
+ try {
224
+ await cdnClient.pushObjectCache(request);
225
+ logger.info('推送cdn缓存成功');
226
+ } catch (err) {
227
+ logger.error('推送cdn缓存失败', err);
228
+ }
229
+
230
+ start += batchSize;
231
+
232
+ // 输出刷新后cdn地址
233
+ logger.info('刷新后cdn地址', cdnUrls);
234
+ }
235
+ },
236
+ };
237
+ }
package/src/App.vue CHANGED
@@ -9,14 +9,13 @@ const color = ref<string>('#1677ff');
9
9
  const locale = ref<LocaleType>('zh-CN');
10
10
 
11
11
  const permissions = reactive([
12
- 'CRANE.ROLE.QUERY',
13
- 'CRANE.ROLE.CREATE',
14
- 'CRANE.ROLE.UPDATE',
15
- 'CRANE.ROLE.DELETE',
16
- 'CRANE.ROLE.PERMISSION_ASSIGN',
17
- 'CRANE.ROLE.EMPLOYEE_ASSIGN',
18
- 'CRANE.ROLE.DETAIL_QUERY',
19
- 'CRANE.ROLE.EXPORT'
12
+ 'test222.testlyt2',
13
+ 'test222.testplyt',
14
+ 'test222.tstplyt3',
15
+ 'test222.tstplyt4',
16
+ 'test222.tstplyt5',
17
+ 'test222.wjkwd13',
18
+ 'test222.YEWEITEST.query01',
20
19
  ]);
21
20
  // const permissions = reactive(['CRANE.BUSINESS.QUERY', 'RANE.BUSINESS.CREATE', 'CRANE.BUSINESS.UPDATE', 'CRANE.BUSINESS.DELETE']);
22
21
  const changeColor = () => {
Binary file
@@ -3,7 +3,7 @@ import axios from './axios';
3
3
  const urlPrefix = '/crane';
4
4
 
5
5
  type apiType = {
6
- [key in string]: (params: any) => Promise<{body: any}>
6
+ [key in string]: (params?: any) => Promise<{body: any}>
7
7
  }
8
8
 
9
9
  export default {
@@ -12,4 +12,9 @@ export default {
12
12
  getFlowPreview: (params: any)=> axios.post(`${urlPrefix}/permission/apply/oa/flow/submit/preview`, params),
13
13
 
14
14
  submitApply: (params: any) => axios.post(`${urlPrefix}/permission/apply/oa/flow/submit`, params),
15
+
16
+ getCategoryValues: (id: any) => axios.get(`${urlPrefix}/permission/apply/attribute/v3/${id}`),
17
+
18
+ getValidTimeOptions: () => axios.get(`${urlPrefix}/permission/apply/enums/ValidTime`),
19
+
15
20
  } as apiType