Showing
6 changed files
with
0 additions
and
1414 deletions
plugins/permission.js
deleted
100644 → 0
1 | -/** | |
2 | - * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启 | |
3 | - */ | |
4 | - | |
5 | -var isIos | |
6 | -// #ifdef APP-PLUS | |
7 | -isIos = (plus.os.name == "iOS") | |
8 | -// #endif | |
9 | - | |
10 | -// 判断推送权限是否开启 | |
11 | -function judgeIosPermissionPush() { | |
12 | - var result = 0; | |
13 | - var UIApplication = plus.ios.import("UIApplication"); | |
14 | - var app = UIApplication.sharedApplication(); | |
15 | - var enabledTypes = 0; | |
16 | - if (app.currentUserNotificationSettings) { | |
17 | - var settings = app.currentUserNotificationSettings(); | |
18 | - enabledTypes = settings.plusGetAttribute("types"); | |
19 | - if (enabledTypes == 0) { | |
20 | - console.log("推送权限没有开启"); | |
21 | - } else { | |
22 | - result = 1; | |
23 | - console.log("已经开启推送功能!") | |
24 | - } | |
25 | - plus.ios.deleteObject(settings); | |
26 | - } else { | |
27 | - enabledTypes = app.enabledRemoteNotificationTypes(); | |
28 | - if (enabledTypes == 0) { | |
29 | - console.log("推送权限没有开启!"); | |
30 | - } else { | |
31 | - result = 1; | |
32 | - console.log("已经开启推送功能!") | |
33 | - } | |
34 | - console.log("enabledTypes2:" + enabledTypes); | |
35 | - } | |
36 | - plus.ios.deleteObject(app); | |
37 | - plus.ios.deleteObject(UIApplication); | |
38 | - return result; | |
39 | -} | |
40 | - | |
41 | -// 判断定位权限是否开启 | |
42 | -function judgeIosPermissionLocation() { | |
43 | - var result = 0; | |
44 | - var cllocationManger = plus.ios.import("CLLocationManager"); | |
45 | - var status = cllocationManger.authorizationStatus(); | |
46 | - result = (status != 2) ? 1 : 0; | |
47 | - console.log("定位权限开启:" + result); | |
48 | - // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation | |
49 | - /* var enable = cllocationManger.locationServicesEnabled(); | |
50 | - var status = cllocationManger.authorizationStatus(); | |
51 | - console.log("enable:" + enable); | |
52 | - console.log("status:" + status); | |
53 | - if (enable && status != 2) { | |
54 | - result = true; | |
55 | - console.log("手机定位服务已开启且已授予定位权限"); | |
56 | - } else { | |
57 | - console.log("手机系统的定位没有打开或未给予定位权限"); | |
58 | - } */ | |
59 | - plus.ios.deleteObject(cllocationManger); | |
60 | - return { | |
61 | - result: result, | |
62 | - permissionName: "定位" | |
63 | - }; | |
64 | -} | |
65 | - | |
66 | -// 判断麦克风权限是否开启 | |
67 | -function judgeIosPermissionRecord() { | |
68 | - var result = 0; | |
69 | - var avaudiosession = plus.ios.import("AVAudioSession"); | |
70 | - var avaudio = avaudiosession.sharedInstance(); | |
71 | - var permissionStatus = avaudio.recordPermission(); | |
72 | - console.log("permissionStatus:" + permissionStatus); | |
73 | - if (permissionStatus == 1684369017 || permissionStatus == 1970168948) { | |
74 | - console.log("麦克风权限没有开启"); | |
75 | - } else { | |
76 | - result = 1; | |
77 | - console.log("麦克风权限已经开启"); | |
78 | - } | |
79 | - plus.ios.deleteObject(avaudiosession); | |
80 | - return { | |
81 | - result: result, | |
82 | - permissionName: "麦克风" | |
83 | - }; | |
84 | -} | |
85 | - | |
86 | -// 判断相机权限是否开启 | |
87 | -function judgeIosPermissionCamera() { | |
88 | - var result = 0; | |
89 | - var AVCaptureDevice = plus.ios.import("AVCaptureDevice"); | |
90 | - var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide'); | |
91 | - console.log("authStatus:" + authStatus); | |
92 | - if (authStatus == 3) { | |
93 | - result = 1; | |
94 | - console.log("相机权限已经开启"); | |
95 | - } else { | |
96 | - console.log("相机权限没有开启"); | |
97 | - } | |
98 | - plus.ios.deleteObject(AVCaptureDevice); | |
99 | - return { | |
100 | - result: result, | |
101 | - permissionName: "相机" | |
102 | - }; | |
103 | -} | |
104 | - | |
105 | -// 判断相册权限是否开启 | |
106 | -function judgeIosPermissionPhotoLibrary() { | |
107 | - var result = 0; | |
108 | - var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary"); | |
109 | - var authStatus = PHPhotoLibrary.authorizationStatus(); | |
110 | - console.log("authStatus:" + authStatus); | |
111 | - if (authStatus == 3) { | |
112 | - result = 1; | |
113 | - console.log("相册权限已经开启"); | |
114 | - } else { | |
115 | - console.log("相册权限没有开启"); | |
116 | - } | |
117 | - plus.ios.deleteObject(PHPhotoLibrary); | |
118 | - return { | |
119 | - result: result, | |
120 | - permissionName: "相册" | |
121 | - }; | |
122 | -} | |
123 | - | |
124 | -// 判断通讯录权限是否开启 | |
125 | -function judgeIosPermissionContact() { | |
126 | - var result = 0; | |
127 | - var CNContactStore = plus.ios.import("CNContactStore"); | |
128 | - var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0); | |
129 | - if (cnAuthStatus == 3) { | |
130 | - result = 1; | |
131 | - console.log("通讯录权限已经开启"); | |
132 | - } else { | |
133 | - console.log("通讯录权限没有开启"); | |
134 | - } | |
135 | - plus.ios.deleteObject(CNContactStore); | |
136 | - return { | |
137 | - result: result, | |
138 | - permissionName: "通讯录" | |
139 | - }; | |
140 | -} | |
141 | - | |
142 | -// 判断日历权限是否开启 | |
143 | -function judgeIosPermissionCalendar() { | |
144 | - var result = 0; | |
145 | - var EKEventStore = plus.ios.import("EKEventStore"); | |
146 | - var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0); | |
147 | - if (ekAuthStatus == 3) { | |
148 | - result = 1; | |
149 | - console.log("日历权限已经开启"); | |
150 | - } else { | |
151 | - console.log("日历权限没有开启"); | |
152 | - } | |
153 | - plus.ios.deleteObject(EKEventStore); | |
154 | - return { | |
155 | - result: result, | |
156 | - permissionName: "日历" | |
157 | - }; | |
158 | -} | |
159 | - | |
160 | -// 判断备忘录权限是否开启 | |
161 | -function judgeIosPermissionMemo() { | |
162 | - var result = 0; | |
163 | - var EKEventStore = plus.ios.import("EKEventStore"); | |
164 | - var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1); | |
165 | - if (ekAuthStatus == 3) { | |
166 | - result = 1; | |
167 | - console.log("备忘录权限已经开启"); | |
168 | - } else { | |
169 | - console.log("备忘录权限没有开启"); | |
170 | - } | |
171 | - plus.ios.deleteObject(EKEventStore); | |
172 | - return { | |
173 | - result: result, | |
174 | - permissionName: "备忘录" | |
175 | - }; | |
176 | -} | |
177 | - | |
178 | -// Android权限查询 | |
179 | -function requestAndroidPermission(permissionID, permissionName) { | |
180 | - return new Promise((resolve, reject) => { | |
181 | - plus.android.requestPermissions( | |
182 | - [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装 | |
183 | - function (resultObj) { | |
184 | - var result = 0; | |
185 | - for (var i = 0; i < resultObj.granted.length; i++) { | |
186 | - var grantedPermission = resultObj.granted[i]; | |
187 | - console.log('已获取的权限:' + grantedPermission); | |
188 | - result = 1 | |
189 | - } | |
190 | - for (var i = 0; i < resultObj.deniedPresent.length; i++) { | |
191 | - var deniedPresentPermission = resultObj.deniedPresent[i]; | |
192 | - console.log('拒绝本次申请的权限:' + deniedPresentPermission); | |
193 | - result = 0 | |
194 | - } | |
195 | - for (var i = 0; i < resultObj.deniedAlways.length; i++) { | |
196 | - var deniedAlwaysPermission = resultObj.deniedAlways[i]; | |
197 | - console.log('永久拒绝申请的权限:' + deniedAlwaysPermission); | |
198 | - result = -1 | |
199 | - } | |
200 | - resolve({ | |
201 | - result: result, | |
202 | - permissionName: permissionName | |
203 | - }); | |
204 | - // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限 | |
205 | - // if (result != 1) { | |
206 | - // gotoAppPermissionSetting() | |
207 | - // } | |
208 | - }, | |
209 | - function (error) { | |
210 | - console.log('申请权限错误:' + error.code + " = " + error.message); | |
211 | - resolve({ | |
212 | - code: error.code, | |
213 | - message: error.message | |
214 | - }); | |
215 | - } | |
216 | - ); | |
217 | - }); | |
218 | -} | |
219 | - | |
220 | -// 使用一个方法,根据参数判断权限 | |
221 | -function judgePermission(permissionID, callback) { | |
222 | - function handle(res) { | |
223 | - callback && callback(res.result); | |
224 | - if (res.result === -1) { | |
225 | - uni.showModal({ | |
226 | - title: "提示", | |
227 | - content: "您还未开通" + res.permissionName + "权限,是否去应用设置里开通~", | |
228 | - confirmText: "去开通", | |
229 | - cancelText: "再逛会", | |
230 | - success: (data) => { | |
231 | - if (data.confirm) { | |
232 | - gotoAppPermissionSetting(); | |
233 | - } | |
234 | - } | |
235 | - }); | |
236 | - } | |
237 | - } | |
238 | - if (permissionID == "location") { // 位置 | |
239 | - if (isIos) { | |
240 | - handle(judgeIosPermissionLocation()); | |
241 | - } else { | |
242 | - requestAndroidPermission("android.permission.ACCESS_FINE_LOCATION", "位置").then(handle); | |
243 | - } | |
244 | - } else if (permissionID == "camera") { // 摄像头 | |
245 | - if (isIos) { | |
246 | - handle(judgeIosPermissionCamera()); | |
247 | - } else { | |
248 | - requestAndroidPermission("android.permission.CAMERA", "摄像头").then(handle); | |
249 | - } | |
250 | - } else if (permissionID == "photoLibrary") { // 相册 | |
251 | - if (isIos) { | |
252 | - handle(judgeIosPermissionPhotoLibrary()); | |
253 | - } else { | |
254 | - requestAndroidPermission("android.permission.READ_EXTERNAL_STORAGE", "相册读取").then(handle); | |
255 | - } | |
256 | - } else if (permissionID == "record") { // 麦克风 | |
257 | - if (isIos) { | |
258 | - handle(judgeIosPermissionRecord()); | |
259 | - } else { | |
260 | - requestAndroidPermission("android.permission.RECORD_AUDIO", "麦克风").then(handle); | |
261 | - } | |
262 | - } else if (permissionID == "push") { // 推送 | |
263 | - if (isIos) { | |
264 | - handle(judgeIosPermissionPush()); | |
265 | - } else { | |
266 | - handle(1); | |
267 | - } | |
268 | - } else if (permissionID == "contact") { // 通讯录 | |
269 | - if (isIos) { | |
270 | - handle(judgeIosPermissionContact()); | |
271 | - } else { | |
272 | - requestAndroidPermission("android.permission.READ_CONTACTS", "通讯录读取").then(handle); | |
273 | - } | |
274 | - } else if (permissionID == "calendar") { // 日历 | |
275 | - if (isIos) { | |
276 | - handle(judgeIosPermissionCalendar()); | |
277 | - } else { | |
278 | - requestAndroidPermission("android.permission.READ_CALENDAR", "日历读取").then(handle); | |
279 | - } | |
280 | - } else if (permissionID == "memo") { // 备忘录 | |
281 | - if (isIos) { | |
282 | - handle(judgeIosPermissionMemo()); | |
283 | - } else { | |
284 | - handle(1); | |
285 | - } | |
286 | - } else if (permissionID == "call_phone") { // 拨打电话 | |
287 | - if (isIos) { | |
288 | - handle(1); | |
289 | - } else { | |
290 | - requestAndroidPermission("android.permission.CALL_PHONE", "拨打电话").then(handle); | |
291 | - } | |
292 | - } | |
293 | -} | |
294 | - | |
295 | -// 跳转到**应用**的权限页面 | |
296 | -function gotoAppPermissionSetting() { | |
297 | - if (isIos) { | |
298 | - var UIApplication = plus.ios.import("UIApplication"); | |
299 | - var application2 = UIApplication.sharedApplication(); | |
300 | - var NSURL2 = plus.ios.import("NSURL"); | |
301 | - // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES"); | |
302 | - var setting2 = NSURL2.URLWithString("app-settings:"); | |
303 | - application2.openURL(setting2); | |
304 | - | |
305 | - plus.ios.deleteObject(setting2); | |
306 | - plus.ios.deleteObject(NSURL2); | |
307 | - plus.ios.deleteObject(application2); | |
308 | - } else { | |
309 | - // console.log(plus.device.vendor); | |
310 | - var Intent = plus.android.importClass("android.content.Intent"); | |
311 | - var Settings = plus.android.importClass("android.provider.Settings"); | |
312 | - var Uri = plus.android.importClass("android.net.Uri"); | |
313 | - var mainActivity = plus.android.runtimeMainActivity(); | |
314 | - var intent = new Intent(); | |
315 | - intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |
316 | - var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); | |
317 | - intent.setData(uri); | |
318 | - mainActivity.startActivity(intent); | |
319 | - } | |
320 | -} | |
321 | - | |
322 | -// 检查系统的设备服务是否开启 | |
323 | -// var checkSystemEnableLocation = async function () { | |
324 | -function checkSystemEnableLocation() { | |
325 | - if (isIos) { | |
326 | - var result = false; | |
327 | - var cllocationManger = plus.ios.import("CLLocationManager"); | |
328 | - var result = cllocationManger.locationServicesEnabled(); | |
329 | - console.log("系统定位开启:" + result); | |
330 | - plus.ios.deleteObject(cllocationManger); | |
331 | - return result; | |
332 | - } else { | |
333 | - var context = plus.android.importClass("android.content.Context"); | |
334 | - var locationManager = plus.android.importClass("android.location.LocationManager"); | |
335 | - var main = plus.android.runtimeMainActivity(); | |
336 | - var mainSvr = main.getSystemService(context.LOCATION_SERVICE); | |
337 | - var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); | |
338 | - console.log("系统定位开启:" + result); | |
339 | - return result | |
340 | - } | |
341 | -} | |
342 | - | |
343 | -module.exports = { | |
344 | - judgePermission: judgePermission, | |
345 | - requestAndroidPermission: requestAndroidPermission, | |
346 | - checkSystemEnableLocation: checkSystemEnableLocation, | |
347 | - gotoAppPermissionSetting: gotoAppPermissionSetting | |
348 | -} |
uni_modules/zhouWei-APPUpdate/changelog.md
deleted
100644 → 0
uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate.js
deleted
100644 → 0
1 | -// #ifdef APP-PLUS | |
2 | -import componentConfig from "@/config/componentConfig" | |
3 | -const platform = uni.getSystemInfoSync().platform; | |
4 | -// 主颜色 | |
5 | -const $mainColor = componentConfig.appUpdateColor ? componentConfig.appUpdateColor : "FF5B78"; | |
6 | -// 弹窗图标url | |
7 | -const $iconUrl = componentConfig.appUpdateIcon ? componentConfig.appUpdateIcon : "/uni_modules/zhouWei-APPUpdate/static/ic_ar.png"; | |
8 | - | |
9 | -// 获取当前应用的版本号 | |
10 | -export const getCurrentNo = function(callback) { | |
11 | - // 获取本地应用资源版本号 | |
12 | - plus.runtime.getProperty(plus.runtime.appid, function(inf) { | |
13 | - callback && callback({ | |
14 | - versionCode: inf.versionCode, | |
15 | - versionName: inf.version | |
16 | - }); | |
17 | - }); | |
18 | -} | |
19 | -// 从服务器下载应用资源包(wgt文件) | |
20 | -const getDownload = function(data) { | |
21 | - let dtask; | |
22 | - if(data.updateType == 'forcibly' || data.updateType == 'solicit'){ | |
23 | - let popupData = { | |
24 | - progress: true, | |
25 | - buttonNum: 2 | |
26 | - }; | |
27 | - if(data.updateType == 'forcibly'){ | |
28 | - popupData.buttonNum = 0; | |
29 | - } | |
30 | - let lastProgressValue = 0; | |
31 | - let popupObj = downloadPopup(popupData); | |
32 | - dtask = plus.downloader.createDownload(data.downloadUrl, { | |
33 | - filename: "_doc/update/" | |
34 | - }, function(download, status) { | |
35 | - if (status == 200) { | |
36 | - popupObj.change({ | |
37 | - progressValue: 100, | |
38 | - progressTip:"正在安装文件...", | |
39 | - progress: true, | |
40 | - buttonNum: 0 | |
41 | - }); | |
42 | - plus.runtime.install(download.filename, {}, function() { | |
43 | - popupObj.change({ | |
44 | - contentText: "应用资源更新完成!", | |
45 | - buttonNum: 1, | |
46 | - progress: false | |
47 | - }); | |
48 | - }, function(e) { | |
49 | - popupObj.cancel(); | |
50 | - plus.nativeUI.alert("安装文件失败[" + e.code + "]:" + e.message); | |
51 | - }); | |
52 | - } else { | |
53 | - popupObj.change({ | |
54 | - contentText: "文件下载失败...", | |
55 | - buttonNum: 1, | |
56 | - progress: false | |
57 | - }); | |
58 | - } | |
59 | - }); | |
60 | - dtask.start(); | |
61 | - dtask.addEventListener("statechanged", function(task, status) { | |
62 | - switch (task.state) { | |
63 | - case 1: // 开始 | |
64 | - popupObj.change({ | |
65 | - progressValue:0, | |
66 | - progressTip:"准备下载...", | |
67 | - progress: true | |
68 | - }); | |
69 | - break; | |
70 | - case 2: // 已连接到服务器 | |
71 | - popupObj.change({ | |
72 | - progressValue:0, | |
73 | - progressTip:"开始下载...", | |
74 | - progress: true | |
75 | - }); | |
76 | - break; | |
77 | - case 3: | |
78 | - const progress = parseInt(task.downloadedSize / task.totalSize * 100); | |
79 | - if(progress - lastProgressValue >= 2){ | |
80 | - lastProgressValue = progress; | |
81 | - popupObj.change({ | |
82 | - progressValue:progress, | |
83 | - progressTip: "已下载" + progress + "%", | |
84 | - progress: true | |
85 | - }); | |
86 | - } | |
87 | - break; | |
88 | - } | |
89 | - }); | |
90 | - // 取消下载 | |
91 | - popupObj.cancelDownload = function(){ | |
92 | - dtask && dtask.abort(); | |
93 | - uni.showToast({ | |
94 | - title: "已取消下载", | |
95 | - icon:"none" | |
96 | - }); | |
97 | - } | |
98 | - // 重启APP | |
99 | - popupObj.reboot = function(){ | |
100 | - plus.runtime.restart(); | |
101 | - } | |
102 | - } else if(data.updateType == "silent"){ | |
103 | - dtask = plus.downloader.createDownload(data.downloadUrl, { | |
104 | - filename: "_doc/update/" | |
105 | - }, function(download, status) { | |
106 | - if (status == 200) { | |
107 | - plus.runtime.install(download.filename, {}, function() { | |
108 | - console.log("应用资源更新完成"); | |
109 | - }, function(e) { | |
110 | - plus.nativeUI.alert("安装文件失败[" + e.code + "]:" + e.message); | |
111 | - }); | |
112 | - } else { | |
113 | - plus.nativeUI.alert("文件下载失败..."); | |
114 | - } | |
115 | - }); | |
116 | - dtask.start(); | |
117 | - } | |
118 | -} | |
119 | -// 文字换行 | |
120 | -function drawtext(text, maxWidth) { | |
121 | - let textArr = text.split(""); | |
122 | - let len = textArr.length; | |
123 | - // 上个节点 | |
124 | - let previousNode = 0; | |
125 | - // 记录节点宽度 | |
126 | - let nodeWidth = 0; | |
127 | - // 文本换行数组 | |
128 | - let rowText = []; | |
129 | - // 如果是字母,侧保存长度 | |
130 | - let letterWidth = 0; | |
131 | - // 汉字宽度 | |
132 | - let chineseWidth = 14; | |
133 | - // otherFont宽度 | |
134 | - let otherWidth = 7; | |
135 | - for (let i = 0; i < len; i++) { | |
136 | - if (/[\u4e00-\u9fa5]|[\uFE30-\uFFA0]/g.test(textArr[i])) { | |
137 | - if(letterWidth > 0){ | |
138 | - if(nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth){ | |
139 | - rowText.push({ | |
140 | - type: "text", | |
141 | - content: text.substring(previousNode, i) | |
142 | - }); | |
143 | - previousNode = i; | |
144 | - nodeWidth = chineseWidth; | |
145 | - letterWidth = 0; | |
146 | - } else { | |
147 | - nodeWidth += chineseWidth + letterWidth * otherWidth; | |
148 | - letterWidth = 0; | |
149 | - } | |
150 | - } else { | |
151 | - if(nodeWidth + chineseWidth > maxWidth){ | |
152 | - rowText.push({ | |
153 | - type: "text", | |
154 | - content: text.substring(previousNode, i) | |
155 | - }); | |
156 | - previousNode = i; | |
157 | - nodeWidth = chineseWidth; | |
158 | - }else{ | |
159 | - nodeWidth += chineseWidth; | |
160 | - } | |
161 | - } | |
162 | - } else { | |
163 | - if(/\n/g.test(textArr[i])){ | |
164 | - rowText.push({ | |
165 | - type: "break", | |
166 | - content: text.substring(previousNode, i) | |
167 | - }); | |
168 | - previousNode = i + 1; | |
169 | - nodeWidth = 0; | |
170 | - letterWidth = 0; | |
171 | - }else if(textArr[i] == "\\" && textArr[i + 1] == "n"){ | |
172 | - rowText.push({ | |
173 | - type: "break", | |
174 | - content: text.substring(previousNode, i) | |
175 | - }); | |
176 | - previousNode = i + 2; | |
177 | - nodeWidth = 0; | |
178 | - letterWidth = 0; | |
179 | - }else if(/[a-zA-Z0-9]/g.test(textArr[i])){ | |
180 | - letterWidth += 1; | |
181 | - if(nodeWidth + letterWidth * otherWidth > maxWidth){ | |
182 | - rowText.push({ | |
183 | - type: "text", | |
184 | - content: text.substring(previousNode, i + 1 - letterWidth) | |
185 | - }); | |
186 | - previousNode = i + 1 - letterWidth; | |
187 | - nodeWidth = letterWidth * otherWidth; | |
188 | - letterWidth = 0; | |
189 | - } | |
190 | - } else{ | |
191 | - if(nodeWidth + otherWidth > maxWidth){ | |
192 | - rowText.push({ | |
193 | - type: "text", | |
194 | - content: text.substring(previousNode, i) | |
195 | - }); | |
196 | - previousNode = i; | |
197 | - nodeWidth = otherWidth; | |
198 | - }else{ | |
199 | - nodeWidth += otherWidth; | |
200 | - } | |
201 | - } | |
202 | - } | |
203 | - } | |
204 | - if (previousNode < len) { | |
205 | - rowText.push({ | |
206 | - type: "text", | |
207 | - content: text.substring(previousNode, len) | |
208 | - }); | |
209 | - } | |
210 | - return rowText; | |
211 | -} | |
212 | -// 是否更新弹窗 | |
213 | -function updatePopup(data, callback) { | |
214 | - // 弹窗遮罩层 | |
215 | - let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 | |
216 | - top: '0px', | |
217 | - left: '0px', | |
218 | - height: '100%', | |
219 | - width: '100%', | |
220 | - backgroundColor: 'rgba(0,0,0,0.5)' | |
221 | - }); | |
222 | - | |
223 | - // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 | |
224 | - const screenWidth = plus.screen.resolutionWidth; | |
225 | - const screenHeight = plus.screen.resolutionHeight; | |
226 | - //弹窗容器宽度 | |
227 | - const popupViewWidth = screenWidth * 0.7; | |
228 | - // 弹窗容器的Padding | |
229 | - const viewContentPadding = 20; | |
230 | - // 弹窗容器的宽度 | |
231 | - const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 2)); | |
232 | - // 描述的列表 | |
233 | - const descriptionList = drawtext(data.versionInfo, viewContentWidth); | |
234 | - // 弹窗容器高度 | |
235 | - let popupViewHeight = 80 + 20 + 20 + 90 + 10; | |
236 | - | |
237 | - let popupViewContentList = [{ | |
238 | - src: $iconUrl, | |
239 | - id: "logo", | |
240 | - tag: "img", | |
241 | - position: { | |
242 | - top: "0px", | |
243 | - left: (popupViewWidth - 124) / 2 + "px", | |
244 | - width: "124px", | |
245 | - height: "80px", | |
246 | - } | |
247 | - }, | |
248 | - { | |
249 | - tag: 'font', | |
250 | - id: 'title', | |
251 | - text: "发现新版本" + data.versionName, | |
252 | - textStyles: { | |
253 | - size: '18px', | |
254 | - color: "#333", | |
255 | - weight: "bold", | |
256 | - whiteSpace: "normal" | |
257 | - }, | |
258 | - position: { | |
259 | - top: '90px', | |
260 | - left: viewContentPadding + "px", | |
261 | - width: viewContentWidth + "px", | |
262 | - height: "30px", | |
263 | - } | |
264 | - }]; | |
265 | - const textHeight = 18; | |
266 | - let contentTop = 130; | |
267 | - descriptionList.forEach((item,index) => { | |
268 | - if(index > 0){ | |
269 | - popupViewHeight += textHeight; | |
270 | - contentTop += textHeight; | |
271 | - } | |
272 | - popupViewContentList.push({ | |
273 | - tag: 'font', | |
274 | - id: 'content' + index + 1, | |
275 | - text: item.content, | |
276 | - textStyles: { | |
277 | - size: '14px', | |
278 | - color: "#666", | |
279 | - lineSpacing: "50%", | |
280 | - align: "left" | |
281 | - }, | |
282 | - position: { | |
283 | - top: contentTop + "px", | |
284 | - left: viewContentPadding + "px", | |
285 | - width: viewContentWidth + "px", | |
286 | - height: textHeight + "px", | |
287 | - } | |
288 | - }); | |
289 | - if(item.type == "break"){ | |
290 | - contentTop += 10; | |
291 | - popupViewHeight += 10; | |
292 | - } | |
293 | - }); | |
294 | - | |
295 | - if(data.updateType == "forcibly"){ | |
296 | - popupViewContentList.push({ | |
297 | - tag: 'rect', //绘制底边按钮 | |
298 | - rectStyles:{ | |
299 | - radius: "6px", | |
300 | - color: $mainColor | |
301 | - }, | |
302 | - position:{ | |
303 | - bottom: viewContentPadding + 'px', | |
304 | - left: viewContentPadding + "px", | |
305 | - width: viewContentWidth + "px", | |
306 | - height: "30px" | |
307 | - } | |
308 | - }); | |
309 | - popupViewContentList.push({ | |
310 | - tag: 'font', | |
311 | - id: 'confirmText', | |
312 | - text: "立即升级", | |
313 | - textStyles: { | |
314 | - size: '14px', | |
315 | - color: "#FFF", | |
316 | - lineSpacing: "0%", | |
317 | - }, | |
318 | - position: { | |
319 | - bottom: viewContentPadding + 'px', | |
320 | - left: viewContentPadding + "px", | |
321 | - width: viewContentWidth + "px", | |
322 | - height: "30px" | |
323 | - } | |
324 | - }); | |
325 | - } else { | |
326 | - // 绘制底边按钮 | |
327 | - popupViewContentList.push({ | |
328 | - tag: 'rect', | |
329 | - id: 'cancelBox', | |
330 | - rectStyles: { | |
331 | - radius: "3px", | |
332 | - borderColor: "#f1f1f1", | |
333 | - borderWidth: "1px", | |
334 | - }, | |
335 | - position: { | |
336 | - bottom: viewContentPadding + 'px', | |
337 | - left: viewContentPadding + "px", | |
338 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
339 | - height: "30px", | |
340 | - } | |
341 | - }); | |
342 | - popupViewContentList.push({ | |
343 | - tag: 'rect', | |
344 | - id: 'confirmBox', | |
345 | - rectStyles: { | |
346 | - radius: "3px", | |
347 | - color: $mainColor, | |
348 | - }, | |
349 | - position: { | |
350 | - bottom: viewContentPadding + 'px', | |
351 | - left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", | |
352 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
353 | - height: "30px", | |
354 | - } | |
355 | - }); | |
356 | - popupViewContentList.push({ | |
357 | - tag: 'font', | |
358 | - id: 'cancelText', | |
359 | - text: "暂不升级", | |
360 | - textStyles: { | |
361 | - size: '14px', | |
362 | - color: "#666", | |
363 | - lineSpacing: "0%", | |
364 | - whiteSpace: "normal" | |
365 | - }, | |
366 | - position: { | |
367 | - bottom: viewContentPadding + 'px', | |
368 | - left: viewContentPadding + "px", | |
369 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
370 | - height: "30px", | |
371 | - } | |
372 | - }); | |
373 | - popupViewContentList.push({ | |
374 | - tag: 'font', | |
375 | - id: 'confirmText', | |
376 | - text: "立即升级", | |
377 | - textStyles: { | |
378 | - size: '14px', | |
379 | - color: "#FFF", | |
380 | - lineSpacing: "0%", | |
381 | - whiteSpace: "normal" | |
382 | - }, | |
383 | - position: { | |
384 | - bottom: viewContentPadding + 'px', | |
385 | - left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", | |
386 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
387 | - height: "30px", | |
388 | - } | |
389 | - }); | |
390 | - } | |
391 | - // 弹窗内容 | |
392 | - let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 | |
393 | - tag: "rect", | |
394 | - top: (screenHeight - popupViewHeight) / 2 + "px", | |
395 | - left: '15%', | |
396 | - height: popupViewHeight + "px", | |
397 | - width: "70%" | |
398 | - }); | |
399 | - // 绘制白色背景 | |
400 | - popupView.drawRect({ | |
401 | - color: "#FFFFFF", | |
402 | - radius: "8px" | |
403 | - }, { | |
404 | - top: "40px", | |
405 | - height: popupViewHeight - 40 + "px", | |
406 | - }); | |
407 | - | |
408 | - popupView.draw(popupViewContentList); | |
409 | - popupView.addEventListener("click", function(e) { | |
410 | - let maxTop = popupViewHeight - viewContentPadding; | |
411 | - let maxLeft = popupViewWidth - viewContentPadding; | |
412 | - let buttonWidth = (viewContentWidth - viewContentPadding) / 2; | |
413 | - if (e.clientY > maxTop - 30 && e.clientY < maxTop) { | |
414 | - if(data.updateType == "forcibly"){ | |
415 | - if(e.clientX > viewContentPadding && e.clientX < maxLeft){ | |
416 | - // 立即升级 | |
417 | - maskLayer.hide(); | |
418 | - popupView.hide(); | |
419 | - callback && callback(); | |
420 | - } | |
421 | - } else { | |
422 | - // 暂不升级 | |
423 | - if (e.clientX > viewContentPadding && e.clientX < maxLeft - buttonWidth - viewContentPadding) { | |
424 | - maskLayer.hide(); | |
425 | - popupView.hide(); | |
426 | - } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) { | |
427 | - // 立即升级 | |
428 | - maskLayer.hide(); | |
429 | - popupView.hide(); | |
430 | - callback && callback(); | |
431 | - } | |
432 | - } | |
433 | - | |
434 | - } | |
435 | - }); | |
436 | - if(data.updateType == "solicit"){ | |
437 | - // 点击遮罩层 | |
438 | - maskLayer.addEventListener("click", function() { //处理遮罩层点击 | |
439 | - maskLayer.hide(); | |
440 | - popupView.hide(); | |
441 | - }); | |
442 | - } | |
443 | - // 显示弹窗 | |
444 | - maskLayer.show(); | |
445 | - popupView.show(); | |
446 | -} | |
447 | -// 文件下载的弹窗绘图 | |
448 | -function downloadPopupDrawing(data){ | |
449 | - // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 | |
450 | - const screenWidth = plus.screen.resolutionWidth; | |
451 | - const screenHeight = plus.screen.resolutionHeight; | |
452 | - //弹窗容器宽度 | |
453 | - const popupViewWidth = screenWidth * 0.7; | |
454 | - // 弹窗容器的Padding | |
455 | - const viewContentPadding = 20; | |
456 | - // 弹窗容器的宽度 | |
457 | - const viewContentWidth = popupViewWidth - (viewContentPadding * 2); | |
458 | - // 弹窗容器高度 | |
459 | - let popupViewHeight = viewContentPadding * 3 + 60; | |
460 | - let progressTip = data.progressTip || "准备下载..."; | |
461 | - let contentText = data.contentText || "正在为您更新,请耐心等待"; | |
462 | - let elementList = [ | |
463 | - { | |
464 | - tag: 'rect', //背景色 | |
465 | - color: '#FFFFFF', | |
466 | - rectStyles:{ | |
467 | - radius: "8px" | |
468 | - } | |
469 | - }, | |
470 | - { | |
471 | - tag: 'font', | |
472 | - id: 'title', | |
473 | - text: "升级APP", | |
474 | - textStyles: { | |
475 | - size: '16px', | |
476 | - color: "#333", | |
477 | - weight: "bold", | |
478 | - verticalAlign: "middle", | |
479 | - whiteSpace: "normal" | |
480 | - }, | |
481 | - position: { | |
482 | - top: viewContentPadding + 'px', | |
483 | - height: "30px", | |
484 | - } | |
485 | - }, | |
486 | - { | |
487 | - tag: 'font', | |
488 | - id: 'content', | |
489 | - text: contentText, | |
490 | - textStyles: { | |
491 | - size: '14px', | |
492 | - color: "#333", | |
493 | - verticalAlign: "middle", | |
494 | - whiteSpace: "normal" | |
495 | - }, | |
496 | - position: { | |
497 | - top: viewContentPadding * 2 + 30 + 'px', | |
498 | - height: "20px", | |
499 | - } | |
500 | - } | |
501 | - ]; | |
502 | - // 是否有进度条 | |
503 | - if(data.progress){ | |
504 | - popupViewHeight += viewContentPadding + 40; | |
505 | - elementList = elementList.concat([ | |
506 | - { | |
507 | - tag: 'font', | |
508 | - id: 'progressValue', | |
509 | - text: progressTip, | |
510 | - textStyles: { | |
511 | - size: '14px', | |
512 | - color: $mainColor, | |
513 | - whiteSpace: "normal" | |
514 | - }, | |
515 | - position: { | |
516 | - top: viewContentPadding * 4 + 20 + 'px', | |
517 | - height: "30px" | |
518 | - } | |
519 | - }, | |
520 | - { | |
521 | - tag: 'rect', //绘制进度条背景 | |
522 | - id: 'progressBg', | |
523 | - rectStyles:{ | |
524 | - radius: "4px", | |
525 | - borderColor: "#f1f1f1", | |
526 | - borderWidth: "1px", | |
527 | - }, | |
528 | - position:{ | |
529 | - top: viewContentPadding * 4 + 60 + 'px', | |
530 | - left: viewContentPadding + "px", | |
531 | - width: viewContentWidth + "px", | |
532 | - height: "8px" | |
533 | - } | |
534 | - }, | |
535 | - ]); | |
536 | - } | |
537 | - if (data.buttonNum == 2) { | |
538 | - popupViewHeight += viewContentPadding + 30; | |
539 | - elementList = elementList.concat([ | |
540 | - { | |
541 | - tag: 'rect', //绘制底边按钮 | |
542 | - rectStyles:{ | |
543 | - radius: "3px", | |
544 | - borderColor: "#f1f1f1", | |
545 | - borderWidth: "1px", | |
546 | - }, | |
547 | - position:{ | |
548 | - bottom: viewContentPadding + 'px', | |
549 | - left: viewContentPadding + "px", | |
550 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
551 | - height: "30px" | |
552 | - } | |
553 | - }, | |
554 | - { | |
555 | - tag: 'rect', //绘制底边按钮 | |
556 | - rectStyles:{ | |
557 | - radius: "3px", | |
558 | - color: $mainColor | |
559 | - }, | |
560 | - position:{ | |
561 | - bottom: viewContentPadding + 'px', | |
562 | - left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", | |
563 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
564 | - height: "30px" | |
565 | - } | |
566 | - }, | |
567 | - { | |
568 | - tag: 'font', | |
569 | - id: 'cancelText', | |
570 | - text: "取消下载", | |
571 | - textStyles: { | |
572 | - size: '14px', | |
573 | - color: "#666", | |
574 | - lineSpacing: "0%", | |
575 | - whiteSpace: "normal" | |
576 | - }, | |
577 | - position: { | |
578 | - bottom: viewContentPadding + 'px', | |
579 | - left: viewContentPadding + "px", | |
580 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
581 | - height: "30px", | |
582 | - } | |
583 | - }, | |
584 | - { | |
585 | - tag: 'font', | |
586 | - id: 'confirmText', | |
587 | - text: "后台下载", | |
588 | - textStyles: { | |
589 | - size: '14px', | |
590 | - color: "#FFF", | |
591 | - lineSpacing: "0%", | |
592 | - whiteSpace: "normal" | |
593 | - }, | |
594 | - position: { | |
595 | - bottom: viewContentPadding + 'px', | |
596 | - left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", | |
597 | - width: (viewContentWidth - viewContentPadding) / 2 + "px", | |
598 | - height: "30px", | |
599 | - } | |
600 | - } | |
601 | - ]); | |
602 | - } | |
603 | - if (data.buttonNum == 1) { | |
604 | - popupViewHeight += viewContentPadding + 40; | |
605 | - elementList = elementList.concat([ | |
606 | - { | |
607 | - tag: 'rect', //绘制底边按钮 | |
608 | - rectStyles:{ | |
609 | - radius: "6px", | |
610 | - color: $mainColor | |
611 | - }, | |
612 | - position:{ | |
613 | - bottom: viewContentPadding + 'px', | |
614 | - left: viewContentPadding + "px", | |
615 | - width: viewContentWidth + "px", | |
616 | - height: "40px" | |
617 | - } | |
618 | - }, | |
619 | - { | |
620 | - tag: 'font', | |
621 | - id: 'confirmText', | |
622 | - text: "关闭", | |
623 | - textStyles: { | |
624 | - size: '14px', | |
625 | - color: "#FFF", | |
626 | - lineSpacing: "0%", | |
627 | - }, | |
628 | - position: { | |
629 | - bottom: viewContentPadding + 'px', | |
630 | - left: viewContentPadding + "px", | |
631 | - width: viewContentWidth + "px", | |
632 | - height: "40px" | |
633 | - } | |
634 | - } | |
635 | - ]); | |
636 | - } | |
637 | - return { | |
638 | - popupViewHeight:popupViewHeight, | |
639 | - popupViewWidth:popupViewWidth, | |
640 | - screenHeight:screenHeight, | |
641 | - viewContentWidth:viewContentWidth, | |
642 | - viewContentPadding:viewContentPadding, | |
643 | - elementList: elementList | |
644 | - }; | |
645 | -} | |
646 | -// 文件下载的弹窗 | |
647 | -function downloadPopup(data) { | |
648 | - // 弹窗遮罩层 | |
649 | - let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 | |
650 | - top: '0px', | |
651 | - left: '0px', | |
652 | - height: '100%', | |
653 | - width: '100%', | |
654 | - backgroundColor: 'rgba(0,0,0,0.5)' | |
655 | - }); | |
656 | - let popupViewData = downloadPopupDrawing(data); | |
657 | - // 弹窗内容 | |
658 | - let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 | |
659 | - tag: "rect", | |
660 | - top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", | |
661 | - left: '15%', | |
662 | - height: popupViewData.popupViewHeight + "px", | |
663 | - width: "70%", | |
664 | - }); | |
665 | - let progressValue = 0; | |
666 | - let progressTip = 0; | |
667 | - let contentText = 0; | |
668 | - let buttonNum = 2; | |
669 | - if(data.buttonNum >= 0){ | |
670 | - buttonNum = data.buttonNum; | |
671 | - } | |
672 | - popupView.draw(popupViewData.elementList); | |
673 | - let callbackData = { | |
674 | - change: function(res) { | |
675 | - let progressElement = []; | |
676 | - if(res.progressValue){ | |
677 | - progressValue = res.progressValue; | |
678 | - // 绘制进度条 | |
679 | - progressElement.push({ | |
680 | - tag: 'rect', //绘制进度条背景 | |
681 | - id: 'progressValueBg', | |
682 | - rectStyles:{ | |
683 | - radius: "4px", | |
684 | - color: $mainColor | |
685 | - }, | |
686 | - position:{ | |
687 | - top: popupViewData.viewContentPadding * 4 + 60 + 'px', | |
688 | - left: popupViewData.viewContentPadding + "px", | |
689 | - width: popupViewData.viewContentWidth * (res.progressValue / 100) + "px", | |
690 | - height: "8px" | |
691 | - } | |
692 | - }); | |
693 | - } | |
694 | - if(res.progressTip){ | |
695 | - progressTip = res.progressTip; | |
696 | - progressElement.push({ | |
697 | - tag: 'font', | |
698 | - id: 'progressValue', | |
699 | - text: res.progressTip, | |
700 | - textStyles: { | |
701 | - size: '14px', | |
702 | - color: $mainColor, | |
703 | - whiteSpace: "normal" | |
704 | - }, | |
705 | - position: { | |
706 | - top: popupViewData.viewContentPadding * 4 + 20 + 'px', | |
707 | - height: "30px" | |
708 | - } | |
709 | - }); | |
710 | - } | |
711 | - if(res.contentText){ | |
712 | - contentText = res.contentText; | |
713 | - progressElement.push({ | |
714 | - tag: 'font', | |
715 | - id: 'content', | |
716 | - text: res.contentText, | |
717 | - textStyles: { | |
718 | - size: '16px', | |
719 | - color: "#333", | |
720 | - whiteSpace: "normal" | |
721 | - }, | |
722 | - position: { | |
723 | - top: popupViewData.viewContentPadding * 2 + 30 + 'px', | |
724 | - height: "30px", | |
725 | - } | |
726 | - }); | |
727 | - } | |
728 | - if(res.buttonNum >= 0 && buttonNum != res.buttonNum){ | |
729 | - buttonNum = res.buttonNum; | |
730 | - popupView.reset(); | |
731 | - popupViewData = downloadPopupDrawing(Object.assign({ | |
732 | - progressValue:progressValue, | |
733 | - progressTip:progressTip, | |
734 | - contentText:contentText, | |
735 | - },res)); | |
736 | - let newElement = []; | |
737 | - popupViewData.elementList.map((item,index) => { | |
738 | - let have = false; | |
739 | - progressElement.forEach((childItem,childIndex) => { | |
740 | - if(item.id == childItem.id){ | |
741 | - have = true; | |
742 | - } | |
743 | - }); | |
744 | - if(!have){ | |
745 | - newElement.push(item); | |
746 | - } | |
747 | - }); | |
748 | - progressElement = newElement.concat(progressElement); | |
749 | - popupView.setStyle({ | |
750 | - tag: "rect", | |
751 | - top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", | |
752 | - left: '15%', | |
753 | - height: popupViewData.popupViewHeight + "px", | |
754 | - width: "70%", | |
755 | - }); | |
756 | - popupView.draw(progressElement); | |
757 | - }else{ | |
758 | - popupView.draw(progressElement); | |
759 | - } | |
760 | - }, | |
761 | - cancel: function() { | |
762 | - maskLayer.hide(); | |
763 | - popupView.hide(); | |
764 | - } | |
765 | - } | |
766 | - popupView.addEventListener("click", function(e) { | |
767 | - let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding; | |
768 | - let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding; | |
769 | - if (e.clientY > maxTop - 40 && e.clientY < maxTop) { | |
770 | - if(buttonNum == 1){ | |
771 | - // 单按钮 | |
772 | - if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) { | |
773 | - maskLayer.hide(); | |
774 | - popupView.hide(); | |
775 | - callbackData.reboot(); | |
776 | - } | |
777 | - }else if(buttonNum == 2){ | |
778 | - // 双按钮 | |
779 | - let buttonWidth = (popupViewData.viewContentWidth - popupViewData.viewContentPadding) / 2; | |
780 | - if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft - buttonWidth - popupViewData.viewContentPadding) { | |
781 | - maskLayer.hide(); | |
782 | - popupView.hide(); | |
783 | - callbackData.cancelDownload(); | |
784 | - } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) { | |
785 | - maskLayer.hide(); | |
786 | - popupView.hide(); | |
787 | - } | |
788 | - } | |
789 | - } | |
790 | - }); | |
791 | - // 显示弹窗 | |
792 | - maskLayer.show(); | |
793 | - popupView.show(); | |
794 | - // 改变进度条 | |
795 | - return callbackData; | |
796 | -} | |
797 | -export default function(isPrompt = false) { | |
798 | - getCurrentNo(versionInfo => { | |
799 | - componentConfig.getServerNo(versionInfo, isPrompt, res => { | |
800 | - if (res.updateType == "forcibly" || res.updateType == "silent") { | |
801 | - if (/\.wgt$/i.test(res.downloadUrl)) { | |
802 | - getDownload(res); | |
803 | - } else if(/\.html$/i.test(res.downloadUrl)){ | |
804 | - plus.runtime.openURL(res.downloadUrl); | |
805 | - } else { | |
806 | - if (platform == "android") { | |
807 | - getDownload(res); | |
808 | - } else { | |
809 | - plus.runtime.openURL(res.downloadUrl); | |
810 | - } | |
811 | - } | |
812 | - } else if(res.updateType == "solicit"){ | |
813 | - updatePopup(res, function() { | |
814 | - if (/\.wgt$/i.test(res.downloadUrl)) { | |
815 | - getDownload(res); | |
816 | - } else if(/\.html$/i.test(res.downloadUrl)){ | |
817 | - plus.runtime.openURL(res.downloadUrl); | |
818 | - } else { | |
819 | - if (platform == "android") { | |
820 | - getDownload(res); | |
821 | - } else { | |
822 | - plus.runtime.openURL(res.downloadUrl); | |
823 | - } | |
824 | - } | |
825 | - }); | |
826 | - } | |
827 | - }); | |
828 | - }); | |
829 | -} | |
830 | -// #endif | |
\ No newline at end of file |
uni_modules/zhouWei-APPUpdate/package.json
deleted
100644 → 0
1 | -{ | |
2 | - "id": "zhouWei-APPUpdate", | |
3 | - "displayName": "APP版本更新、强制更新、静默更新、下载进度(wgt更新)", | |
4 | - "version": "3.0.1", | |
5 | - "description": "APP版本更新、强制更新、静默更新、漂亮弹窗、下载进度(wgt更新)", | |
6 | - "keywords": [ | |
7 | - "APP版本更新", | |
8 | - "强制更新", | |
9 | - "版本更新", | |
10 | - "静默更新" | |
11 | -], | |
12 | - "repository": "https://github.com/zhouwei1994/uni-app-demo", | |
13 | - "engines": { | |
14 | - "HBuilderX": "^3.1.0" | |
15 | - }, | |
16 | - "dcloudext": { | |
17 | - "category": [ | |
18 | - "JS SDK", | |
19 | - "通用 SDK" | |
20 | - ], | |
21 | - "sale": { | |
22 | - "regular": { | |
23 | - "price": "0.00" | |
24 | - }, | |
25 | - "sourcecode": { | |
26 | - "price": "0.00" | |
27 | - } | |
28 | - }, | |
29 | - "contact": { | |
30 | - "qq": "465081029" | |
31 | - }, | |
32 | - "declaration": { | |
33 | - "ads": "无", | |
34 | - "data": "无", | |
35 | - "permissions": "<uses-permission android:name=\\\"android.permission.INSTALL_PACKAGES\\\"/> \n<uses-permission android:name=\\\"android.permission.REQUEST_INSTALL_PACKAGES\\\"/>" | |
36 | - }, | |
37 | - "npmurl": "" | |
38 | - }, | |
39 | - "uni_modules": { | |
40 | - "dependencies": [], | |
41 | - "encrypt": [], | |
42 | - "platforms": { | |
43 | - "cloud": { | |
44 | - "tcb": "y", | |
45 | - "aliyun": "y" | |
46 | - }, | |
47 | - "client": { | |
48 | - "App": { | |
49 | - "app-vue": "y", | |
50 | - "app-nvue": "y" | |
51 | - }, | |
52 | - "H5-mobile": { | |
53 | - "Safari": "n", | |
54 | - "Android Browser": "n", | |
55 | - "微信浏览器(Android)": "n", | |
56 | - "QQ浏览器(Android)": "n" | |
57 | - }, | |
58 | - "H5-pc": { | |
59 | - "Chrome": "n", | |
60 | - "IE": "n", | |
61 | - "Edge": "n", | |
62 | - "Firefox": "n", | |
63 | - "Safari": "n" | |
64 | - }, | |
65 | - "小程序": { | |
66 | - "微信": "n", | |
67 | - "阿里": "n", | |
68 | - "百度": "n", | |
69 | - "字节跳动": "n", | |
70 | - "QQ": "n" | |
71 | - }, | |
72 | - "快应用": { | |
73 | - "华为": "n", | |
74 | - "联盟": "n" | |
75 | - } | |
76 | - } | |
77 | - } | |
78 | - } | |
79 | -} | |
\ No newline at end of file |
uni_modules/zhouWei-APPUpdate/readme.md
deleted
100644 → 0
1 | -### 常见问题 | |
2 | -1.安卓apk下载完成后没有更新APP? | |
3 | - | |
4 | -答:问题是因为没有添加APP安装应用的权限,解决方法在`manifest.json`文件里面`APP模块权限配置`的`Android打包权限配置`勾选以下权限 | |
5 | -``` | |
6 | -<uses-permission android:name=\"android.permission.INSTALL_PACKAGES\"/> | |
7 | -<uses-permission android:name=\"android.permission.REQUEST_INSTALL_PACKAGES\"/> | |
8 | -``` | |
9 | -若还有问题请看[安装apk无法执行的解决方案](https://ask.dcloud.net.cn/article/35703 "安装apk无法执行的解决方案") | |
10 | - | |
11 | -2.APP更新后版本号没变,还是之前的版本号? | |
12 | - | |
13 | -答:可能是更新的安装包没有升级版本号,`manifest.json`文件里面基本设置`应用版本号`和`应用版本名称`需要升高(保持一直减少问题) | |
14 | - | |
15 | -3.APP更新后没有覆盖之前的APP? | |
16 | - | |
17 | -答:可能是更新的安装包`包名`和APP的`包名`不一样 | |
18 | - | |
19 | -4.弹窗的图标不显示? | |
20 | - | |
21 | -答:检查图片是不是放项目资源文件`static`,然后重新运行项目 | |
22 | - | |
23 | -5.版本号是在前端对比还是在后端接口对比? | |
24 | - | |
25 | -答:当前案例是本地的版本号通过接口传递给后台,是后台对比的,若需要前端对比,请在接口返回数据的地方修改,不更新就不要调用`callback`方法 | |
26 | - | |
27 | -6.本地的版本号比接口的版本号高还弹窗升级窗口? | |
28 | - | |
29 | -答:当前案例是本地的版本号通过接口传递给后台,后台对比是否需要升级,不需要升级就不要返回数据(特别是需要wgt更新的,建议这种方式) | |
30 | - | |
31 | -### 第一步`关键`配置APP更新接口(可以参考上面的示例) | |
32 | -在项目目录下`config/componentConfig.js`里面如下配置 | |
33 | -``` | |
34 | -// 此方法是接口请求方法 | |
35 | -import $http from '@/config/requestConfig' | |
36 | -export default { | |
37 | - // 发起ajax请求获取服务端版本号 | |
38 | - getServerNo: (version, isPrompt = false, callback) => { | |
39 | - let httpData = { | |
40 | - version: version.versionCode, | |
41 | - // 版本名称 | |
42 | - versionName: version.versionName, | |
43 | - // setupPage参数说明(判断用户是不是从设置页面点击的更新,如果是设置页面点击的更新,有不要用静默更新了,不然用户点击没反应很奇怪的) | |
44 | - setupPage: isPrompt | |
45 | - }; | |
46 | - if (platform == "android") { | |
47 | - httpData.type = 1101; | |
48 | - } else { | |
49 | - httpData.type = 1102; | |
50 | - } | |
51 | - /* 接口入参说明 | |
52 | - * version: 应用当前版本号(已自动获取) | |
53 | - * versionName: 应用当前版本名称(已自动获取) | |
54 | - * type:平台(1101是安卓,1102是IOS) | |
55 | - */ | |
56 | - /****************以下是示例*******************/ | |
57 | - // 可以用自己项目的请求方法(接口自己找后台要,插件不提供) | |
58 | - $http.get("api/common/v1/app_version", httpData,{ | |
59 | - isPrompt: isPrompt | |
60 | - }).then(res => { | |
61 | - /* res的数据说明 | |
62 | - * | 参数名称 | 一定返回 | 类型 | 描述 | |
63 | - * | -------------|--------- | --------- | ------------- | | |
64 | - * | versionCode | y | int | 版本号 | | |
65 | - * | versionName | y | String | 版本名称 | | |
66 | - * | versionInfo | y | String | 版本信息 | | |
67 | - * | updateType | y | String | forcibly = 强制更新, solicit = 弹窗确认更新, silent = 静默更新 | | |
68 | - * | downloadUrl | y | String | 版本下载链接(IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接) | | |
69 | - */ | |
70 | - if (res && res.downloadUrl) { | |
71 | - // 兼容之前的版本(updateType是新版才有的参数) | |
72 | - if(res.updateType){ | |
73 | - callback && callback(res); | |
74 | - } else { | |
75 | - if(res.forceUpdate){ | |
76 | - res.updateType = "forcibly"; | |
77 | - } else { | |
78 | - res.updateType = "solicit"; | |
79 | - } | |
80 | - callback && callback(res); | |
81 | - } | |
82 | - } else if (isPrompt) { | |
83 | - uni.showToast({ | |
84 | - title: "暂无新版本", | |
85 | - icon: "none" | |
86 | - }); | |
87 | - } | |
88 | - }); | |
89 | - /****************以上是示例*******************/ | |
90 | - }, | |
91 | - // 弹窗主颜色(不填默认粉色) | |
92 | - appUpdateColor: "f00", | |
93 | - // 弹窗图标(不填显示默认图标,链接配置示例如: '/static/demo/ic_attention.png') | |
94 | - appUpdateIcon: '' | |
95 | -} | |
96 | -``` | |
97 | - | |
98 | -### 第二步 使用方法 | |
99 | -``` | |
100 | -// App.vue页面 | |
101 | - | |
102 | -// #ifdef APP-PLUS | |
103 | -import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate'; | |
104 | -// #endif | |
105 | - | |
106 | -onLaunch: function(e) { | |
107 | - // #ifdef APP-PLUS | |
108 | - APPUpdate(); | |
109 | - // #endif | |
110 | -} | |
111 | -``` | |
112 | - | |
113 | -### 第三步 添加APP安装应用的权限 | |
114 | -在`manifest.json`文件里面`APP模块权限配置`的`Android打包权限配置`勾选以下权限 | |
115 | -``` | |
116 | -<uses-permission android:name=\"android.permission.INSTALL_PACKAGES\"/> | |
117 | -<uses-permission android:name=\"android.permission.REQUEST_INSTALL_PACKAGES\"/> | |
118 | -``` | |
119 | - | |
120 | -### 修改弹窗的主题色或弹窗图标 | |
121 | -在`APPUpdate/index.js`里面上面`$mainColor`常量中定义主题颜色,`$iconUrl`常量中定义图标地址 | |
122 | - | |
123 | -### 检查APP是否有新版本(一般在设置页面使用) | |
124 | -``` | |
125 | -// #ifdef APP-PLUS | |
126 | -import APPUpdate, { getCurrentNo } from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate'; | |
127 | -// #endif | |
128 | -export default { | |
129 | - data() { | |
130 | - return { | |
131 | - version: "" // 版本号 | |
132 | - }; | |
133 | - }, | |
134 | - //第一次加载 | |
135 | - onLoad(e) { | |
136 | - // #ifdef APP-PLUS | |
137 | - getCurrentNo(res => { | |
138 | - // 进页面获取当前APP版本号(用于页面显示) | |
139 | - this.version = res.version; | |
140 | - }); | |
141 | - // #endif | |
142 | - }, | |
143 | - //方法 | |
144 | - methods: { | |
145 | - // 检查APP是否有新版本 | |
146 | - onAPPUpdate() { | |
147 | - // true 没有新版本的时候有提示,默认:false | |
148 | - APPUpdate(true); | |
149 | - } | |
150 | - } | |
151 | -} | |
152 | -``` | |
\ No newline at end of file |
uni_modules/zhouWei-APPUpdate/static/ic_ar.png
deleted
100644 → 0
30.7 KB