Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
胡锦波
/
org-manager-web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
579d89ce
authored
Apr 08, 2022
by
胡锦波
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1. init sdk请求打通
parent
6f71b59f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
39 deletions
src/api/core.ts
src/api/sdk-service.ts
src/views/pages/employ-management/address-book/address-book.vue
src/api/core.ts
View file @
579d89ce
...
@@ -33,7 +33,7 @@ export default abstract class BaseService {
...
@@ -33,7 +33,7 @@ export default abstract class BaseService {
protected
readonly
positiveValue
=
1
;
protected
readonly
positiveValue
=
1
;
protected
readonly
negativeValue
=
0
;
protected
readonly
negativeValue
=
0
;
private
once
App
Id
:
string
|
number
=
0
;
private
once
Company
Id
:
string
|
number
=
0
;
protected
constructor
()
{
protected
constructor
()
{
if
(
!
this
.
isDevEnvironment
())
{
if
(
!
this
.
isDevEnvironment
())
{
...
@@ -189,43 +189,16 @@ export default abstract class BaseService {
...
@@ -189,43 +189,16 @@ export default abstract class BaseService {
return
config
;
return
config
;
}
}
p
ublic
setEnterprise4Cache
(
data
:
any
)
{
p
rotected
useOnceApp
(
poid
:
string
|
number
)
{
localStorage
.
setItem
(
'currentEnterPriseList'
,
JSON
.
stringify
(
data
))
;
this
.
onceCompanyId
=
poid
;
}
}
public
getEnterprise4Cache
()
{
protected
async
buildCompanyToken2Config
(
config
?:
AxiosRequestConfig
)
{
const
item
=
localStorage
.
getItem
(
'currentEnterPriseList'
);
return
(
item
&&
JSON
.
parse
(
item
))
||
null
;
}
public
getEnterpriseToken4RegisterId
()
{
const
currentRegisterId
=
localStorage
.
getItem
(
"currentTemmixCompany"
)
||
""
;
const
cache
=
this
.
getEnterprise4Cache
();
if
(
cache
&&
cache
[
currentRegisterId
])
{
return
cache
[
currentRegisterId
].
appRegisterId
;
}
return
''
;
}
public
getEnterpriseToken4Id
()
{
const
currentRegisterId
=
localStorage
.
getItem
(
"currentTemmixCompany"
)
||
""
;
const
cache
=
this
.
getEnterprise4Cache
();
if
(
cache
&&
cache
[
currentRegisterId
])
{
return
cache
[
currentRegisterId
].
id
;
}
return
''
;
}
protected
useOnceApp
(
app
:
string
|
number
)
{
this
.
onceAppId
=
app
;
}
protected
async
buildAppToken2Config
(
config
?:
AxiosRequestConfig
)
{
config
=
this
.
buildRequestConfig
(
config
);
config
=
this
.
buildRequestConfig
(
config
);
if
(
config
.
headers
)
{
if
(
config
.
headers
)
{
config
.
headers
[
this
.
authKey
]
=
await
TokenManager
.
getCompanyToken
(
this
.
once
AppId
||
this
.
getEnterpriseToken4RegisterId
()
);
config
.
headers
[
this
.
authKey
]
=
await
TokenManager
.
getCompanyToken
(
this
.
once
CompanyId
);
}
}
this
.
once
App
Id
=
0
;
this
.
once
Company
Id
=
0
;
return
this
.
checkContentType
(
config
);
return
this
.
checkContentType
(
config
);
}
}
...
@@ -251,8 +224,8 @@ export default abstract class BaseService {
...
@@ -251,8 +224,8 @@ export default abstract class BaseService {
return
this
.
invokeGet
(
url
,
config
)
as
Promise
<
T
>
;
return
this
.
invokeGet
(
url
,
config
)
as
Promise
<
T
>
;
}
}
protected
async
getWith
App
Token
<
T
>
(
url
:
string
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
protected
async
getWith
Company
Token
<
T
>
(
url
:
string
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
config
=
await
this
.
build
App
Token2Config
(
config
);
config
=
await
this
.
build
Company
Token2Config
(
config
);
return
this
.
invokeGet
(
url
,
config
)
as
Promise
<
T
>
;
return
this
.
invokeGet
(
url
,
config
)
as
Promise
<
T
>
;
}
}
...
@@ -261,13 +234,13 @@ export default abstract class BaseService {
...
@@ -261,13 +234,13 @@ export default abstract class BaseService {
return
this
.
invokePost
(
url
,
data
,
config
)
as
Promise
<
T
>
;
return
this
.
invokePost
(
url
,
data
,
config
)
as
Promise
<
T
>
;
}
}
protected
async
postWith
App
Token
<
T
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
protected
async
postWith
Company
Token
<
T
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
config
=
await
this
.
build
App
Token2Config
(
config
);
config
=
await
this
.
build
Company
Token2Config
(
config
);
return
this
.
invokePost
(
url
,
data
,
config
)
as
Promise
<
T
>
;
return
this
.
invokePost
(
url
,
data
,
config
)
as
Promise
<
T
>
;
}
}
protected
async
deleteWith
App
Token
<
T
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
protected
async
deleteWith
Company
Token
<
T
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
config
=
await
this
.
build
App
Token2Config
(
config
);
config
=
await
this
.
build
Company
Token2Config
(
config
);
return
this
.
invokeDelete
(
url
,
data
,
config
)
as
Promise
<
T
>
;
return
this
.
invokeDelete
(
url
,
data
,
config
)
as
Promise
<
T
>
;
}
}
...
...
src/api/sdk-service.ts
0 → 100644
View file @
579d89ce
import
Axios
,
{
AxiosRequestConfig
}
from
"axios"
;
import
{
TokenManager
}
from
"@/api/token"
;
import
EnterpriseHost
from
"@/views/service/enterprise-host"
;
class
SdkCoreService
{
private
baseUrl
=
""
;
private
config
=
{};
protected
async
buildSdkHeaders
()
{
this
.
baseUrl
=
'http://hro.test-api.qqxb.jinsehuaqin.com:8800'
||
process
.
env
.
VUE_APP_UNIPLAT_BASE_URL
||
'https://api-hro.qinqinxiaobao.com'
;
const
comid
=
EnterpriseHost
.
getPoid
();
const
token
=
await
TokenManager
.
getCompanyToken
(
comid
);
this
.
config
=
{
headers
:
{
passportToken
:
`
${
token
}
`
},
baseURL
:
this
.
baseUrl
,
};
return
this
.
config
;
}
protected
invokeGet
(
url
:
string
,
config
:
AxiosRequestConfig
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
Axios
.
get
(
`
${
this
.
baseUrl
}${
url
}
`
,
config
).
then
(
r
=>
{
if
(
!
r
)
{
return
reject
(
r
);
}
if
(
r
.
data
.
rescode
)
{
reject
(
r
.
data
);
}
else
{
resolve
(
r
.
data
.
data
);
}
});
});
}
protected
invokePost
(
url
:
string
,
body
:
any
,
config
=
this
.
config
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
Axios
.
post
(
`
${
this
.
baseUrl
}${
url
}
`
,
body
,
config
).
then
(
r
=>
{
if
(
!
r
)
{
return
reject
(
r
);
}
if
(
r
.
data
.
rescode
)
{
reject
(
r
.
data
);
}
else
{
resolve
(
r
.
data
.
data
);
}
});
});
}
protected
async
get
(
url
:
string
)
{
const
config
=
await
this
.
buildSdkHeaders
();
return
this
.
invokeGet
(
url
,
config
);
}
protected
async
post
(
url
:
string
,
body
:
any
)
{
const
config
=
await
this
.
buildSdkHeaders
();
return
this
.
invokePost
(
url
,
body
,
config
);
}
}
class
SdkService
extends
SdkCoreService
{
getJoinedList
()
{
return
this
.
get
(
`/system/org/joined/list`
);
}
getWaitJoinList
()
{
return
this
.
get
(
`/system/org/waitjoin/list`
);
}
}
const
sdkService
=
new
SdkService
();
export
{
sdkService
};
src/views/pages/employ-management/address-book/address-book.vue
View file @
579d89ce
...
@@ -10,10 +10,12 @@
...
@@ -10,10 +10,12 @@
import
{
Component
,
Vue
}
from
"vue-property-decorator"
;
import
{
Component
,
Vue
}
from
"vue-property-decorator"
;
import
{
TokenManager
}
from
"@/api/token"
;
import
{
TokenManager
}
from
"@/api/token"
;
import
EnterpriseHost
from
"@/views/service/enterprise-host"
;
import
EnterpriseHost
from
"@/views/service/enterprise-host"
;
import
{
sdkService
}
from
"@/api/sdk-service"
;
@
Component
({
components
:
{}
})
@
Component
({
components
:
{}
})
export
default
class
AddressBook
extends
Vue
{
export
default
class
AddressBook
extends
Vue
{
private
test
()
{
private
test
()
{
sdkService
.
getJoinedList
();
const
comid
=
EnterpriseHost
.
getPoid
();
const
comid
=
EnterpriseHost
.
getPoid
();
TokenManager
.
getCompanyToken
(
comid
);
TokenManager
.
getCompanyToken
(
comid
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment