1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* @Description H5+插件
* @Author ZPFly
* @Date 2021/10/13
*/
import mediaService from "@/services/media.service";
declare global {
interface Window {
plus: any; //H5+插件
$bridge: any;
}
}
declare module "vue/types/vue" {
interface Vue {
$native: NativeService;
}
}
import Vue from "vue";
import { MediaFile } from "@/model/entity/MediaFile";
class NativeService {
init() {
Vue.prototype.$native = this;
}
/**
* @Description 拍照
* @Author ZPFly
* @Date 2021/10/13
*/
capturePhoto(media: MediaFile) {
const $bridge = window.$bridge;
return new Promise((resolve) => {
$bridge.takePhoto(media, (data: any) => {
mediaService.batAdd(data).then(() => {
alert("插入影像记录");
});
resolve(data);
});
});
}
/**
* @Description 录音
* @Author ZPFly
* @Date 2021/10/13
*/
captureRecord(media: MediaFile) {
const $bridge = window.$bridge;
return new Promise((resolve) => {
const audio = window.plus.audio.getRecorder();
const path = $bridge.getAudioPath();
const startRecord = () => {
const fileName = $bridge.generateAudioName();
audio.record(
{ filename: `${path}/${fileName}` },
(path: string) => {
media.filePath = path;
mediaService.add(media);
startRecord();
},
() => {
resolve({});
}
);
};
startRecord();
});
}
/**
* @Description 录像
* @Author ZPFly
* @Date 2021/10/13
*/
captureVideo(media: MediaFile) {
const $bridge = window.$bridge;
return new Promise((resolve) => {
const path = $bridge.getVideoPath();
const startCapture = () => {
const cmr = window.plus.camera.getCamera();
const res = cmr.supportedVideoResolutions[0];
const fmt = cmr.supportedVideoFormats[0];
const fileName = $bridge.generateVideoName();
cmr.startVideoCapture(
(path: any) => {
media.filePath = path;
mediaService.add(media);
startCapture();
console.log("Capture video success: " + path);
},
(error: any) => {
console.log("Capture video failed: " + error.message);
resolve({});
},
{ filename: `${path}/${fileName}`, resolution: res, format: fmt }
);
};
startCapture();
});
}
/**
* @Description 二维码扫描
* @Author ZPFly
* @Date 2021/10/13
*/
qrScan() {
return new Promise((resolve) => {
const plus = window.plus;
// 创建Barcode扫码控件
const barcode: any = plus.barcode.create("plusBarcode", [plus.barcode.QR], {
top: "100px",
left: "0px",
width: "100%",
height: "500px",
position: "static",
});
barcode.onmarked = (type: any, result: string) => {
console.log("扫描结果:" + type + "-" + result);
resolve(result);
plus.webview.currentWebview().remove(barcode);
};
plus.webview.currentWebview().append(barcode);
// 开始识别
barcode.start();
});
}
/**
* @Description 预览图片
* @Author ZPFly
* @Date 2021/10/13
*/
previewImage(paths: Array<string>) {
window.plus?.nativeUI.previewImage(paths);
}
/**
* @Description 获取设备信息
* @Author ZPFly
* @Date 2021/10/13
*/
getDeviceInfo() {
const plus = window.plus;
// getOAID 获取匿名设备标识符
return new Promise((resolve, reject) => {
plus.device.getInfo({
success: (e: any) => {
resolve(e);
console.log("getDeviceInfo success: " + JSON.stringify(e));
},
fail: (e: any) => {
reject(e);
console.log("getDeviceInfo failed: " + JSON.stringify(e));
},
});
});
}
/**
* @Description 获取当前位置信息
* @Author ZPFly
* @Date 2021/10/13
*/
getCurrentPosition() {
// 使用百度地图地位模块获取位置信息
return new Promise((resolve, reject) => {
window.plus.geolocation.getCurrentPosition(
function (p: any) {
resolve(p.coords);
},
function (e: any) {
reject(e);
},
{ provider: "baidu", coordsType: "bd09ll" }
);
});
}
/**
*@Desc 功能描述:云从人脸识别
*@Author XWH
*Date 2022/2/19 18:24
*/
cloudWalkBiometrics() {
const $bridge = window.$bridge;
return new Promise((resolve) => {
$bridge.cloudWalkBiometrics({},(data: any) => {
resolve(data);
});
});
}
/**
*@Desc 功能描述:新增日程
*@Author XWH
*Date 2022/2/19 18:27
*/
addCalendar(params: any) {
const $bridge = window.$bridge;
return new Promise((resolve) => {
$bridge.calendarOperate(params,(data: any) => {
console.log('日程----'+data);
resolve(data);
});
});
}
}
const nativeService = new NativeService();
export default nativeService;