@dt-frames/ui 1.0.7 → 1.0.8

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,5 +1,4 @@
1
- import { ApiType } from "../types/source.type";
2
- import { Recordable } from "@dt-frames/core";
1
+ import { Recordable, ApiType } from "@dt-frames/core";
3
2
  export declare function useFetch(api: string | ApiType, baseUrl?: string): {
4
3
  fetch: (params?: Recordable) => Promise<unknown>;
5
4
  };
@@ -1,4 +1,4 @@
1
- import { Recordable } from "@dt-frames/core";
1
+ import { Recordable, ApiType } from "@dt-frames/core";
2
2
  export declare type PageQueryType = {
3
3
  entityDTO: Recordable;
4
4
  orderDTOs: Recordable[];
@@ -8,14 +8,6 @@ export declare type PageQueryType = {
8
8
  [key: string]: any;
9
9
  };
10
10
  };
11
- export declare type ApiType = {
12
- api: string;
13
- type?: 'get' | 'post' | 'put' | 'delete';
14
- header?: any;
15
- model?: Recordable;
16
- beforeFetch?: <T = any>(params: T) => T;
17
- afterFetch?: <T = any>(data: any) => T;
18
- };
19
11
  export declare type ApiObjType = {
20
12
  add?: string | ApiType;
21
13
  update?: string | ApiType;
package/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineComponent, resolveComponent, openBlock, createBlock, computed, unref, createElementBlock, normalizeClass, normalizeStyle, createElementVNode, ref, watch, Fragment, renderList, createTextVNode, toDisplayString, KeepAlive, createVNode, withCtx, reactive, toRaw, getCurrentInstance, watchEffect, nextTick, onUnmounted, toRefs, isVNode, inject, h, provide, onMounted, onBeforeUnmount, resolveDynamicComponent, renderSlot, createCommentVNode, mergeProps, readonly, isRef, withDirectives, resolveDirective, render, normalizeProps, guardReactiveProps, createSlots, useAttrs as useAttrs$1, vShow, toRef, withModifiers, Transition } from "vue";
2
2
  import { isString, isArray as isArray$1, isObject, isFunction, error, useTimeoutFn, useAttrs, useSlots, dispatchResize, BAR_MAP, off, renderThumbStyle, on, useAppStore, addResizeListener, removeResizeListener, windowResizeFn, isNumber, isBoolean, isNull, DtCache, CacheKey, deepMerge, dateFormat, http, getDynamicProps, getDictValueByCode, formatNumber, isVnode, getPopupContainer, isNullAndUnDef, useMessage, useTheme, useMenu, useHeader, useGo, Pages, localeList, changeLocale, Theme, MenuMode, MenuType, useThemeStore, ContentMode, useMultipleTab, copyText, MenuSplitTye, isUrl, openWindow, RouteReuseStore, menuList2Map, useApp } from "@dt-frames/core";
3
- import { InputSearch, Tooltip, Modal as Modal$1, RadioGroup, RadioButton, InputGroup, Input, Button, Select, TreeSelect, Radio, Checkbox, AutoComplete, Cascader, DatePicker, InputNumber, Switch, TimePicker, Slider, Rate, Divider, Col, Form, FormItem, Row, Dropdown, Menu, MenuItem, Popover, CheckboxGroup, Table, message, Spin, BackTop, Breadcrumb, Avatar, Drawer, Empty, SubMenu, LayoutHeader, LayoutSider, MenuDivider, Tabs, TabPane, LayoutFooter, LayoutContent, ConfigProvider, Layout } from "ant-design-vue";
3
+ import { InputSearch, Tooltip, Modal as Modal$1, RadioGroup, RadioButton, InputGroup, Input, Button, Select, TreeSelect, Radio, Checkbox, AutoComplete, Cascader, DatePicker, InputNumber, Switch, TimePicker, Slider, Rate, Divider, Col, Form, FormItem, Row, Dropdown, Menu, MenuItem, Popover, CheckboxGroup, Table, Spin, BackTop, Breadcrumb, Avatar, Drawer, Empty, SubMenu, LayoutHeader, LayoutSider, MenuDivider, Tabs, TabPane, LayoutFooter, LayoutContent, ConfigProvider, Layout } from "ant-design-vue";
4
4
  import { isEqual, cloneDeep, upperFirst, set, uniqBy, omit, trim } from "lodash-es";
