@gx-design-vue/create-gx-cli 0.0.1 → 0.0.2

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.
Files changed (42) hide show
  1. package/package.json +1 -1
  2. package/template-mobile-ts/README.md +1 -16
  3. package/template-mobile-ts/build/plugin/index.ts +13 -1
  4. package/template-mobile-ts/build/script/postBuild.ts +15 -0
  5. package/template-mobile-ts/package.json +12 -5
  6. package/template-mobile-ts/postcss.config.js +5 -8
  7. package/template-mobile-ts/src/components/PageContainer/index.tsx +1 -0
  8. package/template-mobile-ts/src/core/vant-design/index.ts +0 -5
  9. package/template-mobile-ts/src/hooks/web/usePageLoading.ts +5 -8
  10. package/template-mobile-ts/src/main.ts +3 -1
  11. package/template-mobile-ts/src/{views → pages}/home.vue +1 -12
  12. package/template-mobile-ts/src/router/index.ts +3 -4
  13. package/template-mobile-ts/src/router/routes.ts +1 -1
  14. package/template-mobile-ts/src/settings/index.ts +10 -0
  15. package/template-mobile-ts/src/store/modules/global.ts +1 -4
  16. package/template-mobile-ts/src/utils/cryptoJS.ts +31 -17
  17. package/template-mobile-ts/src/utils/{index.ts → env.ts} +1 -1
  18. package/template-mobile-ts/src/utils/request/XHR.ts +131 -0
  19. package/template-mobile-ts/src/utils/request/axiosCancel.ts +60 -0
  20. package/template-mobile-ts/src/utils/request/checkStatus.ts +11 -0
  21. package/template-mobile-ts/src/utils/request/index.ts +143 -0
  22. package/template-mobile-ts/src/utils/request/typings.ts +114 -0
  23. package/template-mobile-ts/src/utils/storage.ts +191 -0
  24. package/template-mobile-ts/src/utils/validate.ts +0 -264
  25. package/template-mobile-ts/types/global.d.ts +16 -0
  26. package/template-mobile-ts/vite.config.ts +16 -2
  27. package/template-mobile-ts/pnpm-lock.yaml +0 -3890
  28. package/template-mobile-ts/src/utils/request.ts +0 -105
  29. package/template-vue-ts/.vscode/extensions.json +0 -3
  30. package/template-vue-ts/README.md +0 -18
  31. package/template-vue-ts/index.html +0 -13
  32. package/template-vue-ts/package.json +0 -20
  33. package/template-vue-ts/public/vite.svg +0 -1
  34. package/template-vue-ts/src/App.vue +0 -30
  35. package/template-vue-ts/src/assets/vue.svg +0 -1
  36. package/template-vue-ts/src/components/HelloWorld.vue +0 -38
  37. package/template-vue-ts/src/main.ts +0 -5
  38. package/template-vue-ts/src/style.css +0 -81
  39. package/template-vue-ts/src/vite-env.d.ts +0 -1
  40. package/template-vue-ts/tsconfig.json +0 -18
  41. package/template-vue-ts/tsconfig.node.json +0 -9
  42. package/template-vue-ts/vite.config.ts +0 -7
