Browse Source

site+'%'

dev
han\hanst 4 weeks ago
parent
commit
3f826e7af1
  1. 80
      src/utils/subSiteAuth.js
  2. 23
      src/views/modules/purchase/cancelReceipt.vue
  3. 5
      src/views/modules/purchase/receiptRecords.vue
  4. 89
      src/views/modules/warehouse/labelQuery.vue

80
src/utils/subSiteAuth.js

@ -0,0 +1,80 @@
/**
* 统一格式化站点编码避免大小写空白和通配符差异导致匹配失败
* @param {*} siteCode
* @returns {string}
*/
function normalizeSiteCode (siteCode) {
return String(siteCode || '')
.replace(/%/g, '')
.trim()
.toUpperCase()
}
/**
* 站点编码去重并清理空值
* @param {Array} siteCodeList
* @returns {Array<string>}
*/
function normalizeSiteCodeList (siteCodeList) {
if (!Array.isArray(siteCodeList)) {
return []
}
return Array.from(
new Set(
siteCodeList
.map(code => normalizeSiteCode(code))
.filter(code => !!code)
)
)
}
/**
* 获取当前用户授权子site编码列表
* 优先读取Vuex若为空再回退localStorage避免刷新后丢失授权缓存
* @param {Array} storeSubSiteCodeList
* @returns {Array<string>}
*/
export function getAuthorizedSubSiteCodeList (storeSubSiteCodeList) {
const subSiteCodeListFromStore = normalizeSiteCodeList(storeSubSiteCodeList)
if (subSiteCodeListFromStore.length > 0) {
return subSiteCodeListFromStore
}
try {
const localSubSiteCodeList = JSON.parse(localStorage.getItem('userSubSiteCodeList') || '[]')
return normalizeSiteCodeList(localSubSiteCodeList)
} catch (error) {
console.error('解析userSubSiteCodeList失败:', error)
return []
}
}
/**
* 按授权子site过滤列表数据避免site前缀查询返回未授权子site数据
* @param {Array} rows 列表原始数据
* @param {Array} authorizedSubSiteCodeList 用户授权子site编码列表
* @param {Array} siteFieldList 数据中可能存放站点编码的字段
* @returns {Array}
*/
export function filterRowsByAuthorizedSubSite (rows, authorizedSubSiteCodeList, siteFieldList = ['contract']) {
const sourceRows = Array.isArray(rows) ? rows : []
const normalizedAuthorizedList = normalizeSiteCodeList(authorizedSubSiteCodeList)
// 未拿到授权子site时,返回空列表,避免越权数据被前端展示
if (normalizedAuthorizedList.length === 0) {
return []
}
const authorizedSiteSet = new Set(normalizedAuthorizedList)
const validSiteFieldList = Array.isArray(siteFieldList) && siteFieldList.length > 0 ? siteFieldList : ['contract']
return sourceRows.filter(row => {
if (!row || typeof row !== 'object') {
return false
}
return validSiteFieldList.some(field => {
const rowSiteCode = normalizeSiteCode(row[field])
return rowSiteCode && authorizedSiteSet.has(rowSiteCode)
})
})
}

23
src/views/modules/purchase/cancelReceipt.vue

