resolver-egretimp-plus 0.0.34 → 0.0.35

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": "resolver-egretimp-plus",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "交付体验渲染",
5
5
  "main": "./dist/web/index.js",
6
6
  "module": "./dist/web/index.js",
@@ -1,4 +1,5 @@
1
1
  import { getRelateConfigKeys } from "../../rules/ruleUtils"
2
+ import { resultToast } from "../../utils/respone"
2
3
  import { openChildDialog } from "../childDialog"
3
4
 
4
5
  export async function dispatchClickEvents ({serviceList = [], axiosInstance, dynamicMapComp, rootValue, dynamicHireRelat, messageInstance}) {
@@ -26,8 +27,7 @@ export async function dispatchClickEvent(service, { dynamicMapComp, rootValue, d
26
27
  method: "post",
27
28
  data: reqData
28
29
  }))
29
- if (!ret?.data?.success) {
30
- messageInstance?.value?.error(ret?.data?.resultMessage || '')
30
+ if (!resultToast(ret?.data, messageInstance)) {
31
31
  await Promise.reject()
32
32
  return
33
33
  }
@@ -104,10 +104,8 @@ export function getTableConfig(outParamMappingList = [], { dynamicMapComp, dynam
104
104
  export function openDailg({
105
105
  pagePopupMap,
106
106
  axiosInstance,
107
- rootValue,
108
107
  dynamicMapComp,
109
108
  dynamicHireRelat,
110
- messageInstance,
111
109
  lang,
112
110
  appContext,
113
111
  }) {
@@ -98,7 +98,7 @@ const buttonAction = (...arg) => {
98
98
  rootValue: rootValue?.value,
99
99
  dynamicMapComp,
100
100
  dynamicHireRelat,
101
- messageInstance
101
+ messageInstance: messageInstance?.value
102
102
  })
103
103
  }
104
104
  const lcpPagePopupMapVO = props.config.lcpPagePopupMapVO
@@ -107,10 +107,8 @@ const buttonAction = (...arg) => {
107
107
  openDailg({
108
108
  pagePopupMap: lcpPagePopupMapVO,
109
109
  axiosInstance: _axiosInstance,
110
- rootValue: rootValue?.value,
111
110
  dynamicMapComp,
112
111
  dynamicHireRelat,
113
- messageInstance,
114
112
  appContext,
115
113
  lang: lang?.value
116
114
  })
@@ -4,6 +4,7 @@ import { buildInRequest } from "../utils/request"
4
4
  import { GET_SYS_PARAM_CACHE, QUERY_PAGE_CONFIG_DATA } from "../api/builtIn"
5
5
  import { normalPageConfigs } from "../components/helper/resolver"
6
6
  import mock from "./mock"
7
+ import { resultToast } from "../utils/respone"
7
8
 
8
9
  export function usePageConfig() {
9
10
  const pageConfigRef = ref(null)
@@ -46,14 +47,13 @@ export function useBuildInData(messageTipInstance, loadingInstance) {
46
47
  loadingInstance.show()
47
48
  }
48
49
  buildInRequest(QUERY_PAGE_CONFIG_DATA, reqData).then(ret => {
49
- if (ret.data.success) {
50
+ if (resultToast(ret.data, messageTipInstance)) {
50
51
  // pageConfig.value = normalPageConfigs(mock)
51
52
  pageConfig.value = normalPageConfigs(ret.data.result)
52
53
  cb(pageConfig.value)
53
54
  getSelects(ret.data.result?.pmBusinessIdentityVO?.tenantId)
54
55
  return
55
56
  }
56
- messageTipInstance?.error(ret.data.resultMessage)
57
57
  }).catch(() => {
58
58
  if (loadingInstance.finish && typeof loadingInstance.finish === 'function') {
59
59
  loadingInstance.finish()
@@ -67,11 +67,10 @@ export function useBuildInData(messageTipInstance, loadingInstance) {
67
67
  buildInRequest(GET_SYS_PARAM_CACHE, {
68
68
  tenantId
69
69
  }).then(ret => {
70
- if (ret.data.success) {
70
+ if (resultToast(ret.data, messageTipInstance)) {
71
71
  selects.value = JSON.parse(ret.data.result || '{}')
72
72
  return
73
73
  }
74
- messageTipInstance?.error(ret.data.resultMessage)
75
74
  }).finally(() => {
76
75
  if (loadingInstance.finish && typeof loadingInstance.finish === 'function') {
77
76
  loadingInstance.finish()
@@ -2,6 +2,7 @@
2
2
  import { computed, useAttrs } from 'vue';
3
3
  import Resolver from './index.jsx'
4
4
  import { useBuildInData } from './hooks/pageConfig';
5
+ import { initInterceptors } from './utils/request.js';
5
6
 
6
7
  const props = defineProps({
7
8
  busiIdentityId: String,
@@ -26,7 +27,7 @@ defineOptions({
26
27
  inheritAttrs: false
27
28
  })
28
29
  const attrs = useAttrs()
29
-
30
+ initInterceptors(props.messageInstance)
30
31
  const { getPageConfig, pageConfig, selects } = useBuildInData(props.messageInstance, props.loadingInstance)
31
32
  getPageConfig({
32
33
  busiIdentityId: props.busiIdentityId,
@@ -4,6 +4,7 @@ import { AUTH_CODE, NOT_AUTH_APIS, PASSWORD, USER_NAME, USER_TYPE } from '../enu
4
4
  import { LCP_LOGIN, REFRESH_TOKEN } from '../api/builtIn'
5
5
  import { HashingFactory } from './cipher'
6
6
  import dayjs from 'dayjs'
7
+ import { resultToast } from './respone'
7
8
 
8
9
  export function generateRequester(config) {
9
10
  const interceptors = config?.interceptors || {}
@@ -20,67 +21,69 @@ let EXPIRATION_Time = null
20
21
  const service = axios.create({
21
22
  timeout: 60000 // request timeout
22
23
  })
23
- service.interceptors.request.use(
24
- config => {
25
- let data = config.data
26
- const url = config.url
27
- if (
28
- config && config.headers &&
29
- (
30
- config.headers['Content-type']?.includes('application/x-www-form-urlencoded')
31
- )
32
- ) {
33
- data = qs.stringify(data)
34
- }
35
- const reqConfig = {
36
- ...config,
37
- data
38
- }
39
- return new Promise(async (resolve, reject) => {
40
- try {
41
- if ((!NOT_AUTH_APIS.includes(url) && !loginToken)) {
42
- await simulatelogin()
43
- reqConfig.headers = {
44
- ...(reqConfig.headers || {}),
45
- Authorization: `Bearer ${loginToken}`
46
- }
47
- } else {
48
- if (!NOT_AUTH_APIS.includes(url)) {
49
- if ((EXPIRATION_Time.getTime() - new Date().getTime()) < THRESHOLD_TIME && REFRESH_TOKEN !== url) {
50
- await refreshToken()
51
- reqConfig.headers = {
52
- ...(reqConfig.headers || {}),
53
- Authorization: `Bearer ${loginToken}`
54
- }
55
- } else {
56
- reqConfig.headers = {
57
- ...(reqConfig.headers || {}),
58
- Authorization: `Bearer ${loginToken}`
24
+ export function initInterceptors(messageInstance) {
25
+ service.interceptors.request.use(
26
+ config => {
27
+ let data = config.data
28
+ const url = config.url
29
+ if (
30
+ config && config.headers &&
31
+ (
32
+ config.headers['Content-type']?.includes('application/x-www-form-urlencoded')
33
+ )
34
+ ) {
35
+ data = qs.stringify(data)
36
+ }
37
+ const reqConfig = {
38
+ ...config,
39
+ data
40
+ }
41
+ return new Promise(async (resolve, reject) => {
42
+ try {
43
+ if ((!NOT_AUTH_APIS.includes(url) && !loginToken)) {
44
+ await simulatelogin(messageInstance)
45
+ reqConfig.headers = {
46
+ ...(reqConfig.headers || {}),
47
+ Authorization: `Bearer ${loginToken}`
48
+ }
49
+ } else {
50
+ if (!NOT_AUTH_APIS.includes(url)) {
51
+ if ((EXPIRATION_Time.getTime() - new Date().getTime()) < THRESHOLD_TIME && REFRESH_TOKEN !== url) {
52
+ await refreshToken(messageInstance)
53
+ reqConfig.headers = {
54
+ ...(reqConfig.headers || {}),
55
+ Authorization: `Bearer ${loginToken}`
56
+ }
57
+ } else {
58
+ reqConfig.headers = {
59
+ ...(reqConfig.headers || {}),
60
+ Authorization: `Bearer ${loginToken}`
61
+ }
59
62
  }
60
63
  }
61
64
  }
65
+ resolve(reqConfig)
66
+ } catch (error) {
67
+ reject()
62
68
  }
63
- resolve(reqConfig)
64
- } catch (error) {
65
- reject()
66
- }
67
- })
68
- },
69
- error => {
70
- return Promise.reject(error)
71
- }
72
- )
69
+ })
70
+ },
71
+ error => {
72
+ return Promise.reject(error)
73
+ }
74
+ )
73
75
 
74
- // response interceptor
75
- service.interceptors.response.use(
76
- response => {
77
- // const { config } = response
78
- return response
79
- },
80
- error => {
81
- return error
82
- }
83
- )
76
+ // response interceptor
77
+ service.interceptors.response.use(
78
+ response => {
79
+ // const { config } = response
80
+ return response
81
+ },
82
+ error => {
83
+ return error
84
+ }
85
+ )
86
+ }
84
87
 
85
88
  export function buildInRequest(url, data, config = {}) {
86
89
  const reqConfig = {
@@ -97,7 +100,7 @@ export function buildInRequest(url, data, config = {}) {
97
100
  return service(reqConfig)
98
101
  }
99
102
 
100
- function simulatelogin() {
103
+ function simulatelogin(messageInstance) {
101
104
  const MD5HashingInstance = HashingFactory.createMD5Hashing()
102
105
  return buildInRequest(LCP_LOGIN, {
103
106
  username: USER_NAME,
@@ -109,7 +112,7 @@ function simulatelogin() {
109
112
  'Content-Type': 'application/x-www-form-urlencoded'
110
113
  },
111
114
  }).then(res => {
112
- if (res.data && res.data.resultCode === '000000') {
115
+ if (resultToast(res.data, messageInstance, {noSuccessIip: true})) {
113
116
  loginToken = res.data.result.token
114
117
  EXPIRATION_Time = dayjs(new Date()).add(2, 'hours').toDate()
115
118
  return Promise.resolve(res)
@@ -120,9 +123,9 @@ function simulatelogin() {
120
123
  }
121
124
 
122
125
 
123
- function refreshToken() {
126
+ function refreshToken(messageInstance) {
124
127
  return buildInRequest(REFRESH_TOKEN).then(res => {
125
- if (res.data && res.data.resultCode === '000000') {
128
+ if (resultToast(res.data, messageInstance, {noSuccessIip: true})) {
126
129
  loginToken = res.data.result
127
130
  EXPIRATION_Time = dayjs(new Date()).add(2, 'hours').toDate()
128
131
  return Promise.resolve(res)
@@ -0,0 +1,41 @@
1
+ export const RESULT_CODE = {
2
+ SUCCESS: '000000',
3
+ INFO: '000088',
4
+ WARNING: '000099',
5
+ ERROR: '000000',
6
+ OTHER: '020002'
7
+ }
8
+ export function resultToast(result = {}, messageInstance, {noSuccessIip = false} = {}) {
9
+ let ret = false
10
+ const resultMessage = result?.resultMessage || ''
11
+ const resultCode = result.resultCode
12
+ switch (resultCode) {
13
+ case RESULT_CODE.SUCCESS:
14
+ if (!noSuccessIip) {
15
+ messageInstance?.success(resultMessage)
16
+ }
17
+ ret = true
18
+ break;
19
+ case RESULT_CODE.INFO:
20
+ if (messageInstance.info && typeof messageInstance.info === 'function') {
21
+ messageInstance.info(resultMessage)
22
+ } else if (messageInstance.text && typeof messageInstance.text === 'function') {
23
+ // 移动端兼容写法
24
+ messageInstance.text(resultMessage)
25
+ }
26
+ break;
27
+ case RESULT_CODE.WARNING:
28
+ messageInstance?.warning(resultMessage)
29
+ break;
30
+ case RESULT_CODE.ERROR:
31
+ messageInstance?.error(resultMessage)
32
+ break;
33
+ case RESULT_CODE.OTHER:
34
+ messageInstance?.error(resultMessage)
35
+ break;
36
+ default:
37
+ messageInstance?.error(resultMessage)
38
+ break;
39
+ }
40
+ return ret
41
+ }