t20-common-lib 0.15.5 → 0.15.6

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": "t20-common-lib",
3
- "version": "0.15.5",
3
+ "version": "0.15.6",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -36,7 +36,7 @@
36
36
  </template>
37
37
  <script>
38
38
  import dayjs from 'dayjs'
39
- import { getDataForPost, getDataForGet } from '../utils/request'
39
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
40
40
  export default {
41
41
  name: 'Dialog',
42
42
  props: {
@@ -27,7 +27,7 @@
27
27
  <script>
28
28
  import dayjs from 'dayjs'
29
29
  /* 各属性,方法参考el-select */
30
- import { getDataForPost, getDataForGet } from '../utils/request'
30
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
31
31
  export default {
32
32
  name: "SelectLazy",
33
33
  props: {
@@ -10,7 +10,7 @@
10
10
  </template>
11
11
 
12
12
  <script>
13
- import { getDataForGet, getDataForPost } from '../utils/request'
13
+ import { getDataForGet, getDataForPost } from '../../../../src/api/common'
14
14
 
15
15
  export default {
16
16
  name: 'ScrollLoadSelect',
@@ -63,10 +63,10 @@ export default {
63
63
  }
64
64
  return this.$attrs.requestFn || this.$attrs['request-fn'] || this.fetchByStaticOptions
65
65
  },
66
- shouldAutoLoad() {
67
- const autoLoad = this.items?.props?.autoLoad ?? this.$attrs.autoLoad
68
- return autoLoad !== false
69
- },
66
+ // shouldAutoLoad() {
67
+ // const autoLoad = this.items?.props?.autoLoad ?? this.$attrs.autoLoad
68
+ // return autoLoad !== false
69
+ // },
70
70
  passThroughProps() {
71
71
  return {
72
72
  ...this.$attrs,
@@ -81,18 +81,18 @@ export default {
81
81
  }
82
82
  },
83
83
  mounted() {
84
- this.triggerInitialRequest()
84
+ // this.triggerInitialRequest()
85
85
  },
86
86
  methods: {
87
- triggerInitialRequest() {
88
- if (!this.shouldAutoLoad) return
89
- this.$nextTick(() => {
90
- const instance = this.$refs.scrollLoadSelect
91
- if (instance && typeof instance.handleFilter === 'function') {
92
- instance.handleFilter('')
93
- }
94
- })
95
- },
87
+ // triggerInitialRequest() {
88
+ // if (!this.shouldAutoLoad) return
89
+ // this.$nextTick(() => {
90
+ // const instance = this.$refs.scrollLoadSelect
91
+ // if (instance && typeof instance.handleFilter === 'function') {
92
+ // instance.handleFilter('')
93
+ // }
94
+ // })
95
+ // },
96
96
  resolvePath(data, path) {
97
97
  if (!path) return data
98
98
  return String(path)
@@ -31,7 +31,7 @@
31
31
  <script>
32
32
  import dayjs from 'dayjs'
33
33
  import clickoutside from 'element-ui/src/utils/clickoutside'
34
- import { getDataForPost, getDataForGet } from '../utils/request'
34
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
35
35
  export default {
36
36
  name: "Select",
37
37
  props: {
@@ -14,7 +14,7 @@
14
14
 
15
15
  <script>
16
16
  import clickoutside from 'element-ui/src/utils/clickoutside'
17
- import { getDataForPost, getDataForGet } from '../utils/request'
17
+ import { getDataForPost, getDataForGet } from '../../../../src/api/common'
18
18
  export default {
19
19
  name: 'SelectTree',
20
20
  props: {
package/src/api/common.js CHANGED
@@ -1,5 +1,13 @@
1
1
  import request from '@/utils/request'
2
2
 
3
+ function normalizeHeaders(headers = {}) {
4
+ if (!headers || typeof headers !== 'object') return {}
5
+ if (headers.headers && typeof headers.headers === 'object') {
6
+ return headers.headers
7
+ }
8
+ return headers
9
+ }
10
+
3
11
  // 单位本位币
4
12
  export function getUnitCurrency(unitNo) {
5
13
  // return request({
@@ -30,4 +38,24 @@ export function getCommonConfig(params = {}) {
30
38
  cache:true,
31
39
  params
32
40
  })
41
+ }
42
+
43
+ export function getDataForGet(url, params = {}, headers = {}) {
44
+ return request({
45
+ url,
46
+ method: 'get',
47
+ loading: false,
48
+ params,
49
+ headers: normalizeHeaders(headers)
50
+ })
51
+ }
52
+
53
+ export function getDataForPost(url, data = {}, headers = {}) {
54
+ return request({
55
+ url,
56
+ method: 'post',
57
+ loading: false,
58
+ data,
59
+ headers: normalizeHeaders(headers)
60
+ })
33
61
  }
@@ -81,4 +81,24 @@ service.interceptors.response.use(
81
81
  }
82
82
  )
83
83
 
84
+ function normalizeConfig(headers = {}) {
85
+ if (!headers || typeof headers !== 'object') return {}
86
+ // 兼容调用方直接传 { headers: {...} } 或扁平对象两种方式
87
+ if (headers.headers && typeof headers.headers === 'object') {
88
+ return headers
89
+ }
90
+ return { headers }
91
+ }
92
+
93
+ export function getDataForGet(url, params = {}, headers = {}) {
94
+ return service.get(url, {
95
+ params,
96
+ ...normalizeConfig(headers)
97
+ })
98
+ }
99
+
100
+ export function getDataForPost(url, data = {}, headers = {}) {
101
+ return service.post(url, data, normalizeConfig(headers))
102
+ }
103
+
84
104
  export default service
@@ -1,19 +0,0 @@
1
- import Vue from 'vue'
2
-
3
- function resolveAxios() {
4
- const axios = Vue.prototype && Vue.prototype.$axios
5
- if (!axios || typeof axios !== 'object') {
6
- throw new Error('[DynamicForm] $axios is required in Vue prototype')
7
- }
8
- return axios
9
- }
10
-
11
- export function getDataForGet(url, params = {}, headers = {}) {
12
- const axios = resolveAxios()
13
- return axios.get(url, params, headers)
14
- }
15
-
16
- export function getDataForPost(url, data = {}, headers = {}) {
17
- const axios = resolveAxios()
18
- return axios.post(url, data, headers)
19
- }