@ -143,6 +143,12 @@
<script> <script>
import { getCancelableReceiptList, cancelReceipt } from '@/api/purchase/purchaseManage' import { getCancelableReceiptList, cancelReceipt } from '@/api/purchase/purchaseManage'
import { filterRowsByAuthorizedSubSite, getAuthorizedSubSiteCodeList } from '@/utils/subSiteAuth'
const getCurrentSiteLike = () => {
const site = localStorage.getItem('site') || ''
return site ? `${site}%` : ''
}
export default { export default {
data () { data () {
@ -156,7 +162,7 @@ export default {
dataListLoading: false, dataListLoading: false,
dataListSelections: [], dataListSelections: [],
queryHeaderData: { queryHeaderData: {
site: localStorage.getItem('site'),
site: getCurrentSiteLike(),
orderNo: '', orderNo: '',
partNo: '', partNo: '',
batchNo: '', batchNo: '',
@ -199,15 +205,20 @@ export default {
return return
} }
this.dataListLoading = true this.dataListLoading = true
const siteLike = getCurrentSiteLike()
const params = { const params = {
page: this.pageIndex, page: this.pageIndex,
size: this.pageSize, size: this.pageSize,
...this.queryHeaderData
...this.queryHeaderData,
site: siteLike
} }
getCancelableReceiptList(params).then(({data}) => { getCancelableReceiptList(params).then(({data}) => {
if (data && data.code === 0) { if (data && data.code === 0) {
this.dataList = data.page.list
this.totalPage = data.page.totalCount
const sourceRows = (data.page && Array.isArray(data.page.list)) ? data.page.list : []
const authorizedSubSiteCodeList = getAuthorizedSubSiteCodeList(this.$store.state.user.subSiteCodeList)
// sitesite
this.dataList = filterRowsByAuthorizedSubSite(sourceRows, authorizedSubSiteCodeList, ['contract'])
this.totalPage = (data.page && data.page.totalCount) ? data.page.totalCount : 0
} else { } else {
this.dataList = [] this.dataList = []
this.totalPage = 0 this.totalPage = 0
@ -274,7 +285,7 @@ export default {
const promises = this.currentCancelRecords.map(record => { const promises = this.currentCancelRecords.map(record => {
return cancelReceipt({ return cancelReceipt({
receiptSequence: record.receiptSequence, receiptSequence: record.receiptSequence,
site: localStorage.getItem('site'),
site: record.contract,
cancelReason: this.cancelForm.cancelReason cancelReason: this.cancelForm.cancelReason
}) })
}) })
@ -314,7 +325,7 @@ export default {
// //
resetQuery () { resetQuery () {
this.queryHeaderData = { this.queryHeaderData = {
site: '',
site: getCurrentSiteLike(),
orderNo: '', orderNo: '',
partNo: '', partNo: '',
batchNo: '', batchNo: '',

5
src/views/modules/purchase/receiptRecords.vue

@ -1,9 +1,6 @@
<template> <template>
<div class="mod-config"> <div class="mod-config">
<el-form :inline="true" label-position="top"> <el-form :inline="true" label-position="top">
<el-form-item :label="$t('purchase.receiptRecords.site')">
<el-input style="width: 120px;" v-model="queryHeaderData.site"></el-input>
</el-form-item>
<el-form-item :label="$t('purchase.receiptRecords.receiptNo')"> <el-form-item :label="$t('purchase.receiptRecords.receiptNo')">
<el-input style="width: 120px;" v-model="queryHeaderData.receiptNo"></el-input> <el-input style="width: 120px;" v-model="queryHeaderData.receiptNo"></el-input>
</el-form-item> </el-form-item>
@ -237,7 +234,7 @@ export default {
dataListLoading: false, dataListLoading: false,
dataListSelections: [], dataListSelections: [],
queryHeaderData: { queryHeaderData: {
site: '',
site: localStorage.getItem('site'),
receiptNo: '', receiptNo: '',
partNo: '', partNo: '',
batchNo: '', batchNo: '',

89
src/views/modules/warehouse/labelQuery.vue

@ -164,6 +164,25 @@
width="450px" width="450px"
:close-on-click-modal="false"> :close-on-click-modal="false">
<el-form :model="otherInboundForm" ref="otherInboundForm" class="other-inbound-form"> <el-form :model="otherInboundForm" ref="otherInboundForm" class="other-inbound-form">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item :label="$t('warehouse.pallet.factory')" prop="site" class="form-item-vertical">
<el-select
v-model="otherInboundForm.site"
:placeholder="$t('warehouse.common.select')"
:loading="otherInboundSiteLoading"
style="width: 100%">
<el-option
v-for="item in otherInboundSiteOptions"
:key="item.siteCode"
:label="item.siteName"
:value="item.siteCode">
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('warehouse.inventory.part')" prop="partNo" class="form-item-vertical"> <el-form-item :label="$t('warehouse.inventory.part')" prop="partNo" class="form-item-vertical">
@ -298,6 +317,8 @@
import { getHandlingUnitLabelList, reprintLabel, deleteLabel, getFailedPrintTasks, retryFailedPrintTasks } from '@/api/warehouse/labelQuery' import { getHandlingUnitLabelList, reprintLabel, deleteLabel, getFailedPrintTasks, retryFailedPrintTasks } from '@/api/warehouse/labelQuery'
import { searchSysLanguagePackList, saveUserFavorite, searchUserFavorite } from '@/api/sysLanguage' import { searchSysLanguagePackList, saveUserFavorite, searchUserFavorite } from '@/api/sysLanguage'
import { createOtherInboundHU, printLabel } from '@/api/warehouse/otherInbound' import { createOtherInboundHU, printLabel } from '@/api/warehouse/otherInbound'
import { getUserAuthorizedSubSiteCodes } from '@/api/factory/accessSite'
import { getAuthorizedSubSiteCodeList } from '@/utils/subSiteAuth'
export default { export default {
data() { data() {
@ -589,7 +610,10 @@ export default {
// //
otherInboundVisible: false, otherInboundVisible: false,
otherInboundLoading: false, otherInboundLoading: false,
otherInboundSiteOptions: [],
otherInboundSiteLoading: false,
otherInboundForm: { otherInboundForm: {
site: '',
partNo: '', partNo: '',
partDesc: '', partDesc: '',
batchNo: '', batchNo: '',
@ -609,6 +633,9 @@ export default {
exportHeader: [this.$t('warehouse.label.query')], exportHeader: [this.$t('warehouse.label.query')],
exportFooter: [], exportFooter: [],
otherInboundRules: { otherInboundRules: {
site: [
{ required: true, message: this.$t('warehouse.pallet.siteRequired'), trigger: 'change' }
],
partNo: [ partNo: [
{ required: true, message: this.$t('warehouse.label.partNoRequired'), trigger: 'blur' } { required: true, message: this.$t('warehouse.label.partNoRequired'), trigger: 'blur' }
], ],
@ -849,11 +876,56 @@ export default {
}) })
}, },
normalizeSiteCodeList(siteCodeList) {
if (!Array.isArray(siteCodeList)) {
return []
}
return Array.from(new Set(siteCodeList.map(item => String(item || '').trim()).filter(item => !!item)))
},
applyOtherInboundAuthorizedSites(siteCodeList, parentSite) {
const normalizedSiteCodeList = this.normalizeSiteCodeList(siteCodeList)
const finalSiteCodeList = normalizedSiteCodeList.length > 0
? normalizedSiteCodeList
: this.normalizeSiteCodeList(parentSite ? [parentSite] : [])
this.otherInboundSiteOptions = finalSiteCodeList.map(siteCode => ({
siteCode,
siteName: siteCode
}))
if (!this.otherInboundSiteOptions.some(item => item.siteCode === this.otherInboundForm.site)) {
this.otherInboundForm.site = this.otherInboundSiteOptions.length > 0 ? this.otherInboundSiteOptions[0].siteCode : ''
}
},
async loadOtherInboundAuthorizedSites() {
const userName = String(localStorage.getItem('userName') || '').trim()
const parentSite = String(localStorage.getItem('site') || '').trim()
const cacheSubSiteCodeList = getAuthorizedSubSiteCodeList(this.$store.state.user.subSiteCodeList)
this.applyOtherInboundAuthorizedSites(cacheSubSiteCodeList, parentSite)
if (!userName || !parentSite) {
return
}
this.otherInboundSiteLoading = true
try {
const { data } = await getUserAuthorizedSubSiteCodes({ userName, site: parentSite })
if (data && data.code === 0) {
const apiSubSiteCodeList = data.data || []
// site退sitesite
this.applyOtherInboundAuthorizedSites(apiSubSiteCodeList, parentSite)
}
} catch (error) {
console.error('获取用户授权site失败:', error)
} finally {
this.otherInboundSiteLoading = false
}
},
// //
showOtherInboundDialog() { showOtherInboundDialog() {
this.otherInboundVisible = true this.otherInboundVisible = true
// //
this.otherInboundForm = { this.otherInboundForm = {
site: '',
partNo: '', partNo: '',
partDesc: '', partDesc: '',
batchNo: '', batchNo: '',
@ -868,6 +940,7 @@ export default {
remark: '', remark: '',
height: '', height: '',
} }
this.loadOtherInboundAuthorizedSites()
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs['otherInboundForm']) { if (this.$refs['otherInboundForm']) {
this.$refs['otherInboundForm'].clearValidate() this.$refs['otherInboundForm'].clearValidate()
@ -879,6 +952,10 @@ export default {
async createOtherInboundHU() { async createOtherInboundHU() {
try { try {
// //
if (!this.otherInboundForm.site) {
this.$alert(this.$t('warehouse.pallet.siteRequired'), this.$t('warehouse.common.error'), { confirmButtonText: this.$t('warehouse.common.confirm') })
return
}
if (!this.otherInboundForm.partNo) { if (!this.otherInboundForm.partNo) {
this.$alert(this.$t('warehouse.label.partNoRequired'), this.$t('warehouse.common.error'), { confirmButtonText: this.$t('warehouse.common.confirm') }) this.$alert(this.$t('warehouse.label.partNoRequired'), this.$t('warehouse.common.error'), { confirmButtonText: this.$t('warehouse.common.confirm') })
return return
@ -904,7 +981,7 @@ export default {
// HU // HU
const createData = { const createData = {
site: localStorage.getItem('site'),
site: this.otherInboundForm.site,
warehouseId: this.otherInboundForm.warehouseId, warehouseId: this.otherInboundForm.warehouseId,
partNo: this.otherInboundForm.partNo, partNo: this.otherInboundForm.partNo,
partDesc: this.otherInboundForm.partDesc, partDesc: this.otherInboundForm.partDesc,
@ -934,7 +1011,7 @@ export default {
} }
// //
await this.printHandlingUnits(data.unitIds, printLabelType)
await this.printHandlingUnits(data.unitIds, printLabelType, this.otherInboundForm.site)
this.otherInboundVisible = false this.otherInboundVisible = false
this.getDataList() // this.getDataList() //
@ -949,7 +1026,7 @@ export default {
}, },
// HandlingUnit // HandlingUnit
async printHandlingUnits(unitIds, printLabelType) {
async printHandlingUnits(unitIds, printLabelType, site) {
if (!unitIds || unitIds.length === 0) { if (!unitIds || unitIds.length === 0) {
return return
} }
@ -957,7 +1034,7 @@ export default {
try { try {
// HandlingUnit // HandlingUnit
for (const unitId of unitIds) { for (const unitId of unitIds) {
await this.printViaServer(unitId, printLabelType)
await this.printViaServer(unitId, printLabelType, site)
} }
this.$message.success(this.$t('warehouse.label.printSuccessWithCount', { count: unitIds.length })) this.$message.success(this.$t('warehouse.label.printSuccessWithCount', { count: unitIds.length }))
} catch (error) { } catch (error) {
@ -966,7 +1043,7 @@ export default {
}, },
// //
async printViaServer(unitId, printLabelType) {
async printViaServer(unitId, printLabelType, site) {
try { try {
const printRequest = { const printRequest = {
reportId: this.reportId, reportId: this.reportId,
@ -976,7 +1053,7 @@ export default {
dpi: this.dpi, dpi: this.dpi,
userId: localStorage.getItem('userName'), userId: localStorage.getItem('userName'),
username: localStorage.getItem('userName'), username: localStorage.getItem('userName'),
site: localStorage.getItem('site'),
site: site,
unitId: unitId, unitId: unitId,
labelType: printLabelType labelType: printLabelType
} }

Loading…
Cancel
Save