wl-design-mobile 0.3.6 → 0.3.8

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 CHANGED
@@ -1,6 +1,6 @@
1
- # wl-design-mobile
2
-
3
- ## Setup
4
- ```
5
- npm i wl-design-mobile
6
- ```
1
+ # wl-design-mobile
2
+
3
+ ## Setup
4
+ ```
5
+ npm i wl-design-mobile
6
+ ```
@@ -1,3 +1,3 @@
1
- .img-upload-container {
2
- padding: 0px 14px 12px 14px;
3
- }
1
+ .img-upload-container {
2
+ padding: 0px 14px 12px 14px;
3
+ }
@@ -1,39 +1,39 @@
1
- .coll-div {
2
- margin-bottom: 8px;
3
- }
4
-
5
- .indicator-title {
6
- display: flex;
7
- align-items: center;
8
- color: var(--scl-blue);
9
- font-size: 14px;
10
- font-family: 微软雅黑, serif Regular;
11
- }
12
-
13
- .indicator-title .color-line {
14
- width: 3px;
15
- height: 14px;
16
- margin-right: 8px;
17
- }
18
-
19
- .coll-title-icon {
20
- justify-content: center;
21
- align-items: center;
22
- align-content: center;
23
- }
24
-
25
- /* 覆盖折叠面板的标题的padding */
26
- /deep/ .van-cell {
27
- padding: 12px 10px;
28
- }
29
-
30
- /* 覆盖去掉折叠面板的标题下面的线 */
31
- /deep/ .van-cell::after {
32
- border: none;
33
- }
34
-
35
- /* 覆盖折叠面板的内容的padding */
36
- /deep/ .van-collapse-item__content {
37
- padding: 0px 0px 0px 0px;
38
- }
39
-
1
+ .coll-div {
2
+ margin-bottom: 8px;
3
+ }
4
+
5
+ .indicator-title {
6
+ display: flex;
7
+ align-items: center;
8
+ color: var(--scl-blue);
9
+ font-size: 14px;
10
+ font-family: 微软雅黑, serif Regular;
11
+ }
12
+
13
+ .indicator-title .color-line {
14
+ width: 3px;
15
+ height: 14px;
16
+ margin-right: 8px;
17
+ }
18
+
19
+ .coll-title-icon {
20
+ justify-content: center;
21
+ align-items: center;
22
+ align-content: center;
23
+ }
24
+
25
+ /* 覆盖折叠面板的标题的padding */
26
+ /deep/ .van-cell {
27
+ padding: 12px 10px;
28
+ }
29
+
30
+ /* 覆盖去掉折叠面板的标题下面的线 */
31
+ /deep/ .van-cell::after {
32
+ border: none;
33
+ }
34
+
35
+ /* 覆盖折叠面板的内容的padding */
36
+ /deep/ .van-collapse-item__content {
37
+ padding: 0px 0px 0px 0px;
38
+ }
39
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wl-design-mobile",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "finch",
@@ -21,7 +21,8 @@
21
21
  "moment": "^2.30.1",
22
22
  "axios": "^1.7.2",
23
23
  "dingtalk-jsapi": "^3.0.12",
24
- "weixin-js-sdk": "^1.6.5"
24
+ "weixin-js-sdk": "^1.6.5",
25
+ "@wecom/jssdk": "^2.1.0"
25
26
  },
