@smart100/spu-web-plugin 0.0.4 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "rollup -c -w",
package/src/index.ts CHANGED
@@ -4,6 +4,10 @@ import { lsProxy, ssProxy } from './storageProxy'
4
4
  import { getLocation, getDistance } from './location'
5
5
  import { spuAxios, apaasAxios } from './axios'
6
6
  import { downloadService, uploadService } from './oss'
7
+ import { getUniqueid } from './utils'
8
+ import AMapLoader from './AMapLoader'
9
+ import login from './login'
10
+ import { v4 as uuid } from 'uuid'
7
11
  // import { downloadService } from './oss'
8
12
 
9
13
  // class SPUWebPlugin {
@@ -18,6 +22,14 @@ const SPUWebPlugin = {
18
22
  version
19
23
  }
20
24
 
25
+
26
+ const getToken = login.getToken.bind(login)
27
+ const getTokenExpires = login.getTokenExpires.bind(login)
28
+ const getRefreshToken = login.getRefreshToken.bind(login)
29
+ const getUser = login.getUser.bind(login)
30
+ const checkLogin = login.checkLogin.bind(login)
31
+
32
+
21
33
  export {
22
34
  SPUWebPlugin as default,
23
35
  lsProxy,
@@ -27,5 +39,13 @@ export {
27
39
  spuAxios,
28
40
  apaasAxios,
29
41
  downloadService,
30
- uploadService
42
+ uploadService,
43
+ getUniqueid,
44
+ uuid,
45
+ AMapLoader,
46
+ getToken,
47
+ getTokenExpires,
48
+ getRefreshToken,
49
+ getUser,
50
+ checkLogin
31
51
  }
package/src/location.ts CHANGED
@@ -181,6 +181,25 @@ const getDistance = async (p1: [number, number], p2: [number, number]) => {
181
181
  return AMap.GeometryUtil.distance(p1, p2)
182
182
  }
183
183
 
184
+
185
+ // // 两个经纬度距离计算
186
+ // function getDistance (latlng1, latlng2) {
187
+ // console.log(latlng1)
188
+ // console.log(latlng2)
189
+ // const lng1 = Number(latlng1[0])
190
+ // const lat1 = Number(latlng1[1])
191
+ // const lng2 = Number(latlng2[0])
192
+ // const lat2 = Number(latlng2[1])
193
+ // const radLat1 = (lat1 * Math.PI) / 180.0
194
+ // const radLat2 = (lat2 * Math.PI) / 180.0
195
+ // const a = radLat1 - radLat2
196
+ // const b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0
197
+ // let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
198
+ // s = s * 6378.137 // EARTH_RADIUS
199
+ // s = Math.round(s * 10000) / 10000
200
+ // return s * 1000
201
+ // }
202
+
184
203
  export {
185
204
  getLocation,
186
205
  getDistance
@@ -60,6 +60,15 @@ const getContentType = (suffix: string) => {
60
60
 
61
61
 
62
62
  type Cope = { width?: number, height?: number } | string | boolean
63
+ interface IDownload {
64
+ type?: 'att' | 'img',
65
+ source: string,
66
+ datetime: string | number,
67
+ storagetype?: StorageType,
68
+ cope?: Cope
69
+ }
70
+
71
+
63
72
 
64
73
  const getNormalizeAliOssCope = (cope?: Cope) => {
65
74
  let copeObj = ''
@@ -83,13 +92,7 @@ const getNormalizeAliOssCope = (cope?: Cope) => {
83
92
  }
84
93
 
85
94
 
86
- interface IDownload {
87
- type?: 'att' | 'img',
88
- source: string,
89
- datetime: string | number,
90
- storagetype?: StorageType,
91
- cope?: Cope
92
- }
95
+
93
96
 
94
97
  // 根据文件信息最后生成一个云文件服务可以用的链接http://xxxxx.xxx.jpg
95
98
  const getUrl = async ({
@@ -1,26 +1,93 @@
1
1
  import type { App } from 'vue'
2
2
  // import type { AxiosInstance } from 'axios'
3
3
 
4
- interface SPUWebPluginOptions {
5
- modulekey: string;
6
- modulename: string;
7
- moduleversion: string;
8
- router: any;
4
+ interface ISPUWebPluginOptions {
5
+ modulekey: string
6
+ modulename: string
7
+ moduleversion: string
8
+ router: any
9
9
  }
10
10
 
11
+ interface IAMapLoader {
12
+ load: (options?: {
13
+ plugins?: Array<string>
14
+ AMapUI?: {
15
+ plugins?: Array<string>
16
+ }
17
+ }) => Promise<any>
18
+ }
19
+
20
+
21
+ type Cope = { width?: number, height?: number } | string | boolean
22
+
23
+ interface IDownload {
24
+ type?: 'att' | 'img',
25
+ source: string,
26
+ datetime: string | number,
27
+ storagetype?: StorageType,
28
+ cope?: Cope
29
+ }
30
+
31
+ interface IDownloadService {
32
+ getUrl: ({
33
+ type = 'img',
34
+ source = '',
35
+ datetime = '',
36
+ storagetype = 'storage',
37
+ cope = ''
38
+ }: IDownload) => Promise<any>
39
+ }
40
+
41
+
42
+ interface IUpload {
43
+ type?: 'att' | 'img',
44
+ file: File,
45
+ source?: string,
46
+ datetime?: string | number,
47
+ storagetype?: StorageType,
48
+ onprogress?: (p: number, _checkpoint?: IAny) => void
49
+ }
50
+
51
+ interface IUploadService {
52
+ upload: ({
53
+ type = 'img',
54
+ file,
55
+ source = '',
56
+ datetime = '',
57
+ storagetype = 'storage',
58
+ onprogress,
59
+ }: IUpload) => Promise<any>
60
+ }
61
+
62
+
63
+ type Location = {
64
+ longitude: string
65
+ latitude: string
66
+ address: string
67
+ [propName: string]: any
68
+ } | null
69
+
70
+
11
71
  export const lsProxy: any
12
72
  export const ssProxy: any
13
- export const getLocation: any
14
- export const getDistance: any
73
+ export const getLocation: () => Promise<Location>
74
+ export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
15
75
  export const spuAxios: any
16
76
  // export const spuAxios: AxiosInstance
17
77
  export const apaasAxios: any
18
- export const downloadService: any
19
- export const uploadService: any
20
-
78
+ export const downloadService: IDownloadService
79
+ export const uploadService: IUploadService
80
+ export const getUniqueid: () => string
81
+ export const uuid: () => string
82
+ export const AMapLoader: IAMapLoader
83
+ export const getToken: () => string
84
+ export const getTokenExpires: () => string
85
+ export const getRefreshToken: () => string
86
+ export const getUser: (key?: string) => any
87
+ export const checkLogin: () => boolean
21
88
 
22
89
  interface ISPUWebPlugin {
23
- install (app: App, option: SPUWebPluginOptions): void
90
+ install (app: App, option: ISPUWebPluginOptions): void
24
91
  // install: any
25
92
  version: string
26
93
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,8 @@
1
+ const isIOS = () => {
2
+ const ua = navigator.userAgent
3
+ return /(iPhone|iPad|iPod|IOS)/i.test(ua)
4
+ }
5
+
1
6
  // 是否企微软件内 包括电脑端和APP端
2
7
  const isInWxwork = () => {
3
8
  return navigator.userAgent.indexOf('wxwork') >= 0
@@ -13,8 +18,19 @@ const isInAppWxwork = () => {
13
18
  return isInWxwork() && navigator.userAgent.indexOf('Mobile') >= 0
14
19
  }
15
20
 
21
+ // 生成唯一id
22
+ const getUniqueid = () => {
23
+ const random = Math.ceil(Math.random() * 100000)
24
+ // TODO:生成的id不能以0开头,在数据库存储转换长整型会被消除,导致唯一编码错误存储
25
+ // TODO: 不能与服务端返回的idarray在未来产生重叠,用9开头(应该够用许多年了?)
26
+ return `9${Date.now()}${random}`
27
+ }
28
+
29
+
16
30
  export {
31
+ isIOS,
17
32
  isInWxwork,
18
33
  isInPcWxwork,
19
- isInAppWxwork
34
+ isInAppWxwork,
35
+ getUniqueid
20
36
  }