5
5
  import { tryOnUnmounted, isFunction as isFunction$1, useFullscreen, useDebounceFn, useThrottleFn } from "@vueuse/core";
6
6
  import Sortablejs from "sortablejs";
@@ -6338,33 +6338,21 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
6338
6338
  }
6339
6339
  var index = /* @__PURE__ */ _export_sfc(_sfc_main$x, [["render", _sfc_render]]);
6340
6340
  function useFetch(api, baseUrl = "") {
6341
- const getApiObj = () => {
6341
+ function fetch(params = {}) {
6342
+ let type = "post", header = {}, model = {}, _api = "";
6342
6343
  if (isString(api)) {
6343
- return { api };
6344
- }
6345
- return { ...api };
6346
- };
6347
- const getParams = (params = {}) => {
6348
- const { model, beforeFetch } = getApiObj();
6349
- if (!api) {
6350
- message.error("\u8BF7\u6C42\u7684url\u4E0D\u80FD\u4E3A\u7A7A");
6351
- return false;
6344
+ _api = baseUrl + api;
6345
+ } else {
6346
+ type = api.type;
6347
+ _api = baseUrl + api.api;
6348
+ header = api.header;
6349
+ model = api.model;
6352
6350
  }
6353
- return beforeFetch && isFunction(beforeFetch) ? beforeFetch(Object.assign({}, model, params)) : params;
6354
- };
6355
- function fetch(params = {}) {
6356
- const handleParams = getParams(params);
6357
- if (isBoolean(handleParams) && handleParams === false)
6358
- return Promise.resolve();
6359
- const { api: _api, type = "post", header = {}, afterFetch } = getApiObj();
6360
6351
  return new Promise((resolve, reject) => {
6361
- http[type](`${baseUrl}${_api}`, handleParams, {
6352
+ http[type](_api, Object.assign({}, model, params), {
6362
6353
  ...header,
6363
6354
  ...{ onlyData: false }
6364
6355
  }).then((data) => {
6365
- if (afterFetch && isFunction(afterFetch)) {
6366
- data = afterFetch(data);
6367
- }
6368
6356
  resolve(data == null ? void 0 : data.data);
6369
6357
  }, (error2) => {
6370
6358
  reject(error2);
@@ -6406,7 +6394,7 @@ function useSource(opt) {
6406
6394
  };
6407
6395
  const { baseUrl = "", api = {}, exportName = "" } = opt;
6408
6396
  const { add, deletes, update, queryById, queryPage } = api;
6409
- const { message: message2 } = useMessage();
6397
+ const { message } = useMessage();
6410
6398
  const apiFul = {};
6411
6399
  for (let it in api) {
6412
6400
  loading["on" + it.slice(0, 1).toUpperCase() + it.slice(1).toLowerCase()] = ref(false);
@@ -6470,7 +6458,7 @@ function useSource(opt) {
6470
6458
  function onAdd(model) {
6471
6459
  const { fetch } = useFetch(add, baseUrl);
6472
6460
  fetch(model).then((rsp) => {
6473
- message2.success("\u65B0\u589E\u6210\u529F");
6461
+ message.success("\u65B0\u589E\u6210\u529F");
6474
6462
  search();
6475
6463
  });
6476
6464
  }
@@ -6481,7 +6469,7 @@ function useSource(opt) {
6481
6469
  function onUpdate(model) {
6482
6470
  const { fetch } = useFetch(update, baseUrl);
6483
6471
  fetch(model).then((rsp) => {
6484
- message2.success("\u66F4\u65B0\u6570\u636E\u6210\u529F");
6472
+ message.success("\u66F4\u65B0\u6570\u636E\u6210\u529F");
6485
6473
  search();
6486
6474
  });
6487
6475
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dt-frames/ui",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "keywords": [
5
5
  "ui",
6
6
  "dt-ui"
@@ -1,58 +1,27 @@
1
- import { ApiType } from "../types/source.type";
2
- import { message } from 'ant-design-vue'
3
- import { http, isBoolean, isFunction, isString, JsonResult, Recordable } from "@dt-frames/core";
1
+ import { http, isString, JsonResult, Recordable, ApiType } from "@dt-frames/core";
4
2
 
5
3
  export function useFetch(api: string | ApiType, baseUrl: string = '') {
6
-
7
- const getApiObj= () => {
8
- if( isString(api) ) {
9
- return { api }
10
- }
11
-
12
- return { ...api }
13
- }
14
-
15
- /**
16
- * 是否可以向服务器发送请求
17
- * 如果beforeFetch返回的是false, 则停止请求
18
- * */
19
- const getParams = (params: Recordable = { }) => {
20
- const { model, beforeFetch } = getApiObj()
21
-
22
- if( !api ) {
23
- message.error('请求的url不能为空')
24
- return false
25
- }
26
-
27
- return beforeFetch && isFunction( beforeFetch )
28
- ? beforeFetch( Object.assign({}, model, params) )
29
- : params
30
- }
31
-
32
-
33
-
34
4
  /**
35
5
  * 发送请求
36
6
  * handleParams 记录返回的值
37
7
  */
38
8
  function fetch(params: Recordable = { }) {
39
- const handleParams = getParams( params )
40
-
41
- if( isBoolean( handleParams ) && handleParams === false)
42
- return Promise.resolve()
43
-
44
- const { api: _api, type = 'post', header = { }, afterFetch } = getApiObj()
9
+ let type = 'post', header = { }, model = {}, _api = ''
10
+ if(isString( api )) {
11
+ _api = baseUrl + api
12
+ } else {
13
+ type = api.type
14
+ _api = baseUrl + api.api
15
+ header = api.header
16
+ model = api.model
17
+ }
45
18
 
46
19
  return new Promise(( resolve, reject ) => {
47
- http[type]( `${ baseUrl }${_api}`, handleParams, {
20
+ http[type]( _api, Object.assign({}, model, params), {
48
21
  ...header,
49
22
  ...{ onlyData: false }
50
23
  }).then(
51
24
  (data: JsonResult) => {
52
- if( afterFetch && isFunction(afterFetch) ) {
53
- data = afterFetch( data )
54
- }
55
-
56
25
  resolve( data?.data )
57
26
  },
58
27
  (error) => {
@@ -1,11 +1,11 @@
1
1
  import { ref, reactive, toRaw, Ref } from 'vue'
2
2
  import { isString, Recordable, useMessage } from "@dt-frames/core"
3
- import { ApiType, BaseDataType, SourceType } from "../types/source.type"
3
+ import { BaseDataType, SourceType } from "../types/source.type"
4
4
  import { useFetch } from './useFetch'
5
5
  import { TableParamsType } from '../types/table.type'
6
6
  import { DownloadType } from '../../../table/src/types/tableHeader.type'
7
7
  import { handleDownloadPage } from '../../../excel/index'
8
- import { useAppStore } from '@dt-frames/core'
8
+ import { useAppStore, ApiType } from '@dt-frames/core'
9
9
 
10
10
  export function useSource(opt: SourceType) {
11
11
  const loading: {
@@ -1,4 +1,4 @@
1
- import { Recordable } from "@dt-frames/core"
1
+ import { Recordable, ApiType } from "@dt-frames/core"
2
2
 
3
3
  export type PageQueryType = {
4
4
  entityDTO: Recordable,
@@ -10,26 +10,6 @@ export type PageQueryType = {
10
10
  }
11
11
  }
12
12
 
13
- export type ApiType = {
14
- // api接口
15
- api: string
16
-
17
- // 请求类型
18
- type?: 'get' | 'post' | 'put' | 'delete',
19
-
20
- // 请求头信息
21
- header?: any
22
-
23
- // 默认的基础数据
24
- model?: Recordable
25
-
26
- // 请求之前
27
- beforeFetch?: <T = any>( params: T ) => T
28
-
29
- // 请求之后
30
- afterFetch?: <T = any>( data: any) => T
31
- }
32
-
33
13
 
34
14
  export type ApiObjType = {
35
15
  // 新增