@10yun/open-sdk 0.3.89

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/app-config.js ADDED
@@ -0,0 +1,47 @@
1
+ const envArr = import.meta.env;
2
+ export default function initConfig() {
3
+ // const envArr = process.env || {};
4
+ // 合并主应用_SY_API_BASE_URL_
5
+ //const last_api_base_url = window._SY_API_BASE_URL_ || envArr.VUE_APP_SY_API_URL;
6
+ const last_api_base_url = window._SY_API_BASE_URL_ || envArr.VITE_SY_API_URL;
7
+ // 合并主应用_项目接入id
8
+ // const lastAppProjectSign = window['SY-APP-PROJECT-SIGN'] || envArr.VUE_APP_SY_APP_PROJECT_SIGN;
9
+ const lastAppProjectSign = window['SY-APP-PROJECT-SIGN'] || envArr.VITE_SY_APP_PROJECT_SIGN;
10
+ // 合并主应用_应用接入id
11
+ // const lastAppConnectId = window['SY-APP-CONNECT-ID'] || envArr.VUE_APP_SY_APP_CONNECT_ID;
12
+ const lastAppConnectId = window['SY-APP-CONNECT-ID'] || envArr.VITE_SY_APP_CONNECT_ID;
13
+ // 合并主应用_应用接入role
14
+ // const lastAppConnectRole = window['SY-APP-CONNECT-ROLE'] || envArr.VUE_APP_SY_APP_CONNECT_ROLE;
15
+ const lastAppConnectRole = window['SY-APP-CONNECT-ROLE'] || envArr.VITE_SY_APP_CONNECT_ROLE;
16
+ // 合并主应用_api_flag
17
+ const last_open_api_flag = window._SY_OPEN_API_FLAG_ || {};
18
+ // 合并主应用_api_auth
19
+ const last_open_api_auth = window._SY_OPEN_API_AUTH_ || {};
20
+
21
+ /**
22
+ * 产品信息
23
+ */
24
+ const last_product_title = envArr.VITE_SY_PRODUCT_TITLE || 'ShiyunProduct';
25
+ const last_product_sign = envArr.VITE_SY_PRODUCT_SIGN || 'ShiyunProduct';
26
+
27
+ return {
28
+ syProductTitle: last_product_title,
29
+ syProductSign: last_product_sign,
30
+ /**
31
+ *
32
+ */
33
+ syOpenApiFlag: last_open_api_flag,
34
+ syOpenApiAuth: last_open_api_auth,
35
+ // syAppUrlBase: lastAppUrlBase,
36
+ // syAppUrlPay: lastAppUrlPay,
37
+ // syAppUrlFile: lastAppUrlFile,
38
+ syApiBaseUrl: last_api_base_url,
39
+ syAppProjectSign: lastAppProjectSign,
40
+ syAppConnectRole: lastAppConnectRole,
41
+ syAppConnectId: lastAppConnectId
42
+ /**
43
+ *
44
+ */
45
+ };
46
+ }
47
+ // export default initConfig();
@@ -0,0 +1,117 @@
1
+ import fs from 'node:fs';
2
+ import { parseRouteItem } from './router.js';
3
+ var nameOnlyArr = {};
4
+ // 解析数据转菜单
5
+ function parseDataToMenu(appFlag, oldData) {
6
+ let newData = [];
7
+
8
+ for (let index1 in oldData) {
9
+ let item1 = oldData[index1];
10
+ item1 = parseRouteItem(item1);
11
+ if (nameOnlyArr[item1.name]) {
12
+ item1.name = item1.name + '_' + index1;
13
+ }
14
+ if (item1.isMenu == false && item1.isRbac == false) {
15
+ continue;
16
+ }
17
+ let item_new = {
18
+ title: item1.title || item1?.meta?.title,
19
+ path: item1.path || '',
20
+ id: appFlag + '@' + item1.name || '',
21
+ name: item1.name || '',
22
+ apiPermissions: item1.apiPermissions || [],
23
+ isPage: item1.path ? true : false,
24
+ isMenu: item1.isMenu || false,
25
+ isRbac: item1.isRbac || false,
26
+ isWindw: item1.isWindw || false,
27
+ isAlone: item1.isAlone || false,
28
+ children: []
29
+ };
30
+ if (item1.isMenu) {
31
+ item_new['checked'] = false;
32
+ item_new['menuName'] = item_new.title;
33
+ item_new['parentId'] = item1.parentId || '';
34
+ item_new['children'] = [];
35
+ }
36
+ // 判断是否有子集
37
+ if (item1.children) {
38
+ let tempChildren = item1.children;
39
+ let childrenIdNum = 0;
40
+ /**
41
+ * 处理 - 子菜单
42
+ */
43
+ let newChildren = [];
44
+ for (let index2 in tempChildren) {
45
+ let item2 = tempChildren[index2];
46
+ if (item2.isMenu) {
47
+ item2['parentId'] = item1.name;
48
+ newChildren.push(item2);
49
+ }
50
+ }
51
+ /**
52
+ * 处理 - 子操作项
53
+ */
54
+ let newOption = [];
55
+ for (let index2 in tempChildren) {
56
+ let item2 = tempChildren[index2];
57
+ item2 = parseRouteItem(item2);
58
+ if (nameOnlyArr[item2.name]) {
59
+ item2.name = item2.name + '_' + index2;
60
+ }
61
+ if (item2.isRbac) {
62
+ item2.id = appFlag + '@' + (item2.name || item1.name + '_' + ++childrenIdNum);
63
+ // item2.id = appFlag + '@' + (item2.name || item1.name);
64
+ item2.optionsName = item2.title || item2.meta.title;
65
+ item2.checked = false;
66
+ newOption.push(item2);
67
+ }
68
+ }
69
+ // 如果不存在的子操作
70
+ if (newOption.length > 0) {
71
+ item_new.menuOptionsList = newOption;
72
+ } else {
73
+ // item_new.menuOptionsList = [
74
+ // {
75
+ // title: '预览',
76
+ // optionsName: '预览',
77
+ // id: item1.name || '',
78
+ // name: item1.name || '',
79
+ // checked: false,
80
+ // isPage: item1.path ? true : false
81
+ // }
82
+ // ];
83
+ }
84
+ //
85
+ // item.children = parseDataToMenu(appFlag, [...tempChildren]);
86
+ if (newChildren.length > 0) {
87
+ item_new = Object.assign({}, item_new, {
88
+ children: parseDataToMenu(appFlag, [...newChildren])
89
+ });
90
+ }
91
+ }
92
+ // item.treeInfo = treeInfo;
93
+ newData.push(item_new);
94
+ }
95
+ return newData;
96
+ }
97
+
98
+ /**
99
+ * 获取 rbac权限配置
100
+ * @param {*} menuArr 菜单组
101
+ * @param {*} rbac_dir rbac生成的目录
102
+ * @param {*} rbac_sett rbac配置
103
+ */
104
+ export function buildRbac(menuArr, rbac_dir, rbac_sett) {
105
+ /**
106
+ * RBAC_BASE_SIGN @ 前面的标识
107
+ */
108
+ const { RBAC_BASE_SIGN } = rbac_sett;
109
+ const appFlag = RBAC_BASE_SIGN || '';
110
+ // 执行脚本的项目路径
111
+ let rbacMenuData = parseDataToMenu(appFlag, menuArr);
112
+ let rbacFile = rbac_dir + '/public/rbac.json';
113
+ let rbacContent = JSON.stringify(rbacMenuData, null, 2);
114
+ fs.writeFileSync(rbacFile, rbacContent, 'utf8');
115
+ // fs.writeFile(rbacFile, rbacContent, { encoding: 'utf8' }, (err) => {});
116
+ console.log('--已经生成 rbac 文件---');
117
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 判断是否为有效字符串:
3
+ * - 类型必须是 string
4
+ * - 不能是空字符串或全是空格
5
+ * - 不能是 'undefined' 这个字符串
6
+ */
7
+ export function isValidString(str) {
8
+ return typeof str === 'string' && str.trim() !== '' && str !== 'undefined';
9
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @action 生成加密
3
+ * @param String _str
4
+ * @param Boolean short 是否简短一些
5
+ * @returns
6
+ */
7
+ export function encryptStrEncode(_str, short = false) {
8
+ var staticchars = 'PXhw7UT1B0a9kQDKZsjIASmOezxYG4CHo5Jyfg2b8FLpEvRr3WtVnlqMidu6cN';
9
+ var encodechars = '';
10
+ for (var i = 0; i < _str.length; i++) {
11
+ var num0 = staticchars.indexOf(_str[i]);
12
+ if (num0 == -1) {
13
+ var code = _str[i];
14
+ } else {
15
+ var code = staticchars[(num0 + 3) % 62];
16
+ }
17
+ var num1 = parseInt(Math.random() * 62, 10);
18
+ if (short) {
19
+ encodechars += code + staticchars[num1];
20
+ } else {
21
+ var num2 = parseInt(Math.random() * 62, 10);
22
+ encodechars += staticchars[num1] + code + staticchars[num2];
23
+ }
24
+ }
25
+ return encodechars;
26
+ }
27
+ export function encryptStrDecode(_str, short = false) {
28
+ var staticchars = 'PXhw7UT1B0a9kQDKZsjIASmOezxYG4CHo5Jyfg2b8FLpEvRr3WtVnlqMidu6cN';
29
+ var decodechars = '';
30
+ for (var i = 1; i < _str.length; ) {
31
+ var num0 = staticchars.indexOf(_str[i]);
32
+ if (num0 == -1) {
33
+ var code = _str[i];
34
+ } else {
35
+ var code = staticchars[(num0 + 59) % 62];
36
+ }
37
+ decodechars += code;
38
+ if (!short) {
39
+ i = i + 3;
40
+ }
41
+ }
42
+ return decodechars;
43
+ }
package/common/rbac.js ADDED
@@ -0,0 +1,71 @@
1
+ import { StorageObj } from '../index.js';
2
+ const envArr = import.meta.env;
3
+ const currSign = envArr.VITE_SY_PRODUCT_SIGN;
4
+ import { isValidString } from './common.js';
5
+ /**
6
+ * 权限检查方法
7
+ * @param {String|Array} value
8
+ * @return
9
+ */
10
+ function permission_auth(value) {
11
+ // 判断数据类型
12
+ let valueType = Object.prototype.toString.call(value);
13
+ // 如果 value 不是字符串或数组,直接返回 false
14
+ if (valueType != '[object String]' && valueType != '[object Array]') {
15
+ return false;
16
+ }
17
+ let rbacStr = StorageObj.localGet('syCacheAppRbac') || '';
18
+ // 如果是字符串,直接调用 permission_check
19
+ if (valueType == '[object String]') {
20
+ return permission_check(value, rbacStr);
21
+ }
22
+ // // 如果是数组,使用 every 方法,遇到第一个 false 就跳出
23
+ // if (valueType === '[object Array]') {
24
+ // return value.every((itemStr) => permission_check(itemStr));
25
+ // }
26
+ // 如果是数组,手动遍历,遇到第一个 false 就跳出
27
+ if (valueType === '[object Array]') {
28
+ for (const itemStr of value) {
29
+ if (!permission_check(itemStr, rbacStr)) {
30
+ return false; // 遇到 false 立即跳出
31
+ }
32
+ }
33
+ return true; // 所有元素都返回 true
34
+ }
35
+ // 默认返回 false
36
+ return false;
37
+ }
38
+ function permission_check(perms_key, init_rbac) {
39
+ // 开发调试
40
+ if (envArr.MODE == 'development' && envArr.VITE_APP_DEBUG === 'on') {
41
+ // console.log(envArr.MODE, envArr.VITE_APP_DEBUG, '----');
42
+ // if (!window.__POWERED_BY_QIANKUN__) {
43
+ return true;
44
+ // }
45
+ }
46
+
47
+ perms_key = perms_key || '';
48
+ perms_key = perms_key.trim();
49
+ if (perms_key == '') {
50
+ return false;
51
+ }
52
+ if (!perms_key.includes('@')) {
53
+ perms_key = `${currSign}@${perms_key}`;
54
+ }
55
+ // 获取权限
56
+ let rbacStr = init_rbac || StorageObj.localGet('syCacheAppRbac') || '';
57
+ // console.log('---rbacStr---', rbacStr);
58
+ rbacStr = rbacStr.trim();
59
+ // 权限为空
60
+ if (!isValidString(rbacStr)) {
61
+ return false;
62
+ }
63
+ // 权限判断-所有权限
64
+ if (rbacStr == '"all@all"' || rbacStr == 'all@all') {
65
+ return true;
66
+ }
67
+ // 分割,并且,清理空格
68
+ const rbacArr = rbacStr.split(',').map((item) => item.trim());
69
+ return rbacArr.includes(perms_key);
70
+ }
71
+ export { permission_auth, permission_check };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * 路由-菜单 处理
3
+ */
4
+ function replaceSlashes(str) {
5
+ // 去除开头的斜杠
6
+ str = str.replace(/^\//, '');
7
+ // 将所有斜杠替换为下划线
8
+ str = str.replace(/\//g, '_');
9
+ return str;
10
+ }
11
+ /**
12
+ * 解析路由菜单单条,确保菜单每条都有`name`值
13
+ * @param {*} tempItem
14
+ * @param {*} i
15
+ * @returns
16
+ */
17
+ function parseRouteItem(tempItem, i) {
18
+ i = i || 1;
19
+ let tempPath = '';
20
+ /**
21
+ * 如果没有 path
22
+ */
23
+ if (!tempItem['path']) {
24
+ if (tempItem['component']) {
25
+ tempPath = tempItem['component'];
26
+ }
27
+ } else {
28
+ tempPath = tempItem.path;
29
+ }
30
+ /**
31
+ * 如果没有 component 应该删除 path
32
+ */
33
+ if (!tempItem['component']) {
34
+ tempPath = '';
35
+ }
36
+
37
+ let tempName = '';
38
+ if (!tempItem['name']) {
39
+ if (tempPath) {
40
+ tempName = replaceSlashes(tempPath);
41
+ } else {
42
+ tempName = 'temp_name_' + i;
43
+ }
44
+ } else {
45
+ tempName = tempItem['name'];
46
+ }
47
+ tempName = replaceSlashes(tempName);
48
+ /**
49
+ * 判断是否有子集
50
+ */
51
+ if (tempItem.children && tempItem.children.length > 0) {
52
+ let tempChildren = tempItem.children;
53
+ let children_menu_num = 0; // 子菜单数量
54
+ let children_opt_num = 0; // 子操作数量
55
+ tempChildren.forEach((item2, index2) => {
56
+ item2.isMenu == true && children_menu_num++;
57
+ item2.isRbac == true && children_opt_num++;
58
+ });
59
+ tempItem.children_menu_num = children_menu_num;
60
+ tempItem.children_opt_num = children_opt_num;
61
+ }
62
+ return {
63
+ ...tempItem,
64
+ path: tempPath,
65
+ name: tempName
66
+ };
67
+ }
68
+ function parseChildrenAll() {}
69
+ function parseChildrenOption() {}
70
+ function parseChildrenMenu() {}
71
+ function parseRouteTree(originalArr) {
72
+ let newArr = [];
73
+ for (let index1 in originalArr) {
74
+ let tempItem1 = originalArr[index1];
75
+ tempItem1 = parseRouteItem(tempItem1, index1);
76
+ if (tempItem.children) {
77
+ tempItem.children = parseRouteTree(tempItem.children);
78
+ }
79
+ }
80
+ }
81
+ export { parseRouteItem, parseRouteTree };
@@ -0,0 +1,15 @@
1
+ import { createElementBlock as c, openBlock as s, createElementVNode as o } from "vue";
2
+ import { _ as t } from "./index-CYEmAMQY.js";
3
+ const d = {}, r = { class: "cloud-404-wrap" };
4
+ function l(n, e) {
5
+ return s(), c("div", r, e[0] || (e[0] = [
6
+ o("div", { class: "cloud-404-box" }, [
7
+ o("div", { class: "cloud-404-code" }, "404"),
8
+ o("div", { class: "cloud-404-message" }, "Not Found")
9
+ ], -1)
10
+ ]));
11
+ }
12
+ const i = /* @__PURE__ */ t(d, [["render", l]]);
13
+ export {
14
+ i as default
15
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-DSBKHepn.cjs"),c={},s={class:"cloud-404-wrap"};function d(r,o){return e.openBlock(),e.createElementBlock("div",s,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-404-box"},[e.createElementVNode("div",{class:"cloud-404-code"},"404"),e.createElementVNode("div",{class:"cloud-404-message"},"Not Found")],-1)]))}const n=t._export_sfc(c,[["render",d]]);exports.default=n;
@@ -0,0 +1,18 @@
1
+ import { createElementBlock as n, openBlock as c, createElementVNode as o } from "vue";
2
+ import { _ as s } from "./index-CYEmAMQY.js";
3
+ const r = {}, t = {
4
+ class: "cloud-none-wrap",
5
+ style: { "background-color": "none" }
6
+ };
7
+ function l(d, e) {
8
+ return c(), n("div", t, e[0] || (e[0] = [
9
+ o("div", { class: "cloud-none-box" }, [
10
+ o("div", { class: "cloud-none-code" }, "不建议,子应用单独运行~"),
11
+ o("div", { class: "cloud-none-message" }, "Not Alone")
12
+ ], -1)
13
+ ]));
14
+ }
15
+ const i = /* @__PURE__ */ s(r, [["render", l]]);
16
+ export {
17
+ i as default
18
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("./index-DSBKHepn.cjs"),c={},t={class:"cloud-none-wrap",style:{"background-color":"none"}};function r(s,o){return e.openBlock(),e.createElementBlock("div",t,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-none-box"},[e.createElementVNode("div",{class:"cloud-none-code"},"不建议,子应用单独运行~"),e.createElementVNode("div",{class:"cloud-none-message"},"Not Alone")],-1)]))}const l=n._export_sfc(c,[["render",r]]);exports.default=l;