yuang-framework-ui-common 1.0.42 → 1.0.44

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,117 @@
1
+
2
+ /**
3
+ * 加载脚本
4
+ * @param src
5
+ * @param callback
6
+ */
7
+ const loadScript = (src, callback) => {
8
+ if (!src) {
9
+ console.error("[src]为空");
10
+ return;
11
+ }
12
+ var script = document.createElement('script') as any,
13
+ head = document.getElementsByTagName('head')[0];
14
+ script.type = 'text/javascript';
15
+ script.charset = 'UTF-8';
16
+ script.src = src;
17
+ if (script.addEventListener) {
18
+ script.addEventListener('load', function () {
19
+ callback && callback();
20
+ }, false);
21
+ } else if (script.attachEvent) {
22
+ script.attachEvent('onreadystatechange', function () {
23
+ var target = window.event.srcElement as any;
24
+ if (target.readyState == 'loaded') {
25
+ callback && callback();
26
+ }
27
+ });
28
+ }
29
+ head.appendChild(script);
30
+ }
31
+
32
+
33
+ /**
34
+ * 加载样式
35
+ * @param src
36
+ * @param callback
37
+ */
38
+ const loadLink = (href: string, callback) => {
39
+ if (!href) {
40
+ console.error("[href]为空");
41
+ return;
42
+ }
43
+ var link = document.createElement('link') as any,
44
+ head = document.getElementsByTagName('head')[0];
45
+ link.rel = 'stylesheet';
46
+ link.charset = 'UTF-8';
47
+ link.href = href;
48
+ if (link.addEventListener) {
49
+ link.addEventListener('load', function () {
50
+ callback && callback();
51
+ }, false);
52
+ } else if (link.attachEvent) {
53
+ link.attachEvent('onreadystatechange', function () {
54
+ var target = window.event.srcElement as any;
55
+ if (target.readyState == 'loaded') {
56
+ callback && callback();
57
+ }
58
+ });
59
+ }
60
+ head.appendChild(link);
61
+ }
62
+
63
+ /**
64
+ * 加载iframe
65
+ * @param src
66
+ * @param callback
67
+ */
68
+ const loadIframe = (src: string, callback) => {
69
+ if (!src) {
70
+ console.error("[src]为空");
71
+ return;
72
+ }
73
+
74
+ var iframe = document.createElement('iframe') as any,
75
+ head = document.getElementsByTagName('head')[0];
76
+ iframe.charset = 'UTF-8';
77
+ iframe.src = src;
78
+ if (iframe.addEventListener) {
79
+ iframe.addEventListener('load', function () {
80
+ callback && callback();
81
+ }, false);
82
+ } else if (iframe.attachEvent) {
83
+ iframe.attachEvent('onreadystatechange', function () {
84
+ var target = window.event.srcElement as any;
85
+ if (target.readyState == 'loaded') {
86
+ callback && callback();
87
+ }
88
+ });
89
+ }
90
+ head.appendChild(iframe);
91
+ }
92
+
93
+ /**
94
+ * 获取文件存储大小,单位:byte字节
95
+ * @param url
96
+ * @returns {Promise<unknown>}
97
+ */
98
+ const getFileSize = (url: string) => {
99
+ return new Promise(function (resolve, reject) {
100
+ const xhr = new XMLHttpRequest();
101
+ xhr.open("HEAD", url);
102
+ xhr.onreadystatechange = function () {
103
+ if (this.readyState == this.DONE) {
104
+ if (this.status == 200) {
105
+ const size = xhr.getResponseHeader("Content-Length");
106
+ resolve(size);
107
+ } else {
108
+ reject("Failed to get file size.");
109
+ }
110
+ }
111
+ };
112
+ xhr.send();
113
+ });
114
+ }
115
+
116
+
117
+ export { loadScript, loadLink, loadIframe, getFileSize };
@@ -4,12 +4,12 @@ import { ElMessageBox } from 'element-plus/es';
4
4
 
5
5
 
6
6
 
