@gindow/element-go 1.0.0
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 +260 -0
- package/dist/element-go.cjs +1 -0
- package/dist/element-go.d.ts +1 -0
- package/dist/element-go.mjs +2994 -0
- package/dist/resolver.cjs +1 -0
- package/dist/resolver.d.ts +1 -0
- package/dist/resolver.mjs +16 -0
- package/dist/styles/index.css +2 -0
- package/package.json +133 -0
- package/src/assets/avatar.png +0 -0
- package/src/assets/icon.png +0 -0
- package/src/components/ExAssetPreview.vue +55 -0
- package/src/components/ExButton.vue +47 -0
- package/src/components/ExEmpty.vue +26 -0
- package/src/components/ExForm.vue +95 -0
- package/src/components/ExFormField.vue +49 -0
- package/src/components/ExFormSearch.vue +50 -0
- package/src/components/ExFormViewer.vue +51 -0
- package/src/components/ExIcon.vue +33 -0
- package/src/components/ExInputPercentage.vue +36 -0
- package/src/components/ExLayout/account.vue +33 -0
- package/src/components/ExLayout/aside.vue +58 -0
- package/src/components/ExLayout/lang.vue +27 -0
- package/src/components/ExLayout.vue +91 -0
- package/src/components/ExLoading.vue +18 -0
- package/src/components/ExMenu.vue +80 -0
- package/src/components/ExPage.vue +66 -0
- package/src/components/ExPageHeader.vue +34 -0
- package/src/components/ExPagination.vue +34 -0
- package/src/components/ExSelect.vue +28 -0
- package/src/components/ExTable.vue +237 -0
- package/src/components/ExTableColumn.vue +160 -0
- package/src/components/ExUpload.vue +91 -0
- package/src/components/ExUploadAsset.vue +299 -0
- package/src/components/vIcon.vue +23 -0
- package/src/env.d.ts +7 -0
- package/src/hooks/useBreak.ts +23 -0
- package/src/hooks/useChat.ts +135 -0
- package/src/hooks/useIcon.ts +8 -0
- package/src/hooks/useMessage.ts +22 -0
- package/src/hooks/useNanoid.ts +9 -0
- package/src/hooks/useUpload.ts +60 -0
- package/src/index.ts +94 -0
- package/src/libs/auto-imports.d.ts +94 -0
- package/src/libs/components.d.ts +171 -0
- package/src/locale/en-US.ts +49 -0
- package/src/locale/index.ts +73 -0
- package/src/locale/zh-CN.ts +49 -0
- package/src/resolver.ts +26 -0
- package/src/styles/arco.css +179 -0
- package/src/styles/index.css +53 -0
- package/src/types/index.ts +77 -0
- package/src/utils/datetime.ts +42 -0
- package/src/utils/download.ts +11 -0
- package/src/utils/formatter.ts +42 -0
- package/src/utils/get.ts +10 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/params.ts +18 -0
- package/src/utils/platform.ts +38 -0
- package/src/utils/request.ts +144 -0
- package/src/utils/validate.ts +23 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios'
|
|
2
|
+
import { $params } from './params'
|
|
3
|
+
import { Platform } from './platform'
|
|
4
|
+
// import JSEncrypt from 'jsencrypt'
|
|
5
|
+
import cookie from 'js-cookie'
|
|
6
|
+
import axios from 'axios'
|
|
7
|
+
|
|
8
|
+
export const request = {
|
|
9
|
+
|
|
10
|
+
baseURL: '',
|
|
11
|
+
publicKey: '',
|
|
12
|
+
headers: { Accept: 'application/json' } as Record<string, string>,
|
|
13
|
+
instance: null as AxiosInstance|null,
|
|
14
|
+
accessToken: 'accessToken',
|
|
15
|
+
|
|
16
|
+
init (config: { baseURL?: string, publicKey?: string } = {}) {
|
|
17
|
+
this.baseURL = config.baseURL ?? ''
|
|
18
|
+
this.publicKey = config.publicKey ?? ''
|
|
19
|
+
|
|
20
|
+
const reload = () => {
|
|
21
|
+
this.delToken()
|
|
22
|
+
location.reload()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.instance = axios.create({ baseURL: this.baseURL })
|
|
26
|
+
|
|
27
|
+
this.instance.interceptors.request.use(config => {
|
|
28
|
+
const language = localStorage.getItem('locale')
|
|
29
|
+
if (language) config.headers['Accept-Language'] = language
|
|
30
|
+
return config
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
this.instance.interceptors.response.use((response: AxiosResponse) => {
|
|
34
|
+
if (response.config.responseType === 'blob') return response // 下载文件
|
|
35
|
+
else if (response.data.code === 401) return reload() // 登陆过期
|
|
36
|
+
else if (response.data.code === 200) return response.data
|
|
37
|
+
else return Promise.reject(response.data)
|
|
38
|
+
}, ({ response }) => Promise.reject(response.data))
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
setToken (token: string, options: { expires?: number, domain?: string } = {}) {
|
|
42
|
+
options = { ...options, domain: '.' + location.hostname }
|
|
43
|
+
cookie.set(this.accessToken, token, options)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
getToken () {
|
|
47
|
+
return cookie.get(this.accessToken) || ''
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
delToken () {
|
|
51
|
+
cookie.remove(this.accessToken, { domain: '.' + location.hostname })
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
get (url: string, params?: {}, auth = false) { return this.request({ method: 'GET', url, params }, auth) },
|
|
55
|
+
put (url: string, data?: {}, auth = false) { return this.request({ method: 'PUT', url, data }, auth) },
|
|
56
|
+
patch (url: string, data?: {}, auth = false) { return this.request({ method: 'PATCH', url, data }, auth) },
|
|
57
|
+
delete (url: string, params?: {}, auth = false) { return this.request({ method: 'DELETE', url, params }, auth) },
|
|
58
|
+
post (url: string, data?: {}, auth = false) { return this.request({ method: 'POST', url, data }, auth) },
|
|
59
|
+
blob (url: string, params?: {}, auth = false) { return this.request({ method: 'GET', url, params, responseType: 'blob' }, auth) },
|
|
60
|
+
|
|
61
|
+
request(para: any, auth: boolean = false) {
|
|
62
|
+
const headers = para.headers ?? this.headers
|
|
63
|
+
if (auth) headers.Authorization = 'Bearer ' + this.getToken()
|
|
64
|
+
if (para.params) para.params = $params(para.params)
|
|
65
|
+
return (this.instance as any)({ ...para, headers })
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// encryptPost(url: string, data?: {}, auth = false) {
|
|
69
|
+
// const encryptor = new JSEncrypt()
|
|
70
|
+
// encryptor.setPublicKey(this.publicKey)
|
|
71
|
+
// const encryptLong = (str: string) => {
|
|
72
|
+
// let maxChunkLength = 200, output = '', inOffset = 0;
|
|
73
|
+
// while (inOffset < str.length) {
|
|
74
|
+
// output += encryptor.encrypt(str.substring(inOffset, inOffset + maxChunkLength))
|
|
75
|
+
// inOffset += maxChunkLength
|
|
76
|
+
// }
|
|
77
|
+
// return output
|
|
78
|
+
// }
|
|
79
|
+
// data = encryptLong(JSON.stringify(data))
|
|
80
|
+
// return this.request({ method: 'post', url, data }, auth)
|
|
81
|
+
// },
|
|
82
|
+
|
|
83
|
+
async download(url: string, params?: {}, filename?: string, auth = false) {
|
|
84
|
+
const ret = await this.blob(url, params, auth)
|
|
85
|
+
if (Platform.isFlutter) return ret
|
|
86
|
+
const getResponseFileName = () => {
|
|
87
|
+
const disposition = ret.headers['content-disposition']
|
|
88
|
+
const parts = disposition.split("filename*=")
|
|
89
|
+
const val = parts[1].split(";")[0].trim()
|
|
90
|
+
return decodeURIComponent(val.replace(/^UTF-8''/i, ''))
|
|
91
|
+
}
|
|
92
|
+
let link = document.createElement('a')
|
|
93
|
+
link.href = window.URL.createObjectURL(ret.data)
|
|
94
|
+
link.download = filename ?? getResponseFileName()
|
|
95
|
+
link.click()
|
|
96
|
+
return ret
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
async upload(url: string, data = {}) {
|
|
100
|
+
const headers ={ ...this.headers, 'Content-Type': 'multipart/form-data' }
|
|
101
|
+
return this.instance!.post(url, data, { headers })
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
sse (url: string, para?: {[key: string]: string | number | undefined | null | void} | null) {
|
|
105
|
+
const params = para ? Object.keys(para).map(key => key +'='+ para[key]).join('&') : ''
|
|
106
|
+
return new EventSource(this.baseURL + '/' + url + '?' + params)
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
setHeader(key: string, value: string) {
|
|
110
|
+
this.headers[key] = value
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
delHeader(key: string) {
|
|
114
|
+
delete this.headers[key]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class resource {
|
|
119
|
+
|
|
120
|
+
url: string
|
|
121
|
+
auth: boolean
|
|
122
|
+
|
|
123
|
+
constructor(url: string, auth = false) {
|
|
124
|
+
this.url = url
|
|
125
|
+
this.auth = auth
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
select = (para?: {}) => request.get(this.url, para, this.auth)
|
|
129
|
+
|
|
130
|
+
create = (para?: {}) => request.post(this.url, para, this.auth)
|
|
131
|
+
|
|
132
|
+
find = (id: string, para?: {}) => request.get(this.url + '/' + id, para, this.auth)
|
|
133
|
+
|
|
134
|
+
update = (id: string, para?: {}) => request.patch(this.url + '/' + id, para, this.auth)
|
|
135
|
+
|
|
136
|
+
delete = (id: string, para?: {}) => request.delete(this.url + '/' + id, para, this.auth)
|
|
137
|
+
|
|
138
|
+
async get(para: any) {
|
|
139
|
+
para.size = 1
|
|
140
|
+
const ret = await this.select(para)
|
|
141
|
+
ret.data = ret.data[0] || {}
|
|
142
|
+
return ret
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class Validate {
|
|
2
|
+
|
|
3
|
+
static country: string = '' // 国家
|
|
4
|
+
|
|
5
|
+
static set = (country: string) => this.country = country
|
|
6
|
+
|
|
7
|
+
static get phone_pattern () {
|
|
8
|
+
return this.country.toUpperCase() === 'CN'
|
|
9
|
+
? /([1][3,4,5,6,7,8,9][0-9]{9})$/
|
|
10
|
+
: /^(?:\+?[1-9]\d{7,14}|\d{6,11})$/
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static email_pattern = /^([a-zA-Z0-9_\.-]+)@([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})$/
|
|
14
|
+
static idcard_pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
|
|
15
|
+
static cname_pattern = /^(?:[一-龥·]{2,16})$/
|
|
16
|
+
static password_pattern = /^(?![A-Za-z]+$)(?![0-9]+$)(?![^A-Za-z0-9]+$).{8,20}$/
|
|
17
|
+
|
|
18
|
+
// 校验方法
|
|
19
|
+
static phone = (str: string) => Validate.phone_pattern.test(str)
|
|
20
|
+
static email = (str: string) => Validate.email_pattern.test(str)
|
|
21
|
+
static idcard = (str: string) => Validate.idcard_pattern.test(str)
|
|
22
|
+
static cname = (str: string) => Validate.cname_pattern.test(str)
|
|
23
|
+
}
|