@kengic/uni 0.6.3-beta.23 → 0.6.3-beta.24

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.
@@ -1,21 +1,21 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
- import * as DEF from '../../../def';
5
- import { keys } from '../../models';
6
-
7
- /** 请求参数. */
8
- export class GetLatestApkVersionQuery {}
9
-
10
- /**
11
- * 获取 APK 最新的版本号.
12
- *
13
- * @param config 请求配置.
14
- * @param option 请求选项.
15
- */
16
- export function GetLatestApkVersion(config?: IRequestConfig<GetLatestApkVersionQuery, {}>, option?: IRequestOptions): Promise<string> {
17
- return httpClient().request({ method: GetLatestApkVersion.method, url: GetLatestApkVersion.url, ...(config ?? {}) }, option);
18
- }
19
-
20
- GetLatestApkVersion.method = 'GET' as const;
21
- GetLatestApkVersion.url = '/sys/common/getLatestApkVersion';
1
+ // noinspection ES6UnusedImports
2
+
3
+ import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
+ import * as DEF from '../../../def';
5
+ import { keys } from '../../models';
6
+
7
+ /** 请求参数. */
8
+ export class GetLatestApkVersionQuery {}
9
+
10
+ /**
11
+ * 获取 APK 最新的版本号.
12
+ *
13
+ * @param config 请求配置.
14
+ * @param option 请求选项.
15
+ */
16
+ export function GetLatestApkVersion(config?: IRequestConfig<GetLatestApkVersionQuery, {}>, option?: IRequestOptions): Promise<string> {
17
+ return httpClient().request({ method: GetLatestApkVersion.method, url: GetLatestApkVersion.url, ...(config ?? {}) }, option);
18
+ }
19
+
20
+ GetLatestApkVersion.method = 'GET' as const;
21
+ GetLatestApkVersion.url = '/sys/common/getLatestApkVersion';
@@ -1,21 +1,21 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
- import * as DEF from '../../../def';
5
- import { keys } from '../../models';
6
-
7
- /** 请求参数. */
8
- export class GetUserInfoQuery {}
9
-
10
- /**
11
- * 获取用户信息.
12
- *
13
- * @param config 请求配置.
14
- * @param option 请求选项.
15
- */
16
- export function GetUserInfo(config?: IRequestConfig<GetUserInfoQuery, {}>, option?: IRequestOptions): Promise<Record<any, any>> {
17
- return httpClient().request({ method: GetUserInfo.method, url: GetUserInfo.url, ...(config ?? {}) }, option);
18
- }
19
-
20
- GetUserInfo.method = 'GET' as const;
21
- GetUserInfo.url = '/sys/getUserInfo';
1
+ // noinspection ES6UnusedImports
2
+
3
+ import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
+ import * as DEF from '../../../def';
5
+ import { keys } from '../../models';
6
+
7
+ /** 请求参数. */
8
+ export class GetUserInfoQuery {}
9
+
10
+ /**
11
+ * 获取用户信息.
12
+ *
13
+ * @param config 请求配置.
14
+ * @param option 请求选项.
15
+ */
16
+ export function GetUserInfo(config?: IRequestConfig<GetUserInfoQuery, {}>, option?: IRequestOptions): Promise<Record<any, any>> {
17
+ return httpClient().request({ method: GetUserInfo.method, url: GetUserInfo.url, ...(config ?? {}) }, option);
18
+ }
19
+
20
+ GetUserInfo.method = 'GET' as const;
21
+ GetUserInfo.url = '/sys/getUserInfo';
@@ -1,21 +1,21 @@
1
- // noinspection ES6UnusedImports
2
-
3
- import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
- import * as DEF from '../../../def';
5
- import { keys } from '../../models';
6
-
7
- /** 请求参数. */
8
- export class LogoutQuery {}
9
-
10
- /**
11
- * 退出登录.
12
- *
13
- * @param config 请求配置.
14
- * @param option 请求选项.
15
- */
16
- export function Logout(config?: IRequestConfig<LogoutQuery, {}>, option?: IRequestOptions): Promise<Record<any, any>> {
17
- return httpClient().request({ method: Logout.method, url: Logout.url, ...(config ?? {}) }, option);
18
- }
19
-
20
- Logout.method = 'GET' as const;
21
- Logout.url = '/sys/logout';
1
+ // noinspection ES6UnusedImports
2
+
3
+ import { httpClient, IRequestConfig, IRequestOptions } from '../../../../service';
4
+ import * as DEF from '../../../def';
5
+ import { keys } from '../../models';
6
+
7
+ /** 请求参数. */
8
+ export class LogoutQuery {}
9
+
10
+ /**
11
+ * 退出登录.
12
+ *
13
+ * @param config 请求配置.
14
+ * @param option 请求选项.
15
+ */
16
+ export function Logout(config?: IRequestConfig<LogoutQuery, {}>, option?: IRequestOptions): Promise<Record<any, any>> {
17
+ return httpClient().request({ method: Logout.method, url: Logout.url, ...(config ?? {}) }, option);
18
+ }
19
+
20
+ Logout.method = 'GET' as const;
21
+ Logout.url = '/sys/logout';
@@ -1,2 +1,2 @@
1
- export { GetUserInfo, GetUserInfoQuery } from './GetUserInfo';
2
- export { Logout, LogoutQuery } from './Logout';
1
+ export { GetUserInfo, GetUserInfoQuery } from './GetUserInfo';
2
+ export { Logout, LogoutQuery } from './Logout';
@@ -1 +1 @@
1
- export { List, ListQuery } from './List';
1
+ export { List, ListQuery } from './List';
@@ -1,4 +1,4 @@
1
- export * as CommonController from './CommonController';
2
- export * as LoginController from './LoginController';
3
- export * as WhController from './WhController';
4
- export * as WorkstationController from './WorkstationController';
1
+ export * as CommonController from './CommonController';
2
+ export * as LoginController from './LoginController';
3
+ export * as WhController from './WhController';
4
+ export * as WorkstationController from './WorkstationController';
@@ -4,6 +4,7 @@ import { KG_DYNAMIC_QUERY_OPERATOR, KG_HTTP_HEADERS } from '../const';
4
4
  import { useKgWarehouse } from '../component/KgWarehouse/index.hooks';