7
- const alertMessageBox = ({title, message, confirmButtonText, callback}) => {
7
+ const alertMessageBox = ({title, message, confirmButtonText, callback}: {title: string, message: string, confirmButtonText: string, callback: (param:string)=>{}}) => {
8
8
  if(isPc()) {
9
9
  ElMessageBox.close();
10
10
  ElMessageBox.alert(message, title, {
11
11
  confirmButtonText: confirmButtonText,
12
- callback: (action) => {
12
+ callback: (action: string) => {
13
13
  callback && callback(action);
14
14
  },
15
15
  type: 'warning',
@@ -4,28 +4,28 @@ import {ElMessage} from 'element-plus'
4
4
  import {showNotify} from 'vant';
5
5
 
6
6
 
7
- const showSuccessMessage = (message) => {
7
+ const showSuccessMessage = (message: string) => {
8
8
  showMessage({
9
9
  type: 'success',
10
10
  message: message,
11
11
  });
12
12
  }
13
13
 
14
- const showWarningMessage = (message) => {
14
+ const showWarningMessage = (message: string) => {
15
15
  showMessage({
16
16
  type: 'warning',
17
17
  message: message,
18
18
  });
19
19
  }
20
20
 
21
- const showInfoMessage = (message) => {
21
+ const showInfoMessage = (message: string) => {
22
22
  showMessage({
23
23
  type: 'info',
24
24
  message: message,
25
25
  });
26
26
  }
27
27
 
28
- const showErrorMessage = (message) => {
28
+ const showErrorMessage = (message: string) => {
29
29
  showMessage({
30
30
  type: 'error',
31
31
  message: message,
@@ -37,7 +37,7 @@ const showErrorMessage = (message) => {
37
37
  * @param type 'success' | 'warning' | 'info' | 'error'
38
38
  * @param message
39
39
  */
40
- const showMessage = ({type, message}) => {
40
+ const showMessage = ({type, message}: {type: any, message: any}) => {
41
41
  if (isPc()) {
42
42
  ElMessage({
43
43
  type: type,
@@ -46,8 +46,20 @@ const typeOf = (obj) => {
46
46
  return Object.prototype.toString.call(obj).slice(8, -1);
47
47
  };
48
48
 
49
+
50
+ /**
51
+ * 是否Promise对象
52
+ * @param obj
53
+ * @returns {boolean}
54
+ */
55
+ const isPromise = (obj) => {
56
+ return obj && Object.prototype.toString.call(obj) ==="[object Promise]";
57
+ }
58
+
49
59
  export {
50
60
  shallowClone,
51
61
  deepClone,
52
62
  typeOf,
63
+
64
+ isPromise
53
65
  }
@@ -1,17 +1,49 @@
1
1
 
2
+ /**
3
+ * 获取url的参数
4
+ * @param name 参数名
5
+ * @param url,如果不传递,就使用当前url
6
+ * @returns {string|null}
7
+ */
8
+ const getParameter = (name: string, url?: string) => {
9
+ url = url || window.location.search;
10
+ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
11
+ var r = url.substr(1).match(reg);
12
+ if (r != null) return decodeURIComponent(r[2]);
13
+ return null;
14
+ }
15
+
16
+ /**
17
+ * 获取url的map集合
18
+ * @param url,如果不传递,就使用当前url
19
+ * @returns {map|null}
20
+ */
21
+ const getParameterMap = (url?: string) => {
22
+ url = url || window.location.search;
23
+
24
+ let arrObj = url.split("?") as any;
25
+ let params = Object.create(null);
26
+ if (arrObj.length > 1) {
27
+ arrObj = arrObj[1].split("&");
28
+ arrObj.forEach((item: any) => {
29
+ item = item.split("=");
30
+ params[item[0]] = decodeURIComponent(item[1]);
31
+ })
32
+ }
33
+ return params;
34
+ }
35
+
2
36
  /**
3
37
  * 删除url中的指定参数
4
- * @param url
38
+ * @param url,如果不传递,就使用当前url
5
39
  * @param parameter
6
40
  * @return {string}
7
41
  */
8
- const removeUrlParameter = (url, parameter) => {
9
- if (!url) {
10
- return console.error('参数[url]为空');
11
- }
12
- if (!parameter) {
13
- return console.error('参数[parameter]为空');
42
+ const removeParameter = (name: string, url?: string) => {
43
+ if (!name) {
44
+ return console.error('参数[name]为空');
14
45
  }
46
+ url = url || location.href;
15
47
  let urlObj;
16
48
  let isFullUrl = url.startsWith('http');
17
49
  if (isFullUrl) {
@@ -19,7 +51,7 @@ const removeUrlParameter = (url, parameter) => {
19
51
  } else {
20
52
  urlObj = new URL(url, window.location.origin);
21
53
  }
22
- urlObj.searchParams.delete(parameter);
54
+ urlObj.searchParams.delete(name);
23
55
  let result = urlObj.pathname + urlObj.search;
24
56
  if (url.includes('#')) {
25
57
  result += '#' + url.split('#')[1];
@@ -30,4 +62,28 @@ const removeUrlParameter = (url, parameter) => {
30
62
  return result;
31
63
  };
32
64
 
33
- export { removeUrlParameter };
65
+
66
+ /**
67
+ * 获取平台基础url
68
+ * @param url,如果不传递,就使用当前url
69
+ * @returns {string}
70
+ */
71
+ const getBaseUrl = (url?: string) => {
72
+ url = url || location.href;
73
+ let arr = url.split('/');
74
+ if (arr.length > 3) {
75
+ var baseUrl = '';
76
+ for (let i = 0; i < arr.length; i++) {
77
+ if (i <= 3) {
78
+ baseUrl += arr[i] + '/';
79
+ }
80
+ }
81
+ if (baseUrl) {
82
+ return baseUrl.substring(0, baseUrl.length - 1);
83
+ }
84
+ } else {
85
+ console.error('地址存在问题');
86
+ }
87
+ };
88
+
89
+ export { getParameter, getParameterMap, removeParameter, getBaseUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -7,6 +7,7 @@
7
7
  import { useRouter } from 'vue-router';
8
8
 
9
9
  import { getSsoLoginUrl, setSsoAccessToken } from '../../../../lib/utils/ssoUtils';
10
+ import { removeUrlParameter } from '../../../../lib/utils/urlUtils';
10
11
 
11
12
  const router = useRouter();
12
13
 
@@ -28,37 +29,6 @@
28
29
  router.push(ssoRedirectRoutePath);
29
30
  });
30
31
  });
31
-
32
- /**
33
- * 删除url中的指定参数
34
- * @param url
35
- * @param parameter
36
- * @return {string}
37
- */
38
- const removeUrlParameter = (url, parameter) => {
39
- if (!url) {
40
- return console.error('参数[url]为空');
41
- }
42
- if (!parameter) {
43
- return console.error('参数[parameter]为空');
44
- }
45
- let urlObj;
46
- let isFullUrl = url.startsWith('http');
47
- if (isFullUrl) {
48
- urlObj = new URL(url);
49
- } else {
50
- urlObj = new URL(url, window.location.origin);
51
- }
52
- urlObj.searchParams.delete(parameter);
53
- let result = urlObj.pathname + urlObj.search;
54
- if (url.includes('#')) {
55
- result += '#' + url.split('#')[1];
56
- }
57
- if (isFullUrl) {
58
- result = urlObj.origin + result;
59
- }
60
- return result;
61
- };
62
32
  </script>
63
33
 
64
34
  <style scoped></style>
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />