wl-design-mobile 0.3.3 → 0.3.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/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
+ ```
@@ -31,8 +31,7 @@ export default {
31
31
 
32
32
  },
33
33
  created() {
34
- console.log("row name:", this.name)
35
- console.log("row val:", this.val)
34
+
36
35
  }
37
36
  }
38
37
  </script>
@@ -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.3",
3
+ "version": "0.3.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "finch",
@@ -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
+
@@ -8,8 +8,11 @@
8
8
  :defaultColDef="defaultColDef"
9
9
  @grid-ready="onGridReady"
10
10
  @sortChanged="onSortChanged"
11
- class="ag-theme-balham"
12
- style="width: 100%; height: 100%;"
11
+ @cell-clicked="onCellClicked"
12
+ :row-selection="isMultiSelect === true ? 'multiple' : false"
13
+ :rowMultiSelectWithClick="isMultiSelect"
14
+ :suppressCellSelection="isMultiSelect"
15
+ class="ag-grid-tb"
13
16
  ></ag-grid-vue>
14
17
  </div>
15
18
  <van-pagination
@@ -34,8 +37,12 @@ import 'ag-grid-community/styles/ag-grid.css'
34
37
  import 'ag-grid-community/styles/ag-theme-balham.css'
35
38
  import {AgGridVue} from 'ag-grid-vue/lib/main.cjs.js'
36
39
  // import {AgGridVue} from 'ag-grid-vue'
37
- import {axios} from "../util/axios/index"
38
40
  import {Toast} from "vant"
41
+ import {axios} from "../util/axios";
42
+
43
+ // 合计行标志
44
+ const TOTAL_ROW_FIELD_KEY = "total_row"
45
+ const PAGE_DRILL_FLAG_KEY = "drill"
39
46
 
40
47
  export default {
41
48
  name: 'LamboAgTable',
@@ -43,7 +50,7 @@ export default {
43
50
  props: {
44
51
  tableHeight: {
45
52
  type: String,
46
- default: '50%',
53
+ default: '381px', // 默认10行的高度
47
54
  },
48
55
  url: {
49
56
  type: String,
@@ -60,6 +67,10 @@ export default {
60
67
  type: Boolean,
61
68
  default: false
62
69
  },
70
+ isMultiSelect: {
71
+ type: Boolean,
72
+ default: false
73
+ }
63
74
  },
64
75
  data() {
65
76
  return {
@@ -69,26 +80,35 @@ export default {
69
80
  lockPosition: true,
70
81
  editable: false,
71
82
  sortable: true,
72
- resizable: false,
73
- filter: false,
74
- autoHeight: true
83
+ autoHeight: true,
84
+ resizable: true,
85
+ filter: true
75
86
  },
76
87
  currentPage: 1,
77
88
  offset: 0,
78
89
  limit: 10,
79
90
  total: 0,
91
+ gridApi: null
80
92
  }
81
93
  },
82
94
  methods: {
83
95
  onGridReady(params) {
84
- params.api.sizeColumnsToFit();
96
+ this.gridApi = params.api
85
97
  },
86
- columnsFilterSort() {
98
+ columnsFilter() {
87
99
  if (this.columns && this.columns.length > 0) {
88
100
  for (const item of this.columns) {
89
101
  if (item && item.hasOwnProperty("field")) {
90
102
  item['comparator'] = this.preventComparator
91
103
  }
104
+ if (item.hasOwnProperty(PAGE_DRILL_FLAG_KEY) && item[PAGE_DRILL_FLAG_KEY] === '1') {
105
+ item.cellStyle= (params) => {
106
+ console.log("lambo-ag-grid columnsFilter params:", params)
107
+ if (params.hasOwnProperty("data") && !(params.data.hasOwnProperty(TOTAL_ROW_FIELD_KEY) && params.data[TOTAL_ROW_FIELD_KEY] === '1')) {
108
+ return {color: '#0070D2'}
109
+ }
110
+ }
111
+ }
92
112
  }
93
113
  }
94
114
  },
@@ -96,7 +116,7 @@ export default {
96
116
  return 0;
97
117
  },
98
118
  onSortChanged(event) {
99
- console.log("lambo-ag-table -- onSortChanged -- event:", event)
119
+ console.log("lambo-ag-table onSortChanged event:", event)
100
120
  if (event && event.hasOwnProperty("columns") && event.columns) {
101
121
  let sortColumns = event.columns
102
122
  if (sortColumns && sortColumns.length > 0) {
@@ -104,7 +124,7 @@ export default {
104
124
  if (sortCol && sortCol.hasOwnProperty("colId") && sortCol.hasOwnProperty("sort")) {
105
125
  let sortField = sortCol.colId
106
126
  let sortType = sortCol.sort
107
- console.log("lambo-ag-table -- onSortChanged -- sortField:" + sortField + ",sortType:" + sortType)
127
+ console.log("lambo-ag-table onSortChanged sortField:" + sortField + ",sortType:" + sortType)
108
128
  if (sortField && (sortType === 'desc' || sortType === 'asc')) {
109
129
  this.searchParams.sort = sortField
110
130
  this.searchParams.order = sortType
@@ -125,9 +145,9 @@ export default {
125
145
  } else {
126
146
  params = {...this.searchParams}
127
147
  }
128
- console.log("lambo-ag-table -- onLoad -- params:", params)
148
+ console.log("lambo-ag-table onLoad params:", params)
129
149
  axios.get(this.url, {params}).then(res => {
130
- console.log("lambo-ag-table -- onLoad -- dataRefresh:", res)
150
+ console.log("lambo-ag-table onLoad dataRefresh res:", res)
131
151
  if (res && res.code === 1) {
132
152
  let dataObj = res.data
133
153
  this.rowData = dataObj.rows || []
@@ -137,20 +157,42 @@ export default {
137
157
  this.total = dataObj.total || 0
138
158
  }
139
159
  } else {
140
- console.error("lambo-ag-table -- onLoad -- 查询[" + this.url + "]数据失败", res)
160
+ console.error("lambo-ag-table onLoad 查询[" + this.url + "]数据失败", res)
141
161
  Toast.fail("查询[" + this.url + "]数据失败:" + res.data || '')
142
162
  }
143
163
  }).catch(err => {
144
- console.error("lambo-ag-table -- onLoad -- 查询[" + this.title + "]异常:", err)
164
+ console.error("lambo-ag-table onLoad 查询[" + this.title + "]异常:", err)
145
165
  Toast.fail("查询[" + this.url + "]数据异常")
146
166
  })
167
+ },
168
+ getSelectedRows() {
169
+ let selData = []
170
+ if (this.gridApi) {
171
+ const selectedNodes = this.gridApi.getSelectedNodes()
172
+ if (selectedNodes) {
173
+ selData = selectedNodes.map(node => node.data)
174
+ }
175
+ console.log('lambo-ag-grid getSelectedRows:', selData);
176
+ }
177
+ return selData
178
+ },
179
+ onCellClicked(event) {
180
+ console.log('lambo-ag-grid onCellClicked event:', event);
181
+ if (event && event.hasOwnProperty("colDef") && event.colDef.hasOwnProperty("field") && event.hasOwnProperty("data")) {
182
+ let detailField = event.colDef.field
183
+ let rowData = event.data
184
+ if (!(rowData.hasOwnProperty(TOTAL_ROW_FIELD_KEY) && rowData[TOTAL_ROW_FIELD_KEY] === '1')) {
185
+ this.$emit('on-cell-click', detailField, event.value, rowData);
186
+ }
187
+ } else {
188
+ console.error("lambo-ag-grid onCellClicked event异常无法点击")
189
+ }
147
190
  }
148
191
  },
149
192
  watch: {
150
193
  searchParams: {
151
194
  handler: function (val, oldVal) {
152
- console.log("lambo-ag-table -- searchParams -- val,oldVal:", {val, oldVal})
153
- console.log("lambo-ag-table -- searchParams -- val===oldVal:", val === oldVal)
195
+ console.log(`lambo-ag-table watch searchParams val,oldVal:`, {val, oldVal}, `val===oldVal:`, val === oldVal)
154
196
  this.rowData = []
155
197
  this.sumData = []
156
198
  this.dataRefresh()
@@ -159,11 +201,16 @@ export default {
159
201
  }
160
202
  },
161
203
  created() {
162
- this.columnsFilterSort()
204
+ this.columnsFilter()
163
205
  }
164
206
  }
165
207
  </script>
166
208
  <style scoped>
209
+ .ag-grid-tb {
210
+ height: 100%;
211
+ width: 100%;
212
+ }
213
+
167
214
  /deep/ .vant-page-comp .van-pagination__item {
168
215
  color: #0070D2
169
216
  }
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,247 @@
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 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
+