提交 18175022 作者: 毛细亚

更新代码

上级 f45d4f1a
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended'
],
parserOptions: {
parser: '@babel/eslint-parser'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
.DS_Store .DS_Store
node_modules node_modules
/dist /dist
/company_app
# local env files # local env files
...@@ -21,3 +22,4 @@ pnpm-debug.log* ...@@ -21,3 +22,4 @@ pnpm-debug.log*
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>cebianlan</title><script src="./js/jweixin-1.2.0.js"></script><script src="./js/jwxwork-1.0.0.js"></script><script defer="defer" src="static/js/app.23002ac1.js"></script><link href="static/css/app.3ca40e10.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but cebianlan doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> <!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>cebianlan</title><script src="./js/jweixin-1.2.0.js"></script><script src="./js/jwxwork-1.0.0.js"></script><script defer="defer" src="static/js/app.ff6fb11f.js"></script><link href="static/css/app.3ca40e10.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but cebianlan doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
\ No newline at end of file \ No newline at end of file
"use strict";(self["webpackChunkcebianlan"]=self["webpackChunkcebianlan"]||[]).push([[155],{155:function(n,t,u){u.r(t),u.d(t,{default:function(){return r}});var a=function(){var n=this;n._self._c;return n._m(0)},e=[function(){var n=this,t=n._self._c;return t("div",{staticClass:"about"},[t("h1",[n._v("about")])])}],l=u(477),s={},c=(0,l.A)(s,a,e,!1,null,null,null),r=c.exports}}]);
//# sourceMappingURL=155.934a6805.js.map
\ No newline at end of file
{"version":3,"file":"static/js/155.934a6805.js","mappings":"6JAAA,IAAIA,EAAS,WAAkB,IAAIC,EAAIC,KAAQD,EAAIE,MAAMC,GAAG,OAAOH,EAAII,GAAG,EAC1E,EACIC,EAAkB,CAAC,WAAY,IAAIL,EAAIC,KAAKE,EAAGH,EAAIE,MAAMC,GAAG,OAAOA,EAAG,MAAM,CAACG,YAAY,SAAS,CAACH,EAAG,KAAK,CAACH,EAAIO,GAAG,YACvH,G,SCFIC,EAAS,CAAC,EAKVC,GAAY,OACdD,EACAT,EACAM,GACA,EACA,KACA,KACA,MAIF,EAAeI,EAAiB,O","sources":["webpack://cebianlan/./src/views/AboutView.vue","webpack://cebianlan/./src/views/AboutView.vue?d8cd"],"sourcesContent":["var render = function render(){var _vm=this,_c=_vm._self._c;return _vm._m(0)\n}\nvar staticRenderFns = [function (){var _vm=this,_c=_vm._self._c;return _c('div',{staticClass:\"about\"},[_c('h1',[_vm._v(\"about\")])])\n}]\n\nexport { render, staticRenderFns }","import { render, staticRenderFns } from \"./AboutView.vue?vue&type=template&id=70bd5d4c\"\nvar script = {}\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.14_css-loader@6.11.0_webpack@5.99.8__lodash@4._898f46ed7f437ee9a834018c670400fe/node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports"],"names":["render","_vm","this","_self","_c","_m","staticRenderFns","staticClass","_v","script","component"],"sourceRoot":""}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -23,14 +23,10 @@ ...@@ -23,14 +23,10 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0", "@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-plugin-vuex": "~5.0.0", "@vue/cli-plugin-vuex": "~5.0.0",
"@vue/cli-service": "~5.0.0", "@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"vue-template-compiler": "^2.6.14" "vue-template-compiler": "^2.6.14"
} }
} }
<template> <template>
<div id="app"> <div id="app">
<router-view/> <router-view />
</div> </div>
</template> </template>
<script>
import { getAuthUser } from '@/api/user'
export default {
name: 'App',
components: {
},
created() {
this.handleAuthCode();
},
provide() {
return {
authPromise: new Promise((resolve) => {
this.resolveAuth = resolve;
})
};
},
methods: {
Authorize() {
// 先获取企微配置信息
let redirectUrl = location.origin + location.pathname;
let returnUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wweaefe716636df3d1&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
console.log('进入Authorize', returnUrl)
window.location.href = returnUrl;
},
handleAuthCode() {
const url = window.location.href;
const questionMarkIndex = url.indexOf('?');
const hashIndex = url.indexOf('#/');
// 确保URL中包含问号和#/
if (questionMarkIndex !== -1 && hashIndex !== -1) {
// 截取?和#/之间的内容
let params = url.substring(questionMarkIndex + 1, hashIndex);
if (params) {
// 将参数字符串转换为对象
let paramsObj = Object.fromEntries(
params.split('&').map(param => param.split('='))
)
console.log(paramsObj, 'paramsObj')
const { code, corp_id } = paramsObj;
const userid = sessio.getItem('userid');
if (userid) {
} else {
getWxUserInfo(code, corp_id);
}
} else {
Authorize(to);
}
} else {
Authorize(to);
}
},
getWxUserInfo(authCode) {
getAuthUser({ code: authCode, corp_id: 'wweaefe716636df3d1' }).then((res) => {
if (res.status_code === 1) {
let { userid } = res.data || {};
if (userid) {
localStorage.setItem('userid', userid);
// 解析 Promise
this.resolveAuth();
} else {
Authorize(to)
}
} else {
Authorize(to)
}
}).catch(() => {
Authorize(to)
})
}
},
}
</script>
<style> <style>
#app { #app {
......
// mixins/externalUserId.js
// 签名获取外部用户externalUserId逻辑
import { getSign, getAgentSign } from '@/api/user';
export default {
data() {
return {
externalUserId: ''
};
},
created() {
},
mounted() {
// 获取企业签名信息
localStorage.removeItem('externalUserId');
this.getCompanySign();
},
methods: {
//获取企业签名信息
getCompanySign() {
// let url = "获取config或agentConfig配置的参数接口";
//该paramUrl 为你使用微信sdk-js相关接口的页面地址 该地址需要配置到应用后台的可信域名下
let url = window.location.href.split("#")[0];
let params = { url };
getSign(params).then(res => {
this.companyConfigInit(res.data);
}).catch(err => {
console.log(err);
});
},
//企业验证配置
companyConfigInit(data) {
let that = this;
// noncestr: "ww09b472814e7d260f"
// signature: "442fde92aa1a440e5e9636364378186e6463306c"
// timestamp: "1647912587432
let { timestamp, noncestr, signature } = data || {};
let wxConfig = localStorage.getItem('wxConfig') ? JSON.parse(localStorage.getItem('wxConfig')) : {};
let { corpid } = wxConfig;
// eslint-disable-next-line
wx.config({
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: corpid, // 必填,企业微信的corpID
timestamp: timestamp, // 必填,生成签名的时间戳
nonceStr: noncestr, // 必填,生成签名的随机串
signature: signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: ["getContext", "getCurExternalContact", "invoke"] //你要调用的sdk接口必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
});
// eslint-disable-next-line
wx.ready(function () {
that.appAgentConfig();
});
// eslint-disable-next-line
wx.error(function (res) {
console.log('config失败了', res)
});
},
//获取应用签名信息
appAgentConfig() {
let url = window.location.href.split("#")[0];
let params = { url };
getAgentSign(params).then((res) => {
let { code, data, message } = res || {};
if (code === 200) {
this.appConfigInit(data);
} else {
console.log(message);
}
})
},
//应用验证配置
appConfigInit(data) {
let that = this;
let { timestamp, noncestr, signature } = data || {};
let wxConfig = localStorage.getItem('wxConfig') ? JSON.parse(localStorage.getItem('wxConfig')) : {};
let { corpid, agentid } = wxConfig;
// eslint-disable-next-line
wx.agentConfig({
corpid,
agentid,
timestamp: timestamp,
nonceStr: noncestr,
signature: signature,
jsApiList: ["getContext", "getCurExternalContact", "invoke"],
success: function () {
// eslint-disable-next-line
wx.invoke('getCurExternalContact', {
}, function (res) {
// alert('invoke成功了')
// alert(JSON.stringify(res),'invokeData数据')
console.log('invoke成功了', res)
if (res.err_msg == "getCurExternalContact:ok") {
localStorage.setItem('externalUserId', res.userId);
// this.$store.dispatch("common/setExternalUserId", res.userId);
that.externalUserId = res.userId; //返回当前外部联系人userId
// alert(that.externalUserId);
} else {
//错误处理
}
//查看相关接口是否可以调用
// that.checkJsApi();
});
},
fail: function (res) {
console.log('invoke失败了', res)
// alert('invoke失败了', res)
if (res.errMsg.indexOf("function not exist") > -1) {
alert("版本过低请升级");
}
}
});
},
}
}
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue' import HomeView from '../views/HomeView.vue'
import {getAuthUser} from '@/api/user'
Vue.use(VueRouter) Vue.use(VueRouter)
function Authorize() {
// 先获取企微配置信息
let redirectUrl = location.origin + location.pathname;
let returnUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wweaefe716636df3d1&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
console.log('进入Authorize',returnUrl)
window.location.href = returnUrl;
}
// 通过oAuth2授权获取当前用户userId
function getWxUserInfo(to, from, next, authCode) {
console.log('进入getWxUserInfo',authCode)
getAuthUser({code:authCode,corp_id:'wweaefe716636df3d1'}).then((res) => {
console.log(res,'res')
if (res.status_code === 1) {
let { userId } = res.data || {};
if (userId) {
localStorage.setItem('userId', userId);
next();
} else {
Authorize(to)
}
} else {
// PC端侧边栏tab页面切换后再切回来, 页面地址还是上次重定向后的带code的,此时code已经消费过一次,再调接口获取用户信息会失败, 所以加上重新授权的逻辑
Authorize(to)
}
}).catch(() => {
Authorize(to)
})
}
const routes = [ const routes = [
{ {
path: '/', path: '/',
...@@ -44,32 +14,9 @@ const routes = [ ...@@ -44,32 +14,9 @@ const routes = [
component: () => import('../views/AboutView.vue') component: () => import('../views/AboutView.vue')
} }
] ]
const router = new VueRouter({ const router = new VueRouter({
mode: 'hash', mode: 'hash',
base: process.env.BASE_URL, base: process.env.BASE_URL,
routes routes
}) })
router.beforeEach((to, from, next) => {
// 判断是否是微信浏览器打开
let ua = navigator.userAgent.toLowerCase();
let isWeixin = ua.indexOf('micromessenger') != -1;
console.log('isWeixin',isWeixin)
if (!isWeixin) {
next()
return
}
console.log('进入router.beforeEach',to.query)
// 企微环境获取当前用户userId和外部客户externalUserId
let code = to.query.code || '';
let corp_id = to.query.corp_id || '';
if (code) {
// 有code说明是授权过的,重定向地址, 调接口获取当前用户信息
getWxUserInfo(to, from, next, code,corp_id);
} else {
// 获取授权
Authorize(to);
}
})
export default router export default router
...@@ -31,11 +31,6 @@ service.interceptors.request.use( ...@@ -31,11 +31,6 @@ service.interceptors.request.use(
const url = config.data const url = config.data
? config.url + JSON.stringify(config.data) ? config.url + JSON.stringify(config.data)
: config.url : config.url
store.state.user.axiosCancelList.push({
url,
cancel: c
})
}) })
// 设置认证token // 设置认证token
......
<template> <template>
<div class="about"> <div class="about">
<h1>about</h1> <h1 @click="$router.push('/')">about</h1>
</div> </div>
</template> </template>
<template> <template>
<div class="home"> <div class="home">
<h1>home</h1> <h1 @click="$router.push('/about')">home</h1>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'HomeView', name: 'HomeView',
components: { inject: ['authPromise'],
created() {
// 等待认证完成后执行 getAuthUser
this.authPromise.then(() => {
this.getAuthUser();
});
},
methods: {
getAuthUser() {
console.log('getAuthUser')
}
} }
} }
</script> </script>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论