@@ -0,0 +1,143 @@
1
+ import { showFailToast } from 'vant'
2
+ import settings from '@/settings'
3
+ import { useStoreGlobal } from '@/store'
4
+ import { isDev } from '@/utils/env'
5
+ import { tansParams } from '@/utils/util'
6
+ import { checkURL } from '@/utils/validate'
7
+ import { isBoolean } from '@gx-design-vue/pro-utils'
8
+ import { GAxios } from './XHR'
9
+ import type { XhtInstance } from './typings'
10
+ import { RequestEnum } from './typings'
11
+ import type { GAxiosOptions } from './typings'
12
+ import { handleCode } from './checkStatus'
13
+
14
+ const { requestPrefix, successCode, requestTimeout, tokenName, contentType } = settings
15
+
16
+ const xhtInstance: XhtInstance = {
17
+ /**
18
+ * @description: 处理响应数据。如果数据不是预期格式,可直接抛出错误
19
+ */
20
+ transformResponseHook: (res, options) => {
21
+ const { customize, isReturnNativeResponse } = options
22
+ // 是否返回原生响应头 比如:需要获取响应头时使用该属性
23
+ if (isReturnNativeResponse) {
24
+ return res
25
+ }
26
+ // 不进行任何处理,直接返回
27
+ // 用于页面代码可能需要直接获取code,data,message这些信息时开启
28
+ if (customize) {
29
+ return res.data
30
+ }
31
+ // 错误的时候返回
32
+
33
+ const { data }: { data: ResponseResult } = res
34
+ if (!data) {
35
+ throw new Error('请求出错,请稍候重试')
36
+ }
37
+ // 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
38
+ const { code, msg = '', message = '' } = data
39
+
40
+ const codeVerificationArray = successCode
41
+
42
+ // 这里逻辑可以根据项目进行修改
43
+ const hasSuccess = codeVerificationArray.includes(code)
44
+ if (hasSuccess) {
45
+ return data
46
+ }
47
+
48
+ // 在此处根据自己项目的实际情况对不同的code执行不同的操作
49
+ // 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
50
+ handleCode(code, message || msg)
51
+
52
+ return Promise.resolve(false)
53
+ },
54
+
55
+ // 请求之前处理config
56
+ beforeRequestHook: (config) => {
57
+ // get请求映射params参数
58
+ if (config.method?.toUpperCase() === RequestEnum.GET && config.params) {
59
+ let url = config.url + '?' + tansParams(config.params)
60
+ url = url.slice(0, -1)
61
+ config.params = {}
62
+ config.url = url
63
+ }
64
+
65
+ if (!checkURL(config.url)) {
66
+ if (config.isMock) {
67
+ config.url = `/mock-server${config.url}`
68
+ } else {
69
+ config.url = `${import.meta.env.VITE_BASE_URL}${isDev ? requestPrefix || '' : ''}${config.url}`
70
+ }
71
+ }
72
+
73
+ return config
74
+ },
75
+
76
+ /**
77
+ * @description: 请求拦截器处理
78
+ */
79
+ requestInterceptors: (config) => {
80
+ const global = useStoreGlobal()
81
+ const carryToken = isBoolean(config.carryToken) ? config.carryToken : true
82
+ if (global.token && carryToken)
83
+ config.headers[tokenName] = global.token
84
+ return config
85
+ },
86
+
87
+ /**
88
+ * @description: 响应拦截器处理
89
+ */
90
+ responseInterceptors: (res) => {
91
+ return res
92
+ },
93
+
94
+ /**
95
+ * @description: 响应错误处理
96
+ */
97
+ responseInterceptorsCatch: (error: any) => {
98
+ const { response } = error
99
+ let errorMessage = error.message || ''
100
+ if (error.response && error.response.data) {
101
+ const { status } = response
102
+ handleCode(status, errorMessage)
103
+ return Promise.resolve(false)
104
+ } else {
105
+ if (errorMessage === 'Network Error') {
106
+ errorMessage = '后端接口连接异常'
107
+ }
108
+ if (errorMessage.includes('timeout')) {
109
+ errorMessage = '后端接口请求超时'
110
+ }
111
+ if (errorMessage.includes('Request failed with status code')) {
112
+ const code = errorMessage.substr(errorMessage.length - 3)
113
+ errorMessage = '后端接口' + code || '' + '异常'
114
+ }
115
+ showFailToast({ message: errorMessage || '服务器出错!' })
116
+ return Promise.resolve(false)
117
+ }
118
+ },
119
+ /**
120
+ * @description: 处理响应错误数据
121
+ */
122
+ requestCatchHook: () => false
123
+ }
124
+
125
+ function createXhr(opt ?: Partial<GAxiosOptions>) {
126
+ return new GAxios({
127
+ method: 'get',
128
+ timeout: requestTimeout,
129
+ headers: {
130
+ 'Content-Type': contentType
131
+ },
132
+ // 忽略重复请求
133
+ ignoreCancelToken: true,
134
+ // 是否携带token
135
+ carryToken: true,
136
+ ...xhtInstance,
137
+ ...opt
138
+ })
139
+ }
140
+
141
+ const request: (opt?: GAxiosOptions) => Promise<ResponseResult> = (opt) => createXhr().request(opt)
142
+
143
+ export default request
@@ -0,0 +1,114 @@
1
+ import type { AxiosRequestConfig, AxiosResponse, Axios, AxiosPromise } from 'axios'
2
+
3
+ export type XhtInstance = {
4
+ /**
5
+ * @Author gx12358
6
+ * @DateTime 2023/1/6
7
+ * @lastTime 2023/1/6
8
+ * @description 请求之前处理config
9
+ */
10
+ beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
11
+
12
+ /**
13
+ * @description: 处理响应数据
14
+ */
15
+ transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
16
+
17
+ /**
18
+ * @description: 请求失败处理
19
+ */
20
+ requestCatchHook?: (e: Error) => boolean;
21
+
22
+ /**
23
+ * @description: 请求之前的拦截器
24
+ */
25
+ requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
26
+
27
+ /**
28
+ * @description: 请求之后的拦截器
29
+ */
30
+ responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
31
+
32
+ /**
33
+ * @description: 请求之前的拦截器错误处理
34
+ */
35
+ requestInterceptorsCatch?: (error: Error) => void;
36
+
37
+ /**
38
+ * @description: 请求之后的拦截器错误处理
39
+ */
40
+ responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
41
+ }
42
+
43
+ export interface GAxiosOptions extends AxiosRequestConfig {
44
+ headers?: RecordType;
45
+ isMock?: boolean; // 是否是mock
46
+ isReturnNativeResponse?: boolean; // 直接返回response,不作任何处理(包含响应值等基本信息)
47
+ customize?: boolean; // 直接返回response.data(接口返回值),错误不做统一提示
48
+ carryToken?: boolean; // 是否携带token
49
+ ignoreCancelToken?: boolean; // 忽略重复请求
50
+ /**
51
+ * @Author gx12358
52
+ * @DateTime 2023/1/6
53
+ * @lastTime 2023/1/6
54
+ * @description 请求之前处理config
55
+ */
56
+ beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
57
+
58
+ /**
59
+ * @description: 处理响应数据
60
+ */
61
+ transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
62
+
63
+ /**
64
+ * @description: 请求失败处理
65
+ */
66
+ requestCatchHook?: (e: Error) => boolean;
67
+
68
+ /**
69
+ * @description: 请求之前的拦截器
70
+ */
71
+ requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
72
+
73
+ /**
74
+ * @description: 请求之后的拦截器
75
+ */
76
+ responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
77
+
78
+ /**
79
+ * @description: 请求之前的拦截器错误处理
80
+ */
81
+ requestInterceptorsCatch?: (error: Error) => void;
82
+
83
+ /**
84
+ * @description: 请求之后的拦截器错误处理
85
+ */
86
+ responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
87
+ }
88
+
89
+ export interface GAxiosInstance extends Axios {
90
+ (config: GAxiosOptions): AxiosPromise<ResponseResult>;
91
+
92
+ (url: string, config?: GAxiosOptions): AxiosPromise<ResponseResult>;
93
+ }
94
+
95
+ /**
96
+ * @description: request method
97
+ */
98
+ export enum RequestEnum {
99
+ GET = 'GET',
100
+ POST = 'POST',
101
+ PUT = 'PUT',
102
+ DELETE = 'DELETE',
103
+ }
104
+
105
+ /**
106
+ * @description: contentType
107
+ */
108
+ export enum ContentTypeEnum {
109
+ // json
110
+ JSON = 'application/json;charset=UTF-8',
111
+ // form-data qs
112
+ FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
113
+ }
114
+
@@ -0,0 +1,191 @@
1
+ import dayjs from 'dayjs'
2
+ import { isPro } from '@/utils/env'
3
+ import { Decrypt, Encrypt } from '@/utils/cryptoJS'
4
+ import { isJSONStr } from '@/utils/validate'
5
+ import { isObject } from '@gx-design-vue/pro-utils'
6
+
7
+ function isEncryption(status: boolean) {
8
+ return isPro() ? status : false
9
+ }
10
+
11
+ function handleStorageValue(value: string) {
12
+ if (isJSONStr(value)) return JSON.parse(value)
13
+ return value
14
+ }
15
+
16
+ /**
17
+ * @Author gx12358
18
+ * @DateTime 2019/12/3
19
+ * @lastTime 2019/12/3
20
+ * @description 设置Local-key的规则
21
+ */
22
+ export function getStorageKey(key: string, originKey?: boolean) {
23
+ const { pkg } = __APP_INFO__
24
+ const { VITE_USE_MODE, VITE_APP_ENV } = import.meta.env
25
+ return originKey ? key : `live_${pkg.version}_${VITE_APP_ENV === 'dev'
26
+ ? 'development'
27
+ : VITE_USE_MODE}_${key}`
28
+ }
29
+
30
+ /**
31
+ * @Author gx12358
32
+ * @DateTime 2019/12/3
33
+ * @lastTime 2019/12/3
34
+ * @description 获取Storage
35
+ */
36
+ export function getStorage({
37
+ key,
38
+ encryption = true,
39
+ type = 'local',
40
+ originKey
41
+ }: { key: string, encryption?: boolean, type?: string, originKey?: boolean }) {
42
+ const storageValue = type === 'local' ?
43
+ localStorage.getItem(getStorageKey(key, originKey))
44
+ : sessionStorage.getItem(getStorageKey(key, originKey))
45
+ const result: string | LocalResult = storageValue ?
46
+ isEncryption(encryption) ? Decrypt(storageValue) : handleStorageValue(storageValue)
47
+ : ''
48
+ if (result && isObject(result)) {
49
+ if (result.expired) {
50
+ const expiredStatus = dayjs().diff(dayjs(result.time)) >= result.expired
51
+ if (expiredStatus) {
52
+ removeStorage(key, type)
53
+ return ''
54
+ }
55
+ }
56
+ }
57
+ return result?.['value'] || result || ''
58
+ }
59
+
60
+ /**
61
+ * @Author gx12358
62
+ * @DateTime 2019/12/3
63
+ * @lastTime 2019/12/3
64
+ * @description 设置Storage
65
+ */
66
+ export function setStorage({
67
+ key,
68
+ value,
69
+ expired,
70
+ originKey,
71
+ encryption = true,
72
+ type = 'local'
73
+ }: {
74
+ key: string;
75
+ value: any;
76
+ originKey?: boolean;
77
+ expired?: number;
78
+ encryption?: boolean;
79
+ type?: string;
80
+ }) {
81
+ const result: LocalResult = originKey ? value : {
82
+ value,
83
+ time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
84
+ expired: expired || 0
85
+ }
86
+ const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(result)
87
+ if (type === 'local') localStorage.setItem(getStorageKey(key, originKey), storageValue)
88
+ sessionStorage.setItem(getStorageKey(key, originKey), storageValue)
89
+ }
90
+
91
+ /**
92
+ * @Author gx12358
93
+ * @DateTime 2019/12/3
94
+ * @lastTime 2019/12/3
95
+ * @description 删除Storage
96
+ */
97
+ export function removeStorage(key: string, type = 'local', originKey?: boolean) {
98
+ if (type === 'local') localStorage.removeItem(getStorageKey(key, originKey))
99
+ sessionStorage.removeItem(getStorageKey(key, originKey))
100
+ }
101
+
102
+ /**
103
+ * @Author gx12358
104
+ * @DateTime 2019-09-24
105
+ * @lastTime 2019-09-24
106
+ * @description 获取Cookie-name
107
+ */
108
+ function getCookies(cname: string) {
109
+ const name = `${cname}=`
110
+ const decodedCookie = decodeURIComponent(document.cookie)
111
+ const ca = decodedCookie.split(';')
112
+ for (let i = 0; i < ca.length; i += 1) {
113
+ let c = ca[i]
114
+ while (c.charAt(0) === ' ') {
115
+ c = c.substring(1)
116
+ }
117
+ if (c.indexOf(name) === 0) {
118
+ return decodeURIComponent(c.substring(name.length, c.length))
119
+ }
120
+ }
121
+ return ''
122
+ }
123
+
124
+ /**
125
+ * @Author gx12358
126
+ * @DateTime 2019-09-24
127
+ * @lastTime 2019-09-24
128
+ * @description 获取Cookiedomin
129
+ */
130
+ function GetCookieDomain() {
131
+ let host = location.hostname
132
+ const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
133
+ if (ip.test(host) === true || host === 'localhost') return host
134
+ const regex = /([^]*).*/
135
+ const match = host.match(regex)
136
+ if (typeof match !== 'undefined' && match !== null) {
137
+ const someIndex = 1
138
+ host = match[someIndex]
139
+ }
140
+ if (typeof host !== 'undefined' && host !== null) {
141
+ const strAry = host.split('.')
142
+ if (strAry.length > 1) {
143
+ host = `${strAry[strAry.length - 2]}.${strAry[strAry.length - 1]}`
144
+ }
145
+ }
146
+ return `.${host}`
147
+ }
148
+
149
+ /**
150
+ * @Author gx12358
151
+ * @DateTime 2019-09-24
152
+ * @lastTime 2019-09-24
153
+ * @description 设置Cookie
154
+ */
155
+ export function setCookie(cname: string, cvalue: string, exdays?: number) {
156
+ const d = new Date()
157
+ d.setTime(d.getTime() + (exdays || 365) * 24 * 60 * 60 * 1000)
158
+ const expires = `=${d.toUTCString()}`
159
+ document.cookie = `${cname}=${encodeURIComponent(
160
+ cvalue
161
+ )}; expires=${expires}; domain=${GetCookieDomain()}; path=/`
162
+ }
163
+
164
+ /**
165
+ * @Author gx12358
166
+ * @DateTime 2019-09-24
167
+ * @lastTime 2019-09-24
168
+ * @description 获取Cookie
169
+ */
170
+ export function getCookie(cname: string) {
171
+ const result = getCookies(cname)
172
+ if (result === '') {
173
+ return ''
174
+ }
175
+ return decodeURIComponent(result)
176
+ }
177
+
178
+ /**
179
+ * @Author gx12358
180
+ * @DateTime 2019-09-24
181
+ * @lastTime 2019-09-24
182
+ * @description 删除Cookie
183
+ */
184
+ export function delCookie(name: string) {
185
+ const exp = new Date()
186
+ exp.setTime(exp.getTime() - 1)
187
+ const cval = getCookies(name)
188
+ if (cval !== null) {
189
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=${GetCookieDomain()}; path=/`
190
+ }
191
+ }
@@ -1,267 +1,3 @@
1
- const toString = Object.prototype.toString
2
-
3
- export function is(val: unknown, type: string) {
4
- return toString.call(val) === `[object ${type}]`
5
- }
6
-
7
- export const isClient = typeof window !== 'undefined'
8
-
9
- export const noop = () => {}
10
-
11
- /**
12
- * @author gx12358 2539306317@qq.com
13
- * @description 判读是否为外链
14
- * @param path
15
- * @returns {boolean}
16
- */
17
- export function isExternal(path) {
18
- return /^(https?:|mailto:|tel:)/.test(path)
19
- }
20
-
21
- /**
22
- * @author gx12358 2539306317@qq.com
23
- * @description 校验密码是否小于6位
24
- * @param value
25
- * @returns {boolean}
26
- */
27
- export function isPassword(value) {
28
- return value.length >= 6
29
- }
30
-
31
- /**
32
- * @author gx12358 2539306317@qq.com
33
- * @description 判断是否为数字
34
- * @param value
35
- * @returns {boolean}
36
- */
37
- export function isNumber(val: unknown) {
38
- return typeof val === 'number'
39
- }
40
-
41
- /**
42
- * @author gx12358 2539306317@qq.com
43
- * @description 判断是否是名称
44
- * @param value
45
- * @returns {boolean}
46
- */
47
- export function isName(value) {
48
- const reg = /^[\u4e00-\u9fa5a-zA-Z0-9]+$/
49
- return reg.test(value)
50
- }
51
-
52
- /**
53
- * @author gx12358 2539306317@qq.com
54
- * @description 判断是否为IP
55
- * @param ip
56
- * @returns {boolean}
57
- */
58
- export function isIP(ip) {
59
- const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
60
- return reg.test(ip)
61
- }
62
-
63
- /**
64
- * @author gx12358 2539306317@qq.com
65
- * @description 判断是否是传统网站
66
- * @param url
67
- * @returns {boolean}
68
- */
69
- export function isUrl(url) {
70
- const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
71
- return reg.test(url)
72
- }
73
-
74
- /**
75
- * @author gx12358 2539306317@qq.com
76
- * @description 判断是否是小写字母
77
- * @param value
78
- * @returns {boolean}
79
- */
80
- export function isLowerCase(value) {
81
- const reg = /^[a-z]+$/
82
- return reg.test(value)
83
- }
84
-
85
- /**
86
- * @author gx12358 2539306317@qq.com
87
- * @description 判断是否是大写字母
88
- * @param value
89
- * @returns {boolean}
90
- */
91
- export function isUpperCase(value) {
92
- const reg = /^[A-Z]+$/
93
- return reg.test(value)
94
- }
95
-
96
- /**
97
- * @author gx12358 2539306317@qq.com
98
- * @description 判断是否是大写字母开头
99
- * @param value
100
- * @returns {boolean}
101
- */
102
- export function isAlphabets(value) {
103
- const reg = /^[A-Za-z]+$/
104
- return reg.test(value)
105
- }
106
-
107
- /**
108
- * @author gx12358 2539306317@qq.com
109
- * @description 判断是否是字符串
110
- * @param value
111
- * @returns {boolean}
112
- */
113
- export function isString(value) {
114
- return typeof value === 'string' || value instanceof String
115
- }
116
-
117
- export function isBoolean(val: unknown): val is boolean {
118
- return is(val, 'Boolean')
119
- }
120
-
121
- export function isFunction(func: any) {
122
- return (typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]')
123
- }
124
-
125
- /**
126
- * @author gx12358 2539306317@qq.com
127
- * @description 判断是否是数组
128
- * @param arg
129
- * @returns {arg is any[]|boolean}
130
- */
131
- export function isArray(arg) {
132
- if (typeof Array.isArray === 'undefined') {
133
- return Object.prototype.toString.call(arg) === '[object Array]'
134
- }
135
- return Array.isArray(arg)
136
- }
137
-
138
- /**
139
- * @Author gaoxiang
140
- * @DateTime 2019/11/29
141
- * @lastTime 2019/11/29
142
- * @description 是否是对象
143
- */
144
- export function isObject(val: any): val is Record<any, any> {
145
- return val !== null && is(val, 'Object')
146
- }
147
-
148
- /**
149
- * @author gx12358 2539306317@qq.com
150
- * @description 判断是否是端口号
151
- * @param value
152
- * @returns {boolean}
153
- */
154
- export function isPort(value) {
155
- const reg = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/
156
- return reg.test(value)
157
- }
158
-
159
- /**
160
- * @author gx12358 2539306317@qq.com
161
- * @description 判断是否是手机号
162
- * @param value
163
- * @returns {boolean}
164
- */
165
- export function isPhone(value) {
166
- const reg = /^1\d{10}$/
167
- return reg.test(value)
168
- }
169
-
170
- /**
171
- * @author gx12358 2539306317@qq.com
172
- * @description 判断是否是身份证号(第二代)
173
- * @param value
174
- * @returns {boolean}
175
- */
176
- export function isIdCard(value) {
177
- const reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
178
- return reg.test(value)
179
- }
180
-
181
- /**
182
- * @author gx12358 2539306317@qq.com
183
- * @description 判断是否是邮箱
184
- * @param value
185
- * @returns {boolean}
186
- */
187
- export function isEmail(value) {
188
- const reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
189
- return reg.test(value)
190
- }
191
-
192
- /**
193
- * @author gx12358 2539306317@qq.com
194
- * @description 判断是否中文
195
- * @param value
196
- * @returns {boolean}
197
- */
198
- export function isChina(value) {
199
- const reg = /^[\u4E00-\u9FA5]{2,4}$/
200
- return reg.test(value)
201
- }
202
-
203
- /**
204
- * @author gx12358 2539306317@qq.com
205
- * @description 判断是否为空
206
- * @param value
207
- * @returns {boolean}
208
- */
209
- export function isBlank(value) {
210
- return (
211
- value == null ||
212
- false ||
213
- value === '' ||
214
- value.trim() === '' ||
215
- value.toLocaleLowerCase().trim() === 'null'
216
- )
217
- }
218
-
219
- /**
220
- * @author gx12358 2539306317@qq.com
221
- * @description 判断是否为固话
222
- * @param value
223
- * @returns {boolean}
224
- */
225
- export function isTel(value) {
226
- const reg = /^(400|800)([0-9\\-]{7,10})|(([0-9]{4}|[0-9]{3})([- ])?)?([0-9]{7,8})(([- 转])*([0-9]{1,4}))?$/
227
- return reg.test(value)
228
- }
229
-
230
- /**
231
- * @author gx12358 2539306317@qq.com
232
- * @description 判断经度 -180.0~+180.0(整数部分为0~180,必须输入1到5位小数)
233
- * @param value
234
- * @returns {boolean}
235
- */
236
- export function isLongitude(value) {
237
- const reg = /^[-|+]?(0?\d{1,2}\.\d{1,5}|1[0-7]?\d{1}\.\d{1,5}|180\.0{1,5})$/
238
- return reg.test(value)
239
- }
240
-
241
- /**
242
- * @author gx12358 2539306317@qq.com
243
- * @description 判断纬度 -90.0~+90.0(整数部分为0~90,必须输入1到5位小数)
244
- * @param value
245
- * @returns {boolean}
246
- */
247
- export function isLatitude(value) {
248
- const reg = /^[-|+]?([0-8]?\d{1}\.\d{1,5}|90\.0{1,5})$/
249
- return reg.test(value)
250
- }
251
-
252
- /**
253
- * @author gx12358 2539306317@qq.com
254
- * @description rtsp校验,只要有rtsp://
255
- * @param value
256
- * @returns {boolean}
257
- */
258
- export function isRTSP(value) {
259
- const reg = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
260
- const reg1 = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):[0-9]{1,5}/
261
- const reg2 = /^rtsp:\/\/([a-z]{0,10}:.{0,10}@)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\//
262
- return reg.test(value) || reg1.test(value) || reg2.test(value)
263
- }
264
-
265
1
  /**
266
2
  * @Author gaoxiang
267
3
  * @DateTime 2020/11/4