@smart100/spu-web-plugin 0.0.15 → 0.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "rollup -c -w",
@@ -0,0 +1,190 @@
1
+ import { globalOptions } from './install'
2
+ import { cloneDeep, merge, set } from 'lodash-es'
3
+ import ApaasSpuTrack from './package/apaas-track/apaas-spu/index.umd.js'
4
+ import login from './login'
5
+
6
+ const getWebInitParams = async () => {
7
+ const user = login.getUser()
8
+ const envname = await login.getEnvname()
9
+ return {
10
+ project: globalOptions.modulename,
11
+ appid: globalOptions.modulekey,
12
+ clientver: globalOptions.moduleversion,
13
+ // anonymousid: '',
14
+ // distinctid: '',
15
+ accountcode: user.accountcode,
16
+ envname: envname,
17
+ tenantcode: user.tenantcode,
18
+ tenantname: user.tenantname,
19
+ positionname: user.positionname,
20
+ mbcode: user.mbcode,
21
+ username: `${user.username1 || ''}|${user.username2 || ''}|${user.username3 || ''}`,
22
+ userinfoname: user.userinfoname
23
+ }
24
+ }
25
+
26
+ const getIndextagSync = (params: any) => {
27
+ const result: any = {
28
+ code: '',
29
+ msg: '',
30
+ indextag: ''
31
+ }
32
+
33
+ if (params.url) {
34
+ const a = params.url.split('indextag=')
35
+ if (a.length > 1) {
36
+ const b = a[1].split('&')
37
+ result.code = 200
38
+ result.indextag = b[0]
39
+ result.msg = '解析成功。'
40
+ } else {
41
+ result.code = 404
42
+ result.msg = '不存在该 url 的 indextag。'
43
+ }
44
+ } else {
45
+ result.code = 404
46
+ result.msg = '传入 url 为空。'
47
+ }
48
+ // console.log(result)
49
+ // debugger
50
+ // params.complete && params.complete(result.code, result.indextag, result.msg)
51
+ return result
52
+ }
53
+
54
+ // 兼容开启SPU日志
55
+ const initApaasSpuTrack = () => {
56
+ setTimeout(() => {
57
+ if (ApaasSpuTrack && !window.apaasSpuTrack && !window?.aPaaS?.getWebInitParams && !window?.Module?.getIndextagSync) {
58
+ window.aPaaS = {
59
+ getWebInitParams
60
+ }
61
+ window.Module = {
62
+ getIndextagSync
63
+ }
64
+ // if (window.aPaaS && !window.aPaaS.getWebInitParams) {
65
+ // window.aPaaS.getWebInitParams = getWebInitParams
66
+ // } else {
67
+ // window.aPaaS = {
68
+ // getWebInitParams
69
+ // }
70
+ // }
71
+ // if (window.Module && !window.Module.getIndextagSync) {
72
+ // window.Module.getIndextagSync = getIndextagSync
73
+ // } else {
74
+ // window.Module = {
75
+ // getIndextagSync
76
+ // }
77
+ // }
78
+
79
+ ApaasSpuTrack.getApaasSpuTrack({
80
+ url: 'https://log.xtion.net/?project=xw_module',
81
+ zip: false,
82
+ online: true
83
+ }).then((apaasSpuTrack: ApaasSpuTrack) => {
84
+ console.log('apaasSpuTrack', apaasSpuTrack)
85
+ window.apaasSpuTrack = apaasSpuTrack
86
+
87
+ // // 监听关闭事件
88
+ // window.addEventListener('beforeunload', (e) => {
89
+ // // console.log(e)
90
+ // // debugger
91
+ // // window.dispatchEvent(new Event('pagehide'))
92
+ // let beforeunloadCount = window.localStorage.getItem('beforeunloadCount')
93
+ // if (!beforeunloadCount) {
94
+ // beforeunloadCount = 0
95
+ // }
96
+ // window.localStorage.setItem('beforeunloadCount', (Number(beforeunloadCount) + 1).toString())
97
+ // })
98
+
99
+ // // 监听关闭事件
100
+ // window.addEventListener('pagehide', () => {
101
+ // // debugger
102
+ // let pagehideCount = window.localStorage.getItem('pagehideCount')
103
+ // if (!pagehideCount) {
104
+ // pagehideCount = 0
105
+ // }
106
+ // window.localStorage.setItem('pagehideCount', (Number(pagehideCount) + 1).toString())
107
+ // })
108
+
109
+ // 重写 transformLog 底层方法
110
+ let initindextag = ''
111
+ apaasSpuTrack.transformLog = (log: any) => {
112
+ if (log.properties) {
113
+ // 发送所有类型的日志前统一在 properties 对象属性下增加SPU相关属性值:modulekey、modulename、moduleversion、indextag、initindextag、toindextag、fromindextag。
114
+ log.properties.modulekey = log.appid
115
+ log.properties.modulename = log.project
116
+ log.properties.moduleversion = log.clientver
117
+ // debugger
118
+
119
+ const urlParseRes = window.Module.getIndextagSync({
120
+ url: log.url
121
+ })
122
+ log.properties.indextag = urlParseRes.indextag
123
+
124
+ // 初始化时记录 initindextag 之后为每个日志都添加 initindextag
125
+ if (log.types === 'init') {
126
+ initindextag = log.properties.indextag
127
+ }
128
+ log.properties.initindextag = initindextag
129
+
130
+ if (log.types === 'pageview' && log.properties.to) {
131
+ const toParseRes = window.Module.getIndextagSync({
132
+ url: log.properties.to
133
+ })
134
+ log.properties.toindextag = toParseRes.indextag
135
+ }
136
+ if (log.types === 'pageview' && log.properties.from) {
137
+ const fromParseRes = window.Module.getIndextagSync({
138
+ url: log.properties.from
139
+ })
140
+ log.properties.fromindextag = fromParseRes.indextag
141
+ }
142
+ }
143
+ return log
144
+ }
145
+
146
+ apaasSpuTrack.start()
147
+ })
148
+ }
149
+ }, 2500)
150
+ }
151
+
152
+ const apaasSpuTrackSendLog = (data: any, end = false) => {
153
+ if (window.apaasSpuTrack) {
154
+ const logtime = Date.now().toString()
155
+ const baselog = cloneDeep({
156
+ ...window.apaasSpuTrack.baseLog,
157
+ logtime: logtime,
158
+ epochnanos: logtime + '000000',
159
+ types: '',
160
+ event: '',
161
+ url: location.href,
162
+ properties: {
163
+ // // 图片导出相关信息
164
+ // // formtype: apaas | litheform | spu
165
+ // formtype: 'spu',
166
+ // // exporttype: 1=普通导出 | 2=后端图片扩展导出 | 3=图片导出SPU
167
+ // exporttype: '3',
168
+ // // pagecode
169
+ // // 当 formtype = apaas 表示低码表单code
170
+ // // 当 formtype = litheform 表示超表表单code
171
+ // // 当 formtype = spu 表示配置的spu页面pagecode
172
+ // pagecode: ''
173
+ }
174
+ })
175
+ const mergedata = merge(baselog, data)
176
+ console.log(mergedata)
177
+ // debugger
178
+ window.apaasSpuTrack.addLogToQueue(mergedata, true)
179
+ } else {
180
+ console.warn('window.apaasSpuTrack 不存在,延迟3秒后发送')
181
+ // setTimeout(() => {
182
+ // sendLog(data)
183
+ // }, 3000)
184
+ }
185
+ }
186
+
187
+ export {
188
+ initApaasSpuTrack,
189
+ apaasSpuTrackSendLog
190
+ }
@@ -7,6 +7,7 @@ import { apaasAxios } from '../../axios'
7
7
  import core, { Module } from '../../core'
8
8
  import login from '../../login'
9
9
  import { downloadService } from '../../oss'
10
+ import { apaasSpuTrackSendLog } from '../../apaasSpuTrack'
10
11
 
11
12
  export default class SpuExpandexp extends HTMLElement {
12
13
 
@@ -340,6 +341,15 @@ export default class SpuExpandexp extends HTMLElement {
340
341
  }
341
342
  }
342
343
  })
344
+ apaasSpuTrackSendLog({
345
+ types: 'exportopenmodal',
346
+ event: 'exportopenmodal',
347
+ properties: {
348
+ formtype: 'spu',
349
+ exporttype: this.data.expandStatus,
350
+ pagecode: this.props.pagecode
351
+ }
352
+ })
343
353
  } else {
344
354
  apaasAxios
345
355
  .post('/api/expandexp/global/searchExpGloConfig', {
@@ -361,6 +371,16 @@ export default class SpuExpandexp extends HTMLElement {
361
371
  .catch((err: Error) => {
362
372
  this.data.expandStatus = '1'
363
373
  }).finally(() => {
374
+ // 发送日志
375
+ apaasSpuTrackSendLog({
376
+ types: 'exportopenmodal',
377
+ event: 'exportopenmodal',
378
+ properties: {
379
+ formtype: 'spu',
380
+ exporttype: this.data.expandStatus,
381
+ pagecode: this.props.pagecode
382
+ }
383
+ })
364
384
 
365
385
  if (this.data.expandStatus === '1') {
366
386
  this.data.exportcontentArray = ['excel']
@@ -468,11 +488,25 @@ export default class SpuExpandexp extends HTMLElement {
468
488
  this.data.resultMessage = '网络连接错误'
469
489
  this.stopInterval()
470
490
  })
491
+
492
+ apaasSpuTrackSendLog({
493
+ types: 'exportclickbutton',
494
+ event: 'exportclickbutton',
495
+ properties: {
496
+ formtype: 'spu',
497
+ exporttype: this.data.expandStatus,
498
+ pagecode: this.props.pagecode,
499
+ bizdata: {
500
+ exportapi: this.props.exportapi,
501
+ params: finallyPost
502
+ }
503
+ }
504
+ })
471
505
  }
472
506
 
473
507
  handleDownload () {
474
- console.log(this.data)
475
- console.log(this.data.exportDataItem)
508
+ // console.log(this.data)
509
+ // console.log(this.data.exportDataItem)
476
510
 
477
511
  let fixExportFileUrl = this.data.exportDataItem.exportfileurl[0] === '/' ? this.data.exportDataItem.exportfileurl : '/' + this.data.exportDataItem.exportfileurl
478
512
  let exportFileName = this.data.exportDataItem.filename
@@ -486,12 +520,27 @@ export default class SpuExpandexp extends HTMLElement {
486
520
  // filename: exportFileName
487
521
  // })
488
522
 
489
- downloadService.downloadFile({
523
+ const params = {
490
524
  type: 'att',
491
525
  source: fixExportFileUrl,
492
526
  datetime: date,
493
527
  storagetype: 'storage-1d',
494
528
  filename: exportFileName
529
+ }
530
+
531
+ downloadService.downloadFile(params as any)
532
+
533
+ apaasSpuTrackSendLog({
534
+ types: 'exportdownloadfile',
535
+ event: 'exportdownloadfile',
536
+ properties: {
537
+ formtype: 'spu',
538
+ exporttype: this.data.expandStatus,
539
+ pagecode: this.props.pagecode,
540
+ bizdata: {
541
+ params: params
542
+ }
543
+ }
495
544
  })
496
545
  }
497
546
 
package/src/install.ts CHANGED
@@ -3,12 +3,9 @@ import login from './login'
3
3
  import { initAxios } from './axios'
4
4
  import urlquery from './urlquery'
5
5
  import { initSpuConfig } from './spuConfig'
6
+ import { initApaasSpuTrack } from './apaasSpuTrack'
6
7
  import { merge } from 'lodash-es'
7
-
8
8
  import { initTest } from './test'
9
- // import tenantInfo from './tenantInfo'
10
- // import { downloadService } from './oss'
11
-
12
9
 
13
10
  const globalOptions: SPUWebPluginOptions = {
14
11
  modulekey: 'demospu',
@@ -17,14 +14,13 @@ const globalOptions: SPUWebPluginOptions = {
17
14
  router: null
18
15
  }
19
16
 
20
- let isInstall = false
21
-
22
17
  const install = (app: any, options: SPUWebPluginOptions) => {
23
18
  // console.log(app)
24
19
  // console.log(app.version)
25
- console.log('@smart100/spu-web-plugin options', options)
26
20
  merge(globalOptions, options)
27
- console.log('@smart100/spu-web-plugin globalOptions', globalOptions)
21
+ console.log('@smart100/spu-web-plugin start!')
22
+ console.log('options', options)
23
+ console.log('globalOptions', globalOptions)
28
24
 
29
25
  // if (install.installed) return
30
26
  // install.installed = true
@@ -40,31 +36,13 @@ const install = (app: any, options: SPUWebPluginOptions) => {
40
36
  // console.error('This plugin requires Vue App Instance')
41
37
  // }
42
38
 
43
-
44
39
  initStorageProxy(globalOptions)
45
40
  initAxios(globalOptions)
46
41
  initSpuConfig(globalOptions)
42
+ initApaasSpuTrack()
47
43
  urlquery.init()
48
44
  login.startRefreshtoken()
49
-
50
- // setTimeout(async () => {
51
- // const a = await downloadService.getUrl({
52
- // // source: 'a1b9954a-fb39-4bb2-aa0b-501f4af0d99e.jpeg',
53
- // // datetime: '1698832693257',
54
- // // source: '2f7dfe47-1827-4db1-9d99-3ddb08bb7e21.jpg',
55
- // // datetime: '1698832697897',
56
- // source: 'e3befbe5-8954-46d2-a368-5f812a5530e5.jpg',
57
- // datetime: '1699527237567',
58
- // // cope: {
59
- // // width: 100
60
- // // }
61
- // })
62
- // console.log(a)
63
- // console.log(71117)
64
- // }, 1000)
65
-
66
-
67
- // tenantInfo.getAndSave()
45
+ initTest(globalOptions)
68
46
 
69
47
  if (globalOptions.router) {
70
48
  globalOptions.router.beforeEach(async (to: any, from: any, next: any) => {
@@ -86,29 +64,11 @@ const install = (app: any, options: SPUWebPluginOptions) => {
86
64
  }
87
65
  })
88
66
  } else {
89
- console.error('请传入 router 实例。')
67
+ console.error('@smart100/spu-web-plugin require a vue-router instance.')
90
68
  }
91
-
92
-
93
- initTest(globalOptions)
94
-
95
- isInstall = true
96
-
97
- // Vue.component('xt-engine', components.engine)
98
- // Vue.prototype.$xtEngine = () => {
99
- // console.log('$xtEngine')
100
- // }
101
-
102
- // const component = options?.component
103
- // if (component) {
104
- // for (const x in component) {
105
- // register(x, component[x])
106
- // }
107
- // }
108
69
  }
109
70
 
110
71
  export {
111
72
  install,
112
- isInstall,
113
73
  globalOptions
114
74
  }
@@ -8,6 +8,7 @@ import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.
8
8
  // const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
9
9
  import dayjs from 'dayjs'
10
10
  import login from '../login'
11
+ import { apaasAxios } from '../axios'
11
12
  // import { get } from 'lodash-es'
12
13
  // import qs from 'qs'
13
14
 
@@ -193,27 +194,25 @@ const getUrl = async ({
193
194
  }
194
195
 
195
196
 
196
- const callDownloadManager = (url: string, filename: string) => {
197
- let aElm = document.createElement('a')
198
- aElm.innerHTML = filename + ''
197
+ const downloadFileByUrl = (url: string, filename: string) => {
198
+ const aElm = document.createElement('a')
199
+ aElm.innerHTML = filename
199
200
  aElm.download = filename
200
- let href = url
201
- aElm.href = href
202
- document.body.appendChild(aElm)
203
201
  aElm.target = '_blank'
202
+ aElm.href = url
203
+ document.body.appendChild(aElm)
204
204
  let evt = document.createEvent('MouseEvents')
205
205
  evt.initEvent('click', false, false)
206
206
  aElm.dispatchEvent(evt)
207
207
  document.body.removeChild(aElm)
208
208
  }
209
209
 
210
- const deal = (response: any, filename: string) => {
211
- let aElm = document.createElement('a')
212
- aElm.innerHTML = filename + ''
210
+ const downloadFileByBlob = (blob: any, filename: string) => {
211
+ const aElm = document.createElement('a')
212
+ aElm.innerHTML = filename
213
213
  aElm.download = filename
214
214
  aElm.target = '_blank'
215
- let href = window.URL.createObjectURL(response.bodyBlob)
216
- aElm.href = href
215
+ aElm.href = window.URL.createObjectURL(blob)
217
216
  document.body.appendChild(aElm)
218
217
  let evt = document.createEvent('MouseEvents')
219
218
  evt.initEvent('click', false, false)
@@ -233,23 +232,50 @@ const downloadFile = async ({
233
232
  if (!filename) {
234
233
  filename = source
235
234
  }
235
+
236
236
  const suffix = filename.slice(filename.lastIndexOf('.'))
237
- filename = filename.replace(suffix, '') + dayjs(+datetime).format('_YYYYMMDDHHmmssS') + String(Math.floor(Math.random() * 9000) + 1000) + suffix
237
+ const realFilename = filename.replace(suffix, '') + dayjs(+datetime).format('_YYYYMMDDHHmmssS') + String(Math.floor(Math.random() * 9000) + 1000) + suffix
238
238
 
239
239
  // console.log(filename)
240
-
241
240
  const url = await getUrl({
242
241
  type,
243
242
  source,
244
243
  datetime,
245
244
  storagetype,
246
- filename,
245
+ filename: realFilename,
247
246
  cope
248
247
  })
248
+ // apaasAxios.get(url, {
249
+ // responseType: 'blob',
250
+ // isSendToken: false,
251
+ // isShowErrorMessage: false
252
+ // }).then((response: any) => {
253
+ // // console.log(response)
254
+ // // debugger
255
+ // downloadFileByBlob(response.data, filename)
256
+ // }).catch((e) => {
257
+ // console.log(e)
258
+ // throw Error(e)
259
+ // })
249
260
 
250
- // console.log(url)
251
-
252
- callDownloadManager(url, filename)
261
+ const isAliYun = CloudServ.isAliyun(storagetype)
262
+ // const isHuawei = CloudServ.isHuawei(storagetype)
263
+ if (isAliYun) {
264
+ downloadFileByUrl(url, filename)
265
+ } else {
266
+ apaasAxios.get(url, {
267
+ responseType: 'blob',
268
+ isSendToken: false,
269
+ isShowErrorMessage: false
270
+ }).then((response: any) => {
271
+ // console.log(response)
272
+ // debugger
273
+ downloadFileByBlob(response.data, filename)
274
+ }).catch((e: any) => {
275
+ console.log(e)
276
+ throw Error(e)
277
+ })
278
+ }
253
279
  }
254
280
 
255
281
  export default {