Commit 44189638 by 张立顺

Merge branch 'SAAS+V5.8.5' of 192.168.3.233:saas/wx-notification into SAAS+V5.8.6

2 parents 44b35065 787588f9
...@@ -12,6 +12,7 @@ import { Http } from 'glsx-common' ...@@ -12,6 +12,7 @@ import { Http } from 'glsx-common'
import { Notify } from 'vant' import { Notify } from 'vant'
import { ssoApi } from '@/api' import { ssoApi } from '@/api'
import store from '@/store' import store from '@/store'
import { shouldRequireWwAuth } from './wwAuth'
const state = { const state = {
showWindow: false, showWindow: false,
...@@ -21,9 +22,6 @@ const state = { ...@@ -21,9 +22,6 @@ const state = {
import router from '@/router' import router from '@/router'
const EVECTION_AUTH_PATHS = ['/department', '/personage', '/company']
const APPROVAL_AUTH_PATHS = ['/orderApproval', '/accountApproval']
function saveUrlParams() { function saveUrlParams() {
const { corpId, agentId, phone, name, id, orderCode, uuid } = util.getQuery() const { corpId, agentId, phone, name, id, orderCode, uuid } = util.getQuery()
if (phone) util.setLocalStorage('ww_params_phone', phone) if (phone) util.setLocalStorage('ww_params_phone', phone)
...@@ -40,12 +38,11 @@ function saveUrlParams() { ...@@ -40,12 +38,11 @@ function saveUrlParams() {
} }
function needWwAuth(href) { function needWwAuth(href) {
const pushId = util.getQuery('pushId') return shouldRequireWwAuth({
const isEvectionPath = EVECTION_AUTH_PATHS.some(keyword => href.includes(keyword)) href,
const isApprovalPath = APPROVAL_AUTH_PATHS.some(keyword => href.includes(keyword)) hostname: window.location.hostname,
if (isEvectionPath && pushId && pushId * 1 > 744) return true pushId: util.getQuery('pushId')
if (isApprovalPath) return true })
return false
} }
async function handleWwLogin({ commit }) { async function handleWwLogin({ commit }) {
......
const DEVELOPMENT_HOSTNAME = 'scrm.dev.glsx.com.cn'
const EVECTION_AUTH_PATHS = ['/evection/department', '/evection/personage', '/evection/company']
const APPROVAL_AUTH_PATHS = ['/orderapproval', '/accountapproval']
function getHashRoutePath(href) {
const hashIndex = href.indexOf('#')
if (hashIndex === -1) return ''
let routePath = href.slice(hashIndex + 1).split('?')[0].toLowerCase()
if (routePath && !routePath.startsWith('/')) routePath = `/${routePath}`
if (routePath.length > 1) routePath = routePath.replace(/\/+$/, '')
return routePath
}
function shouldRequireWwAuth({ href = '', hostname = '', pushId } = {}) {
const routePath = getHashRoutePath(href)
const isEvectionPath = EVECTION_AUTH_PATHS.includes(routePath)
const isApprovalPath = APPROVAL_AUTH_PATHS.includes(routePath)
if (isApprovalPath) return true
if (isEvectionPath && hostname === DEVELOPMENT_HOSTNAME) return false
if (isEvectionPath && pushId && pushId * 1 > 744) return true
return false
}
module.exports = {
shouldRequireWwAuth
}
...@@ -132,6 +132,28 @@ ...@@ -132,6 +132,28 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box focusIssues" v-if="infoData.focusIssues && infoData.focusIssues.length">
<SectionTitle title="重点问题聚焦" :titleIcon="focusIssues"></SectionTitle>
<div class="focusIssues">
<div class="focusIssues-list">
<div
class="focusIssues-group"
v-for="(group, groupIndex) in focusIssuesRows"
:key="groupIndex"
>
<div class="group-title">{{ groupIndex === 0 ? '当月用餐招待超标' : '当月差旅住宿连续超7天' }}</div>
<div
class="focusIssues-item"
v-for="(item, index) in group"
:key="index"
>
<div class="text">{{ item.staffName }}</div>
<div class="value">{{ item.value }}{{ groupIndex === 0 ? '次' : '天' }}</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
<div v-show="!$store.state.app.authorizePage" class="loadingBox" ></div> <div v-show="!$store.state.app.authorizePage" class="loadingBox" ></div>
</div> </div>
...@@ -145,6 +167,7 @@ import DataItem from './components/DataItem.vue' ...@@ -145,6 +167,7 @@ import DataItem from './components/DataItem.vue'
import pieChart from './components/pieChart.vue' import pieChart from './components/pieChart.vue'
import evectionApi from '@/api/evection' import evectionApi from '@/api/evection'
import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js' import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js'
import { groupFocusIssues } from './focusIssues'
import store from '@/store' import store from '@/store'
export default { export default {
...@@ -160,6 +183,7 @@ export default { ...@@ -160,6 +183,7 @@ export default {
hospitalityIcon: require('@/assets/images/hospitality.png'), hospitalityIcon: require('@/assets/images/hospitality.png'),
deptIcon: require('@/assets/images/deptIcon.png'), deptIcon: require('@/assets/images/deptIcon.png'),
hotel: require('@/assets/images/hotel.png'), hotel: require('@/assets/images/hotel.png'),
focusIssues: require('@/assets/images/focusIssues.png'),
analyse: require('@/assets/images/analyse.png'), analyse: require('@/assets/images/analyse.png'),
pushId: this.$route.query.pushId, pushId: this.$route.query.pushId,
infoData: {}, infoData: {},
...@@ -221,6 +245,9 @@ export default { ...@@ -221,6 +245,9 @@ export default {
} }
return rows return rows
}, },
focusIssuesRows() {
return groupFocusIssues(this.infoData.focusIssues)
},
StatisticData() { StatisticData() {
return [ return [
{ {
...@@ -548,6 +575,45 @@ $boxWidth: 351; ...@@ -548,6 +575,45 @@ $boxWidth: 351;
} }
} }
} }
.focusIssues {
.focusIssues-list {
display: flex;
align-items: stretch;
height: auto;
.focusIssues-group {
flex: 1;
padding: 4px 8px;
box-sizing: border-box;
margin-right: 4px;
height: auto;
.group-title {
color: #666666;
font-size: 14px;
}
.focusIssues-item {
color: #222222;
font-size: 14px;
margin-top: 8px;
display: flex;
align-items: center;
.text {
padding-right: 4px;
border-right: 1px solid #f0f0f0;
max-width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.value {
padding-left: 4px;
}
}
}
.focusIssues-group:nth-child(1) {
border-right: 1px solid #f0f0f0;
}
}
}
// .block-145 { // .block-145 {
// width: formatWidth(145, $boxWidth); // width: formatWidth(145, $boxWidth);
// } // }
......
...@@ -128,6 +128,7 @@ import DataItem from './components/DataItem.vue' ...@@ -128,6 +128,7 @@ import DataItem from './components/DataItem.vue'
import pieChart from './components/pieChart.vue' import pieChart from './components/pieChart.vue'
import evectionApi from '@/api/evection' import evectionApi from '@/api/evection'
import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js' import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js'
import { groupFocusIssues } from './focusIssues'
import store from '@/store' import store from '@/store'
export default { export default {
...@@ -230,19 +231,7 @@ export default { ...@@ -230,19 +231,7 @@ export default {
return rows return rows
}, },
focusIssuesRows() { focusIssuesRows() {
const groupedData = return groupFocusIssues(this.infoData.focusIssues)
this.infoData.focusIssues &&
this.infoData.focusIssues.reduce((acc, item) => {
const key = item.sceneType
if (!acc[key]) {
acc[key] = []
}
acc[key].push(item)
return acc
}, {})
if (groupedData) {
return [groupedData[1] || [], groupedData[3] || []]
}
}, },
StatisticData() { StatisticData() {
if (this.infoData.reportDetail) { if (this.infoData.reportDetail) {
......
function groupFocusIssues(issues) {
const rows = [[], []]
if (!Array.isArray(issues)) return rows
issues.forEach(item => {
if (!item) return
if (item.sceneType === 1) rows[0].push(item)
if (item.sceneType === 3) rows[1].push(item)
})
return rows
}
module.exports = {
groupFocusIssues
}
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const Vue = require('vue')
const { compile, parseComponent } = require('vue-template-compiler')
let groupFocusIssues
try {
const focusIssuesModule = require('../src/views/evection/focusIssues')
groupFocusIssues = focusIssuesModule.groupFocusIssues
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND' || !error.message.includes('focusIssues')) {
throw error
}
}
assert.strictEqual(
typeof groupFocusIssues,
'function',
'focusIssues should expose a shared grouping function'
)
const issues = [
{ sceneType: 3, staffName: '李四', value: 8 },
{ sceneType: 1, staffName: '张三', value: 0 },
{ sceneType: 2, staffName: '未知场景', value: 99 },
null,
{ sceneType: 1, staffName: '王五', value: 2 }
]
const issuesSnapshot = JSON.parse(JSON.stringify(issues))
assert.deepStrictEqual(groupFocusIssues(issues), [
[
{ sceneType: 1, staffName: '张三', value: 0 },
{ sceneType: 1, staffName: '王五', value: 2 }
],
[{ sceneType: 3, staffName: '李四', value: 8 }]
])
assert.deepStrictEqual(issues, issuesSnapshot, 'grouping should not mutate API data')
for (const emptyValue of [undefined, null, '', {}, []]) {
assert.deepStrictEqual(groupFocusIssues(emptyValue), [[], []])
}
function renderCompanyTemplate(renderData) {
const componentPath = path.resolve(__dirname, '../src/views/evection/company.vue')
const descriptor = parseComponent(fs.readFileSync(componentPath, 'utf8'))
const compiled = compile(descriptor.template.content)
assert.deepStrictEqual(compiled.errors, [], 'company template should compile')
Vue.config.silent = true
Vue.prototype.$store = {
state: {
app: {
authorizePage: true
}
}
}
const vm = new Vue({
data() {
return renderData
},
methods: {
formatNum: value => value,
formatRatio: value => value,
formatIsRatio: () => false,
getRatioColor: () => '',
getIconSrc: () => ''
},
render: new Function(compiled.render),
staticRenderFns: compiled.staticRenderFns.map(code => new Function(code))
})
return vm._render()
}
function collectRenderedText(vnode, output = []) {
if (!vnode) return output
if (typeof vnode.text === 'string') output.push(vnode.text)
if (vnode.data && vnode.data.attrs && vnode.data.attrs.title) {
output.push(vnode.data.attrs.title)
}
for (const child of vnode.children || []) collectRenderedText(child, output)
return output
}
const companyRenderData = {
analyse: '',
colors: [],
deptArrRows: [],
deptIcon: '',
deptSpendListData: null,
dinnerDeptSpendListData: null,
focusIssues: '',
focusIssuesRows: [
[{ sceneType: 1, staffName: '张三', value: 2 }],
[{ sceneType: 3, staffName: '李四', value: 8 }]
],
hospitalityIcon: '',
hotel: '',
infoData: {
focusIssues: [
{ sceneType: 1, staffName: '张三', value: 2 },
{ sceneType: 3, staffName: '李四', value: 8 }
],
monthEndDay: 30,
monthStartDay: 1,
monthValue: 9
},
StatisticData: [],
travelArrRows: [],
travelDeptSpendListData: []
}
const renderedText = collectRenderedText(renderCompanyTemplate(companyRenderData)).join('|')
assert.match(renderedText, /部门总览|差旅住宿.*重点问题聚焦/)
assert.match(renderedText, /当月用餐招待超标.*张三.*2次/)
assert.match(renderedText, /当月差旅住宿连续超7天.*李四.*8天/)
for (const emptyFocusIssues of [undefined, []]) {
const emptyRenderedText = collectRenderedText(
renderCompanyTemplate({
...companyRenderData,
focusIssuesRows: [[], []],
infoData: {
...companyRenderData.infoData,
focusIssues: emptyFocusIssues
}
})
).join('|')
assert.strictEqual(emptyRenderedText.includes('重点问题聚焦'), false)
}
console.log('focusIssues tests passed')
const assert = require('assert')
let shouldRequireWwAuth
try {
const wwAuth = require('../src/store/modules/wwAuth')
shouldRequireWwAuth = wwAuth.shouldRequireWwAuth
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND' || !error.message.includes('wwAuth')) {
throw error
}
}
assert.strictEqual(
typeof shouldRequireWwAuth,
'function',
'wwAuth should expose an authorization decision function'
)
const companyHref = 'http://scrm.dev.glsx.com.cn/wx-notification/#/evection/company'
assert.strictEqual(
shouldRequireWwAuth({
href: companyHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '745'
}),
false,
'Meituan reports on the development host should skip WeCom authorization'
)
for (const reportPath of ['personage', 'department', 'company']) {
assert.strictEqual(
shouldRequireWwAuth({
href: `http://scrm.dev.glsx.com.cn/wx-notification/#/evection/${reportPath}`,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
false
)
}
for (const hostname of ['scrm.test.glsx.com.cn', 'scrm.glsx.com.cn']) {
assert.strictEqual(
shouldRequireWwAuth({
href: `https://${hostname}/wx-notification/#/evection/company`,
hostname,
pushId: '745'
}),
true,
`${hostname} should retain the existing authorization rule`
)
}
assert.strictEqual(
shouldRequireWwAuth({
href: 'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval',
hostname: 'scrm.dev.glsx.com.cn'
}),
true,
'the development-host bypass should not apply to approval pages'
)
for (const approvalHref of [
'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval?return=/company',
'http://scrm.dev.glsx.com.cn/wx-notification/#/accountApproval?from=/personage',
'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval/',
'http://scrm.dev.glsx.com.cn/wx-notification/#/accountApproval///',
'http://scrm.dev.glsx.com.cn/wx-notification/#/OrderApproval'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: approvalHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
true,
'approval pages must remain protected when query values contain report path names'
)
}
for (const reportHref of [
'https://scrm.test.glsx.com.cn/wx-notification/#/evection/company/',
'https://scrm.test.glsx.com.cn/wx-notification/#/EVECTION/COMPANY'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: reportHref,
hostname: 'scrm.test.glsx.com.cn',
pushId: '999'
}),
true,
'Router-equivalent report paths must retain authorization outside development'
)
}
for (const nonReportHref of [
'http://scrm.dev.glsx.com.cn/wx-notification/#/evection/company-preview',
'http://scrm.dev.glsx.com.cn/wx-notification/#/unrelated?next=/department'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: nonReportHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
false,
'only exact Meituan report routes should participate in the report authorization rule'
)
}
assert.strictEqual(
shouldRequireWwAuth({
href: companyHref,
hostname: 'scrm.dev.glsx.com.cn.evil.example',
pushId: '745'
}),
true,
'the bypass must require an exact hostname match'
)
assert.strictEqual(
shouldRequireWwAuth({
href: 'https://scrm.test.glsx.com.cn/wx-notification/#/evection/company',
hostname: 'scrm.test.glsx.com.cn',
pushId: '624'
}),
false,
'legacy report links should keep the existing pushId compatibility behavior'
)
console.log('wwAuth tests passed')
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!