@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.2 → 1.0.0-beta.5

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/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
  # Changelog
2
+ ## [1.0.0-beta.5](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.4...@lambo-design-mobile/js-bridge@1.0.0-beta.5) (2024-08-29)
3
+
4
+
5
+ ### ✨ Features | 新功能
6
+
7
+ * **@lambo-dsign-mobile/js-bridge:** 新增filepreview ([80de1a1](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/80de1a1b7c7c690ea55895f2c6c9acfbf1859fda))
8
+
9
+ ## [1.0.0-beta.4](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.3...@lambo-design-mobile/js-bridge@1.0.0-beta.4) (2024-08-23)
10
+
11
+
12
+ ### ✨ Features | 新功能
13
+
14
+ * **@lambo-design-mobile/lambo-js-picker:** 修改云途 ([0d8dd53](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/0d8dd5347c349787a1705e0d83531677e34159b2))
15
+
16
+ ## [1.0.0-beta.3](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.2...@lambo-design-mobile/js-bridge@1.0.0-beta.3) (2024-08-22)
17
+
2
18
  ## [1.0.0-beta.2](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design-mobile/js-bridge@1.0.0-beta.1...@lambo-design-mobile/js-bridge@1.0.0-beta.2) (2024-08-22)
3
19
 
4
20
 
package/demo/index.vue CHANGED
@@ -24,6 +24,9 @@
24
24
  <van-button @click="openLocation">打开位置</van-button>
25
25
  <pre v-if="openLocationResult"><code>{{ openLocationResult }}</code></pre>
26
26
  </demo-block>
27
+ <demo-block title="文件预览">
28
+ <a href="javascript:void(0);" @click="previewFile">点击这里预览文件</a>
29
+ </demo-block>
27
30
  </demo-section>
28
31
  </template>
29
32
 
@@ -43,8 +46,8 @@ export default {
43
46
  scanResult: '',
44
47
  photoResult: '',
45
48
  openLocationResult: '', // 添加用于存储打开位置的返回值
46
- latitude: null, // 存储纬度
47
- longitude: null, // 存储经度
49
+ latitude: 117.129, // 存储纬度
50
+ longitude: 36.662, // 存储经度
48
51
  ossServerContext: 'ibp-upms-server',
49
52
  ossImgPutUrl: '/oss/file/put',
50
53
  ossImgGetUrl: '/oss/file/get/',
@@ -100,11 +103,13 @@ export default {
100
103
  // 初始化参数,根据需要填写
101
104
  };
102
105
  const location = await this.lamboBridge.getLocation(options);
103
- console.log("location",location)
106
+ // console.log("location",location)
104
107
  this.location += `${JSON.stringify(location)}\n`; // 追加新数据
105
108
  this.latitude = location.latitude; // 存储纬度
106
109
  this.longitude = location.longitude; // 存储经度
107
- console.log('Location:', location);
110
+ console.log("this.latitude:",this.latitude);
111
+ console.log("this.longitude:",this.longitude);
112
+ // console.log('Location:', location);
108
113
  } catch (error) {
109
114
  console.error('Error getting location:', error);
110
115
  }
@@ -126,7 +131,8 @@ export default {
126
131
  const options = {
127
132
  ossServerContext: this.ossServerContext,
128
133
  ossImgPutUrl: this.ossImgPutUrl,
129
- ossImgGetUrl: this.ossImgGetUrl
134
+ ossImgGetUrl: this.ossImgGetUrl,
135
+ // sourceType: 'gallery'
130
136
  };
131
137
  const photos = await this.lamboBridge.takePhoto(options);
132
138
  this.photoResult += `${JSON.stringify(photos)}\n`;
@@ -167,6 +173,18 @@ export default {
167
173
  this.openLocationResult = `打开位置时出错: ${error.message}`; // 存储错误信息
168
174
  console.error('Error opening location:', error);
169
175
  }
176
+ },
177
+ async previewFile() {
178
+ try {
179
+ const options = {
180
+ title: '预览文件', // 文件的标题
181
+ path: 'http://160.mall.eap.lambo.top/ecm-runtime-server/api/file/get/123456' // 文件的URL路径
182
+ };
183
+ const result = await this.lamboBridge.filePreview(options);
184
+ console.log('File preview result:', result);
185
+ } catch (error) {
186
+ console.error('Error previewing file:', error);
187
+ }
170
188
  }