26
27
  "devDependencies": {
27
28
  "vue": "^2.6.14"
@@ -1,136 +1,136 @@
1
- .search-top-pop {
2
- min-height: 112px;
3
- max-height: 33%;
4
- background-color: var(--scl-white-1)
5
- }
6
-
7
- .search-body {
8
- border-top: none;
9
- overflow-y: auto;
10
- flex: 1
11
- }
12
-
13
- .search-bottom-btn {
14
- padding: 12px 14px 12px 14px;
15
- box-shadow: 0 -2px 10px rgba(125, 126, 128, .16);
16
- background-color: rgb(255, 255, 255, 1);
17
- }
18
-
19
- /*日期选择*/
20
- .search-row {
21
- display: flex;
22
- flex-direction: row;
23
- justify-content: flex-start;
24
- flex-wrap: nowrap;
25
- align-items: center;
26
- align-content: center;
27
- height: 50px;
28
- padding: 10px 0;
29
- margin: 0 14px;
30
- border-bottom: 1px solid var(--scl-white-2);
31
- border-top: none;
32
- }
33
-
34
- .search-input-title {
35
- height: 16px;
36
- font-size: 12px;
37
- color: var(--scl-gray-2);
38
- display: flex;
39
- justify-content: flex-start;
40
- align-items: center;
41
- margin-left: 12px;
42
- width: 76px;
43
- }
44
-
45
- .search-lambo-input {
46
- border: none;
47
- outline: none;
48
- background: none;
49
- height: 16px;
50
- font-size: 12px;
51
- color: var(--scl-gray-1);
52
- display: flex;
53
- justify-content: flex-start;
54
- align-items: center;
55
- margin-left: 8px;
56
- flex: 1;
57
- }
58
-
59
- /*输入框*/
60
- .search-lambo-input .van-cell {
61
- padding: 10px 0;
62
- }
63
-
64
- /*多选*/
65
- .search-top-div {
66
- display: flex;
67
- justify-content: space-between;
68
- height: 44px;
69
- line-height: 44px;
70
- width: 100%;
71
- position: fixed;
72
- z-index: 2;
73
- box-shadow: 0 2px 10px rgba(125, 126, 128, .16);
74
- background-color: rgb(255, 255, 255, 1);
75
- }
76
-
77
- .search-cancel-btn {
78
- border: none;
79
- color: var(--scl-gray-3);
80
- }
81
-
82
- .search-confirm-btn {
83
- border: none;
84
- color: var(--scl-blue);
85
- }
86
-
87
- .search-select-title {
88
- font-size: 16px;
89
- font-weight: bold;
90
- }
91
-
92
- /*修改单选多选的滚动条样式*/
93
- /deep/ .van-radio-group {
94
- position: relative;
95
- }
96
-
97
- /*修改单选多选的滚动条样式*/
98
- /deep/ .van-cell-group {
99
- padding-top: 44px;
100
- }
101
-
102
- /*修改单选多选的滚动条样式*/
103
- /deep/ .van-cell:first-child {
104
- padding-top: 10px;
105
- }
106
-
107
- /*滚动条样式*/
108
- /deep/ ::-webkit-scrollbar {
109
- width: 6px;
110
- }
111
-
112
- /*滚动条样式*/
113
- /deep/ ::-webkit-scrollbar-thumb {
114
- border-radius: var(--ind-border-radius-xl);
115
- background: rgba(45, 140, 240, 0.6);
116
- }
117
-
118
- /*滚动条样式*/
119
- /deep/ ::-webkit-scrollbar-track {
120
- -webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
121
- border-radius: var(--ind-border-radius-xl);
122
- background: rgba(231, 242, 250, 0.4);
123
- }
124
-
125
- .bottom-div {
126
- display: flex;
127
- flex-direction: column;
128
- }
129
-
130
- .cell-group-div {
131
- flex: 1;
132
- overflow-y: auto;
133
- margin-top: 44px;
134
- }
135
-
136
-
1
+ .search-top-pop {
2
+ min-height: 112px;
3
+ max-height: 33%;
4
+ background-color: var(--scl-white-1)
5
+ }
6
+
7
+ .search-body {
8
+ border-top: none;
9
+ overflow-y: auto;
10
+ flex: 1
11
+ }
12
+
13
+ .search-bottom-btn {
14
+ padding: 12px 14px 12px 14px;
15
+ box-shadow: 0 -2px 10px rgba(125, 126, 128, .16);
16
+ background-color: rgb(255, 255, 255, 1);
17
+ }
18
+
19
+ /*日期选择*/
20
+ .search-row {
21
+ display: flex;
22
+ flex-direction: row;
23
+ justify-content: flex-start;
24
+ flex-wrap: nowrap;
25
+ align-items: center;
26
+ align-content: center;
27
+ height: 50px;
28
+ padding: 10px 0;
29
+ margin: 0 14px;
30
+ border-bottom: 1px solid var(--scl-white-2);
31
+ border-top: none;
32
+ }
33
+
34
+ .search-input-title {
35
+ height: 16px;
36
+ font-size: 12px;
37
+ color: var(--scl-gray-2);
38
+ display: flex;
39
+ justify-content: flex-start;
40
+ align-items: center;
41
+ margin-left: 12px;
42
+ width: 76px;
43
+ }
44
+
45
+ .search-lambo-input {
46
+ border: none;
47
+ outline: none;
48
+ background: none;
49
+ height: 16px;
50
+ font-size: 12px;
51
+ color: var(--scl-gray-1);
52
+ display: flex;
53
+ justify-content: flex-start;
54
+ align-items: center;
55
+ margin-left: 8px;
56
+ flex: 1;
57
+ }
58
+
59
+ /*输入框*/
60
+ .search-lambo-input .van-cell {
61
+ padding: 10px 0;
62
+ }
63
+
64
+ /*多选*/
65
+ .search-top-div {
66
+ display: flex;
67
+ justify-content: space-between;
68
+ height: 44px;
69
+ line-height: 44px;
70
+ width: 100%;
71
+ position: fixed;
72
+ z-index: 2;
73
+ box-shadow: 0 2px 10px rgba(125, 126, 128, .16);
74
+ background-color: rgb(255, 255, 255, 1);
75
+ }
76
+
77
+ .search-cancel-btn {
78
+ border: none;
79
+ color: var(--scl-gray-3);
80
+ }
81
+
82
+ .search-confirm-btn {
83
+ border: none;
84
+ color: var(--scl-blue);
85
+ }
86
+
87
+ .search-select-title {
88
+ font-size: 16px;
89
+ font-weight: bold;
90
+ }
91
+
92
+ /*修改单选多选的滚动条样式*/
93
+ /deep/ .van-radio-group {
94
+ position: relative;
95
+ }
96
+
97
+ /*修改单选多选的滚动条样式*/
98
+ /deep/ .van-cell-group {
99
+ padding-top: 44px;
100
+ }
101
+
102
+ /*修改单选多选的滚动条样式*/
103
+ /deep/ .van-cell:first-child {
104
+ padding-top: 10px;
105
+ }
106
+
107
+ /*滚动条样式*/
108
+ /deep/ ::-webkit-scrollbar {
109
+ width: 6px;
110
+ }
111
+
112
+ /*滚动条样式*/
113
+ /deep/ ::-webkit-scrollbar-thumb {
114
+ border-radius: var(--ind-border-radius-xl);
115
+ background: rgba(45, 140, 240, 0.6);
116
+ }
117
+
118
+ /*滚动条样式*/
119
+ /deep/ ::-webkit-scrollbar-track {
120
+ -webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
121
+ border-radius: var(--ind-border-radius-xl);
122
+ background: rgba(231, 242, 250, 0.4);
123
+ }
124
+
125
+ .bottom-div {
126
+ display: flex;
127
+ flex-direction: column;
128
+ }
129
+
130
+ .cell-group-div {
131
+ flex: 1;
132
+ overflow-y: auto;
133
+ margin-top: 44px;
134
+ }
135
+
136
+
package/util/assist.js CHANGED
@@ -1,43 +1,43 @@
1
- // 深拷贝
2
- export function deepCopy(data) {
3
- let i;
4
- const t = typeOf(data);
5
- let o;
6
-
7
- if (t === 'array') {
8
- o = [];
9
- } else if (t === 'object') {
10
- o = {};
11
- } else {
12
- return data;
13
- }
14
-
15
- if (t === 'array') {
16
- for (i = 0; i < data.length; i++) {
17
- o.push(deepCopy(data[i]));
18
- }
19
- } else if (t === 'object') {
20
- for (i in data) {
21
- o[i] = deepCopy(data[i]);
22
- }
23
- }
24
- return o;
25
- }
26
-
27
- // 判断对象类型
28
- export function typeOf(obj) {
29
- const toString = Object.prototype.toString;
30
- const map = {
31
- '[object Boolean]': 'boolean',
32
- '[object Number]': 'number',
33
- '[object String]': 'string',
34
- '[object Function]': 'function',
35
- '[object Array]': 'array',
36
- '[object Date]': 'date',
37
- '[object RegExp]': 'regExp',
38
- '[object Undefined]': 'undefined',
39
- '[object Null]': 'null',
40
- '[object Object]': 'object'
41
- };
42
- return map[toString.call(obj)];
43
- }
1
+ // 深拷贝
2
+ export function deepCopy(data) {
3
+ let i;
4
+ const t = typeOf(data);
5
+ let o;
6
+
7
+ if (t === 'array') {
8
+ o = [];
9
+ } else if (t === 'object') {
10
+ o = {};
11
+ } else {
12
+ return data;
13
+ }
14
+
15
+ if (t === 'array') {
16
+ for (i = 0; i < data.length; i++) {
17
+ o.push(deepCopy(data[i]));
18
+ }
19
+ } else if (t === 'object') {
20
+ for (i in data) {
21
+ o[i] = deepCopy(data[i]);
22
+ }
23
+ }
24
+ return o;
25
+ }
26
+
27
+ // 判断对象类型
28
+ export function typeOf(obj) {
29
+ const toString = Object.prototype.toString;
30
+ const map = {
31
+ '[object Boolean]': 'boolean',
32
+ '[object Number]': 'number',
33
+ '[object String]': 'string',
34
+ '[object Function]': 'function',
35
+ '[object Array]': 'array',
36
+ '[object Date]': 'date',
37
+ '[object RegExp]': 'regExp',
38
+ '[object Undefined]': 'undefined',
39
+ '[object Null]': 'null',
40
+ '[object Object]': 'object'
41
+ };
42
+ return map[toString.call(obj)];
43
+ }
package/util/bus.js CHANGED
@@ -1,4 +1,4 @@
1
- import Vue from 'vue'
2
-
3
- const Bus = new Vue();
4
- export default Bus;
1
+ import Vue from 'vue'
2
+
3
+ const Bus = new Vue();
4
+ export default Bus;
package/util/jssdk.js CHANGED
@@ -1,247 +1,424 @@
1
- import wx from "weixin-js-sdk";
2
- import * as dd from 'dingtalk-jsapi';
3
- import config from '../config/config'
4
- import {axios} from '../util/axios'
5
-
6
- let appId,agentId,corpId,appKey
7
-
8
- function init({appId:a,agentId:b,corpId:c,appKey:d}){
9
- appId = a
10
- agentId = b
11
- corpId = c
12
- appKey = d
13
- }
14
-
15
-
16
- function getAppType() {
17
- let ua = navigator.userAgent.toLowerCase();
18
- let isWxWork = ua.match(/WxWork/i) == 'wxwork';
19
- if (isWxWork) {
20
- return '20'
21
- }
22
-
23
- let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
24
- if (isWx) {
25
- if(agentId){//如果有agentId认为是企业微信
26
- return '20'
27
- }
28
- return '10'
29
- }
30
-
31
- if (dd.env.platform != 'notInDingTalk') {
32
- return '30'
33
- }
34
-
35
- return ''
36
- }
37
-
38
- function getJsConfig(){
39
- let url = window.location.href.split('#')[0]
40
- return new Promise((resolve, reject)=>{
41
- axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
42
- appType: getAppType(),
43
- appId: appId,
44
- agentId: agentId,
45
- corpId: corpId,
46
- appKey: appKey,
47
- url: url
48
- }).then((resp) => {
49
- resolve(resp.data)
50
- }).catch((error) => {
51
- reject(error)
52
- })
53
- })
54
- }
55
-
56
- function configWx(){
57
- return new Promise((resolve, reject) =>{
58
- getJsConfig().then((resp)=>{
59
- wx.config({
60
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
61
- appId: appId, // 必填,公众号的唯一标识
62
- timestamp: resp.timestamp, // 必填,生成签名的时间戳
63
- nonceStr: resp.noncestr, // 必填,生成签名的随机串
64
- signature: resp.signature, // 必填,签名
65
- jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
66
- //jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
67
- });
68
-
69
- wx.ready(() => {
70
- console.log('初始化js-sdk成功');
71
- resolve()
72
- });
73
- wx.error(res => {
74
- console.log('初始化js-sdk失败' + res.errMsg);
75
- console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
76
- reject('初始化js-sdk失败' + res.errMsg)
77
- });
78
- }).catch((error)=>{
79
- reject('请求服务端jssdk签名失败:'+error)
80
- })
81
- })
82
- }
83
-
84
- function configDd(){
85
- return new Promise((resolve, reject)=>{
86
- getJsConfig().then((resp)=>{
87
- //钉钉js-api配置
88
- console.log("当前页面:"+location.href);
89
- dd.config({
90
- agentId:agentId,
91
- corpId: corpId, // 必填,公众号的唯一标识
92
- timeStamp: resp.timestamp, // 必填,生成签名的时间戳
93
- nonceStr: resp.noncestr, // 必填,生成签名的随机串
94
- signature: resp.signature, // 必填,签名
95
- jsApiList: [
96
- 'getDeviceUUID',
97
- 'getLocation',
98
-
99
- ] // 必填,需要使用的jsapi列表,注意:不要带dd。
100
- });
101
-
102
- dd.ready(() => {
103
- console.log('初始化钉钉 js-sdk成功');
104
- resolve()
105
- });
106
- dd.error(res => {
107
- console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
108
- console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
109
- reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
110
- });
111
- }).catch((error)=>{
112
- reject('请求服务端jssdk签名失败:'+error)
113
- })
114
- })
115
- }
116
-
117
- let JsSDK = (function () {
118
- function scanQRCode(){
119
- return new Promise((resolve, reject) =>{
120
- if(getAppType() === '30'){
121
- dd.scan({
122
- type: 'all',
123
- success: (res) => {
124
- console.log('钉钉扫码结果',res)
125
- resolve(res.text)
126
- },
127
- fail: (err) => {
128
- console.log('钉钉扫码失败',err)
129
- reject('钉钉扫码失败:'+err)
130
- },
131
- complete: () => {},
132
- });
133
- }else{
134
- configWx().then(()=>{
135
- wx.scanQRCode({
136
- desc: 'scanQRCode desc',
137
- needResult: 1,
138
- scanType: ["qrCode", "barCode"],
139
- success: function (resp) {
140
- console.log("微信扫码结果:",resp)
141
- let result = resp.resultStr
142
- resolve(result)
143
- },
144
- fail: function (res) {
145
- console.log("失败res=>",res)
146
- if (res.errMsg.indexOf('function_not_exist') > 0) {
147
- reject('版本过低请升级');
148
- } else {
149
- reject("微信扫码失败,请联系系统管理员!");
150
- }
151
- }
152
- })
153
- }).catch((error)=>{
154
- reject('微信扫码失败:'+error)
155
- })
156
- }
157
- })
158
- }
159
- function getLocation(){
160
- return new Promise((resolve, reject)=>{
161
- if(getAppType() === '30'){
162
- configDd().then(()=>{
163
- dd.getLocation({
164
- targetAccuracy: '200',
165
- cacheTimeout: 20,
166
- coordinate: '1',
167
- useCache: true,
168
- withReGeocode: true,
169
- type: 1,
170
- success: (res) => {
171
- console.log('钉钉获取当前位置结果:', res)
172
- resolve(res)
173
- },
174
- fail: (error) => {
175
- console.log('钉钉获取位置失败:', error)
176
- reject('钉钉获取位置失败:'+error)
177
- },
178
- complete: () => {},
179
- })
180
- }).catch((error)=>{
181
- reject('钉钉获取位置失败:'+error)
182
- })
183
- }else{
184
- configWx().then(()=>{
185
- wx.getLocation({
186
- type: 'gcj02', //获取gcj02的坐标
187
- success: (res) => {
188
- //res.longitude 获取经度
189
- //res.latitude 获取纬度
190
- console.log(res);
191
- resolve(res)
192
- }, fail: (res) => {
193
- console.log("微信获取位置失败。"+JSON.stringify(res));
194
- reject("微信获取位置失败" + JSON.stringify(res))
195
- }
196
- });
197
- }).catch((error)=>{
198
- reject('微信获取位置失败:'+error)
199
- })
200
- }
201
- })
202
- }
203
- function openLocation({longitude,latitude,name,address,scale= 15} = {}){
204
- return new Promise((resolve, reject)=>{
205
- if(getAppType() === '30'){
206
- configDd().then(()=>{
207
- dd.openLocation({
208
- title: name,
209
- address: address,
210
- latitude: latitude,
211
- longitude: longitude,
212
- success: () => {},
213
- fail: () => {},
214
- complete: () => {},
215
- });
216
- resolve()
217
- }).catch((error)=>{
218
- reject('钉钉启动内置地图位置失败:'+error)
219
- })
220
- }else{
221
- configWx().then(()=>{
222
- wx.openLocation({
223
- latitude: latitude,//目的地latitude
224
- longitude: longitude,//目的地longitude
225
- name: name,
226
- address: address,
227
- scale: scale//地图缩放大小,可根据情况具体调整
228
- });
229
- resolve()
230
- }).catch((error)=>{
231
- reject('微信启动内置地图失败:'+error)
232
- })
233
- }
234
- })
235
- }
236
-
237
- // 公开API
238
- return {
239
- init:init,
240
- scanQRCode: scanQRCode,
241
- getLocation:getLocation,
242
- openLocation:openLocation
243
- };
244
- })();
245
-
246
- export default JsSDK
247
-
1
+ import wx from "weixin-js-sdk";
2
+ import * as ww from '@wecom/jssdk'
3
+ import * as dd from 'dingtalk-jsapi';
4
+ import config from '../config/config'
5
+ import {axios} from '../util/axios'
6
+
7
+ let appId,agentId,corpId,appKey
8
+
9
+ function init({appId:a,agentId:b,corpId:c,appKey:d}){
10
+ appId = a
11
+ agentId = b
12
+ corpId = c
13
+ appKey = d
14
+ }
15
+
16
+
17
+ function getAppType() {
18
+ let ua = navigator.userAgent.toLowerCase();
19
+ let isWxWork = ua.match(/WxWork/i) == 'wxwork';
20
+ if (isWxWork) {
21
+ return '20'
22
+ }
23
+
24
+ let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
25
+ if (isWx) {
26
+ if(agentId){//如果有agentId认为是企业微信
27
+ return '20'
28
+ }
29
+ return '10'
30
+ }
31
+
32
+ if (dd.env.platform != 'notInDingTalk') {
33
+ return '30'
34
+ }
35
+
36
+ return ''
37
+ }
38
+
39
+ function getJsConfig(){
40
+ let url = window.location.href.split('#')[0]
41
+ return new Promise((resolve, reject)=>{
42
+ axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
43
+ appType: getAppType(),
44
+ appId: appId,
45
+ agentId: agentId,
46
+ corpId: corpId,
47
+ appKey: appKey,
48
+ url: url
49
+ }).then((resp) => {
50
+ resolve(resp.data)
51
+ }).catch((error) => {
52
+ reject(error)
53
+ })
54
+ })
55
+ }
56
+
57
+ function configWx(){
58
+ return new Promise((resolve, reject) =>{
59
+ getJsConfig().then((resp)=>{
60
+ wx.config({
61
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
62
+ appId: appId, // 必填,公众号的唯一标识
63
+ timestamp: resp.timestamp, // 必填,生成签名的时间戳
64
+ nonceStr: resp.noncestr, // 必填,生成签名的随机串
65
+ signature: resp.signature, // 必填,签名
66
+ jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
67
+ //jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
68
+ });
69
+
70
+ wx.ready(() => {
71
+ console.log('微信初始化js-sdk成功');
72
+ resolve()
73
+ });
74
+ wx.error(res => {
75
+ console.log('微信初始化js-sdk失败' + res.errMsg);
76
+ console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
77
+ reject('微信初始化js-sdk失败' + res.errMsg)
78
+ });
79
+ }).catch((error)=>{
80
+ reject('请求服务端jssdk签名失败:'+error)
81
+ })
82
+ })
83
+ }
84
+
85
+ async function getConfigSignature(url) {
86
+ const resp = await axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
87
+ appType: getAppType(),
88
+ appId: appId,
89
+ agentId: agentId,
90
+ corpId: corpId,
91
+ appKey: appKey,
92
+ url: url
93
+ })
94
+
95
+ let timestamp = resp.data.timeStamp
96
+ let nonceStr = resp.data.nonceStr
97
+ let signature = resp.data.signature
98
+
99
+ return { timestamp, nonceStr, signature }
100
+ }
101
+
102
+ function configWw(){
103
+ return new Promise((resolve, reject) =>{
104
+ ww.register({
105
+ corpId: appId, // 必填,当前用户企业所属企业ID
106
+ jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
107
+ getConfigSignature, // 必填,根据url生成企业签名的回调函数
108
+ onConfigSuccess:(res) => {
109
+ console.log('企业微信初始化js-sdk成功');
110
+ console.log(res.checkResult)
111
+ resolve()
112
+ },
113
+ onConfigFail:(res) =>{
114
+ console.log('企业微信初始化js-sdk失败' + res.errMsg);
115
+ console.log(res)
116
+ reject('企业微信初始化js-sdk失败' + res.errMsg)
117
+ }
118
+ })
119
+ })
120
+ }
121
+
122
+ function configDd(){
123
+ return new Promise((resolve, reject)=>{
124
+ getJsConfig().then((resp)=>{
125
+ //钉钉js-api配置
126
+ console.log("当前页面:"+location.href);
127
+ dd.config({
128
+ agentId:agentId,
129
+ corpId: corpId, // 必填,公众号的唯一标识
130
+ timeStamp: resp.timestamp, // 必填,生成签名的时间戳
131
+ nonceStr: resp.noncestr, // 必填,生成签名的随机串
132
+ signature: resp.signature, // 必填,签名
133
+ jsApiList: [
134
+ 'getDeviceUUID',
135
+ 'getLocation',
136
+
137
+ ] // 必填,需要使用的jsapi列表,注意:不要带dd。
138
+ });
139
+
140
+ dd.ready(() => {
141
+ console.log('初始化钉钉 js-sdk成功');
142
+ resolve()
143
+ });
144
+ dd.error(res => {
145
+ console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
146
+ console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
147
+ reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
148
+ });
149
+ }).catch((error)=>{
150
+ reject('请求服务端jssdk签名失败:'+error)
151
+ })
152
+ })
153
+ }
154
+
155
+ let JsSDK = (function () {
156
+ function scanQRCode(){
157
+ return new Promise((resolve, reject) =>{
158
+ if(getAppType() === '30'){
159
+ dd.scan({
160
+ type: 'all',
161
+ success: (res) => {
162
+ console.log('钉钉扫码结果',res)
163
+ resolve(res.text)
164
+ },
165
+ fail: (err) => {
166
+ console.log('钉钉扫码失败',err)
167
+ reject('钉钉扫码失败:'+err)
168
+ },
169
+ complete: () => {},
170
+ });
171
+ }else if(getAppType() === '20'){
172
+ configWw().then(()=>{
173
+ ww.scanQRCode({
174
+ needResult: true,
175
+ scanType: ['qrCode', 'barCode']
176
+ }). then(resp =>{
177
+ console.log("微信扫码结果:", resp)
178
+ if(resp.resultStr){
179
+ resolve(resp.resultStr)
180
+ }else{
181
+ reject("企业微信扫码失败!"+resp.errMsg)
182
+ }
183
+ })
184
+ }).catch((error)=>{
185
+ reject('企业微信扫码失败:'+error)
186
+ })
187
+ }else{
188
+ configWx().then(()=>{
189
+ wx.scanQRCode({
190
+ desc: 'scanQRCode desc',
191
+ needResult: 1,
192
+ scanType: ["qrCode", "barCode"],
193
+ success: function (resp) {
194
+ console.log("微信扫码结果:",resp)
195
+ let result = resp.resultStr
196
+ resolve(result)
197
+ },
198
+ fail: function (res) {
199
+ console.log("失败res=>",res)
200
+ if (res.errMsg.indexOf('function_not_exist') > 0) {
201
+ reject('版本过低请升级');
202
+ } else {
203
+ reject("微信扫码失败,请联系系统管理员!");
204
+ }
205
+ }
206
+ })
207
+ }).catch((error)=>{
208
+ reject('微信扫码失败:'+error)
209
+ })
210
+ }
211
+ })
212
+ }
213
+ function getLocation(){
214
+ return new Promise((resolve, reject)=>{
215
+ if(getAppType() === '30'){
216
+ configDd().then(()=>{
217
+ dd.getLocation({
218
+ targetAccuracy: '200',
219
+ cacheTimeout: 20,
220
+ coordinate: '1',
221
+ useCache: true,
222
+ withReGeocode: true,
223
+ type: 1,
224
+ success: (res) => {
225
+ console.log('钉钉获取当前位置结果:', res)
226
+ resolve(res)
227
+ },
228
+ fail: (error) => {
229
+ console.log('钉钉获取位置失败:', error)
230
+ reject('钉钉获取位置失败:'+error)
231
+ },
232
+ complete: () => {},
233
+ })
234
+ }).catch((error)=>{
235
+ reject('钉钉获取位置失败:'+error)
236
+ })
237
+ }else if(getAppType() === '20'){
238
+ configWw().then(()=>{
239
+ ww.getLocation({
240
+ type: 'gcj02'
241
+ }).then((resp) => {
242
+ console.log(resp);
243
+ if(resp.longitude){
244
+ resolve(resp)
245
+ }else{
246
+ reject("企业微信获取位置失败" + JSON.stringify(resp))
247
+ }
248
+ })
249
+ }).catch((error)=>{
250
+ reject('企业微信获取位置失败:'+error)
251
+ })
252
+
253
+ }else{
254
+ configWx().then(()=>{
255
+ wx.getLocation({
256
+ type: 'gcj02', //获取gcj02的坐标
257
+ success: (res) => {
258
+ //res.longitude 获取经度
259
+ //res.latitude 获取纬度
260
+ console.log(res);
261
+ resolve(res)
262
+ }, fail: (res) => {
263
+ console.log("微信获取位置失败。"+JSON.stringify(res));
264
+ reject("微信获取位置失败" + JSON.stringify(res))
265
+ }
266
+ });
267
+ }).catch((error)=>{
268
+ reject('微信获取位置失败:'+error)
269
+ })
270
+ }
271
+ })
272
+ }
273
+ function openLocation({longitude,latitude,name,address,scale= 15} = {}){
274
+ return new Promise((resolve, reject)=>{
275
+ if(getAppType() === '30'){
276
+ configDd().then(()=>{
277
+ dd.openLocation({
278
+ title: name,
279
+ address: address,
280
+ latitude: latitude,
281
+ longitude: longitude,
282
+ success: () => {
283
+ resolve()
284
+ },
285
+ fail: () => {
286
+ reject()
287
+ },
288
+ complete: () => {
289
+ resolve()
290
+ },
291
+ });
292
+
293
+ }).catch((error)=>{
294
+ reject('钉钉启动内置地图位置失败:'+error)
295
+ })
296
+ }else if(getAppType() === '20'){
297
+ configWw().then(()=>{
298
+ ww.openLocation({
299
+ latitude: latitude,//目的地latitude
300
+ longitude: longitude,//目的地longitude
301
+ name: name,
302
+ address: address,
303
+ scale: scale//地图缩放大小,可根据情况具体调整
304
+ }).then((resp)=>{
305
+ console.log(resp)
306
+ resolve()
307
+ })
308
+ }).catch((error)=>{
309
+ reject('企业微信启动内置地图失败:'+error)
310
+ })
311
+ }else{
312
+ configWx().then(()=>{
313
+ wx.openLocation({
314
+ latitude: latitude,//目的地latitude
315
+ longitude: longitude,//目的地longitude
316
+ name: name,
317
+ address: address,
318
+ scale: scale//地图缩放大小,可根据情况具体调整
319
+ });
320
+ resolve()
321
+ }).catch((error)=>{
322
+ reject('微信启动内置地图失败:'+error)
323
+ })
324
+ }
325
+ })
326
+ }
327
+
328
+ function startAutoLBS({sceneId:sceneId}){
329
+ return new Promise((resolve, reject)=>{
330
+ if(getAppType() === '30'){
331
+ configDd().then(()=>{
332
+ dd.startLocating({
333
+ sceneId: sceneId,
334
+ useCache: true,
335
+ withReGeocode: false,
336
+ targetAccuracy: 200,
337
+ callBackInterval: 1000,
338
+ iOSDistanceFilter: 10,
339
+ success: (res) => {
340
+ resolve({longitude:res.longitude,latitude:res.latitude})
341
+ },
342
+ fail: () => {
343
+ reject()
344
+ },
345
+ complete: () => {
346
+ resolve()
347
+ },
348
+ });
349
+ }).catch((error)=>{
350
+ reject('钉钉启动内置地图位置失败:'+error)
351
+ })
352
+ }else if(getAppType() === '20'){
353
+ configWw().then(()=>{
354
+ ww.startAutoLBS({
355
+ type: 'gcj02',
356
+ success:()=>{
357
+ ww.onLocationChange(function(event) {
358
+ console.log(event)
359
+ resolve({longitude:event.longitude,latitude:event.latitude})
360
+ })
361
+ },
362
+ fail:()=>{
363
+ reject()
364
+ }
365
+ }).then(resp => {
366
+ console.log(resp)
367
+ })
368
+ }).catch((error)=>{
369
+ reject('企业微信开启连续定位失败:'+error)
370
+ })
371
+ }else{
372
+ reject('微信不支持连续定位')
373
+ }
374
+ })
375
+ }
376
+
377
+ function stopAutoLBS({sceneId:sceneId}){
378
+ return new Promise((resolve, reject)=>{
379
+ if(getAppType() === '30'){
380
+ configDd().then(()=>{
381
+ dd.stopLocating({
382
+ sceneId: sceneId,
383
+ success: () => {
384
+ resolve()
385
+ },
386
+ fail: () => {
387
+ reject()
388
+ },
389
+ complete: () => {
390
+ resolve()
391
+ },
392
+ });
393
+ resolve()
394
+ }).catch((error)=>{
395
+ reject('钉钉启动内置地图位置失败:'+error)
396
+ })
397
+ }else if(getAppType() === '20'){
398
+ configWw().then(()=>{
399
+ ww.stopAutoLBS().then(resp => {
400
+ console.log(resp)
401
+ resolve()
402
+ })
403
+ }).catch((error)=>{
404
+ reject('企业微信关闭连续定位失败:'+error)
405
+ })
406
+ }else{
407
+ reject('微信不支持连续定位')
408
+ }
409
+ })
410
+ }
411
+
412
+ // 公开API
413
+ return {
414
+ init:init,
415
+ scanQRCode: scanQRCode,
416
+ getLocation:getLocation,
417
+ openLocation:openLocation,
418
+ startAutoLBS:startAutoLBS,
419
+ stopAutoLBS:stopAutoLBS,
420
+ };
421
+ })();
422
+
423
+ export default JsSDK
424
+