金民工程向黑龙江民政厅合并

This commit is contained in:
2023-02-21 18:28:28 +08:00
parent 4f3a43885d
commit cde000b511
2 changed files with 3 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
<template>
<section class="AppJinMinLogin">
<AiResult :tips="errTip" :status="err" class="t-center"/>
</section>
</template>
<script>
import {mapActions} from "vuex";
export default {
name: "AppJinMinLogin",
appName: "金民工程登录",
data() {
return {err: "loading"}
},
computed: {
errTip: v => ({
loading: "正在登录中...",
error: "登录失败!"
}[v.err]),
},
methods: {
...mapActions(['getCode']),
handleLogin() {
const {code} = this.$route.query
if (code) {
this.$http.post("/app/wxcp/portal/hljJmgcLogin", null, {
withoutToken: true,
params: {code}
}).then(res => {
const token = res?.data?.data?.["TA-JTOKEN"]
if (token) {
// location.replace()
}
}).catch(() => this.err = "error")
} else this.getCode();
}
},
onShow() {
this.handleLogin()
}
}
</script>
<style lang="scss" scoped>
.AppJinMinLogin {
}
</style>

View File

@@ -0,0 +1,93 @@
import http from "axios";
const timer = {}
/**
* 企业微信工具类
* @param config 应用配置
* @param agentSignURL 授权url
* @param apiList 授权的接口集合
*/
class wxworkKit {
constructor() {
this.agentSignURL = ""
this.agentSign()
}
/**
* 授权jssdk在url上使用,并获取当前的企业微信应用配置
* @param params
* @returns {Promise<void>}
*/
agentSign(params = {}) {
//授权jssdk在url上使用,并获取corpId
const url = window.location.href
if (this.agentSignURL == url && this.config.corpId) {
return Promise.resolve()
} else {
this.agentSignURL = url
this.apiList = []
return http.post("https://mzt.hlj.gov.cn/mztweb/app/wxcp/portal/agentSign", null, {
params: {...params, url}
}).then(res => {
if (res?.data?.data) {
const config = {
...params,
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
beta: true,// 必须这么写否则wx.invoke调用形式的jsapi会有问题
corpId: res.data.corpid, // 必填企业微信的corpid必须与当前登录的企业一致
agentId: res.data.agentid, // 必填企业微信的应用id e.g. 1000247
timestamp: Number(res.data.timestamp), // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
...res.data.data
}
this.config = config
return config
}
}).catch(err => {
console.error(err)
})
}
}
/**
* 授权jssdk的使用
* @param apis 可以为数组或者单字符串
* @returns {Promise<unknown>}
*/
injectJWeixin(apis) {
const inject = (jsApiList) => new Promise((resolve, reject) => {
jsApiList = jsApiList || []
if (timer.injectJWeixin) {//节流设置,500ms内的多次请求合并到一处
clearTimeout(timer.injectJWeixin)
jsApiList = [...new Set([...this.apiList, ...jsApiList])]
this.apiList = jsApiList
}
timer.injectJWeixin = setTimeout(() => {
const sdk = wx?.agentConfig ? wx : jWeixin
console.log("agentConfig配置:")
console.log({...this.config, jsApiList})
sdk?.agentConfig({
...this.config, jsApiList,
success: res => resolve(res),
fail: err => {
console.error(err)
reject(err)
}
})
}, 500)
})
return inject([apis].flat().filter(Boolean))
}
/**
* 判断是否为企业微信环境
* @returns {boolean}
*/
static isWxwork() {
return /wxwork/i.test(navigator.userAgent)
}
}
export default wxworkKit