171
189
  },
172
190
  beforeRouteEnter (to, from, next) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design-mobile/lambo-js-bridge",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -9,7 +9,9 @@
9
9
  "access": "public",
10
10
  "registry": "https://registry.npmjs.org/"
11
11
  },
12
- "dependencies": {},
12
+ "dependencies": {
13
+ "coordtransform": "^2.1.2"
14
+ },
13
15
  "scripts": {
14
16
  "release-js-bridge": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
15
17
  "release-major": "standard-version --release-as major",
@@ -0,0 +1,74 @@
1
+ import config from "@lambo-design-mobile/shared/config/config";
2
+ import coordtransform from "coordtransform";
3
+
4
+ const addScript = function (src, cb) {
5
+ const script = document.createElement('script')
6
+ script.src = src
7
+ document.getElementsByTagName('head')[0].appendChild(script)
8
+ script.onload = function () {
9
+ if (!!cb) {
10
+ cb()
11
+ }
12
+ }
13
+ }
14
+
15
+ export function initBdMap() {
16
+ let tempAk = 'AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT'
17
+ if (config.akList) {
18
+ tempAk = config.akList[Math.random() * config.akList.length]
19
+ }
20
+ addScript('https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=' + tempAk)
21
+ addScript('https://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=' + tempAk)
22
+ }
23
+
24
+ export function getAddress(longitude, latitude) {
25
+ const myGeo = new BMap.Geocoder({extensions_town: false});
26
+ let city = ''
27
+ let province = ''
28
+ let address = ''
29
+
30
+ // 根据坐标得到地址描述
31
+ myGeo.getLocation(new BMap.Point(longitude, latitude), function(result){
32
+ if (result){
33
+ city = result.addressComponents.city
34
+ province = result.addressComponents.province
35
+ address = result.address
36
+ }
37
+ });
38
+ return {
39
+ city,
40
+ province,
41
+ address
42
+ }
43
+ }
44
+
45
+ export function getAxisByType(unifiedLocation, locationType) {
46
+ // 目前只有wgs84 bd09 gcj02 默认传进unifiedLocation 坐标系为gcj02 不转换
47
+ if(locationType === 'bd09') {
48
+ // 将 gcj02 坐标转换为 bd09
49
+ const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
50
+ unifiedLocation.longitude = bd09Lng;
51
+ unifiedLocation.latitude = bd09Lat;
52
+ }
53
+ else if(locationType === 'wgs84'){
54
+ // 将 gcj02 坐标转换为 bd09
55
+ const [wgs84Lng, wgs84Lat] = coordtransform.gcj02towgs84(unifiedLocation.longitude, unifiedLocation.latitude);
56
+ unifiedLocation.longitude = wgs84Lng;
57
+ unifiedLocation.latitude = wgs84Lat;
58
+ }
59
+ if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
60
+ return false;
61
+ }
62
+ return unifiedLocation
63
+ }
64
+
65
+ export function getAddressByType(unifiedLocation, locationType) {
66
+
67
+ const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
68
+ // 根据坐标得到地址描述
69
+ const res = getAddress(bd09Lng, bd09Lat)
70
+ unifiedLocation.city = res.addressComponents.city
71
+ unifiedLocation.province = res.addressComponents.province
72
+ unifiedLocation.address = res.address
73
+ getAxisByType(unifiedLocation, locationType)
74
+ }
@@ -4,28 +4,16 @@ import CordovaAdapter from './CordovaAdapter';
4
4
  import YunTuAdapter from './YunTuAdapter';
5
5
  import WeComAdapter from './WeComAdapter';
6
6
  import BrowserAdapter from './BrowserAdapter';
7
+ import { initBdMap } from './BdMapUtils';
7
8
 
8
9
  class LamboJsBridge {
9
- constructor(param) {
10
- // param.isBdNiJieXi 需要百度地图逆地址解析
11
- if(param.isBdNiJieXi) {
12
- const addScript = function (src, cb) {
13
- const script = document.createElement('script')
14
- script.src = src
15
- document.getElementsByTagName('head')[0].appendChild(script)
16
- script.onload = function () {
17
- if (!!cb) {
18
- cb()
19
- }
20
- }
21
- }
22
- addScript('https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT')
23
- addScript(
24
- 'https://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT',
25
- )
26
- }
27
- this._detectPlatform(param);
10
+ constructor(param) {
11
+ // param.isBdNiJieXi 需要百度地图逆地址解析
12
+ if (param.isBdNiJieXi) {
13
+ initBdMap();
28
14
  }
15
+ this._detectPlatform(param);
16
+ }
29
17
 
30
18
  _detectPlatform(param) {
31
19
  const userAgent = navigator.userAgent.toLowerCase();
@@ -45,6 +33,16 @@ class LamboJsBridge {
45
33
 
46
34
  }
47
35
 
36
+ // yuntu接口:初始化插件(只有yuntu平台需要)
37
+ async initializePlugin(pluginConfig = []) {
38
+ if (this.platform instanceof YunTuAdapter) {
39
+ return this.platform.initializePlugin(pluginConfig);
40
+ } else {
41
+ // 非 yuntu 平台,直接返回一个已解决的 Promise
42
+ return Promise.resolve();
43
+ }
44
+ }
45
+
48
46
  // 通用接口:获取初始化信息
49
47
  async getPlatform(options = {}) {
50
48
  return this.platform.getPlatform(options);
@@ -69,5 +67,9 @@ class LamboJsBridge {
69
67
  async openLocation(options = {}){
70
68
  return this.platform.openLocation(options);
71
69
  }
70
+
71
+ async filePreview(options={}){
72
+ return this.platform.filePreview(options);
73
+ }
72
74
  }
73
75
  export default LamboJsBridge;
@@ -3,7 +3,8 @@
3
3
 
4
4
  import ajax from "@lambo-design-mobile/shared/utils/ajax";
5
5
  import config from "@lambo-design-mobile/shared/config/config";
6
- import coordtransform from "coordtransform";
6
+ // import coordtransform from "coordtransform";
7
+ import { getAddress, initBdMap, getAddressByType, getAxisByType } from './BdMapUtils';
7
8
 
8
9
  class WechatAdapter {
9
10
  constructor(_options) {
@@ -23,11 +24,9 @@ class WechatAdapter {
23
24
  });
24
25
  }
25
26
  loadScript('//res.wx.qq.com/open/js/jweixin-1.6.0.js')
26
- .then(script => {
27
- console.log('Script loaded');
28
- this.init(_options);
29
- })
27
+ .then(script => console.log('Script loaded'))
30
28
  .catch(err => console.error(err));
29
+ this.init(_options);
31
30
  }
32
31
 
33
32
  async init(options) {
@@ -87,16 +86,14 @@ class WechatAdapter {
87
86
  if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
88
87
  return reject(new Error('Invalid location data'));
89
88
  }
90
-
91
- const myGeo = new BMap.Geocoder({extensions_town: false});
92
- // 根据坐标得到地址描述
93
- myGeo.getLocation(new BMap.Point(unifiedLocation.longitude, unifiedLocation.latitude), function(result){
94
- if (result){
95
- unifiedLocation.city = result.addressComponents.city
96
- unifiedLocation.province = result.addressComponents.province
97
- unifiedLocation.address = result.address
98
- }
99
- });
89
+ // options.needAddress 是否需要地址信息
90
+ // if(options.needAddress && !unifiedLocation.address) {
91
+ // // 根据坐标得到地址描述
92
+ // const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
93
+ // unifiedLocation.city = res.addressComponents.city
94
+ // unifiedLocation.province = res.addressComponents.province
95
+ // unifiedLocation.address = res.address
96
+ // }
100
97
 
101
98
  resolve(unifiedLocation);
102
99
  },
@@ -108,31 +105,67 @@ class WechatAdapter {
108
105
  });
109
106
  };
110
107
 
111
- if (locationType === 'bd09') {
112
- // 先获取 gcj02 坐标
113
- fetchLocation('gcj02').then(unifiedLocation => {
114
- // gcj02 坐标转换为 bd09
115
- const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
116
- unifiedLocation.longitude = bd09Lng;
117
- unifiedLocation.latitude = bd09Lat;
108
+ // 先判断是否需要地理位置 如不需要 直接返回坐标
109
+ if(options.needAddress) {
110
+ fetchLocation('gcj02'.then(unifiedLocation => {
111
+ const result = getAddressByType(unifiedLocation, locationType)
112
+ if(!result) {
113
+ return reject(new Error('Invalid location data'));
114
+ }
115
+ resolve(unifiedLocation);
116
+ }))
117
+ .catch(err => { reject(err) })
118
+ }
119
+ else {
120
+ resolve(fetchLocation(locationType))
121
+ }
118
122
 
119
- const myGeo = new BMap.Geocoder({extensions_town: false});
120
- // 根据坐标得到地址描述
121
- myGeo.getLocation(new BMap.Point(unifiedLocation.longitude, unifiedLocation.latitude), function(result){
122
- if (result){
123
- unifiedLocation.city = result.addressComponents.city
124
- unifiedLocation.province = result.addressComponents.province
125
- unifiedLocation.address = result.address
126
- }
127
- });
123
+ // // 先取gcj02 再根据type转成不同坐标系
124
+ // fetchLocation('gcj02').then(unifiedLocation => {
125
+ // // options.needAddress 是否需要地址信息
126
+ // if(options.needAddress && !unifiedLocation.address) {
127
+ // const result = getAddressByType(unifiedLocation, locationType)
128
+ // if(!result) {
129
+ // return reject(new Error('Invalid location data'));
130
+ // }
131
+ // resolve(unifiedLocation);
132
+ // }
133
+ // else {
134
+ // const result = getAxisByType(unifiedLocation, locationType)
135
+ // if(!result) {
136
+ // return reject(new Error('Invalid location data'));
137
+ // }
138
+ // resolve(unifiedLocation);
139
+ // }
140
+ // }).catch(err => {
141
+ // reject(err);
142
+ // });
128
143
 
129
- resolve(unifiedLocation);
130
- }).catch(err => {
131
- reject(err);
132
- });
133
- } else {
134
- fetchLocation(locationType).then(resolve).catch(reject);
135
- }
144
+
145
+ // if (locationType === 'bd09') {
146
+ // // 先获取 gcj02 坐标
147
+ // fetchLocation('gcj02').then(unifiedLocation => {
148
+ // // gcj02 坐标转换为 bd09
149
+ // const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
150
+ // unifiedLocation.longitude = bd09Lng;
151
+ // unifiedLocation.latitude = bd09Lat;
152
+ // if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
153
+ // return reject(new Error('Invalid location data'));
154
+ // }
155
+ // // options.needAddress 是否需要地址信息
156
+ // if(options.needAddress && !unifiedLocation.address) {
157
+ // // 根据坐标得到地址描述
158
+ // const res = getAddress(unifiedLocation.longitude, unifiedLocation.latitude)
159
+ // unifiedLocation.city = res.addressComponents.city
160
+ // unifiedLocation.province = res.addressComponents.province
161
+ // unifiedLocation.address = res.address
162
+ // }
163
+
164
+ // resolve(unifiedLocation);
165
+ // }).catch(err => {
166
+ // reject(err);
167
+ // });
168
+ // }
136
169
  });
