提交 d695ffbf 作者: 毛细亚

企微调试完成

上级 c2e8be46
...@@ -5,5 +5,6 @@ VUE_APP_BASE_API = '/dev-api' ...@@ -5,5 +5,6 @@ VUE_APP_BASE_API = '/dev-api'
VUE_APP_URL = 'http://localhost:9528' VUE_APP_URL = 'http://localhost:9528'
# 掌权登录跳转url # 掌权登录跳转url
NODE_ENV = 'development'
ENV = 'development'
VUE_APP_ZQLOGIN_URL = 'http://zq.zwwlkj03.top'
# just a flag # just a flag
ENV = 'production' ENV = 'production'
NODE_ENV = 'production'
# base api # base api
VUE_APP_BASE_API = '/api/' VUE_APP_BASE_API = '/api/'
# 掌权登录跳转url
VUE_APP_ZQLOGIN_URL = 'http://zq.wozhangwan.com'
# build src
VUE_APP_BUILD_DIR = 'dist'
# just a flag
NODE_ENV = 'staging'
ENV = 'staging'
# base api
VUE_APP_BASE_API = '/api/'
<!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="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script><script defer="defer" src="static/js/chunk-vendors.fca6e705.js"></script><script defer="defer" src="static/js/app.e2a51498.js"></script><link href="static/css/chunk-vendors.f50bf6ae.css" rel="stylesheet"><link href="static/css/app.bd071c00.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>
\ No newline at end of file <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.0">
<link rel="icon" href="favicon.ico">
<title>cebianlan</title>
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>
<script defer src="static/js/chunk-vendors.js"></script><script defer src="static/js/app.js"></script></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>
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build:prod": "vue-cli-service build --mode prod",
"build:stage": "vue-cli-service build --mode staging",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
"babel-plugin-component": "^1.1.1", "babel-plugin-component": "^1.1.1",
"bi-eleme": "^2.4.4", "bi-eleme": "^2.4.4",
"bi-element-ui": "^1.5.2", "bi-element-ui": "^1.5.2",
"clipboard": "^2.0.11",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"dingtalk-jsapi": "^3.1.0", "dingtalk-jsapi": "^3.1.0",
"element-ui": "^2.15.14", "element-ui": "^2.15.14",
......
...@@ -23,6 +23,9 @@ importers: ...@@ -23,6 +23,9 @@ importers:
bi-element-ui: bi-element-ui:
specifier: ^1.5.2 specifier: ^1.5.2
version: 1.5.2 version: 1.5.2
clipboard:
specifier: ^2.0.11
version: 2.0.11
core-js: core-js:
specifier: ^3.8.3 specifier: ^3.8.3
version: 3.42.0 version: 3.42.0
...@@ -1478,6 +1481,9 @@ packages: ...@@ -1478,6 +1481,9 @@ packages:
resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==}
engines: {node: '>=6'} engines: {node: '>=6'}
clipboard@2.0.11:
resolution: {integrity: sha512-C+0bbOqkezLIsmWSvlsXS0Q0bmkugu7jcfMIACB+RDEntIzQIkdr148we28AfSloQLRdZlYL/QYyrq05j/3Faw==}
clipboardy@2.3.0: clipboardy@2.3.0:
resolution: {integrity: sha512-mKhiIL2DrQIsuXMgBgnfEHOZOryC7kY7YO//TN6c63wlEm3NG5tz+YgY5rVi29KCmq/QQjKYvM7a19+MDOTHOQ==} resolution: {integrity: sha512-mKhiIL2DrQIsuXMgBgnfEHOZOryC7kY7YO//TN6c63wlEm3NG5tz+YgY5rVi29KCmq/QQjKYvM7a19+MDOTHOQ==}
engines: {node: '>=8'} engines: {node: '>=8'}
...@@ -2004,6 +2010,9 @@ packages: ...@@ -2004,6 +2010,9 @@ packages:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'} engines: {node: '>=0.4.0'}
delegate@3.2.0:
resolution: {integrity: sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==}
depd@1.1.2: depd@1.1.2:
resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==} resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==}
engines: {node: '>= 0.6'} engines: {node: '>= 0.6'}
...@@ -2543,6 +2552,9 @@ packages: ...@@ -2543,6 +2552,9 @@ packages:
resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==}
engines: {node: '>=10'} engines: {node: '>=10'}
good-listener@1.2.2:
resolution: {integrity: sha512-goW1b+d9q/HIwbVYZzZ6SsTr4IgE+WA44A0GmPIQstuOrgsFcT7VEJ48nmr9GaRtNu0XTKacFLGnBPAM6Afouw==}
gopd@1.2.0: gopd@1.2.0:
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==} resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
...@@ -4230,6 +4242,9 @@ packages: ...@@ -4230,6 +4242,9 @@ packages:
select-hose@2.0.0: select-hose@2.0.0:
resolution: {integrity: sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==} resolution: {integrity: sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==}
select@1.1.2:
resolution: {integrity: sha512-OwpTSOfy6xSs1+pwcNrv0RBMOzI39Lp3qQKUTPVVPRjCdNa5JH/oPRiqsesIskK8TVgmRiHwO4KXlV2Li9dANA==}
selfsigned@2.4.1: selfsigned@2.4.1:
resolution: {integrity: sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==} resolution: {integrity: sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==}
engines: {node: '>=10'} engines: {node: '>=10'}
...@@ -4593,6 +4608,9 @@ packages: ...@@ -4593,6 +4608,9 @@ packages:
resolution: {integrity: sha512-G7r3AhovYtr5YKOWQkta8RKAPb+J9IsO4uVmzjl8AZwfhs8UcUwTiD6gcJYSgOtzyjvQKrKYn41syHbUWMkafA==} resolution: {integrity: sha512-G7r3AhovYtr5YKOWQkta8RKAPb+J9IsO4uVmzjl8AZwfhs8UcUwTiD6gcJYSgOtzyjvQKrKYn41syHbUWMkafA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
tiny-emitter@2.1.0:
resolution: {integrity: sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==}
to-arraybuffer@1.0.1: to-arraybuffer@1.0.1:
resolution: {integrity: sha512-okFlQcoGTi4LQBG/PgSYblw9VOyptsz2KJZqc6qtgGdes8VktzUQkj4BI2blit072iS8VODNcMA+tvnS9dnuMA==} resolution: {integrity: sha512-okFlQcoGTi4LQBG/PgSYblw9VOyptsz2KJZqc6qtgGdes8VktzUQkj4BI2blit072iS8VODNcMA+tvnS9dnuMA==}
...@@ -7027,6 +7045,12 @@ snapshots: ...@@ -7027,6 +7045,12 @@ snapshots:
cli-spinners@2.9.2: {} cli-spinners@2.9.2: {}
clipboard@2.0.11:
dependencies:
good-listener: 1.2.2
select: 1.1.2
tiny-emitter: 2.1.0
clipboardy@2.3.0: clipboardy@2.3.0:
dependencies: dependencies:
arch: 2.2.0 arch: 2.2.0
...@@ -7449,6 +7473,8 @@ snapshots: ...@@ -7449,6 +7473,8 @@ snapshots:
delayed-stream@1.0.0: {} delayed-stream@1.0.0: {}
delegate@3.2.0: {}
depd@1.1.2: {} depd@1.1.2: {}
depd@2.0.0: {} depd@2.0.0: {}
...@@ -8145,6 +8171,10 @@ snapshots: ...@@ -8145,6 +8171,10 @@ snapshots:
merge2: 1.4.1 merge2: 1.4.1
slash: 3.0.0 slash: 3.0.0
good-listener@1.2.2:
dependencies:
delegate: 3.2.0
gopd@1.2.0: {} gopd@1.2.0: {}
got@7.1.0: got@7.1.0:
...@@ -9915,6 +9945,8 @@ snapshots: ...@@ -9915,6 +9945,8 @@ snapshots:
select-hose@2.0.0: {} select-hose@2.0.0: {}
select@1.1.2: {}
selfsigned@2.4.1: selfsigned@2.4.1:
dependencies: dependencies:
'@types/node-forge': 1.3.11 '@types/node-forge': 1.3.11
...@@ -10363,6 +10395,8 @@ snapshots: ...@@ -10363,6 +10395,8 @@ snapshots:
timed-out@4.0.1: timed-out@4.0.1:
optional: true optional: true
tiny-emitter@2.1.0: {}
to-arraybuffer@1.0.1: {} to-arraybuffer@1.0.1: {}
to-buffer@1.1.1: to-buffer@1.1.1:
......
<template> <template>
<div id="app"> <div id="app">
<!-- <h1>客服id:{{userInfo.userid}}</h1> <router-view></router-view>
<h1>客户id:{{userInfo.externalUserId}}</h1> -->
<router-view />
</div> </div>
</template> </template>
<script> <script>
import * as ww from '@wecom/jssdk'
import { getAuthUser } from '@/api/user'
import {mapState,mapMutations} from 'vuex'
import DdLogin from '@/views/ddLogin'
export default { export default {
name: 'App', name: 'App',
components: {
DdLogin
},
created() { created() {
// this.handleAuthCode();
}, },
data() { data() {
return { return {
...@@ -24,161 +14,13 @@ export default { ...@@ -24,161 +14,13 @@ export default {
} }
}, },
computed: { computed: {
...mapState('user', ['userInfo','userid'])
}, },
methods: { methods: {
...mapMutations('user',['set_userInfo','set_userid']),
Authorize() { }
// 先获取企微配置信息
let redirectUrl = location.origin + location.pathname;
let returnUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wweaefe716636df3d1&redirect_uri=${encodeURIComponent(redirectUrl)}&type=auth&response_type=code&scope=snsapi_base&state=wweaefe716636df3d1#wechat_redirect`
this.num++;
console.log('进入Authorize', returnUrl)
if(this.num>3){
return
}
window.location.href = returnUrl;
},
handleAuthCode() {
console.log('进入handleAuthCode')
const url = window.location.href;
const questionMarkIndex = url.indexOf('?');
const hashIndex = url.indexOf('#/');
// 确保URL中包含问号和#/
if (questionMarkIndex !== -1 && hashIndex !== -1) {
console.log('questionMarkIndex')
// 截取?和#/之间的内容
let params = url.substring(questionMarkIndex + 1, hashIndex);
if (params) {
console.log('params')
// 将参数字符串转换为对象
let paramsObj = Object.fromEntries(
params.split('&').map(param => param.split('='))
)
const { code, corp_id } = paramsObj;
if(code){
console.log('code')
this.getWxUserInfo(code, corp_id);
}else{
console.log('nocode')
this.Authorize();
}
} else {
console.log('noparams')
this.Authorize();
}
} else {
console.log('no questionMarkIndex')
this.Authorize();
}
},
getWxUserInfo(authCode) {
console.log('进入getWxUserInfo')
getAuthUser({ code: authCode, corp_id: 'wweaefe716636df3d1' }).then((res) => {
if (res.status_code === 1) {
let { userid } = res.data || {};
if ( res.data && userid) {
this.set_userInfo(res.data)
this.set_userid(userid)
this.register()
} else {
this.Authorize()
}
} else {
this.Authorize()
}
}).catch(() => {
console.log('请求 进入getWxUserInfo 失败')
this.Authorize()
})
},
register(data) {
console.log('进入register',this.userInfo)
let that = this
let jsApiList = ['checkJsApi', 'getContext', 'selectEnterpriseContact','getCurExternalContact'];
// 应用身份与权限
ww.register({
corpId: that.userInfo.corp_id, // 必填,当前用户企业所属企业ID
agentId: 1000013, // 必填,当前应用的AgentID
jsApiList: jsApiList, // 必填,需要使用的JSAPI列表
getConfigSignature:function(){ // // 必填,根据url生成企业签名的回调函数
return new Promise((resolve, reject) => {
resolve({
nonceStr: that.userInfo.nonceStr,
timestamp: that.userInfo.time,
signature: that.userInfo.corp_signature,
})
})
},
getAgentConfigSignature:function(){ // 必填,根据url生成应用签名的回调函数
return new Promise((resolve, reject) => {
resolve({
nonceStr: that.userInfo.nonceStr,
timestamp: that.userInfo.time,
signature: that.userInfo.agent_signature,
})
})
},
onConfigSuccess:function(res){
console.log('onConfigSuccess',res)
},
onConfigFail:function(err){
console.log('onConfigFail',err)
},
onConfigComplete:function(res){
console.log('onConfigComplete',res)
},
onAgentConfigSuccess:function(res){
console.log('onAgentConfigSuccess',res)
that.getCurExternalContact()
},
onAgentConfigFail:function(err){
console.log('onAgentConfigFail',err)
},
onAgentConfigComplete:function(res){
console.log('onAgentConfigComplete',res)
},
})
},
getCurExternalContact(){
let that = this;
ww.getCurExternalContact({
success: (res) => {
console.log('获取成功33',res)
if (res.err_msg === "getCurExternalContact:ok") {
console.log('获取成功开始',res.userId)
that.$set(that.userInfo,'externalUserId',res.userId)
that.set_userInfo(that.userInfo)
}
},
fail: (err) => {
console.log('获取失败',err)
}
})
}
},
} }
</script> </script>
<style> <style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style> </style>
import request from '@/utils/request' import request from '@/utils/request'
import axios from 'axios'
// import { getSignatureData } from '@wecom/jssdk' // import { getSignatureData } from '@wecom/jssdk'
export function cross_systemRequest(data) { export function cross_systemRequest(data) {
!data.noApi ? data.api = '/api' + data.api : '' !data.noApi ? data.api = '/api' + data.api : ''
...@@ -12,6 +13,7 @@ export function cross_systemRequest(data) { ...@@ -12,6 +13,7 @@ export function cross_systemRequest(data) {
data data
}) })
} }
// 获取 企微登录的信息
export function getAuthUser(data) { export function getAuthUser(data) {
return request({ return request({
url: '/api/sidebar_login/workWeiXin', url: '/api/sidebar_login/workWeiXin',
...@@ -19,28 +21,17 @@ export function getAuthUser(data) { ...@@ -19,28 +21,17 @@ export function getAuthUser(data) {
data data
}) })
} }
export function getSignature(data) { // 获取组织列表
// return getSignature(data)
}
export function getOrganization(data) { export function getOrganization(data) {
return new Promise((resovle, reject) => { return axios.post('https://zq.zwwlkj03.top/api/login/organization',data)
cross_systemRequest({
system: 'zq',
api: '/api/login/organization',
params: data
}).then((res) => {
resovle(res)
})
})
} }
// 获取签名信息
export function getSignature(data) {
export function getDingLogin(data) { return request({
return request({ url: '/sidebar/work_wei_xin/signature',
url: '/api/sidebar_login/ding', method: 'post',
method: 'post', data
data })
})
} }
......
...@@ -40,4 +40,7 @@ ...@@ -40,4 +40,7 @@
```js ```js
import {getParams} from '@/utils/index.js' import {getParams} from '@/utils/index.js'
``` ```
获取 url 后面的参数 储存在 vuex 中 获取 url 后面的参数 储存在 vuex 中
\ No newline at end of file
本项目中会经历两次页面回调 一次是企微的授权验证回调 一次是 钉钉登录成功的回调 回调页面必须在首页完成 因为这个回调地址已经配置过了 钉钉回调成功后 页面 url 上会带一个 type=ding 的参数 需要根据这个参数来判断 是钉钉回调还是企微回调 如果是钉钉的回调 表明 微信授权的逻辑已经完成了 可以直接去 首页了
\ No newline at end of file
...@@ -2,4 +2,31 @@ ...@@ -2,4 +2,31 @@
# 1.后端签名时候的 url 应该是 重定向回来的那个 url 带 code 和 state 参数 而不是 在企微后台设置的那个 url # 1.后端签名时候的 url 应该是 重定向回来的那个 url 带 code 和 state 参数 而不是 在企微后台设置的那个 url
应该是 https://companywx.jianshuwenhua.com/company_app/index.html?code=-aXitj4Tt8UNLq_evPRgECSVS6zHpP6-r3ofYzk0BeM&state=STATE 带上参数去签名 应该是 https://companywx.jianshuwenhua.com/company_app/index.html?code=-aXitj4Tt8UNLq_evPRgECSVS6zHpP6-r3ofYzk0BeM&state=STATE 带上参数去签名
# 1.掌权扫码登录的时候需要在 钉钉应用后台添加授权跳转地址 由于每个主体的域名不一样 所以所有的主体的地址都需要添加 新增加的主体也需要在钉钉应用后台添加 # 1.掌权扫码登录的时候需要在 钉钉应用后台添加授权跳转地址 由于每个主体的域名不一样 所以所有的主体的地址都需要添加 新增加的主体也需要在钉钉应用后台添加
\ No newline at end of file
# 2.这里用 hash 模式 因为本项目是在企微 服务器下的一个二级页面 如果用 history 模式 需要修改 nginx 配置 在 nginx 配置中 需要添加
```
location /company_app/ {
root /usr/share/nginx/html; # 注意这里是html,不是html/company_app
try_files $uri $uri/ /company_app/index.html;
}
```
这个配置是 如果访问的 url 是 /company_app/ 那么就访问 /company_app/index.html 这个文件 用 hash 模式不用修改 nginx 配置 直接用就行了
如果用 history 需要在 vue.config.js 中配置 historyApiFallback: true, 解决本地开发404问题
# 3. 在域名的二级目录下 重新上传一个 带路由的项目时 需要在 router.js 中设置 base 目录 本地不需要设置
```
base:process.env.NODE_ENV === 'production' ? '/company_app' : '/',
```
# 4.打包到测试环境的时候 用 npm run build:stage 打包到正式环境的时候 用 npm run build:prod
因为企微侧边栏是跟当前登录的主体的域名下的 html 文件 主体域名下 没有测试和正式的域名 只有一个域名
例如 简书 的域名 https://companywx.jianshuwenhua.com/ 不管在 正式环境还是在测试环境的掌微中 都是跳转这个域名 所以 在配置钉钉回调的时候 回调地址有测试和正式的域名 但是 在企微侧边栏打开的页面只有一个 域名 companywx.jianshuwenhua.com 所以在打包到测试环境的时候
用 npm run build:stage 打包到正式环境的时候 用 npm run build:prod
# 5. 谨记 当打包上线到正式环境的时候 一定要 用npm run build:prod 重新打包一次 要不钉钉扫码登录会有问题 回调地址会有错误
\ No newline at end of file
...@@ -18,11 +18,5 @@ new Vue({ ...@@ -18,11 +18,5 @@ new Vue({
}).$mount('#app') }).$mount('#app')
Vue.prototype.$cookies = Cookies; Vue.prototype.$cookies = Cookies;
Vue.prototype.$lodash = _; Vue.prototype.$lodash = _;
const name = Cookies.get('name');
if(!name){
console.log('cookie 不存在');
Cookies.set('name', 'maoxiya');
}else{
console.log('cookie 存在');
}
...@@ -3,18 +3,20 @@ import VueRouter from 'vue-router' ...@@ -3,18 +3,20 @@ import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue' import HomeView from '../views/HomeView.vue'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
Vue.use(VueRouter) Vue.use(VueRouter)
import { getParams } from '@/utils/index'
const routes = [ const routes = [
{
path: '/login',
name: 'login',
component: () => import('../views/login.vue')
},
{ {
path: '/', path: '/',
name: 'home', name: 'home',
component: HomeView component: HomeView
}, },
{ {
path: '/login',
name: 'login',
component: () => import('../views/login.vue')
},
{
path: '/about', path: '/about',
name: 'about', name: 'about',
component: () => import('../views/AboutView.vue') component: () => import('../views/AboutView.vue')
...@@ -26,28 +28,40 @@ const routes = [ ...@@ -26,28 +28,40 @@ const routes = [
// } // }
] ]
const router = new VueRouter({ const router = new VueRouter({
/* 这里用 hash 模式 因为本项目是在企微 服务器下的一个二级页面 如果用 history 模式 需要修改 nginx 配置 在 nginx 配置中 需要添加 location /company_app/ {
root /usr/share/nginx/html; # 注意这里是html,不是html/company_app
try_files $uri $uri/ /company_app/index.html;
}
这个配置是 如果访问的 url 是 /company_app/ 那么就访问 /company_app/index.html 这个文件
用 hash 模式不用修改 nginx 配置 直接用就行了
如果用 history 需要在 vue.config.js 中配置 historyApiFallback: true, 解决404问题
*/
mode: 'history', mode: 'history',
base: process.env.BASE_URL, base:process.env.NODE_ENV === 'development' ? '/' : '/company_app',
routes routes
}) })
// router/index.js // router/index.js
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// 需要登录态的页面 // 需要登录态的页面
const needAuth = !['/login'].includes(to.path) const needAuth = !['/login'].includes(to.path)
// 检查登录信息 // 检查登录信息
const wecomUserId = Cookies.get('wecom_userid') const wecomUserId = Cookies.get('wx_userid')
const dingUserId = Cookies.get('ding_userid') const dingUserId = Cookies.get('ding_userid')
const externalUserId = Cookies.get('wecom_external_userid') const urlParams = getParams();
if (needAuth) { if (needAuth) {
if (wecomUserId && dingUserId && externalUserId) { if (wecomUserId && dingUserId) {
// 登录信息齐全,允许进入 // 登录信息齐全,允许进入
next() next()
} else { } else {
// 缺少登录信息,跳转到登录页 // 缺少登录信息,跳转到登录页
next('/login') // 跳转到 login 的时候带上当前 url 的参数
next({
path: '/login',
query: urlParams
})
} }
} else { } else {
// 登录页、回调页等不需要校验 // 登录页、回调页等不需要校验
......
...@@ -8,7 +8,9 @@ const state = { ...@@ -8,7 +8,9 @@ const state = {
"time": 1747726636, "time": 1747726636,
externalUserId:'' externalUserId:''
}, },
userid:'userid' userid:'userid',
corp_id:'',
externalUserId:''
} }
const mutations = { const mutations = {
set_userInfo(state,userInfo){ set_userInfo(state,userInfo){
...@@ -16,6 +18,12 @@ const mutations = { ...@@ -16,6 +18,12 @@ const mutations = {
}, },
set_userid(state,userid){ set_userid(state,userid){
state.userid = userid state.userid = userid
},
set_corp_id(state,corp_id){
state.corp_id = corp_id
},
set_externalUserId(state,externalUserId){
state.externalUserId = externalUserId
} }
} }
const actions = { const actions = {
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
*/ */
import store from '@/store' import store from '@/store'
import Clipboard from 'clipboard' import Clipboard from 'clipboard'
import * as imageConversion from 'image-conversion'
export function parseTime(time, cFormat) { export function parseTime(time, cFormat) {
if (arguments.length === 0 || !time) { if (arguments.length === 0 || !time) {
return null return null
...@@ -104,6 +103,7 @@ export function formatTime(time, option) { ...@@ -104,6 +103,7 @@ export function formatTime(time, option) {
* @returns {Object} * @returns {Object}
*/ */
export function getParams(url) { export function getParams(url) {
url = url || window.location.href;
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
if (!search) { if (!search) {
return {} return {}
......
...@@ -71,7 +71,6 @@ service.interceptors.response.use( ...@@ -71,7 +71,6 @@ service.interceptors.response.use(
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) })
// 处理token相关错误: 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; // 处理token相关错误: 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (TOKEN_ERROR_CODES.includes(res.status_code)) { if (TOKEN_ERROR_CODES.includes(res.status_code)) {
// to re-login // to re-login
...@@ -83,10 +82,7 @@ service.interceptors.response.use( ...@@ -83,10 +82,7 @@ service.interceptors.response.use(
console.log('重新登录') console.log('重新登录')
}) })
} }
return Promise.reject(new Error(res.msg || 'Error'))
} }
return res return res
}, },
(error) => { (error) => {
...@@ -96,7 +92,6 @@ service.interceptors.response.use( ...@@ -96,7 +92,6 @@ service.interceptors.response.use(
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) })
return Promise.reject(error) return Promise.reject(error)
} }
) )
......
{
"status_code": 1,
"msg": "操作成功",
"data": {
"_id": {
"oid": "6267d7e03c5d2012c56a43e8"
},
"userid": "JinDuoXia",
"name": "毛细亚",
"department": [
4
],
"position": "",
"mobile": "18236536168",
"gender": "1",
"email": "",
"avatar": "https://wework.qpic.cn/wwpic3az/139259_PMNrkYz3SXeS019_1704886075/0",
"status": 1,
"isleader": 0,
"extattr": {
"attrs": [
]
},
"telephone": "",
"enable": 1,
"hide_mobile": 0,
"order": [
0
],
"main_department": 4,
"qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=vc78f27c823c0be068",
"alias": "123132",
"is_leader_in_dept": [
0
],
"thumb_avatar": "https://wework.qpic.cn/wwhead/duc2TvpEgSTUk5XcCXup4xOJsyGFXcvS9fNicPuAERuNELRicnFsEwvHcAF8jF18Gfziavv8CnZKWU/100",
"direct_leader": [
],
"biz_mail": "jinduoxia@hzjswhcbyxgs3.wecom.work",
"corp_id": "wweaefe716636df3d1",
"external_user_count": 10,
"online_status": "offline",
"is_follow_user": 1,
"is_kf_account": 1,
"shell_userid": "1688858370304431",
"self_defined_columns": [
{
"name": "1231"
},
{
"name": "测试"
},
{
"name": "冯源"
}
],
"created_at": 1650972640,
"updated_at": 1747812312,
"active_time": "1747289758",
"login_pc": "PC01-01",
"external_profile": {
"external_attr": [
{
"type": 0,
"name": "工作时间",
"text": {
"value": ""
}
},
{
"type": 1,
"name": "服务升级",
"web": {
"url": "",
"title": ""
}
},
{
"type": 1,
"name": "意见反馈",
"web": {
"url": "",
"title": ""
}
},
{
"type": 1,
"name": "百度一下",
"web": {
"url": "",
"title": ""
}
},
{
"type": 0,
"name": "验收文本",
"text": {
"value": "测试"
}
},
{
"type": 2,
"name": "测试跳转",
"miniprogram": {
"appid": "",
"pagepath": "",
"title": ""
}
}
]
},
"show_avatar": "http://zhangsheng-1300623068.cos.ap-guangzhou.myqcloud.com/zhangsheng/service/avatars/20231026/GdkmBnfAH83ASRe8naN2QFPexiD65yKs1698312096458.png",
"show_name": "哈哈哈1231",
"weixin_blongs_id": 2955,
"group_chat_count": 2,
"group_chat_member_count": 12,
"receipt_cser_id": 4090,
"receipt_cser_name": "毛细亚"
},
"extra": {
}
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ module.exports = defineConfig({ ...@@ -9,6 +9,7 @@ module.exports = defineConfig({
transpileDependencies: true, transpileDependencies: true,
outputDir: 'company_app', outputDir: 'company_app',
devServer: { devServer: {
historyApiFallback: true, // 解决404问题
open: false, open: false,
client: { client: {
overlay: { overlay: {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论