Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
corporate-culture-qd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王立鹏
corporate-culture-qd
Commits
d48b10fd
Commit
d48b10fd
authored
Jun 05, 2026
by
lijiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【需求 22261】 refactor: 重构关于初始化SDK相关代码
parent
0810b91c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
59 deletions
+111
-59
App.vue
src/App.vue
+0
-2
index.ts
src/utils/wxUtil/index.ts
+31
-3
initWXConfig.ts
src/utils/wxUtil/initWXConfig.ts
+61
-50
actionButtons.vue
src/views/articleDetail/components/actionButtons.vue
+7
-2
index.vue
src/views/questionDetail/index.vue
+6
-1
index.vue
src/views/videoDetail/index.vue
+6
-1
No files found.
src/App.vue
View file @
d48b10fd
...
...
@@ -22,9 +22,7 @@ const locale = ref(zhCn)
onMounted
(()
=>
{
// console.table(__CORE_LIB_VERSION__)
if
(
import
.
meta
.
env
.
MODE
===
'production'
)
{
setTimeout
(()
=>
{
initWxConfig
()
},
3000
)
}
})
</
script
>
src/utils/wxUtil/index.ts
View file @
d48b10fd
export
*
from
'./wxLogin'
export
*
from
'./initWXConfig'
import
*
as
ww
from
'@wecom/jssdk'
import
{
initWxConfig
}
from
'./initWXConfig'
const
DEFAULT_SHARE_TITLE
=
'企业文化'
const
DEFAULT_SHARE_DESC
=
'点击查看详情'
...
...
@@ -14,15 +15,41 @@ interface IShareWxOption {
imgUrl
?:
string
}
export
async
function
wxShare
(
option
:
IShareWxOption
)
{
await
ww
.
shareAppMessage
({
interface
IShareWxResult
{
err_msg
?:
string
errMsg
?:
string
}
export
async
function
wxShare
(
option
:
IShareWxOption
):
Promise
<
IShareWxResult
>
{
await
initWxConfig
()
return
new
Promise
((
resolve
,
reject
)
=>
{
ww
.
invoke
(
'shareAppMessage'
,
{
title
:
option
.
title
||
DEFAULT_SHARE_TITLE
,
desc
:
option
.
desc
||
DEFAULT_SHARE_DESC
,
link
:
option
.
link
||
location
.
href
,
imgUrl
:
option
.
imgUrl
||
DEFAULT_SHARE_IMAGE
,
},
function
(
res
:
IShareWxResult
)
{
const
errMsg
=
res
.
err_msg
||
res
.
errMsg
if
(
errMsg
===
'shareAppMessage:ok'
||
errMsg
===
'openExistedChatWithMsg:ok'
)
{
resolve
(
res
)
}
else
{
reject
(
res
)
}
},
)
})
}
export
function
isWxShareCancel
(
error
:
unknown
)
{
const
err
=
error
as
{
errMsg
?:
string
;
err_msg
?:
string
;
message
?:
string
}
return
[
err
.
errMsg
,
err
.
err_msg
,
err
.
message
].
some
((
msg
)
=>
msg
?.
includes
(
'shareAppMessage:cancel'
),
)
}
interface
ISelectDepOrUser
{
err_msg
:
string
result
:
IResult
...
...
@@ -44,7 +71,8 @@ export interface ISelectDept {
name
:
string
}
export
function
selectDepOrUser
(
wxOption
=
{}):
Promise
<
IResult
>
{
export
async
function
selectDepOrUser
(
wxOption
=
{}):
Promise
<
IResult
>
{
await
initWxConfig
()
const
defaultOption
=
{
fromDepartmentId
:
-
1
,
mode
:
'single'
,
...
...
src/utils/wxUtil/initWXConfig.ts
View file @
d48b10fd
/* 企业微信js配置 */
//注意:如果要在页面调用企业微信内部方法,请现在下面的jsApiList数组中添加方法
import
{
getWxSignature
}
from
'@/api'
import
*
as
ww
from
'@wecom/jssdk'
// export async function initWxConfig() {
// const url = location.href.split('#')[0]
// const response = await getWxSignature(url)
// const timestamp = response.data.timestamp //时间戳
// const nonceStr = response.data.nonceStr //随机字符串
// const signature = response.data.signature //签名
// const appId = response.data.appId //企业id
// wx.config({
// beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
// appId: appId, // 必填,企业微信的corpID
// timestamp: timestamp, // 必填,生成签名的时间戳
// nonceStr: nonceStr, // 必填,生成签名的随机串
// signature: signature, // 必填,签名,见附录1
// jsApiList: [
// // 所有要调用的 API 都要加到这个列表中
// 'shareAppMessage',
// 'selectEnterpriseContact',
// ],
// // success: function (result) {
// // // 回调
// // }
// })
// }
export
async
function
initWxConfig
()
{
let
wxConfigPromise
:
Promise
<
void
>
|
null
=
null
export
function
initWxConfig
()
{
if
(
wxConfigPromise
)
return
wxConfigPromise
wxConfigPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
;(
async
()
=>
{
try
{
const
url
=
location
.
href
.
split
(
'#'
)[
0
]
const
response
=
await
getWxSignature
(
url
!
)
const
timestamp
=
response
.
data
.
timestamp
//时间戳
const
nonceStr
=
response
.
data
.
nonceStr
//随机字符串
const
signature
=
response
.
data
.
signature
//签名
// const appId = response.data.appId //企业id
const
corpId
=
response
.
data
.
corpid
//企业id
const
agentId
=
response
.
data
.
agentid
//应用id
ww
.
register
({
corpId
,
// 必填,当前用户企业所属企业ID
agentId
,
// 必填,当前应用的AgentID
jsApiList
:
[
'shareAppMessage'
,
'selectEnterpriseContact'
],
// 必填,需要使用的JSAPI列表
getConfigSignature
:
function
()
{
return
{
timestamp
:
timestamp
,
nonceStr
:
nonceStr
,
signature
:
signature
,
const
{
data
}
=
await
getWxSignature
(
url
!
)
let
resolved
=
false
const
timer
=
window
.
setTimeout
(()
=>
{
if
(
!
resolved
)
{
resolved
=
true
console
.
warn
(
'企业微信 SDK 初始化未返回成功回调,继续执行后续操作'
)
resolve
()
}
},
3000
)
const
handleFail
=
(
error
:
unknown
)
=>
{
window
.
clearTimeout
(
timer
)
wxConfigPromise
=
null
reject
(
error
)
}
const
handleConfigSuccess
=
()
=>
{
if
(
!
resolved
)
{
resolved
=
true
window
.
clearTimeout
(
timer
)
resolve
()
}
},
// 必填,根据url生成企业签名的回调函数
getAgentConfigSignature
:
function
()
{
return
{
timestamp
:
timestamp
,
nonceStr
:
nonceStr
,
signature
:
signature
,
}
},
// 必填,根据url生成应用签名的回调函数
const
signature
=
{
timestamp
:
data
.
timestamp
,
nonceStr
:
data
.
nonceStr
,
signature
:
data
.
signature
,
}
ww
.
register
({
corpId
:
data
.
corpid
,
agentId
:
data
.
agentid
,
jsApiList
:
[
'shareAppMessage'
,
'selectEnterpriseContact'
],
getConfigSignature
()
{
return
signature
},
getAgentConfigSignature
()
{
return
signature
},
onConfigSuccess
:
handleConfigSuccess
,
onAgentConfigSuccess
:
handleConfigSuccess
,
onConfigFail
:
handleFail
,
onAgentConfigFail
(
error
)
{
console
.
warn
(
error
)
},
})
}
catch
(
error
)
{
console
.
error
(
error
)
wxConfigPromise
=
null
reject
(
error
)
}
})()
})
return
wxConfigPromise
}
src/views/articleDetail/components/actionButtons.vue
View file @
d48b10fd
...
...
@@ -36,7 +36,7 @@ import type { Component } from 'vue'
import
{
useScrollTop
}
from
'@/hooks'
import
{
addOrCanceArticlelCollect
,
addOrCanceArticlelLike
}
from
'@/api'
import
{
push
}
from
'notivue'
import
{
wxShare
}
from
'@/utils/wxUtil'
import
{
isWxShareCancel
,
wxShare
}
from
'@/utils/wxUtil'
const
modelValue
=
defineModel
<
ArticleItemDto
>
(
'modelValue'
,
{
required
:
true
})
...
...
@@ -118,8 +118,13 @@ const stats = computed(() => {
})
push
.
success
(
'分享成功'
)
}
catch
(
error
)
{
if
(
isWxShareCancel
(
error
))
{
console
.
warn
(
error
)
push
.
warning
(
'取消分享'
)
return
}
console
.
error
(
error
)
push
.
error
(
'分享失败'
)
push
.
error
(
'分享失败
,请刷新页面重新分享
'
)
}
},
},
...
...
src/views/questionDetail/index.vue
View file @
d48b10fd
...
...
@@ -470,7 +470,7 @@ import { storeToRefs } from 'pinia'
import
{
useNavigation
,
useScrollTop
}
from
'@/hooks'
import
{
useMessageBox
}
from
'@/hooks'
import
{
parseEmoji
}
from
'@/utils/emoji'
import
{
wxShare
}
from
'@/utils/wxUtil'
import
{
isWxShareCancel
,
wxShare
}
from
'@/utils/wxUtil'
import
{
ArticleTypeEnum
,
BooleanFlag
}
from
'@/constants'
import
{
push
}
from
'notivue'
import
{
CommentSortTypeEnum
}
from
'@/constants'
...
...
@@ -587,6 +587,11 @@ const handleShareQuestion = async () => {
})
push
.
success
(
'分享成功'
)
}
catch
(
error
)
{
if
(
isWxShareCancel
(
error
))
{
console
.
warn
(
error
)
push
.
warning
(
'取消分享'
)
return
}
console
.
error
(
error
)
push
.
error
(
'分享失败'
)
}
...
...
src/views/videoDetail/index.vue
View file @
d48b10fd
...
...
@@ -356,7 +356,7 @@ import ActionMore from '@/components/common/ActionMore/index.vue'
import
SendMessageDialog
from
'@/components/common/SendMessageDialog/index.vue'
import
BackButton
from
'@/components/common/BackButton/index.vue'
import
{
useNavigation
}
from
'@/hooks'
import
{
wxShare
}
from
'@/utils/wxUtil'
import
{
isWxShareCancel
,
wxShare
}
from
'@/utils/wxUtil'
import
{
ArticleTypeEnum
,
BooleanFlag
,
...
...
@@ -564,6 +564,11 @@ const handleShareVideo = async () => {
})
push
.
success
(
'分享成功'
)
}
catch
(
error
)
{
if
(
isWxShareCancel
(
error
))
{
console
.
warn
(
error
)
push
.
warning
(
'取消分享'
)
return
}
console
.
error
(
error
)
push
.
error
(
'分享失败'
)
}
...
...
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