mix-public 1.1.7 → 1.1.9
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/README.md +4 -2
- package/customMethod/cachPictureForWeb.ts +67 -0
- package/customMethod/cookie.js +1 -1
- package/customMethod/cryptoJS.js +1 -1
- package/customMethod/{imageFormat.js → imageFormat.ts} +74 -62
- package/customMethod/{pageParams.js → pageParams.ts} +3 -3
- package/customMethod/publicLogic.ts +168 -0
- package/docs/01./346/241/206/346/236/266/344/273/213/347/273/215/02./345/211/215/347/253/257/346/241/206/346/236/266.md +0 -203
- package/docs/01./346/241/206/346/236/266/344/273/213/347/273/215/03./345/211/215/347/253/257/351/241/271/347/233/256/344/273/213/347/273/215.md +2 -44
- package/docs/01./346/241/206/346/236/266/344/273/213/347/273/215/04./345/277/253/351/200/237/344/270/212/346/211/213.md +83 -0
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./351/241/265/351/235/242/350/267/263/350/275/254/01.Goto.md +66 -0
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./{346/234/254/345/234/260/345/234/260/345/235/200 → 351/241/265/351/235/242}/350/267/263/350/275/254/02.GotoMain.md +6 -3
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./{346/234/254/345/234/260/345/234/260/345/235/200 → 351/241/265/351/235/242}/350/267/263/350/275/254/03.Drawer.md +17 -11
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./{346/234/254/345/234/260/345/234/260/345/235/200 → 351/241/265/351/235/242}/350/267/263/350/275/254/04.PopupShow.md +11 -9
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./{346/234/254/345/234/260/345/234/260/345/235/200 → 351/241/265/351/235/242}/350/267/263/350/275/254/05.GoBack.md +7 -4
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./{346/234/254/345/234/260/345/234/260/345/235/200 → 351/241/265/351/235/242}/350/267/263/350/275/254/06.ReturnHomePage.md +7 -4
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{02./347/275/221/347/273/234/345/234/260/345/235/200/350/267/263/350/275/254/02.GotoUrlByBrowse.md → 01./351/241/265/351/235/242/350/267/263/350/275/254/07.GotoUrlByBrowse.md} +8 -5
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{03./350/267/263/350/275/254/347/211/271/346/256/212/351/241/265/351/235/242 → 02./347/211/271/346/256/212/351/241/265/351/235/242/350/267/263/350/275/254}/01.GoToVideo.md +7 -4
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{03./350/267/263/350/275/254/347/211/271/346/256/212/351/241/265/351/235/242 → 02./347/211/271/346/256/212/351/241/265/351/235/242/350/267/263/350/275/254}/02.GoToMap.md +3 -2
- package/docs/02.API/01./346/234/254/345/234/260/345/217/202/346/225/260/345/255/230/345/202/250/01.putCookieInfo.md +3 -3
- package/docs/02.API/01./346/234/254/345/234/260/345/217/202/346/225/260/345/255/230/345/202/250/02.getCookieInfo.md +5 -5
- package/docs/02.API/15.APP/346/223/215/344/275/234/346/226/271/346/263/225/02.ClosePop.md +1 -1
- package/main/{mixappfunc.js → mixappfunc.ts} +449 -314
- package/main/paramsTypes.ts +283 -0
- package/main/returnTypes.ts +10 -0
- package/mix-project/src/components/lkb-custom-navigation-container/index.vue +2 -2
- package/mix-project/src/pages/index/index.js +6 -6
- package/mix-project/src/pages/index/index.vue +2 -2
- package/mix-project/src/pages/user-login/index.vue +11 -10
- package/mixRender.js +16 -16
- package/package.json +1 -1
- package/pageRender/componentsRender.js +16 -16
- package/pageRender/getInfo.js +76 -76
- package/pageRender/navigation.js +17 -17
- package/pageRender/pageDisplay.js +13 -5
- package/pageRender/tabbar.js +1 -1
- package/types/global.d.ts +16 -0
- package/customMethod/cachPictureForWeb.js +0 -60
- package/customMethod/publicLogic.js +0 -140
- package/docs/01./346/241/206/346/236/266/344/273/213/347/273/215/04./345/211/215/347/253/257/344/273/243/347/240/201/350/247/204/350/214/203.md +0 -153
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/01./346/234/254/345/234/260/345/234/260/345/235/200/350/267/263/350/275/254/01.Goto.md +0 -35
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/02./347/275/221/347/273/234/345/234/260/345/235/200/350/267/263/350/275/254/01.GoTo.md +0 -31
- package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/_meta.json +0 -30
- /package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{03./350/267/263/350/275/254/347/211/271/346/256/212/351/241/265/351/235/242 → 02./347/211/271/346/256/212/351/241/265/351/235/242/350/267/263/350/275/254}/03.MapSearch.md" +0 -0
- /package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{03./350/267/263/350/275/254/347/211/271/346/256/212/351/241/265/351/235/242 → 02./347/211/271/346/256/212/351/241/265/351/235/242/350/267/263/350/275/254}/04.OnlineService.md" +0 -0
- /package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{04. → 03.}/350/267/263/350/275/254/344/270/211/346/226/271/01.OpenOtherApp.md" +0 -0
- /package/docs/02.API/00./351/241/265/351/235/242/350/267/263/350/275/254/{04. → 03.}/350/267/263/350/275/254/344/270/211/346/226/271/02.OpenWechatMiniProgram.md" +0 -0
package/README.md
CHANGED
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
|
|
62
62
|
// 调用类型
|
|
63
63
|
//1.直接调用类
|
|
64
|
-
mixPublicLib.
|
|
64
|
+
mixPublicLib.PutCookieInfo('key','value')
|
|
65
65
|
//2.同步返回类
|
|
66
|
-
const result = mixPublicLib.
|
|
66
|
+
const result = mixPublicLib.GetCookieInfo('key')
|
|
67
67
|
//1.异步返回类
|
|
68
68
|
mixPublicLib.UploadPhoto({PhotoCount:1, isCut:true, Quality:1}).then(file=>{
|
|
69
69
|
console.log(file)
|
|
@@ -90,3 +90,5 @@
|
|
|
90
90
|
- v1.1.5 部分方法网页版完善/优化方法样式
|
|
91
91
|
- v1.1.6 添加APPpop页面
|
|
92
92
|
- v1.1.7 添加文档模板/部分 web 实现添加
|
|
93
|
+
- v1.1.8 添加核心方法TS配置,部分方法修复/部分方法吗规范统一
|
|
94
|
+
- v1.1.9 添加视频下载/视频预览/音频录制方法
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
interface IcachPic {
|
|
2
|
+
Picurl: string;
|
|
3
|
+
Domid: string;
|
|
4
|
+
}
|
|
5
|
+
import md5 from "../resource/md5.js"
|
|
6
|
+
export default (op: IcachPic): void => {
|
|
7
|
+
var indexedDB =
|
|
8
|
+
window.indexedDB ||
|
|
9
|
+
window.mozIndexedDB ||
|
|
10
|
+
window.webkitIndexedDB ||
|
|
11
|
+
window.msIndexedDB
|
|
12
|
+
var dataBase: any = null
|
|
13
|
+
dataBase = indexedDB.open("MIXAPPCachePicture", 1)
|
|
14
|
+
dataBase.onupgradeneeded = function (e: any) {
|
|
15
|
+
var active = dataBase.result
|
|
16
|
+
var objectDb = active.createObjectStore("seasidecity", {
|
|
17
|
+
keyPath: "id",
|
|
18
|
+
})
|
|
19
|
+
objectDb.createIndex("index_base64", "base64", {
|
|
20
|
+
unique: false,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
dataBase.onsuccess = function (e: any) {
|
|
24
|
+
var transaction = dataBase.result.transaction(["seasidecity"])
|
|
25
|
+
var objectStore = transaction.objectStore("seasidecity")
|
|
26
|
+
var request = objectStore.get(md5(op.Picurl))
|
|
27
|
+
request.onerror = function (event: any) { }
|
|
28
|
+
request.onsuccess = function (event: any) {
|
|
29
|
+
if (request.result) {
|
|
30
|
+
setTimeout(function () {
|
|
31
|
+
const Domid: any = document.getElementById(op.Domid)
|
|
32
|
+
if (Domid)
|
|
33
|
+
Domid.src = request.result.base64
|
|
34
|
+
}, 300)
|
|
35
|
+
} else {
|
|
36
|
+
setTimeout(function () {
|
|
37
|
+
const Domid: any = document.getElementById(op.Domid)
|
|
38
|
+
if (Domid)
|
|
39
|
+
Domid.src = op.Picurl
|
|
40
|
+
}, 300)
|
|
41
|
+
var img = document.createElement("img")
|
|
42
|
+
img.setAttribute("crossOrigin", "anonymous")
|
|
43
|
+
img.src = op.Picurl
|
|
44
|
+
img.onload = function () {
|
|
45
|
+
var canvas = document.createElement("canvas")
|
|
46
|
+
canvas.width = img.width
|
|
47
|
+
canvas.height = img.height
|
|
48
|
+
var ctx: any = canvas.getContext("2d")
|
|
49
|
+
ctx.drawImage(img, 0, 0, img.width, img.height)
|
|
50
|
+
var dataURL = canvas.toDataURL("image/png")
|
|
51
|
+
|
|
52
|
+
var active = dataBase.result
|
|
53
|
+
var data = active.transaction(["seasidecity"], "readwrite")
|
|
54
|
+
var objectDb = data.objectStore("seasidecity")
|
|
55
|
+
var request = objectDb.put({
|
|
56
|
+
id: md5(op.Picurl),
|
|
57
|
+
base64: dataURL,
|
|
58
|
+
})
|
|
59
|
+
request.onerror = function (e: any) { }
|
|
60
|
+
|
|
61
|
+
data.oncomplete = function (e: any) { }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
dataBase.onerror = function (e: any) { }
|
|
67
|
+
}
|
package/customMethod/cookie.js
CHANGED
package/customMethod/cryptoJS.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import SimpleCrop from "../imageCut/SimpleCrop.js"
|
|
2
2
|
import jsQR from "../resource/jsQR.js"
|
|
3
3
|
// 文件下载
|
|
4
|
-
function downloadBlob(blob) {
|
|
4
|
+
function downloadBlob(blob: Blob | MediaSource) {
|
|
5
5
|
// 1. 创建下载链接
|
|
6
6
|
const url = window.URL.createObjectURL(blob);
|
|
7
7
|
const a = document.createElement('a');
|
|
8
8
|
a.href = url;
|
|
9
9
|
a.download = 'mix_app_image_' + new Date().getTime();
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
// 2. 触发下载
|
|
12
12
|
document.body.appendChild(a);
|
|
13
13
|
a.click();
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
// 3. 清理
|
|
16
16
|
document.body.removeChild(a);
|
|
17
17
|
window.URL.revokeObjectURL(url);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// base64转换为blob
|
|
21
|
-
const dataURLtoBlob = function (base64) {
|
|
22
|
-
var arr = base64.split(",");
|
|
23
|
-
var
|
|
21
|
+
const dataURLtoBlob = function (base64: string) {
|
|
22
|
+
var arr = base64.split(",") || [];
|
|
23
|
+
var mimeMatch = arr[0].match(/:(.*?);/);
|
|
24
|
+
var mime = mimeMatch ? mimeMatch[1] : '';
|
|
24
25
|
var bstr = atob(arr[1]);
|
|
25
26
|
var n = bstr.length;
|
|
26
27
|
var u8arr = new Uint8Array(n);
|
|
@@ -31,7 +32,7 @@ const dataURLtoBlob = function (base64) {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
// 获取文件,返回file对象
|
|
34
|
-
const getImgFile = async (imgData, type = "image/png", fileName = "mixImage.png")=> {
|
|
35
|
+
const getImgFile = async (imgData: string | object, type: string = "image/png", fileName: string = "mixImage.png") => {
|
|
35
36
|
if (typeof imgData === "object") {
|
|
36
37
|
return Promise.resolve(imgData)
|
|
37
38
|
} else {
|
|
@@ -58,7 +59,7 @@ const getImgFile = async (imgData, type = "image/png", fileName = "mixImage.png"
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
// 非裁剪压缩
|
|
61
|
-
function compressImage(src, quality = 1, outputFormat = "image/jpeg") {
|
|
62
|
+
function compressImage(src: any, quality = 1, outputFormat = "image/jpeg") {
|
|
62
63
|
return new Promise((resolve, reject) => {
|
|
63
64
|
const type = Object.prototype.toString.call(src);
|
|
64
65
|
const image = new Image();
|
|
@@ -73,7 +74,7 @@ function compressImage(src, quality = 1, outputFormat = "image/jpeg") {
|
|
|
73
74
|
canvas.width = width;
|
|
74
75
|
canvas.height = height;
|
|
75
76
|
const ctx = canvas.getContext("2d");
|
|
76
|
-
ctx
|
|
77
|
+
ctx?.drawImage(image, 0, 0, width, height);
|
|
77
78
|
resolve(dataURLtoBlob(canvas.toDataURL(outputFormat, quality)));
|
|
78
79
|
};
|
|
79
80
|
image.onerror = reject;
|
|
@@ -81,7 +82,7 @@ function compressImage(src, quality = 1, outputFormat = "image/jpeg") {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
// 保存在线图片到浏览器下载
|
|
84
|
-
export async function saveOnlineImage(imageUrl) {
|
|
85
|
+
export async function saveOnlineImage(imageUrl: string) {
|
|
85
86
|
try {
|
|
86
87
|
// 1. 获取图片数据
|
|
87
88
|
const response = await fetch(imageUrl);
|
|
@@ -98,7 +99,7 @@ export async function saveOnlineImage(imageUrl) {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
// 保存base64到浏览器下载
|
|
101
|
-
export function savebase64Image(base64) {
|
|
102
|
+
export function savebase64Image(base64: string) {
|
|
102
103
|
try {
|
|
103
104
|
// 1. 转 base64为blob
|
|
104
105
|
var blob = dataURLtoBlob(base64);
|
|
@@ -108,12 +109,17 @@ export function savebase64Image(base64) {
|
|
|
108
109
|
console.error('保存图片失败:', error);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
112
|
+
interface imageCropType {
|
|
113
|
+
file: any;
|
|
114
|
+
width: number;
|
|
115
|
+
height: number;
|
|
116
|
+
}
|
|
111
117
|
|
|
112
118
|
function imageCrop({
|
|
113
119
|
width,
|
|
114
120
|
height,
|
|
115
121
|
file,
|
|
116
|
-
}) {
|
|
122
|
+
}: imageCropType) {
|
|
117
123
|
return new Promise((resolve, reject) => {
|
|
118
124
|
new SimpleCrop({
|
|
119
125
|
src: file,
|
|
@@ -122,8 +128,8 @@ function imageCrop({
|
|
|
122
128
|
height: height,
|
|
123
129
|
},
|
|
124
130
|
cropSizePercent: 1,
|
|
125
|
-
cropCallback: function (resultCanvas) {
|
|
126
|
-
resultCanvas.toBlob((fileBlob) => {
|
|
131
|
+
cropCallback: function (resultCanvas: any) {
|
|
132
|
+
resultCanvas.toBlob((fileBlob: any) => {
|
|
127
133
|
if (!fileBlob) {
|
|
128
134
|
reject(new Error("裁切失败"))
|
|
129
135
|
return
|
|
@@ -148,62 +154,68 @@ function imageCrop({
|
|
|
148
154
|
* Quality // 压缩质量 0-1
|
|
149
155
|
* }
|
|
150
156
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
getImgFile(imgPath).then(async(file)=>{
|
|
155
|
-
// 使用createImageBitmap解码图片
|
|
156
|
-
const bitmap = await createImageBitmap(file);
|
|
157
|
-
const width = Math.floor(bitmap.width * formatConfig.Quality)
|
|
158
|
-
const height = Math.floor(bitmap.height * formatConfig.Quality)
|
|
159
|
-
imageCrop({file,width,height}).then(file=>{
|
|
160
|
-
resolve(file)
|
|
161
|
-
}).catch(err=>{
|
|
162
|
-
reject(err)
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
}else{
|
|
166
|
-
compressImage(imgPath, formatConfig.Quality).then(blob=>{
|
|
167
|
-
resolve(new File([blob], "mix_app_image.png", { type: blob.type }))
|
|
168
|
-
}).catch(err=>{
|
|
169
|
-
reject(err)
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
})
|
|
157
|
+
interface formatImageType {
|
|
158
|
+
isCut?: boolean;
|
|
159
|
+
Quality?: number;
|
|
173
160
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
161
|
+
export async function formatImage(imgPath: any, formatConfig: formatImageType = { isCut: false, Quality: 1 }) {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const Quality: number = formatConfig.Quality ?? 1
|
|
164
|
+
if (formatConfig.isCut) {
|
|
165
|
+
getImgFile(imgPath).then(async (file: any) => {
|
|
166
|
+
// 使用createImageBitmap解码图片
|
|
167
|
+
const bitmap = await createImageBitmap(file);
|
|
168
|
+
const width = Math.floor(bitmap.width * Quality)
|
|
169
|
+
const height = Math.floor(bitmap.height * Quality)
|
|
170
|
+
imageCrop({ file, width, height }).then(file => {
|
|
178
171
|
resolve(file)
|
|
172
|
+
}).catch(err => {
|
|
173
|
+
reject(err)
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
} else {
|
|
177
|
+
compressImage(imgPath, Quality).then((blob: any) => {
|
|
178
|
+
resolve(new File([blob], "mix_app_image.png", { type: blob.type }))
|
|
179
|
+
}).catch(err => {
|
|
180
|
+
reject(err)
|
|
179
181
|
})
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function formatVideo(imgPath: any) {
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
getImgFile(imgPath, "video/mp4", "mixVide.mp4").then(async (file) => {
|
|
189
|
+
resolve(file)
|
|
180
190
|
})
|
|
191
|
+
})
|
|
181
192
|
}
|
|
182
193
|
|
|
183
|
-
export function scanQrcode(imgPath){
|
|
194
|
+
export function scanQrcode(imgPath: any) {
|
|
184
195
|
return new Promise((resolve, reject) => {
|
|
185
|
-
getImgFile(imgPath).then(file=>{
|
|
196
|
+
getImgFile(imgPath).then((file: any) => {
|
|
186
197
|
const reader = new FileReader();
|
|
187
|
-
reader.onload = function(event) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
reader.onload = function (event) {
|
|
199
|
+
const result: any = event.target?.result;
|
|
200
|
+
const img = new Image();
|
|
201
|
+
img.onload = function () {
|
|
202
|
+
const canvas = document.createElement('canvas');
|
|
203
|
+
const ctx = canvas.getContext('2d');
|
|
204
|
+
canvas.width = img.width;
|
|
205
|
+
canvas.height = img.height;
|
|
206
|
+
ctx?.drawImage(img, 0, 0);
|
|
207
|
+
const imageData: any = ctx?.getImageData(0, 0, canvas.width, canvas.height);
|
|
208
|
+
const code = jsQR(imageData.data, imageData.width, imageData.height);
|
|
209
|
+
if (code) {
|
|
210
|
+
resolve(code.data)
|
|
211
|
+
} else {
|
|
212
|
+
resolve("")
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
img.onerror = function (event) {
|
|
216
|
+
reject(event)
|
|
217
|
+
};
|
|
218
|
+
img.src = result;
|
|
207
219
|
};
|
|
208
220
|
reader.readAsDataURL(file);
|
|
209
221
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* 获取url上的query参数以对象的方式返回 */
|
|
2
|
-
function getUrlQuery(url) {
|
|
2
|
+
function getUrlQuery(url: string): any {
|
|
3
3
|
const urlSearch = url.replace(/^[^?=]*\?/g, "")
|
|
4
|
-
const obj = {}
|
|
4
|
+
const obj: any = {}
|
|
5
5
|
const searchURL = new URLSearchParams(urlSearch)
|
|
6
|
-
searchURL.forEach((value, key) => {
|
|
6
|
+
searchURL.forEach((value: any, key: any) => {
|
|
7
7
|
obj[key] = value
|
|
8
8
|
})
|
|
9
9
|
return obj
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
[key: string]: any; // 允许通过字符串索引访问任意属性
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
declare const Func: {
|
|
7
|
+
[key: string]: (params: string) => any;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function mixJsonParse(str: string) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(str)
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return str
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function mixJsonStringify(val: object | any) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.stringify(val)
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return val
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function isPromise(obj: object | Promise<any>): boolean {
|
|
25
|
+
return obj && Object.prototype.toString.call(obj) === '[object Promise]';
|
|
26
|
+
}
|
|
27
|
+
interface callFunction {
|
|
28
|
+
(params: any): any | void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface callMethodType {
|
|
32
|
+
environment: { isWeb: boolean, isHarmony: boolean, isAndroid: boolean, isIOS: boolean };
|
|
33
|
+
params: object;
|
|
34
|
+
methodName: string;
|
|
35
|
+
webMethod?: callFunction | null | any;
|
|
36
|
+
androidMethod?: callFunction | null | any;
|
|
37
|
+
iosMethod?: callFunction | null | any;
|
|
38
|
+
}
|
|
39
|
+
interface asyncReturnMethodType {
|
|
40
|
+
callBackMethod?: callFunction | null | any;
|
|
41
|
+
}
|
|
42
|
+
interface syncReturnMethod {
|
|
43
|
+
singleField?: boolean;
|
|
44
|
+
asyncReturn?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export const asyncReturnMethod = (op: callMethodType & asyncReturnMethodType): Promise<any> => {
|
|
47
|
+
var environment = {
|
|
48
|
+
isWeb: op?.environment?.isWeb || false,
|
|
49
|
+
isHarmony: op?.environment?.isHarmony || false,
|
|
50
|
+
isAndroid: op?.environment?.isAndroid || false,
|
|
51
|
+
isIOS: op?.environment?.isIOS || false
|
|
52
|
+
}
|
|
53
|
+
var webMethod = op.webMethod || false;
|
|
54
|
+
var androidMethod = op.androidMethod || false;
|
|
55
|
+
var iosMethod = op.iosMethod || false;
|
|
56
|
+
var callBackMethod = op.callBackMethod || false;
|
|
57
|
+
var params: any = op.params || {};
|
|
58
|
+
var methodName = op.methodName || "";
|
|
59
|
+
var callBackMethodName: string = "MIX_APP_" + methodName
|
|
60
|
+
params.MethodName = callBackMethodName
|
|
61
|
+
callMethod({
|
|
62
|
+
environment,
|
|
63
|
+
methodName,
|
|
64
|
+
androidMethod: () => { androidMethod && androidMethod().then((data: any) => { window[callBackMethodName](data) }).catch((err: any) => { window[callBackMethodName](err) }) },
|
|
65
|
+
iosMethod: () => { iosMethod && iosMethod().then((data: any) => { window[callBackMethodName](data) }).catch((err: any) => { window[callBackMethodName](err) }) },
|
|
66
|
+
webMethod: () => { webMethod && webMethod().then((data: any) => { window[callBackMethodName](data) }).catch((err: any) => { window[callBackMethodName](err) }) },
|
|
67
|
+
params
|
|
68
|
+
})
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
window[callBackMethodName] = (data: any) => {
|
|
71
|
+
callBackMethod && data ? callBackMethod(data).then((formatData: any) => { resolve(formatData) }).catch((err: any) => { reject(err) }) : resolve(data)
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export const callMethod = (op: callMethodType): void => {
|
|
76
|
+
var isWeb = op?.environment?.isWeb || false;
|
|
77
|
+
var isHarmony = op?.environment?.isHarmony || false;
|
|
78
|
+
var isAndroid = op?.environment?.isAndroid || false;
|
|
79
|
+
var isIOS = op?.environment?.isIOS || false;
|
|
80
|
+
var webMethod = op.webMethod || false;
|
|
81
|
+
var androidMethod = op.androidMethod || false;
|
|
82
|
+
var iosMethod = op.iosMethod || false;
|
|
83
|
+
var params: any = op.params || {};
|
|
84
|
+
var methodName = op.methodName;
|
|
85
|
+
for (var key in params) {
|
|
86
|
+
if (!Object.hasOwn(params, key)) continue;
|
|
87
|
+
params[key] = params[key].toString();
|
|
88
|
+
}
|
|
89
|
+
if (isWeb) {
|
|
90
|
+
webMethod && webMethod();
|
|
91
|
+
} else {
|
|
92
|
+
if (isAndroid || isHarmony) {
|
|
93
|
+
androidMethod ? androidMethod(mixJsonStringify(params)) : window.Func[methodName](mixJsonStringify(params));
|
|
94
|
+
} else if (isIOS) {
|
|
95
|
+
iosMethod ? iosMethod(mixJsonStringify(params)) : window.webkit.messageHandlers[methodName].postMessage(
|
|
96
|
+
mixJsonStringify(params)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export const syncReturnMethod = (op: callMethodType & syncReturnMethod & asyncReturnMethodType) => {
|
|
102
|
+
var isWeb = op?.environment?.isWeb || false;
|
|
103
|
+
var isHarmony = op?.environment?.isHarmony || false;
|
|
104
|
+
var isAndroid = op?.environment?.isAndroid || false;
|
|
105
|
+
var isIOS = op?.environment?.isIOS || false;
|
|
106
|
+
var webMethod = op.webMethod || false;
|
|
107
|
+
var asyncReturn = op.asyncReturn || false;
|
|
108
|
+
var androidMethod = op.androidMethod || false;
|
|
109
|
+
var iosMethod = op.iosMethod || false;
|
|
110
|
+
var params: any = op.params || {};
|
|
111
|
+
var methodName = op.methodName;
|
|
112
|
+
var singleField = op.singleField || false;
|
|
113
|
+
var singleParam = ""
|
|
114
|
+
for (var key in params) {
|
|
115
|
+
if (!Object.hasOwn(params, key)) continue;
|
|
116
|
+
params[key] = params[key].toString();
|
|
117
|
+
if (singleField) {
|
|
118
|
+
singleParam = params[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
var result: any;
|
|
122
|
+
if (isWeb) {
|
|
123
|
+
webMethod && (result = webMethod());
|
|
124
|
+
} else {
|
|
125
|
+
if (isAndroid || isHarmony) {
|
|
126
|
+
if (asyncReturn) {
|
|
127
|
+
result = new Promise((resolve, reject) => {
|
|
128
|
+
try {
|
|
129
|
+
params.MethodName = "MIX_APP_" + methodName
|
|
130
|
+
window["MIX_APP_" + methodName] = (data: any) => {
|
|
131
|
+
resolve(data)
|
|
132
|
+
}
|
|
133
|
+
androidMethod ? resolve(androidMethod()) : window.Func[methodName](mixJsonStringify(params))
|
|
134
|
+
} catch (error) {
|
|
135
|
+
reject(error)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
} else {
|
|
139
|
+
result = androidMethod ? androidMethod() : window.Func[methodName](mixJsonStringify(params));
|
|
140
|
+
}
|
|
141
|
+
} else if (isIOS) {
|
|
142
|
+
if (asyncReturn) {
|
|
143
|
+
result = new Promise((resolve, reject) => {
|
|
144
|
+
try {
|
|
145
|
+
params.MethodName = "MIX_APP_" + methodName
|
|
146
|
+
window["MIX_APP_" + methodName] = (data: any) => {
|
|
147
|
+
resolve(data)
|
|
148
|
+
}
|
|
149
|
+
if (singleField) {
|
|
150
|
+
result = iosMethod ? resolve(iosMethod()) : decodeURIComponent(window.prompt(methodName, singleParam) ?? "")
|
|
151
|
+
} else {
|
|
152
|
+
result = iosMethod ? resolve(iosMethod()) : decodeURIComponent(window.prompt(methodName, mixJsonStringify(params)) ?? "")
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
reject(error)
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
} else {
|
|
159
|
+
if (singleField) {
|
|
160
|
+
result = iosMethod ? iosMethod() : decodeURIComponent(window.prompt(methodName, singleParam) ?? "")
|
|
161
|
+
} else {
|
|
162
|
+
result = iosMethod ? iosMethod() : decodeURIComponent(window.prompt(methodName, mixJsonStringify(params)) ?? "")
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return mixJsonParse(result);
|
|
168
|
+
};
|