@10yun/cv-mobile-ui 0.5.24 → 0.5.27

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/plugins/lbs.js DELETED
@@ -1,300 +0,0 @@
1
- /**
2
- * 地图 web服务 API
3
- */
4
-
5
- class LbsClass {
6
- /* 实例化类时默认会执行构造函数 */
7
- constructor(options = {}) {
8
- this._KEY_ = options.key || '';
9
- this._TYPE_ = options.type || '';
10
- if (!this._KEY_) {
11
- console.error('请先设置Key');
12
- }
13
- }
14
- setType(newOpt) {
15
- this._TYPE_ = newOpt || '';
16
- }
17
- setKey() {
18
- this._KEY_ = newOpt || '';
19
- }
20
- getConfig() {
21
- return {
22
- _KEY_: this._KEY_,
23
- _TYPE_: this._TYPE_
24
- };
25
- }
26
- /**
27
- * 获取路线规划方案
28
- *
29
- * @param {Object},type
30
- * @return {Object}
31
- * 腾讯地图路线规划坐标整理后字段res.data.result.routes[].coors
32
- * 高德地图路线规划坐标整理后字段res.data.data.paths[].polyline
33
- * 后续可统一数据结构
34
- */
35
- getRoutes(param, type = 'driving') {
36
- return new Promise((resolve, reject) => {
37
- if (!this._KEY_) {
38
- reject('请先设置Key');
39
- console.error('请先设置Key');
40
- return false;
41
- }
42
- if (this._TYPE_ == 'qq' || this._TYPE_ == '') {
43
- let formData = Object.assign(
44
- {
45
- output: 'json',
46
- key: this._KEY_,
47
- policy: 'REAL_TRAFFIC'
48
- },
49
- param
50
- );
51
- formData.from = formData.origin.split(',')[1] + ',' + formData.origin.split(',')[0];
52
- formData.to = formData.destination.split(',')[1] + ',' + formData.destination.split(',')[0];
53
- uni.request({
54
- url: '/tx_apis_map' + '/ws/direction/v1/' + type + '/',
55
- header: {
56
- 'Content-Type': 'application/x-www-form-urlencoded',
57
- 'token-type': '0'
58
- },
59
- data: formData,
60
- success: (res) => {
61
- if (res.data.status !== 0) {
62
- reject(res);
63
- console.error('路线规划失败', res.data.message);
64
- }
65
- //所有路线方案
66
-
67
- let routes = res.data.result.routes;
68
- for (const key in routes) {
69
- let polyline = routes[key].polyline;
70
- var coors = [...polyline];
71
- for (var i = 2; i < coors.length; i++) {
72
- coors[i] = coors[i - 2] + coors[i] / 1000000;
73
- }
74
- let temp = '';
75
- for (let i = 0; i < coors.length; i += 2) {
76
- temp += coors[i + 1] + ',' + coors[i] + ';';
77
- }
78
- routes[key].coors = temp;
79
- }
80
- res.data.result.routes = routes;
81
- resolve(res.data);
82
- },
83
- fail: (error) => {
84
- console.error(error);
85
- reject(error);
86
- }
87
- });
88
- } else if (this._TYPE_ == 'amap') {
89
- /* 高德地图 */
90
- let formData = Object.assign(
91
- {
92
- output: 'JSON',
93
- key: this._KEY_
94
- },
95
- param
96
- );
97
- uni.request({
98
- url: '/amap_restapi_map' + '/v4/direction/' + type,
99
- header: {
100
- 'Content-Type': 'application/x-www-form-urlencoded',
101
- 'token-type': '0'
102
- },
103
- data: formData,
104
- success: (res) => {
105
- if (res.data.errcode !== 0) {
106
- reject(res);
107
- console.error('路线规划失败', res.data.message);
108
- }
109
- //所有路线方案
110
- let paths = res.data.data.paths;
111
- for (const key in paths) {
112
- const steps = [...paths[key].steps];
113
- let polyline = '';
114
- for (const k in steps) {
115
- polyline += steps[k].polyline + ';';
116
- }
117
- paths[key].polyline = polyline;
118
- }
119
- res.data.data.paths = paths;
120
- resolve(res.data);
121
- },
122
- fail: (error) => {
123
- console.error(error);
124
- reject(error);
125
- }
126
- });
127
- }
128
- });
129
- }
130
- /**
131
- * 根据用户ip地址获取当前市级位置
132
- *
133
- * @return {Object}
134
- */
135
- getLocation = (ip = '') => {
136
- const _self = this;
137
- return new Promise((resolve, reject) => {
138
- if (!_self._KEY_) {
139
- reject('请先设置Key');
140
- console.error('请先设置Key');
141
- return false;
142
- }
143
- var formData = {};
144
- if (ip) {
145
- formData.ip = ip;
146
- }
147
- formData.key = _self._KEY_;
148
-
149
- if (_self._TYPE_ == 'qq') {
150
- formData.output = 'json';
151
- uni.request({
152
- url: '/tx_apis_map' + '/ws/location/v1/ip/',
153
- header: {
154
- 'Content-Type': 'application/x-www-form-urlencoded',
155
- 'token-type': '0'
156
- },
157
- data: formData,
158
- success: (res) => {
159
- if (res.data.status !== 0) {
160
- reject(res);
161
- console.error('定位失败', res.data.message);
162
- }
163
- for (const key in res.data.result.ad_info) {
164
- res.data[key] = res.data.result.ad_info[key];
165
- }
166
- res.data.location = {
167
- longitude: res.data.result.location.lng,
168
- latitude: res.data.result.location.lat
169
- };
170
- resolve(res.data);
171
- },
172
- fail: (error) => {
173
- console.error(error);
174
- reject(error);
175
- }
176
- });
177
- } else if (_self._TYPE_ == 'amap') {
178
- formData.output = 'JSON';
179
- /* 高德地图 */
180
- uni.request({
181
- url: '/amap_restapi_map' + '/v3/ip',
182
- header: {
183
- 'Content-Type': 'application/x-www-form-urlencoded',
184
- 'token-type': '0'
185
- },
186
- data: formData,
187
- success: (res) => {
188
- if (res.data.status != 1) {
189
- reject(res);
190
- console.error('定位失败', res.data);
191
- }
192
- //计算城市中心点
193
- let rectangles = res.data.rectangle.split(';');
194
- let zx = rectangles[0].split(','),
195
- ys = rectangles[1].split(',');
196
- let longitude_dif = ys[0] * 100000000 - zx[0] * 100000000,
197
- latitude = ys[1] * 100000000 - zx[1] * 100000000;
198
- res.data.location = {
199
- longitude: (ys[0] * 100000000 - longitude_dif / 2) / 100000000,
200
- latitude: (ys[1] * 100000000 - latitude / 2) / 100000000
201
- };
202
- resolve(res.data);
203
- },
204
- fail: (error) => {
205
- console.error(error);
206
- reject(error);
207
- }
208
- });
209
- } else {
210
- uni.getLocation({
211
- type: 'gcj02',
212
- success: (res) => {
213
- res.location = {
214
- longitude: res.longitude,
215
- latitude: res.latitude
216
- };
217
- resolve(res);
218
- },
219
- fail: (error) => {
220
- console.error(error);
221
- reject(error);
222
- }
223
- });
224
- }
225
- });
226
- };
227
- /**
228
- * 获取全部行政区划数据。该请求为GET请求。
229
- *
230
- * @return {Object}
231
- */
232
- getDistrict = (keyword = '') => {
233
- return new Promise((resolve, reject) => {
234
- if (!this._KEY_) {
235
- reject('请先设置Key');
236
- console.error('请先设置Key');
237
- return false;
238
- }
239
- if (this._TYPE_ == 'qq' || this._TYPE_ == '') {
240
- uni.request({
241
- url: '/tx_apis_map' + '/ws/district/v1/search',
242
- header: {
243
- 'Content-Type': 'application/x-www-form-urlencoded',
244
- 'token-type': '0'
245
- },
246
- data: {
247
- keyword: keyword,
248
- key: this._KEY_,
249
- output: 'json'
250
- },
251
- success: (res) => {
252
- if (res.data.status !== 0) {
253
- reject(res);
254
- console.error('获取行政区失败', res.data.message);
255
- }
256
- resolve(res.data);
257
- },
258
- fail: (error) => {
259
- console.error(error);
260
- reject(error);
261
- }
262
- });
263
- } else if (this._TYPE_ == 'amap') {
264
- /* 高德地图 */
265
- uni.request({
266
- url: '/amap_restapi_map' + '/v3/config/district',
267
- header: {
268
- 'Content-Type': 'application/x-www-form-urlencoded',
269
- 'token-type': '0'
270
- },
271
- data: {
272
- keywords: keyword,
273
- key: this._KEY_,
274
- output: 'JSON'
275
- },
276
- success: (res) => {
277
- if (res.data.status != 1) {
278
- reject(res);
279
- console.error('获取行政区失败', res.data);
280
- }
281
- resolve(res.data);
282
- },
283
- fail: (error) => {
284
- console.error(error);
285
- reject(error);
286
- }
287
- });
288
- }
289
- });
290
- };
291
- }
292
-
293
- export function useBindPlugin(bindInstance, options) {
294
- const LbsObj = new LbsClass(options);
295
-
296
- bindInstance.cv__lbsGetLocation = LbsObj.getLocation;
297
-
298
- uni.cv__lbsGetLocation = LbsObj.getLocation;
299
- }
300
- export default LbsClass;
@@ -1,46 +0,0 @@
1
- export default function uniCopy({ content, success, error }) {
2
- console.log(content);
3
- content = typeof content === 'string' ? content : content.toString(); // 复制内容,必须字符串,数字需要转换为字符串
4
-
5
- /**
6
- * 小程序端 和 app端的复制逻辑
7
- */
8
- //#ifndef H5
9
- uni.setClipboardData({
10
- data: content,
11
- success: function () {
12
- success('复制成功~');
13
- console.log('success');
14
- },
15
- fail: function () {
16
- success('复制失败~');
17
- }
18
- });
19
- //#endif
20
-
21
- /**
22
- * H5端的复制逻辑
23
- */
24
- // #ifdef H5
25
- if (!document.queryCommandSupported('copy')) {
26
- //为了兼容有些浏览器 queryCommandSupported 的判断
27
- // 不支持
28
- error('浏览器不支持');
29
- }
30
- let textarea = document.createElement('textarea');
31
- textarea.value = content;
32
- textarea.readOnly = 'readOnly';
33
- document.body.appendChild(textarea);
34
- textarea.select(); // 选择对象
35
- textarea.setSelectionRange(0, content.length); //核心
36
- let result = document.execCommand('copy'); // 执行浏览器复制命令
37
- if (result) {
38
- success('复制成功~');
39
- } else {
40
- error(
41
- '复制失败,请检查h5中调用该方法的方式,是不是用户点击的方式调用的,如果不是请改为用户点击的方式触发该方法,因为h5中安全性,不能js直接调用!'
42
- );
43
- }
44
- textarea.remove();
45
- // #endif
46
- }
@@ -1,12 +0,0 @@
1
- let fun_arr = ['requestApi', '$reqUploadImg', 'nvue_func'];
2
- for (let i in fun_arr) {
3
- let key = fun_arr[i];
4
- uni.$on(key, (res) => {
5
- if (!res) res = [];
6
- if (typeof res != 'object') {
7
- console.log('uni.$emit失败!res需为空或数组');
8
- return;
9
- }
10
- this[key](...res);
11
- });
12
- }
@@ -1,90 +0,0 @@
1
- uni.request({
2
- url: 'http://2132', //请求更新地址
3
- data: '',
4
- success(res) {
5
- if (!!res.data) {
6
- uni.showModal({
7
- title: '版本更新' + res.data.versionCode,
8
- content: res.data.description,
9
- confirmText: '更新',
10
- showCancel: !res.forceUpdate,
11
- success: function (e) {
12
- if (e.confirm) {
13
- if (plus.os.name.toLowerCase() == 'ios') {
14
- // 跳转到下载页面
15
- plus.runtime.openURL(res.data.upgradeUrl);
16
- } else {
17
- var dtask = plus.downloader.createDownload(res.data.upgradeUrl, {}, function (d, status) {
18
- uni.showToast({
19
- title: '下载完成',
20
- mask: false,
21
- duration: 1000
22
- });
23
- // 下载完成
24
- if (status == 200) {
25
- plus.runtime.install(
26
- plus.io.convertLocalFileSystemURL(d.filename),
27
- {},
28
- (e) => e,
29
- function (error) {
30
- uni.showToast({
31
- title: '安装失败-01',
32
- mask: false,
33
- duration: 1500
34
- });
35
- }
36
- );
37
- } else {
38
- uni.showToast({
39
- title: '更新失败-02',
40
- mask: false,
41
- duration: 1500
42
- });
43
- }
44
- });
45
- try {
46
- dtask.start(); // 开启下载的任务
47
- var prg = 0;
48
- var showLoading = plus.nativeUI.showWaiting('正在下载'); //创建一个showWaiting对象
49
- dtask.addEventListener('statechanged', function (task, status) {
50
- // 给下载任务设置一个监听 并根据状态 做操作
51
- switch (task.state) {
52
- case 1:
53
- showLoading.setTitle('正在下载');
54
- break;
55
- case 2:
56
- showLoading.setTitle('已连接到服务器');
57
- break;
58
- case 3:
59
- prg = parseInt((parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100);
60
- showLoading.setTitle(' 正在下载' + prg + '% ');
61
- break;
62
- case 4:
63
- plus.nativeUI.closeWaiting();
64
- //下载完成
65
- break;
66
- }
67
- });
68
- } catch (err) {
69
- plus.nativeUI.closeWaiting();
70
- uni.showToast({
71
- title: '更新失败-03',
72
- mask: false,
73
- duration: 1500
74
- });
75
- }
76
- }
77
- } else {
78
- //取消
79
- }
80
- }
81
- });
82
- } else {
83
- uni.showModal({
84
- title: '提示',
85
- content: '已是最新版本',
86
- showCancel: false
87
- });
88
- }
89
- }
90
- });
@@ -1,103 +0,0 @@
1
- import HttpObj from '@/plugins/http.js';
2
- let xx = {
3
- //检测当前版本号
4
- dqbanben: function () {
5
- var that = this;
6
- //在页面中初始化plus插件
7
- mui.init();
8
- mui.plusReady(function () {
9
- // 获取本地应用资源版本号
10
- that.wgtVer = plus.runtime.version;
11
- that.checkUpdate();
12
- });
13
- },
14
- //检查更新
15
- checkUpdate: function () {
16
- var that = this;
17
- HttpObj.post('/version/checkUpdate', {
18
- version: that.wgtVer
19
- })
20
- .then((res) => {
21
- if (res.data.code == 0) {
22
- if (res.data.result == 1) {
23
- //跟后台传过来的版本号比对,如果版本号不一致
24
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
25
- //如果是苹果手机
26
- plus.nativeUI.confirm(
27
- '检测到有新版本,是否更新',
28
- function (e) {
29
- if (e.index == 0) {
30
- //如果选择更新
31
- window.location.href =
32
- 'itms-services://?action=download-manifest&url=https://ios.17rua.top/static/ios/x5.plist';
33
- //不经过苹果商店下载(不懂得看我的另一篇文章)
34
- plus.nativeUI.showWaiting('正在下载...');
35
- }
36
- },
37
- '',
38
- ['立即更新', '以后再说']
39
- );
40
- return;
41
- } else {
42
- plus.nativeUI.confirm(
43
- '检测到有新版本,是否更新',
44
- function (e) {
45
- if (e.index == 0) {
46
- that.downWgt(res.data.url); //下载文件
47
- } else {
48
- plus.runtime.quit(); //安卓控制不更新退出应用
49
- }
50
- },
51
- '',
52
- ['立即更新', '以后再说']
53
- );
54
- }
55
- sessionStorage.setItem('kbj_banben', true); //检验过一次版本就加入缓存,不在检测
56
- } else {
57
- sessionStorage.setItem('kbj_banben', true);
58
- return;
59
- }
60
- } else {
61
- alert('获取数据失败');
62
- }
63
- })
64
- .catch(function (error) {
65
- alert('请检查网络连接');
66
- });
67
- },
68
- //下载资源包
69
- downWgt: function (wgtUrl) {
70
- var that = this;
71
- var task = plus.downloader.createDownload(wgtUrl, {}, function (download, status) {
72
- //安装到手机的目录
73
- if (status == 200) {
74
- plus.runtime.install(download.filename); // 安装下载的apk文件
75
- } else {
76
- mui.toast('下载更新失败!');
77
- plus.nativeUI.closeWaiting();
78
- }
79
- });
80
- //监听下载
81
- task.addEventListener('statechanged', function (download, status) {
82
- switch (download.state) {
83
- case 2:
84
- plus.nativeUI.showWaiting('正在下载...');
85
- break;
86
- case 3:
87
- //进度条百分比 totalSize为总量,baifen为当前下载的百分比
88
- if (that.totalSize == 0) {
89
- that.totalSize = parseInt(download.totalSize);
90
- }
91
- if (parseInt((download.downloadedSize / that.totalSize) * 100) != that.baifen) {
92
- that.baifen = parseInt((download.downloadedSize / that.totalSize) * 100);
93
- }
94
- break;
95
- case 4:
96
- mui.toast('下载完成');
97
- plus.nativeUI.closeWaiting();
98
- break;
99
- }
100
- });
101
- task.start();
102
- }
103
- };