5
5
  import { useKgStation } from '../component/KgStation';
6
6
  import { isNil } from 'lodash-es';
7
+ import dayjs from 'dayjs';
7
8
 
8
9
  /*
9
10
  * 对请求做统一的拦截.
@@ -11,7 +12,7 @@ import { isNil } from 'lodash-es';
11
12
  uni.addInterceptor('request', {
12
13
  invoke(args) {
13
14
  if (args?.isShowLoading !== false) {
14
- uni.showLoading({});
15
+ uni.showLoading({ mask: true });
15
16
  }
16
17
 
17
18
  const appStore = useAppStore();
@@ -60,6 +61,8 @@ type IHttpClient = {
60
61
 
61
62
  /** 请求配置. */
62
63
  type IRequestOptions = Omit<UniApp.RequestOptions, 'url'> & {
64
+ $dayjs?: typeof dayjs;
65
+
63
66
  /**
64
67
  * 不放入 WHERE SQL 中的参数.
65
68
  */
@@ -220,6 +223,7 @@ const _httpClient: IHttpClient = {
220
223
  }
221
224
 
222
225
  const { sql, whereSql, orderBySql, offsetSql, operatorJSON } = Kg.getQueryHeaders({
226
+ $dayjs: options?.$dayjs,
223
227
  dynamicQueryExcludeProperties: options?.dynamicQueryExcludeProperties,
224
228
  dynamicQueryOperatorModel: options?.dynamicQueryOperatorModel,
225
229
  params: Kg.parseParams(params),
package/dist/util/kg.ts CHANGED
@@ -4,6 +4,7 @@ import { API } from '../api';
4
4
  import { useKgStation, useKgWarehouse } from '../component';
5
5
  import { useAppStore } from '../store/app.store';
6
6
  import { KG_DYNAMIC_QUERY_OPERATOR } from '../const';
7
+ import dayjs, { Dayjs } from 'dayjs';
7
8
 
8
9
  /**
9
10
  * 通用工具.
@@ -195,11 +196,12 @@ export class Kg {
195
196
  * @param param.params 请求参数.
196
197
  */
197
198
  public static getQueryHeaders(param: {
199
+ $dayjs?: typeof dayjs;
198
200
  dynamicQueryExcludeProperties: Array<string> | null | undefined;
199
201
  dynamicQueryOperatorModel: Record<string, any> | null | undefined;
200
202
  params: Record<string, any> | null | undefined;
201
203
  }) {
202
- const { params, dynamicQueryExcludeProperties, dynamicQueryOperatorModel } = param ?? {};
204
+ const { $dayjs, params, dynamicQueryExcludeProperties, dynamicQueryOperatorModel } = param ?? {};
203
205
 
204
206
  let _params = cloneDeep(toRaw(unref(params ?? {})));
205
207
 
@@ -211,7 +213,8 @@ export class Kg {
211
213
  // 特殊字段, 这些特殊字段的值不做处理, 保持原样
212
214
  const SPECIAL_FIELD_KEYS = ['pageNo', 'pageSize', 'column', 'order'];
213
215
 
214
- const _paramsForWhereSql: Record<string, any> = {};
216
+ const _paramsForQueryWhereSql: Record<string, any> = {};
217
+
215
218
  Object.keys(_params)
216
219
  .sort()
217
220
  .forEach((key) => {
@@ -235,16 +238,87 @@ export class Kg {
235
238
  let operator: string = dynamicQueryOperatorModel?.[key] ?? KG_DYNAMIC_QUERY_OPERATOR.EQ;
236
239
 
237
240
  switch (true) {
241
+ //region 日期范围
242
+ //----------------------------------------------------------------------------------------------------
243
+ case !!$dayjs && isArray(value) && value.length === 2 && $dayjs.isDayjs(value[0]) && $dayjs.isDayjs(value[1]): {
244
+ let _stringValue = '';
245
+
246
+ switch (operator) {
247
+ case 'BETWEEN':
248
+ default: {
249
+ const _leftValue = value[0] as Dayjs;
250
+ const _rightValue = value[1] as Dayjs;
251
+
252
+ // 左侧日期的字符串
253
+ let _leftStringValue = _leftValue.format('YYYY-MM-DD HH:mm:ss');
254
+ // 右侧日期的字符串
255
+ let _rightStringValue = '';
256
+
257
+ switch (true) {
258
+ // 左侧日期为空
259
+ case !_leftStringValue: {
260
+ _rightStringValue = _rightValue.format('YYYY-MM-DD HH:mm:ss');
261
+ break;
262
+ }
263
+
264
+ // 日期格式为 YYYY-MM-DD HH:mm:ss
265
+ case /\d\d-\d\d-\d\d \d\d:\d\d:\d\d/.test(_leftStringValue): {
266
+ if (_rightValue.isValid()) {
267
+ _rightStringValue = _rightValue.add(1, 'second').format('YYYY-MM-DD HH:mm:ss');
268
+ }
269
+ break;
270
+ }
271
+
272
+ // 日期格式为 YYYY-MM-DD
273
+ case /\d\d-\d\d-\d\d/.test(_leftStringValue): {
274
+ _leftStringValue = `${_leftStringValue} 00:00:00`;
275
+ if (_rightValue.isValid()) {
276
+ _rightStringValue = _rightValue.add(1, 'day').format('YYYY-MM-DD 00:00:00');
277
+ }
278
+ break;
279
+ }
280
+
281
+ // 日期格式为 HH:mm:ss
282
+ case /\d\d:\d\d:\d\d/.test(_leftStringValue): {
283
+ _leftStringValue = `1900-01-01 ${_leftStringValue}`;
284
+ if (_rightValue.isValid()) {
285
+ _rightStringValue = _rightValue.add(1, 'second').format('1900-01-01 HH:mm:ss');
286
+ }
287
+ break;
288
+ }
289
+ }
290
+
291
+ if (_leftStringValue) {
292
+ _stringValue += `(${_key} >= '${_leftStringValue}')`;
293
+ }
294
+
295
+ if (_rightStringValue) {
296
+ if (_stringValue) {
297
+ _stringValue += ' AND ';
298
+ }
299
+
300
+ _stringValue += `(${_key} < '${_rightStringValue}')`;
301
+ }
302
+ break;
303
+ }
304
+ }
305
+
306
+ _paramsForQueryWhereSql[key] = _stringValue;
307
+
308
+ break;
309
+ }
310
+ //endregion
311
+
238
312
  // array
239
313
  case Array.isArray(value): {
240
314
  if (value.length === 0) {
241
- _paramsForWhereSql[key] = undefined;
315
+ _paramsForQueryWhereSql[key] = undefined;
242
316
  break;
243
317
  }
244
318
 
245
319
  const _value = value.map((i: any) => `N'${String(i)}'`).join(', ');
246
320
 
247
- _paramsForWhereSql[key] = ` AND (${_key} IN (${_value}))`;
321
+ _paramsForQueryWhereSql[key] = ` AND (${_key} IN (${_value}))`;
248
322
  break;
249
323
  }
250
324
 
@@ -257,7 +331,7 @@ export class Kg {
257
331
  case typeof value === 'string': {
258
332
  // 空白字符
259
333
  if (value.trim() === '') {
260
- _paramsForWhereSql[key] = undefined;
334
+ _paramsForQueryWhereSql[key] = undefined;
261
335
  break;
262
336
  }
263
337
 
@@ -291,7 +365,7 @@ export class Kg {
291
365
  }
292
366
  }
293
367
 
294
- _paramsForWhereSql[key] = _strValue;
368
+ _paramsForQueryWhereSql[key] = _strValue;
295
369
 
296
370
  break;
297
371
  }
@@ -333,7 +407,7 @@ export class Kg {
333
407
  }
334
408
  }
335
409
 
336
- _paramsForWhereSql[key] = _strValue;
410
+ _paramsForQueryWhereSql[key] = _strValue;
337
411
 
338
412
  break;
339
413
  }
@@ -355,14 +429,14 @@ export class Kg {
355
429
  }
356
430
  }
357
431
 
358
- _paramsForWhereSql[key] = _strValue;
432
+ _paramsForQueryWhereSql[key] = _strValue;
359
433
 
360
434
  break;
361
435
  }
362
436
 
363
437
  // null, undefined
364
438
  default: {
365
- _paramsForWhereSql[key] = value;
439
+ _paramsForQueryWhereSql[key] = value;
366
440
 
367
441
  break;
368
442
  }
@@ -370,7 +444,7 @@ export class Kg {
370
444
  });
371
445
 
372
446
  const whereSqlSegment = reduce(
373
- _paramsForWhereSql,
447
+ _paramsForQueryWhereSql,
374
448
  (sql, value) => {
375
449
  if (!value) {
376
450
  return sql;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kengic/uni",
3
- "version": "0.6.3-beta.23",
3
+ "version": "0.6.3-beta.24",
4
4
  "scripts": {
5
5
  "build": "npm run use-node && rimraf dist && vue-tsc && vite build",
6
6
  "------ -------------------------------------------": "",
@@ -40,6 +40,7 @@
40
40
  "@vueuse/shared": "8.9.4",
41
41
  "ant-design-vue": "3.2.20",
42
42
  "chalk": "4.1.2",
43
+ "dayjs": "1.11.10",
43
44
  "less": "4.1.3",
44
45
  "lodash-es": "4.17.21",
45
46
  "pinia": "2.0.35",