137
170
  });
138
171
  }
@@ -1,34 +1,33 @@
1
- import ajax from "@lambo-design-mobile/shared/utils/ajax";
2
- import config from "@lambo-design-mobile/shared/config/config";
3
- import coordtransform from "coordtransform";
1
+ import './yuntu';
4
2
 
5
3
  class YunTuAdapter {
6
4
  constructor() {
7
- this.isInitialized = false; // 标志插件是否已初始化
8
- function loadScript(src) {
9
- return new Promise((resolve, reject) => {
10
- const script = document.createElement('script');
11
- script.src = src;
12
- script.onload = () => resolve(script);
13
- script.onerror = () => reject(new Error('Failed to load script'));
14
- document.head.appendChild(script);
15
- });
16
- }
17
- loadScript('/packages/js-bridge/yuntu.js')
18
- .then(script => {
19
- console.log('Script loaded');
20
- this.initializePlugin(); // 确保初始化完成
21
- })
22
- .catch(err => console.error(err));
5
+ // 标志插件是否已初始化
6
+ this.isInitialized = false;
23
7
  }
24
8
 
25
- async initializePlugin() {
26
- window.yuntu.config('["myPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin","appUpdatePlugin"]');
27
- this.isInitialized = true;
28
- console.log("this.isInitialized:",this.isInitialized);
9
+ async initializePlugin(pluginConfig) {
10
+ try {
11
+ // 如果传入的是非空数组,则直接使用;否则使用默认的全部插件配置
12
+ const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
13
+ ? JSON.stringify(pluginConfig)
14
+ : '["myPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
15
+ // 调用插件初始化
16
+ await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
17
+
18
+ this.isInitialized = true;
19
+ // 将插件信息解析并存储到 this.plugin
20
+ this.plugins = JSON.parse(configToUse);
21
+ console.log("Initialized plugins:", this.plugins);
22
+ return this.plugins;
23
+ } catch (error) {
24
+ console.error("Plugin initialization failed:", error);
25
+ this.isInitialized = false;
26
+ return "Plugin initialization failed:" + error;
27
+ }
29
28
  }
30
29
 
31
-
30
+ // 其余代码保持不变
32
31
  async getPlatform() {
33
32
  return {
34
33
  platform: 'Yuntu'
@@ -0,0 +1,55 @@
1
+ (function(global) {
2
+ global.yuntu = {
3
+ config: function (options) {
4
+ global.flutter_inappwebview.callHandler(
5
+ "yuntu",
6
+ "init",
7
+ options
8
+ );
9
+ },
10
+ exec: function(plugin, action, successCallback, errorCallback, options) {
11
+ global.flutter_inappwebview.callHandler(
12
+ plugin,
13
+ action,
14
+ options
15
+ ).then((result) => {
16
+ successCallback(result);
17
+ }).catch((error) => {
18
+ errorCallback(error);
19
+ });
20
+ }
21
+ };
22
+
23
+ // 等待一个全局函数或变量加载完成
24
+ function waitForGlobalVariableOrFunction(globalName, callHandler) {
25
+ return new Promise((resolve, reject) => {
26
+ var interval = 1000; // 每1000毫秒检查一次
27
+ var timeout = 10000; // 设定最大等待时间 10 秒
28
+ var elapsedTime = 0;
29
+
30
+ var timer = setInterval(function () {
31
+ elapsedTime += interval;
32
+ if (global[globalName] && global[globalName][callHandler] !== undefined) {
33
+ clearInterval(timer); // 停止定时器
34
+ resolve(); // 执行回调函数,表示成功
35
+ console.log("yuntu 插件加载成功");
36
+ } else if (elapsedTime >= timeout) {
37
+ clearInterval(timer); // 停止定时器
38
+ console.log("yuntu 插件加载失败");
39
+ reject(new Error(`Timeout: ${globalName}.${callHandler} not found within ${timeout}ms`));
40
+ }
41
+ }, interval);
42
+ });
43
+ }
44
+
45
+ global.yuntuConfig = async function(options) {
46
+ try {
47
+ await waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler');
48
+ global.yuntu.config(options);
49
+ } catch (error) {
50
+ console.error("yuntuConfig 初始化失败:", error);
51
+ throw error; // 如果失败则抛出错误
52
+ }
53
+ };
54
+
55
+ })(window);
package/yuntu.js DELETED
@@ -1,42 +0,0 @@
1
- window.yuntu = {
2
- config: function (options) {
3
- window.flutter_inappwebview.callHandler(
4
- "yuntu",
5
- "init",
6
- options
7
- )
8
- },
9
- exec: function(plugin, action, successCallback, errorCallback, options) {
10
- window.flutter_inappwebview.callHandler(
11
- plugin,
12
- action,
13
- options
14
- ).then((result) => {
15
- successCallback(result);
16
- }).catch((error) => {
17
- errorCallback(error);
18
- });
19
- }
20
- }
21
- // 等待一个全局函数或变量加载完成
22
- function waitForGlobalVariableOrFunction(globalName, callHandler, callback) {
23
- // 设置轮询的时间间隔(毫秒)
24
- var interval = 100; // 例如,每100毫秒检查一次
25
- var t = 0
26
- // 定义一个定时器函数
27
- var timer = setInterval(function () {
28
- console.log(t++)
29
- if (window[globalName][callHandler] !== undefined) {
30
- // 全局变量或函数已加载
31
- clearInterval(timer); // 停止定时器
32
- callback(); // 执行回调函数
33
- }
34
- }, interval);
35
- }
36
-
37
- function yuntuConfig(options){
38
- waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler', function () {
39
- // 在这里执行你的代码,myFunction 已加载
40
- window.yuntu.config(options);
41
- });
42
- }